Overwrite
Complete Overwrite of the Folder with the free shard. ServUO 57.3 has been added.
This commit is contained in:
@@ -0,0 +1,212 @@
|
||||
using System;
|
||||
using Server;
|
||||
using Server.Items;
|
||||
using Server.Mobiles;
|
||||
|
||||
namespace Server.Engines.NewMagincia
|
||||
{
|
||||
public abstract class BaseBazaarBroker : BaseCreature
|
||||
{
|
||||
private MaginciaBazaarPlot m_Plot;
|
||||
private int m_BankBalance;
|
||||
private DateTime m_NextFee;
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public MaginciaBazaarPlot Plot { get { return m_Plot; } set { m_Plot = value; } }
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public int BankBalance { get { return m_BankBalance; } set { m_BankBalance = value; } }
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public bool SendToWarehouse
|
||||
{
|
||||
get { return false; }
|
||||
set
|
||||
{
|
||||
Delete();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual int ComissionFee { get { return MaginciaBazaar.DefaultComissionFee; } }
|
||||
|
||||
public override bool IsInvulnerable { get { return true; } }
|
||||
|
||||
public BaseBazaarBroker(MaginciaBazaarPlot plot) : base(AIType.AI_Vendor, FightMode.None, 2, 1, 0.5, 2)
|
||||
{
|
||||
m_Plot = plot;
|
||||
m_BankBalance = 0;
|
||||
m_NextFee = DateTime.UtcNow + TimeSpan.FromHours(23);
|
||||
InitBody();
|
||||
InitOutfit();
|
||||
|
||||
Blessed = true;
|
||||
CantWalk = true;
|
||||
Direction = Direction.East;
|
||||
}
|
||||
|
||||
public virtual void InitOutfit()
|
||||
{
|
||||
switch (Utility.Random(3))
|
||||
{
|
||||
case 0: EquipItem(new FancyShirt(GetRandomHue())); break;
|
||||
case 1: EquipItem(new Doublet(GetRandomHue())); break;
|
||||
case 2: EquipItem(new Shirt(GetRandomHue())); break;
|
||||
}
|
||||
|
||||
switch (Utility.Random(4))
|
||||
{
|
||||
case 0: EquipItem(new Shoes()); break;
|
||||
case 1: EquipItem(new Boots()); break;
|
||||
case 2: EquipItem(new Sandals()); break;
|
||||
case 3: EquipItem(new ThighBoots()); break;
|
||||
}
|
||||
|
||||
if (Female)
|
||||
{
|
||||
switch (Utility.Random(6))
|
||||
{
|
||||
case 0: EquipItem(new ShortPants(GetRandomHue())); break;
|
||||
case 1:
|
||||
case 2: EquipItem(new Kilt(GetRandomHue())); break;
|
||||
case 3:
|
||||
case 4:
|
||||
case 5: EquipItem(new Skirt(GetRandomHue())); break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (Utility.Random(2))
|
||||
{
|
||||
case 0: EquipItem(new LongPants(GetRandomHue())); break;
|
||||
case 1: EquipItem(new ShortPants(GetRandomHue())); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void InitBody()
|
||||
{
|
||||
InitStats( 100, 100, 25 );
|
||||
|
||||
SpeechHue = Utility.RandomDyedHue();
|
||||
Hue = Utility.RandomSkinHue();
|
||||
|
||||
if ( IsInvulnerable && !Core.AOS )
|
||||
NameHue = 0x35;
|
||||
|
||||
if ( Female = Utility.RandomBool() )
|
||||
{
|
||||
Body = 0x191;
|
||||
Name = NameList.RandomName( "female" );
|
||||
}
|
||||
else
|
||||
{
|
||||
Body = 0x190;
|
||||
Name = NameList.RandomName( "male" );
|
||||
}
|
||||
|
||||
Hue = Race.RandomSkinHue();
|
||||
|
||||
HairItemID = Race.RandomHair(Female);
|
||||
HairHue = Race.RandomHairHue();
|
||||
|
||||
FacialHairItemID = Race.RandomFacialHair(Female);
|
||||
if (FacialHairItemID != 0)
|
||||
FacialHairHue = Race.RandomHairHue();
|
||||
else
|
||||
FacialHairHue = 0;
|
||||
}
|
||||
|
||||
public virtual int GetRandomHue()
|
||||
{
|
||||
switch ( Utility.Random( 5 ) )
|
||||
{
|
||||
default:
|
||||
case 0: return Utility.RandomBlueHue();
|
||||
case 1: return Utility.RandomGreenHue();
|
||||
case 2: return Utility.RandomRedHue();
|
||||
case 3: return Utility.RandomYellowHue();
|
||||
case 4: return Utility.RandomNeutralHue();
|
||||
}
|
||||
}
|
||||
|
||||
public void Dismiss()
|
||||
{
|
||||
Delete();
|
||||
}
|
||||
|
||||
public abstract bool HasValidEntry(Mobile m);
|
||||
|
||||
public override void Delete()
|
||||
{
|
||||
if(m_Plot != null && MaginciaBazaar.Instance != null)
|
||||
MaginciaBazaar.Instance.AddInventoryToWarehouse(m_Plot.Owner, this);
|
||||
|
||||
m_Plot.Merchant = null;
|
||||
|
||||
base.Delete();
|
||||
}
|
||||
|
||||
public virtual void OnTick()
|
||||
{
|
||||
if(m_NextFee < DateTime.UtcNow)
|
||||
{
|
||||
m_BankBalance -= GetWeeklyFee() / 7;
|
||||
|
||||
m_NextFee = DateTime.UtcNow + TimeSpan.FromHours(23);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual int GetWeeklyFee()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void TryWithdrawFunds(Mobile from, int amount)
|
||||
{
|
||||
if(m_BankBalance < amount || !Banker.Deposit(from, amount))
|
||||
from.SendLocalizedMessage(1150214); // Transfer of funds from the broker to your bank box failed. Please check the amount to transfer is available in the broker's account, and make sure your bank box is able to hold the new funds without becoming overloaded.
|
||||
else
|
||||
{
|
||||
m_BankBalance -= amount;
|
||||
from.SendMessage("You withdraw {0}gp to your broker.", amount);
|
||||
from.PlaySound(0x37);
|
||||
}
|
||||
}
|
||||
|
||||
public void TryDepositFunds(Mobile from, int amount)
|
||||
{
|
||||
if(Banker.Withdraw(from, amount))
|
||||
{
|
||||
m_BankBalance += amount;
|
||||
from.SendMessage("You deposit {0}gp to your brokers account.", amount);
|
||||
from.PlaySound(0x37);
|
||||
}
|
||||
else
|
||||
{
|
||||
from.SendLocalizedMessage(1150215); // You have entered an invalid value, or a non-numeric value. Please try again.ase deposit the necessary funds into your bank box and try again.
|
||||
}
|
||||
}
|
||||
|
||||
public BaseBazaarBroker(Serial serial) : base(serial)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Serialize(GenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write((int)0);
|
||||
|
||||
writer.Write(m_BankBalance);
|
||||
writer.Write(m_NextFee);
|
||||
}
|
||||
|
||||
public override void Deserialize(GenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
int version = reader.ReadInt();
|
||||
|
||||
m_BankBalance = reader.ReadInt();
|
||||
m_NextFee = reader.ReadDateTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,392 @@
|
||||
using System;
|
||||
using Server;
|
||||
using Server.Items;
|
||||
using Server.Mobiles;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Server.Engines.NewMagincia
|
||||
{
|
||||
public class CommodityBroker : BaseBazaarBroker
|
||||
{
|
||||
private List<CommodityBrokerEntry> m_CommodityEntries = new List<CommodityBrokerEntry>();
|
||||
public List<CommodityBrokerEntry> CommodityEntries { get { return m_CommodityEntries; } }
|
||||
|
||||
public static readonly int MaxEntries = 50;
|
||||
|
||||
public CommodityBroker(MaginciaBazaarPlot plot) : base(plot)
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnDoubleClick(Mobile from)
|
||||
{
|
||||
if(from.InRange(this.Location, 4) && Plot != null)
|
||||
{
|
||||
if(Plot.Owner == from)
|
||||
{
|
||||
from.CloseGump(typeof(CommodityBrokerGump));
|
||||
from.SendGump(new CommodityBrokerGump(this, from));
|
||||
}
|
||||
else
|
||||
{
|
||||
from.CloseGump(typeof(CommodityInventoryGump));
|
||||
from.SendGump(new CommodityInventoryGump(this));
|
||||
}
|
||||
}
|
||||
else
|
||||
base.OnDoubleClick(from);
|
||||
}
|
||||
|
||||
public override int GetWeeklyFee()
|
||||
{
|
||||
int total = 0;
|
||||
|
||||
foreach(CommodityBrokerEntry entry in m_CommodityEntries)
|
||||
{
|
||||
if(entry.SellPricePer > 0)
|
||||
total += entry.Stock * entry.SellPricePer;
|
||||
}
|
||||
|
||||
double perc = (double)total * .05;
|
||||
return (int)perc;
|
||||
}
|
||||
|
||||
public bool TryAddBrokerEntry(Item item, Mobile from)
|
||||
{
|
||||
Item realItem = item;
|
||||
|
||||
if (item is CommodityDeed)
|
||||
realItem = ((CommodityDeed)item).Commodity;
|
||||
|
||||
Type type = realItem.GetType();
|
||||
int amount = realItem.Amount;
|
||||
|
||||
if(HasType(type))
|
||||
return false;
|
||||
|
||||
CommodityBrokerEntry entry = new CommodityBrokerEntry(realItem, this, amount);
|
||||
m_CommodityEntries.Add(entry);
|
||||
|
||||
if(amount > 0)
|
||||
from.SendLocalizedMessage(1150220, String.Format("{0}\t#{1}\t{2}", amount.ToString(), entry.Label, Plot.ShopName == null ? "an unnamed shop" : Plot.ShopName)); // You have added ~1_QUANTITY~ units of ~2_ITEMNAME~ to the inventory of "~3_SHOPNAME~"
|
||||
|
||||
item.Delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void RemoveEntry(Mobile from, CommodityBrokerEntry entry)
|
||||
{
|
||||
if(m_CommodityEntries.Contains(entry))
|
||||
{
|
||||
if(entry.Stock > 0)
|
||||
WithdrawInventory(from, GetStock(entry), entry);
|
||||
m_CommodityEntries.Remove(entry);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool HasValidEntry(Mobile m)
|
||||
{
|
||||
foreach (CommodityBrokerEntry entry in m_CommodityEntries)
|
||||
{
|
||||
if (entry.Stock > 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void AddInventory(Mobile from, Item item)
|
||||
{
|
||||
Type type = item.GetType();
|
||||
int amountToAdd = item.Amount;
|
||||
|
||||
if(item is CommodityDeed)
|
||||
{
|
||||
type = ((CommodityDeed)item).Commodity.GetType();
|
||||
amountToAdd = ((CommodityDeed)item).Commodity.Amount;
|
||||
}
|
||||
|
||||
foreach(CommodityBrokerEntry entry in m_CommodityEntries)
|
||||
{
|
||||
if(entry.CommodityType == type)
|
||||
{
|
||||
entry.Stock += amountToAdd;
|
||||
item.Delete();
|
||||
|
||||
if(from != null && Plot.Owner == from)
|
||||
from.SendLocalizedMessage(1150220, String.Format("{0}\t#{1}\t{2}", amountToAdd.ToString(), entry.Label, Plot.ShopName == null ? "an unnamed shop" : Plot.ShopName)); // You have added ~1_QUANTITY~ units of ~2_ITEMNAME~ to the inventory of "~3_SHOPNAME~"
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool HasType(Type type)
|
||||
{
|
||||
foreach(CommodityBrokerEntry entry in m_CommodityEntries)
|
||||
{
|
||||
if(entry.CommodityType == type)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public int GetStock(CommodityBrokerEntry entry)
|
||||
{
|
||||
return entry.Stock;
|
||||
}
|
||||
|
||||
public void WithdrawInventory(Mobile from, int amount, CommodityBrokerEntry entry)
|
||||
{
|
||||
if(from == null || Plot == null || entry == null || !m_CommodityEntries.Contains(entry))
|
||||
return;
|
||||
|
||||
Container pack = from.Backpack;
|
||||
|
||||
if(pack != null)
|
||||
{
|
||||
while(amount > 60000)
|
||||
{
|
||||
CommodityDeed deed = new CommodityDeed();
|
||||
Item item = Loot.Construct(entry.CommodityType);
|
||||
item.Amount = 60000;
|
||||
deed.SetCommodity(item);
|
||||
pack.DropItem(deed);
|
||||
amount -= 60000;
|
||||
entry.Stock -= 60000;
|
||||
}
|
||||
|
||||
CommodityDeed deed2 = new CommodityDeed();
|
||||
Item newitem = Loot.Construct(entry.CommodityType);
|
||||
newitem.Amount = amount;
|
||||
deed2.SetCommodity(newitem);
|
||||
pack.DropItem(deed2);
|
||||
entry.Stock -= amount;
|
||||
}
|
||||
|
||||
if(Plot != null && from == Plot.Owner)
|
||||
from.SendLocalizedMessage(1150221, String.Format("{0}\t#{1}\t{2}", amount.ToString(), entry.Label, Plot.ShopName != null ? Plot.ShopName : "a shop with no name")); // You have removed ~1_QUANTITY~ units of ~2_ITEMNAME~ from the inventory of "~3_SHOPNAME~"
|
||||
}
|
||||
|
||||
public int GetBuyCost(Mobile from, CommodityBrokerEntry entry, int amount)
|
||||
{
|
||||
int totalCost = entry.SellPricePer * amount;
|
||||
int toDeduct = totalCost + (int)((double)totalCost * ((double)ComissionFee / 100.0));
|
||||
|
||||
return toDeduct;
|
||||
}
|
||||
|
||||
// Called when a player BUYS the commodity from teh broker...this is fucking confusing
|
||||
public void TryBuyCommodity(Mobile from, CommodityBrokerEntry entry, int amount)
|
||||
{
|
||||
int totalCost = entry.SellPricePer * amount;
|
||||
int toAdd = totalCost + (int)((double)totalCost * ((double)ComissionFee / 100.0));
|
||||
|
||||
if (Banker.Withdraw(from, totalCost, true))
|
||||
{
|
||||
from.SendLocalizedMessage(1150643, String.Format("{0}\t#{1}", amount.ToString("###,###,###"), entry.Label)); // A commodity deed worth ~1_AMOUNT~ ~2_ITEM~ has been placed in your backpack.
|
||||
WithdrawInventory(from, amount, entry);
|
||||
BankBalance += toAdd;
|
||||
}
|
||||
else
|
||||
{
|
||||
from.SendLocalizedMessage(1150252); // You do not have the funds needed to make this trade available in your bank box. Brokers are only able to transfer funds from your bank box. Please deposit the necessary funds into your bank box and try again.
|
||||
}
|
||||
}
|
||||
|
||||
public bool SellCommodityControl(Mobile from, CommodityBrokerEntry entry, int amount)
|
||||
{
|
||||
int totalCost = entry.BuyPricePer * amount;
|
||||
Type type = entry.CommodityType;
|
||||
|
||||
if (from.Backpack != null)
|
||||
{
|
||||
int total = amount;
|
||||
int typeAmount = from.Backpack.GetAmount(type);
|
||||
int commodityAmount = GetCommodityType(from.Backpack, type);
|
||||
|
||||
if (typeAmount + commodityAmount >= total)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Called when a player SELLs the commodity from teh broker...this is fucking confusing
|
||||
public void TrySellCommodity(Mobile from, CommodityBrokerEntry entry, int amount)
|
||||
{
|
||||
int totalCost = entry.BuyPricePer * amount;
|
||||
Type type = entry.CommodityType;
|
||||
|
||||
if(BankBalance < totalCost)
|
||||
{
|
||||
//No message, this should have already been handled elsewhere
|
||||
}
|
||||
else if(from.Backpack != null)
|
||||
{
|
||||
int total = amount;
|
||||
int typeAmount = from.Backpack.GetAmount(type);
|
||||
int commodityAmount = GetCommodityType(from.Backpack, type);
|
||||
|
||||
if(typeAmount + commodityAmount < total)
|
||||
from.SendLocalizedMessage(1150667); // You do not have the requested amount of that commodity (either in item or deed form) in your backpack to trade. Note that commodities cannot be traded from your bank box.
|
||||
else if(Banker.Deposit(from, totalCost))
|
||||
{
|
||||
TakeItems(from.Backpack, type, ref total);
|
||||
|
||||
if(total > 0)
|
||||
TakeCommodities(from.Backpack, type, ref total);
|
||||
|
||||
BankBalance -= totalCost + (int)((double)totalCost * ((double)ComissionFee / 100.0));
|
||||
from.SendLocalizedMessage(1150668, String.Format("{0}\t#{1}", amount.ToString(), entry.Label)); // You have sold ~1_QUANTITY~ units of ~2_COMMODITY~ to the broker. These have been transferred from deeds and/or items in your backpack.
|
||||
}
|
||||
else
|
||||
from.SendLocalizedMessage(1150265); // Your bank box cannot hold the proceeds from this transaction.
|
||||
}
|
||||
}
|
||||
|
||||
private void TakeCommodities(Container c, Type type, ref int amount)
|
||||
{
|
||||
if (c == null)
|
||||
return;
|
||||
|
||||
Item[] items = c.FindItemsByType(typeof(CommodityDeed));
|
||||
List<Item> toSell = new List<Item>();
|
||||
|
||||
foreach(Item item in items)
|
||||
{
|
||||
CommodityDeed commodityDeed = item as CommodityDeed;
|
||||
|
||||
if (commodityDeed != null && commodityDeed.Commodity != null && commodityDeed.Commodity.GetType() == type)
|
||||
{
|
||||
Item commodity = commodityDeed.Commodity;
|
||||
|
||||
if (commodity.Amount <= amount)
|
||||
{
|
||||
toSell.Add(item);
|
||||
amount -= commodity.Amount;
|
||||
}
|
||||
else
|
||||
{
|
||||
CommodityDeed newDeed = new CommodityDeed();
|
||||
Item newItem = Loot.Construct(type);
|
||||
newItem.Amount = amount;
|
||||
newDeed.SetCommodity(newItem);
|
||||
|
||||
commodity.Amount -= amount;
|
||||
commodityDeed.InvalidateProperties();
|
||||
toSell.Add(newDeed);
|
||||
amount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach(Item item in toSell)
|
||||
{
|
||||
AddInventory(null, item);
|
||||
}
|
||||
}
|
||||
|
||||
private void TakeItems(Container c, Type type, ref int amount)
|
||||
{
|
||||
if (c == null)
|
||||
return;
|
||||
|
||||
Item[] items = c.FindItemsByType(type);
|
||||
List<Item> toSell = new List<Item>();
|
||||
|
||||
foreach(Item item in items)
|
||||
{
|
||||
if(amount <= 0)
|
||||
break;
|
||||
|
||||
if(item.Amount <= amount)
|
||||
{
|
||||
toSell.Add(item);
|
||||
amount -= item.Amount;
|
||||
}
|
||||
else
|
||||
{
|
||||
Item newItem = Loot.Construct(type);
|
||||
newItem.Amount = amount;
|
||||
item.Amount -= amount;
|
||||
toSell.Add(newItem);
|
||||
amount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
foreach(Item item in toSell)
|
||||
{
|
||||
AddInventory(null, item);
|
||||
}
|
||||
}
|
||||
|
||||
public int GetCommodityType(Container c, Type type)
|
||||
{
|
||||
if (c == null)
|
||||
return 0;
|
||||
|
||||
Item[] items = c.FindItemsByType(typeof(CommodityDeed));
|
||||
int amt = 0;
|
||||
|
||||
foreach (Item item in items)
|
||||
{
|
||||
if (item is CommodityDeed && ((CommodityDeed)item).Commodity != null && ((CommodityDeed)item).Commodity.GetType() == type)
|
||||
amt += ((CommodityDeed)item).Commodity.Amount;
|
||||
}
|
||||
|
||||
return amt;
|
||||
}
|
||||
|
||||
public int GetLabelID(CommodityBrokerEntry entry)
|
||||
{
|
||||
/*Item[] items = BuyPack.FindItemsByType(typeof(CommodityDeed));
|
||||
|
||||
foreach(Item item in items)
|
||||
{
|
||||
if(item is CommodityDeed)
|
||||
{
|
||||
CommodityDeed deed = (CommodityDeed)item;
|
||||
|
||||
if(deed.Commodity != null && deed.Commodity.GetType() == entry.CommodityType)
|
||||
return deed.Commodity.ItemID;
|
||||
}
|
||||
}
|
||||
|
||||
Item item = Loot.Construct(entry.CommodityType);
|
||||
int id = 0;
|
||||
|
||||
if(item != null)
|
||||
{
|
||||
id = item.ItemID;
|
||||
item.Delete();
|
||||
}*/
|
||||
|
||||
return entry != null ? entry.Label : 1;
|
||||
}
|
||||
|
||||
public CommodityBroker(Serial serial) : base(serial)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Serialize(GenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write((int)0);
|
||||
|
||||
writer.Write(m_CommodityEntries.Count);
|
||||
foreach(CommodityBrokerEntry entry in m_CommodityEntries)
|
||||
entry.Serialize(writer);
|
||||
}
|
||||
|
||||
public override void Deserialize(GenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
int version = reader.ReadInt();
|
||||
|
||||
int count = reader.ReadInt();
|
||||
for(int i = 0; i < count; i++)
|
||||
m_CommodityEntries.Add(new CommodityBrokerEntry(reader));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,276 @@
|
||||
using System;
|
||||
using Server;
|
||||
using Server.Items;
|
||||
using Server.Mobiles;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Server.Engines.NewMagincia
|
||||
{
|
||||
public class PetBroker : BaseBazaarBroker
|
||||
{
|
||||
private List<PetBrokerEntry> m_BrokerEntries = new List<PetBrokerEntry>();
|
||||
public List<PetBrokerEntry> BrokerEntries { get { return m_BrokerEntries; } }
|
||||
|
||||
public static readonly int MaxEntries = 10;
|
||||
|
||||
public PetBroker(MaginciaBazaarPlot plot) : base(plot)
|
||||
{
|
||||
FollowersMax = 500;
|
||||
}
|
||||
|
||||
public override void OnDoubleClick(Mobile from)
|
||||
{
|
||||
if(from.InRange(this.Location, 4) && Plot != null)
|
||||
{
|
||||
if(Plot.Owner == from)
|
||||
{
|
||||
from.CloseGump(typeof(PetBrokerGump));
|
||||
from.SendGump(new PetBrokerGump(this, from));
|
||||
}
|
||||
else
|
||||
{
|
||||
from.CloseGump(typeof(PetInventoryGump));
|
||||
from.SendGump(new PetInventoryGump(this, from));
|
||||
}
|
||||
}
|
||||
else
|
||||
base.OnDoubleClick(from);
|
||||
}
|
||||
|
||||
public bool TryAddEntry(BaseCreature bc, Mobile from, int cost)
|
||||
{
|
||||
if(bc == null || HasEntry(bc) || !bc.Alive || !bc.IsStabled)
|
||||
from.SendLocalizedMessage(1150342); // That pet is not in the stables. The pet must remain in the stables in order to be transferred to the broker's inventory.
|
||||
else if(m_BrokerEntries.Count >= MaxEntries)
|
||||
from.SendLocalizedMessage(1150631); // You cannot add more pets to this animal broker's inventory at this time, because the shop inventory is full.
|
||||
else if (!from.Stabled.Contains(bc))
|
||||
from.SendLocalizedMessage(1150344); // Transferring the pet from the stables to the animal broker's inventory failed for an unknown reason.
|
||||
else
|
||||
{
|
||||
m_BrokerEntries.Add(new PetBrokerEntry(bc, cost));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void RemoveEntry(PetBrokerEntry entry)
|
||||
{
|
||||
if (m_BrokerEntries.Contains(entry))
|
||||
{
|
||||
m_BrokerEntries.Remove(entry);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool HasValidEntry(Mobile m)
|
||||
{
|
||||
var hasValid = false;
|
||||
|
||||
foreach (PetBrokerEntry entry in m_BrokerEntries)
|
||||
{
|
||||
if (entry.Pet != null)
|
||||
{
|
||||
if (m.Stabled.Count < AnimalTrainer.GetMaxStabled(m))
|
||||
{
|
||||
SendToStables(m, entry.Pet);
|
||||
}
|
||||
else
|
||||
{
|
||||
hasValid = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return hasValid;
|
||||
}
|
||||
|
||||
public bool HasEntry(BaseCreature bc)
|
||||
{
|
||||
foreach(PetBrokerEntry entry in m_BrokerEntries)
|
||||
{
|
||||
if(entry.Pet == bc)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void CheckInventory()
|
||||
{
|
||||
List<PetBrokerEntry> entries = new List<PetBrokerEntry>(m_BrokerEntries);
|
||||
|
||||
foreach(PetBrokerEntry entry in entries)
|
||||
{
|
||||
if (entry.Pet == null || entry.Pet.Deleted)
|
||||
m_BrokerEntries.Remove(entry);
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetWeeklyFee()
|
||||
{
|
||||
int total = 0;
|
||||
|
||||
foreach(PetBrokerEntry entry in m_BrokerEntries)
|
||||
{
|
||||
if(entry.SalePrice > 0)
|
||||
total += entry.SalePrice;
|
||||
}
|
||||
|
||||
double perc = (double)total * .05;
|
||||
return (int)perc;
|
||||
}
|
||||
|
||||
public int TryBuyPet(Mobile from, PetBrokerEntry entry)
|
||||
{
|
||||
if (from == null || entry == null || entry.Pet == null)
|
||||
{
|
||||
return 1150377; // Unable to complete the desired transaction at this time.
|
||||
}
|
||||
|
||||
int cost = entry.SalePrice;
|
||||
int toAdd = cost - (int)((double)cost * ((double)ComissionFee / 100.0));
|
||||
BaseCreature pet = entry.Pet;
|
||||
|
||||
if (!m_BrokerEntries.Contains(entry) || entry.Pet == null || entry.Pet.Deleted)
|
||||
{
|
||||
return 1150377; // Unable to complete the desired transaction at this time.
|
||||
}
|
||||
else if (pet.GetControlChance(from) <= 0.0)
|
||||
{
|
||||
return 1150379; // Unable to transfer that pet to you because you have no chance at all of controlling it.
|
||||
}
|
||||
else if (from.Stabled.Count >= AnimalTrainer.GetMaxStabled(from))
|
||||
{
|
||||
return 1150376; // You do not have any available stable slots. The Animal Broker can only transfer pets to your stables. Please make a stables slot available and try again.
|
||||
}
|
||||
else if (!Banker.Withdraw(from, cost, true))
|
||||
{
|
||||
return 1150252; // You do not have the funds needed to make this trade available in your bank box. Brokers are only able to transfer funds from your bank box. Please deposit the necessary funds into your bank box and try again.
|
||||
}
|
||||
else
|
||||
{
|
||||
BankBalance += toAdd;
|
||||
pet.IsBonded = false;
|
||||
|
||||
SendToStables(from, pet);
|
||||
|
||||
from.SendLocalizedMessage(1150380, String.Format("{0}\t{1}", entry.TypeName, pet.Name)); // You have purchased ~1_TYPE~ named "~2_NAME~". The animal is now in the stables and you may retrieve it there.
|
||||
m_BrokerEntries.Remove(entry);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SendToStables(Mobile to, BaseCreature pet)
|
||||
{
|
||||
EndViewTimer(pet);
|
||||
|
||||
pet.Blessed = false;
|
||||
pet.ControlTarget = null;
|
||||
pet.ControlOrder = OrderType.Stay;
|
||||
pet.Internalize();
|
||||
pet.SetControlMaster(null);
|
||||
pet.SummonMaster = null;
|
||||
pet.IsStabled = true;
|
||||
pet.Loyalty = BaseCreature.MaxLoyalty;
|
||||
to.Stabled.Add(pet);
|
||||
}
|
||||
|
||||
public static void SendToBrokerStables(BaseCreature pet)
|
||||
{
|
||||
if (pet is BaseMount)
|
||||
((BaseMount)pet).Rider = null;
|
||||
|
||||
pet.ControlTarget = null;
|
||||
pet.ControlOrder = OrderType.Stay;
|
||||
pet.Internalize();
|
||||
|
||||
pet.SetControlMaster(null);
|
||||
pet.SummonMaster = null;
|
||||
|
||||
pet.IsStabled = true;
|
||||
pet.Loyalty = BaseCreature.MaxLoyalty;
|
||||
|
||||
pet.Home = Point3D.Zero;
|
||||
pet.RangeHome = 10;
|
||||
pet.Blessed = false;
|
||||
|
||||
EndViewTimer(pet);
|
||||
}
|
||||
|
||||
private static Dictionary<BaseCreature, Timer> m_ViewTimer = new Dictionary<BaseCreature, Timer>();
|
||||
|
||||
public static void AddToViewTimer(BaseCreature bc)
|
||||
{
|
||||
if(m_ViewTimer.ContainsKey(bc))
|
||||
{
|
||||
if(m_ViewTimer[bc] != null)
|
||||
m_ViewTimer[bc].Stop();
|
||||
}
|
||||
|
||||
m_ViewTimer[bc] = new InternalTimer(bc);
|
||||
m_ViewTimer[bc].Start();
|
||||
}
|
||||
|
||||
public static void EndViewTimer(BaseCreature bc)
|
||||
{
|
||||
if(m_ViewTimer.ContainsKey(bc))
|
||||
{
|
||||
if(m_ViewTimer[bc] != null)
|
||||
m_ViewTimer[bc].Stop();
|
||||
|
||||
m_ViewTimer.Remove(bc);
|
||||
}
|
||||
}
|
||||
|
||||
private class InternalTimer : Timer
|
||||
{
|
||||
BaseCreature m_Creature;
|
||||
|
||||
public InternalTimer(BaseCreature bc) : base(TimeSpan.FromMinutes(2), TimeSpan.FromMinutes(2))
|
||||
{
|
||||
m_Creature = bc;
|
||||
Priority = TimerPriority.OneMinute;
|
||||
}
|
||||
|
||||
protected override void OnTick()
|
||||
{
|
||||
PetBroker.SendToBrokerStables(m_Creature);
|
||||
}
|
||||
}
|
||||
|
||||
public PetBroker(Serial serial) : base(serial)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Serialize(GenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write((int)0);
|
||||
|
||||
writer.Write(m_BrokerEntries.Count);
|
||||
foreach(PetBrokerEntry entry in m_BrokerEntries)
|
||||
entry.Serialize(writer);
|
||||
}
|
||||
|
||||
public override void Deserialize(GenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
int version = reader.ReadInt();
|
||||
|
||||
int count = reader.ReadInt();
|
||||
for(int i = 0; i < count; i++)
|
||||
m_BrokerEntries.Add(new PetBrokerEntry(reader));
|
||||
|
||||
Timer.DelayCall(TimeSpan.FromSeconds(10), () =>
|
||||
{
|
||||
foreach (var entry in m_BrokerEntries)
|
||||
{
|
||||
if (entry.Pet != null && !entry.Pet.IsStabled)
|
||||
{
|
||||
AddToViewTimer(entry.Pet);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,316 @@
|
||||
using System;
|
||||
using Server;
|
||||
using Server.Items;
|
||||
using Server.Mobiles;
|
||||
using Server.Gumps;
|
||||
using Server.Network;
|
||||
using System.Collections.Generic;
|
||||
using Server.ContextMenus;
|
||||
using Server.Prompts;
|
||||
|
||||
namespace Server.Engines.NewMagincia
|
||||
{
|
||||
public class WarehouseSuperintendent : BaseCreature
|
||||
{
|
||||
public override bool IsInvulnerable { get { return true; } }
|
||||
|
||||
[Constructable]
|
||||
public WarehouseSuperintendent() : base(AIType.AI_Vendor, FightMode.None, 2, 1, 0.5, 2)
|
||||
{
|
||||
Race = Race.Human;
|
||||
Blessed = true;
|
||||
Title = "The Warehouse Superintendent";
|
||||
|
||||
if(Utility.RandomBool())
|
||||
{
|
||||
Female = true;
|
||||
Body = 0x191;
|
||||
Name = NameList.RandomName( "female" );
|
||||
|
||||
AddItem(new Skirt(Utility.RandomPinkHue()));
|
||||
}
|
||||
else
|
||||
{
|
||||
Female = false;
|
||||
Body = 0x190;
|
||||
Name = NameList.RandomName( "male" );
|
||||
AddItem(new ShortPants(Utility.RandomBlueHue()));
|
||||
}
|
||||
|
||||
AddItem(new Tunic(Utility.RandomBlueHue()));
|
||||
AddItem(new Boots());
|
||||
|
||||
Utility.AssignRandomHair(this, Utility.RandomHairHue());
|
||||
Utility.AssignRandomFacialHair(this, Utility.RandomHairHue());
|
||||
|
||||
Hue = Race.RandomSkinHue();
|
||||
}
|
||||
|
||||
/*public override void OnDoubleClick(Mobile from)
|
||||
{
|
||||
if(from.InRange(this.Location, 3) && from.Backpack != null)
|
||||
{
|
||||
WarehouseContainer container = MaginciaBazaar.ClaimContainer(from);
|
||||
|
||||
if(container != null)
|
||||
TryTransferItems(from, container);
|
||||
}
|
||||
}*/
|
||||
|
||||
public void TryTransfer(Mobile from, StorageEntry entry)
|
||||
{
|
||||
if (entry == null)
|
||||
return;
|
||||
|
||||
int fees = entry.Funds;
|
||||
|
||||
if (fees < 0)
|
||||
{
|
||||
int owed = fees * -1;
|
||||
SayTo(from, String.Format("It looks like you owe {0}gp as back fees. How much would you like to pay now?", owed.ToString("###,###,###")));
|
||||
from.Prompt = new BackfeePrompt(this, entry);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!TryPayFunds(from, entry))
|
||||
{
|
||||
from.SendGump(new BazaarInformationGump(1150681, 1150678)); // Some personal possessions that were equipped on the broker still remain in storage, because your backpack cannot hold them. Please free up space in your backpack and return to claim these items.
|
||||
return;
|
||||
}
|
||||
|
||||
if (entry.Creatures.Count > 0)
|
||||
{
|
||||
List<BaseCreature> list = new List<BaseCreature>(entry.Creatures);
|
||||
|
||||
foreach (BaseCreature bc in list)
|
||||
{
|
||||
if (from.Stabled.Count < AnimalTrainer.GetMaxStabled(from))
|
||||
{
|
||||
bc.Blessed = false;
|
||||
bc.ControlOrder = OrderType.Stay;
|
||||
bc.Internalize();
|
||||
bc.IsStabled = true;
|
||||
bc.Loyalty = BaseCreature.MaxLoyalty; // Wonderfully happy
|
||||
from.Stabled.Add(bc);
|
||||
bc.SetControlMaster(null);
|
||||
bc.SummonMaster = null;
|
||||
|
||||
entry.RemovePet(bc);
|
||||
}
|
||||
else
|
||||
{
|
||||
from.SendGump(new BazaarInformationGump(1150681, 1150678)); // Some personal possessions that were equipped on the broker still remain in storage, because your backpack cannot hold them. Please free up space in your backpack and return to claim these items.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ColUtility.Free(list);
|
||||
}
|
||||
|
||||
if (entry.CommodityTypes.Count > 0)
|
||||
{
|
||||
Dictionary<Type, int> copy = new Dictionary<Type, int>(entry.CommodityTypes);
|
||||
|
||||
foreach (KeyValuePair<Type, int> commodities in copy)
|
||||
{
|
||||
Type type = commodities.Key;
|
||||
int amt = commodities.Value;
|
||||
|
||||
if (!GiveItems(from, type, amt, entry))
|
||||
{
|
||||
from.SendGump(new BazaarInformationGump(1150681, 1150678)); // Some personal possessions that were equipped on the broker still remain in storage, because your backpack cannot hold them. Please free up space in your backpack and return to claim these items.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
copy.Clear();
|
||||
}
|
||||
|
||||
entry.CommodityTypes.Clear();
|
||||
ColUtility.Free(entry.Creatures);
|
||||
|
||||
from.SendGump(new BazaarInformationGump(1150681, 1150677)); // There are no longer any items or funds in storage for your former bazaar stall. Thank you for your diligence in recovering your possessions.
|
||||
MaginciaBazaar.RemoveFromStorage(from);
|
||||
}
|
||||
|
||||
private bool GiveItems(Mobile from, Type type, int amt, StorageEntry entry)
|
||||
{
|
||||
int amount = amt;
|
||||
|
||||
while (amount > 60000)
|
||||
{
|
||||
CommodityDeed deed = new CommodityDeed();
|
||||
Item item = Loot.Construct(type);
|
||||
item.Amount = 60000;
|
||||
deed.SetCommodity(item);
|
||||
amount -= 60000;
|
||||
|
||||
if (from.Backpack == null || !from.Backpack.TryDropItem(from, deed, false))
|
||||
{
|
||||
deed.Delete();
|
||||
return false;
|
||||
}
|
||||
else
|
||||
entry.RemoveCommodity(type, 60000);
|
||||
}
|
||||
|
||||
CommodityDeed deed2 = new CommodityDeed();
|
||||
Item item2 = Loot.Construct(type);
|
||||
item2.Amount = amount;
|
||||
deed2.SetCommodity(item2);
|
||||
|
||||
if (from.Backpack == null || !from.Backpack.TryDropItem(from, deed2, false))
|
||||
{
|
||||
deed2.Delete();
|
||||
return false;
|
||||
}
|
||||
else
|
||||
entry.RemoveCommodity(type, amount);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool TryPayFunds(Mobile from, StorageEntry entry)
|
||||
{
|
||||
int amount = entry.Funds;
|
||||
|
||||
if (Banker.Withdraw(from, amount, true))
|
||||
{
|
||||
entry.Funds = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void TryPayBackfee(Mobile from, string text, StorageEntry entry)
|
||||
{
|
||||
int amount = Utility.ToInt32(text);
|
||||
int owed = entry.Funds * -1;
|
||||
|
||||
if (amount > 0)
|
||||
{
|
||||
int toDeduct = Math.Min(owed, amount);
|
||||
|
||||
if (Banker.Withdraw(from, toDeduct))
|
||||
{
|
||||
entry.Funds += toDeduct;
|
||||
int newAmount = entry.Funds;
|
||||
|
||||
if (newAmount >= 0)
|
||||
{
|
||||
TryTransfer(from, entry);
|
||||
}
|
||||
else
|
||||
{
|
||||
SayTo(from, String.Format("Thank you! You have a remaining balance of {0}gp as backfees!", newAmount * -1));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SayTo(from, "You don't have enough funds in your bankbox to support that amount.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class BackfeePrompt : Prompt
|
||||
{
|
||||
private WarehouseSuperintendent m_Mobile;
|
||||
private StorageEntry m_Entry;
|
||||
|
||||
public BackfeePrompt(WarehouseSuperintendent mobile, StorageEntry entry)
|
||||
{
|
||||
m_Mobile = mobile;
|
||||
m_Entry = entry; ;
|
||||
}
|
||||
|
||||
public override void OnResponse( Mobile from, string text )
|
||||
{
|
||||
m_Mobile.TryPayBackfee(from, text, m_Entry);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*private bool TransferItems(Mobile from, WarehouseContainer c)
|
||||
{
|
||||
List<Item> items = new List<Item>(c.Items);
|
||||
|
||||
foreach(Item item in items)
|
||||
{
|
||||
from.Backpack.TryDropItem(from, item, false);
|
||||
}
|
||||
|
||||
return c.Items.Count == 0;
|
||||
}*/
|
||||
|
||||
public override void GetContextMenuEntries( Mobile from, List<ContextMenuEntry> list )
|
||||
{
|
||||
base.GetContextMenuEntries(from, list);
|
||||
|
||||
list.Add(new ClaimStorageEntry(from, this));
|
||||
list.Add(new ChangeMatchBidEntry(from));
|
||||
}
|
||||
|
||||
private class ClaimStorageEntry : ContextMenuEntry
|
||||
{
|
||||
private WarehouseSuperintendent m_Mobile;
|
||||
private StorageEntry m_Entry;
|
||||
|
||||
public ClaimStorageEntry(Mobile from, WarehouseSuperintendent mobile) : base(1150681, 3)
|
||||
{
|
||||
m_Mobile = mobile;
|
||||
m_Entry = MaginciaBazaar.GetStorageEntry(from);
|
||||
|
||||
if(m_Entry == null)
|
||||
Flags |= CMEFlags.Disabled;
|
||||
}
|
||||
|
||||
public override void OnClick()
|
||||
{
|
||||
Mobile from = Owner.From;
|
||||
|
||||
if (from == null || m_Entry == null)
|
||||
return;
|
||||
|
||||
m_Mobile.TryTransfer(from, m_Entry);
|
||||
}
|
||||
}
|
||||
|
||||
private class ChangeMatchBidEntry : ContextMenuEntry
|
||||
{
|
||||
public ChangeMatchBidEntry(Mobile from) : base(1150587, 3)
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnClick()
|
||||
{
|
||||
Mobile from = Owner.From;
|
||||
|
||||
if(from != null)
|
||||
from.SendGump(new MatchBidGump(from, null));
|
||||
}
|
||||
}
|
||||
|
||||
public WarehouseSuperintendent(Serial serial) : base(serial)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Serialize(GenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write((int)1);
|
||||
}
|
||||
|
||||
public override void Deserialize(GenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
int version = reader.ReadInt();
|
||||
|
||||
if(version == 0)
|
||||
{
|
||||
Hue = Race.RandomSkinHue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user