public void PutItemToBody(BodySlot slot, Item item) { // unequip existing item on specified slot // if item count is too large if (item.Count > 1) { // put excessive items back to pack Item newitem = new Item(item, 1); item.Count--; ItemsPack.PutItem(ItemsPack.Count, item); item = newitem; } Item currentItem = GetItemFromBody(slot); if (currentItem != null) { ItemsPack.PutItem(ItemsPack.Count, ItemsBody.TakeItem(currentItem, 1)); } if (item.Class.Option.TwoHanded == 2) { // unequip shield for 2-handed weapon Item shield = GetItemFromBody(BodySlot.Shield); if (shield != null) { ItemsPack.PutItem(ItemsPack.Count, ItemsBody.TakeItem(shield, 1)); } } ItemsBody.PutItem(ItemsBody.Count, item); UpdateItems(); DoUpdateInfo = true; }
public static void DropItem(MapHuman human, Item item, int x, int y) { if (NetworkManager.IsClient) { // check what this item is. if (item.Parent == human.ItemsBody) { SendItemMove(ServerCommands.ItemMoveLocation.UnitBody, ServerCommands.ItemMoveLocation.Ground, item.Class.Option.Slot, -1, item.Count, human, x, y); } else if (item.Parent == human.ItemsPack) { SendItemMove(ServerCommands.ItemMoveLocation.UnitPack, ServerCommands.ItemMoveLocation.Ground, item.Index, -1, item.Count, human, x, y); } } else { // check coordinates if (Math.Abs(human.X - x) > 2 || Math.Abs(human.Y - y) > 2) { x = human.X; y = human.Y; } ItemPack pack = new ItemPack(); pack.PutItem(0, new Item(item, item.Count)); MapLogic.Instance.PutSackAt(x, y, pack, false); } }
public bool Process(ServerClient client) { if (client.State != ClientState.Playing) { return(false); } Player player = MapLogic.Instance.GetNetPlayer(client); if (player == null) { return(false); // huehue, same as "order error" in a2server.exe, except we just boot them } MapUnit unit = MapLogic.Instance.GetUnitByTag(UnitTag); // we can't do anything with units that don't belong to our player. if (unit.Player != player) { return(true); } // right now only body<->pack is supported, no shop or ground items Item item = null; switch (Destination) { case ItemMoveLocation.UnitBody: if (unit == null) { return(true); } item = GetItem(unit); if (!unit.IsItemUsable(item)) { return(true); // can't use } item = TakeItem(unit); if (item == null) { return(true); } unit.PutItemToBody((MapUnit.BodySlot)item.Class.Option.Slot, item); break; case ItemMoveLocation.UnitPack: if (unit == null) { return(true); } item = TakeItem(unit); if (item == null) { return(true); } unit.ItemsPack.PutItem(DestinationIndex, item); break; case ItemMoveLocation.Ground: if (unit == null) { return(true); } item = TakeItem(unit); if (item == null) { return(true); } if (Math.Abs(CellX - unit.X) > 2 || Math.Abs(CellY - unit.Y) > 2) { CellX = unit.X; CellY = unit.Y; } ItemPack pack = new ItemPack(); pack.PutItem(0, new Item(item, item.Count)); MapLogic.Instance.PutSackAt(CellX, CellY, pack, false); break; } Server.NotifyUnitPack(unit); return(true); }