/// <summary> /// Picks an item up after client request /// </summary> /// <returns>true if the item was picked up, or false if the player could not pick up the item.</returns> public bool PickUp(Item item) { System.Diagnostics.Debug.Assert(!_inventoryStash.Contains(item) && !_equipment.IsItemEquipped(item), "Item already in inventory"); // TODO: Autoequip when equipment slot is empty bool success = false; if (!_inventoryStash.HasFreeSpace(item)) { // Inventory full _owner.InGameClient.SendMessage(new ACDPickupFailedMessage() { ItemID = item.DynamicID, Reason = ACDPickupFailedMessage.Reasons.InventoryFull }); } else { _inventoryStash.AddItem(item); if (_owner.GroundItems.ContainsKey(item.DynamicID)) _owner.GroundItems.Remove(item.DynamicID); success = true; } AcceptMoveRequest(item); return success; }
private void AcceptMoveRequest(Item item) { /*_owner.InGameClient.SendMessage(new ACDInventoryPositionMessage() { ItemID = item.DynamicID, InventoryLocation = item.InventoryLocationMessage, Field2 = 1 // what does this do? // 0 - source item not disappearing from inventory, 1 - Moving, any other possibilities? its an int32 });*/ }
private uint[] _equipment; // array of equiped items_id (not item) public Equipment(Player owner){ this._equipment = new uint[17]; this._owner = owner; this.Items = new Dictionary<uint, Item>(); this._inventoryGold = ItemGenerator.CreateGold(_owner, 0); this._inventoryGold.Attributes[GameAttribute.ItemStackQuantityLo] = 0; this._inventoryGold.SetInventoryLocation(18, 0, 0); this._inventoryGold.Owner = _owner; this.Items.Add(_inventoryGold.DynamicID,_inventoryGold); }
/// <summary> /// Equips an item in an equipment slot /// </summary> public void EquipItem(Item item, int slot) { _equipment[slot] = item.DynamicID; if (!Items.ContainsKey(item.DynamicID)) Items.Add(item.DynamicID, item); item.Owner = _owner; item.Attributes[GameAttribute.Item_Equipped] = true; // Probaly should be handled by Equipable class /fasbat item.Attributes.SendChangedMessage(_owner.InGameClient, item.DynamicID); item.SetInventoryLocation(slot, 0, 0); }
/// <summary> /// Removes an item from the equipment slot it uses /// returns the used equipmentSlot /// </summary> public int UnequipItem(Item item) { for (int i = 0; i < EquipmentSlots; i++) { if (_equipment[i] == item.DynamicID) { _equipment[i] = 0; item.SetInventoryLocation(-1, -1, -1); item.Owner = null; return i; } } return 0; }
/// <summary> /// Equips an item in an equipment slot /// </summary> public void EquipItem(Item item, int slot) { _equipment[slot] = item.DynamicID; item.Owner = _owner; item.SetInventoryLocation(slot, 0, 0); item.Attributes[GameAttributeB.Item_Equipped] = true; if (slot == (int)EquipmentSlotId.Off_Hand) { if (_equipment[(int)EquipmentSlotId.Main_Hand] != 0) { Item mainWeapon = GetEquipment(EquipmentSlotId.Main_Hand); GameAttributeMap other = new GameAttributeMap(); mainWeapon.Attributes[GameAttribute.Damage_Weapon_Delta_Total_MainHand] = mainWeapon.Attributes[GameAttribute.Damage_Weapon_Delta_Total]; mainWeapon.Attributes[GameAttribute.Damage_Weapon_Delta_Total_OffHand] = 0; item.Attributes[GameAttribute.Damage_Weapon_Delta_Total_OffHand] = item.Attributes[GameAttribute.Damage_Weapon_Delta_Total]; item.Attributes[GameAttribute.Damage_Weapon_Delta_Total_MainHand] = 0; mainWeapon.Attributes[GameAttribute.Damage_Weapon_Min_Total_MainHand] = mainWeapon.Attributes[GameAttribute.Damage_Weapon_Min_Total]; mainWeapon.Attributes[GameAttribute.Damage_Weapon_Min_Total_OffHand] = 0; item.Attributes[GameAttribute.Damage_Weapon_Min_Total_OffHand] = item.Attributes[GameAttribute.Damage_Weapon_Min_Total]; item.Attributes[GameAttribute.Damage_Weapon_Min_Total_MainHand] = 0; other.SendChangedMessage((mainWeapon.Owner as Player).InGameClient, mainWeapon.DynamicID); } } else if (slot == (int)EquipmentSlotId.Main_Hand) { if (_equipment[(int)EquipmentSlotId.Off_Hand] != 0) { Item offHandWeapon = GetEquipment(EquipmentSlotId.Off_Hand); item.Attributes[GameAttribute.Damage_Weapon_Delta_Total_MainHand] = item.Attributes[GameAttribute.Damage_Weapon_Delta_Total]; offHandWeapon.Attributes[GameAttribute.Damage_Weapon_Delta_Total_OffHand] = offHandWeapon.Attributes[GameAttribute.Damage_Weapon_Delta_Total]; item.Attributes[GameAttribute.Damage_Weapon_Min_Total_MainHand] = item.Attributes[GameAttribute.Damage_Weapon_Min_Total]; offHandWeapon.Attributes[GameAttribute.Damage_Weapon_Min_Total_OffHand] = offHandWeapon.Attributes[GameAttribute.Damage_Weapon_Min_Total]; offHandWeapon.Attributes[GameAttribute.Held_In_OffHand] = true; item.Attributes[GameAttribute.Damage_Weapon_Min_Total_OffHand] = 0; item.Attributes[GameAttribute.Damage_Weapon_Delta_Total_OffHand] = 0; offHandWeapon.Attributes[GameAttribute.Damage_Weapon_Delta_Total_MainHand] = 0; offHandWeapon.Attributes[GameAttribute.Damage_Weapon_Min_Total_MainHand] = 0; offHandWeapon.Attributes.SendChangedMessage((offHandWeapon.Owner as Player).InGameClient, offHandWeapon.DynamicID); } } if (item.Owner is Player) { item.Attributes.SendChangedMessage((item.Owner as Player).InGameClient, item.DynamicID); // flag item as equipped, so as not to shown in red color } _equippedMap = null; // compute stats (depends on items) AttributeMath.ComputeStats(_owner, GetEquippedMap()); }
/// <summary> /// Removes an item from the equipment slot it uses /// returns the used equipmentSlot /// </summary> public int UnequipItem(Item item) { if (!Items.ContainsKey(item.DynamicID)) return 0; Items.Remove(item.DynamicID); var slot = item.EquipmentSlot; if (_equipment[slot] == item.DynamicID) { _equipment[slot] = 0; item.Attributes[GameAttribute.Item_Equipped] = false; // Probaly should be handled by Equipable class /fasbat item.Attributes.SendChangedMessage(_owner.InGameClient, item.DynamicID); return slot; } return 0; }
public virtual void OnRequestBuyItem(Players.Player player, Item item) { // TODO: Check gold here if (!player.Inventory.HasInventorySpace(item)) { return; } // TODO: Remove the gold var newItem = new Item(this.World, item.SNOId, item.GBHandle.GBID, item.ItemType); var attributeCreators = new AttributeCreatorFactory().Create(item.ItemType); foreach (IItemAttributeCreator creator in attributeCreators) { creator.CreateAttributes(item); } player.Inventory.PickUp(newItem); // TODO: Dont use pickup? ;) }
/// <summary> /// Picks an item up after client request /// </summary> /// <returns>true if the item was picked up, or false if the player could not pick up the item.</returns> public bool PickUp(Item item) { System.Diagnostics.Debug.Assert(!_inventoryGrid.Contains(item) && !_equipment.IsItemEquipped(item), "Item already in inventory"); // TODO: Autoequip when equipment slot is empty bool success = false; if (!_inventoryGrid.HasFreeSpace(item)) { // Inventory full _owner.InGameClient.SendMessage(new ACDPickupFailedMessage() { ItemID = item.DynamicID, Reason = ACDPickupFailedMessage.Reasons.InventoryFull }); } else { item.CurrentState = ItemState.PickingUp; if (item.HasWorldLocation && item.World != null) { item.Owner = _owner; item.World.Leave(item); } _inventoryGrid.AddItem(item); if (_owner.GroundItems.ContainsKey(item.DynamicID)) _owner.GroundItems.Remove(item.DynamicID); success = true; item.CurrentState = ItemState.Normal; AcceptMoveRequest(item); } return success; }
public void BuyItem(Item originalItem) { // TODO: Create a copy instead of random. var newItem = ItemGenerator.CreateItem(_owner, originalItem.ItemDefinition); _inventoryGrid.AddItem(newItem); }
public Item AddGoldItem(Item collectedItem) { _inventoryGold.Attributes[GameAttribute.ItemStackQuantityLo] += collectedItem.Attributes[GameAttribute.Gold]; _inventoryGold.Attributes.SendChangedMessage(_owner.InGameClient, _inventoryGold.DynamicID); return _inventoryGold; }
/// <summary> /// Checks if Item can be equipped at that slot. Handels equipment for Two-Handed-Weapons. /// </summary> /// <param name="item"></param> /// <param name="equipmentSlot"></param> /// <returns></returns> private bool IsValidEquipmentRequest(Item item, int equipmentSlot) { ItemType type = item.ItemType; if (equipmentSlot == (int)EquipmentSlotId.Main_Hand) { // useful for 1hand + shield switching, this is to avoid shield to be go to main hand if (!Item.IsWeapon(type)) return false; if (Item.Is2H(type)) { Item itemOffHand = _equipment.GetEquipment(EquipmentSlotId.Off_Hand); if (itemOffHand != null) { _equipment.UnequipItem(itemOffHand); if (!_inventoryStash.AddItem(itemOffHand)) { _equipment.EquipItem(itemOffHand, (int)EquipmentSlotId.Off_Hand); return false; } AcceptMoveRequest(itemOffHand); } } } else if (equipmentSlot == (int)EquipmentSlotId.Off_Hand) { Item itemMainHand = _equipment.GetEquipment(EquipmentSlotId.Main_Hand); if (Item.Is2H(type)) { //remove object first to make room for possible unequiped item _inventoryStash.RemoveItem(item); if(itemMainHand != null) { _equipment.UnequipItem(itemMainHand); _inventoryStash.AddItem(itemMainHand); AcceptMoveRequest(itemMainHand); } _equipment.EquipItem(item, (int)EquipmentSlotId.Main_Hand); AcceptMoveRequest(item); SendVisualInventory(this._owner); // All equipment commands are executed. the original EquipmentRequest is invalid at this moment return false; } if (itemMainHand != null) { if (Item.Is2H(itemMainHand.ItemType)) { return false; } } } return true; }
internal Item AddGoldItem(Item collectedItem) { if (_inventoryGold == null) { _inventoryGold = ItemGenerator.CreateGold(_owner, collectedItem.Attributes[GameAttribute.Gold]); _inventoryGold.Attributes[GameAttribute.ItemStackQuantityLo] = collectedItem.Attributes[GameAttribute.Gold]; _inventoryGold.Owner = _owner; _inventoryGold.SetInventoryLocation(18, 0, 0); // Equipment slot 18 ==> Gold _inventoryGold.Reveal(_owner); } else { _inventoryGold.Attributes[GameAttribute.ItemStackQuantityLo] += collectedItem.Attributes[GameAttribute.Gold]; _inventoryGold.Attributes.SendChangedMessage(_owner.InGameClient, _inventoryGold.DynamicID); } return _inventoryGold; }
public virtual void OnRequestUse(Player player, Item target, int actionId, WorldPlace worldPlace) { throw new System.NotImplementedException(); }
public bool IsItemEquipped(Item item) { return IsItemEquipped(item.DynamicID); }
private uint[] _equipment; // array of equiped items_id (not item) public Equipment(Player owner){ this._equipment = new uint[16]; this._inventoryGold = null; this._owner = owner; }
public Item AddGoldItem(Item collectedItem) { // the logic is flawed, we shouldn't be creating new gold when it's collected! /raist. if (_inventoryGold == null) { _inventoryGold = ItemGenerator.CreateGold(_owner, collectedItem.Attributes[GameAttribute.Gold]); _inventoryGold.Attributes[GameAttribute.ItemStackQuantityLo] = collectedItem.Attributes[GameAttribute.Gold]; _inventoryGold.Owner = _owner; _inventoryGold.SetInventoryLocation(18, 0, 0); // Equipment slot 18 ==> Gold _inventoryGold.Reveal(_owner); } else { _inventoryGold.Attributes[GameAttribute.ItemStackQuantityLo] += collectedItem.Attributes[GameAttribute.Gold]; //_inventoryGold.Attributes.SendChangedMessage(_owner.InGameClient, _inventoryGold.DynamicID); // causes: !!!ERROR!!! Setting attribute for unknown ACD [ANN:1253] [Attribute:ItemStackQuantityLo-1048575: 8669] and client crash /raist. } return _inventoryGold; }
/// <summary> /// Equips an item in an equipment slot /// </summary> public void EquipItem(Item item, int slot) { _equipment[slot] = item.DynamicID; item.Owner = _owner; item.SetInventoryLocation(slot, 0, 0); }
public virtual void OnRequestBuyItem(Players.Player player, Item item) { // TODO: Check gold here if (!player.Inventory.HasInventorySpace(item)) { return; } // TODO: Remove the gold // TODO: new item would randomize new stats, should better copy item as it // dark0ne var newItem = new Item(this.World, item.ItemDefinition); player.Inventory.PickUp(newItem); // TODO: Dont use pickup? ;) }
/// <summary> /// Removes an item from the equipment slot it uses /// returns the used equipmentSlot /// </summary> public int UnequipItem(Item item) { for (int i = 0; i < EquipmentSlots; i++) { if (_equipment[i] == item.DynamicID) { _equipment[i] = 0; item.SetInventoryLocation(-1, -1, -1); item.Attributes[GameAttributeB.Item_Equipped] = false; if (item.Attributes[GameAttribute.Held_In_OffHand]) { item.Attributes[GameAttribute.Held_In_OffHand] = false; if (_equipment[(int)EquipmentSlotId.Main_Hand] != 0) { Item mainWeapon = GetEquipment(EquipmentSlotId.Main_Hand); mainWeapon.Attributes[GameAttribute.Damage_Weapon_Min_Total_MainHand] = 0; mainWeapon.Attributes[GameAttribute.Damage_Weapon_Delta_Total_MainHand] = 0; mainWeapon.Attributes.SendChangedMessage((mainWeapon.Owner as Player).InGameClient, mainWeapon.DynamicID); } } else if (i == (int)EquipmentSlotId.Main_Hand) { if (_equipment[(int)EquipmentSlotId.Off_Hand] != 0) { Item offHandWeapon = GetEquipment(EquipmentSlotId.Off_Hand); offHandWeapon.Attributes[GameAttribute.Damage_Weapon_Min_Total_OffHand] = 0; offHandWeapon.Attributes[GameAttribute.Damage_Weapon_Delta_Total_OffHand] = 0; offHandWeapon.Attributes[GameAttribute.Held_In_OffHand] = false; offHandWeapon.Attributes.SendChangedMessage((offHandWeapon.Owner as Player).InGameClient, offHandWeapon.DynamicID); } } // compute stats (depends on items) item.Attributes.SendChangedMessage((item.Owner as Player).InGameClient, item.DynamicID); // unflag item item.Owner = null; _equippedMap = null; AttributeMath.ComputeStats(_owner, GetEquippedMap()); return i; } } return 0; }
/// <summary> /// Checks if Item can be equipped at that slot. Handels equipment for Two-Handed-Weapons. /// </summary> /// <param name="item"></param> /// <param name="equipmentSlot"></param> /// <returns></returns> private bool IsValidEquipmentRequest(Item item, int equipmentSlot) { ItemType type = item.ItemType; if (equipmentSlot == (int)EquipmentSlotId.Main_Hand) { if (Item.Is2H(type)) { Item itemOffHand = _equipment.GetEquipment(EquipmentSlotId.Off_Hand); if (itemOffHand != null) { _equipment.UnequipItem(itemOffHand); _inventoryStash.AddItem(itemOffHand); AcceptMoveRequest(itemOffHand); } } } else if (equipmentSlot == (int)EquipmentSlotId.Off_Hand) { Item itemMainHand = _equipment.GetEquipment(EquipmentSlotId.Main_Hand); if (Item.Is2H(type)) { if(itemMainHand != null) { _equipment.UnequipItem(itemMainHand); _inventoryStash.AddItem(itemMainHand); AcceptMoveRequest(itemMainHand); } _inventoryStash.RemoveItem(item); _equipment.EquipItem(item, (int)EquipmentSlotId.Main_Hand); AcceptMoveRequest(item); SendVisualInvetory(this._owner); // All equipment commands are executed. the original EquipmentRequest is invalid at this moment return false; } if (itemMainHand != null) { if (Item.Is2H(itemMainHand.ItemType)) { return false; } } } return true; }
/// <summary> /// Visually adds rune to skill /// </summary> /// <param name="rune"></param> /// <param name="PowerSNOId"></param> /// <param name="skillIndex"></param> public void SetRune(Item rune, int PowerSNOId, int skillIndex) { if ((skillIndex < 0) || (skillIndex > 5)) { return; } if (rune == null) { _skillSocketRunes[skillIndex] = 0; return; } _inventoryGrid.RemoveItem(rune); rune.Owner = _owner; _skillSocketRunes[skillIndex] = rune.DynamicID; // position of rune is read from mpq as INDEX of skill in skill kit /xsochor var y = MPQStorage.Data.Assets[SNOGroup.SkillKit].FirstOrDefault(x => x.Value.SNOId == _owner.SkillKit); for (int i = 0; i < (y.Value.Data as SkillKit).ActiveSkillEntries.Count; i++) { if ((y.Value.Data as SkillKit).ActiveSkillEntries[i].SNOPower == PowerSNOId) { rune.SetInventoryLocation(16, i, 0); break; } } }
public void DestroyInventoryItem(Item item) { _inventoryStash.RemoveItem(item); _equipment.UnequipItem(item); item.Destroy(); }
public bool HasInventorySpace(Item item) { return _inventoryGrid.HasFreeSpace(item); }
public void SpawnItem(Item item) { _inventoryGrid.AddItem(item); }
/// <summary> /// Handles auto-equipping of items on pickup. Returns true if they were able to be equipped. /// </summary> private bool AttemptAutoEquip(Item item) { bool result = false; if (Item.IsWeapon(item.ItemType)) { if (_equipment.GetEquipment(EquipmentSlotId.Main_Hand) == null && IsValidEquipmentRequest(item, (int)EquipmentSlotId.Main_Hand)) { _equipment.EquipItem(item, (int)EquipmentSlotId.Main_Hand); result = true; } else if (!Item.Is2H(item.ItemType) && _equipment.GetEquipment(EquipmentSlotId.Off_Hand) == null && IsValidEquipmentRequest(item, (int)EquipmentSlotId.Off_Hand)) { _equipment.EquipItem(item, (int)EquipmentSlotId.Off_Hand); result = true; } } else if (Item.IsArmor(item.ItemType) || Item.IsAccessory(item.ItemType)) { switch (item.ItemType) { case ItemType.ChestArmor: if (_equipment.GetEquipment(EquipmentSlotId.Chest) == null && IsValidEquipmentRequest(item, (int)EquipmentSlotId.Chest)) { _equipment.EquipItem(item, (int)EquipmentSlotId.Chest); result = true; } break; case ItemType.Helm: if (_equipment.GetEquipment(EquipmentSlotId.Helm) == null && IsValidEquipmentRequest(item, (int)EquipmentSlotId.Helm)) { _equipment.EquipItem(item, (int)EquipmentSlotId.Helm); result = true; } break; case ItemType.Shoulders: if (_equipment.GetEquipment(EquipmentSlotId.Shoulders) == null && IsValidEquipmentRequest(item, (int)EquipmentSlotId.Shoulders)) { _equipment.EquipItem(item, (int)EquipmentSlotId.Shoulders); result = true; } break; case ItemType.Bracers: if (_equipment.GetEquipment(EquipmentSlotId.Bracers) == null && IsValidEquipmentRequest(item, (int)EquipmentSlotId.Bracers)) { _equipment.EquipItem(item, (int)EquipmentSlotId.Bracers); result = true; } break; case ItemType.Gloves: if (_equipment.GetEquipment(EquipmentSlotId.Hands) == null && IsValidEquipmentRequest(item, (int)EquipmentSlotId.Hands)) { _equipment.EquipItem(item, (int)EquipmentSlotId.Hands); result = true; } break; case ItemType.Boots: if (_equipment.GetEquipment(EquipmentSlotId.Feet) == null && IsValidEquipmentRequest(item, (int)EquipmentSlotId.Feet)) { _equipment.EquipItem(item, (int)EquipmentSlotId.Feet); result = true; } break; case ItemType.Pants: if (_equipment.GetEquipment(EquipmentSlotId.Legs) == null && IsValidEquipmentRequest(item, (int)EquipmentSlotId.Legs)) { _equipment.EquipItem(item, (int)EquipmentSlotId.Legs); result = true; } break; case ItemType.Amulet: if (_equipment.GetEquipment(EquipmentSlotId.Amulett) == null && IsValidEquipmentRequest(item, (int)EquipmentSlotId.Amulett)) { _equipment.EquipItem(item, (int)EquipmentSlotId.Amulett); result = true; } break; case ItemType.Belt: if (_equipment.GetEquipment(EquipmentSlotId.Belt) == null && IsValidEquipmentRequest(item, (int)EquipmentSlotId.Belt)) { _equipment.EquipItem(item, (int)EquipmentSlotId.Belt); result = true; } break; case ItemType.Ring: if (_equipment.GetEquipment(EquipmentSlotId.Ring_left) == null && IsValidEquipmentRequest(item, (int)EquipmentSlotId.Ring_left)) { _equipment.EquipItem(item, (int)EquipmentSlotId.Ring_left); result = true; } else if (_equipment.GetEquipment(EquipmentSlotId.Ring_right) == null && IsValidEquipmentRequest(item, (int)EquipmentSlotId.Ring_right)) { _equipment.EquipItem(item, (int)EquipmentSlotId.Ring_right); result = true; } break; } } if(result) SendVisualInventory(this._owner); return result; }