Esempio n. 1
0
        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;
        }
Esempio n. 2
0
        public override void Write(System.IO.BinaryWriter writer)
        {
            long CurrentExp = Player.Exp - Data.Data.PlayerExperience[Player.Level - 1];
            long MaxExpOfLevel = Data.Data.PlayerExperience[Player.Level] - Data.Data.PlayerExperience[Player.Level - 1];

            if (CurrentExp < 1)
            {
                Player.Exp = Data.Data.PlayerExperience[Player.Level - 1];
                CurrentExp = 0;
            }

            WriteQ(writer, (CurrentExp < 1) ? 0 : CurrentExp); // Current Player Exp
            WriteQ(writer, MaxExpOfLevel); // Max exp of level

            WriteD(writer, 0);
            WriteD(writer, Player.SkillPoint); // Ki Point

            // Crafting
            WriteH(writer, Player.CraftType); // type
            WriteH(writer, Player.CraftLevel); // level
            WriteD(writer, Player.CraftExp); // exp
            //
            if (Player.GetJobLevel() >= 6)
            {
                Player.AscensionPoint += Player.CurrentAscensionPoint;
                if (Player.AscensionPoint >= 50000000)
                {
                    int FreeSlot = Player.Inventory.GetFreeSlot();
                    if (FreeSlot != -1)
                    {
                        StorageItem item = new StorageItem() { ItemId = 1000000714, Amount = 1 };
                        Global.Global.StorageService.AddItem(Player, Player.Inventory, item);
                    }
                }
                WriteD(writer, Player.AscensionPoint);
                WriteD(writer, Player.CurrentAscensionPoint);
                Player.CurrentAscensionPoint = 0;
            }
            else
            {
                WriteD(writer, 0);
                WriteD(writer, 0);
            }
        }
Esempio n. 3
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.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;
        }
Esempio n. 4
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;
            }
        }
Esempio n. 5
0
 public ShoppingItem(ItemTemplate itemTemplate, int count, StorageItem inventoryItem = null)
 {
     ItemTemplate = itemTemplate;
     Count = count;
     InventoryItem = inventoryItem;
 }
Esempio n. 6
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.pid);
            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),
                            Count = LoadStorageReader.GetInt32(3),
                            Color = LoadStorageReader.GetInt32(4),
                        };

                        storage.Items.Add(LoadStorageReader.GetInt32(5), item);
                    }
                    else
                    {
                        storage.Money = LoadStorageReader.GetInt32(3);
                    }
                }
            }
            LoadStorageReader.Close();

            return storage;
        }
Esempio n. 7
0
 public long UidRegister(StorageItem Item)
 {
     return IDFactory.Register(Item.UID);
 }
Esempio n. 8
0
        public Dictionary<int, StorageItem> LoadStorage(Player player, StorageType type)
        {
            string cmdString = "SELECT * FROM inventory WHERE PlayerId=?id AND StorageType=?type";
            MySqlCommand command = new MySqlCommand(cmdString, InvenDAOConnection);
            command.Parameters.AddWithValue("?id", player.Id);
            command.Parameters.AddWithValue("?type", type.ToString());
            MySqlDataReader reader = command.ExecuteReader();

            Dictionary<int, StorageItem> items = new Dictionary<int, StorageItem>();
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    StorageItem item = new StorageItem()
                    {
                        ItemId = reader.GetInt32(3),
                        Count = reader.GetInt32(4),
                        Color = reader.GetInt32(5),
                    };
                    items.Add(reader.GetInt32(6), item);
                }
            }
            reader.Close();

            return items;
        }
Esempio n. 9
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.Level < 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) && (Funcs.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))
                {
                    Log.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;
        }
Esempio n. 10
0
        public override void Process(IConnection connection, string[] msg)
        {
            try
            {
                Player player = connection.Player;
                Player target = player.Target as Player;
                if (target == null)
                {
                    target = player;
                }

                long itemid = 0;
                int count = 1;

                switch (msg.Length)
                {
                    case 2:
                        {
                            if (msg[0].Equals("money") || int.Parse(msg[0]) == 2000000000)
                            {
                                long money = long.Parse(msg[1]);
                                Global.Global.StorageService.AddMoneys(target, target.Inventory, money);
                                return;
                            }

                            itemid = long.Parse(msg[0]);
                            count = (msg.Length > 1) ? int.Parse(msg[1]) : 1;
                            break;
                        }
                    case 3:
                        {
                            target = Global.Global.VisibleService.FindTarget(player, msg[0]);

                            if (msg[1].Equals("money") || int.Parse(msg[1]) == 2000000000)
                            {
                                long money = long.Parse(msg[2]);
                                Global.Global.StorageService.AddMoneys(target, target.Inventory, money);
                                return;
                            }

                            itemid = long.Parse(msg[1]);
                            count = (msg.Length > 1) ? int.Parse(msg[2]) : 1;
                            break;
                        }
                    default:
                        Print(connection, "Wrong syntax!");
                        Print(connection, "Syntax: @additem <{item_id} {counter}> | <{target name} {item_id} {counter}>");
                        break;
                }

                ItemTemplate itemTemplate = Data.Data.ItemTemplates[itemid];
                if (itemTemplate == null)
                {
                    return;
                }

                StorageItem item = new StorageItem() { ItemId = itemid, Amount = count, State = ItemState.NEW };
                Global.Global.StorageService.AddItem(target, target.Inventory, item);
            }
            catch (Exception e)
            {
                Print(connection, "Wrong syntax!");
                Print(connection, "Syntax: @additem <{item_id} {counter}> | <{target name} {item_id} {counter}>");
                Log.Warn(e.ToString());
            }
        }
Esempio n. 11
0
 protected void WriteItemInfo(BinaryWriter writer, StorageItem item)
 {
     if (item != null)
     {
         WriteQ(writer, item.UID);
         WriteQ(writer, item.ItemId);
         WriteD(writer, item.Amount); // Amount
         WriteD(writer, item.Magic0); // FLD_MAGIC0
         WriteD(writer, item.Magic1); // FLD_MAGIC1
         WriteD(writer, item.Magic2); // FLD_MAGIC2
         WriteD(writer, item.Magic3); // FLD_MAGIC3
         WriteD(writer, item.Magic4); // FLD_MAGIC4
         WriteH(writer, 0);
         WriteH(writer, 0); // (IsBlue == true ? 1 : 0)
         WriteH(writer, item.BonusMagic1); // BonusMagic1
         WriteH(writer, item.BonusMagic2); // BonusMagic2
         WriteH(writer, item.BonusMagic3); // BonusMagic3
         WriteH(writer, item.BonusMagic4); // BonusMagic4
         WriteH(writer, item.BonusMagic5); // BonusMagic5
         WriteD(writer, 0);
         WriteD(writer, (item.LimitTime > 0 ? 1 : 0));
         WriteD(writer, item.LimitTime);
         WriteH(writer, item.Upgrade);
         WriteH(writer, item.ItemTemplate.Category); // ItemType
         WriteH(writer, 0); // 0
         WriteH(writer, 0);
         WriteQ(writer, 0);
         WriteB(writer, new byte[6]);
     }
     else
         WriteB(writer, new byte[88]);
 }
Esempio n. 12
0
        private bool CanStack(StorageItem item)
        {
            bool retval = true;

            switch (item.ItemTemplate.Category)
            {
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                case 7:
                case 8:
                case 9:
                case 21:
                    retval = false;
                    break;
            }

            return retval;
        }
Esempio n. 13
0
        private bool CanDress(Player player, StorageItem item, bool sendErrors = false)
        {
            if (player.PlayerData.Class != (PlayerClass)item.ItemTemplate.Class)
            {
                if(sendErrors)
                    new SpChatMessage(player, "Can't Equip!!", ChatType.House, true).Send(player.Connection);

                return false;
            }

            if (item.ItemTemplate.Level > player.GetLevel() && item.ItemTemplate.JobLevel > player.GetJobLevel())
            {
                if (sendErrors)
                    new SpChatMessage(player, "Can't Equip!!", ChatType.House, true).Send(player.Connection);

                return false;
            }

            return true;
        }
Esempio n. 14
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;
            }
        }
Esempio n. 15
0
        /// <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;
        }
Esempio n. 16
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;
        }
 public SpCraftUpdateWindow(StorageItem item)
 {
     Item = item;
 }
Esempio n. 18
0
        public Dictionary<int, StorageItem> LoadAccountStorage(Account account)
        {
            string cmdString = "SELECT * FROM inventory WHERE AccountName=?aname AND StorageType=?type";
            MySqlCommand command = new MySqlCommand(cmdString, InvenDAOConnection);
            command.Parameters.AddWithValue("?aname", account.Name);
            command.Parameters.AddWithValue("?type", StorageType.AccountWarehouse.ToString());
            MySqlDataReader reader = command.ExecuteReader();

            Dictionary<int, StorageItem> items = new Dictionary<int, StorageItem>();
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    StorageItem item = new StorageItem()
                    {
                        ItemId = reader.GetInt32(3),
                        Count = reader.GetInt32(4),
                        Color = reader.GetInt32(5),
                    };
                    items.Add(reader.GetInt32(6), item);
                }
            }
            reader.Close();

            return items;
        }
Esempio n. 19
0
        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;
            }
        }