/// <summary> /// Constructor /// </summary> public TradeInfo() { itemsYou = new ObjectBaseList <ObjectBase>(20); itemsPartner = new ObjectBaseList <ObjectBase>(20); Clear(false); }
/// <summary> /// Constructor /// </summary> public TradeInfo() { itemsYou = new ObjectBaseList<ObjectBase>(20); itemsPartner = new ObjectBaseList<ObjectBase>(20); Clear(false); }
/// <summary> /// Constructor /// </summary> public DataController() { // create lists roomObjects = new RoomObjectList(300); roomObjectsFiltered = new RoomObjectListFiltered(roomObjects); projectiles = new ProjectileList(50); onlinePlayers = new OnlinePlayerList(200); inventoryObjects = new InventoryObjectList(100); avatarCondition = new StatNumericList(5); avatarAttributes = new StatNumericList(10); avatarSkills = new SkillList(100); avatarSpells = new SkillList(100); avatarQuests = new SkillList(100); roomBuffs = new ObjectBaseList<ObjectBase>(30); avatarBuffs = new ObjectBaseList<ObjectBase>(30); spellObjects = new SpellObjectList(100); backgroundOverlays = new BackgroundOverlayList(5); playerOverlays = new ObjectBaseList<PlayerOverlay>(10); chatMessages = new BaseList<ServerString>(101); gameMessageLog = new BaseList<GameMessage>(100); visitedTargets = new List<RoomObject>(50); clickedTargets = new List<uint>(50); actionButtons = new ActionButtonList(); ignoreList = new List<string>(20); chatCommandHistory = new List<string>(20); // attach some listeners RoomObjects.ListChanged += OnRoomObjectsListChanged; Projectiles.ListChanged += OnProjectilesListChanged; ChatMessages.ListChanged += OnChatMessagesListChanged; // make some lists sorted OnlinePlayers.SortByName(); AvatarSkills.SortByResourceName(); AvatarSpells.SortByResourceName(); SpellObjects.SortByName(); // create single data objects roomInformation = new RoomInfo(); lightShading = new LightShading(0, new SpherePosition(0, 0)); backgroundMusic = new PlayMusic(); guildInfo = new GuildInfo(); guildShieldInfo = new GuildShieldInfo(); guildAskData = new GuildAskData(); diplomacyInfo = new DiplomacyInfo(); adminInfo = new AdminInfo(); tradeInfo = new TradeInfo(); buyInfo = new BuyInfo(); welcomeInfo = new WelcomeInfo(); charCreationInfo = new CharCreationInfo(); statChangeInfo = new StatChangeInfo(); newsGroup = new NewsGroup(); objectContents = new ObjectContents(); effects = new Effects(); lookPlayer = new PlayerInfo(); lookObject = new ObjectInfo(); clientPreferences = new PreferencesFlags(); // some values ChatMessagesMaximum = 100; ChatCommandHistoryMaximum = 20; ChatCommandHistoryIndex = -1; AvatarObject = null; IsResting = false; SelfTarget = false; IsNextAttackApplyCastOnHighlightedObject = false; AvatarID = UInt32.MaxValue; TargetID = UInt32.MaxValue; ViewerPosition = V3.ZERO; UIMode = UIMode.None; }
public BuyInfo() { items = new ObjectBaseList<TradeOfferObject>(20); Clear(false); }
public BuyInfo() { items = new ObjectBaseList <TradeOfferObject>(20); Clear(false); }
public ObjectContents() { items = new ObjectBaseList <ObjectBase>(20); Clear(false); }
public ObjectContents() { items = new ObjectBaseList<ObjectBase>(20); Clear(false); }
/// <summary> /// Handles someone offers you first /// </summary> /// <param name="Message"></param> protected override void HandleOfferMessage(OfferMessage Message) { base.HandleOfferMessage(Message); // no tradepartner set (bug!?) or // someone tried to offer nothing (pointless) if (Data.Trade.TradePartner == null || Data.Trade.ItemsPartner.Count == 0) { SendCancelOffer(); return; } /// /// ADMIN /// // accept any items from configured admins in config, offer nothing in return if (Config.IsAdmin(Data.Trade.TradePartner.Name)) { // nothing SendReqCounterOffer(new ObjectID[0]); // tell admin SendSayGroupMessage( Data.Trade.TradePartner.ID, Config.ChatPrefixString + "I will take that, master " + Data.Trade.TradePartner.Name); // exit return; } /// /// NORMAL /// uint offersum = 0; Dictionary <string, uint> dict = new Dictionary <string, uint>(); // see what they offered for (int i = 0; i < Data.Trade.ItemsPartner.Count; i++) { ObjectBase obj = Data.Trade.ItemsPartner[i]; ShopItem entry = Config.BuyListGetItemByName(obj.Name); // if there's anything we don't buy, reject offer if (entry == null) { // tell customer SendSayGroupMessage( new uint[] { Data.Trade.TradePartner.ID }, Config.ChatPrefixString + "Sorry, I'm not buying " + obj.Name); SendCancelOffer(); return; } // process stackable offered item if (obj.IsStackable) { // get the ones we already have ObjectBaseList <InventoryObject> inventoryObjects = Data.InventoryObjects.GetItemsByName(entry.Name, false); int toBuy; // have none yet? accept up to amount if (inventoryObjects.Count == 0) { toBuy = (int)entry.Amount; } // stackable else if (inventoryObjects[0].IsStackable) { toBuy = (int)entry.Amount - (int)inventoryObjects[0].Count; } // non stackable else { toBuy = (int)entry.Amount - (int)inventoryObjects.Count; } if (toBuy <= 0) { // tell customer SendSayGroupMessage( new uint[] { Data.Trade.TradePartner.ID }, Config.ChatPrefixString + "Sorry, I'm not buying " + entry.Name); SendCancelOffer(); return; } else if (obj.Count > toBuy) { // tell customer SendSayGroupMessage( new uint[] { Data.Trade.TradePartner.ID }, Config.ChatPrefixString + "Sorry, I'm only buying " + toBuy + " " + entry.Name); SendCancelOffer(); return; } // add to sum offersum += obj.Count * entry.UnitPrice; } // process nonstackable offered item else { // in this iteration we just count them up uint count; if (dict.TryGetValue(obj.Name, out count)) { dict[obj.Name] = dict[obj.Name] + 1; } else { dict.Add(obj.Name, 1); } } } // process nonstackable offered items now foreach (KeyValuePair <string, uint> keyvalue in dict) { ShopItem entry = Config.BuyListGetItemByName(keyvalue.Key); if (entry != null) { // get the ones we already have ObjectBaseList <InventoryObject> inventoryObjects = Data.InventoryObjects.GetItemsByName(entry.Name, false); int toBuy; // have none yet? accept up to amount if (inventoryObjects.Count == 0) { toBuy = (int)entry.Amount; } // non stackable else { toBuy = (int)entry.Amount - (int)inventoryObjects.Count; } if (toBuy <= 0) { // tell customer SendSayGroupMessage( new uint[] { Data.Trade.TradePartner.ID }, Config.ChatPrefixString + "Sorry, I'm not buying " + entry.Name); SendCancelOffer(); return; } else if (keyvalue.Value > toBuy) { // tell customer SendSayGroupMessage( new uint[] { Data.Trade.TradePartner.ID }, Config.ChatPrefixString + "Sorry, I'm only buying " + toBuy + " " + entry.Name); SendCancelOffer(); return; } // add to sum offersum += keyvalue.Value * entry.UnitPrice; } } // get our shillings from inventory InventoryObject shillings = Data.InventoryObjects.GetItemByName(NAME_SHILLING, false); // do we have enough money? bool haveMoney = (shillings != null && shillings.Count >= offersum); // offer shillings if (offersum > 0 && haveMoney) { SendReqCounterOffer(new ObjectID[] { new ObjectID(shillings.ID, offersum) }); } // offer nothing else if (offersum == 0) { SendReqCounterOffer(new ObjectID[0]); } // cancel trade else { // tell customer SendSayGroupMessage( new uint[] { Data.Trade.TradePartner.ID }, Config.ChatPrefixString + TELL_NOMONEY); SendCancelOffer(); // log warning Log("WARN", "Not enough shillings to perform trade with " + Data.Trade.TradePartner.Name); } }
/// <summary> /// Returns an advertisement string for broadcast and whispers. /// </summary> /// <returns>Advertise message or NULL if no items</returns> protected string GetAdvertisement() { string head = Config.Shopname + " ~n~B~k - (~n " + Data.RoomInformation.RoomName + " ~B~k)~n" + " ~n~B~k - (~n Prices are per unit ~B~k)~n"; string offerstr = "~B~kSelling:~n"; string buystr = "~B~kBuying:~n"; List <string[]> offerStrings = new List <string[]>(); List <string[]> buyStrings = new List <string[]>(); /// /// Prepare offer-item strings /// foreach (ShopItem shopItem in Config.OfferList) { // get the ones we still have ObjectBaseList <InventoryObject> inventoryObjects = Data.InventoryObjects.GetItemsByName(shopItem.Name, false); // no more? skip rest of iteration. if (inventoryObjects.Count == 0) { continue; } // it's stackable if (inventoryObjects[0].IsStackable) { int toSell = (int)inventoryObjects[0].Count - (int)shopItem.Amount; if (toSell > 0) { offerStrings.Add(new string[2] { toSell.ToString(), shopItem.Name + " ~r@~n " + shopItem.UnitPrice + " shillings" }); } } // non stackable, count entries else { int toSell = (int)inventoryObjects.Count - (int)shopItem.Amount; if (toSell > 0) { offerStrings.Add(new string[2] { toSell.ToString(), shopItem.Name + " ~r@~n " + shopItem.UnitPrice + " shillings" }); } } } /// /// Prepare buy-item strings /// foreach (ShopItem shopItem in Config.BuyList) { // skip elements with 0 if (shopItem.Amount == 0) { continue; } // get the ones we have already ObjectBaseList <InventoryObject> inventoryObjects = Data.InventoryObjects.GetItemsByName(shopItem.Name, false); // none yet? if (inventoryObjects.Count == 0) { buyStrings.Add(new string[2] { shopItem.Amount.ToString(), shopItem.Name + " ~r@~n " + shopItem.UnitPrice + " shillings" }); } // it's stackable else if (inventoryObjects[0].IsStackable) { int toBuy = (int)shopItem.Amount - (int)inventoryObjects[0].Count; if (toBuy > 0) { buyStrings.Add(new string[2] { toBuy.ToString(), shopItem.Name + " ~r@~n " + shopItem.UnitPrice + " shillings" }); } } // non stackable, count entries else { int toBuy = (int)shopItem.Amount - (int)inventoryObjects.Count; if (toBuy > 0) { buyStrings.Add(new string[2] { toBuy.ToString(), shopItem.Name + " ~r@~n " + shopItem.UnitPrice + " shillings" }); } } } /// /// Start building message /// string message = head + Environment.NewLine; if (offerStrings.Count > 0) { message += offerstr; foreach (string[] strings in offerStrings) { message += " ~B~r[~n" + strings[0] + "x " + strings[1] + "~B~r]~n"; } message += Environment.NewLine; } if (buyStrings.Count > 0) { message += buystr; foreach (string[] strings in buyStrings) { message += " ~B~r[~n" + strings[0] + "x " + strings[1] + "~B~r]~n"; } } // return message or null return((offerStrings.Count > 0 || buyStrings.Count > 0) ? message : null); }
/// <summary> /// Processed a received buy command /// </summary> /// <param name="CustomerID"></param> /// <param name="Words"></param> protected void ProcessCommandBuy(uint CustomerID, string[] Words) { uint amount = 0; string name; // buy needs at least 3 parameters (e.g. buy 10 purple mushroom) // get amount user wants if (Words.Length < 3 || !UInt32.TryParse(Words[1], out amount) || amount == 0) { // tell customer SendSayGroupMessage(CustomerID, Config.ChatPrefixString + TELL_WRONGSYNTAXBUY); // return return; } // concatenate other words name = String.Empty; for (int i = 2; i < Words.Length; i++) { name += Words[i] + " "; } name = name.TrimEnd(); // try to get this from offered items ShopItem offerItem = Config.OfferListGetItemByName(name); // not selling this? return if (offerItem == null) { // tell customer SendSayGroupMessage(CustomerID, Config.ChatPrefixString + "Sorry, I'm not selling " + name + "."); return; } // get the items from our inventory that match the name ObjectBaseList <InventoryObject> inventoryObjects = Data.InventoryObjects.GetItemsByName(name, false); // don't have that item anymore? if (inventoryObjects.Count == 0) { // tell customer SendSayGroupMessage(CustomerID, Config.ChatPrefixString + "Sorry, I don't have any more " + name + "."); return; } int tempamount; bool isstackable = false; // non stackable item if (!inventoryObjects[0].IsStackable) { isstackable = false; tempamount = (int)inventoryObjects.Count - (int)offerItem.Amount; if (tempamount <= 0) { // tell customer SendSayGroupMessage(CustomerID, Config.ChatPrefixString + "Sorry, I don't have any more " + name + "."); return; } else { amount = Math.Min(amount, (uint)tempamount); } } // stackable else { isstackable = true; tempamount = (int)inventoryObjects[0].Count - (int)offerItem.Amount; if (tempamount <= 0) { // tell customer SendSayGroupMessage(CustomerID, Config.ChatPrefixString + "Sorry, I don't have any more " + name + "."); return; } else { amount = Math.Min(amount, (uint)tempamount); } } // get the object we trade with RoomObject tradePartner = Data.RoomObjects.GetItemByID(CustomerID); if (tradePartner == null) { return; } // save this as our tradepartner (required for we offer first) Data.Trade.TradePartner = tradePartner; // how much we expect for our offer uint expectedsum = offerItem.UnitPrice * amount; // make offer depending on stackflag if (isstackable) { ObjectID[] offer = new ObjectID[] { new ObjectID(inventoryObjects[0].ID, amount) }; // finally offer him stackable item SendReqOffer(new ObjectID(CustomerID), offer); // tell customer SendSayGroupMessage(CustomerID, Config.ChatPrefixString + "This costs you " + expectedsum + " shillings."); } else { ObjectID[] offer = new ObjectID[amount]; for (int i = 0; i < amount; i++) { offer[i] = new ObjectID(inventoryObjects[i].ID); } // finally offer him non stackable item(s) SendReqOffer(new ObjectID(CustomerID), offer); // tell customer SendSayGroupMessage(CustomerID, Config.ChatPrefixString + "This costs you " + expectedsum + " shillings."); } }