public Storage LoadStorage(Player player, StorageType type) { string SQL = "SELECT * FROM `inventory` WHERE " + "`playerid` = ?pid AND `storagetype` = ?type"; MySqlCommand cmd = new MySqlCommand(SQL, InventoryDAOConnection); cmd.Parameters.AddWithValue("?pid", player.Id); cmd.Parameters.AddWithValue("?type", type.ToString()); MySqlDataReader LoadStorageReader = cmd.ExecuteReader(); var storage = new Storage { StorageType = StorageType.Inventory }; if (LoadStorageReader.HasRows) { while (LoadStorageReader.Read()) { if (LoadStorageReader.GetInt32(2) != 20000000) { StorageItem item = new StorageItem() { ItemId = LoadStorageReader.GetInt32(2), Amount = LoadStorageReader.GetInt32(3), Color = LoadStorageReader.GetInt32(4), }; storage.Items.Add(LoadStorageReader.GetInt32(5), item); } else { storage.Money = LoadStorageReader.GetInt32(3); } } } LoadStorageReader.Close(); return storage; }
public Storage LoadAccountStorage(Account account) { string SQL = "SELECT * FROM `inventory` WHERE " + "`accountname` = ?accountname AND `storagetype` = ?type"; MySqlCommand cmd = new MySqlCommand(SQL, InventoryDAOConnection); cmd.Parameters.AddWithValue("?accountname", account.Name); cmd.Parameters.AddWithValue("?type", StorageType.AccountWarehouse.ToString()); MySqlDataReader LoadAccountStorageReader = cmd.ExecuteReader(); var storage = new Storage { StorageType = StorageType.AccountWarehouse }; if (LoadAccountStorageReader.HasRows) { while (LoadAccountStorageReader.Read()) { StorageItem item = new StorageItem() { ItemId = LoadAccountStorageReader.GetInt32(2), Count = LoadAccountStorageReader.GetInt32(3), Color = LoadAccountStorageReader.GetInt32(4), }; storage.Items.Add(LoadAccountStorageReader.GetInt32(5), item); } } LoadAccountStorageReader.Close(); return storage; }
public void SaveStorage(Player player, Storage storage) { string cmdString = "DELETE FROM inventory WHERE PlayerId=?pid"; MySqlCommand command = new MySqlCommand(cmdString, InventoryDAOConnection); command.Parameters.AddWithValue("?pid", player.Id); command.ExecuteNonQuery(); storage.Items.Add(999, storage.MoneyToItem); // add temporary save money item if (storage.Items.Count > 0) { foreach (var item in storage.Items) AddItem(player, storage.StorageType, item); } storage.Items.Remove(999); // remove temporary save money item }
public bool AddMoneys(Player player, Storage storage, long counter) { if (counter < 0) return false; storage.Money += counter; ShowPlayerStorage(player, storage.StorageType); return true; }
public bool AddItem(Player player, Storage storage, StorageItem item) { lock (storage.ItemsLock) { int maxStack = ItemTemplate.Factory(item.ItemId).MaxStack; int canStacked = 0; if (maxStack > 1) { for (int i = 20; i < 20 + storage.Size; i++) { if (!storage.Items.ContainsKey(i)) continue; if (storage.Items[i].ItemId == item.ItemId) { canStacked += maxStack - storage.Items[i].Amount; if (canStacked >= item.Amount) break; } } } if (canStacked < item.Amount && GetFreeSlots(storage).Count < 1) return false; if (canStacked > 0) { for (int i = 20; i < 20 + storage.Size; i++) { if (!storage.Items.ContainsKey(i)) continue; if (storage.Items[i].ItemId == item.ItemId) { int put = maxStack - storage.Items[i].Amount; if (item.Amount < put) put = item.Amount; storage.Items[i].Amount += put; item.Amount -= put; if (item.Amount <= 0) break; } } } if (item.Amount > 0) storage.Items.Add(storage.GetFreeSlot(), item); ShowPlayerStorage(player, storage.StorageType); return true; } }
public bool ContainsItem(Storage storage, int itemId, long counter) { lock (storage.ItemsLock) { for (int i = 0; i <= storage.Size; i++) if (storage.Items.ContainsKey(i)) { if (storage.Items[i].ItemId == itemId && storage.Items[i].Amount >= counter) return true; } } return false; }
public override void Release() { ObservedCreature = null; Inventory.Release(); Inventory = null; PlayerData = null; try { Visible.Stop(); Visible.Release(); } // ReSharper disable EmptyGeneralCatchClause catch // ReSharper restore EmptyGeneralCatchClause { //Already stoped } Visible = null; Skills = null; Quests = null; if (CurrentDialog != null) CurrentDialog.Release(); if (Pet != null) Pet.Release(); Pet = null; MarkedCreatures = null; TeleportLoadMapEvent = null; try { SystemWindowsTimer.Stop(); SystemWindowsTimer.Dispose(); } // ReSharper disable EmptyGeneralCatchClause catch // ReSharper restore EmptyGeneralCatchClause { } SystemWindowsTimer = null; BlockersInChat = null; Friends = null; base.Release(); }
public bool RemoveMoney(Player player, Storage storage, long counter) { if (counter < 0) return false; if (storage.Money - counter >= 0) storage.Money -= counter; else { player.Inventory.Money = 0; Log.Warn("InventorService: Player {0} moneys can't be less than 0"); ShowPlayerStorage(player, storage.StorageType); return false; } ShowPlayerStorage(player, storage.StorageType); return true; }
public bool RemoveItem(Player player, Storage storage, int slot, int counter) { if (counter < 0) return false; slot += 20; lock (storage.ItemsLock) { if (!storage.Items.ContainsKey(slot) || storage.Items[slot].Amount < counter) return false; if (storage.Items[slot].Amount == counter) storage.Items.Remove(slot); else if (storage.Items[slot].Amount > counter) storage.Items[slot].Amount -= counter; ShowPlayerStorage(player, storage.StorageType, false); } return true; }
public StorageItem GetItemById(Storage storage, int id) { lock (storage.ItemsLock) { for (int i = 0; i <= storage.Size; i++) if (storage.Items.ContainsKey(i)) { if (storage.Items[i].ItemId == id) return storage.Items[i]; } } return null; }
public StorageItem GetItemById(Storage storage, int id) { lock (storage.ItemsLock) { for (int i = (storage.StorageType == StorageType.Inventory ? 20 : 0); i <= storage.Size + (storage.StorageType == StorageType.Inventory ? 19 : 0); i++) if (storage.Items.ContainsKey(i)) { if (storage.Items[i].ItemId == id) return storage.Items[i]; } } return null; }
public void ReplaceItem(Player player, Storage storage, MoveItemArgs Args, bool showStorage = true) { lock (storage.ItemsLock) { switch (Args.IsFromInventory) { case 1: // Move item from inventory storage.Items.TryGetValue(Args.FromSlot, out Args.ItemToMove); switch (Args.IsToInventory) { case 1: // to inventory { Args.ItemToReplace = player.Inventory.GetItem(Args.ToSlot); storage.Items.Remove(Args.FromSlot); if (Args.ItemToReplace != null) { storage.Items.Remove(Args.ToSlot); storage.Items.Add(Args.FromSlot, Args.ItemToReplace); } storage.Items.Add(Args.ToSlot, Args.ItemToMove); } break; case 0: // to Equiped { if (!CanDress(player, Args.ItemToMove) && !Global.Global.AdminEngine.IsDev(player)) return; storage.EquipItems.TryGetValue(Args.ToSlot, out Args.ItemToReplace); storage.Items.Remove(Args.FromSlot); storage.EquipItems.Remove(Args.ToSlot); if (Args.ItemToReplace != null) storage.Items.Add(Args.FromSlot, Args.ItemToReplace); storage.EquipItems.Add(Args.ToSlot, Args.ItemToMove); } break; } break; case 0: // Move item from Equiped Args.ItemToMove = player.Inventory.GetEquipItem(Args.FromSlot); switch (Args.IsToInventory) { case 1: // to inventory { Args.ItemToReplace = player.Inventory.GetItem(Args.ToSlot); storage.EquipItems.Remove(Args.FromSlot); if (Args.ItemToReplace != null) { storage.Items.Remove(Args.ToSlot); //storage.EquipItems.Add(Args.FromSlot, Args.ItemToReplace); } storage.Items.Add(Args.ToSlot, Args.ItemToMove); } break; case 0: // to Equiped // this may be not use break; } break; } switch (Args.ItemToMove.State) { case ItemState.NEW: Args.ItemToMove.State = ItemState.NEW; break; case ItemState.UPDATE: Args.ItemToMove.State = ItemState.UPDATE; break; case ItemState.DELETE: break; } } new SpInventoryMove(Args).Send(player.Connection); CreatureLogic.UpdateCreatureStats(player); if (showStorage) { Global.Global.VisibleService.Send(player, new SpEquipInfo(player)); ShowPlayerStorage(player, storage.StorageType); } }
public bool RemoveItemById(Player player, Storage storage, int itemId, int counter) { //todo rework for (int slot = 0; slot <= player.Inventory.Size; slot++) if (player.Inventory.Items.ContainsKey(slot)) { if (player.Inventory.Items[slot].ItemId == itemId) { if (player.Inventory.Items[slot].Amount <= counter) { player.Inventory.Items[slot].State = ItemState.DELETE; storage.DeleteItems.Add(player.Inventory.Items[slot].UID, player.Inventory.Items[slot]); player.Inventory.Items.Remove(slot); } else { player.Inventory.Items[slot].Amount -= counter; player.Inventory.Items[slot].State = ItemState.UPDATE; } ShowPlayerStorage(player, storage.StorageType); return true; } } return false; }
public bool RemoveItem(Player player, Storage storage, int slot, int counter) { if (counter < 0) return false; lock (storage.ItemsLock) { if (!storage.Items.ContainsKey(slot) || storage.Items[slot].Amount < counter) return false; if (storage.Items[slot].Amount == counter) { storage.Items[slot].State = ItemState.DELETE; storage.DeleteItems.Add(storage.Items[slot].UID, storage.Items[slot]); storage.Items.Remove(slot); } else if (storage.Items[slot].Amount > counter) { storage.Items[slot].Amount -= counter; storage.Items[slot].State = ItemState.UPDATE; } ShowPlayerStorage(player, storage.StorageType, false); } return true; }
public int GetTotalWeight(Player player, Storage storage) { int totalWeight = 0; storage.Items.Values.ToList().Each(i => { totalWeight += i.ItemTemplate.Weight; }); return totalWeight; }
public bool ContainsItem(Storage storage, int itemId, long counter) { lock (storage.ItemsLock) { for (int i = (storage.StorageType == StorageType.Inventory ? 20 : 0); i <= storage.Size + (storage.StorageType == StorageType.Inventory ? 19 : 0); i++) if (storage.Items.ContainsKey(i)) { if (storage.Items[i].ItemId == itemId && storage.Items[i].Amount >= counter) return true; } } return false; }
public bool PlaceItemToOtherStorage(Player player, Player second, Storage from, int fromSlot, Storage to, int toSlot, int count) { if (to.IsFull()) return false; if (count < 0) return false; if (!(player.Controller is DefaultController) || !(second.Controller is DefaultController)) return false; if(player == second) { StorageItem item = null; if(to.StorageType == StorageType.CharacterWarehouse) { if(toSlot == -1) toSlot = to.GetFreeSlot(player.CurrentBankSection * 72); if(toSlot == 0 && to.Items.ContainsKey(toSlot)) toSlot = to.GetFreeSlot(player.CurrentBankSection * 72); if (toSlot == to.LastIdRanged(player.CurrentBankSection * 72, (player.CurrentBankSection + 1) * 72 - 1)) toSlot = to.GetFreeSlot(player.CurrentBankSection * 72); } else if ((toSlot == 0 && to.Items.ContainsKey(toSlot)) || toSlot == -1) toSlot = to.GetFreeSlot(); if (to.Items.ContainsKey(toSlot)) { if (!PlaceItemToOtherStorage(player, player, to, toSlot, player.Inventory, player.Inventory.GetFreeSlot(), to.Items[toSlot].Amount)) return false; } lock (from.ItemsLock) { if(from.Items.ContainsKey(fromSlot)) { item = from.Items[fromSlot]; if(item.Amount < count) return false; if (item.Amount == count) from.Items.Remove(fromSlot); else { from.Items[fromSlot].Amount -= count; item = new StorageItem { ItemId = item.ItemId, Amount = count }; } } } if (item == null) return false; if (!AddItem(player, to, item.ItemId, count, toSlot)) AddItem(player, from, item.ItemId, count, fromSlot); } return false; }
public List<int> GetFreeSlots(Storage storage) { var freeSlots = new List<int>(); for (int i = (storage.StorageType == StorageType.Inventory ? 20 : 0); i <= storage.Size + (storage.StorageType == StorageType.Inventory ? 19 : 0); i++) if (!storage.Items.ContainsKey(i)) freeSlots.Add(i); return freeSlots; }
public List<int> GetFreeSlots(Storage storage) { var freeSlots = new List<int>(); for (int i = 0; i <= storage.Size; i++) if (!storage.Items.ContainsKey(i)) freeSlots.Add(i); return freeSlots; }
public StorageItem GetItemBySlot(Storage storage, int slot) { lock (storage.ItemsLock) { if (!storage.Items.ContainsKey(slot)) return null; return storage.Items[slot]; } }
public SpInventoryInfo(Storage s) { Storage = s; }
public bool AddItem(Player player, Storage storage, int itemId, int count, int slot = -1) { if (count < 0) return false; if (slot > (storage.StorageType == StorageType.Inventory ? storage.Size + 20 : storage.Size)) return false; if ((storage.StorageType == StorageType.Inventory && slot < 20 && slot != -1)) return false; if (slot < -1) return false; lock (storage.ItemsLock) { int stackSize = ItemTemplate.Factory(itemId).MaxStack; if (stackSize == 1 && storage.IsFull()) { SystemMessages.InventoryIsFull.Send(player); return false; } if (stackSize == 1) { if (slot == -1) storage.Items.Add(storage.GetFreeSlot(), new StorageItem {ItemId = itemId, Amount = count}); else if (storage.Items.ContainsKey(slot)) { SystemMessages.YouCantPutItemInInventory(ItemTemplate.Factory(itemId).Name).Send(player); return false; } else storage.Items.Add(slot, new StorageItem {ItemId = itemId, Amount = count}); } else { if (slot != -1) { // Certain slot + Stackable if (storage.Items.ContainsKey(slot)) { SystemMessages.YouCantPutItemInInventory(ItemTemplate.Factory(itemId).Name).Send(player); return false; } storage.Items.Add(slot, new StorageItem { ItemId = itemId, Amount = count }); } else { #region Any slot + Stackable Dictionary<int, StorageItem> itemsById = storage.GetItemsById(itemId); int canBeAdded = itemsById.Values.Where(storageItem => storageItem.Amount < stackSize).Sum( storageItem => stackSize - storageItem.Amount); if (canBeAdded >= count) { foreach (var storageItem in itemsById.Values) { int added = Math.Min(stackSize - storageItem.Amount, count); storageItem.Amount += added; count -= added; if (count == 0) break; } } else { if (storage.IsFull() || count > GetFreeSlots(storage).Count*stackSize) { SystemMessages.InventoryIsFull.Send(player); return false; } foreach (var storageItem in itemsById.Values) { int added = Math.Min(stackSize - storageItem.Amount, count); storageItem.Amount += added; count -= added; } while (count > 0) { int added = Math.Min(stackSize, count); StorageItem item = new StorageItem {ItemId = itemId, Amount = added}; storage.Items.Add(storage.GetFreeSlot(), item); count -= added; } } #endregion } } ShowPlayerStorage(player, storage.StorageType); return true; } }
/// <summary> /// Save Player Character Storage /// </summary> /// <param name="PID"></param> /// <param name="storage"></param> public static void SavePlayerStorage(int PID, Storage storage) { using (MySqlConnection connection = new MySqlConnection(connectionString)) { connection.Open(); //using (MySqlCommand command = connection.CreateCommand()) //{ // command.CommandText = "GAME_INVENTORY_CLEAR"; // command.CommandType = System.Data.CommandType.StoredProcedure; // command.Parameters.AddWithValue("@in_PID", PID); // command.ExecuteNonQuery(); //} using (MySqlCommand command = connection.CreateCommand()) { command.CommandText = "GAME_PLAYER_MONEY_UPDATE"; command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@in_PID", PID); command.Parameters.AddWithValue("@in_AMOUNT", storage.Money); command.ExecuteNonQuery(); } foreach (var storageitem in storage.DeleteItems) { using (MySqlCommand command = connection.CreateCommand()) { long uid = storageitem.Key; var item = storageitem.Value; if (item != null) { command.CommandText = "GAME_INVENTORY_DELETE"; command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@in_UID", item.UID); command.Parameters.AddWithValue("@in_PID", PID); command.ExecuteNonQuery(); } } } foreach (var storageitem in storage.Items) { using (MySqlCommand command = connection.CreateCommand()) { int slot = storageitem.Key; var item = storageitem.Value; if (item != null) { switch (item.State) { case ItemState.UPDATE: command.CommandText = "GAME_INVENTORY_UPDATE"; break; case ItemState.NEW: command.CommandText = "GAME_INVENTORY_ADD"; break; } command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@in_UID", item.UID); command.Parameters.AddWithValue("@in_PID", PID); command.Parameters.AddWithValue("@in_ID", item.ItemId); command.Parameters.AddWithValue("@in_Amount", item.Amount); command.Parameters.AddWithValue("@in_Magic0", item.Magic0); command.Parameters.AddWithValue("@in_Magic1", item.Magic1); command.Parameters.AddWithValue("@in_Magic2", item.Magic2); command.Parameters.AddWithValue("@in_Magic3", item.Magic3); command.Parameters.AddWithValue("@in_Magic4", item.Magic4); command.Parameters.AddWithValue("@in_BonusMagic1", item.BonusMagic1); command.Parameters.AddWithValue("@in_BonusMagic2", item.BonusMagic2); command.Parameters.AddWithValue("@in_BonusMagic3", item.BonusMagic3); command.Parameters.AddWithValue("@in_BonusMagic4", item.BonusMagic4); command.Parameters.AddWithValue("@in_BonusMagic5", item.BonusMagic5); command.Parameters.AddWithValue("@in_Equiped", 0); command.Parameters.AddWithValue("@in_Slot", slot); command.Parameters.AddWithValue("@in_InventoryType", storage.StorageType); command.Parameters.AddWithValue("@in_LimitTime", item.LimitTime); command.Parameters.AddWithValue("@in_Upgrade", item.Upgrade); command.Parameters.AddWithValue("@in_Quality", item.Quality); command.Parameters.AddWithValue("@in_Lock", item.Lock); command.ExecuteNonQuery(); } } } if (storage.StorageType == StorageType.Inventory) { foreach (var storageitem in storage.EquipItems) { using (MySqlCommand command = connection.CreateCommand()) { int slot = storageitem.Key; var item = storageitem.Value; if (item != null) { switch (item.State) { case ItemState.UPDATE: command.CommandText = "GAME_INVENTORY_UPDATE"; break; case ItemState.NEW: command.CommandText = "GAME_INVENTORY_ADD"; break; } command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@in_UID", item.UID); command.Parameters.AddWithValue("@in_PID", PID); command.Parameters.AddWithValue("@in_ID", item.ItemId); command.Parameters.AddWithValue("@in_Amount", item.Amount); command.Parameters.AddWithValue("@in_Magic0", item.Magic0); command.Parameters.AddWithValue("@in_Magic1", item.Magic1); command.Parameters.AddWithValue("@in_Magic2", item.Magic2); command.Parameters.AddWithValue("@in_Magic3", item.Magic3); command.Parameters.AddWithValue("@in_Magic4", item.Magic4); command.Parameters.AddWithValue("@in_BonusMagic1", item.BonusMagic1); command.Parameters.AddWithValue("@in_BonusMagic2", item.BonusMagic2); command.Parameters.AddWithValue("@in_BonusMagic3", item.BonusMagic3); command.Parameters.AddWithValue("@in_BonusMagic4", item.BonusMagic4); command.Parameters.AddWithValue("@in_BonusMagic5", item.BonusMagic5); command.Parameters.AddWithValue("@in_Equiped", 1); command.Parameters.AddWithValue("@in_Slot", slot); command.Parameters.AddWithValue("@in_InventoryType", storage.StorageType); command.Parameters.AddWithValue("@in_LimitTime", item.LimitTime); command.Parameters.AddWithValue("@in_Upgrade", item.Upgrade); command.Parameters.AddWithValue("@in_Quality", item.Quality); command.Parameters.AddWithValue("@in_Lock", item.Lock); command.ExecuteNonQuery(); } } } } connection.Close(); } }
public bool RemoveItemById(Player player, Storage storage, int itemId, int counter) { //todo rework for (int i = 20; i <= player.Inventory.Size + 19; i++) if (player.Inventory.Items.ContainsKey(i)) { if (player.Inventory.Items[i].ItemId == itemId) { if (player.Inventory.Items[i].Amount <= counter) player.Inventory.Items.Remove(i); else player.Inventory.Items[i].Amount -= counter; ShowPlayerStorage(player, storage.StorageType); return true; } } return false; }
/// <summary> /// Get Player storages, default is Inventory /// </summary> /// <param name="PID"></param> /// <param name="type"></param> /// <returns></returns> public static Storage GetPlayerStorage(int PID, StorageType type = StorageType.Inventory) { Storage storage = new Storage(); using (MySqlConnection connection = new MySqlConnection(connectionString)) { connection.Open(); using (MySqlCommand command = connection.CreateCommand()) { command.CommandText = "GAME_PLAYER_MONEY_GET"; command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@in_PID", PID); command.Parameters.AddWithValue("@out_Money", MySqlDbType.Int64); command.Parameters["@out_Money"].Direction = System.Data.ParameterDirection.Output; command.ExecuteNonQuery(); storage.Money = (int)command.Parameters["@out_Money"].Value; } using (MySqlCommand command = connection.CreateCommand()) { command.CommandText = "GAME_INVENTORY_GET"; command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@in_PID", PID); command.Parameters.AddWithValue("@in_TYPE", (int)type); var reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { StorageItem item = new StorageItem() { UID = reader.GetInt64(0), ItemId = reader.GetInt32(2), Amount = reader.GetInt32(3), Magic0 = reader.GetInt32(4), Magic1 = reader.GetInt32(5), Magic2 = reader.GetInt32(6), Magic3 = reader.GetInt32(7), Magic4 = reader.GetInt32(8), BonusMagic1 = reader.GetInt32(9), BonusMagic2 = reader.GetInt32(10), BonusMagic3 = reader.GetInt32(11), BonusMagic4 = reader.GetInt32(12), BonusMagic5 = reader.GetInt32(13), LimitTime = reader.GetInt32(17), Upgrade = reader.GetInt32(18), Quality = reader.GetInt32(19), Lock = reader.GetInt32(20), }; item.UID = Global.Global.StorageService.UidRegister(item); if (reader.GetInt32(14) == 0) { storage.Items.Add(reader.GetInt32(15), item); } else { if (!storage.EquipItems.ContainsKey(reader.GetInt32(15))) storage.EquipItems.Add(reader.GetInt32(15), item); else storage.EquipItems[reader.GetInt32(15)] = item; } } } } connection.Close(); } return storage; }
public void ReplaceItem(Player player, Storage storage, int @from, int to, bool isForDress = false, bool showStorage = true) { lock (storage.ItemsLock) { if (!storage.Items.ContainsKey(@from)) return; if (from < 20 && GetFreeSlots(storage).Count == 0) return; StorageItem item = storage.Items[@from]; if (isForDress && storage.StorageType == StorageType.Inventory) { if (to == 0) to = GetDressSlot(item.ItemId); if (to == 0) return; } if (to != 0 && to < 20 && storage.StorageType == StorageType.Inventory) { if (!CanDress(player, item, true)) return; switch (GetDressSlot(item.ItemId)) { case 6: if (to != 6 && to != 7) return; break; case 8: if (to != 8 && to != 9) return; break; default: if (to != GetDressSlot(item.ItemId)) return; break; } } storage.Items.Remove(@from); if (storage.Items.ContainsKey(to)) { StorageItem item2 = storage.Items[to]; storage.Items.Remove(to); storage.Items.Add(@from, item2); } if (to == 0) to = storage.GetFreeSlot(); storage.Items.Add(to, item); if (@from <= 20 || to <= 20) Communication.Logic.CreatureLogic.UpdateCreatureStats(player); } if (showStorage) { ShowPlayerStorage(player, storage.StorageType); if(@from <= 20 || to <= 20) new SpCharacterThings(player).Send(player.Connection); } }
private void CheckLock(Storage storage) { if (!storage.Locked) return; storage.Locked = false; SystemMessages.TradeHasChangedPleaseCheckItAgain.Send(storage.Equals(Storage1) ? Player1 : Player2); }
public bool SaveStorage(Player player, Storage storage) { if (storage.Items.Count > 0) { foreach (var item in storage.Items) AddItem(player, storage.StorageType, item); return true; } return false; }
public bool AddItem(Player player, Storage storage, StorageItem item) { item.UID = IDFactory.GetNext(); lock (storage.ItemsLock) { if (item.ItemId == 0) { Log.Debug("Item UID[{0}]: ItemId = {1}", item.UID, item.ItemId); return false; } int maxStack = CanStack(item) ? 99 : 1; int canStacked = 1; if (maxStack > 1) { for (int i = 0; i < storage.Size; i++) { if (!storage.Items.ContainsKey(i)) continue; if (storage.Items[i].ItemId == item.ItemId) { canStacked += maxStack - storage.Items[i].Amount; if (canStacked >= item.Amount) break; } } } if (canStacked < item.Amount && GetFreeSlots(storage).Count < 1) return false; if (canStacked > 0) { for (int i = 0; i < storage.Size; i++) { if (!storage.Items.ContainsKey(i)) continue; if (storage.Items[i].ItemId == item.ItemId) { int put = maxStack - storage.Items[i].Amount; if (item.Amount < put) put = item.Amount; storage.Items[i].Amount += put; storage.Items[i].State = ItemState.UPDATE; item.Amount -= put; if (item.Amount <= 0) break; } } } if (item.Amount > 0) { storage.Items.Add(storage.GetFreeSlot(), item); } ShowPlayerStorage(player, storage.StorageType); return true; } }