示例#1
0
        public int[] GetNextEmptyPosition(FreeItem item)
        {
            for (int i = 0; i <= row - item.GetGridHeight(); i++)
            {
                for (int j = 0; j <= column - item.GetGridWidth(); j++)
                {
                    bool filled = false;
                    for (int ii = i; ii < i + item.GetGridHeight(); ii++)
                    {
                        for (int jj = j; jj < j + item.GetGridWidth(); jj++)
                        {
                            if (ins[ii][jj])
                            {
                                filled = true;
                            }
                        }
                    }
                    if (!filled)
                    {
                        return(new int[] { j, i });
                    }
                }
            }

            return(new int[] { 0, 0 });
        }
示例#2
0
        private bool AddNewItem(ISkillArgs args, FreeItem item, bool useMove)
        {
            for (int i = 0; i <= row - item.GetGridHeight(); i++)
            {
                for (int j = 0; j <= column - item.GetGridWidth(); j++)
                {
                    bool filled = false;
                    for (int ii = i; ii < i + item.GetGridHeight(); ii++)
                    {
                        for (int jj = j; jj < j + item.GetGridWidth(); jj++)
                        {
                            if (ins[ii][jj])
                            {
                                filled = true;
                            }
                        }
                    }
                    if (!filled)
                    {
                        ItemPosition ip = new ItemPosition(item, j, i);
                        ip.inventory = this;
                        posList.Add(ip);
                        for (int ii_1 = i; ii_1 < i + item.GetGridHeight(); ii_1++)
                        {
                            for (int jj = j; jj < j + item.GetGridWidth(); jj++)
                            {
                                ins[ii_1][jj] = true;
                            }
                        }
                        if (inventoryUI != null && args != null)
                        {
                            inventoryUI.AddItem(args, this, ip);
                        }
                        //if ("default".Equals(name))
                        //{
                        args.TempUsePara(new StringPara("inventory", name));
                        item.Added(args);
                        if (inventoryUI != null && inventoryUI.MoveAction != null && useMove)
                        {
                            args.TempUsePara(new StringPara("to", this.name));
                            args.TempUse("item", ip);

                            inventoryUI.MoveAction.Act(args);

                            args.Resume("item");
                            args.ResumePara("to");
                        }
                        args.ResumePara("inventory");
                        //}
                        return(true);
                    }
                }
            }
            if (inventoryUI != null)
            {
                inventoryUI.Error(args, this, "物品栏已满");
            }
            return(false);
        }
示例#3
0
 public ItemPosition(FreeItem key, int x, int y)
     : base()
 {
     this.key       = key;
     this.x         = x;
     this.y         = y;
     this.count     = key.GetCount();
     this.keyFields = new ObjectFields(key);
 }
示例#4
0
 private ItemPosition GetExisted(FreeItem item)
 {
     foreach (ItemPosition ip in posList)
     {
         if (ip.key.GetKey().Equals(item.GetKey()))
         {
             return(ip);
         }
     }
     return(null);
 }
示例#5
0
        public virtual bool AddItem(ISkillArgs args, FreeItem item, bool useMove)
        {
            bool existed = (GetExisted(item) != null);

            if (existed)
            {
                if (item.IsUnique())
                {
                    if (inventoryUI != null)
                    {
                        inventoryUI.Error(args, this, "已存在唯一物品'" + item.GetName() + "'");
                    }
                    return(false);
                }
            }
            ItemPosition old = GetNotFullExisted(item);

            if (old != null)
            {
                int addCount = item.GetCount();
                old.SetKey(item);
                int removed = Math.Min(item.GetItemStack() - old.GetCount(), item.GetCount());
                old.SetCount(old.GetCount() + removed);
                if (inventoryUI != null && args != null)
                {
                    inventoryUI.UpdateItem(args, this, old);
                }

                if (removed < addCount)
                {
                    FreeItem clone = item.Clone();
                    clone.SetCount(addCount - removed);
                    AddNewItem(args, clone, false);
                }

                args.TempUsePara(new StringPara("inventory", name));
                item.Added(args);
                if (inventoryUI != null && inventoryUI.MoveAction != null && useMove)
                {
                    args.TempUsePara(new StringPara("to", this.name));
                    inventoryUI.MoveAction.Act(args);
                    args.ResumePara("to");
                }
                args.ResumePara("inventory");



                return(true);
            }
            else
            {
                return(AddNewItem(args, item, useMove));
            }
        }
示例#6
0
        public virtual void SetKey(FreeItem key)
        {
            this.key = key;

            this.keyFields.SetObj(key);

            IniParameters();
            foreach (IPara p in key.GetParameters().GetMapPara().Values)
            {
                paras.AddPara(p);
            }
        }
示例#7
0
 private ItemPosition GetNotFullExisted(FreeItem item)
 {
     foreach (ItemPosition ip in posList)
     {
         if (ip.key.GetKey().Equals(item.GetKey()))
         {
             if (ip.GetCount() < item.GetItemStack())
             {
                 return(ip);
             }
         }
     }
     return(null);
 }
示例#8
0
        public ItemPosition GetItemPosition(FreeItem item)
        {
            foreach (string invName in inventoryManager.GetInventoryNames())
            {
                ItemInventory ii = inventoryManager.GetInventory(invName);
                foreach (ItemPosition ip in ii.GetItems())
                {
                    if (ip.GetKey().GetId() == item.GetId())
                    {
                        return(ip);
                    }
                }
            }

            return(null);
        }