Beispiel #1
0
        private static void ProcessObjectEatLivingItemRequest(WorldClient Client, string Packet)
        {
            if (Client.GetFight() != null && (int)Client.GetFight().FightState > 2)
            {
                Client.Send(new BasicNoOperationMessage());
                return;
            }

            var Data = Packet.Split('|');

            long ItemGuid    = 0;
            long IdEatObject = 0;

            if (!long.TryParse(Data[0].Substring(2), out ItemGuid))
            {
                Client.Send(new BasicNoOperationMessage());
                return;
            }

            if (!long.TryParse(Data[2], out IdEatObject))
            {
                Client.Send(new BasicNoOperationMessage());
                return;
            }

            var Item     = Client.Character.InventoryCache.GetItem(ItemGuid);
            var ItemAlim = Client.Character.InventoryCache.GetItem(IdEatObject);

            if (Item == null || ItemAlim == null)
            {
                Client.Send(new BasicNoOperationMessage());
                return;
            }

            if (Item.SpeakingItem == null)
            {
                Client.Send(new BasicNoOperationMessage());
                return;
            }

            if ((ItemAlim.Quantity > 1) && (Item.Quantity - 1 > 0))
            {
                int newQ = ItemAlim.Quantity - 1;
                InventoryItemTable.TryCreateItem(ItemAlim.TemplateID, Client.Character, Stats: ItemAlim.GetStats().ToItemStats(), quantity: newQ);
                Client.Character.InventoryCache.UpdateObjectquantity(ItemAlim, 1);
            }
            long xp = long.Parse(ItemAlim.Template.Level.ToString());

            Item.SpeakingItem.EXP += xp;
            Client.Character.InventoryCache.RemoveItem(ItemAlim);
            InventoryItemTable.removeItem(ItemAlim.ID);
            Client.Send(new ObjectRemoveMessage(ItemAlim.ID));
            Client.Send(new ObjectRefreshMessage(Item));
            Client.Character.myMap.SendToMap(new ObjectActualiseMessage(Client.Character));
            if (Client.GetFight() != null)
            {
                Client.GetFight().SendToFight(new ObjectActualiseMessage(Client.Character));
            }
            Client.Send(new AccountStatsMessage(Client.Character));
        }
Beispiel #2
0
        public override bool SellItem(WorldClient Client, InventoryItemModel Item, ushort Quantity)
        {
            if (this.myEnd)
            {
                return(false);
            }

            if (Quantity > Item.Quantity)
            {
                Quantity = (ushort)Item.Quantity;
            }

            uint Refund = (uint)Math.Floor((double)ItemTemplateTable.GetTemplate(Item.TemplateID).Price / 10) * Quantity;

            Client.Character.InventoryCache.AddKamas(Refund);
            if (Quantity == Item.Quantity)
            {
                //DatabaseEntities.TryDeleteItem(Item);
                InventoryItemTable.removeItem(Item.ID);
                Client.Send(new ObjectRemoveMessage(Item.ID));
            }
            else
            {
                Client.Character.InventoryCache.UpdateObjectquantity(Item, Item.Quantity - Quantity);
            }

            Client.Send(new AccountStatsMessage(Client.Character));

            return(true);
        }
Beispiel #3
0
        public static void removeFromBank(Player character, int guid, int qua)
        {
            InventoryItemModel BankObj = InventoryItemTable.getItem(guid);

            if (BankObj == null)
            {
                character.Send(new BasicNoOperationMessage());
                return;
            }
            if (!character.Client.Account.Data.bankItems.ContainsKey(guid))
            {
                Logger.Error("Le joueur " + character.Name + " a tenter de retirer un Item en banque qu'il n'avait pas.");
            }
            InventoryItemModel PersoObj = character.InventoryCache.ItemsCache.Values.FirstOrDefault(x => x.TemplateID == BankObj.TemplateID && x.GetStats().ToItemStats() == BankObj.GetStats().ToItemStats() && x.ID != BankObj.ID && x.Position == -1); /* getSimilarBankItem(Character, BankObj);*/
            int newQua = BankObj.Quantity - qua;

            if (PersoObj == null)
            {
                if (newQua <= 0)
                {
                    character.Client.Account.Data.bankItems.Remove(guid);
                    character.InventoryCache.Add(BankObj, false);
                    String str = "O-" + guid;
                    character.Send(new BankUpdateMessage(str));
                }
                else
                {
                    PersoObj = getCloneItem(BankObj, qua);
                    InventoryItemTable.addItem(PersoObj, true);
                    character.InventoryCache.Add(PersoObj, false);
                    String str = "O+" + BankObj.ID + "|" + BankObj.Quantity + "|" + BankObj.TemplateID + "|" + BankObj.GetStats().ToItemStats();
                    character.Send(new BankUpdateMessage(str));
                }
            }
            else
            {
                if (newQua <= 0)
                {
                    character.Client.Account.Data.bankItems.Remove(BankObj.ID);
                    InventoryItemTable.removeItem(BankObj.ID);
                    PersoObj.Quantity += BankObj.Quantity;
                    character.Send(new ObjectQuantityMessage(PersoObj.ID, PersoObj.Quantity));
                    String str = "O-" + guid;
                    character.Send(new BankUpdateMessage(str));
                }
                else
                {
                    BankObj.Quantity   = newQua;
                    PersoObj.Quantity += qua;
                    character.Send(new ObjectQuantityMessage(PersoObj.ID, PersoObj.Quantity));
                    String str = "O+" + BankObj.ID + "|" + BankObj.Quantity + "|" + BankObj.TemplateID + "|" + BankObj.GetStats().ToItemStats();
                    character.Send(new BankUpdateMessage(str));
                }
            }
            //SEND POD MESSAGE ?
            character.GetClient().Account.Data.Save();
        }
Beispiel #4
0
        public static void ProcessObjectDestroyMessage(WorldClient Client, string Packet)
        {
            String[] infos = Regex.Split(Packet.Substring(2), "\\|");
            try
            {
                int guid = int.Parse(infos[0]);
                int qua  = 1;
                try
                {
                    qua = int.Parse(infos[1]);
                }
                catch (Exception e)
                {
                    return;
                }

                InventoryItemModel obj = InventoryItemTable.getItem(guid);

                if (!Client.Character.InventoryCache.hasItemGuid(guid) || qua <= 0 || obj == null)
                {
                    Client.Send(new BasicNoOperationMessage());
                    return;
                }

                int newQua = obj.Quantity - qua;
                if (newQua <= 0)
                {
                    Client.Character.InventoryCache.remove(guid);
                    InventoryItemTable.removeItem(guid);
                    Client.Send(new ObjectRemoveMessage(guid));
                }
                else
                {
                    obj.Quantity = newQua;
                    Client.Send(new ObjectQuantityMessage(guid, newQua));
                }
                Client.Send(new AccountStatsMessage(Client.GetCharacter()));
                Client.Send(new InventoryWeightMessage(0, 2000));
            }
            catch (Exception e) { Client.Send(new BasicNoOperationMessage()); }
        }
        public bool TryMergeItem(int TemplateId, string Stats, ItemSlotEnum Slot, int Quantity = 1, InventoryItemModel RemoveItem = null)
        {
            if (Slot < ItemSlotEnum.SLOT_AMULETTE || Slot > ItemSlotEnum.SLOT_BOUCLIER)
            {
                var ItemsCopy = this.ItemsCache.ToArray();

                foreach (var Item in ItemsCopy)
                {
                    if (Item.Value.GetStats().ToItemStats() == Stats && Item.Value.TemplateID == TemplateId && Item.Value.Slot == Slot)
                    {
                        if (RemoveItem != null)
                        {
                            InventoryItemTable.removeItem(RemoveItem.ID);
                            Player.Send(new ObjectRemoveMessage(RemoveItem.ID));
                        }

                        this.UpdateObjectquantity(Item.Value, Item.Value.Quantity + Quantity);
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #6
0
        public static void addInBank(Player character, int guid, int qua)
        {
            InventoryItemModel item = InventoryItemTable.getItem(guid);

            if (item == null)
            {
                character.Send(new BasicNoOperationMessage());
                return;
            }
            if (!character.InventoryCache.hasItemGuid(guid))
            {
                Logger.Error("Le joueur " + character.Name + " a tenter d'ajouter un Item en banque qu'il n'avait pas.");
            }
            if (item.Slot != ItemSlotEnum.SLOT_INVENTAIRE)
            {
                character.Send(new BasicNoOperationMessage());
                return;
            }
            InventoryItemModel bankItem = getSimilarBankItem(character, item);
            int newQua = item.Quantity - qua;

            if (bankItem == null)
            {
                if (newQua <= 0)
                {
                    character.InventoryCache.RemoveItem(item);
                    character.Client.Account.Data.bankItems.Add(item.ID, item);
                    String str = "O+" + item.ID + "|" + item.Quantity + "|" + item.TemplateID + "|" + item.GetStats().ToItemStats();
                    character.Send(new BankUpdateMessage(str));
                    character.Send(new ObjectRemoveMessage(guid));
                }

                else
                {
                    item.Quantity = newQua;
                    bankItem      = getCloneItem(item, qua);
                    InventoryItemTable.addItem(bankItem, true);
                    character.Client.Account.Data.bankItems.Add(bankItem.ID, bankItem);
                    String str = "O+" + bankItem.ID + "|" + bankItem.Quantity + "|" + bankItem.TemplateID + "|" + bankItem.GetStats().ToItemStats();
                    character.Send(new BankUpdateMessage(str));
                    character.Send(new ObjectQuantityMessage(item.ID, item.Quantity));
                }
            }
            else
            {
                if (newQua <= 0)
                {
                    character.InventoryCache.RemoveItem(item);
                    InventoryItemTable.removeItem(item.ID);
                    bankItem.Quantity += item.Quantity;
                    String str = "O+" + bankItem.ID + "|" + bankItem.Quantity + "|" + bankItem.TemplateID + "|" + bankItem.GetStats().ToItemStats();
                    character.Send(new BankUpdateMessage(str));
                    character.Send(new ObjectRemoveMessage(guid));
                }
                else
                {
                    item.Quantity      = newQua;
                    bankItem.Quantity += qua;
                    String str = "O+" + bankItem.ID + "|" + bankItem.Quantity + "|" + bankItem.TemplateID + "|" + bankItem.GetStats().ToItemStats();
                    character.Send(new BankUpdateMessage(str));
                    character.Send(new ObjectQuantityMessage(item.ID, item.Quantity));
                }
            }
            //SEND POD MESSAGE ?
            character.GetClient().Account.Data.Save();
        }
Beispiel #7
0
        private static void ProcessExchangeMountParkRequest(WorldClient Client, string Packet)
        {
            MountPark MP = Client.Character.inMountPark;

            if (MP != null)
            {
                char c = Packet[2];
                Packet = Packet.Substring(3);
                int guid = -1;
                try
                {
                    guid = int.Parse(Packet);
                }
                catch (Exception e)
                {
                };
                switch (c)
                {
                case 'C':    //Parcho => Etable (Stocker)
                    if (guid == -1 || !Client.Character.InventoryCache.hasItemGuid(guid))
                    {
                        return;
                    }
                    InventoryItemModel obj = Client.Character.InventoryCache.GetItem(guid);

                    //on prend la DD demandée
                    int   DDid = -1;
                    Mount DD   = null;
                    if (obj.GetStats().HasEffect(EffectEnum.MountOwner))
                    {
                        DDid = obj.GetStats().GetEffect(EffectEnum.MountOwner).Items;
                        DD   = MountTable.getMount(DDid);
                    }
                    //FIXME mettre return au if pour ne pas créer des nouvelles dindes
                    if (DD == null)
                    {
                        int color = StaticMountTable.getMountColorByParchoTemplate(obj.TemplateID);
                        if (color < 1)
                        {
                            return;
                        }
                        DD = new Mount(color);
                    }
                    DD.Intialize();

                    //On enleve l'Item du Monde et du Perso
                    Client.Character.InventoryCache.remove(guid);
                    InventoryItemTable.removeItem(guid);
                    //on ajoute la dinde a l'étable
                    Client.Account.Data.Mounts.Add(DD.ID, DD);
                    Client.Account.Data.Save();

                    //On envoie les Packet
                    Client.Send(new ObjectRemoveMessage(obj.ID));
                    Client.Send(new ExchangeEndMessage('+', DD.parse()));
                    break;

                case 'c':    //Etable => Parcho(Echanger)
                    Mount DD1 = MountTable.getMount(guid);
                    //S'il n'a pas la dinde
                    if (!Client.Account.Data.Mounts.ContainsKey(DD1.ID) || DD1 == null)
                    {
                        return;
                    }
                    //on retire la dinde de l'étable
                    Client.Account.Data.Mounts.Remove(DD1.ID);

                    GenericStats Stat = new GenericStats();
                    Stat.AddItem(EffectEnum.MountOwner, DD1.ID);
                    Stat.AddSpecialEffect(EffectEnum.MountOwnerName, Client.Character.Name);
                    Stat.AddSpecialEffect(EffectEnum.MountName, DD1.Name);

                    var item = InventoryItemTable.TryCreateItem(StaticMountTable.getMountScroll(DD1.get_color()).ID, Client.Character, 1, -1, Stat.ToItemStats());

                    Client.Send(new ExchangeEndMessage('-', DD1.ID + ""));
                    Stat = null;
                    break;

                case 'g':    //Equiper
                    Mount DD3 = MountTable.getMount(guid);
                    //S'il n'a pas la dinde
                    if (DD3 == null || !Client.Account.Data.Mounts.ContainsKey(DD3.ID) || Client.Character.Mount != null)
                    {
                        return;
                    }
                    DD3.Intialize();
                    Client.Account.Data.Mounts.Remove(DD3.ID);
                    Client.Account.Data.Save();
                    Client.Character.Mount = DD3;

                    //Packets
                    Client.Send(new CharacterRideEventMessage("+", DD3));
                    Client.Send(new ExchangeEndMessage('-', DD3.ID + ""));
                    Client.Send(new CharacterMountXpGive(Client.Character.MountXPGive));
                    break;

                case 'p':    //Equipé => Stocker
                    //Si c'est la dinde équipé
                    if (Client.Character.Mount != null ? Client.Character.Mount.ID == guid : false)
                    {
                        //Si le perso est sur la monture on le fait descendre
                        if (Client.Character.isOnMount())
                        {
                            Client.Character.toogleOnMount();
                        }
                        //Si ca n'a pas réussie, on s'arrete là (Items dans le sac ?)
                        if (Client.Character.isOnMount())
                        {
                            return;
                        }

                        Mount DD2 = Client.Character.Mount;
                        DD2.Intialize();
                        Client.Account.Data.Mounts.Add(DD2.ID, DD2);
                        Client.Account.Data.Save();
                        Client.Character.Mount = null;

                        //Packets
                        Client.Send(new ExchangeEndMessage('+', DD2.parse()));
                        Client.Send(new CharacterRideEventMessage("-", null));
                        Client.Send(new CharacterMountXpGive(Client.Character.MountXPGive));
                    }
                    else    //Sinon...
                    {
                    }
                    break;
                }
            }
            else
            {
                Client.Send(new BasicNoOperationMessage());
                return;
            }
        }
Beispiel #8
0
        public override bool MoveItem(Network.WorldClient Client, Database.Models.InventoryItemModel Item, ushort Quantity, bool Add = false)
        {
            if (Add)
            {
                if (Quantity > Item.Quantity)
                {
                    Quantity = (ushort)Item.Quantity;
                }

                InventoryItemModel ObjectEqualize = getSimilarItem(Item);
                int    newQua = Item.Quantity - Quantity;
                String str;

                if (ObjectEqualize == null)
                {
                    if (newQua <= 0)
                    {
                        Client.Character.InventoryCache.RemoveItem(Item);
                        Mount.Items.Add(Item);
                        str = "O+" + Item.ID + "|" + Item.Quantity + "|" + Item.TemplateID + "|" + Item.GetStats().ToItemStats();
                        Client.Send(new ObjectRemoveMessage(Item.ID));
                    }
                    else
                    {
                        Client.Character.InventoryCache.UpdateObjectquantity(Item, newQua);
                        ObjectEqualize = InventoryItemTable.TryCreateItem(Item.TemplateID, Mount, Quantity, Stats: Item.Effects);
                        str            = "O+" + ObjectEqualize.ID + "|" + ObjectEqualize.Quantity + "|" + ObjectEqualize.TemplateID + "|" + ObjectEqualize.GetStats().ToItemStats();
                    }
                }
                else if (newQua <= 0)
                {
                    Client.Character.InventoryCache.RemoveItem(Item);
                    ObjectEqualize.Quantity += Item.Quantity;
                    InventoryItemTable.removeItem(Item.ID);
                    str = "O+" + ObjectEqualize.ID + "|" + ObjectEqualize.Quantity + "|" + ObjectEqualize.TemplateID + "|" + ObjectEqualize.GetStats().ToItemStats();
                    Client.Send(new ObjectRemoveMessage(Item.ID));
                    InventoryItemTable.Update(ObjectEqualize);
                }
                else
                {
                    Client.Character.InventoryCache.UpdateObjectquantity(Item, newQua);
                    ObjectEqualize.Quantity += Quantity;
                    str = "O+" + ObjectEqualize.ID + "|" + ObjectEqualize.Quantity + "|" + ObjectEqualize.TemplateID + "|" + ObjectEqualize.GetStats().ToItemStats();
                    InventoryItemTable.Update(ObjectEqualize);
                }
                Client.Send(new BankUpdateMessage(str));
                Client.Send(new InventoryWeightMessage(0, 2000)); // TODO PODS
                Client.Send(new MountActualPodMessage(Mount));
                MountTable.Update(Mount);
            }
            else
            {
                if (!Mount.Items.Contains(Item))
                {
                    return(false);
                }
                InventoryItemModel ObjectEqualize = Client.Character.InventoryCache.getSimilarInventoryItem(Item);
                int    newQua = Item.Quantity - Quantity;
                String str;

                if (ObjectEqualize == null)
                {
                    if (newQua <= 0)
                    {
                        Mount.Items.Remove(Item);
                        if (Client.Character.InventoryCache.TryMergeItem(Item.TemplateID, Item.GetStats().ToItemStats(), Item.Slot, Item.Quantity))
                        {
                            InventoryItemTable.removeItem(Item.ID);
                        }
                        else
                        {
                            Client.Character.InventoryCache.Add(Item);
                        }
                        str = "O-" + Item.ID;
                    }
                    else
                    {
                        ObjectEqualize = InventoryItemTable.TryCreateItem(Item.TemplateID, Client.Character, Quantity, Stats: Item.Effects);
                        Item.Quantity  = newQua;
                        str            = "O+" + Item.ID + "|" + Item.Quantity + "|" + Item.TemplateID + "|" + Item.GetStats().ToItemStats();
                    }
                }
                else if (newQua <= 0)
                {
                    Mount.Items.Remove(Item);
                    ObjectEqualize.Quantity += Item.Quantity;
                    Client.Send(new ObjectQuantityMessage(ObjectEqualize.ID, ObjectEqualize.Quantity));
                    InventoryItemTable.removeItem(Item.ID);
                    str = "O-" + Item.ID;
                    InventoryItemTable.Update(ObjectEqualize);
                }
                else
                {
                    Item.Quantity            = newQua;
                    ObjectEqualize.Quantity += Quantity;
                    Client.Send(new ObjectQuantityMessage(ObjectEqualize.ID, ObjectEqualize.Quantity));
                    str = "O+" + Item.ID + "|" + Item.Quantity + "|" + Item.TemplateID + "|" + Item.GetStats().ToItemStats();
                    InventoryItemTable.Update(ObjectEqualize);
                }
                Client.Send(new BankUpdateMessage(str));
                Client.Send(new InventoryWeightMessage(0, 2000)); // TODO PODS
                Client.Send(new MountActualPodMessage(Mount));
                MountTable.Update(Mount);
            }
            return(true);
        }
Beispiel #9
0
        public override bool Finish()
        {
            if (this.myEnd)
            {
                return(false);
            }

            Logger.Debug("PlayerExchange(" + this.myClient1.Account.Username + " - " + this.myClient2.Account.Username + ")::Finish()" +
                         "\n          -- P1(Items=" + string.Join(",", this.myItemsToTrade[this.myClient1].Select(x => x.Key)) + " Kamas=" + this.myKamasToTrade[this.myClient1] + ")" +
                         "\n          -- P2(Items=" + string.Join(",", this.myItemsToTrade[this.myClient2].Select(x => x.Key)) + " Kamas=" + this.myKamasToTrade[this.myClient2] + ")");


            foreach (var ItemData in this.myItemsToTrade[this.myClient1])
            {
                var Item = this.myClient1.Character.InventoryCache.GetItem(ItemData.Key);
                Item.Quantity -= ItemData.Value;

                if (Item.Quantity == 0)
                {
                    InventoryItemTable.removeItem(Item.ID);
                    this.myClient1.Character.InventoryCache.RemoveItem(Item);
                    this.myClient1.Send(new ObjectRemoveMessage(Item.ID));
                }
                else if (Item.Quantity < 0)
                {
                    Logger.Debug("PlayerExchange::Finish() item quantity < 0 : " + myClient1.Character.Name);
                    InventoryItemTable.removeItem(Item.ID);
                    this.myClient1.Character.InventoryCache.RemoveItem(Item);
                }
                else
                {
                    this.myClient1.Character.InventoryCache.UpdateObjectquantity(Item, Item.Quantity);
                }

                InventoryItemTable.TryCreateItem(Item.TemplateID, this.myClient2.Character, ItemData.Value, Stats: Item.Effects);
            }

            foreach (var ItemData in this.myItemsToTrade[this.myClient2])
            {
                var Item = this.myClient2.Character.InventoryCache.GetItem(ItemData.Key);
                Item.Quantity -= ItemData.Value;

                if (Item.Quantity == 0)
                {
                    InventoryItemTable.removeItem(Item.ID);
                    this.myClient2.Character.InventoryCache.RemoveItem(Item);
                    this.myClient2.Send(new ObjectRemoveMessage(Item.ID));
                }
                else if (Item.Quantity < 0)
                {
                    Logger.Debug("PlayerExchange::Finish() item quantity < 0 : " + myClient2.Character.Name);
                    InventoryItemTable.removeItem(Item.ID);
                    this.myClient2.Character.InventoryCache.RemoveItem(Item);
                }
                else
                {
                    this.myClient2.Character.InventoryCache.UpdateObjectquantity(Item, Item.Quantity);
                }

                InventoryItemTable.TryCreateItem(Item.TemplateID, this.myClient1.Character, ItemData.Value, Stats: Item.Effects);
            }

            this.myClient1.Character.InventoryCache.SubstractKamas(this.myKamasToTrade[this.myClient1]);
            this.myClient2.Character.InventoryCache.SubstractKamas(this.myKamasToTrade[this.myClient2]);

            this.myClient1.Character.InventoryCache.AddKamas(this.myKamasToTrade[this.myClient2]);
            this.myClient2.Character.InventoryCache.AddKamas(this.myKamasToTrade[this.myClient1]);

            this.myClient1.Send(new AccountStatsMessage(myClient1.Character));
            this.myClient2.Send(new AccountStatsMessage(myClient2.Character));

            return(true);
        }
Beispiel #10
0
        public override bool MoveItem(Network.WorldClient Client, Database.Models.InventoryItemModel Item, ushort Quantity, bool Add = false)
        {
            if (!Add)
            {
                if (!Npc.Items.ContainsKey(Item.ID))
                {
                    return(false);
                }
                InventoryItemModel ObjectEqualize = Client.Character.InventoryCache.getSimilarInventoryItem(Item);
                int    newQua = Item.Quantity - Quantity;
                String str;

                if (ObjectEqualize == null)
                {
                    if (newQua <= 0)
                    {
                        Npc.Items.Remove(Item.ID);
                        if (Client.Character.InventoryCache.TryMergeItem(Item.TemplateID, Item.GetStats().ToItemStats(), Item.Slot, Item.Quantity))
                        {
                            InventoryItemTable.removeItem(Item.ID);
                        }
                        else
                        {
                            Client.Character.InventoryCache.Add(Item);
                        }
                        str = "O-" + Item.ID;
                    }
                    else
                    {
                        ObjectEqualize = InventoryItemTable.TryCreateItem(Item.TemplateID, Client.Character, Quantity, Stats: Item.Effects);
                        Item.Quantity  = newQua;
                        str            = "O+" + Item.ID + "|" + Item.Quantity + "|" + Item.TemplateID + "|" + Item.GetStats().ToItemStats();
                    }
                }
                else if (newQua <= 0)
                {
                    Npc.Items.Remove(Item.ID);
                    ObjectEqualize.Quantity += Item.Quantity;
                    Client.Send(new ObjectQuantityMessage(ObjectEqualize.ID, ObjectEqualize.Quantity));
                    InventoryItemTable.removeItem(Item.ID);
                    str = "O-" + Item.ID;
                    InventoryItemTable.Update(ObjectEqualize);
                }
                else
                {
                    Item.Quantity            = newQua;
                    ObjectEqualize.Quantity += Quantity;
                    Client.Send(new ObjectQuantityMessage(ObjectEqualize.ID, ObjectEqualize.Quantity));
                    str = "O+" + Item.ID + "|" + Item.Quantity + "|" + Item.TemplateID + "|" + Item.GetStats().ToItemStats();
                    InventoryItemTable.Update(ObjectEqualize);
                }
                Client.Send(new BankUpdateMessage(str));
                Client.Send(new InventoryWeightMessage(0, 2000)); // TODO PODS
                TaxCollectorTable.Update(Npc);

                Npc.LogItems.Add(Item.ID, Item);
            }
            Client.GetCharacter().AddExperience(Npc.XP);
            Npc.LogXP += Npc.XP;
            Npc.XP     = 0;
            TaxCollectorTable.Update(Npc);

            return(true);
        }
Beispiel #11
0
        public void removeByTemplateID(int tID, int count)
        {
            List <InventoryItemModel> list   = this.ItemsCache.Values.Where(x => x.TemplateID == tID).ToList();
            List <InventoryItemModel> remove = new List <InventoryItemModel>();

            int tempCount = count;

            foreach (InventoryItemModel obj in list)
            {
                if (obj.Quantity >= count)
                {
                    int newQua = obj.Quantity - count;
                    if (newQua > 0)
                    {
                        obj.Quantity = newQua;
                        if (this.Player.IsOnline())
                        {
                            Player.Send(new ObjectQuantityMessage(obj.ID, obj.Quantity));
                        }
                    }
                    else
                    {
                        this.ItemsCache.Remove(obj.ID);
                        InventoryItemTable.removeItem(obj.ID);

                        if (this.Player.IsOnline())
                        {
                            Player.Send(new ObjectRemoveMessage(obj.ID));
                        }
                    }
                    return;
                }
                if (obj.Quantity >= tempCount)
                {
                    int newQua = obj.Quantity - tempCount;
                    if (newQua > 0)
                    {
                        obj.Quantity = newQua;
                        if (this.Player.IsOnline())
                        {
                            Player.Send(new ObjectQuantityMessage(obj.ID, obj.Quantity));
                        }
                    }
                    else
                    {
                        remove.Add(obj);
                    }
                    foreach (InventoryItemModel o in remove)
                    {
                        this.ItemsCache.Remove(o.ID);
                        InventoryItemTable.removeItem(o.ID);

                        if (this.Player.IsOnline())
                        {
                            Player.Send(new ObjectRemoveMessage(obj.ID));
                        }
                    }
                }
                else
                {
                    tempCount -= obj.Quantity;
                    remove.Add(obj);
                }
            }
        }