Exemplo n.º 1
0
        public static void LoadItems()
        {
            var reader = DatabaseManager.Provider.ExecuteReader("SELECT * FROM bidhouse_items");
            int nbr    = 0;
            var BItems = new List <BidHouseItem>();

            while (reader.Read())
            {
                //TODO Load item after consulting HDV .. but i think not good idea
                BidHouse bHouse       = null;
                var      ItemToDelete = new List <long>();
                if (!Cache.TryGetValue(reader.GetInt16("map"), out bHouse))
                {
                    continue;
                }

                var BItem = new BidHouseItem()
                {
                    Price    = reader.GetInt64("price"),
                    Quantity = reader.GetInt32("count"),
                    Owner    = reader.GetInt32("owner"),
                    ItemID   = reader.GetInt64("item"),
                    BH       = bHouse
                };

                BItems.Add(BItem);

                nbr++;
            }
            reader.Close();
            BItems.ForEach(x => x.Initialize());

            Logger.Info("Loaded @'" + nbr + "'@ BidHouse Items");
        }
Exemplo n.º 2
0
        private void OnBidHouseItemRemoved(BidHouseItem item, BidHouseCategory category, bool categoryDeleted)
        {
            if (!Types.Contains((int)item.Template.TypeId))
            {
                return;
            }

            if (!BidHouseManager.Instance.GetBidHouseCategories(item.Template.Id, MaxItemLevel).Any())
            {
                CurrentViewedItem = 0;
                InventoryHandler.SendExchangeBidHouseGenericItemRemovedMessage(Character.Client, item);
                UpdateCurrentViewedItem(item.Template.Id);

                return;
            }

            if (CurrentViewedItem != item.Template.Id)
            {
                return;
            }

            if (categoryDeleted)
            {
                InventoryHandler.SendExchangeBidHouseInListRemovedMessage(Character.Client, category);
            }
            else
            {
                InventoryHandler.SendExchangeBidHouseInListUpdatedMessage(Character.Client, category);
            }
        }
Exemplo n.º 3
0
        public Boolean RemoveBidHouseItemAtLine(BidHouseItem BHI)
        {
            byte    cat       = (byte)(BHI.getQuantity(false) - 1);
            Boolean canDelete = Categories[cat].Remove(BHI);

            Tri(cat);
            return(canDelete);
        }
Exemplo n.º 4
0
        public Boolean RemoveItem(BidHouseItem BHI)
        {
            Boolean canDelete = Lines[BHI.LineID].RemoveBidHouseItemAtLine(BHI);

            if (Lines[BHI.LineID].CategorieIsBlank())
            {
                Lines.Remove(BHI.LineID);
            }
            return(canDelete);
        }
Exemplo n.º 5
0
 public Line(int lineID, BidHouseItem BHI)
 {
     this.LineID     = lineID;
     this.StringStat = BHI.Item.GetStats().ToItemStats();
     for (int i = 0; i < 3; i++)
     {
         Categories.Add(new List <BidHouseItem>());
     }
     addBidHouseObjectAtLine(BHI);
 }
Exemplo n.º 6
0
        public Boolean removeModel(BidHouseItem BHI)
        {
            Boolean canDelete = false;

            (Items[BHI.Item.TemplateID]).RemoveItem(BHI);
            if (canDelete = Items[BHI.Item.TemplateID].isEmpty())
            {
                Items.Remove(BHI.Item.TemplateID);
            }
            return(canDelete);
        }
Exemplo n.º 7
0
 public void addModel(BidHouseItem BHI)
 {
     if (!Items.ContainsKey(BHI.Item.TemplateID))
     {
         Items.Add(BHI.Item.TemplateID, new Model(BHI.Item.TemplateID, BHI));
     }
     else
     {
         Items[BHI.Item.TemplateID].addBidHouseItemToLine(BHI);
     }
 }
Exemplo n.º 8
0
 public static void addBidHouseItem(int owner, int hdvID, BidHouseItem BHI)
 {
     if (!BHITEMS.ContainsKey(owner))
     {
         BHITEMS.Add(owner, new Dictionary <int, List <BidHouseItem> >());
     }
     if (!BHITEMS[owner].ContainsKey(hdvID))
     {
         BHITEMS[owner].Add(hdvID, new List <BidHouseItem>());
     }
     BHITEMS[owner][hdvID].Add(BHI);
 }
Exemplo n.º 9
0
        public Boolean addBidHouseObjectAtLine(BidHouseItem BHI)
        {
            if ((!CategorieIsBlank()) && (!HasEqualStats(BHI)))
            {
                return(false);
            }
            BHI.LineID = this.LineID;
            byte index = (byte)(BHI.QuantityType(false) - 1);

            Categories[index].Add(BHI);
            Tri(index);
            return(true);
        }
Exemplo n.º 10
0
        public void addBidHouseItemToLine(BidHouseItem BHI)
        {
            foreach (var line in Lines.Values)
            {
                if (line.addBidHouseObjectAtLine(BHI))
                {
                    return;
                }
            }
            int lineID = BidHouseTable.NextLineID();

            Lines.Add(lineID, new Line(lineID, BHI));
        }
Exemplo n.º 11
0
 public static void Add(BidHouseItem BHI)
 {
     try
     {
         MySqlCommand Command = new MySqlCommand()
         {
             Connection  = DatabaseManager.Provider.getConnection(),
             CommandText = "REPLACE INTO `bidhouse_items` VALUES(@map,@owner,@price,@count,@item);",
         };
         Command.Prepare();
         Command.Parameters.AddWithValue("@map", BHI.MapID);
         Command.Parameters.AddWithValue("@owner", BHI.Owner);
         Command.Parameters.AddWithValue("@price", BHI.Price);
         Command.Parameters.AddWithValue("@count", BHI.getQuantity(false));
         Command.Parameters.AddWithValue("@item", BHI.Item.ID);
         Command.ExecuteNonQuery();
     }
     catch (Exception e)
     {
         Logger.Error("Can't execute query : " + e.ToString());
     }
 }
Exemplo n.º 12
0
 public static void SendExchangeBidHouseGenericItemRemovedMessage(IPacketReceiver client, BidHouseItem item)
 {
     client.Send(new ExchangeBidHouseGenericItemRemovedMessage((short)item.Template.Id));
 }
Exemplo n.º 13
0
 public Boolean HasEqualStats(BidHouseItem BHI)
 {
     return((StringStat.Equals(BHI.Item.GetStats().ToItemStats())) && (BHI.Item.Template.Type != 85));
 }
Exemplo n.º 14
0
 public Model(int templateID, BidHouseItem BHI)
 {
     this.TemplateID = templateID;
     addBidHouseItemToLine(BHI);
 }
Exemplo n.º 15
0
 public override bool MoveItem(WorldClient Client, Database.Models.InventoryItemModel Item, ushort Quantity, bool Add = false)
 {
     if (Add)
     {
         long Taxe = (long)(Price * (Market.SellTaxe / 100));
         if (myClient.Account.Data.canTaxBidHouseItem(Market.HdvID) >= Market.countItem)
         {
             myClient.Send(new TextInformationMessage(Libs.Enumerations.TextInformationTypeEnum.INFO, 58));
             return(false);
         }
         if (myClient.Character.Kamas < Taxe)
         {
             myClient.Send(new TextInformationMessage(Libs.Enumerations.TextInformationTypeEnum.ERREUR, 76));
             return(false);
         }
         myClient.Character.InventoryCache.SubstractKamas(Taxe);
         int cantReal  = (int)(Math.Pow(10, Quantity) / 10);
         int nuevaCant = Item.Quantity - cantReal;
         if (nuevaCant <= 0)
         {
             myClient.Character.InventoryCache.RemoveItem(Item);
             myClient.Character.Send(new ObjectRemoveMessage(Item.ID));
         }
         else
         {
             Item.Quantity -= cantReal;
             myClient.Send(new ObjectQuantityMessage(Item.ID, Item.Quantity));
             Item = InventoryItemTable.TryCreateItem(Item.TemplateID, quantity: cantReal, Stats: Item.GetStats().ToItemStats());
         }
         var MarketItem = new BidHouseItem()
         {
             Price    = Price,
             Quantity = Quantity,
             Owner    = myClient.Account.ID,
             Item     = Item,
         };
         Market.addObject(MarketItem);
         BidHouseTable.Add(MarketItem);
         myClient.Send(new ExchangeMoveDistantObject('+', "", MarketItem.SerializeAsDisplayEquipmentOnMarket()));
         Client.Send(new AccountStatsMessage(myClient.Character));
     }
     else
     {
         var          MarketID = Market.HdvID;
         BidHouseItem BHI      = null;
         try
         {
             foreach (var BH in myClient.Account.Data.BHI[MarketID])
             {
                 if (BH.LineID == ItemID)
                 {
                     BHI = BH;
                     break;
                 }
             }
         }
         catch (Exception e)
         {
             return(false);
         }
         if (BHI == null)
         {
             return(false);
         }
         myClient.Account.Data.BHI[MarketID].Remove(BHI);
         var Object = BHI.Item;
         myClient.Character.InventoryCache.Add(Object);
         Market.DestroyObject(BHI);
         BidHouseTable.Delete(BHI.ItemID);
         myClient.Send(new ExchangeMoveDistantObject('-', "", ItemID + ""));
     }
     return(true);
 }