using CommonLang; using CommonLang.IO; using pomelo.area; using Pomelo.DotNetClient; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace XmdsBattleClientBot.Bot { partial class BotClient { public InventoryManager CurrentInventories { get; private set; } private void callback_gs_BagItemUpdatePush(BagItemUpdatePush on) { if (on.s2c_data != null) { CurrentInventories.Refresh(on); } } public virtual void gs_EquipItemByID(string id, Action action = null) { int index; var item = CurrentInventories.Bag.GetItemByID(id, out index); if (item != null) { if(item.code.CompareTo("lweap1-test") != 0 && item.code.CompareTo("lclot1-test") != 0) { return; } client.GameSocket.equipHandler.equipRequest(index, (err, rsp) => { if (action != null) { action(err, rsp); } }); } } public enum BagType { Bag = 1, Warehouse = 2, Recycled = 4, } public class InventoryStore { public BagType Type { get; private set; } public int TotalCount { get; private set; } public int GridCount { get; private set; } public int GridPrice { get; private set; } private readonly BotClient bot; private HashMap grid = new HashMap(); internal InventoryStore(BotClient bot, pomelo.player.Store store) { this.bot = bot; this.Type = (BagType)store.type; this.TotalCount = store.bagTotalCount; this.GridCount = store.bagGridCount; this.GridPrice = store.gridPrice; foreach (var g in store.bagGrids) { this.grid.Put(g.gridIndex, g.item); } } internal void Refresh(BagItemUpdatePush on) { foreach (var g in on.s2c_data) { this.grid.Put(g.gridIndex, g.item); } } public void OpenStorage(int count, Action action = null) { if (this.TotalCount > this.GridCount) { bot.client.GameSocket.bagHandler.openBagGridRequest( (int)BotClient.BagType.Bag, Math.Min(count, this.TotalCount - this.GridCount), (e, r) => { if (action != null) action(e, r); }); } } public pomelo.item.Item GetItemByIndex(int index) { return grid[index]; } public pomelo.item.Item GetItemByID(string id, out int index) { foreach (var item in grid) { if (item.Value != null && item.Value.id == id) { index = item.Key; return item.Value; } } index = -1; return null; } } public class InventoryManager { private readonly BotClient bot; private InventoryStore bag_grid; private InventoryStore warehouse_grid; private InventoryStore recyled_grid; public InventoryStore Bag { get { return bag_grid; } } public InventoryStore Warehouse { get { return warehouse_grid; } } public InventoryStore Recycled { get { return recyled_grid; } } internal InventoryManager(BotClient bot) { this.bot = bot; this.bag_grid = new InventoryStore(bot, bot.PlayerData.store.bag); this.warehouse_grid = new InventoryStore(bot, bot.PlayerData.store.wareHouse); this.recyled_grid = new InventoryStore(bot, bot.PlayerData.store.recycle); } internal void Refresh(BagItemUpdatePush on) { switch ((BagType)on.s2c_type) { case BagType.Bag: bag_grid.Refresh(on); break; case BagType.Warehouse: warehouse_grid.Refresh(on); break; case BagType.Recycled: recyled_grid.Refresh(on); break; } } // public pomelo.item.Item GetRandomItem(BotClient.BagType type, out int index) // { // switch ((BagType)on.s2c_type) // { // case BagType.Bag: // bag_grid.Refresh(on); // break; // case BagType.Warehouse: // warehouse_grid.Refresh(on); // break; // case BagType.Recycled: // recyled_grid.Refresh(on); // break; // } // } } } }