Esempio n. 1
0
        private bool CheckCondition(RuleAttackWithWeapon evt)
        {
            ItemEnchantment itemEnchantment = base.Fact as ItemEnchantment;
            ItemEntity      itemEntity      = (itemEnchantment != null) ? itemEnchantment.Owner : null;

            if (itemEntity != null && itemEntity != evt.Weapon)
            {
                return(false);
            }
            if (this.CriticalHit && (!evt.AttackRoll.IsCriticalConfirmed || evt.AttackRoll.FortificationNegatesCriticalHit))
            {
                return(false);
            }
            if (this.ReduceHPToZero)
            {
                return(evt.MeleeDamage != null && !evt.MeleeDamage.IsFake && evt.Target.HPLeft <= 0 && evt.Target.HPLeft + evt.MeleeDamage.Damage > 0);
            }
            if (this.CheckWeaponCategory && this.Category != evt.Weapon.Blueprint.Category)
            {
                return(false);
            }
            if (this.OnlyOnFullAttack && !evt.IsFullAttack)
            {
                return(false);
            }
            if (this.OnlyOnFirstAttack && !evt.IsFirstAttack)
            {
                return(false);
            }
            if (this.DuelistWeapon && !Extensions.isSwashbucklerWeapon(evt.Weapon.Blueprint, evt.Initiator.Descriptor))
            {
                return(false);
            }
            return(true);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            ItemEnchantment itemEnchantment = db.ItemEnchanments.Find(id);

            db.ItemEnchanments.Remove(itemEnchantment);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
        public override void OnFactActivate()
        {
            m_unlock = false;
            var unit = this.Owner;

            if (unit == null)
            {
                return;
            }

            Main.DebugLog(unit.Body.Wrist.MaybeItem?.ToString() ?? "wrist is null");

            ItemEntity armor = unit.Body.Armor.MaybeArmor;

            Main.DebugLog("1: " + armor?.ToString() ?? "armor is null");
            if (armor == null)
            {
                armor = unit.Body.Wrist.MaybeItem;
            }
            Main.DebugLog("2: " + armor?.ToString() ?? "wrist-armor is null");
            if (armor == null)
            {
                return;
            }

            int bonus = value.Calculate(Context) - 1;

            Main.DebugLog("3: " + bonus);
            if (bonus < 0)
            {
                bonus = 0;
            }
            if (bonus >= enchantments.Length)
            {
                bonus = enchantments.Length - 1;
            }
            Main.DebugLog("4: " + bonus);
            Main.DebugLog("5: " + enchantments.Length);

            if (armor.Enchantments.HasFact(enchantments[bonus]))
            {
                Main.DebugLog("6: Enchantments.HasFact");
                return;
            }

            m_Enchantment = armor.AddEnchantment(enchantments[bonus], Context, new Rounds?());

            //armor.RecalculateStats();
            m_Armor = armor;
            if (lock_slot && !armor.IsNonRemovable)
            {
                armor.IsNonRemovable = true;
                m_unlock             = true;
            }

            Main.DebugLog("x: ");
        }
        public override void OnFactActivate()
        {
            m_unlock = false;
            var unit = this.Owner;

            if (unit == null)
            {
                return;
            }

            var weapon = unit.Body.PrimaryHand.HasWeapon ? unit.Body.PrimaryHand.MaybeWeapon : unit.Body.EmptyHandWeapon;

            if (weapon == null)
            {
                return;
            }

            if (!allowed_types.Empty() && !allowed_types.Contains(weapon.Blueprint.Type))
            {
                return;
            }
            int bonus = getRemainingGroupSize() - 1;

            if (bonus < 0)
            {
                return;
            }

            if (bonus >= enchantments.Length)
            {
                bonus = enchantments.Length - 1;
            }


            if (weapon.Enchantments.HasFact(enchantments[bonus]))
            {
                return;
            }

            if (weapon.EnchantmentValue != 0 && only_non_magical)
            {
                return;
            }
            m_Enchantment = weapon.AddEnchantment(enchantments[bonus], Context, new Rounds?());



            if (lock_slot && !weapon.IsNonRemovable)
            {
                weapon.IsNonRemovable = true;
                m_unlock = true;
            }
            //m_Enchantment.RemoveOnUnequipItem = remove_on_unequip;
            m_Weapon = weapon;
        }
Esempio n. 5
0
 public IEnumerable <ItemEnchantment> GetAllEnchantments()
 {
     for (EnchantSlot slot = EnchantSlot.Permanent; slot < EnchantSlot.End; ++slot)
     {
         ItemEnchantment enchant = GetEnchantment(slot);
         if (enchant != null)
         {
             yield return(enchant);
         }
     }
 }
Esempio n. 6
0
        public override bool OnExpire(Player player, ItemTemplate pItemProto)
        {
            List <ItemPosCount> dest = new List <ItemPosCount>();
            InventoryResult     msg  = player.CanStoreNewItem(ItemConst.NullBag, ItemConst.NullSlot, dest, 44718, 1); // Ripe Disgusting Jar

            if (msg == InventoryResult.Ok)
            {
                player.StoreNewItem(dest, 44718, true, ItemEnchantment.GenerateItemRandomPropertyId(44718));
            }

            return(true);
        }
Esempio n. 7
0
        public override bool OnExpire(Player player, ItemTemplate pItemProto)
        {
            List <ItemPosCount> dest = new List <ItemPosCount>();
            InventoryResult     msg  = player.CanStoreNewItem(ItemConst.NullBag, ItemConst.NullSlot, dest, 39883, 1); // Cracked Egg

            if (msg == InventoryResult.Ok)
            {
                player.StoreNewItem(dest, 39883, true, ItemEnchantment.GenerateItemRandomPropertyId(39883));
            }

            return(true);
        }
        public override void OnFactActivate()
        {
            m_unlock = false;
            var unit = this.Owner;

            if (unit == null)
            {
                return;
            }

            var weapon = unit.Body.PrimaryHand.HasWeapon ? unit.Body.PrimaryHand.MaybeWeapon : unit.Body.EmptyHandWeapon;

            if (weapon == null)
            {
                return;
            }

            if (!allowed_types.Empty() && !allowed_types.Contains(weapon.Blueprint.Type))
            {
                return;
            }

            if (!Context.HasMetamagic(metamagic))
            {
                return;
            }

            if (weapon.Enchantments.HasFact(enchantment))
            {
                return;
            }

            /*var fact = weapon.Enchantments.Find(x => x.Blueprint == enchantment);
             * if (fact != null)
             * {
             *  weapon.RemoveEnchantment(fact);
             * }*/

            if (weapon.EnchantmentValue != 0 && only_non_magical)
            {
                return;
            }

            m_Enchantment = weapon.AddEnchantment(enchantment, Context, new Rounds?());

            if (lock_slot && !weapon.IsNonRemovable)
            {
                weapon.IsNonRemovable = true;
                m_unlock = true;
            }
            //m_Enchantment.RemoveOnUnequipItem = remove_on_unequip;
            m_Weapon = weapon;
        }
 public ActionResult Edit([Bind(Include = "ItemEnchantmentID,ItemID,EnchantmentID")] ItemEnchantment itemEnchantment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(itemEnchantment).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.EnchantmentID = new SelectList(db.Enchantments, "EnchantmentID", "EnchantmentName", itemEnchantment.EnchantmentID);
     ViewBag.ItemID        = new SelectList(db.Items, "ItemID", "ItemName", itemEnchantment.ItemID);
     return(View(itemEnchantment));
 }
        // GET: ItemEnchantment/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ItemEnchantment itemEnchantment = db.ItemEnchanments.Find(id);

            if (itemEnchantment == null)
            {
                return(HttpNotFound());
            }
            return(View(itemEnchantment));
        }
        public override void OnFactActivate()
        {
            m_unlock = false;
            var unit = this.Owner;

            if (unit == null)
            {
                return;
            }

            var armor = unit.Body.Armor.MaybeArmor;

            if (armor == null)
            {
                return;
            }

            int bonus = getRemainingGroupSize() - 1;

            if (bonus < 0)
            {
                return;
            }

            if (shift_with_current_enchantment)
            {
                bonus += GameHelper.GetItemEnhancementBonus(armor);
            }

            if (bonus >= enchantments.Length)
            {
                bonus = enchantments.Length - 1;
            }

            if (armor.Enchantments.HasFact(enchantments[bonus]))
            {
                return;
            }


            m_Enchantment = armor.AddEnchantment(enchantments[bonus], Context, new Rounds?());

            armor.RecalculateStats();
            m_Armor = armor;
            if (lock_slot && !armor.IsNonRemovable)
            {
                armor.IsNonRemovable = true;
                m_unlock             = true;
            }
        }
Esempio n. 12
0
 private void SetEnchantUnequipped(ItemEnchantment enchant)
 {
     if (enchant.Slot == EnchantSlot.Permanent)
     {
         Owner.SetUInt16Low((PlayerFields)(284 + Slot * 2), 0);
     }
     else if (enchant.Slot == EnchantSlot.Temporary)
     {
         Owner.SetUInt16High((PlayerFields)(284 + Slot * 2), 0);
     }
     for (int index = 0; index < enchant.Entry.Effects.Length; ++index)
     {
         EnchantMgr.RemoveEffect(this, enchant.Entry.Effects[index]);
     }
 }
Esempio n. 13
0
        /// <summary>
        /// Adds a new the <see cref="ItemEnchantment"/> to the given Slot.
        /// Will remove any existing Enchantment in that slot.
        /// </summary>
        /// <param name="enchantSlot"></param>
        public void ApplyEnchant(ItemEnchantmentEntry enchantEntry,
                                 EnchantSlot enchantSlot,
                                 int duration,
                                 int charges,
                                 bool applyBoni)
        {
            // TODO: Add charges
            if (m_enchantments == null)
            {
                m_enchantments = new ItemEnchantment[(int)EnchantSlot.End];
            }

            if (m_enchantments[(int)enchantSlot] != null)
            {
                RemoveEnchant(enchantSlot);
            }

            var enchant = new ItemEnchantment(enchantEntry, enchantSlot, DateTime.Now, duration);

            m_enchantments[(int)enchantSlot] = enchant;
            m_record.SetEnchant(enchantSlot, (int)enchant.Entry.Id, duration);

            SetEnchantId(enchantSlot, enchantEntry.Id);
            SetEnchantDuration(enchantSlot, duration);
            if (charges > 0)
            {
                SetEnchantCharges(enchantSlot, charges - 1);
            }

            var owner = OwningCharacter;

            if (owner != null)
            {
                EnchantMgr.ApplyEnchantToItem(this, enchant);

                if (enchant.Entry.GemTemplate != null)
                {
                    owner.Inventory.ModUniqueCount(enchant.Entry.GemTemplate, 1);
                }
                OnOwnerReceivedNewEnchant(enchant);

                if (applyBoni && IsEquippedItem)
                {
                    // render on Character and apply boni
                    SetEnchantEquipped(enchant);
                }
            }
        }
        // GET: ItemEnchantment/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ItemEnchantment itemEnchantment = db.ItemEnchanments.Find(id);

            if (itemEnchantment == null)
            {
                return(HttpNotFound());
            }
            ViewBag.EnchantmentID = new SelectList(db.Enchantments, "EnchantmentID", "EnchantmentName", itemEnchantment.EnchantmentID);
            ViewBag.ItemID        = new SelectList(db.Items, "ItemID", "ItemName", itemEnchantment.ItemID);
            return(View(itemEnchantment));
        }
Esempio n. 15
0
 /// <summary>
 /// Called when this Item was added to someone's inventory
 /// </summary>
 protected internal void OnAdd()
 {
     if (m_template.BondType == ItemBondType.OnPickup || m_template.BondType == ItemBondType.Quest)
     {
         Flags |= ItemFlags.Soulbound;
     }
     m_owner = m_container.Owner;
     for (EnchantSlot slot = EnchantSlot.Permanent; slot < EnchantSlot.End; ++slot)
     {
         ItemEnchantment enchantment = GetEnchantment(slot);
         if (enchantment != null)
         {
             OnOwnerReceivedNewEnchant(enchantment);
         }
     }
 }
        private void deactivateEnchants()
        {
            if (m_PrimaryHandEnchantment != null && m_PriamryHandWeapon != null)
            {
                m_PrimaryHandEnchantment.Owner?.RemoveEnchantment(this.m_PrimaryHandEnchantment);
                m_PrimaryHandEnchantment = null;
                m_PriamryHandWeapon      = null;
            }

            if (m_SecondaryHandEnchantment != null && m_SecondaryHandWeapon != null)
            {
                m_SecondaryHandEnchantment.Owner?.RemoveEnchantment(this.m_SecondaryHandEnchantment);
                m_SecondaryHandEnchantment = null;
                m_SecondaryHandWeapon      = null;
            }
        }
Esempio n. 17
0
        public LootItem(LootStoreItem li)
        {
            itemid     = li.itemid;
            conditions = li.conditions;

            ItemTemplate proto = Global.ObjectMgr.GetItemTemplate(itemid);

            freeforall        = proto != null && proto.GetFlags().HasAnyFlag(ItemFlags.MultiDrop);
            follow_loot_rules = proto != null && proto.FlagsCu.HasAnyFlag(ItemFlagsCustom.FollowLootRules);

            needs_quest = li.needs_quest;

            randomSuffix     = ItemEnchantment.GenerateEnchSuffixFactor(itemid);
            randomPropertyId = ItemEnchantment.GenerateItemRandomPropertyId(itemid);
            upgradeId        = Global.DB2Mgr.GetRulesetItemUpgrade(itemid);
            canSave          = true;
        }
Esempio n. 18
0
        void SetEnchantUnequipped(ItemEnchantment enchant)
        {
            if (enchant.Slot == EnchantSlot.Permanent)
            {
                Owner.SetUInt16Low(
                    PlayerFields.VISIBLE_ITEM_1_ENCHANTMENT + (Slot * ItemConstants.PlayerFieldVisibleItemSize), 0);
            }
            else if (enchant.Slot == EnchantSlot.Temporary)
            {
                Owner.SetUInt16High(
                    PlayerFields.VISIBLE_ITEM_1_ENCHANTMENT + (Slot * ItemConstants.PlayerFieldVisibleItemSize), 0);
            }

            for (var i = 0; i < enchant.Entry.Effects.Length; i++)
            {
                EnchantMgr.RemoveEffect(this, enchant.Entry.Effects[i]);
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Sends the new state of the trading window to other party
        /// </summary>
        /// <param name="otherParty">Whether this is sending the own info to the other party (or, if false, to oneself)</param>
        /// <param name="client">receiving party</param>
        /// <param name="money">new amount of money</param>
        /// <param name="items">new items</param>
        public static void SendTradeUpdate(IPacketReceiver client, bool otherParty, uint money, Item[] items)
        {
            using (RealmPacketOut packet = new RealmPacketOut(RealmServerOpCode.SMSG_TRADE_STATUS_EXTENDED,
                                                              30 + 72 * items.Length))
            {
                packet.Write(otherParty);
                packet.Write(0);
                packet.Write(items.Length);
                packet.Write(items.Length);
                packet.Write(money);
                packet.Write(0);
                for (int val = 0; val < items.Length; ++val)
                {
                    packet.WriteByte(val);
                    Item obj = items[val];
                    if (obj != null)
                    {
                        packet.Write(obj.EntryId);
                        packet.Write(obj.Template.DisplayId);
                        packet.Write(obj.Amount);
                        packet.Write(0);
                        packet.Write(obj.GiftCreator);
                        ItemEnchantment enchantment = obj.GetEnchantment(EnchantSlot.Permanent);
                        packet.Write(enchantment != null ? enchantment.Entry.Id : 0U);
                        packet.Zero(12);
                        packet.Write(obj.Creator);
                        packet.Write(obj.SpellCharges);
                        packet.Write(obj.Template.RandomSuffixFactor);
                        packet.Write(obj.RandomPropertiesId);
                        LockEntry lockEntry = obj.Lock;
                        packet.Write(lockEntry != null ? lockEntry.Id : 0U);
                        packet.Write(obj.MaxDurability);
                        packet.Write(obj.Durability);
                    }
                    else
                    {
                        packet.Zero(72);
                    }
                }

                client.Send(packet, false);
            }
        }
        public override void OnFactActivate()
        {
            m_unlock = false;
            var unit = this.Owner;

            if (unit == null)
            {
                return;
            }

            var weapon = unit.Body.PrimaryHand.HasWeapon ? unit.Body.PrimaryHand.MaybeWeapon : unit.Body.EmptyHandWeapon;

            if (weapon == null)
            {
                return;
            }

            if (!allowed_types.Empty() && !allowed_types.Contains(weapon.Blueprint.Type))
            {
                return;
            }

            int bonus = value.Calculate(Context) - GameHelper.GetItemEnhancementBonus(weapon) - 1;

            if (bonus < 0)
            {
                return;
            }
            if (bonus >= 5)
            {
                bonus = 4;
            }

            m_Enchantment = weapon.AddEnchantment(WeaponEnchantments.temporary_enchants[bonus], Context, new Rounds?());

            if (lock_slot && !weapon.IsNonRemovable)
            {
                weapon.IsNonRemovable = true;
                m_unlock = true;
            }
            //m_Enchantment.RemoveOnUnequipItem = remove_on_unequip;
            m_Weapon = weapon;
        }
        private void checkWeapons()
        {
            deactivateEnchants();
            var primary_hand_weapon   = this.Owner?.Body?.PrimaryHand?.MaybeWeapon;
            var secondary_hand_weapon = this.Owner?.Body?.SecondaryHand?.MaybeWeapon;

            if (primary_hand && primary_hand_weapon != null && !primary_hand_weapon.Enchantments.HasFact(enchant))
            {
                m_PrimaryHandEnchantment = primary_hand_weapon.AddEnchantment(enchant, this.Fact.MaybeContext, new Rounds?());
                m_PrimaryHandEnchantment.RemoveOnUnequipItem = true;
                m_PriamryHandWeapon = primary_hand_weapon;
            }
            if (secondary_hand && secondary_hand_weapon != null && !secondary_hand_weapon.Enchantments.HasFact(enchant))
            {
                m_SecondaryHandEnchantment = secondary_hand_weapon.AddEnchantment(enchant, this.Fact.MaybeContext, new Rounds?());
                m_SecondaryHandEnchantment.RemoveOnUnequipItem = true;
                m_SecondaryHandWeapon = secondary_hand_weapon;
            }
        }
        public override void OnFactActivate()
        {
            m_unlock = false;
            var unit = this.Owner;

            if (unit == null)
            {
                return;
            }

            var armor = unit.Body.Armor.MaybeArmor;

            if (armor == null)
            {
                return;
            }

            int bonus = value.Calculate(Context) - 1;

            if (bonus < 0)
            {
                bonus = 0;
            }
            if (bonus >= enchantments.Length)
            {
                bonus = enchantments.Length - 1;
            }

            if (armor.Enchantments.HasFact(enchantments[bonus]))
            {
                return;
            }

            m_Enchantment = armor.AddEnchantment(enchantments[bonus], Context, new Rounds?());

            armor.RecalculateStats();
            m_Armor = armor;
            if (lock_slot && !armor.IsNonRemovable)
            {
                armor.IsNonRemovable = true;
                m_unlock             = true;
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Called when owner learns about new enchant:
        /// When enchant gets added and when receiving an enchanted item
        /// </summary>
        private void OnOwnerReceivedNewEnchant(ItemEnchantment enchant)
        {
            var owner = OwningCharacter;

            ItemHandler.SendEnchantLog(owner, (ItemId)EntryId, enchant.Entry.Id);

            if (enchant.Duration != 0)
            {
                var timeLeft = (int)enchant.RemainingTime.TotalMilliseconds;
                owner.CallDelayed(timeLeft, obj =>
                {
                    if (!IsDeleted && Owner == owner)
                    {
                        RemoveEnchant(enchant);
                    }
                });
                ItemHandler.SendEnchantTimeUpdate(owner, this, enchant.Duration);
            }
        }
        public override void OnFactActivate()
        {
            m_unlock = false;
            var unit = this.Owner;

            if (unit == null)
            {
                return;
            }

            var shield = unit.Body.SecondaryHand.MaybeShield;

            if (shield == null)
            {
                return;
            }

            int bonus = value.Calculate(Context) - 1;

            if (bonus < 0)
            {
                bonus = 0;
            }
            if (bonus >= enchantments.Length)
            {
                bonus = enchantments.Length - 1;
            }

            if (shield.ArmorComponent.Enchantments.HasFact(enchantments[bonus]))
            {
                return;
            }

            m_Enchantment = shield.ArmorComponent.AddEnchantment(enchantments[bonus], Context, new Rounds?());
            shield.ArmorComponent.RecalculateStats();
            m_Shield = shield;
            if (lock_slot && !shield.IsNonRemovable)
            {
                shield.IsNonRemovable = true;
                m_unlock = true;
            }
        }
Esempio n. 25
0
        public void RemoveEnchant(ItemEnchantment enchant)
        {
            m_enchantments[(int)enchant.Slot] = null;
            m_record.SetEnchant(enchant.Slot, 0, 0);

            var owner = OwningCharacter;

            if (owner != null)
            {
                EnchantMgr.RemoveEnchantFromItem(this, enchant);
                if (IsEquipped)
                {
                    SetEnchantUnequipped(enchant);
                }
                if (enchant.Entry.GemTemplate != null)
                {
                    owner.Inventory.ModUniqueCount(enchant.Entry.GemTemplate, -1);
                }
            }
        }
Esempio n. 26
0
        /// <summary>
        /// Called when owner learns about new enchant:
        /// When enchant gets added and when receiving an enchanted item
        /// </summary>
        private void OnOwnerReceivedNewEnchant(ItemEnchantment enchant)
        {
            Character owner = OwningCharacter;

            ItemHandler.SendEnchantLog(owner, (Asda2ItemId)EntryId, enchant.Entry.Id);
            if (enchant.Duration == 0)
            {
                return;
            }
            int totalMilliseconds = (int)enchant.RemainingTime.TotalMilliseconds;

            owner.CallDelayed(totalMilliseconds, obj =>
            {
                if (IsDeleted || Owner != owner)
                {
                    return;
                }
                RemoveEnchant(enchant);
            });
            ItemHandler.SendEnchantTimeUpdate(owner, this, enchant.Duration);
        }
Esempio n. 27
0
        /// <summary>
        /// Adds a new the <see cref="T:WCell.RealmServer.Items.Enchanting.ItemEnchantment" /> to the given Slot.
        /// Will remove any existing Enchantment in that slot.
        /// </summary>
        /// <param name="enchantSlot"></param>
        public void ApplyEnchant(ItemEnchantmentEntry enchantEntry, EnchantSlot enchantSlot, int duration, int charges,
                                 bool applyBoni)
        {
            if (m_enchantments == null)
            {
                m_enchantments = new ItemEnchantment[12];
            }
            if (m_enchantments[(int)enchantSlot] != null)
            {
                RemoveEnchant(enchantSlot);
            }
            ItemEnchantment enchant = new ItemEnchantment(enchantEntry, enchantSlot, DateTime.Now, duration);

            m_enchantments[(int)enchantSlot] = enchant;
            m_record.SetEnchant(enchantSlot, (int)enchant.Entry.Id, duration);
            SetEnchantId(enchantSlot, enchantEntry.Id);
            SetEnchantDuration(enchantSlot, duration);
            if (charges > 0)
            {
                SetEnchantCharges(enchantSlot, charges - 1);
            }
            Character owningCharacter = OwningCharacter;

            if (owningCharacter == null)
            {
                return;
            }
            EnchantMgr.ApplyEnchantToItem(this, enchant);
            if (enchant.Entry.GemTemplate != null)
            {
                owningCharacter.Inventory.ModUniqueCount(enchant.Entry.GemTemplate, 1);
            }
            OnOwnerReceivedNewEnchant(enchant);
            if (!applyBoni || !IsEquippedItem)
            {
                return;
            }
            SetEnchantEquipped(enchant);
        }
Esempio n. 28
0
        /// <summary>
        /// Is called before adding the given amount of the given Item.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="amount"></param>
        /// <param name="err"></param>
        internal void CheckUniqueness(IMountableItem item, ref int amount, ref InventoryError err, bool isNew)
        {
            ItemTemplate template = item.Template;

            if (!isNew)
            {
                return;
            }
            if (template.UniqueCount > 0 &&
                this.OwnerInventory.GetUniqueCount(template.ItemId) + amount > template.UniqueCount)
            {
                amount -= template.UniqueCount;
                if (amount < 1)
                {
                    err = InventoryError.CANT_CARRY_MORE_OF_THIS;
                    return;
                }
            }

            if (item.Enchantments == null)
            {
                return;
            }
            for (EnchantSlot enchantSlot = EnchantSlot.Socket1; enchantSlot < EnchantSlot.Bonus; ++enchantSlot)
            {
                ItemEnchantment enchantment = item.Enchantments[(uint)enchantSlot];
                if (enchantment != null && enchantment.Entry.GemTemplate != null &&
                    (enchantment.Entry.GemTemplate.UniqueCount > 0 &&
                     this.OwnerInventory.GetUniqueCount(enchantment.Entry.GemTemplate.ItemId) >=
                     enchantment.Entry.GemTemplate.UniqueCount))
                {
                    err = InventoryError.CANT_CARRY_MORE_OF_THIS;
                    break;
                }
            }
        }
Esempio n. 29
0
        void HandlePlayerChoiceResponse(ChoiceResponse choiceResponse)
        {
            if (_player.PlayerTalkClass.GetInteractionData().PlayerChoiceId != choiceResponse.ChoiceID)
            {
                Log.outError(LogFilter.Player, $"Error in CMSG_CHOICE_RESPONSE: {GetPlayerInfo()} tried to respond to invalid player choice {choiceResponse.ChoiceID} (allowed {_player.PlayerTalkClass.GetInteractionData().PlayerChoiceId}) (possible packet-hacking detected)");
                return;
            }

            PlayerChoice playerChoice = Global.ObjectMgr.GetPlayerChoice(choiceResponse.ChoiceID);

            if (playerChoice == null)
            {
                return;
            }

            PlayerChoiceResponse playerChoiceResponse = playerChoice.GetResponse(choiceResponse.ResponseID);

            if (playerChoiceResponse == null)
            {
                Log.outError(LogFilter.Player, $"Error in CMSG_CHOICE_RESPONSE: {GetPlayerInfo()} tried to select invalid player choice response {choiceResponse.ResponseID} (possible packet-hacking detected)");
                return;
            }

            Global.ScriptMgr.OnPlayerChoiceResponse(GetPlayer(), (uint)choiceResponse.ChoiceID, (uint)choiceResponse.ResponseID);

            if (playerChoiceResponse.Reward.HasValue)
            {
                var reward = playerChoiceResponse.Reward.Value;
                if (reward.TitleId != 0)
                {
                    _player.SetTitle(CliDB.CharTitlesStorage.LookupByKey(reward.TitleId), false);
                }

                if (reward.PackageId != 0)
                {
                    _player.RewardQuestPackage((uint)reward.PackageId);
                }

                if (reward.SkillLineId != 0 && _player.HasSkill((SkillType)reward.SkillLineId))
                {
                    _player.UpdateSkillPro((uint)reward.SkillLineId, 1000, reward.SkillPointCount);
                }

                if (reward.HonorPointCount != 0)
                {
                    _player.AddHonorXP(reward.HonorPointCount);
                }

                if (reward.Money != 0)
                {
                    _player.ModifyMoney((long)reward.Money, false);
                }

                if (reward.Xp != 0)
                {
                    _player.GiveXP(reward.Xp, null, 0.0f);
                }

                foreach (PlayerChoiceResponseRewardItem item in reward.Items)
                {
                    List <ItemPosCount> dest = new List <ItemPosCount>();
                    if (_player.CanStoreNewItem(ItemConst.NullBag, ItemConst.NullSlot, dest, item.Id, (uint)item.Quantity) == InventoryResult.Ok)
                    {
                        Item newItem = _player.StoreNewItem(dest, item.Id, true, ItemEnchantment.GenerateItemRandomPropertyId(item.Id), null, 0, item.BonusListIDs);
                        _player.SendNewItem(newItem, (uint)item.Quantity, true, false);
                    }
                }

                foreach (PlayerChoiceResponseRewardEntry currency in reward.Currency)
                {
                    _player.ModifyCurrency((CurrencyTypes)currency.Id, currency.Quantity);
                }

                foreach (PlayerChoiceResponseRewardEntry faction in reward.Faction)
                {
                    _player.GetReputationMgr().ModifyReputation(CliDB.FactionStorage.LookupByKey(faction.Id), faction.Quantity);
                }
            }
        }