public ShopItem(GameItem parent, string id, int count, float quality, float maxQuality, bool isSingle, float cost, string owner) { Parent = parent; ID = id; Count = count; Quality = quality; MaxQuality = maxQuality; IsSingle = isSingle; Cost = cost; Owner = owner; }
public static ShopItem FromInventoryItem(GameItem parent, InventoryItem inventoryItem, string owner) { return new ShopItem ( parent, inventoryItem.ID, inventoryItem.Count, inventoryItem.Quality, inventoryItem.MaxQuality, inventoryItem.IsSingle, float.MaxValue, owner ); }
private bool PassAntibotManeuvers(GameItem gameItem, int count, string owner) { //Check on antibot maneuvers, 1 if (IsPossibleAntiBotManeuvers(gameItem, count)) { return false; } //Check on antibot maneuvers, 2 if (!_listOfItemsOwners.Check(owner)) { return false; } //Check on antibot maneuvers, 3 if (!_listOfPurchasedItemsWithOwners.Check(gameItem, owner)) { return false; } return true; }
public ShoppingPurchasedItemWithOwner(GameItem gameItem, string owner) { Item = gameItem.ToString(); Owner = owner; LastUpdateTime = DateTime.Now; }
private bool IsPossibleAntiBotManeuvers(GameItem gameItem, int count) { return gameItem.FactoryCost > 0f && gameItem.FactoryCost * count < 30f; }
private void InstantBuyItem(NetworkClient networkClient, GameClient client, string groupId, int groupPage, XmlNode item, GameItem gameItem, string owner) { if (item != null && item.Attributes != null) { XmlAttribute cost = item.Attributes["cost"]; if (cost != null) { float qualityMdf = 1f; float fCost = float.Parse(cost.InnerText); //If InstantPurchaseCost isn`t very low, take into an item quality if (gameItem.FactoryCost > 0 && gameItem.InstantPurchaseCost > 0 && gameItem.FactoryCost / gameItem.InstantPurchaseCost > 10f) { XmlAttribute quality = item.Attributes["quality"]; XmlAttribute maxQuality = item.Attributes["maxquality"]; if (quality != null && maxQuality != null) { float fQuality = float.Parse(quality.InnerText); float fMaxQuality = float.Parse(maxQuality.InnerText); qualityMdf = fQuality / fMaxQuality; } } //If an item cost is lower than InstantPurchaseCost, let`s try to buy the item if (fCost <= gameItem.InstantPurchaseCost * qualityMdf) { XmlAttribute id = item.Attributes["id"]; XmlAttribute count = item.Attributes["count"]; if (id != null && count != null) { string sId = id.InnerText; int iCount = int.Parse(count.InnerText); //Check on antibot maneuvers if (!PassAntibotManeuvers(gameItem, iCount, owner)) { return; } //Out log message int totalCost = (int) Math.Ceiling(iCount * fCost); string groupName = _gameItemsGroups[groupId].Name; string message = string.Format("Trying to buy: '{0}', owner: [{1}], group: {2}, page: {3}, count: {4}, cost: {5}, total cost: {6}...", gameItem, owner, groupName, groupPage + 1, iCount, fCost, totalCost); networkClient.OutLogMessage(message); //Try to buy the item //Query params: 1: item ID, 2: count, 3: cost string getGroupsItemsList = Packet.BuildPacket(FromClient.SHOP, Shop.ITEMS_BUY, sId, iCount, fCost); networkClient.SendData(getGroupsItemsList); //Get a purchase result string[] packetTypes = new[] {FromServer.ITEM_ADD_ONE, FromServer.SHOP_ERROR}; Packet purchaseResult = networkClient.InputQueue.PopAny(packetTypes); //Check the purchase result if (purchaseResult != null) { switch (purchaseResult.Type) { //Purchasing is failed case FromServer.SHOP_ERROR: { string errorCode = purchaseResult["@code"]; string errorMessage = Errors.ShopError.GetErrorMessage(errorCode); networkClient.ThrowError(errorMessage, false); break; } //Successful default: { //Add the item to the inventory or, if it`s bad, out log message InventoryItem inventoryItem = Helper.ParseInventoryItem(purchaseResult.Data); if (inventoryItem != null) { //Add inventory item record client.InventoryItems.Add(inventoryItem); //Join inventory items GameStep_JoinInventory.DoJoin(networkClient, client); } else { string errorMessage = string.Format("BUY: BAD INVENTORY ITEM: {0}", purchaseResult.Data); networkClient.ThrowError(errorMessage); } //Play alert _soundPlayer.Play(); //Out log message networkClient.OutLogMessage("Successful"); break; } } } } } } } }
public void RemoveItem(GameItem item) { if (item != null) { string ident = item.Ident; if (!string.IsNullOrEmpty(ident) && _gameItems.ContainsKey(ident)) { _gameItems.Remove(ident); } } }
public GameItem AddItem(GameItem item) { string itemIdent = item.Ident; if (_gameItems.ContainsKey(itemIdent)) { throw new Exception("Item is exists in the group"); } _gameItems.Add(itemIdent, item); return item; }
public GameItem AddItem(string text, string modification, string level, float massa, string subGroupID, string subGroupType) { GameItem item = new GameItem(text, modification, level, massa, subGroupID, subGroupType); return AddItem(item); }