/**************************************
*Script Name: Alpha Gold Ledger *
*Author: Joeku AKA Demortris *
*For use with RunUO 1.0.0 *
*Client Tested with: 5.0.2b *
*Version: 1.6 *
*Initial Release: 01/30/06 *
*Revision Date: 06/04/06 *
**************************************/
using System;
using System.Collections;
using Server;
using Server.Targeting;
using Server.Mobiles;
using Server.Gumps;
using Server.Misc;
using Server.Network;
namespace Server.Items
{
public class GoldLedger : Item
{
public const double GoldWeight = 0.02;
public const bool GoldAutoLootAvailable = true;
public const bool GoldSweeperAvailable = true;
public double d_WeightScale = 0.00001;
public bool b_open = false;
private int i_Gold;
private bool b_GoldAutoLoot = true;
private bool b_GoldSweeper = true;
public int i_Selection = 0;
[CommandProperty(AccessLevel.GameMaster)]
public int Gold
{
get { return i_Gold; }
set
{
if (value > 999999999)
i_Gold = 999999999;
else if (value < 0)
i_Gold = 0;
else
i_Gold = value;
//TotalGold = i_Gold;
this.AppendWeight();
InvalidateProperties();
}
}
[CommandProperty(AccessLevel.GameMaster)]
public bool GoldAutoLoot { get { return b_GoldAutoLoot; } set { b_GoldAutoLoot = value; InvalidateProperties(); } }
[CommandProperty(AccessLevel.GameMaster)]
public bool GoldSweeper { get { return b_GoldSweeper; } set { b_GoldSweeper = value; InvalidateProperties(); } }
[CommandProperty(AccessLevel.GameMaster)]
public double WeightScale { get { return d_WeightScale; } set { d_WeightScale = value; this.AppendWeight(); } }
public override bool ForceShowProperties { get { return ObjectPropertyList.Enabled; } }
[Constructable]
public GoldLedger()
: base(7714)
{
Name = "a gold ledger";
Hue = 2125;
Weight = 1;
LootType = LootType.Blessed;
}
public override void UpdateTotals()
{
base.UpdateTotals();
//SetTotalGold(this.Gold);
}
public override void OnDoubleClick(Mobile from)
{
if (this.IsChildOf(from.Backpack))
{
from.CloseGump(typeof(GoldLedgerGump));
from.SendGump(new GoldLedgerGump(this));
from.SendMessage(2125, "You open your gold ledger.");
this.b_open = true;
}
else
from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it.
}
public void BeginAddGold(Mobile from)
{
if (this.Gold >= 999999999)
{
from.SendGump(new GoldLedgerGump(this));
from.SendMessage(2125, "You cannot deposit any more gold into this gold ledger.");
return;
}
from.Target = new AddGoldTarget(this);
from.SendMessage(2125, "What do you wish to deposit? (ESC to cancel)");
}
public class AddGoldTarget : Target
{
private GoldLedger m_TL;
public AddGoldTarget(GoldLedger tl)
: base(18, false, TargetFlags.None)
{
m_TL = tl;
}
protected override void OnTarget(Mobile from, object targeted)
{
if (m_TL.Deleted)
return;
m_TL.EndAddGold(from, targeted);
}
}
public void EndAddGold(Mobile from, object obj)
{
from.CloseGump(typeof(GoldLedgerGump));
if (obj is Item)
{
Item item = obj as Item;
double maxWeight = (WeightOverloading.GetMaxWeight(from));
int golda = 0;
if (!this.IsChildOf(from.Backpack))
{
from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it.
return;
}
if (!item.IsAccessibleTo(from))
{
from.SendGump(new GoldLedgerGump(this));
from.SendLocalizedMessage(3000270); // That is not accessible.
return;
}
if (obj is Gold)
{
Gold gold = obj as Gold;
golda = gold.Amount;
if ((gold.Amount + this.Gold) > 999999999)
golda = (999999999 - this.Gold);
double maxgold = golda;
if (this.d_WeightScale > 0 && gold.RootParent != from)
maxgold = ((maxWeight - ((double)Mobile.BodyWeight + (double)from.TotalWeight)) / this.d_WeightScale);
if (golda > maxgold)
golda = (int)maxgold;
if (golda < gold.Amount)
gold.Amount -= golda;
else
gold.Delete();
this.Gold += golda;
from.SendGump(new GoldLedgerGump(this));
from.SendMessage(2125, String.Format("You deposit {0} gold into your gold ledger.", golda.ToString("#,0")));
from.PlaySound(0x249);
}
else if (obj is GoldLedger && obj != this)
{
GoldLedger gledger = obj as GoldLedger;
golda = gledger.Gold;
if ((gledger.Gold + this.Gold) > 999999999)
golda = (999999999 - this.Gold);
double maxgold = golda;
if (this.d_WeightScale > 0)
maxgold = ((maxWeight - ((double)Mobile.BodyWeight + (double)from.TotalWeight)) / this.d_WeightScale);
if (golda > maxgold)
golda = (int)maxgold;
gledger.Gold -= golda;
this.Gold += golda;
from.SendGump(new GoldLedgerGump(this));
from.SendMessage(2125, String.Format("You transfer {0} gold into your gold ledger.", golda.ToString("#,0")));
from.PlaySound(0x249);
}
else
{
from.SendGump(new GoldLedgerGump(this));
from.SendMessage(2125, "You can only deposit gold into your gold ledger.");
}
}
else
{
from.SendGump(new GoldLedgerGump(this));
from.SendMessage(2125, "You can only deposit gold into your gold ledger.");
}
from.SendMessage(2125, "Do you want to deposit anything else? (ESC to cancel)");
from.Target = new AddGoldTarget(this);
}
public GoldLedger(Serial serial)
: base(serial)
{
}
public override void GetProperties(ObjectPropertyList list)
{
string weight = "" + (int)this.Weight;
base.AddNameProperties(list);
list.Add(1060738, this.Gold.ToString("#,0") + " Gold"); //value: ~1_val~
if (this.GoldSweeper && GoldLedger.GoldSweeperAvailable)
list.Add(1060661, "Gold Sweeper\tEnabled");
else if (!this.GoldSweeper && GoldLedger.GoldSweeperAvailable)
list.Add(1060661, "Gold Sweeper\tDisabled");
if (this.GoldAutoLoot && GoldLedger.GoldAutoLootAvailable)
list.Add(1060660, "Gold Looting\tAutomatic");
else if (!this.GoldAutoLoot && GoldLedger.GoldAutoLootAvailable)
list.Add(1060660, "Gold Looting\tManual");
if (this.d_WeightScale > 0)
{
if (this.Weight < 2 && this.Weight >= 1)
list.Add(1072788, weight); //Weight: ~1_WEIGHT~ stone
else if (this.Weight >= 2)
list.Add(1072789, weight); //Weight: ~1_WEIGHT~ stones
}
}
public void AppendWeight()
{
double newweight = (this.Gold * this.d_WeightScale);
this.Weight = newweight + 1;
}
public override bool OnDroppedToMobile(Mobile from, Mobile target)
{
Item item = target.Backpack.FindItemByType(typeof(GoldLedger));
if (item != null)
{
if (target == from)
from.SendMessage(2125, "You can only carry one gold ledger!");
else
from.SendMessage(2125, "That player can only carry one gold ledger!");
return false;
}
return true;
}
public override bool OnDroppedInto(Mobile from, Container target, Point3D p)
{
if (target == from.Backpack)
{
Item item = from.Backpack.FindItemByType(typeof(GoldLedger));
if (item != null)
{
from.SendMessage(2125, "You can only carry one gold ledger!");
return false;
}
}
else if (target.IsChildOf(from.Backpack))
{
Item item = from.Backpack.FindItemByType(typeof(GoldLedger));
if (item != null)
{
from.SendMessage(2125, "You can only carry one gold ledger!");
return false;
}
}
return target.OnDragDropInto(from, this, p);
}
public override bool OnDroppedOnto(Mobile from, Item target)
{
if (target == from.Backpack)
{
Item item = from.Backpack.FindItemByType(typeof(GoldLedger));
if (item != null)
{
from.SendMessage(2125, "You can only carry one gold ledger!");
return false;
}
}