Ejemplo n.º 1
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        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);
                }
            }
        }