public static bool SellResource(TradeAdvisor trader, PlayerMobile buyer, CraftResource r, int amount) { if(trader.Government == null || trader.Government.Deleted) return false; if (trader.Government.TradeInformation == null) return false; if (!CanDoBusiness(trader.Government, buyer)) { trader.Say("I cannot do business with you."); return false; } #region Amount Checking if (trader.Government.Resources[GetType(r)] < 1) { trader.Say("I have no " + GetType(r).ToString() + " in stock."); return false; } else if (amount / GetDivisor(r) > trader.Government.Resources[GetType(r)]) { trader.Say("I only have " + trader.Government.Resources[GetType(r)] + " units of " + GetType(r).ToString() + " in stock."); return false; } else if (amount < GetDivisor(r)) { trader.Say("You must purchase at least " + GetDivisor(r).ToString() + " " + GetString(r) + "."); return false; } else if (r != CraftResource.Gold && amount % GetDivisor(r) > 0) { trader.Say(r.ToString() + " is handled in units of " + GetDivisor(r).ToString() + "."); return false; } #endregion if (CustomGuildStone.IsGuildEconomic(buyer, trader.Government)) { Item res = (Item)Activator.CreateInstance(GetResourceObject(r), amount); buyer.AddToBackpack(res); trader.Say("Of course you may freely access " + trader.Government.Name + "'s resources."); trader.Government.Resources[GetType(r)] -= (int)(amount / GetDivisor(r)); return true; } else { if (trader.Government.Resources[GetType(r)] - (amount / GetDivisor(r)) < GetMinimum(r, trader.Government)) { trader.Say("I have been ordered not to go below " + GetMinimum(r, trader.Government).ToString() + " units of " + GetType(r).ToString() + " in my stock."); return false; } else if (buyer.Backpack.GetAmount(typeof(Copper)) < ((amount / GetDivisor(r)) * GetSellPrice(r, trader.Government))) { trader.Say("You don't have enough coin to buy " + (amount / GetDivisor(r)) + " units of " + GetType(r).ToString() + "."); return false; } else if (buyer.Backpack.ConsumeTotal(typeof(Copper), ((int)(amount / GetDivisor(r)) * GetSellPrice(r, trader.Government)))) { #region Successful Sale of Resources to a Player switch (Utility.Random(3)) { case 0: buyer.PlaySound(0x2E5); break; case 1: buyer.PlaySound(0x2E6); break; case 2: buyer.PlaySound(0x2E7); break; } Item res = (Item)Activator.CreateInstance(GetResourceObject(r), amount); buyer.AddToBackpack(res); trader.Government.Resources[GetType(r)] -= (int)(amount / GetDivisor(r)); return true; #endregion } else { trader.Say("You do not have enough copper coins."); return false; } } }
public static bool BuyResource(TradeAdvisor trader, PlayerMobile seller, CraftResource r, int amount) { if (!CanDoBusiness(trader.Government, seller)) { trader.Say("I cannot do business with you."); return false; } int itemCount = 0; foreach (Item i in seller.Backpack.Items) { if (i.GetType() == GetResourceObject(r)) itemCount += i.Amount; } if (itemCount <= 0) { trader.Say("You do not have any " + GetString(r)); return false; } else if (itemCount < amount) amount = itemCount; if (amount < GetDivisor(r)) { trader.Say("You must have " + GetDivisor(r).ToString() + " " + GetString(r) + " to make a sale; you only have " + amount.ToString() + " " + GetString(r) + "."); return false; } else if (amount / GetDivisor(r) < 1) { trader.Say(amount.ToString() + " " + GetString(r) + " is not enough to make a sale."); return false; } else if (r != CraftResource.Gold && amount % GetDivisor(r) > 0) { trader.Say(GetString(r) + " is handled in units of " + GetDivisor(r).ToString() + "."); return false; } else if ((trader.Government.GetTreasuryBalance() - ((amount / GetDivisor(r)) * GetBuyPrice(r, trader.Government))) < trader.Government.TradeInformation.BudgetMinimum) { trader.Say("I've been ordered to buy for no more than " + trader.Government.TradeInformation.BudgetMinimum.ToString() + " copper."); return false; } else if ((amount / GetDivisor(r)) * GetBuyPrice(r, trader.Government) > trader.Government.GetTreasuryBalance()) { trader.Say("We've not enough in our treasury to make that purchase."); return false; } switch (Utility.Random(3)) { case 0: seller.PlaySound(0x2E4); break; case 1: seller.PlaySound(0x2E5); break; case 2: seller.PlaySound(0x2E6); break; } seller.Backpack.ConsumeTotal(GetResourceObject(r), amount); trader.Government.Resources[GetType(r)] += (int)(amount / GetDivisor(r)); int giveCopper = (int)((amount / GetDivisor(r)) * GetBuyPrice(r, trader.Government)); if (giveCopper > 60000) { while (giveCopper > 60000) { seller.Backpack.AddItem(new Copper(trader.Government.WithdrawFromTreasury(giveCopper / 2))); giveCopper -= (giveCopper / 2); } if (giveCopper > 0) seller.Backpack.AddItem(new Copper(trader.Government.WithdrawFromTreasury(giveCopper))); } else seller.Backpack.AddItem(new Copper(trader.Government.WithdrawFromTreasury(giveCopper))); return true; }
public static bool DonateResource(TradeAdvisor trader, PlayerMobile giver, CraftResource r, int amount) { if (!CanDoBusiness(trader.Government, giver)) { trader.Say("I cannot do business with you."); return false; } int itemCount = 0; foreach (Item i in giver.Backpack.Items) { if (i.GetType() == GetResourceObject(r)) itemCount += i.Amount; } if (itemCount < amount) { amount = itemCount; } if (amount / GetDivisor(r) < 1) { trader.Say("You don't have enough " + GetString(r) + " to make a donation."); return false; } else if (amount < GetDivisor(r)) { trader.Say("You must have " + GetDivisor(r).ToString() + " to make a donation."); return false; } else if (r != CraftResource.Gold && (amount % GetDivisor(r)) > 0) { trader.Say(GetString(r).ToUpper() + " is handled in units of " + GetDivisor(r).ToString() + "."); return false; } giver.Backpack.ConsumeTotal(GetResourceObject(r), amount); trader.Government.Resources[GetType(r)] += (int)(amount / GetDivisor(r)); trader.Say(trader.Government.Name + " thanks you for your generosity."); return true; }