Exemple #1
0
 // Convert unpacked itemproperty structure to native type.
 public static NWN.ItemProperty PackIP(ItemPropertyUnpacked itemProperty)
 {
     Internal.NativeFunctions.nwnxSetFunction(PLUGIN_NAME, "PackIP");
     Internal.NativeFunctions.nwnxPushString(itemProperty.Tag);
     Internal.NativeFunctions.nwnxPushObject(itemProperty.Creator !);
     Internal.NativeFunctions.nwnxPushInt(itemProperty.SpellID);
     Internal.NativeFunctions.nwnxPushInt(itemProperty.IsUseable ? 1 : 0);
     Internal.NativeFunctions.nwnxPushInt(itemProperty.ChanceToAppear);
     Internal.NativeFunctions.nwnxPushInt(itemProperty.UsesPerDay);
     Internal.NativeFunctions.nwnxPushInt(itemProperty.Param1Value);
     Internal.NativeFunctions.nwnxPushInt(itemProperty.Param1);
     Internal.NativeFunctions.nwnxPushInt(itemProperty.CostTableValue);
     Internal.NativeFunctions.nwnxPushInt(itemProperty.CostTable);
     Internal.NativeFunctions.nwnxPushInt(itemProperty.SubType);
     Internal.NativeFunctions.nwnxPushInt(itemProperty.Property);
     Internal.NativeFunctions.nwnxPushInt(itemProperty.ItemPropertyID);
     Internal.NativeFunctions.nwnxCallFunction();
     return(new NWN.ItemProperty(Internal.NativeFunctions.nwnxPopItemProperty()));
 }
        // Convert unpacked itemproperty structure to native type.
        public static Lite.ItemProperty PackIP(ItemPropertyUnpacked itemProperty)
        {
            const string sFunc = "PackIP";

            NWNXCore.NWNX_PushArgumentString(itemProperty.Tag);
            NWNXCore.NWNX_PushArgumentObject(itemProperty.Creator);
            NWNXCore.NWNX_PushArgumentInt(itemProperty.SpellId);
            NWNXCore.NWNX_PushArgumentInt(itemProperty.IsUseable ? 1 : 0);
            NWNXCore.NWNX_PushArgumentInt(itemProperty.ChanceToAppear);
            NWNXCore.NWNX_PushArgumentInt(itemProperty.UsesPerDay);
            NWNXCore.NWNX_PushArgumentInt(itemProperty.Param1Value);
            NWNXCore.NWNX_PushArgumentInt(itemProperty.Param1);
            NWNXCore.NWNX_PushArgumentInt(itemProperty.CostTableValue);
            NWNXCore.NWNX_PushArgumentInt(itemProperty.CostTable);
            NWNXCore.NWNX_PushArgumentInt(itemProperty.SubType);
            NWNXCore.NWNX_PushArgumentInt(itemProperty.Property);

            NWNXCore.NWNX_CallFunction(PLUGIN_NAME, sFunc);
            return(NWNXCore.NWNX_GetReturnValueItemProperty());
        }
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);
        }