Ejemplo n.º 1
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);
            ItemPropertyType 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 ItemPropertyType.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 ItemPropertyType.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 ItemPropertyType.GreenMod:
                if (slots.FilledGreenSlots < 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 ItemPropertyType.YellowMod:
                if (slots.FilledYellowSlots < 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 (GetLocalBool(targetItem, "LIGHTSABER") == true)
            {
                skillType = SkillType.Engineering;
            }
            else 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);
        }
Ejemplo n.º 2
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));
        }