public override void DoAction(IEventArgs args) { FreeRuleEventArgs fr = (FreeRuleEventArgs)args; IGameUnit player = GetPlayer(args); if (player != null) { IParable pa = fr.GetUnit(item); if (pa is ItemPosition) { ItemPosition ip = (ItemPosition)pa; FreeData fd = (FreeData)player; ItemInventory toInv = fd.freeInventory.GetInventoryManager().GetInventory(FreeUtil.ReplaceVar(toInventory, args)); if (toInv != null) { int toX = 0; int toY = 0; if (string.IsNullOrEmpty(x) && string.IsNullOrEmpty(y)) { int[] next = toInv.GetNextEmptyPosition(ip.GetKey()); toX = next[0]; toY = next[1]; } else { toX = FreeUtil.ReplaceInt(x, args); toY = FreeUtil.ReplaceInt(y, args); } ItemInventoryUtil.MovePosition(ip, toInv, toX, toY, fr); } } } }
public static void MoveItem(string key, FreeData fd, ISkillArgs args, int x, int y, int toGlobalX, int toGlobalY, int stageWidth, int stageHeigth, int fromGlobalX, int fromGlobalY) { toGlobalY = stageHeigth - toGlobalY; fromGlobalY = stageHeigth - fromGlobalY; ItemPosition ip = GetItemPosition(args, key, fd.freeInventory.GetInventoryManager()); if (ip != null) { InventoryManager invManager = fd.freeInventory.GetInventoryManager(); ItemInventory fromInv = ip.GetInventory(); ItemInventory toInv = null; FreeUIUtil.Rectangle rec = null; foreach (string inv in invManager.GetInventoryNames()) { ItemInventory ii = invManager.GetInventory(inv); if (ii != null && ii.IsOpen()) { rec = ((SimpleInventoryUI)ii.GetInventoryUI()).GetItemRegion(args, stageWidth, stageHeigth); if (rec.In(toGlobalX, toGlobalY)) { toInv = ii; break; } } } if (toInv == fromInv || toInv == null) { ItemInventoryUtil.MovePosition(ip.GetInventory(), ip.GetInventory(), (SimpleInventoryUI)fromInv.GetInventoryUI(), (SimpleInventoryUI)fromInv.GetInventoryUI(), ip, x, y, args); } else { FreeUIUtil.Rectangle itemRec = ((SimpleInventoryUI)fromInv.GetInventoryUI()).GetItemRegion(fromInv, args, stageWidth, stageHeigth, ip); ItemInventoryUtil.MovePosition(ip.GetInventory(), invManager.GetInventory(toInv.GetName()), (SimpleInventoryUI)fromInv.GetInventoryUI(), (SimpleInventoryUI)toInv.GetInventoryUI(), ip, toGlobalX - rec.x - (fromGlobalX - itemRec.x), toGlobalY - rec.y - (fromGlobalY - itemRec.y), args); } } }
public static void DragItem(string key, FreeData fd, ISkillArgs args, string toKey) { ItemPosition ip = GetItemPosition(args, key, fd.freeInventory.GetInventoryManager()); if (ip == null) { ItemInventory inv = fd.freeInventory.GetInventoryManager().GetInventory(key.Trim()); if (inv != null && inv.GetInventoryUI() is UnityOneInventoryUi) { if (inv.posList.Count > 0) { ip = inv.posList[0]; } } } ItemPosition toIp = null; if (!StringUtil.IsNullOrEmpty(toKey)) { toIp = GetItemPosition(args, toKey, fd.freeInventory.GetInventoryManager()); } if (ip != null) { InventoryManager invManager = fd.freeInventory.GetInventoryManager(); ItemInventory fromInv = ip.GetInventory(); ItemInventory toInv = null; if (toIp != null) { toInv = toIp.GetInventory(); } else { string[] ss = toKey.Split(','); toInv = fd.freeInventory.GetInventoryManager().GetInventory(ss[0].Trim()); } int x = -1; int y = -1; if (toIp != null) { x = toIp.x; y = toIp.y; } else if (toInv != null) { if (toInv.GetName() == ChickenConstant.BagDefault) { foreach (ItemPosition old in toInv.GetItems()) { if (old.GetKey().GetKey() == ip.GetKey().GetKey() && old.GetCount() < ip.GetKey().GetItemStack()) { x = old.GetX(); y = old.GetY(); break; } } } if (x < 0) { int[] pos = toInv.GetNextEmptyPosition(ip.GetKey()); x = pos[0]; y = pos[1]; } } if (toInv != null && fromInv != toInv) { if (toInv.GetName() == ChickenConstant.BagDefault) { if (BagCapacityUtil.CanAddToBag(args, fd, ip)) { ItemInventoryUtil.Move(fromInv, toInv, ip, x, y, args, (FreeRuleEventArgs)args, fromInv.GetInventoryUI(), toInv.GetInventoryUI()); } } else { ItemInventoryUtil.Move(fromInv, toInv, ip, x, y, args, (FreeRuleEventArgs)args, fromInv.GetInventoryUI(), toInv.GetInventoryUI()); } } else { if (toInv == null) { //fromInv.GetInventoryUI().ReDraw(args, fromInv, true); } else { //fromInv.GetInventoryUI().ReDraw(args, fromInv, true); } } } }