コード例 #1
0
        public string IsValidTarget(NWCreature user, NWItem mod, NWObject target, Location targetLocation)
        {
            if (target.ObjectType != OBJECT_TYPE_ITEM)
            {
                return("Only items may be targeted by mods.");
            }
            if (!user.IsPlayer)
            {
                return("Only players may use mods.");
            }
            NWPlayer player     = (user.Object);
            NWItem   targetItem = (target.Object);

            int modLevel          = mod.RecommendedLevel;
            int itemLevel         = targetItem.RecommendedLevel;
            int requiredPerkLevel = modLevel / 5;

            if (requiredPerkLevel <= 0)
            {
                requiredPerkLevel = 1;
            }
            int perkLevel = 0;
            CustomItemPropertyType modType = ModService.GetModType(mod);
            ModSlots modSlots = ModService.GetModSlots(targetItem);
            int      modID    = mod.GetLocalInt("RUNE_ID");

            string[] modArgs = mod.GetLocalString("RUNE_VALUE").Split(',');

            // Check for a misconfigured mod item.
            if (modType == CustomItemPropertyType.Unknown)
            {
                return("Mod color couldn't be found. Notify an admin that this mod item is not set up properly.");
            }
            if (modID <= 0)
            {
                return("Mod ID couldn't be found. Notify an admin that this mod item is not set up properly.");
            }
            if (modArgs.Length <= 0)
            {
                return("Mod value couldn't be found. Notify an admin that this mod item is not set up properly.");
            }

            // No available slots on target item
            if (modType == CustomItemPropertyType.RedMod && !modSlots.CanRedModBeAdded)
            {
                return("That item has no available red mod slots.");
            }
            if (modType == CustomItemPropertyType.BlueMod && !modSlots.CanBlueModBeAdded)
            {
                return("That item has no available blue mod slots.");
            }
            if (modType == CustomItemPropertyType.GreenMod && !modSlots.CanGreenModBeAdded)
            {
                return("That item has no available green mod slots.");
            }
            if (modType == CustomItemPropertyType.YellowMod && !modSlots.CanYellowModBeAdded)
            {
                return("That item has no available yellow mod slots.");
            }

            // Get the perk level based on target item type and mod type.
            if (WeaponsmithBaseItemTypes.Contains(targetItem.BaseItemType))
            {
                switch (modType)
                {
                case CustomItemPropertyType.RedMod:
                    perkLevel = PerkService.GetPCPerkLevel(player, PerkType.CombatModInstallationWeapons);
                    break;

                case CustomItemPropertyType.BlueMod:
                    perkLevel = PerkService.GetPCPerkLevel(player, PerkType.ForceModInstallationWeapons);
                    break;

                case CustomItemPropertyType.GreenMod:
                    perkLevel = PerkService.GetPCPerkLevel(player, PerkType.CraftingModInstallationWeapons);
                    break;

                case CustomItemPropertyType.YellowMod:
                    perkLevel = PerkService.GetPCPerkLevel(player, PerkType.SpecialModInstallationWeapons);
                    break;

                default:
                    perkLevel = 0;
                    break;
                }
            }
            else if (ArmorBaseItemTypes.Contains(targetItem.BaseItemType))
            {
                switch (modType)
                {
                case CustomItemPropertyType.RedMod:
                    perkLevel = PerkService.GetPCPerkLevel(player, PerkType.CombatModInstallationArmors);
                    break;

                case CustomItemPropertyType.BlueMod:
                    perkLevel = PerkService.GetPCPerkLevel(player, PerkType.ForceModInstallationArmors);
                    break;

                case CustomItemPropertyType.GreenMod:
                    perkLevel = PerkService.GetPCPerkLevel(player, PerkType.CraftingModInstallationArmors);
                    break;

                case CustomItemPropertyType.YellowMod:
                    perkLevel = PerkService.GetPCPerkLevel(player, PerkType.SpecialModInstallationArmors);
                    break;

                default:
                    perkLevel = 0;
                    break;
                }
            }
            else if (EngineeringBaseItemTypes.Contains(targetItem.BaseItemType))
            {
                switch (modType)
                {
                case CustomItemPropertyType.RedMod:
                    perkLevel = PerkService.GetPCPerkLevel(player, PerkType.CombatModInstallationEngineering);
                    break;

                case CustomItemPropertyType.BlueMod:
                    perkLevel = PerkService.GetPCPerkLevel(player, PerkType.ForceModInstallationEngineering);
                    break;

                case CustomItemPropertyType.GreenMod:
                    perkLevel = PerkService.GetPCPerkLevel(player, PerkType.CraftingModInstallationEngineering);
                    break;

                case CustomItemPropertyType.YellowMod:
                    perkLevel = PerkService.GetPCPerkLevel(player, PerkType.SpecialModInstallationEngineering);
                    break;

                default:
                    perkLevel = 0;
                    break;
                }
            }

            // Ensure item isn't equipped.
            for (int slot = 0; slot < NUM_INVENTORY_SLOTS; slot++)
            {
                if (_.GetItemInSlot(slot, user.Object) == targetItem.Object)
                {
                    return("Targeted item must be unequipped before installing a mod.");
                }
            }

            // Check for perk level requirement
            if (perkLevel < requiredPerkLevel)
            {
                return("You do not have the necessary perk rank required. (Required: " + requiredPerkLevel + ", Your level: " + perkLevel + ")");
            }

            // Can't modify items above perk level * 10
            if (itemLevel > perkLevel * 10)
            {
                return("Your current perks allow you to add mods to items up to level " + perkLevel * 10 + ". This item is level " + itemLevel + " so you can't install a mod into it.");
            }

            // Item must be in the user's inventory.
            if (!targetItem.Possessor.Equals(player))
            {
                return("Targeted item must be in your inventory.");
            }

            var handler = ModService.GetModHandler(modID);

            // Run the individual mod's rules for application. Will return the error message or a null.
            return(handler.CanApply(player, targetItem, modArgs));
        }
コード例 #2
0
        public void ApplyEffects(NWCreature user, NWItem modItem, NWObject target, Location targetLocation, CustomData customData)
        {
            NWPlayer player                = (user.Object);
            NWItem   targetItem            = (target.Object);
            ModSlots slots                 = ModService.GetModSlots(targetItem);
            CustomItemPropertyType modType = ModService.GetModType(modItem);
            int modID = modItem.GetLocalInt("RUNE_ID");

            string[] modArgs       = modItem.GetLocalString("RUNE_VALUE").Split(',');
            int      modLevel      = modItem.RecommendedLevel;
            int      levelIncrease = modItem.LevelIncrease;

            var mod = ModService.GetModHandler(modID);

            mod.Apply(player, targetItem, modArgs);

            string description  = mod.Description(player, targetItem, modArgs);
            bool   usePrismatic = false;

            switch (modType)
            {
            case CustomItemPropertyType.RedMod:
                if (slots.FilledRedSlots < slots.RedSlots)
                {
                    targetItem.SetLocalInt("MOD_SLOT_RED_" + (slots.FilledRedSlots + 1), modID);
                    targetItem.SetLocalString("MOD_SLOT_RED_DESC_" + (slots.FilledRedSlots + 1), description);
                    player.SendMessage("Mod installed into " + ColorTokenService.Red("red") + " slot #" + (slots.FilledRedSlots + 1));
                }
                else
                {
                    usePrismatic = true;
                }
                break;

            case CustomItemPropertyType.BlueMod:
                if (slots.FilledBlueSlots < slots.BlueSlots)
                {
                    targetItem.SetLocalInt("MOD_SLOT_BLUE_" + (slots.FilledBlueSlots + 1), modID);
                    targetItem.SetLocalString("MOD_SLOT_BLUE_DESC_" + (slots.FilledBlueSlots + 1), description);
                    player.SendMessage("Mod installed into " + ColorTokenService.Blue("blue") + " slot #" + (slots.FilledBlueSlots + 1));
                }
                else
                {
                    usePrismatic = true;
                }
                break;

            case CustomItemPropertyType.GreenMod:
                if (slots.FilledBlueSlots < slots.GreenSlots)
                {
                    targetItem.SetLocalInt("MOD_SLOT_GREEN_" + (slots.FilledGreenSlots + 1), modID);
                    targetItem.SetLocalString("MOD_SLOT_GREEN_DESC_" + (slots.FilledGreenSlots + 1), description);
                    player.SendMessage("Mod installed into " + ColorTokenService.Green("green") + " slot #" + (slots.FilledGreenSlots + 1));
                }
                else
                {
                    usePrismatic = true;
                }
                break;

            case CustomItemPropertyType.YellowMod:
                if (slots.FilledBlueSlots < slots.YellowSlots)
                {
                    targetItem.SetLocalInt("MOD_SLOT_YELLOW_" + (slots.FilledYellowSlots + 1), modID);
                    targetItem.SetLocalString("MOD_SLOT_YELLOW_DESC_" + (slots.FilledYellowSlots + 1), description);
                    player.SendMessage("Mod installed into " + ColorTokenService.Yellow("yellow") + " slot #" + (slots.FilledYellowSlots + 1));
                }
                else
                {
                    usePrismatic = true;
                }
                break;
            }

            if (usePrismatic)
            {
                string prismaticText = ModService.PrismaticString();
                targetItem.SetLocalInt("MOD_SLOT_PRISMATIC_" + (slots.FilledPrismaticSlots + 1), modID);
                targetItem.SetLocalString("MOD_SLOT_PRISMATIC_DESC_" + (slots.FilledPrismaticSlots + 1), description);
                player.SendMessage("Mod installed into " + prismaticText + " slot #" + (slots.FilledPrismaticSlots + 1));
            }

            targetItem.RecommendedLevel += levelIncrease;
            modItem.Destroy();

            SkillType skillType;

            if (ArmorBaseItemTypes.Contains(targetItem.BaseItemType))
            {
                skillType = SkillType.Armorsmith;
            }
            else if (WeaponsmithBaseItemTypes.Contains(targetItem.BaseItemType))
            {
                skillType = SkillType.Weaponsmith;
            }
            else if (EngineeringBaseItemTypes.Contains(targetItem.BaseItemType))
            {
                skillType = SkillType.Engineering;
            }
            else
            {
                return;
            }

            int rank = SkillService.GetPCSkillRank(player, skillType);
            int xp   = (int)SkillService.CalculateRegisteredSkillLevelAdjustedXP(400, modLevel, rank);

            SkillService.GiveSkillXP(player, skillType, xp);
        }
コード例 #3
0
        public string IsValidTarget(NWCreature user, NWItem mod, NWObject target, Location targetLocation)
        {
            if (target.ObjectType != ObjectType.Item)
            {
                return("Only items may be targeted by mods.");
            }
            if (!user.IsPlayer && !user.IsDM)
            {
                return("Only players may use mods.");
            }
            NWPlayer player     = (user.Object);
            NWItem   targetItem = (target.Object);

            int modLevel          = mod.RecommendedLevel;
            int itemLevel         = targetItem.RecommendedLevel;
            int requiredPerkLevel = modLevel / 5;

            if (requiredPerkLevel <= 0)
            {
                requiredPerkLevel = 1;
            }
            int perkLevel             = 0;
            ItemPropertyType modType  = ModService.GetModType(mod);
            ModSlots         modSlots = ModService.GetModSlots(targetItem);
            int modID = mod.GetLocalInt("RUNE_ID");

            string[] modArgs = mod.GetLocalString("RUNE_VALUE").Split(',');

            // Check for a misconfigured mod item.
            if (modType == ItemPropertyType.Invalid)
            {
                return("Mod color couldn't be found. Notify an admin that this mod item is not set up properly.");
            }
            if (modID <= 0)
            {
                return("Mod ID couldn't be found. Notify an admin that this mod item is not set up properly.");
            }
            if (modArgs.Length <= 0)
            {
                return("Mod value couldn't be found. Notify an admin that this mod item is not set up properly.");
            }

            // No available slots on target item
            if (modType == ItemPropertyType.RedMod && !modSlots.CanRedModBeAdded)
            {
                return("That item has no available red mod slots.");
            }
            if (modType == ItemPropertyType.BlueMod && !modSlots.CanBlueModBeAdded)
            {
                return("That item has no available blue mod slots.");
            }
            if (modType == ItemPropertyType.GreenMod && !modSlots.CanGreenModBeAdded)
            {
                return("That item has no available green mod slots.");
            }
            if (modType == ItemPropertyType.YellowMod && !modSlots.CanYellowModBeAdded)
            {
                return("That item has no available yellow mod slots.");
            }

            // Get the perk level based on target item type and mod type.
            if (GetLocalBool(targetItem, "LIGHTSABER") == false && WeaponsmithBaseItemTypes.Contains(targetItem.BaseItemType))
            {
                perkLevel = PerkService.GetCreaturePerkLevel(player, PerkType.WeaponModInstallation);
            }
            else if (ArmorBaseItemTypes.Contains(targetItem.BaseItemType))
            {
                perkLevel = PerkService.GetCreaturePerkLevel(player, PerkType.ArmorModInstallation);
            }
            else if (GetLocalBool(targetItem, "LIGHTSABER") == true || EngineeringBaseItemTypes.Contains(targetItem.BaseItemType))
            {
                perkLevel = PerkService.GetCreaturePerkLevel(player, PerkType.EngineeringModInstallation);
            }

            // Ensure item isn't equipped.
            for (int slot = 0; slot < NumberOfInventorySlots; slot++)
            {
                if (_.GetItemInSlot((InventorySlot)slot, user.Object) == targetItem.Object)
                {
                    return("Targeted item must be unequipped before installing a mod.");
                }
            }

            // Check for perk level requirement
            if (perkLevel < requiredPerkLevel && !player.IsDM)
            {
                return("You do not have the necessary perk rank required. (Required: " + requiredPerkLevel + ", Your level: " + perkLevel + ")");
            }

            // Can't modify items above perk level * 10
            if (itemLevel > perkLevel * 10 && !player.IsDM)
            {
                return("Your current perks allow you to add mods to items up to level " + perkLevel * 10 + ". This item is level " + itemLevel + " so you can't install a mod into it.");
            }

            // Item must be in the user's inventory.
            if (!targetItem.Possessor.Equals(player))
            {
                return("Targeted item must be in your inventory.");
            }

            // It's possible that this mod is no longer usable. Notify the player if we can't find one registered.
            if (!ModService.IsModHandlerRegistered(modID))
            {
                return("Unfortunately, this mod can no longer be used.");
            }

            var handler = ModService.GetModHandler(modID);

            // Run the individual mod's rules for application. Will return the error message or a null.
            return(handler.CanApply(player, targetItem, modArgs));
        }