public class GiveGold
{
public static void GoldTransfer(Mobile m, Container c, BaseCreature creature)
{
if (creature.IsBonded)
return;
if (m.Map != creature.Map || !m.InRange(creature, 12))
return;
string nametitle = null;
if (creature.Title != null)
nametitle = creature.Name + " " + creature.Title;
else
nametitle = creature.Name;
Item item = m.Backpack.FindItemByType(typeof(GoldLedger));
GoldLedger ledger = item as GoldLedger;
if (ledger == null)
return;
if (!ledger.GoldAutoLoot || !m.Alive || !GoldLedger.GoldAutoLootAvailable)
return;
TransferGold(m, c, ledger, nametitle);
}
public static void TransferGold(Mobile m, Container c, GoldLedger ledger, string nametitle)
{
Item[] items = c.FindItemsByType(typeof(Gold));
foreach (Gold ngold in items)
{
Gold gold = ngold as Gold;
if (gold != null)
{
if (ledger.Gold < 999999999)
{
double maxWeight = (WeightOverloading.GetMaxWeight(m));
if ((Mobile.BodyWeight + m.TotalWeight) < (maxWeight))
{
int golda = gold.Amount;
if ((gold.Amount + ledger.Gold) > 999999999)
golda = (999999999 - ledger.Gold);
double maxgold = golda;
if (ledger.d_WeightScale > 0)
maxgold = ((maxWeight - ((double)Mobile.BodyWeight + (double)m.TotalWeight)) / ledger.d_WeightScale);
if (golda > maxgold)
golda = (int)maxgold;
int GoldID = 0;
if (golda == 1)
GoldID = gold.ItemID;
else if (golda > 1 && golda < 6)
GoldID = gold.ItemID + 1;
else if (golda >= 6)
GoldID = gold.ItemID + 2;
if (golda < gold.Amount)
gold.Amount -= golda;
else
gold.Delete();
ledger.Gold += golda;
if (ledger.b_open && golda > 0)
{
m.CloseGump(typeof(GoldLedgerGump));
m.SendGump(new GoldLedgerGump(ledger));
}
if (golda > 0)
{
m.SendMessage(2125, "You loot {0} gold from {1} and deposit it into your gold ledger.", golda.ToString("#,0"), nametitle);
Effects.SendMovingEffect(c, m, GoldID, 5, 50, true, false);
m.PlaySound(0x2E6);
}
}
}
}
}
}
public static void GoldSweep(Mobile m, Gold gold)
{
Item item = m.Backpack.FindItemByType(typeof(GoldLedger));
GoldLedger ledger = item as GoldLedger;
if (ledger == null)
return;
if (!ledger.GoldSweeper || !GoldLedger.GoldSweeperAvailable || !gold.Movable)
return;
if (gold != null)
{
if (ledger.Gold < 999999999)
{
double maxWeight = (WeightOverloading.GetMaxWeight(m));
if ((Mobile.BodyWeight + m.TotalWeight) < (maxWeight))
{
int golda = gold.Amount;
if ((gold.Amount + ledger.Gold) > 999999999)
golda = (999999999 - ledger.Gold);
double maxgold = golda;
if (ledger.d_WeightScale > 0)
maxgold = ((maxWeight - ((double)Mobile.BodyWeight + (double)m.TotalWeight)) / ledger.d_WeightScale);
if (golda > maxgold)
golda = (int)maxgold;
int GoldID = 0;
if (golda == 1)
GoldID = gold.ItemID;
else if (golda > 1 && golda < 6)
GoldID = gold.ItemID + 1;
else if (golda >= 6)
GoldID = gold.ItemID + 2;
if (golda < gold.Amount)
gold.Amount -= golda;
else
gold.Delete();
ledger.Gold += golda;
if (ledger.b_open && golda > 0)
{
m.CloseGump(typeof(GoldLedgerGump));
m.SendGump(new GoldLedgerGump(ledger));
}
if (golda > 0)
{
m.SendMessage(2125, "You deposit {0} gold into your gold ledger.", golda.ToString("#,0"));
if (!m.Mounted)
m.Animate(32, 5, 1, true, false, 0);
Effects.SendMovingEffect(gold, m, GoldID, 5, 50, true, false);
m.PlaySound(0x2E6);
}
}
}
}
}
}