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); }
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)); } }
public virtual void RemoveItem(ISkillArgs args, ItemPosition ip) { ip.key.Removed(args); RemoveItemPosition(ip); if (inventoryUI != null) { inventoryUI.DeleteItem(args, this, ip); } if (inventoryUI != null && inventoryUI.MoveAction != null) { args.TempUsePara(new StringPara("from", this.name)); args.TempUse("item", ip); inventoryUI.MoveAction.Act(args); args.ResumePara("from"); args.Resume("item"); } }