Exemple #1
0
        public static void ProcessVersion6RemoveACFromItem(NWItem item)
        {
            // Start by pulling the custom AC off the item and halving it.
            // Durability is +1 for every 2 AC on the item.
            int amount = item.CustomAC / 2;

            if (amount > 0)
            {
                float newMax     = DurabilityService.GetMaxDurability(item) + amount;
                float newCurrent = DurabilityService.GetDurability(item) + amount;
                DurabilityService.SetMaxDurability(item, newMax);
                DurabilityService.SetDurability(item, newCurrent);
            }

            item.CustomAC = 0;

            // Check all item properties. If the IP is a component Armor Class Bonus, remove it and replace with an increase to durability.
            foreach (var ip in item.ItemProperties)
            {
                if (_.GetItemPropertyType(ip) == (int)CustomItemPropertyType.ComponentBonus)
                {
                    // Check the sub-type. If it's AC, then do the replacement.
                    if (GetItemPropertySubType(ip) == (int)ComponentBonusType.ACUp)
                    {
                        amount = GetItemPropertyCostTableValue(ip) / 2;
                        // Grant the durability up property if amount > 0
                        if (amount > 0)
                        {
                            // Unpack the IP we're working with. Adjust its type and value, then reapply it.
                            var unpacked = NWNXItemProperty.UnpackIP(ip);
                            unpacked.SubType        = (int)ComponentBonusType.DurabilityUp;
                            unpacked.CostTableValue = amount;
                            var packed = NWNXItemProperty.PackIP(unpacked);
                            BiowareXP2.IPSafeAddItemProperty(item, packed, 0.0f, AddItemPropertyPolicy.IgnoreExisting, true, true);
                        }

                        _.RemoveItemProperty(item, ip);
                    }
                }
            }
        }
        private static void ProcessVersion6_ComponentBonuses(NWItem item, ItemProperty ip)
        {
            // Component Bonuses
            if (_.GetItemPropertyType(ip) == ItemPropertyType.ComponentBonus)
            {
                // +AC Component Bonus
                if (GetItemPropertySubType(ip) == (int)ComponentBonusType.ACUp)
                {
                    int amount = GetItemPropertyCostTableValue(ip) / 2;
                    // Grant the durability up property if amount > 0
                    if (amount > 0)
                    {
                        // Unpack the IP we're working with. Adjust its type and value, then reapply it.
                        var unpacked = NWNXItemProperty.UnpackIP(ip);
                        unpacked.SubType        = (int)ComponentBonusType.DurabilityUp;
                        unpacked.CostTableValue = amount;
                        var packed = NWNXItemProperty.PackIP(unpacked);
                        BiowareXP2.IPSafeAddItemProperty(item, packed, 0.0f, AddItemPropertyPolicy.IgnoreExisting, true, true);
                    }

                    _.RemoveItemProperty(item, ip);
                }
            }
        }
Exemple #3
0
        private int ProcessProperty(int amount, int maxBonuses, ComponentBonusType bonus, float levelsPerBonus = 1.0f)
        {
            string resref  = _componentType.ReassembledResref;
            int    penalty = 0;
            int    luck    = PerkService.GetPCPerkLevel(_player, PerkType.Lucky) + (_playerItemStats.Luck / 3);
            int    xp      = 0;

            ItemPropertyUnpacked bonusIP = new ItemPropertyUnpacked
            {
                Property       = (int)CustomItemPropertyType.ComponentBonus,
                SubType        = (int)bonus,
                CostTable      = 62,
                CostTableValue = 0,
                Param1         = 255,
                Param1Value    = 0,
                UsesPerDay     = 255,
                ChanceToAppear = 100,
                IsUseable      = true,
                SpellID        = -1
            };

            while (amount > 0)
            {
                int chanceToTransfer = CraftService.CalculateReassemblyChance(_player, penalty);
                // Roll to see if the item can be created.
                bool success = RandomService.Random(0, 100) <= chanceToTransfer;

                // Do a lucky roll if we failed the first time.
                if (!success && luck > 0 && RandomService.Random(0, 100) <= luck)
                {
                    _player.SendMessage("Lucky reassemble!");
                    success = true;
                }

                if (amount >= maxBonuses)
                {
                    if (success)
                    {
                        int levelIncrease = (int)(maxBonuses * levelsPerBonus);
                        // Roll succeeded. Create item.
                        bonusIP.CostTableValue = maxBonuses;
                        ItemProperty bonusIPPacked = NWNXItemProperty.PackIP(bonusIP);
                        NWItem       item          = _.CreateItemOnObject(resref, _player);
                        item.RecommendedLevel = levelIncrease;
                        BiowareXP2.IPSafeAddItemProperty(item, bonusIPPacked, 0.0f, AddItemPropertyPolicy.ReplaceExisting, true, false);

                        xp += (150 * maxBonuses + RandomService.Random(0, 5));
                    }
                    else
                    {
                        _player.SendMessage(ColorTokenService.Red("You failed to create a component. (+" + maxBonuses + ")"));
                        xp += (50 + RandomService.Random(0, 5));
                    }
                    // Penalty to chance increases regardless if item was created or not.
                    penalty += (maxBonuses * 5);
                    amount  -= maxBonuses;
                }
                else
                {
                    if (success)
                    {
                        int levelIncrease = (int)(amount * levelsPerBonus);
                        bonusIP.CostTableValue = amount;
                        ItemProperty bonusIPPacked = NWNXItemProperty.PackIP(bonusIP);
                        NWItem       item          = _.CreateItemOnObject(resref, _player);
                        item.RecommendedLevel = levelIncrease;
                        BiowareXP2.IPSafeAddItemProperty(item, bonusIPPacked, 0.0f, AddItemPropertyPolicy.ReplaceExisting, true, false);

                        xp += (150 * amount + RandomService.Random(0, 5));
                    }
                    else
                    {
                        _player.SendMessage(ColorTokenService.Red("You failed to create a component. (+" + amount + ")"));
                        xp += (50 + RandomService.Random(0, 5));
                    }
                    break;
                }
            }

            return(xp);
        }