Overwrite

Complete Overwrite of the Folder with the free shard. ServUO 57.3 has been added.
This commit is contained in:
Unstable Kitsune
2023-11-28 23:20:26 -05:00
parent 3cd54811de
commit b918192e4e
11608 changed files with 2644205 additions and 47 deletions

View File

@@ -0,0 +1,233 @@
using System;
using Server;
using Server.Items;
using Server.Mobiles;
using System.Collections.Generic;
namespace Server.Engines.NewMagincia
{
public class CommodityBrokerEntry
{
private Type m_CommodityType;
private CommodityBroker m_Broker;
private int m_ItemID;
private int m_Label;
private int m_SellPricePer;
private int m_BuyPricePer;
private int m_BuyLimit;
private int m_SellLimit;
private int m_Stock;
public Type CommodityType { get { return m_CommodityType; } }
public CommodityBroker Broker { get { return m_Broker; } }
public int ItemID { get { return m_ItemID; } }
public int Label { get { return m_Label; } }
public int SellPricePer { get { return m_SellPricePer; } set { m_SellPricePer = value; } }
public int BuyPricePer { get { return m_BuyPricePer; } set { m_BuyPricePer = value; } }
public int BuyLimit { get { return m_BuyLimit; } set { m_BuyLimit = value; } }
public int SellLimit { get { return m_SellLimit; } set { m_SellLimit = value; } }
public int Stock { get { return m_Stock; } set { m_Stock = value; } }
public int ActualSellLimit
{
get
{
if (m_Stock < m_SellLimit)
return m_Stock;
return m_SellLimit;
}
}
public int ActualBuyLimit
{
get
{
if (m_Broker != null && m_Broker.BankBalance < m_BuyLimit * m_BuyPricePer && m_BuyPricePer > 0)
return m_Broker.BankBalance / m_BuyPricePer;
int limit = m_BuyLimit - m_Stock;
if (limit <= 0)
return 0;
return limit;
}
}
/* SellPricePer - price per unit the broker is selling to players for
* BuyPricePer - price per unit the borker is buying from players for
* BuyAtLimit - Limit a commodity must go below before it will buy that particular commodity
*
* SellAtLimit - Limit a commodty must go above before it will sell that particular commodity
* BuyLimit - Limit (in units) it will buy from players
* SellLimit - Limit (in units) it will sell to players
*/
public CommodityBrokerEntry (Item item, CommodityBroker broker, int amount)
{
m_CommodityType = item.GetType();
m_ItemID = item.ItemID;
m_Broker = broker;
m_Stock = amount;
if(item is ICommodity)
m_Label = ((ICommodity)item).Description;
else
m_Label = item.LabelNumber;
}
/// <summary>
/// Player buys, the vendor is selling
/// </summary>
/// <param name="amount"></param>
/// <returns></returns>
public bool PlayerCanBuy(int amount)
{
//return (m_SellAtLimit == 0 || m_Stock >= m_SellAtLimit) && m_Stock > 0 && m_SellPricePer > 0 && m_SellLimit < amount;
return (m_SellLimit == 0 || amount <= ActualSellLimit) && m_SellPricePer > 0;
}
/// <summary>
/// Player sells, the vendor is buying
/// </summary>
/// <param name="amount"></param>
/// <returns></returns>
public bool PlayerCanSell(int amount)
{
//(m_BuyAtLimit == 0 || m_Stock <= entry.BuyAtLimit) && m_Stock > 0 && m_BuyPricePer * amount <= m_Broker.BankBalance && m_BuyPricePer > 0 && m_BuyLimit < amount;
return (m_BuyLimit == 0 || amount <= ActualBuyLimit) && m_Stock > 0 && m_BuyPricePer > 0 && m_BuyPricePer <= m_Broker.BankBalance;
}
public CommodityBrokerEntry(GenericReader reader)
{
int version = reader.ReadInt();
m_CommodityType = ScriptCompiler.FindTypeByName(reader.ReadString());
m_Label = reader.ReadInt();
m_Broker = reader.ReadMobile() as CommodityBroker;
m_ItemID = reader.ReadInt();
m_SellPricePer = reader.ReadInt();
m_BuyPricePer = reader.ReadInt();
m_BuyLimit = reader.ReadInt();
m_SellLimit = reader.ReadInt();
m_Stock = reader.ReadInt();
}
public void Serialize(GenericWriter writer)
{
writer.Write((int)0);
writer.Write(m_CommodityType.Name);
writer.Write(m_Label);
writer.Write(m_Broker);
writer.Write(m_ItemID);
writer.Write(m_SellPricePer);
writer.Write(m_BuyPricePer);
writer.Write(m_BuyLimit);
writer.Write(m_SellLimit);
writer.Write(m_Stock);
}
}
public class PetBrokerEntry
{
private BaseCreature m_Pet;
private int m_SalePrice;
private string m_TypeName;
public BaseCreature Pet { get { return m_Pet; } }
public int SalePrice { get { return m_SalePrice; } set { m_SalePrice = value; } }
public string TypeName { get { return m_TypeName; } set { m_TypeName = value; } }
private static Dictionary<Type, string> m_NameBuffer = new Dictionary<Type, string>();
public static Dictionary<Type, string> NameBuffer { get { return m_NameBuffer; } }
public static readonly int DefaultPrice = 1000;
public PetBrokerEntry(BaseCreature pet) : this(pet, DefaultPrice)
{
}
public PetBrokerEntry(BaseCreature pet, int price)
{
m_Pet = pet;
m_SalePrice = price;
m_TypeName = GetOriginalName(pet);
}
public static string GetOriginalName(BaseCreature bc)
{
if(bc == null)
return null;
Type t = bc.GetType();
if(m_NameBuffer.ContainsKey(t))
return m_NameBuffer[t];
BaseCreature c = Activator.CreateInstance(t) as BaseCreature;
if(c != null)
{
c.Delete();
AddToBuffer(t, c.Name);
return c.Name;
}
return t.Name;
}
public static void AddToBuffer(Type type, string s)
{
if(s != null && s.Length > 0 && !m_NameBuffer.ContainsKey(type))
m_NameBuffer[type] = s;
}
public void Internalize()
{
if (m_Pet.Map == Map.Internal)
return;
m_Pet.ControlTarget = null;
m_Pet.ControlOrder = OrderType.Stay;
m_Pet.Internalize();
m_Pet.SetControlMaster(null);
m_Pet.SummonMaster = null;
m_Pet.IsStabled = true;
m_Pet.Loyalty = BaseCreature.MaxLoyalty;
m_Pet.Home = Point3D.Zero;
m_Pet.RangeHome = 10;
m_Pet.Blessed = false;
}
public PetBrokerEntry(GenericReader reader)
{
int version = reader.ReadInt();
m_Pet = reader.ReadMobile() as BaseCreature;
m_SalePrice = reader.ReadInt();
m_TypeName = reader.ReadString();
if (m_Pet != null)
{
AddToBuffer(m_Pet.GetType(), m_TypeName);
m_Pet.IsStabled = true;
Timer.DelayCall(TimeSpan.FromSeconds(10), new TimerCallback(Internalize));
}
}
public void Serialize(GenericWriter writer)
{
writer.Write((int)0);
writer.Write(m_Pet);
writer.Write(m_SalePrice);
writer.Write(m_TypeName);
}
}
}

View File

@@ -0,0 +1,899 @@
using Server;
using System;
using System.Collections.Generic;
using Server.Mobiles;
using Server.Items;
using Server.Accounting;
namespace Server.Engines.NewMagincia
{
public class MaginciaBazaar : Item
{
public static readonly int DefaultComissionFee = 5;
public static TimeSpan GetShortAuctionTime { get { return TimeSpan.FromMinutes(Utility.RandomMinMax(690, 750)); } }
public static TimeSpan GetLongAuctionTime { get { return TimeSpan.FromHours(Utility.RandomMinMax(168, 180)); } }
private static MaginciaBazaar m_Instance;
public static MaginciaBazaar Instance { get { return m_Instance; } set { m_Instance = value; } }
private Timer m_Timer;
private static List<MaginciaBazaarPlot> m_Plots = new List<MaginciaBazaarPlot>();
public static List<MaginciaBazaarPlot> Plots { get { return m_Plots; } }
private static Dictionary<Mobile, BidEntry> m_NextAvailable = new Dictionary<Mobile, BidEntry>();
public static Dictionary<Mobile, BidEntry> NextAvailable { get { return m_NextAvailable; } }
private static Dictionary<Mobile, int> m_Reserve = new Dictionary<Mobile, int>();
public static Dictionary<Mobile, int> Reserve { get { return m_Reserve; } }
private bool m_Enabled;
[CommandProperty(AccessLevel.GameMaster)]
public bool Enabled
{
get { return m_Enabled; }
set
{
if(m_Enabled != value)
{
if(value)
StartTimer();
else
EndTimer();
}
m_Enabled = value;
}
}
/*
* Phase 1 - Stalls A - D (0 - 19)
* Phase 2 - Stalls E - G (20 - 34)
* Phase 3 - Stalls H - J (35 - 49)
*/
public enum Phase
{
Phase1 = 1,
Phase2 = 2,
Phase3 = 3
}
private Phase m_Phase;
[CommandProperty(AccessLevel.GameMaster)]
public Phase PlotPhase
{
get { return m_Phase; }
set
{
if (value > m_Phase)
{
m_Phase = value;
ActivatePlots();
}
}
}
public MaginciaBazaar() : base(3240)
{
Movable = false;
m_Enabled = true;
WarehouseSuperintendent mob = new WarehouseSuperintendent();
mob.MoveToWorld(new Point3D(3795, 2259, 20), Map.Trammel);
mob.Home = mob.Location;
mob.RangeHome = 12;
mob = new WarehouseSuperintendent();
mob.MoveToWorld(new Point3D(3795, 2259, 20), Map.Felucca);
mob.Home = mob.Location;
mob.RangeHome = 12;
LoadPlots();
AddPlotSigns();
if (m_Enabled)
StartTimer();
m_Phase = Phase.Phase1;
ActivatePlots();
}
public static bool IsActivePlot(MaginciaBazaarPlot plot)
{
if (m_Instance != null)
{
int index = m_Plots.IndexOf(plot);
if (index == -1)
return false;
switch ((int)m_Instance.m_Phase)
{
case 1: return index < 40;
case 2: return index < 70;
case 3: return index < 100;
}
}
return false;
}
public void ActivatePlots()
{
for (int i = 0; i < m_Plots.Count; i++)
{
MaginciaBazaarPlot plot = m_Plots[i];
switch ((int)m_Phase)
{
case 1:
if (i < 40 && plot.Auction == null)
{
plot.NewAuction(GetShortAuctionTime);
}
break;
case 2:
if (i < 70 && plot.Auction == null)
{
plot.NewAuction(GetShortAuctionTime);
}
break;
case 3:
if (i < 100 && plot.Auction == null)
{
plot.NewAuction(GetShortAuctionTime);
}
break;
}
if (plot.Sign != null)
plot.Sign.InvalidateProperties();
}
}
public void StartTimer()
{
if (m_Timer != null)
m_Timer.Stop();
m_Timer = Timer.DelayCall(TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1), new TimerCallback(OnTick));
m_Timer.Priority = TimerPriority.OneMinute;
m_Timer.Start();
}
public void EndTimer()
{
if(m_Timer != null)
m_Timer.Stop();
m_Timer = null;
}
public void OnTick()
{
foreach(MaginciaBazaarPlot plot in m_Plots)
{
if (plot.Active)
plot.OnTick();
}
List<Mobile> toRemove = new List<Mobile>();
foreach(KeyValuePair<Mobile, StorageEntry> kvp in m_WarehouseStorage)
{
Mobile m = kvp.Key;
StorageEntry entry = kvp.Value;
if (entry.Expires < DateTime.UtcNow)
{
bool deleted = false;
bool stabled = false;
if (entry.CommodityTypes.Count > 0)
{
deleted = true;
}
foreach (BaseCreature bc in entry.Creatures)
{
if (m.Stabled.Count < AnimalTrainer.GetMaxStabled(m))
{
PetBroker.SendToStables(m, bc);
if (!stabled)
{
stabled = true;
}
}
else
{
if (!deleted)
{
deleted = true;
}
bc.Delete();
}
}
if (stabled)
{
string message;
if (deleted)
{
message = "Your broker inventory and/or funds in storage at the New Magincia Warehouse " +
"have been donated to charity, because these items remained unclaimed for a " +
"full week. These items may no longer be recovered, but the orphans will " +
"appreciate a nice hot meal. One or all of your pets have been placed in your stables.";
}
else
{
message = "Because your pets remained in storage for more than a full week, one or all of them have been placed in your stables. " +
"If you had insufficient room in your stables, any further pets will be lost and returned to the wild.";
}
MaginciaLottoSystem.SendMessageTo(m, new NewMaginciaMessage(new TextDefinition(1150676), message, null));
}
else if (deleted)
{
toRemove.Add(m);
/*Your broker inventory and/or funds in storage at the New Magincia Warehouse
*have been donated to charity, because these items remained unclaimed for a
*full week. These items may no longer be recovered, but the orphans will
*appreciate a nice hot meal.*/
MaginciaLottoSystem.SendMessageTo(m, new NewMaginciaMessage(new TextDefinition(1150676), new TextDefinition(1150673), null));
}
}
}
foreach (Mobile m in toRemove)
{
if (m_WarehouseStorage.ContainsKey(m))
m_WarehouseStorage.Remove(m);
}
ColUtility.Free(toRemove);
}
public void AddPlotSigns()
{
foreach (MaginciaBazaarPlot plot in m_Plots)
{
Point3D loc = new Point3D(plot.PlotDef.SignLoc.X - 1, plot.PlotDef.SignLoc.Y, plot.PlotDef.SignLoc.Z);
Static pole = new Static(2592);
pole.MoveToWorld(loc, plot.PlotDef.Map);
pole = new Static(2969);
pole.MoveToWorld(plot.PlotDef.SignLoc, plot.PlotDef.Map);
plot.AddPlotSign();
}
}
public override void Delete()
{
// Note: This cannot be deleted. That could potentially piss alot of people off who have items and gold invested in a plot.
}
public static MaginciaBazaarPlot GetPlot(Mobile from)
{
foreach(MaginciaBazaarPlot plot in m_Plots)
{
if(plot.IsOwner(from))
return plot;
}
return null;
}
public static bool HasPlot(Mobile from)
{
foreach(MaginciaBazaarPlot plot in m_Plots)
{
if(plot.IsOwner(from))
return true;
}
return false;
}
public static MaginciaBazaarPlot GetBiddingPlot(Mobile from)
{
Account acct = from.Account as Account;
if(acct == null)
return null;
for (int i = 0; i < acct.Length; i++)
{
Mobile m = acct[i];
if (m == null)
continue;
MaginciaBazaarPlot plot = GetBiddingPlotForAccount(m);
if (plot != null)
return plot;
}
return null;
}
public static MaginciaBazaarPlot GetBiddingPlotForAccount(Mobile from)
{
foreach(MaginciaBazaarPlot plot in m_Plots)
{
if(plot.Auction != null && plot.Auction.Auctioners.ContainsKey(from))
return plot;
}
return null;
}
public bool HasActiveBid(Mobile from)
{
return GetBiddingPlot(from) != null || m_NextAvailable.ContainsKey(from);
}
public static bool TryRetractBid(Mobile from)
{
MaginciaBazaarPlot plot = GetBiddingPlot(from);
if(plot != null)
return plot.Auction.RetractBid(from);
return RetractBid(from);
}
public static bool RetractBid(Mobile from)
{
Account acct = from.Account as Account;
for (int i = 0; i < acct.Length; i++)
{
Mobile m = acct[i];
if (m == null)
continue;
if (m_NextAvailable.ContainsKey(m))
{
BidEntry entry = m_NextAvailable[m];
if (entry != null && Banker.Deposit(m, entry.Amount))
{
m_NextAvailable.Remove(m);
return true;
}
}
}
return false;
}
public static bool IsBiddingNextAvailable(Mobile from)
{
return m_NextAvailable.ContainsKey(from);
}
public static int GetNextAvailableBid(Mobile from)
{
if(m_NextAvailable.ContainsKey(from))
return m_NextAvailable[from].Amount;
return 0;
}
public static void MakeBidNextAvailable(Mobile from, int amount)
{
m_NextAvailable[from] = new BidEntry(from, amount, BidType.NextAvailable);
}
public static void RemoveBidNextAvailable(Mobile from)
{
if (m_NextAvailable.ContainsKey(from))
m_NextAvailable.Remove(from);
}
public static void AwardPlot(MaginciaPlotAuction auction, Mobile winner, int highest)
{
MaginciaBazaarPlot plot = auction.Plot;
if(m_NextAvailable.ContainsKey(winner))
m_NextAvailable.Remove(winner);
if (plot != null && plot.Owner != winner)
{
MaginciaBazaarPlot current = GetPlot(winner);
//new owner
if (current == null && winner != plot.Owner)
{
/*You won a lease on Stall ~1_STALLNAME~ at the ~2_FACET~ New Magincia Bazaar.
*Your bid amount of ~3_BIDAMT~gp won the auction and has been remitted. Your
*lease begins immediately and will continue for 7 days.*/
MaginciaLottoSystem.SendMessageTo(winner, new NewMaginciaMessage(null, new TextDefinition(1150426), String.Format("{0}\t{1}\t{2}", plot.PlotDef.ID, plot.PlotDef.Map.ToString(), highest.ToString("###,###,###"))));
}
plot.Reset();
//Transfer to new plot
if (current != null)
{
/*You won a lease and moved to Stall ~1_STALLNAME~ at the ~2_FACET~ New Magincia
*Bazaar. The lease on your previous stall has been terminated. Your hired
*merchant, if any, has relocated your stall and goods to the new lot. Your
*bid amount of ~3_BIDAMT~gp has been remitted.*/
MaginciaLottoSystem.SendMessageTo(winner, new NewMaginciaMessage(null, new TextDefinition(1150428), String.Format("{0}\t{1}\t{2}", plot.PlotDef.ID, plot.PlotDef.Map, highest.ToString("###,###,###"))));
plot.PlotMulti = current.PlotMulti;
plot.Merchant = current.Merchant;
plot.ShopName = current.ShopName;
current.PlotMulti = null;
current.Merchant = null;
current.Owner = null;
if(current.Auction != null)
current.Auction.EndAuction();
}
plot.Owner = winner;
plot.NewAuction(GetLongAuctionTime);
}
else if(plot != null)
{
if (plot.Owner != null)
plot.NewAuction(GetLongAuctionTime);
else
{
plot.Reset();
plot.NewAuction(GetShortAuctionTime);
}
}
}
public static void RegisterPlot(PlotDef plotDef)
{
m_Plots.Add(new MaginciaBazaarPlot(plotDef));
}
public static bool IsSameAccount(Mobile check, Mobile checkAgainst)
{
return IsSameAccount(check, checkAgainst, false);
}
public static bool IsSameAccount(Mobile check, Mobile checkAgainst, bool checkLink)
{
if(check == null || checkAgainst == null)
return false;
Account acct1 = checkAgainst.Account as Account;
Account acct2 = check.Account as Account;
if(acct1 != null && acct1 == acct2)
return true;
return false;
}
#region Bizaar Authority Storage
private static Dictionary<Mobile, StorageEntry> m_WarehouseStorage = new Dictionary<Mobile, StorageEntry>();
public void AddInventoryToWarehouse(Mobile owner, BaseBazaarBroker broker)
{
StorageEntry entry = GetStorageEntry(owner);
if (entry == null)
{
if (broker.HasValidEntry(owner))
{
entry = new StorageEntry(owner, broker);
}
}
else if (broker.HasValidEntry(owner))
{
entry.AddInventory(owner, broker);
}
if (entry != null)
{
m_WarehouseStorage[owner] = entry;
/*Your hired broker has transferred any remaining inventory and funds from
*your stall at the New Magincia Bazaar into storage at the New Magincia
*Warehouse. You must reclaim these items or they will be destroyed! To reclaim
*these items, see the Warehouse Superintendent in New Magincia.<br><br>This
*service is provided free of charge. If you owed your broker any back fees,
*those fees must be paid before you can reclaim your belongings. The storage
*period lasts 7 days starting with the expiration of your lease at the New
*Magincia Bazaar, and this storage period cannot be extended. Claim your
*possessions and gold without delay!<br><br>The expiration time of this
*message coincides with the expiration time of your Warehouse storage.*/
MaginciaLottoSystem.SendMessageTo(owner, new NewMaginciaMessage(1150676, new TextDefinition(1150674), null));
}
}
public static StorageEntry GetStorageEntry(Mobile from)
{
if (m_WarehouseStorage.ContainsKey(from))
return m_WarehouseStorage[from];
return null;
}
public static void RemoveFromStorage(Mobile from)
{
if (m_WarehouseStorage.ContainsKey(from))
{
m_WarehouseStorage.Remove(from);
}
}
public static void AddToReserve(Mobile from, int amount)
{
foreach(Mobile m in m_Reserve.Keys)
{
if(from == m || IsSameAccount(from, m))
{
m_Reserve[m] += amount;
return;
}
}
m_Reserve[from] = amount;
}
public static void DeductReserve(Mobile from, int amount)
{
foreach(Mobile m in m_Reserve.Keys)
{
if(from == m || IsSameAccount(from, m))
{
m_Reserve[m] -= amount;
if(m_Reserve[m] <= 0)
m_Reserve.Remove(m);
return;
}
}
}
public static int GetBidMatching(Mobile from)
{
foreach(Mobile m in m_Reserve.Keys)
{
if(from == m || IsSameAccount(m, from))
return m_Reserve[m];
}
return 0;
}
#endregion
public MaginciaBazaar(Serial serial) : base(serial)
{
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write((int)0);
writer.Write(m_Enabled);
writer.Write((int)m_Phase);
writer.Write(m_Plots.Count);
for(int i = 0; i < m_Plots.Count; i++)
{
m_Plots[i].Serialize(writer);
}
writer.Write(m_NextAvailable.Count);
foreach(KeyValuePair<Mobile, BidEntry> kvp in m_NextAvailable)
{
writer.Write(kvp.Key);
kvp.Value.Serialize(writer);
}
writer.Write(m_WarehouseStorage.Count);
foreach (KeyValuePair<Mobile, StorageEntry> kvp in m_WarehouseStorage)
{
writer.Write(kvp.Key);
kvp.Value.Serialize(writer);
}
writer.Write(m_Reserve.Count);
foreach (KeyValuePair<Mobile, int> kvp in m_Reserve)
{
writer.Write(kvp.Key);
writer.Write(kvp.Value);
}
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
m_Enabled = reader.ReadBool();
m_Phase = (Phase)reader.ReadInt();
int count = reader.ReadInt();
for(int i = 0; i < count; i++)
{
m_Plots.Add(new MaginciaBazaarPlot(reader));
}
count = reader.ReadInt();
for(int i = 0; i < count; i++)
{
Mobile m = reader.ReadMobile();
BidEntry entry = new BidEntry(reader);
if(m != null)
m_NextAvailable[m] = entry;
}
count = reader.ReadInt();
for (int i = 0; i < count; i++)
{
Mobile m = reader.ReadMobile();
StorageEntry entry = new StorageEntry(reader);
if (m != null)
m_WarehouseStorage[m] = entry;
}
count = reader.ReadInt();
for (int i = 0; i < count; i++)
{
Mobile m = reader.ReadMobile();
int amt = reader.ReadInt();
if (m != null && amt > 0)
m_Reserve[m] = amt;
}
m_Instance = this;
if (m_Enabled)
StartTimer();
}
public static void LoadPlots()
{
int idx = 0;
RegisterPlot(new PlotDef("A-1", m_StallLocs[idx], 0));
RegisterPlot(new PlotDef("A-1", m_StallLocs[idx], 1));
idx++;
RegisterPlot(new PlotDef("A-2", m_StallLocs[idx], 0));
RegisterPlot(new PlotDef("A-2", m_StallLocs[idx], 1));
idx++;
RegisterPlot(new PlotDef("A-3", m_StallLocs[idx], 0));
RegisterPlot(new PlotDef("A-3", m_StallLocs[idx], 1));
idx++;
RegisterPlot(new PlotDef("A-4", m_StallLocs[idx], 0));
RegisterPlot(new PlotDef("A-4", m_StallLocs[idx], 1));
idx++;
RegisterPlot(new PlotDef("B-1", m_StallLocs[idx], 0));
RegisterPlot(new PlotDef("B-1", m_StallLocs[idx], 1));
idx++;
RegisterPlot(new PlotDef("B-2", m_StallLocs[idx], 0));
RegisterPlot(new PlotDef("B-2", m_StallLocs[idx], 1));
idx++;
RegisterPlot(new PlotDef("B-3", m_StallLocs[idx], 0));
RegisterPlot(new PlotDef("B-3", m_StallLocs[idx], 1));
idx++;
RegisterPlot(new PlotDef("B-4", m_StallLocs[idx], 0));
RegisterPlot(new PlotDef("B-4", m_StallLocs[idx], 1));
idx++;
RegisterPlot(new PlotDef("B-5", m_StallLocs[idx], 0));
RegisterPlot(new PlotDef("B-5", m_StallLocs[idx], 1));
idx++;
RegisterPlot(new PlotDef("B-6", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("B-6", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("C-1", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("C-1", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("C-2", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("C-2", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("C-3", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("C-3", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("C-4", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("C-4", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("C-5", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("C-5", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("D-1", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("D-1", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("D-2", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("D-2", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("D-3", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("D-3", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("D-4", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("D-4", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("D-5", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("D-5", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("E-1", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("E-1", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("E-2", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("E-2", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("E-3", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("E-3", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("E-4", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("E-4", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("E-5", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("E-5", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("F-1", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("F-1", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("F-2", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("F-2", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("F-3", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("F-3", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("F-4", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("F-4", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("F-5", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("F-5", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("G-1", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("G-1", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("G-2", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("G-2", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("G-3", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("G-3", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("G-4", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("G-4", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("G-5", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("G-5", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("H-1", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("H-1", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("H-2", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("H-2", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("H-3", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("H-3", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("H-4", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("H-4", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("H-5", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("H-5", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("H-6", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("H-6", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("I-1", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("I-1", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("I-2", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("I-2", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("I-3", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("I-3", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("I-4", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("I-4", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("I-5", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("I-5", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("J-1", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("J-1", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("J-2", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("J-2", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("J-3", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("J-3", m_StallLocs[idx], 0));
idx++;
RegisterPlot(new PlotDef("J-4", m_StallLocs[idx], 1));
RegisterPlot(new PlotDef("J-4", m_StallLocs[idx], 0));
}
private static Point3D[] m_StallLocs = new Point3D[]
{
//A
new Point3D(3716, 2198, 20),
new Point3D(3709, 2198, 20),
new Point3D(3700, 2192, 20),
new Point3D(3693, 2192, 20),
//B
new Point3D(3686, 2192, 20),
new Point3D(3686, 2198, 20),
new Point3D(3686, 2204, 20),
new Point3D(3686, 2210, 20),
new Point3D(3686, 2216, 20),
new Point3D(3686, 2222, 20),
//C
new Point3D(3686, 2228, 20),
new Point3D(3692, 2228, 20),
new Point3D(3698, 2228, 20),
new Point3D(3704, 2228, 20),
new Point3D(3710, 2228, 20),
//D
new Point3D(3716, 2228, 20),
new Point3D(3716, 2222, 20),
new Point3D(3716, 2216, 20),
new Point3D(3716, 2210, 20),
new Point3D(3716, 2204, 20),
//E
new Point3D(3686, 2178, 20),
new Point3D(3686, 2171, 20),
new Point3D(3686, 2164, 20),
new Point3D(3686, 2157, 20),
new Point3D(3686, 2150, 20),
//F
new Point3D(3693, 2178, 20),
new Point3D(3693, 2171, 20),
new Point3D(3693, 2164, 20),
new Point3D(3693, 2157, 20),
new Point3D(3693, 2150, 20),
//G
new Point3D(3700, 2178, 20),
new Point3D(3700, 2171, 20),
new Point3D(3700, 2164, 20),
new Point3D(3700, 2157, 20),
new Point3D(3700, 2150, 20),
//H
new Point3D(3672, 2238, 20),
new Point3D(3665, 2238, 20),
new Point3D(3658, 2238, 20),
new Point3D(3672, 2245, 20),
new Point3D(3665, 2245, 20),
new Point3D(3658, 2245, 20),
//I
new Point3D(3730, 2249, 20),
new Point3D(3730, 2242, 20),
new Point3D(3737, 2242, 20),
new Point3D(3737, 2249, 20),
new Point3D(3737, 2256, 20),
//J
new Point3D(3730, 2220, 20),
new Point3D(3737, 2220, 20),
new Point3D(3730, 2228, 20),
new Point3D(3737, 2228, 20),
};
}
}

View File

@@ -0,0 +1,441 @@
using Server;
using System;
using Server.Items;
using Server.Mobiles;
using Server.Accounting;
namespace Server.Engines.NewMagincia
{
[PropertyObject]
public class MaginciaBazaarPlot
{
private PlotDef m_Definition;
private Mobile m_Owner;
private string m_ShopName;
private BaseBazaarMulti m_PlotMulti;
private BaseBazaarBroker m_Merchant;
private PlotSign m_Sign;
private MaginciaPlotAuction m_Auction;
[CommandProperty(AccessLevel.GameMaster)]
public PlotDef PlotDef { get { return m_Definition; } set { } }
[CommandProperty(AccessLevel.GameMaster)]
public Mobile Owner { get { return m_Owner; } set { m_Owner = value; } }
[CommandProperty(AccessLevel.GameMaster)]
public string ShopName { get { return m_ShopName; } set { m_ShopName = value; } }
[CommandProperty(AccessLevel.GameMaster)]
public BaseBazaarMulti PlotMulti
{
get { return m_PlotMulti; }
set
{
if (m_PlotMulti != null && m_PlotMulti != value && value != null)
{
m_PlotMulti.Delete();
m_PlotMulti = null;
}
m_PlotMulti = value;
if(m_PlotMulti != null)
m_PlotMulti.MoveToWorld(m_Definition.MultiLocation, m_Definition.Map);
}
}
[CommandProperty(AccessLevel.GameMaster)]
public BaseBazaarBroker Merchant
{
get { return m_Merchant; }
set
{
m_Merchant = value;
if(m_Merchant != null)
{
m_Merchant.Plot = this;
Point3D p = m_Definition.Location;
p.X++;
p.Y++;
p.Z = 27;
if (m_PlotMulti != null && m_PlotMulti.Fillers.Count > 0)
{
p = m_PlotMulti.Fillers[0].Location;
p.Z = m_PlotMulti.Fillers[0].Z + TileData.ItemTable[m_PlotMulti.Fillers[0].ItemID & TileData.MaxItemValue].CalcHeight;
}
m_Merchant.MoveToWorld(p, m_Definition.Map);
}
}
}
[CommandProperty(AccessLevel.GameMaster)]
public PlotSign Sign { get { return m_Sign; } set { m_Sign = value; } }
[CommandProperty(AccessLevel.GameMaster)]
public MaginciaPlotAuction Auction
{
get
{
/*if(m_Auction == null)
{
TimeSpan ts;
if(m_Owner == null)
ts = MaginciaBazaar.GetLongAuctionTime;
else
ts = MaginciaBazaar.GetShortAuctionTime;
m_Auction = new MaginciaPlotAuction(this, ts);
}*/
return m_Auction;
}
set { m_Auction = value; }
}
[CommandProperty(AccessLevel.GameMaster)]
public bool Active { get { return MaginciaBazaar.IsActivePlot(this); } }
[CommandProperty(AccessLevel.GameMaster)]
public DateTime AuctionEnds
{
get
{
if (Auction == null)
return DateTime.MinValue;
return Auction.AuctionEnd;
}
}
public MaginciaBazaarPlot(PlotDef definition)
{
m_Definition = definition;
m_Owner = null;
m_PlotMulti = null;
m_Merchant = null;
m_ShopName = null;
}
public bool IsOwner(Mobile from)
{
if(from == null || m_Owner == null)
return false;
if(from == m_Owner)
return true;
Account acct1 = from.Account as Account;
Account acct2 = m_Owner.Account as Account;
return acct1 != null && acct2 != null && acct1 == acct2;
}
public void AddPlotSign()
{
m_Sign = new PlotSign(this);
m_Sign.MoveToWorld(m_Definition.SignLoc, m_Definition.Map);
}
public void Reset()
{
if(m_PlotMulti != null)
Timer.DelayCall(TimeSpan.FromMinutes(2), new TimerCallback(DeleteMulti_Callback));
EndTempMultiTimer();
if(m_Merchant != null)
m_Merchant.Dismiss();
m_Owner = null;
m_ShopName = null;
m_Merchant = null;
m_ShopName = null;
}
public void NewAuction(TimeSpan time)
{
m_Auction = new MaginciaPlotAuction(this, time);
if (m_Sign != null)
m_Sign.InvalidateProperties();
}
private void DeleteMulti_Callback()
{
if (m_PlotMulti != null)
m_PlotMulti.Delete();
m_PlotMulti = null;
}
public void OnTick()
{
if (m_Auction != null)
m_Auction.OnTick();
if(m_Merchant != null)
m_Merchant.OnTick();
if (m_Sign != null)
m_Sign.InvalidateProperties();
}
#region Stall Style Multis
private Timer m_Timer;
public void AddTempMulti(int idx1, int idx2)
{
if (m_PlotMulti != null)
{
m_PlotMulti.Delete();
m_PlotMulti = null;
}
BaseBazaarMulti multi = null;
if (idx1 == 0)
{
switch (idx2)
{
case 0: multi = new CommodityStyle1(); break;
case 1: multi = new CommodityStyle2(); break;
case 2: multi = new CommodityStyle3(); break;
}
}
else
{
switch (idx2)
{
case 0: multi = new PetStyle1(); break;
case 1: multi = new PetStyle2(); break;
case 2: multi = new PetStyle3(); break;
}
}
if (multi != null)
{
PlotMulti = multi;
BeginTempMultiTimer();
}
}
public void ConfirmMulti(bool commodity)
{
EndTempMultiTimer();
if(commodity)
Merchant = new CommodityBroker(this);
else
Merchant = new PetBroker(this);
}
public void RemoveTempPlot()
{
EndTempMultiTimer();
if (m_PlotMulti != null)
{
m_PlotMulti.Delete();
m_PlotMulti = null;
}
}
public void BeginTempMultiTimer()
{
if(m_Timer != null)
{
m_Timer.Stop();
m_Timer = null;
}
m_Timer = new InternalTimer(this);
m_Timer.Start();
}
public void EndTempMultiTimer()
{
if(m_Timer != null)
{
m_Timer.Stop();
m_Timer = null;
}
}
public bool HasTempMulti()
{
return m_Timer != null;
}
private class InternalTimer : Timer
{
private MaginciaBazaarPlot m_Plot;
public InternalTimer(MaginciaBazaarPlot plot) : base(TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1))
{
m_Plot = plot;
}
protected override void OnTick()
{
if(m_Plot != null)
m_Plot.RemoveTempPlot();
}
}
#endregion
public override string ToString()
{
return "...";
}
public bool TrySetShopName(Mobile from, string text)
{
if (text == null || !Server.Guilds.BaseGuildGump.CheckProfanity(text) || text.Length == 0 || text.Length > 40)
return false;
m_ShopName = text;
if(m_Merchant != null)
m_Merchant.InvalidateProperties();
if(m_Sign != null)
m_Sign.InvalidateProperties();
from.SendLocalizedMessage(1150333); // Your shop has been renamed.
return true;
}
public void FireBroker()
{
if(m_Merchant != null)
{
m_Merchant.Delete();
m_Merchant = null;
if (m_PlotMulti != null)
{
m_PlotMulti.Delete();
m_PlotMulti = null;
}
}
}
public void Abandon()
{
Reset();
if (m_Auction != null)
m_Auction.ChangeAuctionTime(MaginciaBazaar.GetShortAuctionTime);
}
public int GetBid(Mobile from)
{
if (m_Auction != null && m_Auction.Auctioners.ContainsKey(from))
return m_Auction.Auctioners[from].Amount;
return 0;
}
public void Serialize(GenericWriter writer)
{
writer.Write((int)0);
m_Definition.Serialize(writer);
writer.Write(m_Owner);
writer.Write(m_ShopName);
writer.Write(m_Merchant);
writer.Write(m_Sign);
writer.Write(m_PlotMulti);
if(m_Auction != null)
{
writer.Write((bool)true);
m_Auction.Serialize(writer);
}
else
writer.Write((bool)false);
}
public MaginciaBazaarPlot(GenericReader reader)
{
int version = reader.ReadInt();
m_Definition = new PlotDef(reader);
m_Owner = reader.ReadMobile();
m_ShopName = reader.ReadString();
m_Merchant = reader.ReadMobile() as BaseBazaarBroker;
m_Sign = reader.ReadItem() as PlotSign;
m_PlotMulti = reader.ReadItem() as BaseBazaarMulti;
if(reader.ReadBool())
m_Auction = new MaginciaPlotAuction(reader, this);
if(m_Merchant != null)
m_Merchant.Plot = this;
if (m_Sign != null)
m_Sign.Plot = this;
}
}
[PropertyObject]
public class PlotDef
{
private string m_ID;
private Point3D m_Location;
private Map m_Map;
[CommandProperty(AccessLevel.GameMaster)]
public string ID { get { return m_ID; } set { m_ID = value; } }
[CommandProperty(AccessLevel.GameMaster)]
public Point3D Location { get { return m_Location; } set { m_Location = value; } }
[CommandProperty(AccessLevel.GameMaster)]
public Map Map { get { return m_Map; } }
[CommandProperty(AccessLevel.GameMaster)]
public Point3D SignLoc { get { return new Point3D(m_Location.X + 1, m_Location.Y - 2, m_Location.Z); } }
[CommandProperty(AccessLevel.GameMaster)]
public Point3D MultiLocation { get { return new Point3D(m_Location.X, m_Location.Y, m_Location.Z + 2); } }
public PlotDef(string id, Point3D pnt, int mapID)
{
m_ID = id;
m_Location = pnt;
m_Map = Server.Map.Maps[mapID];
}
public override string ToString()
{
return "...";
}
public PlotDef(GenericReader reader)
{
int version = reader.ReadInt();
m_ID = reader.ReadString();
m_Location = reader.ReadPoint3D();
m_Map = reader.ReadMap();
}
public void Serialize(GenericWriter writer)
{
writer.Write((int)0);
writer.Write(m_ID);
writer.Write(m_Location);
writer.Write(m_Map);
}
}
}

View File

@@ -0,0 +1,347 @@
using Server;
using System;
using System.Collections.Generic;
using Server.Items;
using Server.Mobiles;
using Server.Accounting;
namespace Server.Engines.NewMagincia
{
[PropertyObject]
public class MaginciaPlotAuction
{
private Dictionary<Mobile, BidEntry> m_Auctioners = new Dictionary<Mobile, BidEntry>();
public Dictionary<Mobile, BidEntry> Auctioners { get { return m_Auctioners; } }
private MaginciaBazaarPlot m_Plot;
private DateTime m_AuctionEnd;
[CommandProperty(AccessLevel.GameMaster)]
public MaginciaBazaarPlot Plot { get { return m_Plot; } }
[CommandProperty(AccessLevel.GameMaster)]
public DateTime AuctionEnd { get { return m_AuctionEnd; } }
[CommandProperty(AccessLevel.GameMaster)]
public bool EndCurrentAuction
{
get { return false; }
set
{
EndAuction();
}
}
public MaginciaPlotAuction(MaginciaBazaarPlot plot) : this(plot, MaginciaBazaar.GetShortAuctionTime)
{
}
public MaginciaPlotAuction(MaginciaBazaarPlot plot, TimeSpan auctionDuration)
{
m_Plot = plot;
m_AuctionEnd = DateTime.UtcNow + auctionDuration;
}
public override string ToString()
{
return "...";
}
public void MakeBid(Mobile bidder, int amount)
{
m_Auctioners[bidder] = new BidEntry(bidder, amount, BidType.Specific);
}
public bool RetractBid(Mobile from)
{
Account acct = from.Account as Account;
for (int i = 0; i < acct.Length; i++)
{
Mobile m = acct[i];
if (m == null)
continue;
if (m_Auctioners.ContainsKey(m))
{
BidEntry entry = m_Auctioners[m];
if (entry != null && Banker.Deposit(m, entry.Amount))
{
m_Auctioners.Remove(m);
return true;
}
}
}
return false;
}
public void RemoveBid(Mobile from)
{
if (m_Auctioners.ContainsKey(from))
m_Auctioners.Remove(from);
}
public int GetHighestBid()
{
int highest = -1;
foreach(BidEntry entry in m_Auctioners.Values)
{
if(entry.Amount >= highest)
highest = entry.Amount;
}
return highest;
}
public void OnTick()
{
if(m_AuctionEnd < DateTime.UtcNow)
EndAuction();
}
public void EndAuction()
{
if (m_Plot == null)
return;
if (m_Plot.HasTempMulti())
m_Plot.RemoveTempPlot();
Mobile winner = null;
int highest = 0;
Dictionary<Mobile, BidEntry> combined = new Dictionary<Mobile, BidEntry>(m_Auctioners);
//Combine auction bids with the bids for next available plot
foreach(KeyValuePair<Mobile, BidEntry> kvp in MaginciaBazaar.NextAvailable)
combined.Add(kvp.Key, kvp.Value);
//Get highest bid
foreach(BidEntry entry in combined.Values)
{
if(entry.Amount > highest)
highest = entry.Amount;
}
// Check for owner, and if the owner has a match bad AND hasn't bidded on another plot!
if(m_Plot.Owner != null && MaginciaBazaar.Reserve.ContainsKey(m_Plot.Owner) && MaginciaBazaar.Instance != null && !MaginciaBazaar.Instance.HasActiveBid(m_Plot.Owner))
{
int matching = MaginciaBazaar.GetBidMatching(m_Plot.Owner);
if(matching >= highest)
{
MaginciaBazaar.DeductReserve(m_Plot.Owner, highest);
int newreserve = MaginciaBazaar.GetBidMatching(m_Plot.Owner);
winner = m_Plot.Owner;
/*You extended your lease on Stall ~1_STALLNAME~ at the ~2_FACET~ New Magincia
*Bazaar. You matched the top bid of ~3_BIDAMT~gp. That amount has been deducted
*from your Match Bid of ~4_MATCHAMT~gp. Your Match Bid balance is now
*~5_NEWMATCH~gp. You may reclaim any additional match bid funds or adjust
*your match bid for next week at the bazaar.*/
MaginciaLottoSystem.SendMessageTo(m_Plot.Owner, new NewMaginciaMessage(null, new TextDefinition(1150427), String.Format("@{0}@{1}@{2}@{3}@{4}", m_Plot.PlotDef.ID, m_Plot.PlotDef.Map.ToString(), highest.ToString("N0"), matching.ToString("N0"), newreserve.ToString("N0"))));
}
else
{
/*You lost the bid to extend your lease on Stall ~1_STALLNAME~ at the ~2_FACET~
*New Magincia Bazaar. Your match bid amount of ~3_BIDAMT~gp is held in escrow
*at the Bazaar. You may obtain a full refund there at any time. Your hired
*merchant, if any, has deposited your proceeds and remaining inventory at the
*Warehouse in New Magincia. You must retrieve these within one week or they
*will be destroyed.*/
MaginciaLottoSystem.SendMessageTo(m_Plot.Owner, new NewMaginciaMessage(null, new TextDefinition(1150528), String.Format("@{0}@{1}@{2}", m_Plot.PlotDef.ID, m_Plot.PlotDef.Map.ToString(), matching.ToString("N0"))));
}
}
else if (m_Plot.Owner != null)
{
/*Your lease has expired on Stall ~1_STALLNAME~ at the ~2_FACET~ New Magincia Bazaar.*/
MaginciaLottoSystem.SendMessageTo(m_Plot.Owner, new NewMaginciaMessage(null, new TextDefinition(1150430), String.Format("@{0}@{1}", m_Plot.PlotDef.ID, m_Plot.PlotDef.Map.ToString())));
}
if(winner == null)
{
//Get list of winners
List<BidEntry> winners = new List<BidEntry>();
foreach(KeyValuePair<Mobile, BidEntry> kvp in combined)
{
if(kvp.Value.Amount >= highest)
winners.Add(kvp.Value);
}
// One winner!
if(winners.Count == 1)
winner = winners[0].Bidder;
else
{
// get a list of specific type (as opposed to next available)
List<BidEntry> specifics = new List<BidEntry>();
foreach(BidEntry bid in winners)
{
if(bid.BidType == BidType.Specific)
specifics.Add(bid);
}
// one 1 specific!
if(specifics.Count == 1)
winner = specifics[0].Bidder;
else if (specifics.Count > 1)
{
//gets oldest specific
BidEntry oldest = null;
foreach(BidEntry entry in specifics)
{
if(oldest == null || entry.DatePlaced < oldest.DatePlaced)
oldest = entry;
}
winner = oldest.Bidder;
}
else
{
//no specifics! gets oldest of list of winners
BidEntry oldest = null;
foreach(BidEntry entry in winners)
{
if(oldest == null || entry.DatePlaced < oldest.DatePlaced)
oldest = entry;
}
if(oldest != null)
winner = oldest.Bidder;
}
}
}
//Give back gold
foreach(KeyValuePair<Mobile, BidEntry> kvp in m_Auctioners)
{
Mobile m = kvp.Key;
if(m != winner)
{
if(!Banker.Deposit(m, kvp.Value.Amount, true) && m.Backpack != null)
{
int total = kvp.Value.Amount;
while(total > 60000)
{
m.Backpack.DropItem(new BankCheck(60000));
total -= 60000;
}
if(total > 0)
m.Backpack.DropItem(new BankCheck(total));
}
}
}
//Does actual changes to plots
if (winner != null)
MaginciaBazaar.AwardPlot(this, winner, highest);
else
{
m_Plot.Reset(); // lease expires
m_Plot.NewAuction(MaginciaBazaar.GetShortAuctionTime);
}
}
public int GetBidAmount(Mobile from)
{
if(!m_Auctioners.ContainsKey(from))
return 0;
return m_Auctioners[from].Amount;
}
public void ChangeAuctionTime(TimeSpan ts)
{
m_AuctionEnd = DateTime.UtcNow + ts;
if (m_Plot != null && m_Plot.Sign != null)
m_Plot.Sign.InvalidateProperties();
}
public MaginciaPlotAuction(GenericReader reader, MaginciaBazaarPlot plot)
{
int version = reader.ReadInt();
m_Plot = plot;
m_AuctionEnd = reader.ReadDateTime();
int c = reader.ReadInt();
for(int i = 0; i < c; i++)
{
Mobile m = reader.ReadMobile();
BidEntry entry = new BidEntry(reader);
if(m != null)
m_Auctioners[m] = entry;
}
}
public void Serialize(GenericWriter writer)
{
writer.Write((int)0);
writer.Write(m_AuctionEnd);
writer.Write(m_Auctioners.Count);
foreach(KeyValuePair<Mobile, BidEntry> kvp in m_Auctioners)
{
writer.Write(kvp.Key);
kvp.Value.Serialize(writer);
}
}
}
public enum BidType
{
Specific,
NextAvailable
}
public class BidEntry : IComparable
{
private Mobile m_Bidder;
private int m_Amount;
private BidType m_BidType;
private DateTime m_DatePlaced;
public Mobile Bidder { get { return m_Bidder; } }
public int Amount { get { return m_Amount; } }
public BidType BidType { get { return m_BidType; } }
public DateTime DatePlaced { get { return m_DatePlaced; } }
public BidEntry(Mobile bidder, int amount, BidType type)
{
m_Bidder = bidder;
m_Amount = amount;
m_BidType = type;
m_DatePlaced = DateTime.UtcNow;
}
public int CompareTo( object obj )
{
return ((BidEntry)obj).m_Amount - m_Amount;
}
public BidEntry(GenericReader reader)
{
int version = reader.ReadInt();
m_Bidder = reader.ReadMobile();
m_Amount = reader.ReadInt();
m_BidType = (BidType)reader.ReadInt();
m_DatePlaced = reader.ReadDateTime();
}
public void Serialize(GenericWriter writer)
{
writer.Write((int)0);
writer.Write(m_Bidder);
writer.Write(m_Amount);
writer.Write((int)m_BidType);
writer.Write(m_DatePlaced);
}
}
}

View File

@@ -0,0 +1,162 @@
using System;
using Server;
using Server.Items;
using Server.Mobiles;
using System.Collections.Generic;
namespace Server.Engines.NewMagincia
{
public class StorageEntry
{
private int m_Funds;
private DateTime m_Expires;
private Dictionary<Type, int> m_CommodityTypes = new Dictionary<Type, int>();
private List<BaseCreature> m_Creatures = new List<BaseCreature>();
public int Funds { get { return m_Funds; } set { m_Funds = value; } }
public DateTime Expires { get { return m_Expires; } }
public Dictionary<Type, int> CommodityTypes { get { return m_CommodityTypes; } }
public List<BaseCreature> Creatures { get { return m_Creatures; } }
public StorageEntry(Mobile m, BaseBazaarBroker broker)
{
AddInventory(m, broker);
}
public void AddInventory(Mobile m, BaseBazaarBroker broker)
{
m_Funds += broker.BankBalance;
m_Expires = DateTime.UtcNow + TimeSpan.FromDays(7);
if (broker is CommodityBroker)
{
foreach (CommodityBrokerEntry entry in ((CommodityBroker)broker).CommodityEntries)
{
if (entry.Stock > 0)
{
m_CommodityTypes[entry.CommodityType] = entry.Stock;
}
}
}
else if (broker is PetBroker)
{
foreach (PetBrokerEntry entry in ((PetBroker)broker).BrokerEntries)
{
if (entry.Pet.Map != Map.Internal || !entry.Pet.IsStabled)
{
entry.Internalize();
}
m_Creatures.Add(entry.Pet);
}
}
}
public void RemoveCommodity(Type type, int amount)
{
if (m_CommodityTypes.ContainsKey(type))
{
m_CommodityTypes[type] -= amount;
if(m_CommodityTypes[type] <= 0)
m_CommodityTypes.Remove(type);
}
}
public void RemovePet(BaseCreature pet)
{
if (m_Creatures.Contains(pet))
m_Creatures.Remove(pet);
}
public StorageEntry(GenericReader reader)
{
int version = reader.ReadInt();
switch (version)
{
case 1:
m_Funds = reader.ReadInt();
m_Expires = reader.ReadDateTime();
int count = reader.ReadInt();
for (int i = 0; i < count; i++)
{
Type cType = ScriptCompiler.FindTypeByName(reader.ReadString());
int amount = reader.ReadInt();
if (cType != null)
m_CommodityTypes[cType] = amount;
}
count = reader.ReadInt();
for (int i = 0; i < count; i++)
{
BaseCreature bc = reader.ReadMobile() as BaseCreature;
if (bc != null)
m_Creatures.Add(bc);
}
break;
case 0:
int type = reader.ReadInt();
m_Funds = reader.ReadInt();
m_Expires = reader.ReadDateTime();
switch (type)
{
case 0: break;
case 1:
{
int c1 = reader.ReadInt();
for (int i = 0; i < c1; i++)
{
Type cType = ScriptCompiler.FindTypeByName(reader.ReadString());
int amount = reader.ReadInt();
if (cType != null)
m_CommodityTypes[cType] = amount;
}
break;
}
case 2:
{
int c2 = reader.ReadInt();
for (int i = 0; i < c2; i++)
{
BaseCreature bc = reader.ReadMobile() as BaseCreature;
if (bc != null)
{
m_Creatures.Add(bc);
}
}
break;
}
}
break;
}
}
public void Serialize(GenericWriter writer)
{
writer.Write((int)1);
writer.Write(m_Funds);
writer.Write(m_Expires);
writer.Write(m_CommodityTypes.Count);
foreach (KeyValuePair<Type, int> kvp in m_CommodityTypes)
{
writer.Write(kvp.Key.Name);
writer.Write(kvp.Value);
}
writer.Write(m_Creatures.Count);
foreach (BaseCreature bc in m_Creatures)
{
writer.Write(bc);
}
}
}
}