public void OnAddSocket(Players.Player player, Item item) { // TODO: Animate Jeweler? Who knows. /fasbat item.Attributes[GameAttribute.Sockets] += 1; // Why this not work? :/ item.Attributes.SendChangedMessage(player.InGameClient, item.DynamicID); }
public static void Generate(Item item, int affixesCount) { if (!Item.IsWeapon(item.ItemType) && !Item.IsArmor(item.ItemType) && !Item.IsOffhand(item.ItemType) && !Item.IsAccessory(item.ItemType)) return; var itemTypes = ItemGroup.HierarchyToHashList(item.ItemType); int itemQualityMask = 1 << item.Attributes[GameAttribute.Item_Quality_Level]; var filteredList = AffixList.Where(a => a.QualityMask.HasFlag((QualityMask)itemQualityMask) && itemTypes.ContainsAtLeastOne(a.ItemGroup) && a.AffixLevel <= item.ItemLevel); Dictionary<int, AffixTable> bestDefinitions = new Dictionary<int, AffixTable>(); foreach (var affix in filteredList) bestDefinitions[affix.AffixFamily0] = affix; var selectedGroups = bestDefinitions.Values.OrderBy(x => RandomHelper.Next()).Take(affixesCount); foreach (var def in selectedGroups) { if (def != null) { //Logger.Debug("Generating affix " + def.Name + " (aLvl:" + def.AffixLevel + ")"); item.AffixList.Add(new Affix(def.Hash)); foreach (var effect in def.AttributeSpecifier) { if (effect.AttributeId > 0) { float result; if (FormulaScript.Evaluate(effect.Formula.ToArray(), item.RandomGenerator, out result)) { //Logger.Debug("Randomized value for attribute " + GameAttribute.Attributes[effect.AttributeId].Name + " is " + result); if (GameAttribute.Attributes[effect.AttributeId] is GameAttributeF) { var attr = GameAttribute.Attributes[effect.AttributeId] as GameAttributeF; if (effect.SNOParam != -1) item.Attributes[attr, effect.SNOParam] += result; else item.Attributes[attr] += result; } else if (GameAttribute.Attributes[effect.AttributeId] is GameAttributeI) { var attr = GameAttribute.Attributes[effect.AttributeId] as GameAttributeI; if (effect.SNOParam != -1) item.Attributes[attr, effect.SNOParam] += (int)result; else item.Attributes[attr] += (int)result; } } } } } } }
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 }); */ }
/// <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.SetInventoryLocation(slot, 0, 0); }
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, _owner.Toon.GoldAmount); this._inventoryGold.Attributes[GameAttribute.ItemStackQuantityLo] = _owner.Toon.GoldAmount; this._inventoryGold.SetInventoryLocation(17, 0, 0); this._inventoryGold.Owner = _owner; this.Items.Add(_inventoryGold.DynamicID,_inventoryGold); }
/// <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); return slot; } return 0; }
public void SpawnItem(Item item) { _inventoryGrid.AddItem(item); }
public bool HasInventorySpace(Item item) { return _inventoryGrid.HasFreeSpace(item); }
/// <summary> /// Visually adds rune to skill (move from backpack to runes' slot) /// </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; } if (_inventoryGrid.Items.ContainsKey(rune.DynamicID)) { _inventoryGrid.RemoveItem(rune); } else { // unattuned rune changes to attuned w/o getting into inventory rune.World.Leave(rune); rune.Reveal(_owner); } _equipment.Items.Add(rune.DynamicID, rune); _skillSocketRunes[skillIndex] = rune.DynamicID; // position of rune is read from mpq as INDEX of skill in skill kit - loaded in helper /xsochor rune.SetInventoryLocation(16, RuneHelper.GetRuneIndexForPower(powerSNOId), 0); }
public void DestroyInventoryItem(Item item) { _inventoryGrid.RemoveItem(item); _equipment.UnequipItem(item); // item.Destroy(); item.Unreveal(_owner); _owner.World.Game.EndTracking(item); }
public Item AddGoldItem(Item collectedItem) { _inventoryGold.Attributes[GameAttribute.ItemStackQuantityLo] += collectedItem.Attributes[GameAttribute.Gold]; _inventoryGold.Attributes.SendChangedMessage(_owner.InGameClient); return _inventoryGold; }
public Item AddGoldItem(Item collectedItem) { return AddGoldAmount(collectedItem.Attributes[GameAttribute.Gold]); }
public bool IsItemEquipped(Item item) { return IsItemEquipped(item.DynamicID); }
public void DestroyInventoryItem(Item item) { if (_equipment.IsItemEquipped(item)) { _equipment.UnequipItem(item); SendVisualInventory(_owner); } else { _inventoryGrid.RemoveItem(item); } item.Destroy(); }
/// <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 // If Item is Stackable try to add the amount if (item.IsStackable()) { // Find items of same type (GBID) and try to add it to one of them List<Item> baseItems = FindSameItems(item.GBHandle.GBID); foreach (Item baseItem in baseItems) { if (baseItem.Attributes[GameAttribute.ItemStackQuantityLo] + item.Attributes[GameAttribute.ItemStackQuantityLo] < baseItem.ItemDefinition.MaxStackAmount) { baseItem.Attributes[GameAttribute.ItemStackQuantityLo] += item.Attributes[GameAttribute.ItemStackQuantityLo]; baseItem.Attributes.SendChangedMessage(_owner.InGameClient); // Item amount successful added. Don't place item in inventory instead destroy it. item.Destroy(); return true; } } } 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; }
/// <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); }
/// <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) { ItemTypeTable 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 (!_inventoryGrid.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 _inventoryGrid.RemoveItem(item); if(itemMainHand != null) { _equipment.UnequipItem(itemMainHand); _inventoryGrid.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; }
public virtual void OnRequestUse(Player player, Item target, int actionId, WorldPlace worldPlace) { throw new System.NotImplementedException(); }
public static void CloneIntoItem(Item source, Item target) { target.AffixList.Clear(); foreach (var affix in source.AffixList) { var newItemAffix = new Affix(affix.AffixGbid); target.AffixList.Add(newItemAffix); } foreach (var affix in target.AffixList) { var definition = AffixList.Single(def => def.Hash == affix.AffixGbid); foreach (var effect in definition.AttributeSpecifier) { if (effect.AttributeId <= 0) continue; var attribute = GameAttribute.Attributes[effect.AttributeId]; if (attribute.ScriptFunc != null && !attribute.ScriptedAndSettable) continue; if (attribute is GameAttributeF) { var attr = GameAttribute.Attributes[effect.AttributeId] as GameAttributeF; if (effect.SNOParam != -1) target.Attributes[attr, effect.SNOParam] = source.Attributes[attr, effect.SNOParam]; else target.Attributes[attr] = source.Attributes[attr]; } else if (GameAttribute.Attributes[effect.AttributeId] is GameAttributeI) { var attr = GameAttribute.Attributes[effect.AttributeId] as GameAttributeI; if (effect.SNOParam != -1) target.Attributes[attr, effect.SNOParam] = source.Attributes[attr, effect.SNOParam]; else target.Attributes[attr] = source.Attributes[attr]; } } } }