public Character() { this.equipment = new Equipment(this); this.inventory = new Inventory(this); this.cargo = new Cargo(this); this.skills = new Skills(this); this.skillBar = new SkillBar(); this.community = new Community(); }
//buy an item public Boolean insertItemFromInventory(Inventory inv, int itemSlot, int line, int row) { updateCargo(); inv.updateInv(); Item item = null; if(inv.getIndexHold() != -1) item = inv.getHoldingItem(); else item = inv.getItemBySeqIndexing(itemSlot); if(item == null) { Console.WriteLine("[inv -> cargo] tried to move not existing item"); return false; } else Console.WriteLine("moving item: {0} at index {1} and seqIndex {2} and line {3} and row {4}", ItemDataCache.Instance.getItemData(item.getItemID()).getName(), itemSlot, inv.getSeq()[itemSlot], line, row); short amount = item.getQuantity(); Item it; cargo.TryGetValue(row * 100 + line, out it); if(it != null && item.getItemID() == it.getItemID() && item.getQuantity() + it.getQuantity() > ItemDataCache.Instance.getItemData(item.getItemID()).getMaxStack()) { Console.WriteLine("[inv -> cargo] cannot move item, max stack"); return false; } List<int> hash = this.checkBlockingItems(line, row, item); //exception in checkBlockingItems if(hash == null) { Console.WriteLine("Cannot move item [crosses inventory border]"); return false; } //move to an empty slot if(hash.Count == 0) { if(!addItem(line, row, item)) { Console.WriteLine("Cannot buy item [no space]"); return false; } if(inv.getIndexHold() != -1) { inv.setHoldingItem(null); } else { inv.removeItem(itemSlot); } saveCargo(); inv.saveInv(); Console.WriteLine("Item putt3d at free line {0} row {1}", line, row); return true; } //swap if(hash.Count == 1) { owner.getInventory().setIndexHold(seq.IndexOf(hash[0])); owner.getInventory().setIndexToSwap(nextFreeSequence()); if(owner.getInventory().getIndexToSwap() == -1) { Console.WriteLine("Cannot buy item [no free space in inv]"); return false; } Console.WriteLine("Item putt3d at free seq {0}, line {1} row {2}", owner.getInventory().getIndexToSwap(), line, row); owner.getInventory().setHoldingItem(cargo[hash[0]]); removeItemFromCargo(hash[0]); putIntoCargo(line, row, item); seq[owner.getInventory().getIndexToSwap()] = (row * 100) + line; seq[owner.getInventory().getIndexHold()] = -1; inv.removeItem(itemSlot); saveCargo(); inv.saveInv(); return true; } Console.WriteLine("too m4ny it3mz 2 sw4p"); return false; }
public void setInventory(Inventory inventory) { this.inventory = inventory; }