private static void ExchangeItem(ItemInventory fromIn, ItemInventory toIn, IInventoryUI fromUI, IInventoryUI toUI, ItemPosition ip, ItemPosition old, ISkillArgs args) { if (fromIn.CanExchange(old, ip) && fromIn.IsCanDrop(old, args)) { fromIn.ExchangeItemPosition(old, ip); HandleMoveAction(fromIn, toIn, fromUI, toUI, ip, args, true); HandleMoveAction(toIn, fromIn, toUI, fromUI, old, args, true); HandleMoveAction(fromIn, toIn, fromUI, toUI, ip, args, false); HandleMoveAction(toIn, fromIn, toUI, fromUI, old, args, false); if (fromIn == toIn) { fromUI.UpdateItem(args, fromIn, old); fromUI.UpdateItem(args, fromIn, ip); } else { fromUI.AddItem(args, fromIn, old); toUI.AddItem(args, toIn, ip); } } else { fromIn.ChangePosition(ip, fromIn, ip.GetX(), ip.GetY()); if (fromUI.CanNotMoveAction != null) { fromUI.CanNotMoveAction.Act(args); } fromUI.UpdateItem(args, fromIn, ip); } }
private static void MoveItem(int countX, int countY, ItemInventory fromIn, ItemInventory toIn, IInventoryUI fromUI, IInventoryUI toUI, ItemPosition ip, ItemPosition old, ISkillArgs args) { if (fromIn.CanMoveTo(ip, toIn, countX, countY)) { fromIn.ChangePosition(ip, toIn, countX, countY); HandleMoveAction(fromIn, toIn, fromUI, toUI, ip, args); if (fromIn == toIn) { fromUI.UpdateItem(args, fromIn, ip); } else { fromUI.DeleteItem(args, fromIn, ip); toUI.AddItem(args, toIn, ip); } } else { fromIn.ChangePosition(ip, fromIn, ip.GetX(), ip.GetY()); if (fromUI.CanNotMoveAction != null) { fromUI.CanNotMoveAction.Act(args); } fromUI.UpdateItem(args, fromIn, ip); } }
private static void ChangeItemStack(int delta, ItemInventory fromIn, ItemInventory toIn, IInventoryUI fromUI, IInventoryUI toUI, ItemPosition ip, ItemPosition old, ISkillArgs args) { if (ip.GetCount() <= delta) { RemoveItem(fromIn, ip, args); HandleMoveAction(fromIn, toIn, fromUI, toUI, ip, args, true); old.SetCount(old.GetCount() + (int)MyMath.Min(delta, ip.GetCount())); toUI.UpdateItem(args, toIn, old); } else { old.SetCount(old.GetKey().GetItemStack()); ip.SetCount(ip.GetCount() - delta); toUI.UpdateItem(args, toIn, old); fromUI.UpdateItem(args, fromIn, ip); } }
public virtual void UseItem(ISkillArgs args, ItemPosition ipos, int count) { ItemPosition remove = null; ItemPosition useIp = null; foreach (ItemPosition ip in posList) { if (ip.GetX() == ipos.x && ip.GetY() == ipos.y) { useIp = ip; if (ip.GetKey().IsConsume()) { ip.count = ip.count - count; } if (ip.count <= 0 && ipos.key.IsConsume()) { remove = ip; } } } if (remove != null) { RemoveItemPosition(remove); } if (inventoryUI != null && ipos.key.IsConsume()) { if (remove != null) { inventoryUI.DeleteItem(args, this, remove); } else { if (useIp != null) { inventoryUI.UpdateItem(args, this, useIp); } } } if (inventoryUI != null && useIp != null) { inventoryUI.UseItem(args, this, useIp); } }
public static void Move(ItemInventory fromIn, ItemInventory toIn, ItemPosition ip, int countX, int countY, ISkillArgs args, FreeRuleEventArgs fr, IInventoryUI fromUI, IInventoryUI toUI) { if (fromIn != toIn) { fr.TempUse(PARA_ITEM, ip); bool canDrop = toIn.IsCanDrop(ip, args); // 如果toIn 不可以拖入物品 if (!canDrop) { fromUI.UpdateItem(args, fromIn, ip); if (toIn.GetDropAction() != null) { toIn.GetDropAction().Act(args); } //HandleMoveAction(fromIn, toIn, fromUI, toUI, ip, args); fr.Resume(PARA_ITEM); return; } fr.Resume(PARA_ITEM); } // 已有 ItemPosition[] olds = toIn.GetItem(countX, countY, ip.GetKey().GetGridWidth(), ip.GetKey().GetGridHeight()); ItemPosition old = null; if (olds.Length == 1) { old = olds[0]; if (old != ip) { fr.TempUse(PARA_ITEM, ip); if (old.GetKey().GetKey().Equals(ip.GetKey().GetKey())) { int delta = old.GetKey().GetItemStack() - old.GetCount(); if (delta > 0) { // 堆叠物品 ChangeItemStack(delta, fromIn, toIn, fromUI, toUI, ip, old, args); } else { // 交换物品位置 ExchangeItem(fromIn, toIn, fromUI, toUI, ip, old, args); } } else { if (!ip.DragTo(args, old)) { ExchangeItem(fromIn, toIn, fromUI, toUI, ip, old, args); } else { if (ip.GetInventory() != null) { fromUI.UpdateItem(args, fromIn, ip); } } } fr.Resume(PARA_ITEM); return; } } fr.TempUse(PARA_ITEM, ip); MoveItem(countX, countY, fromIn, toIn, fromUI, toUI, ip, old, args); fr.Resume(PARA_ITEM); }