123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- 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<PomeloException, EquipResponse> 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<int, pomelo.item.Item> grid = new HashMap<int, pomelo.item.Item>();
- 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<PomeloException, OpenBagGridResponse> 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;
- // }
- // }
- }
- }
- }
|