Example #1
0
        private bool CanUseItem(Player player, StorageItem item, Player secondPlayer = null, bool sendmessages = false)
        {
            int groupId = ItemTemplate.Factory(item.ItemId).CoolTimeGroup;

            if (item.ItemTemplate.RequiredUserStatus != null
                && !item.ItemTemplate.RequiredUserStatus.Contains(player.PlayerMode.ToString().ToUpper()))
                return false;

            if (player.PlayerLevel < item.ItemTemplate.Level)
            {
                if (sendmessages)
                    SystemMessages.YouMustBeAHigherLevelToUseThat.Send(player.Connection);

                return false;
            }

            if (item.ItemTemplate.RequiredSecondCharacter && secondPlayer == null)
                return false;

            if (groupId != 0 && player.ItemCoodowns.ContainsKey(groupId) && (RandomUtilities.GetCurrentMilliseconds() - player.ItemCoodowns[groupId]) / 1000 < item.ItemTemplate.Cooltime)
            {
                //todo System message
                return false;
            }
            if(item.ItemTemplate.CombatItemType == CombatItemType.RECIPE && player.Recipes.Contains(item.ItemId))
            {
                if (!Data.Data.Recipes.ContainsKey(item.ItemId))
                {
                    Logger.WriteLine(LogState.Warn,"ItemService: Can't find recipe {0}", item.ItemId);
                    return false;
                }

                if (player.Recipes.Contains(item.ItemId))
                {
                    //todo System message
                    return false;
                }
                if(player.PlayerCraftStats.GetCraftSkills(Data.Data.Recipes[item.ItemId].CraftStat) < Data.Data.Recipes[item.ItemId].ReqMin)
                {
                    //todo System message
                    return false;
                }
            }

            return true;
        }
Example #2
0
 public SpCraftUpdateWindow(StorageItem item)
 {
     Item = item;
 }
Example #3
0
        public Storage LoadAccountStorage(GameAccount gameAccount)
        {
            string SQL = "SELECT * FROM `inventory` WHERE "
                + "`accountname` = ?accountname AND `storagetype` = ?type";
            MySqlCommand cmd = new MySqlCommand(SQL, InventoryDAOConnection);
            cmd.Parameters.AddWithValue("?accountname", gameAccount.Username);
            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),
                        Amount = LoadAccountStorageReader.GetInt32(3),
                        Color = LoadAccountStorageReader.GetInt32(4),
                    };
                    storage.Items.Add(LoadAccountStorageReader.GetInt32(5), item);
                }
            }
            LoadAccountStorageReader.Close();

            return storage;
        }
Example #4
0
        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;
        }
Example #5
0
 public ShoppingItem(ItemTemplate itemTemplate, int count, StorageItem inventoryItem = null)
 {
     ItemTemplate = itemTemplate;
     Count = count;
     InventoryItem = inventoryItem;
 }
Example #6
0
        private bool CanDress(Player player, StorageItem item, bool sendErrors = false)
        {
            if (GetDressSlot(item.ItemId) > 20)
                return false;

            if (item.ItemTemplate.RequiredClassesList.Count > 0
                && !item.ItemTemplate.RequiredClassesList.Contains(player.PlayerData.Class))
            {
                if (sendErrors)
                    SystemMessages.ThatItemIsUnavailableToYourClass.Send(player.Connection);
                return false;
            }

            if (item.ItemTemplate.RequiredLevel > player.GetLevel())
            {
                if (sendErrors)
                    SystemMessages.YouMustBeAHigherLevelToUseThat.Send(player.Connection);
                return false;
            }

            return true;
        }
Example #7
0
        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.PlayerCurrentBankSection * 72);

                    if(toSlot == 0 && to.Items.ContainsKey(toSlot))
                        toSlot = to.GetFreeSlot(player.PlayerCurrentBankSection * 72);

                    if (toSlot == to.LastIdRanged(player.PlayerCurrentBankSection * 72, (player.PlayerCurrentBankSection + 1) * 72 - 1))
                        toSlot = to.GetFreeSlot(player.PlayerCurrentBankSection * 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;
        }
Example #8
0
        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;
            }
        }
Example #9
0
        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;
            }
        }