Example #1
0
        public static string OnModuleExamine(string existingDescription, NWPlayer examiner, NWObject examinedObject)
        {
            if (examinedObject.ObjectType != _.OBJECT_TYPE_ITEM)
            {
                return(existingDescription);
            }
            NWItem   examinedItem = (examinedObject.Object);
            string   description  = string.Empty;
            ModSlots slot         = GetModSlots(examinedItem);

            for (int red = 1; red <= slot.FilledRedSlots; red++)
            {
                description += ColorTokenService.Red("Red Slot #" + red + ": ") + examinedItem.GetLocalString("MOD_SLOT_RED_DESC_" + red) + "\n";
            }
            for (int blue = 1; blue <= slot.FilledBlueSlots; blue++)
            {
                description += ColorTokenService.Red("Blue Slot #" + blue + ": ") + examinedItem.GetLocalString("MOD_SLOT_BLUE_DESC_" + blue) + "\n";
            }
            for (int green = 1; green <= slot.FilledGreenSlots; green++)
            {
                description += ColorTokenService.Red("Green Slot #" + green + ": ") + examinedItem.GetLocalString("MOD_SLOT_GREEN_DESC_" + green) + "\n";
            }
            for (int yellow = 1; yellow <= slot.FilledYellowSlots; yellow++)
            {
                description += ColorTokenService.Red("Yellow Slot #" + yellow + ": ") + examinedItem.GetLocalString("MOD_SLOT_YELLOW_DESC_" + yellow) + "\n";
            }
            for (int prismatic = 1; prismatic <= slot.FilledPrismaticSlots; prismatic++)
            {
                description += PrismaticString() + " Slot #" + prismatic + ": " + examinedItem.GetLocalString("MOD_SLOT_PRISMATIC_DESC_" + prismatic) + "\n";
            }

            return(existingDescription + "\n" + description);
        }
Example #2
0
        private void ResetName()
        {
            NWPlayer player = GetPC();
            NWItem   item   = player.GetLocalObject("ITEM_BEING_RENAMED");

            if (string.IsNullOrWhiteSpace(item.GetLocalString("RENAMED_ITEM_ORIGINAL_NAME")))
            {
                item.SetLocalString("RENAMED_ITEM_ORIGINAL_NAME", item.Name);
            }

            item.Name = item.GetLocalString("RENAMED_ITEM_ORIGINAL_NAME");
        }
Example #3
0
        private static void OnModuleUseFeat()
        {
            NWPlayer pc     = _.OBJECT_SELF;
            int      featID = Convert.ToInt32(NWNXEvents.GetEventData("FEAT_ID"));

            if (featID != (int)Feat.RenameCraftedItem)
            {
                return;
            }
            pc.ClearAllActions();

            bool   isSetting  = GetLocalBool(pc, "CRAFT_RENAMING_ITEM") == true;
            NWItem renameItem = NWNXObject.StringToObject(NWNXEvents.GetEventData("TARGET_OBJECT_ID"));

            if (isSetting)
            {
                pc.SendMessage("You are no longer naming an item.");
                pc.DeleteLocalInt("CRAFT_RENAMING_ITEM");
                pc.DeleteLocalObject("CRAFT_RENAMING_ITEM_OBJECT");
                return;
            }

            string crafterPlayerID = renameItem.GetLocalString("CRAFTER_PLAYER_ID");

            if (string.IsNullOrWhiteSpace(crafterPlayerID) || new Guid(crafterPlayerID) != pc.GlobalID)
            {
                pc.SendMessage("You may only rename items which you have personally crafted.");
                return;
            }

            SetLocalBool(pc, "CRAFT_RENAMING_ITEM", true);
            pc.SetLocalObject("CRAFT_RENAMING_ITEM_OBJECT", renameItem);
            pc.SendMessage("Please enter in a name for this item. Length should be between 3 and 64 characters. Use this feat again to cancel this procedure.");
        }
Example #4
0
        public void ApplyEffects(NWCreature user, NWItem item, NWObject target, Location targetLocation, CustomData customData)
        {
            user.SetLocalObject("ITEM_BEING_RENAMED", item);
            string conversation = item.GetLocalString("CONVERSATION");

            DialogService.StartConversation((NWPlayer)user, user, conversation);
        }
Example #5
0
        private void LoadHeader()
        {
            NWPlayer player = GetPC();

            player.SetLocalBool("ITEM_RENAMING_LISTENING", true);

            NWItem item         = player.GetLocalObject("ITEM_BEING_RENAMED");
            string originalName = item.GetLocalString("RENAMED_ITEM_ORIGINAL_NAME");

            if (string.IsNullOrWhiteSpace(originalName))
            {
                originalName = item.Name;
            }
            string currentName  = item.Name;
            string renamingName = player.GetLocalString("RENAMED_ITEM_NEW_NAME");

            if (string.IsNullOrWhiteSpace(renamingName))
            {
                renamingName = "{UNSPECIFIED}";
            }

            string header = "You are renaming an item.\n\n";

            header += ColorTokenService.Green("Original Name: ") + originalName + "\n";
            header += ColorTokenService.Green("Current Name: ") + currentName + "\n";
            header += ColorTokenService.Green("New Name: ") + renamingName + "\n";
            header += "Type in a new name, click 'Refresh', and then select 'Change Name' to make the changes. Click 'Reset Name' to switch back to the item's original name.";

            SetPageHeader("MainPage", header);
        }
Example #6
0
        private static void OnModuleUseFeat()
        {
            NWPlayer pc     = Object.OBJECT_SELF;
            int      featID = NWNXEvents.OnFeatUsed_GetFeatID();

            if (featID != (int)CustomFeatType.RenameCraftedItem)
            {
                return;
            }
            pc.ClearAllActions();

            bool   isSetting  = pc.GetLocalInt("CRAFT_RENAMING_ITEM") == TRUE;
            NWItem renameItem = NWNXEvents.OnFeatUsed_GetTarget().Object;

            if (isSetting)
            {
                pc.SendMessage("You are no longer naming an item.");
                pc.DeleteLocalInt("CRAFT_RENAMING_ITEM");
                pc.DeleteLocalObject("CRAFT_RENAMING_ITEM_OBJECT");
                return;
            }

            string crafterPlayerID = renameItem.GetLocalString("CRAFTER_PLAYER_ID");

            if (string.IsNullOrWhiteSpace(crafterPlayerID) || new Guid(crafterPlayerID) != pc.GlobalID)
            {
                pc.SendMessage("You may only rename items which you have personally crafted.");
                return;
            }

            pc.SetLocalInt("CRAFT_RENAMING_ITEM", TRUE);
            pc.SetLocalObject("CRAFT_RENAMING_ITEM_OBJECT", renameItem);
            pc.SendMessage("Please enter in a name for this item. Length should be between 3 and 64 characters. Use this feat again to cancel this procedure.");
        }
Example #7
0
        private void ChangeName()
        {
            NWPlayer player = GetPC();

            // Player hasn't specified a new name for this item.
            string newName = player.GetLocalString("RENAMED_ITEM_NEW_NAME");

            if (string.IsNullOrWhiteSpace(newName))
            {
                player.FloatingText("Enter a new name into the chat box, select 'Refresh' then select 'Change Name'.");
                return;
            }
            NWItem item = player.GetLocalObject("ITEM_BEING_RENAMED");

            // Item isn't in player's inventory.
            if (_.GetItemPossessor(item) != player.Object)
            {
                player.FloatingText("Item must be in your inventory in order to rename it.");
                return;
            }

            // Item's original name isn't being stored. Do that now.
            if (string.IsNullOrWhiteSpace(item.GetLocalString("RENAMED_ITEM_ORIGINAL_NAME")))
            {
                item.SetLocalString("RENAMED_ITEM_ORIGINAL_NAME", item.Name);
            }

            item.Name = newName;

            player.FloatingText("Item renamed to '" + newName + "'.");
            EndConversation();
        }
Example #8
0
        public void ApplyEffects(NWCreature user, NWItem item, NWObject target, Location targetLocation, CustomData customData)
        {
            string type   = item.GetLocalString("BONUS_TYPE");
            int    length = item.GetLocalInt("BONUS_LENGTH") * 60;
            int    amount = item.GetLocalInt("BONUS_AMOUNT");

            string data = $"{type},{amount}";

            _customEffect.ApplyCustomEffect(user, target.Object, CustomEffectType.FoodEffect, length, item.RecommendedLevel, data);
        }
Example #9
0
        public bool Run(params object[] args)
        {
            if (_.GetInventoryDisturbType() != _.INVENTORY_DISTURB_TYPE_ADDED)
            {
                return(false);
            }

            NWPlayer    player = _.GetLastDisturbed();
            NWPlaceable device = Object.OBJECT_SELF;
            NWItem      item   = _.GetInventoryDisturbItem();

            // Check the item type to see if it's valid.
            if (!IsValidItemType(item))
            {
                ItemService.ReturnItem(player, item);
                player.SendMessage("You cannot reassemble this item.");
                return(false);
            }

            // Only crafted items can be reassembled.
            if (string.IsNullOrWhiteSpace(item.GetLocalString("CRAFTER_PLAYER_ID")))
            {
                ItemService.ReturnItem(player, item);
                player.SendMessage("Only crafted items may be reassembled.");
                return(false);
            }

            // DMs cannot reassemble because they don't have the necessary DB records.
            if (player.IsDM)
            {
                ItemService.ReturnItem(player, item);
                player.SendMessage("DMs cannot reassemble items at this time.");
                return(false);
            }

            // Serialize the item into a string and store it into the temporary data for this player. Destroy the physical item.
            var model = CraftService.GetPlayerCraftingData(player);

            model.SerializedSalvageItem = SerializationService.Serialize(item);
            item.Destroy();

            // Start the Molecular Reassembly conversation.
            DialogService.StartConversation(player, device, "MolecularReassembly");

            return(true);
        }
Example #10
0
        public string IsValidTarget(NWCreature user, NWItem item, NWObject target, Location targetLocation)
        {
            string type   = item.GetLocalString("BONUS_TYPE");
            int    length = item.GetLocalInt("BONUS_LENGTH");
            int    amount = item.GetLocalInt("BONUS_AMOUNT");

            if (string.IsNullOrWhiteSpace(type) || length <= 0 || amount <= 0)
            {
                return("ERROR: This food isn't set up properly. Please inform an admin. Resref: " + item.Resref);
            }

            bool hasFoodEffect = _customEffect.DoesPCHaveCustomEffectByCategory(user.Object, CustomEffectCategoryType.FoodEffect);

            if (hasFoodEffect)
            {
                return("You are not hungry right now.");
            }

            return(null);
        }
Example #11
0
        public void Main()
        {
            NWPlaceable container = (NWGameObject.OBJECT_SELF);
            NWPlayer    oPC       = (_.GetLastDisturbed());
            NWItem      oItem     = (_.GetInventoryDisturbItem());
            int         type      = _.GetInventoryDisturbType();

            if (type == _.INVENTORY_DISTURB_TYPE_ADDED)
            {
                container.AssignCommand(() => _.ActionGiveItem(oItem.Object, oPC.Object));
                return;
            }

            Guid           overflowItemID = new Guid(oItem.GetLocalString("TEMP_OVERFLOW_ITEM_ID"));
            PCOverflowItem overflowItem   = DataService.PCOverflowItem.GetByID(overflowItemID);

            DataService.SubmitDataChange(overflowItem, DatabaseActionType.Delete);
            oItem.DeleteLocalInt("TEMP_OVERFLOW_ITEM_ID");

            if (!container.InventoryItems.Any())
            {
                container.Destroy();
            }
        }
Example #12
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));
        }
Example #13
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));
        }
Example #14
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);
        }
Example #15
0
        public void OnModuleActivatedItem()
        {
            NWPlayer user           = (_.GetItemActivator());
            NWItem   oItem          = (_.GetItemActivated());
            NWObject target         = (_.GetItemActivatedTarget());
            Location targetLocation = _.GetItemActivatedTargetLocation();

            string className = oItem.GetLocalString("JAVA_SCRIPT");

            if (string.IsNullOrWhiteSpace(className))
            {
                className = oItem.GetLocalString("ACTIVATE_JAVA_SCRIPT");
            }
            if (string.IsNullOrWhiteSpace(className))
            {
                className = oItem.GetLocalString("JAVA_ACTION_SCRIPT");
            }
            if (string.IsNullOrWhiteSpace(className))
            {
                className = oItem.GetLocalString("SCRIPT");
            }
            if (string.IsNullOrWhiteSpace(className))
            {
                return;
            }

            user.ClearAllActions();

            if (user.IsBusy)
            {
                user.SendMessage("You are busy.");
                return;
            }

            // Remove "Item." prefix if it exists.
            if (className.StartsWith("Item."))
            {
                className = className.Substring(5);
            }

            App.ResolveByInterface <IActionItem>("Item." + className, (item) =>
            {
                string invalidTargetMessage = item.IsValidTarget(user, oItem, target, targetLocation);
                if (!string.IsNullOrWhiteSpace(invalidTargetMessage))
                {
                    user.SendMessage(invalidTargetMessage);
                    return;
                }

                float maxDistance = item.MaxDistance(user, oItem, target, targetLocation);
                if (maxDistance > 0.0f)
                {
                    if (target.IsValid &&
                        (_.GetDistanceBetween(user.Object, target.Object) > maxDistance ||
                         user.Area.Resref != target.Area.Resref))
                    {
                        user.SendMessage("Your target is too far away.");
                        return;
                    }
                    else if (!target.IsValid &&
                             (_.GetDistanceBetweenLocations(user.Location, targetLocation) > maxDistance ||
                              user.Area.Resref != ((NWArea)_.GetAreaFromLocation(targetLocation)).Resref))
                    {
                        user.SendMessage("That location is too far away.");
                        return;
                    }
                }

                CustomData customData = item.StartUseItem(user, oItem, target, targetLocation);
                float delay           = item.Seconds(user, oItem, target, targetLocation, customData);
                int animationID       = item.AnimationID();
                bool faceTarget       = item.FaceTarget();
                Vector userPosition   = user.Position;

                user.AssignCommand(() =>
                {
                    user.IsBusy = true;
                    if (faceTarget)
                    {
                        _.SetFacingPoint(!target.IsValid ? _.GetPositionFromLocation(targetLocation) : target.Position);
                    }
                    if (animationID > 0)
                    {
                        _.ActionPlayAnimation(animationID, 1.0f, delay);
                    }
                });

                _nwnxPlayer.StartGuiTimingBar(user, delay, string.Empty);
                user.DelayEvent <FinishActionItem>(
                    delay,
                    className,
                    user,
                    oItem,
                    target,
                    targetLocation,
                    userPosition,
                    customData);
            });
        }
Example #16
0
        public bool Run(params object[] args)
        {
            NWPlaceable container = Object.OBJECT_SELF;
            NWObject    owner     = container.GetLocalObject("QUEST_OWNER");

            NWPlayer player            = _.GetLastDisturbed();
            NWItem   item              = _.GetInventoryDisturbItem();
            int      disturbType       = _.GetInventoryDisturbType();
            string   crafterPlayerID   = item.GetLocalString("CRAFTER_PLAYER_ID");
            Guid?    crafterPlayerGUID = null;

            if (!string.IsNullOrWhiteSpace(crafterPlayerID))
            {
                crafterPlayerGUID = new Guid(crafterPlayerID);
            }

            if (disturbType == INVENTORY_DISTURB_TYPE_ADDED)
            {
                int                 questID  = container.GetLocalInt("QUEST_ID");
                PCQuestStatus       status   = _data.Single <PCQuestStatus>(x => x.PlayerID == player.GlobalID && x.QuestID == questID);
                PCQuestItemProgress progress = _data.SingleOrDefault <PCQuestItemProgress>(x => x.PCQuestStatusID == status.ID && x.Resref == item.Resref);
                DatabaseActionType  action   = DatabaseActionType.Update;

                if (progress == null)
                {
                    _.CopyItem(item, player, TRUE);
                    player.SendMessage(_color.Red("That item is not required for this quest."));
                }
                else if (progress.MustBeCraftedByPlayer && crafterPlayerGUID != player.GlobalID)
                {
                    _.CopyItem(item, player, TRUE);
                    player.SendMessage(_color.Red("You may only submit items which you have personally created for this quest."));
                }
                else
                {
                    progress.Remaining--;

                    if (progress.Remaining <= 0)
                    {
                        var progressCopy = progress;
                        progress = _data.Single <PCQuestItemProgress>(x => x.ID == progressCopy.ID);
                        action   = DatabaseActionType.Delete;
                    }
                    _data.SubmitDataChange(progress, action);

                    // Recalc the remaining items needed.
                    int remainingCount = _data.GetAll <PCQuestItemProgress>().Count(x => x.PCQuestStatusID == status.ID);
                    if (remainingCount <= 0)
                    {
                        _quest.AdvanceQuestState(player, owner, questID);
                    }

                    player.SendMessage("You need " + progress.Remaining + " " + item.Name + " for this quest.");
                }
                item.Destroy();

                var questItemProgresses = _data.Where <PCQuestItemProgress>(x => x.PCQuestStatusID == status.ID);
                if (!questItemProgresses.Any())
                {
                    string conversation = _.GetLocalString(owner, "CONVERSATION");
                    if (!string.IsNullOrWhiteSpace(conversation))
                    {
                        _dialog.StartConversation(player, owner, conversation);
                    }
                    else
                    {
                        player.AssignCommand(() =>
                        {
                            _.ActionStartConversation(owner, "", TRUE, FALSE);
                        });
                    }
                }
            }

            return(true);
        }
Example #17
0
        public bool Run(params object[] args)
        {
            int type = _.GetInventoryDisturbType();

            if (type != INVENTORY_DISTURB_TYPE_ADDED)
            {
                return(true);
            }
            NWPlaceable device      = Object.OBJECT_SELF;
            NWPlayer    player      = _.GetLastDisturbed();
            NWItem      item        = _.GetInventoryDisturbItem();
            var         componentIP = item.ItemProperties.FirstOrDefault(x => _.GetItemPropertyType(x) == (int)CustomItemPropertyType.ComponentType);

            // Not a component. Return the item.
            if (componentIP == null)
            {
                ItemService.ReturnItem(player, item);
                player.FloatingText("You cannot scrap this item.");
                return(false);
            }

            // Item is a component but it was crafted. Cannot scrap crafted items.
            if (!string.IsNullOrWhiteSpace(item.GetLocalString("CRAFTER_PLAYER_ID")))
            {
                ItemService.ReturnItem(player, item);
                player.FloatingText("You cannot scrap crafted items.");
                return(false);
            }

            // Remove the item properties
            foreach (var ip in item.ItemProperties)
            {
                var ipType = _.GetItemPropertyType(ip);
                if (ipType != (int)CustomItemPropertyType.ComponentType)
                {
                    _.RemoveItemProperty(item, ip);
                }
            }

            // Remove local variables (except the global ID)
            int varCount = NWNXObject.GetLocalVariableCount(item);

            for (int index = varCount - 1; index >= 0; index--)
            {
                var localVar = NWNXObject.GetLocalVariable(item, index);

                if (localVar.Key != "GLOBAL_ID")
                {
                    switch (localVar.Type)
                    {
                    case LocalVariableType.Int:
                        item.DeleteLocalInt(localVar.Key);
                        break;

                    case LocalVariableType.Float:
                        item.DeleteLocalFloat(localVar.Key);
                        break;

                    case LocalVariableType.String:
                        item.DeleteLocalString(localVar.Key);
                        break;

                    case LocalVariableType.Object:
                        item.DeleteLocalObject(localVar.Key);
                        break;

                    case LocalVariableType.Location:
                        item.DeleteLocalLocation(localVar.Key);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }

            if (!item.Name.Contains("(SCRAPPED)"))
            {
                item.Name = item.Name + " (SCRAPPED)";
            }

            device.AssignCommand(() =>
            {
                _.ActionGiveItem(item, player);
            });

            return(true);
        }
Example #18
0
        public void ApplyEffects(NWCreature user, NWItem modItem, NWObject target, Location targetLocation, CustomData customData)
        {
            NWPlayer player                = (user.Object);
            NWItem   targetItem            = (target.Object);
            ModSlots slots                 = _mod.GetModSlots(targetItem);
            CustomItemPropertyType modType = _mod.GetModType(modItem);
            int modID = modItem.GetLocalInt("RUNE_ID");

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

            var dbMod = _data.Single <Data.Entity.Mod>(x => x.ID == modID && x.IsActive);

            App.ResolveByInterface <IMod>("Mod." + dbMod.Script, mod =>
            {
                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 " + _color.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 " + _color.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 " + _color.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 " + _color.Yellow("yellow") + " slot #" + (slots.FilledYellowSlots + 1));
                    }
                    else
                    {
                        usePrismatic = true;
                    }
                    break;
                }

                if (usePrismatic)
                {
                    string prismaticText = _mod.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 (ItemService.ArmorBaseItemTypes.Contains(targetItem.BaseItemType))
                {
                    skillType = SkillType.Armorsmith;
                }
                else if (ItemService.WeaponBaseItemTypes.Contains(targetItem.BaseItemType))
                {
                    skillType = SkillType.Weaponsmith;
                }
                else
                {
                    return;
                }

                int rank = _skill.GetPCSkillRank(player, skillType);
                int xp   = (int)_skill.CalculateRegisteredSkillLevelAdjustedXP(400, modLevel, rank);
                _skill.GiveSkillXP(player, skillType, xp);
            });
        }
Example #19
0
        public string IsValidTarget(NWCreature user, NWItem mod, NWObject target, Location targetLocation)
        {
            if (target.ObjectType != NWScript.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 = _mod.GetModType(mod);
            ModSlots modSlots = _mod.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 (ItemService.WeaponBaseItemTypes.Contains(targetItem.BaseItemType))
            {
                switch (modType)
                {
                case CustomItemPropertyType.RedMod:
                    perkLevel = _perk.GetPCPerkLevel(player, PerkType.CombatModInstallationWeapons);
                    break;

                case CustomItemPropertyType.BlueMod:
                    perkLevel = _perk.GetPCPerkLevel(player, PerkType.MagicModInstallationWeapons);
                    break;

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

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

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

                case CustomItemPropertyType.BlueMod:
                    perkLevel = _perk.GetPCPerkLevel(player, PerkType.MagicModInstallationArmors);
                    break;

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

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

                default:
                    perkLevel = 0;
                    break;
                }
            }

            // Ensure item isn't equipped.
            for (int slot = 0; slot < NWScript.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 + ")");
            }

            // 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.");
            }

            // Look for a database entry for this mod type.
            var dbMod = _data.SingleOrDefault <Data.Entity.Mod>(x => x.ID == modID && x.IsActive);

            if (dbMod == null)
            {
                return("Couldn't find a matching mod ID in the database. Inform an admin of this issue.");
            }

            // Run the individual mod's rules for application. Will return the error message or a null.
            string canApply = App.ResolveByInterface <IMod, string>("Mod." + dbMod.Script,
                                                                    (modRules) => modRules.CanApply(player, targetItem, modArgs));

            return(canApply);
        }
Example #20
0
        public void ApplyEffects(NWCreature user, NWItem item, NWObject target, Location targetLocation, CustomData customData)
        {
            string conversation = item.GetLocalString("CONVERSATION");

            _dialog.StartConversation((NWPlayer)user, user, conversation);
        }
Example #21
0
        /// <summary>
        /// Returns an ID tied to the MarketCategory table. This is where players may find
        /// the item on the marketplace.
        /// </summary>
        /// <param name="item">The item to use for the determination.</param>
        /// <returns>The market category ID or a value of -1 if item is not supported.</returns>
        public static int DetermineMarketCategory(NWItem item)
        {
            // ===============================================================================
            // The following items are intentionally excluded from market transactions:
            // Lightsaber, Saberstaff
            // ===============================================================================

            // Some of the determinations require looking at the item's properties. Pull that list back now for later use.
            var properties = item.ItemProperties.ToList();
            var resref     = item.Resref;

            // Weapons - These IDs are based solely on the NWN BaseItemType
            switch (item.BaseItemType)
            {
            case BASE_ITEM_GREATAXE: return(1);

            case BASE_ITEM_BATTLEAXE: return(2);

            case BASE_ITEM_BASTARDSWORD: return(3);

            case BASE_ITEM_DAGGER: return(4);

            case BASE_ITEM_GREATSWORD: return(5);

            case BASE_ITEM_LONGSWORD: return(7);

            case BASE_ITEM_RAPIER: return(8);

            case BASE_ITEM_KATANA: return(9);

            case BASE_ITEM_SHORTSWORD: return(10);

            case BASE_ITEM_CLUB: return(11);

            case BASE_ITEM_LIGHTMACE: return(12);

            case BASE_ITEM_MORNINGSTAR: return(13);

            case BASE_ITEM_QUARTERSTAFF: return(15);

            case BASE_ITEM_DOUBLEAXE: return(16);

            case BASE_ITEM_TWOBLADEDSWORD: return(17);

            case BASE_ITEM_KUKRI: return(18);

            case BASE_ITEM_HALBERD: return(19);

            case BASE_ITEM_SHORTSPEAR: return(20);

            case BASE_ITEM_LIGHTCROSSBOW: return(21); // Blaster Rifles

            case BASE_ITEM_SHORTBOW: return(22);      // Blaster Pistols

            case BASE_ITEM_HELMET: return(23);

            case BASE_ITEM_SMALLSHIELD: return(28);    // Shields

            case BASE_ITEM_LARGESHIELD: return(28);    // Shields

            case BASE_ITEM_TOWERSHIELD: return(28);    // Shields

            case BASE_ITEM_BOOK: return(29);

            case BASE_ITEM_GLOVES: return(30);    // Power Gloves

            case BASE_ITEM_AMULET: return(102);   // Necklace

            case BASE_ITEM_RING: return(103);
            }

            // Check for armor.
            if (item.BaseItemType == BASE_ITEM_ARMOR ||
                item.BaseItemType == BASE_ITEM_BELT ||
                item.BaseItemType == BASE_ITEM_CLOAK ||
                item.BaseItemType == BASE_ITEM_BOOTS)
            {
                switch (item.CustomItemType)
                {
                case CustomItemType.LightArmor: return(24);

                case CustomItemType.ForceArmor: return(25);

                case CustomItemType.HeavyArmor: return(26);

                default: return(23);    // Default to clothes if no armor type is specified.
                }
            }

            // Check for Scanners
            if (item.GetLocalString("SCRIPT") == "ResourceScanner" ||
                item.GetLocalString("SCRIPT") == "MineralScanner")
            {
                return(31);
            }
            // Check for Harvesters
            if (item.GetLocalString("SCRIPT") == "ResourceHarvester")
            {
                return(32);
            }
            // Check for Repair Kits
            if (item.GetLocalString("SCRIPT") == "RepairKit")
            {
                return(104);
            }
            // Check for Stim Packs
            if (item.GetLocalString("JAVA_ACTION_SCRIPT") == "Medicine.StimPack")
            {
                return(105);
            }
            // Check for Force Packs
            if (item.GetLocalString("JAVA_ACTION_SCRIPT") == "Medicine.ForcePack")
            {
                return(106);
            }
            // Check for Healing Kits
            if (item.GetLocalString("JAVA_ACTION_SCRIPT") == "Medicine.HealingKit")
            {
                return(107);
            }
            // Check for Resuscitation Devices
            if (item.GetLocalString("JAVA_ACTION_SCRIPT") == "Medicine.ResuscitationKit")
            {
                return(108);
            }
            // Check for Starcharts
            if (item.GetLocalString("SCRIPT") == "StarchartDisk" &&
                item.GetLocalInt("Starcharts") > 0)
            {
                return(109);
            }
            // Check for Starship Equipment
            if (item.GetLocalString("SCRIPT") == "SSEnhancement")
            {
                return(124);
            }
            // Check for Starship Repair Kits
            if (item.GetLocalString("SCRIPT") == "SSRepairKit")
            {
                return(104);
            }

            // Check item properties
            foreach (var prop in properties)
            {
                var propertyType = _.GetItemPropertyType(prop);
                // Check for components
                if (propertyType == (int)CustomItemPropertyType.ComponentType)
                {
                    // IDs are mapped to the iprp_comptype.2da file.
                    switch (_.GetItemPropertyCostTableValue(prop))
                    {
                    case 1: return(33);

                    case 2: return(34);

                    case 3: return(35);

                    case 4: return(36);

                    case 5: return(37);

                    case 6: return(38);

                    case 7: return(39);

                    case 8: return(40);

                    case 9: return(41);

                    case 10: return(42);

                    case 11: return(43);

                    case 12: return(44);

                    case 13: return(45);

                    case 14: return(46);

                    case 15: return(47);

                    case 16: return(48);

                    case 17: return(49);

                    case 18: return(50);

                    case 19: return(51);

                    case 20: return(52);

                    case 21: return(53);

                    case 22: return(54);

                    case 23: return(55);

                    case 24: return(56);

                    case 25: return(57);

                    case 26: return(58);

                    case 27: return(59);

                    case 28: return(60);

                    case 29: return(61);

                    case 30: return(62);

                    case 31: return(63);

                    case 32: return(64);

                    case 33: return(65);

                    case 34: return(66);

                    case 35: return(67);

                    case 36: return(68);

                    case 37: return(69);

                    case 38: return(70);

                    case 39: return(71);

                    case 40: return(72);

                    case 41: return(73);

                    case 42: return(74);

                    case 43: return(75);

                    case 44: return(76);

                    case 45: return(77);

                    case 46: return(78);

                    case 47: return(79);

                    case 48: return(80);

                    case 49: return(81);

                    case 50: return(82);

                    case 51: return(83);

                    case 52: return(84);

                    case 53: return(85);

                    case 54: return(86);

                    case 55: return(87);

                    case 56: return(88);

                    case 57: return(89);

                    case 58: return(90);

                    case 59: return(91);

                    case 60: return(92);

                    case 61: return(93);

                    case 62: return(94);

                    case 63: return(95);

                    case 64: return(96);

                    case 65: return(97);
                    }
                }

                // Check for mods
                if (propertyType == (int)CustomItemPropertyType.BlueMod)
                {
                    return(98);
                }
                if (propertyType == (int)CustomItemPropertyType.GreenMod)
                {
                    return(99);
                }
                if (propertyType == (int)CustomItemPropertyType.RedMod)
                {
                    return(100);
                }
                if (propertyType == (int)CustomItemPropertyType.YellowMod)
                {
                    return(101);
                }
            }

            // Check base structures.
            int baseStructureID = item.GetLocalInt("BASE_STRUCTURE_ID");

            if (baseStructureID > 0)
            {
                var baseStructure     = DataService.Get <BaseStructure>(baseStructureID);
                var baseStructureType = (BaseStructureType)baseStructure.BaseStructureTypeID;

                switch (baseStructureType)
                {
                case BaseStructureType.ControlTower: return(111);

                case BaseStructureType.Drill: return(112);

                case BaseStructureType.ResourceSilo: return(113);

                case BaseStructureType.Turret: return(114);

                case BaseStructureType.Building: return(115);

                case BaseStructureType.MassProduction: return(116);

                case BaseStructureType.StarshipProduction: return(117);

                case BaseStructureType.Furniture: return(118);

                case BaseStructureType.StronidiumSilo: return(119);

                case BaseStructureType.FuelSilo: return(120);

                case BaseStructureType.CraftingDevice: return(121);

                case BaseStructureType.PersistentStorage: return(122);

                case BaseStructureType.Starship: return(123);
                }
            }

            // Check for individual resrefs. This should be used as a last-resort.
            switch (resref)
            {
            case "fuel_cell":
            case "stronidium":
                return(110);
            }

            // A -1 represents that this item is not supported on the market system.
            // This could be because we forgot to add a determination for it but more than likely it was
            // excluded on purpose. Lightsabers and Saberstaffs are an example of this.
            return(-1);
        }
Example #22
0
        /// <summary>
        /// Returns an ID tied to the MarketCategory table. This is where players may find
        /// the item on the marketplace.
        /// </summary>
        /// <param name="item">The item to use for the determination.</param>
        /// <returns>The market category ID or a value of -1 if item is not supported.</returns>
        public static int DetermineMarketCategory(NWItem item)
        {
            // ===============================================================================
            // The following items are intentionally excluded from market transactions:
            // Lightsaber, Saberstaff
            // ===============================================================================

            // Some of the determinations require looking at the item's properties. Pull that list back now for later use.
            var properties = item.ItemProperties.ToList();
            var resref     = item.Resref;

            // Weapons - These IDs are based solely on the NWN BaseItemType
            switch (item.BaseItemType)
            {
            case BaseItem.GreatAxe: return(1);

            case BaseItem.BattleAxe: return(2);

            case BaseItem.BastardSword: return(3);

            case BaseItem.Dagger: return(4);

            case BaseItem.GreatSword: return(5);

            case BaseItem.Longsword: return(7);

            case BaseItem.Rapier: return(8);

            case BaseItem.Katana: return(9);

            case BaseItem.ShortSword: return(10);

            case BaseItem.Club: return(11);

            case BaseItem.LightMace: return(12);

            case BaseItem.MorningStar: return(13);

            case BaseItem.QuarterStaff: return(15);

            case BaseItem.DoubleAxe: return(16);

            case BaseItem.TwoBladedSword: return(17);

            case BaseItem.Kukri: return(18);

            case BaseItem.Halberd: return(19);

            case BaseItem.ShortSpear: return(20);

            case BaseItem.LightCrossbow: return(21); // Blaster Rifles

            case BaseItem.ShortBow: return(22);      // Blaster Pistols

            case BaseItem.Helmet: return(23);

            case BaseItem.SmallShield: return(28);    // Shields

            case BaseItem.LargeShield: return(28);    // Shields

            case BaseItem.TowerShield: return(28);    // Shields

            case BaseItem.Book: return(29);

            case BaseItem.Gloves: return(30);    // Power Gloves

            case BaseItem.Amulet: return(102);   // Necklace

            case BaseItem.Ring: return(103);
            }

            // Check for armor.
            if (item.BaseItemType == BaseItem.Armor ||
                item.BaseItemType == BaseItem.Belt ||
                item.BaseItemType == BaseItem.Cloak ||
                item.BaseItemType == BaseItem.Boots ||
                item.BaseItemType == BaseItem.Bracer)
            {
                switch (item.CustomItemType)
                {
                case CustomItemType.LightArmor: return(24);

                case CustomItemType.ForceArmor: return(25);

                case CustomItemType.HeavyArmor: return(26);

                default: return(23);    // Default to clothes if no armor type is specified.
                }
            }

            // Check for Scanners
            if (item.GetLocalString("SCRIPT") == "ResourceScanner" ||
                item.GetLocalString("SCRIPT") == "MineralScanner")
            {
                return(31);
            }
            // Check for Harvesters
            if (item.GetLocalString("SCRIPT") == "ResourceHarvester")
            {
                return(32);
            }
            // Check for Repair Kits
            if (item.GetLocalString("SCRIPT") == "RepairKit")
            {
                return(104);
            }
            // Check for Stim Packs
            if (item.GetLocalString("ACTION_SCRIPT") == "Medicine.StimPack")
            {
                return(105);
            }
            // Check for Force Packs
            if (item.GetLocalString("ACTION_SCRIPT") == "Medicine.ForcePack")
            {
                return(106);
            }
            // Check for Healing Kits
            if (item.GetLocalString("ACTION_SCRIPT") == "Medicine.HealingKit")
            {
                return(107);
            }
            // Check for Resuscitation Devices
            if (item.GetLocalString("ACTION_SCRIPT") == "Medicine.ResuscitationKit")
            {
                return(108);
            }
            // Check for Starcharts
            if (item.GetLocalString("SCRIPT") == "StarchartDisk" &&
                item.GetLocalInt("Starcharts") > 0)
            {
                return(109);
            }
            // Check for Starship Equipment
            if (item.GetLocalString("SCRIPT") == "SSEnhancement")
            {
                return(124);
            }
            // Check for Starship Repair Kits
            if (item.GetLocalString("SCRIPT") == "SSRepairKit")
            {
                return(104);
            }

            // Check item properties
            foreach (var prop in properties)
            {
                var propertyType = _.GetItemPropertyType(prop);
                // Check for components
                if (propertyType == ItemPropertyType.ComponentType)
                {
                    // IDs are mapped to the iprp_comptype.2da file.
                    switch (_.GetItemPropertyCostTableValue(prop))
                    {
                    case 1: return(33);

                    case 2: return(34);

                    case 3: return(35);

                    case 4: return(36);

                    case 5: return(37);

                    case 6: return(38);

                    case 7: return(39);

                    case 8: return(40);

                    case 9: return(41);

                    case 10: return(42);

                    case 11: return(43);

                    case 12: return(44);

                    case 13: return(45);

                    case 14: return(46);

                    case 15: return(47);

                    case 16: return(48);

                    case 17: return(49);

                    case 18: return(50);

                    case 19: return(51);

                    case 20: return(52);

                    case 21: return(53);

                    case 22: return(54);

                    case 23: return(55);

                    case 24: return(56);

                    case 25: return(57);

                    case 26: return(58);

                    case 27: return(59);

                    case 28: return(60);

                    case 29: return(61);

                    case 30: return(62);

                    case 31: return(63);

                    case 32: return(64);

                    case 33: return(65);

                    case 34: return(66);

                    case 35: return(67);

                    case 36: return(68);

                    case 37: return(69);

                    case 38: return(70);

                    case 39: return(71);

                    case 40: return(72);

                    case 41: return(73);

                    case 42: return(74);

                    case 43: return(75);

                    case 44: return(76);

                    case 45: return(77);

                    case 46: return(78);

                    case 47: return(79);

                    case 48: return(80);

                    case 49: return(81);

                    case 50: return(82);

                    case 51: return(83);

                    case 52: return(84);

                    case 53: return(85);

                    case 54: return(86);

                    case 55: return(87);

                    case 56: return(88);

                    case 57: return(89);

                    case 58: return(90);

                    case 59: return(91);

                    case 60: return(92);

                    case 61: return(93);

                    case 62: return(94);

                    case 63: return(95);

                    case 64: return(96);

                    case 65: return(97);
                    }
                }

                // Check for mods
                if (propertyType == ItemPropertyType.BlueMod)
                {
                    return(98);
                }
                if (propertyType == ItemPropertyType.GreenMod)
                {
                    return(99);
                }
                if (propertyType == ItemPropertyType.RedMod)
                {
                    return(100);
                }
                if (propertyType == ItemPropertyType.YellowMod)
                {
                    return(101);
                }
            }

            // Check base structures.
            int baseStructureID = item.GetLocalInt("BASE_STRUCTURE_ID");

            if (baseStructureID > 0)
            {
                var baseStructure     = DataService.BaseStructure.GetByID(baseStructureID);
                var baseStructureType = (BaseStructureType)baseStructure.BaseStructureTypeID;

                switch (baseStructureType)
                {
                case BaseStructureType.ControlTower: return(111);

                case BaseStructureType.Drill: return(112);

                case BaseStructureType.ResourceSilo: return(113);

                case BaseStructureType.Turret: return(114);

                case BaseStructureType.Building: return(115);

                case BaseStructureType.MassProduction: return(116);

                case BaseStructureType.StarshipProduction: return(117);

                case BaseStructureType.Furniture: return(118);

                case BaseStructureType.StronidiumSilo: return(119);

                case BaseStructureType.FuelSilo: return(120);

                case BaseStructureType.CraftingDevice: return(121);

                case BaseStructureType.PersistentStorage: return(122);

                case BaseStructureType.Starship: return(123);
                }
            }

            // Check for individual resrefs. This should be used as a last-resort.
            switch (resref)
            {
            case "fuel_cell":
            case "stronidium":
                return(110);
            }

            // A -1 represents that this item is not supported on the market system.
            // This could be because we forgot to add a determination for it but more than likely it was
            // excluded on purpose. Lightsabers and Saberstaffs are an example of this.
            return(-1);
        }
Example #23
0
        private static void OnItemUsed()
        {
            NWPlayer user            = _.OBJECT_SELF;
            NWItem   oItem           = _.StringToObject(NWNXEvents.GetEventData("ITEM_OBJECT_ID"));
            NWObject target          = _.StringToObject(NWNXEvents.GetEventData("TARGET_OBJECT_ID"));
            var      targetPositionX = (float)Convert.ToDouble(NWNXEvents.GetEventData("TARGET_POSITION_X"));
            var      targetPositionY = (float)Convert.ToDouble(NWNXEvents.GetEventData("TARGET_POSITION_Y"));
            var      targetPositionZ = (float)Convert.ToDouble(NWNXEvents.GetEventData("TARGET_POSITION_Z"));
            var      targetPosition  = Vector3(targetPositionX, targetPositionY, targetPositionZ);
            Location targetLocation  = Location(user.Area, targetPosition, 0.0f);

            string className = oItem.GetLocalString("SCRIPT");

            if (string.IsNullOrWhiteSpace(className))
            {
                className = oItem.GetLocalString("ACTIVATE_SCRIPT");
            }
            if (string.IsNullOrWhiteSpace(className))
            {
                className = oItem.GetLocalString("ACTION_SCRIPT");
            }
            if (string.IsNullOrWhiteSpace(className))
            {
                className = oItem.GetLocalString("SCRIPT");
            }
            // Legacy events follow. We can't remove these because of backwards compatibility issues with existing items.
            if (string.IsNullOrWhiteSpace(className))
            {
                className = oItem.GetLocalString("JAVA_SCRIPT");
            }
            if (string.IsNullOrWhiteSpace(className))
            {
                className = oItem.GetLocalString("ACTIVATE_JAVA_SCRIPT");
            }
            if (string.IsNullOrWhiteSpace(className))
            {
                className = oItem.GetLocalString("JAVA_ACTION_SCRIPT");
            }
            if (string.IsNullOrWhiteSpace(className))
            {
                return;
            }

            // Bypass the NWN "item use" animation.
            NWNXEvents.SkipEvent();

            user.ClearAllActions();

            if (user.IsBusy)
            {
                user.SendMessage("You are busy.");
                return;
            }

            // Remove "Item." prefix if it exists.
            if (className.StartsWith("Item."))
            {
                className = className.Substring(5);
            }
            IActionItem item = GetActionItemHandler(className);

            string invalidTargetMessage = item.IsValidTarget(user, oItem, target, targetLocation);

            if (!string.IsNullOrWhiteSpace(invalidTargetMessage))
            {
                user.SendMessage(invalidTargetMessage);
                return;
            }

            // NOTE - these checks are duplicated in FinishActionItem.  Keep both in sync.
            float maxDistance = item.MaxDistance(user, oItem, target, targetLocation);

            if (maxDistance > 0.0f)
            {
                NWObject owner = GetItemPossessor(target);

                if (target.IsValid && owner.IsValid)
                {
                    // We are okay - we have targeted an item in our inventory (we can't target someone
                    // else's inventory, so no need to actually check distance).
                }
                else if (target.Object == _.OBJECT_SELF)
                {
                    // Also okay.
                }
                else if (target.IsValid &&
                         (GetDistanceBetween(user.Object, target.Object) > maxDistance ||
                          user.Area.Resref != target.Area.Resref))
                {
                    user.SendMessage("Your target is too far away.");
                    return;
                }
                else if (!target.IsValid &&
                         (GetDistanceBetweenLocations(user.Location, targetLocation) > maxDistance ||
                          user.Area.Resref != ((NWArea)GetAreaFromLocation(targetLocation)).Resref))
                {
                    user.SendMessage("That location is too far away.");
                    return;
                }
            }

            CustomData customData   = item.StartUseItem(user, oItem, target, targetLocation);
            float      delay        = item.Seconds(user, oItem, target, targetLocation, customData);
            var        animationID  = item.AnimationID();
            bool       faceTarget   = item.FaceTarget();
            Vector3    userPosition = user.Position;

            user.AssignCommand(() =>
            {
                user.IsBusy = true;
                if (faceTarget)
                {
                    SetFacingPoint(!target.IsValid ? GetPositionFromLocation(targetLocation) : target.Position);
                }
                if (animationID > 0)
                {
                    ActionPlayAnimation(animationID, 1.0f, delay);
                }
            });

            if (delay > 0.0f)
            {
                NWNXPlayer.StartGuiTimingBar(user, delay, string.Empty);
            }

            var @event = new OnFinishActionItem(className, user, oItem, target, targetLocation, userPosition, customData);

            user.DelayEvent(delay, @event);
        }
Example #24
0
        public void Main()
        {
            NWPlaceable container = NWGameObject.OBJECT_SELF;
            NWObject    owner     = container.GetLocalObject("QUEST_OWNER");

            NWPlayer player            = _.GetLastDisturbed();
            NWItem   item              = _.GetInventoryDisturbItem();
            int      disturbType       = _.GetInventoryDisturbType();
            string   crafterPlayerID   = item.GetLocalString("CRAFTER_PLAYER_ID");
            Guid?    crafterPlayerGUID = null;

            if (!string.IsNullOrWhiteSpace(crafterPlayerID))
            {
                crafterPlayerGUID = new Guid(crafterPlayerID);
            }

            if (disturbType == _.INVENTORY_DISTURB_TYPE_ADDED)
            {
                int                 questID  = container.GetLocalInt("QUEST_ID");
                PCQuestStatus       status   = DataService.PCQuestStatus.GetByPlayerAndQuestID(player.GlobalID, questID);
                PCQuestItemProgress progress = DataService.PCQuestItemProgress.GetByPCQuestStatusIDAndResrefOrDefault(status.ID, item.Resref);
                DatabaseActionType  action   = DatabaseActionType.Update;

                if (progress == null)
                {
                    _.CopyItem(item, player, _.TRUE);
                    player.SendMessage(ColorTokenService.Red("That item is not required for this quest."));
                }
                else if (progress.MustBeCraftedByPlayer && crafterPlayerGUID != player.GlobalID)
                {
                    _.CopyItem(item, player, _.TRUE);
                    player.SendMessage(ColorTokenService.Red("You may only submit items which you have personally created for this quest."));
                }
                else
                {
                    progress.Remaining--;

                    if (progress.Remaining <= 0)
                    {
                        var progressCopy = progress;
                        progress = DataService.PCQuestItemProgress.GetByID(progressCopy.ID);
                        action   = DatabaseActionType.Delete;
                    }
                    DataService.SubmitDataChange(progress, action);

                    // Recalc the remaining items needed.
                    int remainingCount = DataService.PCQuestItemProgress.GetCountByPCQuestStatusID(status.ID);
                    if (remainingCount <= 0)
                    {
                        QuestService.AdvanceQuestState(player, owner, questID);
                    }

                    player.SendMessage("You need " + progress.Remaining + "x " + item.Name + " for this quest.");
                }
                item.Destroy();

                var questItemProgresses = DataService.PCQuestItemProgress.GetAllByPCQuestStatusID(status.ID);
                if (!questItemProgresses.Any())
                {
                    string conversation = _.GetLocalString(owner, "CONVERSATION");

                    // Either start a SWLOR conversation
                    if (!string.IsNullOrWhiteSpace(conversation))
                    {
                        DialogService.StartConversation(player, owner, conversation);
                    }
                    // Or a regular NWN conversation.
                    else
                    {
                        player.AssignCommand(() => { _.ActionStartConversation(owner, "", _.TRUE, _.FALSE); });
                    }
                }
            }
        }
Example #25
0
        public void ApplyEffects(NWCreature user, NWItem item, NWObject target, Location targetLocation, CustomData customData)
        {
            DateTime now            = DateTime.UtcNow;
            DateTime unlockDateTime = now;

            if (string.IsNullOrWhiteSpace(GetLocalString(user, "GRENADE_UNLOCKTIME")))
            {
                unlockDateTime = unlockDateTime.AddSeconds(-1);
            }
            else
            {
                unlockDateTime = DateTime.ParseExact(GetLocalString(user, "GRENADE_UNLOCKTIME"), "yyyy-MM-dd hh:mm:ss", CultureInfo.InvariantCulture);
            }
            //Console.WriteLine("IsValidTarget - Current Time = " + now.ToString("yyyy-MM-dd hh:mm:ss", CultureInfo.InvariantCulture));
            //Console.WriteLine("IsValidTarget - Unlocktime = " + unlockDateTime.ToString("yyyy-MM-dd hh:mm:ss", CultureInfo.InvariantCulture));
            //Console.WriteLine("IsValidTarget - DateTime.Compare = " + DateTime.Compare(unlockDateTime, now));

            // Check if we've passed the unlock date. Exit early if we have not.
            if (DateTime.Compare(unlockDateTime, now) > 0 || unlockDateTime > now)
            {
                string timeToWait = TimeService.GetTimeToWaitLongIntervals(now, unlockDateTime, false);
                //Console.WriteLine("IsValidTarget - That ability can be used in " + timeToWait + ".");
                SendMessageToPC(user, "That ability can be used in " + timeToWait + ".");
                return;
            }

            Effect impactEffect = null;
            var    spellId      = Spell.Invalid;
            string soundName    = null;
            int    perkLevel    = 1 + PerkService.GetCreaturePerkLevel(user, PerkType.GrenadeProficiency);
            int    skillLevel   = 5 + SkillService.GetPCSkillRank((NWPlayer)user, SkillType.Throwing);

            if (perkLevel == 0)
            {
                perkLevel += 1;
            }

            if (GetIsObjectValid(target) == true)
            {
                targetLocation = GetLocation(target);
            }
            string grenadeType = item.GetLocalString("TYPE");
            //Console.WriteLine("Throwing " + grenadeType + " grenade at perk level " + perkLevel);
            Location originalLocation = targetLocation;

            int roll = RandomService.D100(1);

            SendMessageToPC(user, roll + " vs. DC " + (100 - skillLevel));
            if (roll < (100 - skillLevel))
            {
                if (RandomService.D20(1) == 1)
                {
                    SendMessageToPC(user, "You threw... poorly.");
                    //targetLocation = VectorService.MoveLocation(targetLocation, GetFacing(user), (RandomService.D6(4) - 10) * 1.0f,
                    targetLocation = VectorService.MoveLocation(user.Location, RandomService.D100(1) + RandomService.D100(1) + RandomService.D100(1) + 60, RandomService.D4(2) * 1.0f,
                                                                RandomService.D100(1) + RandomService.D100(1) + RandomService.D100(1));
                    int count = 0;
                    while ((GetSurfaceMaterial(targetLocation) == 0 ||
                            LineOfSightVector(GetPositionFromLocation(targetLocation), GetPosition(user)) == false) &&
                           count < 10)
                    {
                        count         += 1;
                        targetLocation = VectorService.MoveLocation(user.Location, RandomService.D100(1) + RandomService.D100(1) + RandomService.D100(1) + 60, RandomService.D4(2) * 1.0f,
                                                                    RandomService.D100(1) + RandomService.D100(1) + RandomService.D100(1));
                    }
                }
                else
                {
                    SendMessageToPC(user, "Your throw was a bit off the mark.");
                    //targetLocation = VectorService.MoveLocation(targetLocation, GetFacing(user), (RandomService.D6(4) - 10) * 1.0f,
                    targetLocation = VectorService.MoveLocation(targetLocation, RandomService.D100(1) + RandomService.D100(1) + RandomService.D100(1) + 60, RandomService.D4(2) /*(RandomService.D6(4) - 10) */ * 1.0f,
                                                                RandomService.D100(1) + RandomService.D100(1) + RandomService.D100(1));
                    int count = 0;
                    while ((GetSurfaceMaterial(targetLocation) == 0 ||
                            LineOfSightVector(GetPositionFromLocation(targetLocation), GetPosition(user)) == false) &&
                           count < 10)
                    {
                        count         += 1;
                        targetLocation = VectorService.MoveLocation(targetLocation, RandomService.D100(1) + RandomService.D100(1) + RandomService.D100(1) + 60, RandomService.D4(2) /*(RandomService.D6(4) - 10) */ * 1.0f,
                                                                    RandomService.D100(1) + RandomService.D100(1) + RandomService.D100(1));
                    }
                }

                if (GetSurfaceMaterial(targetLocation) == 0 ||
                    LineOfSightVector(GetPositionFromLocation(targetLocation), GetPosition(user)) == false)
                {
                    targetLocation = originalLocation;
                }
            }

            switch (grenadeType)
            {
            case "FRAG":
                impactEffect = EffectVisualEffect(VisualEffect.Fnf_Fireball);
                // force a specific spell id (for projectile model) for this grenade.
                spellId   = Spell.Grenade10;
                soundName = "explosion2";
                break;

            case "CONCUSSION":
                impactEffect = EffectVisualEffect(VisualEffect.Vfx_Fnf_Sound_Burst_Silent);
                impactEffect = EffectLinkEffects(EffectVisualEffect(VisualEffect.Vfx_Fnf_Screen_Shake), impactEffect);
                spellId      = Spell.Grenade10;
                soundName    = "explosion1";
                break;

            case "FLASHBANG":
                impactEffect = EffectVisualEffect(VisualEffect.Vfx_Fnf_Mystical_Explosion);
                spellId      = Spell.Grenade10;
                soundName    = "explosion1";
                break;

            case "ION":
                impactEffect = EffectVisualEffect(VisualEffect.Vfx_Fnf_Electric_Explosion);
                spellId      = Spell.Grenade10;
                soundName    = "explosion1";
                break;

            case "BACTA":
                impactEffect = EffectVisualEffect(VisualEffect.Vfx_Fnf_Gas_Explosion_Nature);
                spellId      = Spell.Grenade10;
                //soundName = "explosion1";
                break;

            case "ADHESIVE":
                impactEffect = EffectVisualEffect(VisualEffect.Fnf_Dispel_Greater);
                spellId      = Spell.Grenade10;
                //soundName = "explosion1";
                break;

            case "SMOKE":
                impactEffect = null;
                spellId      = Spell.Grenade10;
                //soundName = "explosion1";
                break;

            case "BACTABOMB":
                impactEffect = null;
                spellId      = Spell.Grenade10;
                //soundName = "explosion1";
                break;

            case "INCENDIARY":
                impactEffect = null;
                spellId      = Spell.Grenade10;
                //soundName = "explosion1";
                break;

            case "GAS":
                impactEffect = null;
                spellId      = Spell.Grenade10;
                //soundName = "explosion1";
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(grenadeType));
            }

            if (spellId == 0)
            {
                // start 974 through 979 in spells.2da for grenades
                // lets randomly assign a projectile appearance for flavor?
                spellId = (Spell)(RandomService.D6(1) + 973);
            }

            float delay = GetDistanceBetweenLocations(user.Location, targetLocation) / 18.0f + 0.75f;

            delay += 0.4f; // added for animation
            user.ClearAllActions();
            //user.AssignCommand(() => _.ActionPlayAnimation(32));
            //user.DelayAssignCommand(() => _.ActionPlayAnimation(32), 0.0f);
            user.AssignCommand(() =>
            {
                ActionPlayAnimation(Animation.LoopingCustom12);
                ActionCastSpellAtLocation(spellId, targetLocation, MetaMagic.Any, true, ProjectilePathType.Ballistic, true);
                //ActionCastFakeSpellAtLocation(spellId, targetLocation, PROJECTILE_PATH_TYPE_BALLISTIC);
            });

            if (soundName != null)
            {
                user.DelayAssignCommand(() =>
                {
                    PlaySound(soundName);
                }, delay);
            }

            if (impactEffect != null)
            {
                user.DelayAssignCommand(() =>
                {
                    ApplyEffectAtLocation(DurationType.Instant, impactEffect, targetLocation);
                }, delay);
            }

            user.DelayAssignCommand(
                () =>
            {
                DoImpact(user, item, targetLocation, grenadeType, perkLevel, RadiusSize.Large, ObjectType.Creature);
            }, delay + 0.75f);


            perkLevel = PerkService.GetCreaturePerkLevel(user, PerkType.GrenadeProficiency);

            now = DateTime.UtcNow;
            DateTime unlockTime = now;

            if (perkLevel < 5)
            {
                unlockTime = unlockTime.AddSeconds(6);
            }
            else if (perkLevel < 10)
            {
                unlockTime = unlockTime.AddSeconds(3);
            }
            else
            {
                unlockTime = unlockTime.AddSeconds(2);
            }

            SetLocalString(user, "GRENADE_UNLOCKTIME", unlockTime.ToString("yyyy-MM-dd hh:mm:ss", CultureInfo.InvariantCulture));
            //Console.WriteLine("StartUseItem - Current Time = " + now.ToString("yyyy-MM-dd hh:mm:ss", CultureInfo.InvariantCulture));
            //Console.WriteLine("StartUseItem - Unlocktime Set To = " + unlockTime.ToString("yyyy-MM-dd hh:mm:ss", CultureInfo.InvariantCulture));
            if (user.IsCreature)
            {
                DurabilityService.RunItemDecay((NWPlayer)user, item, 1.0f);
            }
        }
Example #26
0
        public string IsValidTarget(NWCreature user, NWItem rune, NWObject target, Location targetLocation)
        {
            if (target.ObjectType != OBJECT_TYPE_ITEM)
            {
                return("Only items may be targeted by Runes.");
            }
            if (!user.IsPlayer)
            {
                return("Only players may use runes.");
            }
            NWPlayer player     = NWPlayer.Wrap(user.Object);
            NWItem   targetItem = NWItem.Wrap(target.Object);

            int runeLevel         = rune.RecommendedLevel;
            int itemLevel         = targetItem.RecommendedLevel;
            int requiredPerkLevel = runeLevel / 5;

            if (requiredPerkLevel <= 0)
            {
                requiredPerkLevel = 1;
            }
            int perkLevel = 0;
            CustomItemPropertyType runeType = _rune.GetRuneType(rune);
            RuneSlots runeSlots             = _rune.GetRuneSlots(targetItem);
            int       runeID = rune.GetLocalInt("RUNE_ID");

            string[] runeArgs = rune.GetLocalString("RUNE_VALUE").Split(',');

            // Check for a misconfigured rune item.
            if (runeType == CustomItemPropertyType.Unknown)
            {
                return("Rune color couldn't be found. Notify an admin that this rune item is not set up properly.");
            }
            if (runeID <= 0)
            {
                return("Rune ID couldn't be found. Notify an admin that this rune item is not set up properly.");
            }
            if (runeArgs.Length <= 0)
            {
                return("Rune value couldn't be found. Notify an admin that this rune item is not set up properly.");
            }

            // No available slots on target item
            if (runeType == CustomItemPropertyType.RedRune && !runeSlots.CanRedRuneBeAdded)
            {
                return("That item has no available red runic slots.");
            }
            if (runeType == CustomItemPropertyType.BlueRune && !runeSlots.CanBlueRuneBeAdded)
            {
                return("That item has no available blue runic slots.");
            }
            if (runeType == CustomItemPropertyType.GreenRune && !runeSlots.CanGreenRuneBeAdded)
            {
                return("That item has no available green runic slots.");
            }
            if (runeType == CustomItemPropertyType.YellowRune && !runeSlots.CanYellowRuneBeAdded)
            {
                return("That item has no available yellow runic slots.");
            }

            // Get the perk level based on target item type and rune type.
            if (_item.WeaponBaseItemTypes.Contains(targetItem.BaseItemType))
            {
                switch (runeType)
                {
                case CustomItemPropertyType.RedRune:
                    perkLevel = _perk.GetPCPerkLevel(player, PerkType.CombatRuneInstallationWeapons);
                    break;

                case CustomItemPropertyType.BlueRune:
                    perkLevel = _perk.GetPCPerkLevel(player, PerkType.MagicRuneInstallationWeapons);
                    break;

                case CustomItemPropertyType.GreenRune:
                    perkLevel = _perk.GetPCPerkLevel(player, PerkType.CraftingRuneInstallationWeapons);
                    break;

                case CustomItemPropertyType.YellowRune:
                    perkLevel = _perk.GetPCPerkLevel(player, PerkType.SpecialRuneInstallationWeapons);
                    break;

                default:
                    perkLevel = 0;
                    break;
                }
            }
            else if (_item.ArmorBaseItemTypes.Contains(targetItem.BaseItemType))
            {
                switch (runeType)
                {
                case CustomItemPropertyType.RedRune:
                    perkLevel = _perk.GetPCPerkLevel(player, PerkType.CombatRuneInstallationArmors);
                    break;

                case CustomItemPropertyType.BlueRune:
                    perkLevel = _perk.GetPCPerkLevel(player, PerkType.MagicRuneInstallationArmors);
                    break;

                case CustomItemPropertyType.GreenRune:
                    perkLevel = _perk.GetPCPerkLevel(player, PerkType.CraftingRuneInstallationArmors);
                    break;

                case CustomItemPropertyType.YellowRune:
                    perkLevel = _perk.GetPCPerkLevel(player, PerkType.SpecialRuneInstallationArmors);
                    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 rune.");
                }
            }

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

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

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

            // Look for a database entry for this rune type.
            var dbRune = _db.Runes.SingleOrDefault(x => x.RuneID == runeID && x.IsActive);

            if (dbRune == null)
            {
                return("Couldn't find a matching rune ID in the database. Inform an admin of this issue.");
            }

            // Run the individual rune's rules for application. Will return the error message or a null.
            IRune runeRules = App.ResolveByInterface <IRune>("Rune." + dbRune.Script);

            return(runeRules.CanApply(player, targetItem, runeArgs));
        }
Example #27
0
        public void ApplyEffects(NWCreature user, NWItem runeItem, NWObject target, Location targetLocation, CustomData customData)
        {
            NWPlayer  player                = NWPlayer.Wrap(user.Object);
            NWItem    targetItem            = NWItem.Wrap(target.Object);
            RuneSlots slots                 = _rune.GetRuneSlots(targetItem);
            CustomItemPropertyType runeType = _rune.GetRuneType(runeItem);
            int runeID = runeItem.GetLocalInt("RUNE_ID");

            string[] runeArgs      = runeItem.GetLocalString("RUNE_VALUE").Split(',');
            int      runeLevel     = runeItem.RecommendedLevel;
            int      levelIncrease = runeItem.LevelIncrease;

            var   dbRune = _db.Runes.Single(x => x.RuneID == runeID && x.IsActive);
            IRune rune   = App.ResolveByInterface <IRune>("Rune." + dbRune.Script);

            rune.Apply(player, targetItem, runeArgs);

            string description  = rune.Description(player, targetItem, runeArgs);
            bool   usePrismatic = false;

            switch (runeType)
            {
            case CustomItemPropertyType.RedRune:
                if (slots.FilledRedSlots < slots.RedSlots)
                {
                    targetItem.SetLocalInt("RUNIC_SLOT_RED_" + (slots.FilledRedSlots + 1), runeID);
                    targetItem.SetLocalString("RUNIC_SLOT_RED_DESC_" + (slots.FilledRedSlots + 1), description);
                    player.SendMessage("Rune installed into " + _color.Red("red") + " slot #" + (slots.FilledRedSlots + 1));
                }
                else
                {
                    usePrismatic = true;
                }
                break;

            case CustomItemPropertyType.BlueRune:
                if (slots.FilledBlueSlots < slots.BlueSlots)
                {
                    targetItem.SetLocalInt("RUNIC_SLOT_BLUE_" + (slots.FilledBlueSlots + 1), runeID);
                    targetItem.SetLocalString("RUNIC_SLOT_BLUE_DESC_" + (slots.FilledBlueSlots + 1), description);
                    player.SendMessage("Rune installed into " + _color.Blue("blue") + " slot #" + (slots.FilledBlueSlots + 1));
                }
                else
                {
                    usePrismatic = true;
                }
                break;

            case CustomItemPropertyType.GreenRune:
                if (slots.FilledBlueSlots < slots.GreenSlots)
                {
                    targetItem.SetLocalInt("RUNIC_SLOT_GREEN_" + (slots.FilledGreenSlots + 1), runeID);
                    targetItem.SetLocalString("RUNIC_SLOT_GREEN_DESC_" + (slots.FilledGreenSlots + 1), description);
                    player.SendMessage("Rune installed into " + _color.Green("green") + " slot #" + (slots.FilledGreenSlots + 1));
                }
                else
                {
                    usePrismatic = true;
                }
                break;

            case CustomItemPropertyType.YellowRune:
                if (slots.FilledBlueSlots < slots.YellowSlots)
                {
                    targetItem.SetLocalInt("RUNIC_SLOT_YELLOW_" + (slots.FilledYellowSlots + 1), runeID);
                    targetItem.SetLocalString("RUNIC_SLOT_YELLOW_DESC_" + (slots.FilledYellowSlots + 1), description);
                    player.SendMessage("Rune installed into " + _color.Yellow("yellow") + " slot #" + (slots.FilledYellowSlots + 1));
                }
                else
                {
                    usePrismatic = true;
                }
                break;
            }

            if (usePrismatic)
            {
                string prismaticText = _rune.PrismaticString();
                targetItem.SetLocalInt("RUNIC_SLOT_PRISMATIC_" + (slots.FilledPrismaticSlots + 1), runeID);
                targetItem.SetLocalString("RUNIC_SLOT_PRISMATIC_DESC_" + (slots.FilledPrismaticSlots + 1), description);
                player.SendMessage("Rune installed into " + prismaticText + " slot #" + (slots.FilledPrismaticSlots + 1));
            }

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

            SkillType skillType;

            if (_item.ArmorBaseItemTypes.Contains(targetItem.BaseItemType))
            {
                skillType = SkillType.Armorsmith;
            }
            else if (_item.WeaponBaseItemTypes.Contains(targetItem.BaseItemType))
            {
                skillType = SkillType.Weaponsmith;
            }
            else
            {
                return;
            }

            PCSkill pcSkill = _skill.GetPCSkill(player, skillType);
            int     xp      = (int)_skill.CalculateRegisteredSkillLevelAdjustedXP(400, runeLevel, pcSkill.Rank);

            _skill.GiveSkillXP(player, skillType, xp);
        }
Example #28
0
        public void OnModuleActivatedItem()
        {
            NWPlayer oPC            = NWPlayer.Wrap(_.GetItemActivator());
            NWItem   oItem          = NWItem.Wrap(_.GetItemActivated());
            NWObject oTarget        = NWObject.Wrap(_.GetItemActivatedTarget());
            Location targetLocation = _.GetItemActivatedTargetLocation();

            string className = oItem.GetLocalString("JAVA_SCRIPT");

            if (className == string.Empty)
            {
                className = oItem.GetLocalString("ACTIVATE_JAVA_SCRIPT");
            }
            if (className == string.Empty)
            {
                className = oItem.GetLocalString("JAVA_ACTION_SCRIPT");
            }
            if (className == string.Empty)
            {
                className = oItem.GetLocalString("SCRIPT");
            }
            if (className == string.Empty)
            {
                return;
            }

            oPC.ClearAllActions();

            // Remove "Item." prefix if it exists.
            if (className.StartsWith("Item."))
            {
                className = className.Substring(5);
            }

            IActionItem item = App.ResolveByInterface <IActionItem>("Item." + className);

            if (oPC.IsBusy)
            {
                oPC.SendMessage("You are busy.");
                return;
            }

            string invalidTargetMessage = item.IsValidTarget(oPC, oItem, oTarget, targetLocation);

            if (!string.IsNullOrWhiteSpace(invalidTargetMessage))
            {
                oPC.SendMessage(invalidTargetMessage);
                return;
            }

            if (item.MaxDistance() > 0.0f)
            {
                if (_.GetDistanceBetween(oPC.Object, oTarget.Object) > item.MaxDistance() ||
                    oPC.Area.Resref != oTarget.Area.Resref)
                {
                    oPC.SendMessage("Your target is too far away.");
                    return;
                }
            }

            CustomData customData   = item.StartUseItem(oPC, oItem, oTarget, targetLocation);
            float      delay        = item.Seconds(oPC, oItem, oTarget, targetLocation, customData);
            int        animationID  = item.AnimationID();
            bool       faceTarget   = item.FaceTarget();
            Vector     userPosition = oPC.Position;

            oPC.AssignCommand(() =>
            {
                oPC.IsBusy = true;
                if (faceTarget)
                {
                    _.SetFacingPoint(oTarget.Position);
                }
                if (animationID > 0)
                {
                    _.ActionPlayAnimation(animationID, 1.0f, delay);
                }
            });

            _nwnxPlayer.StartGuiTimingBar(oPC, delay, string.Empty);
            oPC.DelayCommand(() =>
            {
                FinishActionItem(item, oPC, oItem, oTarget, targetLocation, userPosition, customData);
            }, delay);
        }