Esempio n. 1
0
        public void RunItemDecay(NWPlayer player, NWItem item, float reduceAmount)
        {
            if (reduceAmount <= 0)
            {
                return;
            }
            if (player.IsPlot ||
                item.IsPlot ||
                item.GetLocalInt("UNBREAKABLE") == 1 ||
                !item.IsValid ||
                item.BaseItemType == BASE_ITEM_CREATUREITEM ||  // Creature skin
                item.BaseItemType == BASE_ITEM_CBLUDGWEAPON ||  // Creature bludgeoning weapon
                item.BaseItemType == BASE_ITEM_CPIERCWEAPON ||  // Creature piercing weapon
                item.BaseItemType == BASE_ITEM_CSLASHWEAPON ||  // Creature slashing weapon
                item.BaseItemType == BASE_ITEM_CSLSHPRCWEAP)    // Creature slashing/piercing weapon
            {
                return;
            }

            float  durability = GetDurability(item);
            string sItemName  = item.Name;
            int    apr        = _creature.GetAttacksPerRound(player, 1);

            // Reduce by 0.001 each time it's run. Player only receives notifications when it drops a full point.
            // I.E: Dropping from 29.001 to 29.
            // Note that players only see two decimal places in-game on purpose.
            durability -= reduceAmount / apr;
            bool displayMessage = Math.Abs(durability % 1) < 0.05f;

            if (displayMessage)
            {
                player.SendMessage(_color.Red("Your " + sItemName + " has been damaged. (" + FormatDurability(durability) + " / " + GetMaxDurability(item)));
            }

            if (durability <= 0.00f)
            {
                item.Destroy();
                player.SendMessage(_color.Red("Your " + sItemName + " has broken!"));
            }
            else
            {
                SetDurability(item, durability);
            }
        }