Re: APPROVED: Powerscroll combine bag
Posted: Tue Sep 23, 2008 3:02 pm
Finished improving the code. Now all that's left is a test on my own test server, and away we go.
Code: Select all
using System;
using System.Collections;
using Server.Multis;
using Server.Mobiles;
using Server.Network;
namespace Server.Items
{
public class PowerscrollBag : BaseContainer
{
private Mobile speaker = null;
#region default stuff
public override int DefaultGumpID { get { return 0x3D; } }
public override int DefaultDropSound { get { return 0x48; } }
public override Rectangle2D Bounds
{
get { return new Rectangle2D(29, 34, 108, 94); }
}
[Constructable]
public PowerscrollBag() : base(0xE76)
{
Weight = 2.0;
Hue = 86;
}
public PowerscrollBag(Serial serial) : base(serial)
{
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write((int)0); // version
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
}
#endregion
public override bool OnDragDropInto(Mobile from, Item item, Point3D p)
{
// Check if this action passes BaseContainer's check
if (!base.OnDragDropInto(from, item, p))
{
return false;
}
else
{
// Item is a PowerScroll
if (item is PowerScroll)
{
// Recast Item
PowerScroll scroll = (PowerScroll)item;
int power = (int) Math.Round(scroll.Value);
// If scroll value is withing normal values
if (power == 105 || power == 110 || power == 115)
{
// Start counting
this.speaker = from;
this.countPowerScrolls(scroll.Skill, scroll.Value);
this.speaker = null;
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
}
public override bool OnDragDrop(Mobile from, Item dropped)
{
return this.OnDragDropInto(from, dropped, new Point3D());
}
/**
* Count all PowerScrolls of a given type.
*/
private void countPowerScrolls(SkillName skill, double power)
{
// Loop through all Items in this Bag
int count = 0;
foreach (Item i in this.Items)
{
// If this item is a PowerScroll
if (i is PowerScroll)
{
// Recast Item
PowerScroll scroll = (PowerScroll) i;
// If this PowerScroll is the same as the one that was dropped
if (scroll.Skill == skill && scroll.Value == power)
{
// Add one
count++;
}
}
}
Console.WriteLine("Counted: " + count.ToString() + "x " + skill.ToString() + " scrolls (" + power.ToString() + ")");
// Check if transformation threshold has been reached
this.transformPowerScrolls(skill, power, count);
}
/**
* Transforms lesser PowerScrolls into greater ones, if the threshold has been reached.
*
* Transformation thresholds:
* 105 -> 110 PS: 7x
* 110 -> 115 PS: 7x
* 115 -> 120 PS: 5x
*/
private void transformPowerScrolls(SkillName skill, double power, int count)
{
// We don't care about doubles
switch ((int)(Math.Round(power)))
{
case 105:
if (count >= 7)
{
this.speaker.PublicOverheadMessage(MessageType.System, 0x22, true, "Upgrading " + skill + " Power Scrolls with a power of " + power);
this.AddItem(new PowerScroll(skill, 110));
this.removePowerScrolls(skill, power);
}
break;
case 110:
if (count >= 7)
{
this.speaker.PublicOverheadMessage(MessageType.System, 0x22, true, "Upgrading " + skill + " Power Scrolls with a power of " + power);
this.AddItem(new PowerScroll(skill, 115));
this.removePowerScrolls(skill, power);
}
break;
case 115:
if (count >= 5)
{
this.speaker.PublicOverheadMessage(MessageType.System, 0x22, true, "Upgrading " + skill + " Power Scrolls with a power of " + power);
this.AddItem(new PowerScroll(skill, 120));
this.removePowerScrolls(skill, power);
}
break;
default:
break;
}
}
/**
* Removes all PowerScrolls of a given type
*/
private void removePowerScrolls(SkillName skill, double power)
{
for (int i = (this.Items.Count - 1); i >= 0; i--)
{
Item item = (Item)this.Items[i];
if (item is PowerscrollBag)
{
PowerScroll s = (PowerScroll)item;
if (s.Skill == skill && s.Value == power)
{
item.Delete();
}
}
}
}
}
}
Yeah thats a thought really, I'm interested in knowing this aswellHarabakc wrote:Since I'm being kind of lazy, and I don't want to re-skim the whole thread to find the correct amount, I'm just going to say 10 in place of the actual number of 110s needed to make a 115 and 115s to make 120s.
Is this setup so that when you put 10 110s in it you get a random 115, or you put 10 of the same 110 to get a 115 of the same type? And same question with the 115s - 120s.
True, I only changed that to use the "is xxx" syntax before posting, so a small typo here. I used the ItemID == 0x... before that.+Colibri wrote:I will post my corrections tomorrow, but I have a feeling you didn't test this in actionLast few lines, there's a "if item is PowerscrollBag" where it should be "if item is Powerscroll".
... Once more, you put a x amount of powerscrolls in the bag. those scrolls need to be of the same skill and same power. you then get a powerscroll with the same skill, but upgraded power. so 10x 110 BS -> 1x 115 BS for example.Harabakc wrote:Since I'm being kind of lazy, and I don't want to re-skim the whole thread to find the correct amount, I'm just going to say 10 in place of the actual number of 110s needed to make a 115 and 115s to make 120s.
Is this setup so that when you put 10 110s in it you get a random 115, or you put 10 of the same 110 to get a 115 of the same type? And same question with the 115s - 120s.
Code: Select all
using System;
using System.Collections;
using Server.Multis;
using Server.Mobiles;
using Server.Network;
namespace Server.Items
{
public class PowerScrollBag : BaseContainer
{
#region default stuff
public override int DefaultGumpID { get { return 0x3D; } }
public override int DefaultDropSound { get { return 0x48; } }
public override Rectangle2D Bounds
{
get { return new Rectangle2D(29, 34, 108, 94); }
}
[Constructable]
public PowerScrollBag() : base(0xE76)
{
Weight = 2.0;
Hue = 86;
}
public PowerScrollBag(Serial serial) : base(serial)
{
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write((int)0); // version
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
}
#endregion
public override bool OnDragDropInto(Mobile from, Item item, Point3D p)
{
// Check if this action passes BaseContainer's check
if ( !base.OnDragDropInto(from, item, p) )
return false;
// Recast Item
PowerScroll scroll = (PowerScroll)item;
if ( scroll == null )
return false;
int power = (int) Math.Round(scroll.Value);
// If scroll value is withing normal values
if ( !( power == 105 || power == 110 || power == 115 || power == 120 ) )
return false;
// Start counting
this.countPowerScrolls( from, scroll.Skill, scroll.Value);
return true;
}
public override bool OnDragDrop(Mobile from, Item dropped)
{
return this.OnDragDropInto(from, dropped, new Point3D());
}
/**
* Count all PowerScrolls of a given type.
*/
private void countPowerScrolls( Mobile from, SkillName skill, double power )
{
// Loop through all Items in this Bag
int count = 0;
foreach (Item i in this.Items)
{
// If this item is a PowerScroll
if (i is PowerScroll)
{
// Recast Item
PowerScroll scroll = (PowerScroll) i;
// If this PowerScroll is the same as the one that was dropped
if (scroll.Skill == skill && scroll.Value == power)
{
// Add one
count++;
}
}
}
//Console.WriteLine("Counted: " + count.ToString() + "x " + skill.ToString() + " scrolls (" + power.ToString() + ")");
// Check if transformation threshold has been reached
this.transformPowerScrolls( from, skill, power, count );
}
/**
* Transforms lesser PowerScrolls into greater ones, if the threshold has been reached.
*
* Transformation thresholds:
* 105 -> 110 PS: 7x
* 110 -> 115 PS: 7x
* 115 -> 120 PS: 5x
* 120 -> 125 PS: 5x
*/
private void transformPowerScrolls( Mobile from, SkillName skill, double power, int count )
{
// We don't care about doubles
switch ((int)(Math.Round(power)))
{
case 105:
if (count >= 7)
{
from.SendMessage("Upgrading " + SkillInfo.Table[(int)skill].Name + " power scrolls with the power of " + power);
this.DropItem(new PowerScroll(skill, 110));
this.removePowerScrolls( from, skill, power, 7);
}
break;
case 110:
if (count >= 7)
{
from.SendMessage( "Upgrading " + SkillInfo.Table[(int)skill].Name + " power scrolls with the power of " + power);
this.DropItem(new PowerScroll(skill, 115));
this.removePowerScrolls( from, skill, power, 7);
}
break;
case 115:
if (count >= 5)
{
from.SendMessage( "Upgrading " + SkillInfo.Table[(int)skill].Name + " power scrolls with the power of " + power);
this.DropItem(new PowerScroll(skill, 120));
this.removePowerScrolls( from, skill, power, 5);
}
break;
case 120:
if (count >= 5)
{
from.SendMessage("Upgrading " + SkillInfo.Table[(int)skill].Name + " power scrolls with the power of " + power);
this.DropItem(new PowerScroll(skill, 125));
this.removePowerScrolls( from, skill, power, 5);
}
break;
default:
break;
}
}
/**
* Removes all PowerScrolls of a given type
*/
private void removePowerScrolls( Mobile from, SkillName skill, double power, int number)
{
int count = 0;
for (int i = (this.Items.Count - 1); i >= 0; i--)
{
Item item = (Item)this.Items[i];
if ( !( item is PowerScroll ) )
continue;
PowerScroll scroll = (PowerScroll)item;
if (scroll.Skill == skill && scroll.Value == power && count < number )
{
count++;
item.Delete();
}
}
Effects.SendLocationParticles( EffectItem.Create( from.Location, from.Map, EffectItem.DefaultDuration ), 0, 0, 0, 0, 0, 5060, 0 );
Effects.PlaySound( from.Location, from.Map, 0x243 );
Effects.SendMovingParticles( new Entity( Serial.Zero, new Point3D( from.X - 6, from.Y - 6, from.Z + 15 ), from.Map ), from, 0x36D4, 7, 0, false, true, 0x497, 0, 9502, 1, 0, (EffectLayer)255, 0x100 );
Effects.SendMovingParticles( new Entity( Serial.Zero, new Point3D( from.X - 4, from.Y - 6, from.Z + 15 ), from.Map ), from, 0x36D4, 7, 0, false, true, 0x497, 0, 9502, 1, 0, (EffectLayer)255, 0x100 );
Effects.SendMovingParticles( new Entity( Serial.Zero, new Point3D( from.X - 6, from.Y - 4, from.Z + 15 ), from.Map ), from, 0x36D4, 7, 0, false, true, 0x497, 0, 9502, 1, 0, (EffectLayer)255, 0x100 );
Effects.SendTargetParticles( from, 0x375A, 35, 90, 0x00, 0x00, 9502, (EffectLayer)255, 0x100 );
}
public void Say( string args )
{
PublicOverheadMessage( MessageType.Regular, 0x3B2, false, args );
}
}
}