Esempio n. 1
0
        private void RunCreateItem(NWPlayer oPC, NWPlaceable device)
        {
            var model = GetPlayerCraftingData(oPC);

            CraftBlueprint blueprint = _db.CraftBlueprints.Single(x => x.CraftBlueprintID == model.BlueprintID);
            PCSkill        pcSkill   = _db.PCSkills.Single(x => x.PlayerID == oPC.GlobalID && x.SkillID == blueprint.SkillID);

            int   pcEffectiveLevel = CalculatePCEffectiveLevel(oPC, device, pcSkill.Rank);
            float chance           = CalculateBaseChanceToAddProperty(pcEffectiveLevel, model.AdjustedLevel);
            float equipmentBonus   = CalculateEquipmentBonus(oPC, (SkillType)blueprint.SkillID);

            var    craftedItems = new List <NWItem>();
            NWItem craftedItem  = NWItem.Wrap(_.CreateItemOnObject(blueprint.ItemResref, oPC.Object, blueprint.Quantity));

            craftedItem.IsIdentified = true;
            craftedItems.Add(craftedItem);

            // If item isn't stackable, loop through and create as many as necessary.
            if (craftedItem.StackSize < blueprint.Quantity)
            {
                for (int x = 2; x <= blueprint.Quantity; x++)
                {
                    craftedItem = NWItem.Wrap(_.CreateItemOnObject(blueprint.ItemResref, oPC.Object));
                    craftedItem.IsIdentified = true;
                    craftedItems.Add(craftedItem);
                }
            }

            foreach (var component in model.MainComponents)
            {
                ComponentBonusType bonus = ComponentBonusType.Unknown;
                foreach (var ip in component.ItemProperties)
                {
                    if (_.GetItemPropertyType(ip) == (int)CustomItemPropertyType.ComponentBonus)
                    {
                        bonus = (ComponentBonusType)_.GetItemPropertyCostTableValue(ip);
                    }
                }

                if (bonus == ComponentBonusType.Unknown)
                {
                    continue;
                }

                if (_random.RandomFloat() * 100.0f + equipmentBonus <= chance)
                {
                    foreach (var item in craftedItems)
                    {
                        ApplyComponentBonus(item, bonus);
                    }
                }
            }

            oPC.SendMessage("You created " + blueprint.Quantity + "x " + blueprint.ItemName + "!");
            float xp = _skill.CalculateRegisteredSkillLevelAdjustedXP(250, model.AdjustedLevel, pcSkill.Rank);

            _skill.GiveSkillXP(oPC, blueprint.SkillID, (int)xp);
            ClearPlayerCraftingData(oPC);
        }
Esempio n. 2
0
        public bool Run(params object[] args)
        {
            NWPlayer            player         = (NWPlayer)args[0];
            string              oreResref      = (string)args[1];
            List <ItemProperty> itemProperties = (List <ItemProperty>)args[2];

            player.IsBusy = false;

            int    rank        = _skill.GetPCSkillRank(player, SkillType.Engineering);
            int    level       = _craft.GetIngotLevel(oreResref);
            string ingotResref = _craft.GetIngotResref(oreResref);

            if (level < 0 || string.IsNullOrWhiteSpace(ingotResref))
            {
                return(false);
            }

            int delta = rank - level;
            int count = 2;

            if (delta > 2)
            {
                count = delta;
            }
            if (count > 4)
            {
                count = 4;
            }

            if (_random.Random(100) + 1 <= _perk.GetPCPerkLevel(player, PerkType.Lucky))
            {
                count++;
            }

            if (_random.Random(100) + 1 <= _perk.GetPCPerkLevel(player, PerkType.ProcessingEfficiency) * 10)
            {
                count++;
            }

            for (int x = 1; x <= count; x++)
            {
                var item = (_.CreateItemOnObject(ingotResref, player.Object));
                foreach (var ip in itemProperties)
                {
                    _biowareXP2.IPSafeAddItemProperty(item, ip, 0.0f, AddItemPropertyPolicy.IgnoreExisting, true, true);
                }
            }

            var effectiveStats   = _playerStat.GetPlayerItemEffectiveStats(player);
            int stronidiumAmount = 2 + effectiveStats.Harvesting;

            _.CreateItemOnObject("stronidium", player.Object, stronidiumAmount);

            int xp = (int)_skill.CalculateRegisteredSkillLevelAdjustedXP(100, level, rank);

            _skill.GiveSkillXP(player, SkillType.Engineering, xp);
            return(true);
        }
Esempio n. 3
0
        public ItemVO GetTempItemInformation(string resref, int quantity)
        {
            NWPlaceable tempStorage = (_.GetObjectByTag(TempStoragePlaceableTag));
            NWItem      tempItem    = (_.CreateItemOnObject(resref, tempStorage.Object));
            ItemVO      model       = new ItemVO
            {
                Name        = tempItem.Name,
                Quantity    = quantity,
                Resref      = resref,
                Tag         = tempItem.Tag,
                Description = tempItem.IdentifiedDescription
            };

            return(model);
        }
Esempio n. 4
0
        public string GetNameByResref(string resref)
        {
            NWPlaceable tempStorage = (_.GetObjectByTag("TEMP_ITEM_STORAGE"));

            if (!tempStorage.IsValid)
            {
                Console.WriteLine("Could not locate temp item storage object. Create a placeable container in a non-accessible area with the tag TEMP_ITEM_STORAGE.");
                return(null);
            }
            NWItem item = (_.CreateItemOnObject(resref, tempStorage.Object));
            string name = item.Name;

            item.Destroy();
            return(name);
        }
Esempio n. 5
0
        public void DoAction(NWPlayer user, params string[] args)
        {
            if (args.Length <= 0)
            {
                user.SendMessage(_color.Red("Please specify a resref and optionally a quantity. Example: /" + nameof(SpawnItem) + " my_resref 20"));
                return;
            }
            string resref   = args[0];
            int    quantity = 1;

            if (args.Length > 1)
            {
                if (!int.TryParse(args[1], out quantity))
                {
                    return;
                }
            }

            var item = NWItem.Wrap(_.CreateItemOnObject(resref, user.Object, quantity));

            if (!item.IsValid)
            {
                user.SendMessage(_color.Red("Item not found! Did you enter the correct ResRef?"));
                return;
            }

            item.IsIdentified = true;
        }
Esempio n. 6
0
        private void ProcessItem(NWPlayer oPC, NWItem item, Dictionary <string, PCMigrationItem> itemMap, List <int> stripItemList)
        {
            string          resref         = item.Resref;
            int             quantity       = item.StackSize;
            int             baseItemTypeID = item.BaseItemType;
            PCMigrationItem migrationItem  = itemMap[resref];

            if (itemMap.ContainsKey(resref))
            {
                item.Destroy();
                if (!string.IsNullOrWhiteSpace(migrationItem.NewResref))
                {
                    NWItem newItem = NWItem.Wrap(_.CreateItemOnObject(migrationItem.NewResref, oPC.Object, quantity));
                    if (!newItem.Possessor.IsValid)
                    {
                        PCOverflowItem overflow = new PCOverflowItem
                        {
                            ItemResref = newItem.Resref,
                            ItemTag    = newItem.Tag,
                            ItemName   = newItem.Name,
                            ItemObject = _serialization.Serialize(newItem),
                            PlayerID   = oPC.GlobalID
                        };
                        _db.PCOverflowItems.Add(overflow);
                        _db.SaveChanges();

                        newItem.Destroy();
                    }
                }
            }
            else if (stripItemList.Contains(baseItemTypeID))
            {
                _item.StripAllItemProperties(item);
            }
        }
Esempio n. 7
0
        public bool Run(params object[] args)
        {
            NWPlayer    player = NWPlayer.Wrap(Object.OBJECT_SELF);
            NWPlaceable forge  = NWPlaceable.Wrap(player.GetLocalObject("FORGE"));
            string      resref = forge.GetLocalString("FORGE_ORE");

            forge.DeleteLocalObject("FORGE_USER");
            player.DeleteLocalObject("FORGE");
            forge.DeleteLocalString("FORGE_ORE");
            player.IsBusy = false;

            PCSkill pcSkill     = _skill.GetPCSkill(player, SkillType.Engineering);
            int     level       = _craft.GetIngotLevel(resref);
            string  ingotResref = _craft.GetIngotResref(resref);

            if (pcSkill == null || level < 0 || string.IsNullOrWhiteSpace(ingotResref))
            {
                return(false);
            }

            int delta = pcSkill.Rank - level;
            int count = 2;

            if (delta > 2)
            {
                count = delta;
            }
            if (count > 6)
            {
                count = 6;
            }

            if (_random.Random(100) + 1 <= _perk.GetPCPerkLevel(player, PerkType.Lucky))
            {
                count++;
            }

            if (_random.Random(100) + 1 <= _perk.GetPCPerkLevel(player, PerkType.ProcessingEfficiency) * 10)
            {
                count++;
            }

            for (int x = 1; x <= count; x++)
            {
                _.CreateItemOnObject(ingotResref, player.Object);
            }

            int xp = (int)_skill.CalculateRegisteredSkillLevelAdjustedXP(100, level, pcSkill.Rank);

            _skill.GiveSkillXP(player, SkillType.Engineering, xp);

            if (_random.Random(100) + 1 <= 3)
            {
                _food.DecreaseHungerLevel(player, 1);
            }
            return(true);
        }
Esempio n. 8
0
        public bool Run(params object[] args)
        {
            NWPlaceable device            = NWPlaceable.Wrap(Object.OBJECT_SELF);
            NWPlayer    oPC               = NWPlayer.Wrap(_.GetLastOpenedBy());
            int         blueprintSelected = device.GetLocalInt("CRAFT_BLUEPRINT_ID");

            _.CreateItemOnObject("cft_choose_bp", device.Object);
            if (blueprintSelected > 0)
            {
                CraftBlueprint entity = _craft.GetBlueprintByID(blueprintSelected);

                NWItem menuItem = NWItem.Wrap(_.CreateItemOnObject("cft_craft_item", device.Object));
                menuItem.Name = "Craft Item: " + entity.ItemName;

                oPC.SendMessage(_craft.BuildBlueprintHeader(oPC, blueprintSelected));
            }

            return(true);
        }
Esempio n. 9
0
        public bool Run(params object[] args)
        {
            NWPlaceable device = NWPlaceable.Wrap(Object.OBJECT_SELF);
            NWPlayer    oPC    = NWPlayer.Wrap(_.GetLastOpenedBy());
            var         model  = _craft.GetPlayerCraftingData(oPC);

            if (model.Access != CraftingAccessType.None)
            {
                NWItem        menuItem     = NWItem.Wrap(_.CreateItemOnObject("cft_confirm", device.Object));
                NWPlaceable   storage      = NWPlaceable.Wrap(_.GetObjectByTag("craft_temp_store"));
                var           storageItems = storage.InventoryItems;
                List <NWItem> list         = null;

                if (model.Access == CraftingAccessType.MainComponent)
                {
                    menuItem.Name = "Confirm Main Components";
                    list          = model.MainComponents;
                }
                else if (model.Access == CraftingAccessType.SecondaryComponent)
                {
                    menuItem.Name = "Confirm Secondary Components";
                    list          = model.SecondaryComponents;
                }
                else if (model.Access == CraftingAccessType.TertiaryComponent)
                {
                    menuItem.Name = "Confirm Tertiary Components";
                    list          = model.TertiaryComponents;
                }
                else if (model.Access == CraftingAccessType.Enhancement)
                {
                    menuItem.Name = "Confirm Enhancement Components";
                    list          = model.EnhancementComponents;
                }

                if (list == null)
                {
                    oPC.FloatingText("Error locating component list. Notify an admin.");
                    return(false);
                }

                foreach (var item in list)
                {
                    NWItem storageItem = storageItems.Single(x => x.GlobalID == item.GlobalID);
                    _.CopyItem(storageItem.Object, device.Object, TRUE);
                }

                oPC.FloatingText("Place the components inside the container and then click the item named '" + menuItem.Name + "' to continue.");
            }

            device.IsLocked = true;
            return(true);
        }
Esempio n. 10
0
        public void OnModuleClientEnter()
        {
            NWPlayer oPC = NWPlayer.Wrap(_.GetEnteringObject());

            if (!oPC.IsPlayer || oPC.IsDM)
            {
                return;
            }

            NWObject        token  = NWObject.Wrap(_.GetItemPossessedBy(oPC.Object, "bkg_token"));
            PlayerCharacter entity = _db.PlayerCharacters.Single(x => x.PlayerID == oPC.GlobalID);

            if (entity.BackgroundID > 0)
            {
                return;
            }

            if (!token.IsValid)
            {
                _.CreateItemOnObject("bkg_token", oPC.Object);
            }
        }
Esempio n. 11
0
        private void ForceEquipFistGlove(NWPlayer oPC)
        {
            _.DelayCommand(1.0f, () =>
            {
                if (!oPC.Arms.IsValid)
                {
                    oPC.ClearAllActions();
                    NWItem glove = (_.CreateItemOnObject("fist", oPC.Object));
                    glove.SetLocalInt("UNBREAKABLE", 1);

                    oPC.AssignCommand(() => _.ActionEquipItem(glove.Object, INVENTORY_SLOT_ARMS));
                }
            });
        }
Esempio n. 12
0
        public bool Run(params object[] args)
        {
            const int   QuestID = 30;
            NWPlaceable crystal = Object.OBJECT_SELF;
            NWPlayer    player  = _.GetLastUsedBy();

            // Check player's current quest state. If they aren't on stage 2 of the quest only show a message.
            var status       = _data.Single <PCQuestStatus>(x => x.PlayerID == player.GlobalID && x.QuestID == QuestID);
            var currentState = _data.Single <QuestState>(x => x.ID == status.CurrentQuestStateID);

            if (currentState.Sequence != 2)
            {
                player.SendMessage("The crystal glows quietly...");
                return(false);
            }

            // Player is on stage 2, so they're able to click the crystal, get a cluster, complete the quest, and teleport back to the cavern.
            int    type = crystal.GetLocalInt("CRYSTAL_COLOR_TYPE");
            string cluster;

            switch (type)
            {
            case 1: cluster = "c_cluster_blue"; break;    // Blue

            case 2: cluster = "c_cluster_red"; break;     // Red

            case 3: cluster = "c_cluster_green"; break;   // Green

            case 4: cluster = "c_cluster_yellow"; break;  // Yellow

            default: throw new Exception("Invalid crystal color type.");
            }

            _.CreateItemOnObject(cluster, player);
            _quest.AdvanceQuestState(player, crystal, QuestID);

            // Hide the "Source of Power?" placeable so the player can't use it again.
            _ovs.AdjustVisibility(player, "81533EBB-2084-4C97-B004-8E1D8C395F56", false);

            NWObject tpWP = _.GetObjectByTag("FORCE_QUEST_LANDING");

            player.AssignCommand(() => _.ActionJumpToLocation(tpWP.Location));

            // Notify the player that new lightsaber perks have unlocked.
            player.FloatingText("You have unlocked the Lightsaber Blueprints perk. Find this under the Engineering category in your perks menu.");

            return(true);
        }
Esempio n. 13
0
        public virtual void InitializePlayer()
        {
            if (IsInitializedAsPlayer || !IsPlayer)
            {
                return;
            }

            NWItem database = NWItem.Wrap(_.GetItemPossessedBy(Object, "database"));

            if (!database.IsValid)
            {
                database = NWItem.Wrap(_.CreateItemOnObject("database", Object));
            }

            string guid = Guid.NewGuid().ToString();

            database.SetLocalString("PC_ID_NUMBER", guid);
        }
Esempio n. 14
0
        public void HarvestPlant(NWPlayer player, NWItem shovel, NWPlaceable plant)
        {
            int growingPlantID = plant.GetLocalInt("GROWING_PLANT_ID");

            if (growingPlantID <= 0)
            {
                return;
            }

            int charges = shovel.Charges;

            if (charges <= 0)
            {
                player.SendMessage("Your shovel is broken.");
                return;
            }

            GrowingPlant growingPlant = _db.GrowingPlants.Single(x => x.GrowingPlantID == growingPlantID);
            Plant        plantEntity  = growingPlant.Plant;

            if (string.IsNullOrWhiteSpace(plantEntity.SeedResref))
            {
                player.SendMessage("That plant cannot be harvested.");
                return;
            }

            PlayerCharacter pcEntity = _db.PlayerCharacters.Single(x => x.PlayerID == player.GlobalID);

            // Farmers get a 5% chance to not expend a charge.
            if (pcEntity.BackgroundID != (int)BackgroundType.Farmer || _random.Random(100) + 1 > 5)
            {
                shovel.ReduceCharges();
            }

            growingPlant.IsActive = false;
            _db.SaveChanges();

            _.CreateItemOnObject(plantEntity.SeedResref, player.Object);
            plant.Destroy();

            player.FloatingText("You harvest the plant.");
        }
Esempio n. 15
0
        private void RunLootAttempt(NWCreature target, int lootTableID, int chance, int attempts)
        {
            if (chance <= 0)
            {
                chance = 75;
            }
            else if (chance > 100)
            {
                chance = 100;
            }

            if (attempts <= 0)
            {
                attempts = 1;
            }

            for (int a = 1; a <= attempts; a++)
            {
                if (_random.Random(100) + 1 <= chance)
                {
                    ItemVO model = PickRandomItemFromLootTable(lootTableID);
                    if (model == null)
                    {
                        continue;
                    }

                    int spawnQuantity = model.Quantity > 1 ? _random.Random(1, model.Quantity) : 1;

                    for (int x = 1; x <= spawnQuantity; x++)
                    {
                        var item = _.CreateItemOnObject(model.Resref, target);
                        if (!string.IsNullOrWhiteSpace(model.SpawnRule))
                        {
                            App.ResolveByInterface <ISpawnRule>("SpawnRule." + model.SpawnRule, action =>
                            {
                                action.Run(item);
                            });
                        }
                    }
                }
            }
        }
Esempio n. 16
0
        public void OnCreatureDeath(NWCreature creature)
        {
            int lootTableNumber = 1;
            int lootTableID     = creature.GetLocalInt("LOOT_TABLE_ID_" + lootTableNumber);

            while (lootTableID > 0)
            {
                int chance = creature.GetLocalInt("LOOT_TABLE_CHANCE_" + lootTableNumber);
                if (chance <= 0 || chance > 100)
                {
                    chance = 100;
                }

                int attempts = creature.GetLocalInt("LOOT_TABLE_ATTEMPTS_" + lootTableNumber);
                if (attempts <= 0)
                {
                    attempts = 1;
                }

                for (int a = 1; a <= attempts; a++)
                {
                    if (_random.Random(100) + 1 <= chance)
                    {
                        ItemVO model = PickRandomItemFromLootTable(lootTableID);
                        if (model == null)
                        {
                            continue;
                        }

                        int spawnQuantity = model.Quantity > 1 ? _random.Random(1, model.Quantity) : 1;

                        for (int x = 1; x <= spawnQuantity; x++)
                        {
                            _.CreateItemOnObject(model.Resref, creature.Object);
                        }
                    }
                }

                lootTableNumber++;
                lootTableID = creature.GetLocalInt("LOOT_TABLE_ID_" + lootTableNumber);
            }
        }
Esempio n. 17
0
        public NWItem ConvertStructureToItem(PCBaseStructure pcBaseStructure, NWObject target)
        {
            var    baseStructure = _data.Get <BaseStructure>(pcBaseStructure.BaseStructureID);
            NWItem item          = (_.CreateItemOnObject(baseStructure.ItemResref, target.Object));

            item.SetLocalInt("BASE_STRUCTURE_ID", pcBaseStructure.BaseStructureID);
            item.Name = baseStructure.Name;

            _durability.SetMaxDurability(item, (float)pcBaseStructure.Durability);
            _durability.SetDurability(item, (float)pcBaseStructure.Durability);
            item.StructureBonus = pcBaseStructure.StructureBonus;

            if (pcBaseStructure.InteriorStyleID != null && pcBaseStructure.ExteriorStyleID != null)
            {
                item.SetLocalInt("STRUCTURE_BUILDING_INTERIOR_ID", (int)pcBaseStructure.InteriorStyleID);
                item.SetLocalInt("STRUCTURE_BUILDING_EXTERIOR_ID", (int)pcBaseStructure.ExteriorStyleID);
                item.SetLocalInt("STRUCTURE_BUILDING_INITIALIZED", TRUE);
            }

            return(item);
        }
Esempio n. 18
0
        public void HarvestPlant(NWPlayer player, NWItem shovel, NWPlaceable plant)
        {
            string growingPlantID   = plant.GetLocalString("GROWING_PLANT_ID");
            Guid?  growingPlantGuid = null;

            if (!string.IsNullOrWhiteSpace(growingPlantID))
            {
                growingPlantGuid = new Guid(growingPlantID);
            }

            if (growingPlantGuid == null)
            {
                return;
            }

            int charges = shovel.Charges;

            if (charges <= 0)
            {
                player.SendMessage("Your shovel is broken.");
                return;
            }

            GrowingPlant growingPlant = _data.Single <GrowingPlant>(x => x.ID == growingPlantGuid);
            Plant        plantEntity  = _data.Get <Plant>(growingPlant.PlantID);

            if (string.IsNullOrWhiteSpace(plantEntity.SeedResref))
            {
                player.SendMessage("That plant cannot be harvested.");
                return;
            }

            growingPlant.IsActive = false;
            _data.SubmitDataChange(growingPlant, DatabaseActionType.Update);

            _.CreateItemOnObject(plantEntity.SeedResref, player.Object);
            plant.Destroy();

            player.FloatingText("You harvest the plant.");
        }
Esempio n. 19
0
        public void Run(NWPlayer player, NWObject questSource, int questID, string[] args)
        {
            string resref = args[0];
            int    amount = 1;

            if (args.Length > 1)
            {
                amount = Convert.ToInt32(args[1]);
            }

            if (amount < 1)
            {
                amount = 1;
            }
            else if (amount > 99)
            {
                amount = 99;
            }

            if (string.IsNullOrWhiteSpace(resref))
            {
                questSource.AssignCommand(() =>
                {
                    _.SpeakString("GiveItemRule misconfigured. Must set resref as first argument. Notify an admin.");
                });
                return;
            }

            NWItem item = _.CreateItemOnObject(resref, player, amount);

            if (!item.IsValid)
            {
                questSource.AssignCommand(() =>
                {
                    _.SpeakString("GiveItemRule misconfigured. Couldn't locate item with resref '" + resref + "'. Notify an admin.");
                });
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Spawns an item by resref in the user's inventory.
        /// </summary>
        /// <param name="user"></param>
        /// <param name="target"></param>
        /// <param name="targetLocation"></param>
        /// <param name="args"></param>
        public void DoAction(NWPlayer user, NWObject target, NWLocation targetLocation, params string[] args)
        {
            string resref   = args[0];
            int    quantity = 1;

            if (args.Length > 1)
            {
                if (!int.TryParse(args[1], out quantity))
                {
                    return;
                }
            }

            NWItem item = (_.CreateItemOnObject(resref, user.Object, quantity));

            if (!item.IsValid)
            {
                user.SendMessage(_color.Red("Item not found! Did you enter the correct ResRef?"));
                return;
            }

            item.IsIdentified = true;
        }
Esempio n. 21
0
        private void RunSearchCycle(NWPlayer oPC, NWPlaceable oChest, int iDC)
        {
            int lootTable = oChest.GetLocalInt(SearchSiteLootTableVariableName);
            int skill     = _.GetSkillRank(NWScript.SKILL_SEARCH, oPC.Object);

            if (skill > 10)
            {
                skill = 10;
            }
            else if (skill < 0)
            {
                skill = 0;
            }

            int roll         = _random.Random(20) + 1;
            int combinedRoll = roll + skill;

            if (roll + skill >= iDC)
            {
                oPC.FloatingText(_color.SkillCheck("Search: *success*: (" + roll + " + " + skill + " = " + combinedRoll + " vs. DC: " + iDC + ")"));
                ItemVO spawnItem = PickResultItem(lootTable);

                if (!string.IsNullOrWhiteSpace(spawnItem.Resref) && spawnItem.Quantity > 0)
                {
                    NWItem foundItem     = (_.CreateItemOnObject(spawnItem.Resref, oChest.Object, spawnItem.Quantity, ""));
                    float  maxDurability = _durability.GetMaxDurability(foundItem);
                    if (maxDurability > -1)
                    {
                        _durability.SetDurability(foundItem, _random.RandomFloat() * maxDurability + 1);
                    }
                }
            }
            else
            {
                oPC.FloatingText(_color.SkillCheck("Search: *failure*: (" + roll + " + " + skill + " = " + combinedRoll + " vs. DC: " + iDC + ")"));
            }
        }
Esempio n. 22
0
        public string GetResourceDescription(NWPlaceable resource)
        {
            NWPlaceable tempStorage = (_.GetObjectByTag("TEMP_ITEM_STORAGE"));
            string      resref      = resource.GetLocalString("RESOURCE_RESREF");
            string      qualityName = resource.GetLocalString("RESOURCE_QUALITY_NAME");

            NWItem tempItem     = (_.CreateItemOnObject(resref, tempStorage.Object));
            string resourceName = tempItem.Name;

            int typeID = 0;

            foreach (var ip in tempItem.ItemProperties)
            {
                if (_.GetItemPropertyType(ip) == (int)CustomItemPropertyType.ComponentType)
                {
                    typeID = _.GetItemPropertyCostTableValue(ip);
                    break;
                }
            }

            if (typeID <= 0)
            {
                return("Invalid component type");
            }

            int    tlkID         = Convert.ToInt32(_.Get2DAString("iprp_comptype", "Name", typeID));
            string componentName = _.GetStringByStrRef(tlkID);

            string description = qualityName + " " +
                                 resourceName + " (" +
                                 componentName + ")";

            tempItem.Destroy();

            return(description);
        }
Esempio n. 23
0
        public void ApplyBackgroundBonuses(NWPlayer oPC)
        {
            var    dbPlayer = _data.Single <Player>(x => x.ID == oPC.GlobalID);
            string pcName   = oPC.Name;
            int    classID  = oPC.Class1;

            string item1Resref   = "";
            int    item1Quantity = 1;
            string item2Resref   = "";
            int    item2Quantity = 1;

            switch ((BackgroundType)classID)
            {
            case BackgroundType.Freelancer:
                dbPlayer.UnallocatedSP = dbPlayer.UnallocatedSP + 3;
                _data.SubmitDataChange(dbPlayer, DatabaseActionType.Update);
                break;

            case BackgroundType.Smuggler:
                item1Resref = "blaster_s";
                break;

            case BackgroundType.Sharpshooter:
                item1Resref = "rifle_s";
                break;

            case BackgroundType.TerasKasi:
                item1Resref = "powerglove_t";
                break;

            case BackgroundType.SecurityOfficer:
                item1Resref = "baton_s";
                break;

            case BackgroundType.Berserker:
                item1Resref = "doubleaxe_z";
                break;

            case BackgroundType.Duelist:
                item1Resref = "kukri_d";
                break;

            case BackgroundType.Soldier:
                item1Resref = "greatsword_s";
                break;

            case BackgroundType.Armorsmith:
                _perk.DoPerkUpgrade(oPC, PerkType.ArmorBlueprints);
                break;

            case BackgroundType.Weaponsmith:
                _perk.DoPerkUpgrade(oPC, PerkType.WeaponBlueprints);
                break;

            case BackgroundType.Chef:
                _perk.DoPerkUpgrade(oPC, PerkType.FoodRecipes);
                break;

            case BackgroundType.Engineer:
                _perk.DoPerkUpgrade(oPC, PerkType.EngineeringBlueprints);
                break;

            case BackgroundType.Fabricator:
                _perk.DoPerkUpgrade(oPC, PerkType.FabricationBlueprints);
                break;

            case BackgroundType.Harvester:
                item1Resref = "scanner_r_h";
                item2Resref = "harvest_r_h";
                break;

            case BackgroundType.Scavenger:
                _perk.DoPerkUpgrade(oPC, PerkType.ScavengingExpert);
                break;

            case BackgroundType.Medic:
                _perk.DoPerkUpgrade(oPC, PerkType.ImmediateImprovement);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (!string.IsNullOrWhiteSpace(item1Resref))
            {
                NWItem oItem1 = (_.CreateItemOnObject(item1Resref, oPC.Object, item1Quantity));
                oItem1.IsCursed = true;
                oItem1.Name     = pcName + "'s " + oItem1.Name;
            }
            if (!string.IsNullOrWhiteSpace(item2Resref))
            {
                NWItem oItem2 = (_.CreateItemOnObject(item2Resref, oPC.Object, item2Quantity, ""));
                oItem2.IsCursed = true;
                oItem2.Name     = pcName + "'s " + oItem2.Name;
            }
        }
Esempio n. 24
0
        public void DoPerkUpgrade(NWPlayer oPC, int perkID)
        {
            Data.Entities.Perk perk   = _db.Perks.Single(x => x.PerkID == perkID);
            PCPerk             pcPerk = _db.PCPerks.SingleOrDefault(x => x.PlayerID == oPC.GlobalID && x.PerkID == perkID);
            PlayerCharacter    player = _db.PlayerCharacters.Single(x => x.PlayerID == oPC.GlobalID);

            if (CanPerkBeUpgraded(perk, pcPerk, player))
            {
                if (pcPerk == null)
                {
                    pcPerk = new PCPerk();
                    DateTime dt = DateTime.UtcNow;
                    pcPerk.AcquiredDate = dt;
                    pcPerk.PerkID       = perk.PerkID;
                    pcPerk.PlayerID     = oPC.GlobalID;
                    pcPerk.PerkLevel    = 0;

                    _db.PCPerks.Add(pcPerk);
                }

                PerkLevel nextPerkLevel = FindPerkLevel(perk.PerkLevels, pcPerk.PerkLevel + 1);
                if (nextPerkLevel == null)
                {
                    return;
                }

                pcPerk.PerkLevel++;
                player.UnallocatedSP -= nextPerkLevel.Price;

                _db.SaveChanges();

                // If a perk is activatable, create the item on the PC.
                // Remove any existing cast spell unique power properties and add the correct one based on the DB flag.
                if (!string.IsNullOrWhiteSpace(perk.ItemResref))
                {
                    if (_.GetIsObjectValid(_.GetItemPossessedBy(oPC.Object, perk.ItemResref)) == FALSE)
                    {
                        NWItem spellItem = NWItem.Wrap(_.CreateItemOnObject(perk.ItemResref, oPC.Object));
                        spellItem.IsCursed = true;
                        spellItem.SetLocalInt("ACTIVATION_PERK_ID", perk.PerkID);

                        foreach (ItemProperty ipCur in spellItem.ItemProperties)
                        {
                            int ipType    = _.GetItemPropertyType(ipCur);
                            int ipSubType = _.GetItemPropertySubType(ipCur);
                            if (ipType == ITEM_PROPERTY_CAST_SPELL &&
                                (ipSubType == IP_CONST_CASTSPELL_UNIQUE_POWER ||
                                 ipSubType == IP_CONST_CASTSPELL_UNIQUE_POWER_SELF_ONLY ||
                                 ipSubType == IP_CONST_CASTSPELL_ACTIVATE_ITEM))
                            {
                                _.RemoveItemProperty(spellItem.Object, ipCur);
                            }
                        }

                        ItemProperty ip;
                        if (perk.IsTargetSelfOnly)
                        {
                            ip = _.ItemPropertyCastSpell(IP_CONST_CASTSPELL_UNIQUE_POWER_SELF_ONLY, IP_CONST_CASTSPELL_NUMUSES_UNLIMITED_USE);
                        }
                        else
                        {
                            ip = _.ItemPropertyCastSpell(IP_CONST_CASTSPELL_UNIQUE_POWER, IP_CONST_CASTSPELL_NUMUSES_UNLIMITED_USE);
                        }

                        _biowareXP2.IPSafeAddItemProperty(spellItem, ip, 0.0f, AddItemPropertyPolicy.ReplaceExisting, false, false);
                    }

                    _.SetName(_.GetItemPossessedBy(oPC.Object, perk.ItemResref), perk.Name + " (Lvl. " + pcPerk.PerkLevel + ")");
                }

                oPC.SendMessage(_color.Green("Perk Purchased: " + perk.Name + " (Lvl. " + pcPerk.PerkLevel + ")"));

                IPerk perkScript = App.ResolveByInterface <IPerk>("Perk." + perk.JavaScriptName);

                if (perkScript == null)
                {
                    return;
                }
                perkScript.OnPurchased(oPC, pcPerk.PerkLevel);
            }
            else
            {
                oPC.FloatingText(_color.Red("You cannot purchase the perk at this time."));
            }
        }
Esempio n. 25
0
        public bool Run(params object[] args)
        {
            NWPlaceable point = NWPlaceable.Wrap(Object.OBJECT_SELF);
            const int   baseChanceToFullyHarvest = 50;
            bool        alwaysDestroys           = point.GetLocalInt("FORAGE_POINT_ALWAYS_DESTROYS") == 1;

            NWPlayer oPC             = NWPlayer.Wrap(_.GetLastOpenedBy());
            bool     hasBeenSearched = point.GetLocalInt("FORAGE_POINT_FULLY_HARVESTED") == 1;

            if (hasBeenSearched)
            {
                oPC.SendMessage("There's nothing left to harvest here...");
                return(true);
            }

            // Not fully harvested but the timer hasn't counted down yet.
            int refillTick = point.GetLocalInt("FORAGE_POINT_REFILL_TICKS");

            if (refillTick > 0)
            {
                oPC.SendMessage("You couldn't find anything new here. Check back later...");
                return(true);
            }

            if (!oPC.IsPlayer && !oPC.IsDM)
            {
                return(false);
            }
            PCSkill pcSkill = _skill.GetPCSkill(oPC, SkillType.Forage);

            if (pcSkill == null)
            {
                return(false);
            }

            int lootTableID = point.GetLocalInt("FORAGE_POINT_LOOT_TABLE_ID");
            int level       = point.GetLocalInt("FORAGE_POINT_LEVEL");
            int rank        = pcSkill.Rank;
            int delta       = level - rank;

            if (delta > 8)
            {
                oPC.SendMessage("You aren't skilled enough to forage through this. (Required Level: " + (level - 8) + ")");
                oPC.AssignCommand(() => _.ActionInteractObject(point.Object));
                return(true);
            }

            int dc = 6 + delta;

            if (dc <= 4)
            {
                dc = 4;
            }
            int searchAttempts = 1 + CalculateSearchAttempts(oPC);

            int luck = _perk.GetPCPerkLevel(oPC, PerkType.Lucky) + oPC.EffectiveLuckBonus;

            if (_random.Random(100) + 1 <= luck / 2)
            {
                dc--;
            }

            oPC.AssignCommand(() => _.ActionPlayAnimation(ANIMATION_LOOPING_GET_LOW, 1.0f, 2.0f));

            for (int attempt = 1; attempt <= searchAttempts; attempt++)
            {
                int roll = _random.Random(20) + 1;
                if (roll >= dc)
                {
                    oPC.FloatingText(_color.SkillCheck("Search: *success*: (" + roll + " vs. DC: " + dc + ")"));
                    ItemVO spawnItem = _loot.PickRandomItemFromLootTable(lootTableID);

                    if (spawnItem == null)
                    {
                        return(false);
                    }

                    if (!string.IsNullOrWhiteSpace(spawnItem.Resref) && spawnItem.Quantity > 0)
                    {
                        _.CreateItemOnObject(spawnItem.Resref, point.Object, spawnItem.Quantity);
                    }

                    float xp = _skill.CalculateRegisteredSkillLevelAdjustedXP(50, level, rank);
                    _skill.GiveSkillXP(oPC, SkillType.Forage, (int)xp);
                }
                else
                {
                    oPC.FloatingText(_color.SkillCheck("Search: *failure*: (" + roll + " vs. DC: " + dc + ")"));

                    float xp = _skill.CalculateRegisteredSkillLevelAdjustedXP(10, level, rank);
                    _skill.GiveSkillXP(oPC, SkillType.Forage, (int)xp);
                }
                dc += _random.Random(3) + 1;
            }

            if (_random.Random(100) + 1 <= 3)
            {
                _food.DecreaseHungerLevel(oPC, 1);
            }


            // Chance to destroy the forage point.
            int chanceToFullyHarvest = baseChanceToFullyHarvest - (_perk.GetPCPerkLevel(oPC, PerkType.CarefulForager) * 5);
            int growingPlantID       = point.GetLocalInt("GROWING_PLANT_ID");

            if (growingPlantID > 0)
            {
                Data.Entities.GrowingPlant growingPlant = _farming.GetGrowingPlantByID(growingPlantID);
                chanceToFullyHarvest = chanceToFullyHarvest - (growingPlant.LongevityBonus);
            }

            if (chanceToFullyHarvest <= 5)
            {
                chanceToFullyHarvest = 5;
            }

            if (alwaysDestroys || _random.Random(100) + 1 <= chanceToFullyHarvest)
            {
                point.SetLocalInt("FORAGE_POINT_FULLY_HARVESTED", 1);
                oPC.SendMessage("This resource has been fully harvested...");
            }
            // Otherwise the forage point will be refilled in 10-20 minutes.
            else
            {
                point.SetLocalInt("FORAGE_POINT_REFILL_TICKS", 100 + _random.Random(100));
            }

            point.SetLocalInt("FORAGE_POINT_DESPAWN_TICKS", 30);

            return(true);
        }
Esempio n. 26
0
        public void InitializePlayer(NWPlayer player)
        {
            if (player == null)
            {
                throw new ArgumentNullException(nameof(player));
            }
            if (player.Object == null)
            {
                throw new ArgumentNullException(nameof(player.Object));
            }

            if (!player.IsPlayer)
            {
                return;
            }

            if (!player.IsInitializedAsPlayer)
            {
                player.DestroyAllInventoryItems();
                player.InitializePlayer();

                _.CreateItemOnObject("open_rest_menu", player.Object);
                _.AssignCommand(player.Object, () => _.TakeGoldFromCreature(_.GetGold(player.Object), player.Object, 1));

                NWItem knife = NWItem.Wrap(_.CreateItemOnObject("survival_knife", player.Object));
                knife.Name          = player.Name + "'s Survival Knife";
                knife.IsCursed      = true;
                knife.MaxDurability = 5;
                knife.Durability    = 5;

                NWItem hammer = NWItem.Wrap(_.CreateItemOnObject("basic_hammer", player.Object));
                hammer.Name          = player.Name + "'s Hammer";
                hammer.IsCursed      = true;
                hammer.MaxDurability = 5;
                hammer.Durability    = 5;

                NWItem darts = NWItem.Wrap(_.CreateItemOnObject("nw_wthdt001", player.Object, 50)); // 50x Dart
                darts.Name     = "Starting Darts";
                darts.IsCursed = true;

                NWItem book = NWItem.Wrap(_.CreateItemOnObject("player_guide", player.Object));
                book.Name     = player.Name + "'s Player Guide";
                book.IsCursed = true;

                NWItem dyeKit = NWItem.Wrap(_.CreateItemOnObject("tk_omnidye", player.Object));
                dyeKit.IsCursed = true;

                NWItem shovel = NWItem.Wrap(_.CreateItemOnObject("basic_shovel", player.Object));
                shovel.Name     = player.Name + "'s Shovel";
                shovel.IsCursed = true;

                int numberOfFeats = _nwnxCreature.GetFeatCount(player);
                for (int currentFeat = numberOfFeats; currentFeat >= 0; currentFeat--)
                {
                    _nwnxCreature.RemoveFeat(player, _nwnxCreature.GetFeatByIndex(player, currentFeat - 1));
                }

                _nwnxCreature.SetClassByPosition(player, 0, CLASS_TYPE_FIGHTER);
                _nwnxCreature.AddFeatByLevel(player, FEAT_ARMOR_PROFICIENCY_LIGHT, 1);
                _nwnxCreature.AddFeatByLevel(player, FEAT_ARMOR_PROFICIENCY_MEDIUM, 1);
                _nwnxCreature.AddFeatByLevel(player, FEAT_ARMOR_PROFICIENCY_HEAVY, 1);
                _nwnxCreature.AddFeatByLevel(player, FEAT_SHIELD_PROFICIENCY, 1);
                _nwnxCreature.AddFeatByLevel(player, FEAT_WEAPON_PROFICIENCY_EXOTIC, 1);
                _nwnxCreature.AddFeatByLevel(player, FEAT_WEAPON_PROFICIENCY_MARTIAL, 1);
                _nwnxCreature.AddFeatByLevel(player, FEAT_WEAPON_PROFICIENCY_SIMPLE, 1);

                for (int iCurSkill = 1; iCurSkill <= 27; iCurSkill++)
                {
                    _nwnxCreature.SetSkillRank(player, iCurSkill - 1, 0);
                }
                _.SetFortitudeSavingThrow(player.Object, 0);
                _.SetReflexSavingThrow(player.Object, 0);
                _.SetWillSavingThrow(player.Object, 0);

                int classID = _.GetClassByPosition(1, player.Object);

                for (int index = 0; index <= 255; index++)
                {
                    _nwnxCreature.RemoveKnownSpell(player, classID, 0, index);
                }

                using (DataContext context = new DataContext())
                {
                    PlayerCharacter entity = player.ToEntity();
                    context.PlayerCharacters.Add(entity);
                    context.SaveChanges();
                }

                _skill.ApplyStatChanges(player, null);

                _.DelayCommand(1000, () => _.ApplyEffectToObject(DURATION_TYPE_INSTANT, _.EffectHeal(999), player.Object));

                InitializeHotBar(player);
            }
        }
Esempio n. 27
0
        public bool Run(params object[] args)
        {
            NWPlaceable drill       = Object.OBJECT_SELF;
            string      structureID = drill.GetLocalString("PC_BASE_STRUCTURE_ID");

            if (string.IsNullOrWhiteSpace(structureID))
            {
                string areaName = drill.Area.Name;
                Console.WriteLine("There was an error retrieving the PC_BASE_STRUCTURE_ID variable on drill in area: " + areaName);
                return(false);
            }

            Guid            structureGUID = new Guid(structureID);
            PCBaseStructure pcStructure   = _data.Get <PCBaseStructure>(structureGUID);
            PCBase          pcBase        = _data.Get <PCBase>(pcStructure.PCBaseID);
            PCBaseStructure tower         = _base.GetBaseControlTower(pcBase.ID);

            // Check whether there's space in this tower.
            int capacity = _base.CalculateResourceCapacity(pcBase.ID);
            int count    = _data.Where <PCBaseStructureItem>(x => x.PCBaseStructureID == tower.ID).Count() + 1;

            if (count > capacity)
            {
                return(false);
            }

            BaseStructure baseStructure = _data.Get <BaseStructure>(pcStructure.BaseStructureID);
            DateTime      now           = DateTime.UtcNow;

            var outOfPowerEffect = drill.Effects.SingleOrDefault(x => _.GetEffectTag(x) == "CONTROL_TOWER_OUT_OF_POWER");

            if (now >= pcBase.DateFuelEnds)
            {
                if (outOfPowerEffect == null)
                {
                    outOfPowerEffect = _.EffectVisualEffect(VFX_DUR_AURA_RED);
                    outOfPowerEffect = _.TagEffect(outOfPowerEffect, "CONTROL_TOWER_OUT_OF_POWER");
                    _.ApplyEffectToObject(DURATION_TYPE_PERMANENT, outOfPowerEffect, drill);
                }

                return(true);
            }
            else if (now < pcBase.DateFuelEnds && outOfPowerEffect != null)
            {
                _.RemoveEffect(drill, outOfPowerEffect);
            }

            int minuteReduce    = 2 * pcStructure.StructureBonus;
            int increaseMinutes = 60 - minuteReduce;
            int retrievalRating = baseStructure.RetrievalRating;

            if (increaseMinutes <= 20)
            {
                increaseMinutes = 20;
            }
            if (pcStructure.DateNextActivity == null)
            {
                pcStructure.DateNextActivity = now.AddMinutes(increaseMinutes);
                _data.SubmitDataChange(pcStructure, DatabaseActionType.Update);
            }

            if (!(now >= pcStructure.DateNextActivity))
            {
                return(true);
            }

            // Time to spawn a new item and reset the timer.
            var    dbArea      = _data.Single <Area>(x => x.Resref == pcBase.AreaResref);
            string sector      = pcBase.Sector;
            int    lootTableID = 0;

            switch (sector)
            {
            case "NE": lootTableID = dbArea.NortheastLootTableID ?? 0; break;

            case "NW": lootTableID = dbArea.NorthwestLootTableID ?? 0; break;

            case "SE": lootTableID = dbArea.SoutheastLootTableID ?? 0; break;

            case "SW": lootTableID = dbArea.SouthwestLootTableID ?? 0; break;
            }

            if (lootTableID <= 0)
            {
                Console.WriteLine("WARNING: Loot table ID not defined for area " + dbArea.Name + ". Drills cannot retrieve items.");
                return(false);
            }

            pcStructure.DateNextActivity = now.AddMinutes(increaseMinutes);

            var controlTower = _base.GetBaseControlTower(pcStructure.PCBaseID);
            var itemDetails  = _loot.PickRandomItemFromLootTable(lootTableID);

            var    tempStorage = _.GetObjectByTag("TEMP_ITEM_STORAGE");
            NWItem item        = _.CreateItemOnObject(itemDetails.Resref, tempStorage, itemDetails.Quantity);

            // Guard against invalid resrefs and missing items.
            if (!item.IsValid)
            {
                Console.WriteLine("ERROR: Could not create base drill item with resref '" + itemDetails.Resref + "'. Is this item valid?");
                return(false);
            }

            if (!string.IsNullOrWhiteSpace(itemDetails.SpawnRule))
            {
                App.ResolveByInterface <ISpawnRule>("SpawnRule." + itemDetails.SpawnRule, action =>
                {
                    action.Run(item, retrievalRating);
                });
            }

            var dbItem = new PCBaseStructureItem
            {
                PCBaseStructureID = controlTower.ID,
                ItemGlobalID      = item.GlobalID.ToString(),
                ItemName          = item.Name,
                ItemResref        = item.Resref,
                ItemTag           = item.Tag,
                ItemObject        = _serialization.Serialize(item)
            };

            _data.SubmitDataChange(pcStructure, DatabaseActionType.Update);
            _data.SubmitDataChange(dbItem, DatabaseActionType.Insert);
            item.Destroy();
            return(true);
        }
Esempio n. 28
0
        private void RunCreateItem(NWPlayer player)
        {
            var model = _craft.GetPlayerCraftingData(player);

            CraftBlueprint blueprint     = _data.Single <CraftBlueprint>(x => x.ID == model.BlueprintID);
            BaseStructure  baseStructure = blueprint.BaseStructureID == null ? null : _data.Get <BaseStructure>(blueprint.BaseStructureID);
            PCSkill        pcSkill       = _skill.GetPCSkill(player, blueprint.SkillID);

            int   pcEffectiveLevel = _craft.CalculatePCEffectiveLevel(player, pcSkill.Rank, (SkillType)blueprint.SkillID);
            int   itemLevel        = model.AdjustedLevel;
            float chance           = CalculateBaseChanceToAddProperty(pcEffectiveLevel, itemLevel);
            float equipmentBonus   = CalculateEquipmentBonus(player, (SkillType)blueprint.SkillID);

            if (chance <= 1.0f)
            {
                player.FloatingText(_color.Red("Critical failure! You don't have enough skill to create that item. All components were lost."));
                _craft.ClearPlayerCraftingData(player, true);
                return;
            }

            int    luckyBonus   = _perk.GetPCPerkLevel(player, PerkType.Lucky);
            var    craftedItems = new List <NWItem>();
            NWItem craftedItem  = (_.CreateItemOnObject(blueprint.ItemResref, player.Object, blueprint.Quantity));

            craftedItem.IsIdentified = true;
            craftedItems.Add(craftedItem);

            // If item isn't stackable, loop through and create as many as necessary.
            if (craftedItem.StackSize < blueprint.Quantity)
            {
                for (int x = 2; x <= blueprint.Quantity; x++)
                {
                    craftedItem = (_.CreateItemOnObject(blueprint.ItemResref, player.Object));
                    craftedItem.IsIdentified = true;
                    craftedItems.Add(craftedItem);
                }
            }

            // Recommended level gets set regardless if all item properties make it on the final product.
            // Also mark who crafted the item. This is later used for display on the item's examination event.
            foreach (var item in craftedItems)
            {
                item.RecommendedLevel = itemLevel < 0 ? 0 : itemLevel;
                item.SetLocalString("CRAFTER_PLAYER_ID", player.GlobalID.ToString());

                _base.ApplyCraftedItemLocalVariables(item, baseStructure);
            }

            if (_random.Random(1, 100) <= luckyBonus)
            {
                chance += _random.Random(1, luckyBonus);
            }

            int successAmount = 0;

            foreach (var component in model.MainComponents)
            {
                var result = RunComponentBonusAttempt(player, component, equipmentBonus, chance, craftedItems);
                successAmount += result.Item1;
                chance         = result.Item2;
            }
            foreach (var component in model.SecondaryComponents)
            {
                var result = RunComponentBonusAttempt(player, component, equipmentBonus, chance, craftedItems);
                successAmount += result.Item1;
                chance         = result.Item2;
            }
            foreach (var component in model.TertiaryComponents)
            {
                var result = RunComponentBonusAttempt(player, component, equipmentBonus, chance, craftedItems);
                successAmount += result.Item1;
                chance         = result.Item2;
            }
            foreach (var component in model.EnhancementComponents)
            {
                var result = RunComponentBonusAttempt(player, component, equipmentBonus, chance, craftedItems);
                successAmount += result.Item1;
                chance         = result.Item2;
            }

            // Structures gain increased durability based on the blueprint
            if (baseStructure != null)
            {
                foreach (var item in craftedItems)
                {
                    var maxDur = _durability.GetMaxDurability(item);
                    maxDur += (float)baseStructure.Durability;
                    _durability.SetMaxDurability(item, maxDur);
                    _durability.SetDurability(item, maxDur);
                }
            }

            player.SendMessage("You created " + blueprint.Quantity + "x " + blueprint.ItemName + "!");
            int   baseXP = 250 + successAmount * _random.Random(1, 50);
            float xp     = _skill.CalculateRegisteredSkillLevelAdjustedXP(baseXP, model.AdjustedLevel, pcSkill.Rank);

            var pcCraftedBlueprint = _data.SingleOrDefault <PCCraftedBlueprint>(x => x.PlayerID == player.GlobalID && x.CraftBlueprintID == blueprint.ID);

            if (pcCraftedBlueprint == null)
            {
                xp = xp * 1.25f;
                player.SendMessage("You receive an XP bonus for crafting this item for the first time.");

                pcCraftedBlueprint = new PCCraftedBlueprint
                {
                    CraftBlueprintID = blueprint.ID,
                    DateFirstCrafted = DateTime.UtcNow,
                    PlayerID         = player.GlobalID
                };

                _data.SubmitDataChange(pcCraftedBlueprint, DatabaseActionType.Insert);
            }

            _skill.GiveSkillXP(player, blueprint.SkillID, (int)xp);
            _craft.ClearPlayerCraftingData(player, true);
        }
Esempio n. 29
0
        public void ApplyEffects(NWCreature user, NWItem item, NWObject target, Location targetLocation, CustomData customData)
        {
            NWPlayer        player        = user.Object;
            ResourceQuality quality       = (ResourceQuality)target.GetLocalInt("RESOURCE_QUALITY");
            int             tier          = target.GetLocalInt("RESOURCE_TIER");
            int             remaining     = target.GetLocalInt("RESOURCE_COUNT") - 1;
            string          itemResref    = target.GetLocalString("RESOURCE_RESREF");
            int             ipBonusChance = _resource.CalculateChanceForComponentBonus(player, tier, quality);
            int             roll          = _random.Random(1, 100);
            int             rank          = _skill.GetPCSkillRank(player, SkillType.Harvesting);

            if (item.RecommendedLevel < rank)
            {
                rank = item.RecommendedLevel;
            }

            int difficulty = (tier - 1) * 10 + _resource.GetDifficultyAdjustment(quality);
            int delta      = difficulty - rank;

            int baseXP = 0;

            if (delta >= 6)
            {
                baseXP = 400;
            }
            else if (delta == 5)
            {
                baseXP = 350;
            }
            else if (delta == 4)
            {
                baseXP = 325;
            }
            else if (delta == 3)
            {
                baseXP = 300;
            }
            else if (delta == 2)
            {
                baseXP = 250;
            }
            else if (delta == 1)
            {
                baseXP = 225;
            }
            else if (delta == 0)
            {
                baseXP = 200;
            }
            else if (delta == -1)
            {
                baseXP = 150;
            }
            else if (delta == -2)
            {
                baseXP = 100;
            }
            else if (delta == -3)
            {
                baseXP = 50;
            }
            else if (delta == -4)
            {
                baseXP = 25;
            }

            int itemHarvestBonus = item.HarvestingBonus;
            int scanningBonus    = user.GetLocalInt(target.GlobalID.ToString());

            ipBonusChance += itemHarvestBonus * 2 + scanningBonus * 2;

            baseXP = baseXP + scanningBonus * 5;

            NWItem resource = _.CreateItemOnObject(itemResref, player.Object);

            if (roll <= ipBonusChance)
            {
                var ip = _resource.GetRandomComponentBonusIP(quality);
                _biowareXP2.IPSafeAddItemProperty(resource, ip.Item1, 0.0f, AddItemPropertyPolicy.IgnoreExisting, true, true);

                switch (ip.Item2)
                {
                case 0:
                    resource.Name = _color.Green(resource.Name);
                    break;

                case 1:
                    resource.Name = _color.Blue(resource.Name);
                    break;

                case 2:
                    resource.Name = _color.Purple(resource.Name);
                    break;

                case 3:
                    resource.Name = _color.Orange(resource.Name);
                    break;
                }
            }

            float decayMinimum = 0.03f;
            float decayMaximum = 0.07f;

            if (delta > 0)
            {
                decayMinimum += delta * 0.1f;
                decayMaximum += delta * 0.1f;
            }

            user.SendMessage("You harvest " + resource.Name + ".");
            _durability.RunItemDecay(player, item, _random.RandomFloat(decayMinimum, decayMaximum));
            int xp = baseXP;

            _skill.GiveSkillXP(player, SkillType.Harvesting, xp);

            if (remaining <= 0)
            {
                NWPlaceable prop = target.GetLocalObject("RESOURCE_PROP_OBJ");

                if (prop.IsValid)
                {
                    prop.Destroy();
                }

                target.Destroy();
                user.DeleteLocalInt(target.GlobalID.ToString());
            }
            else
            {
                target.SetLocalInt("RESOURCE_COUNT", remaining);
            }

            _.ApplyEffectAtLocation(DURATION_TYPE_INSTANT, _.EffectVisualEffect(VFX_FNF_SUMMON_MONSTER_3), target.Location);
        }
Esempio n. 30
0
        public bool Run(params object[] args)
        {
            NWPlaceable resource = NWPlaceable.Wrap(Object.OBJECT_SELF);
            NWPlayer    oPC      = NWPlayer.Wrap(_.GetLastDamager(resource.Object));

            if (oPC.GetLocalInt("NOT_USING_CORRECT_WEAPON") == 1)
            {
                oPC.DeleteLocalInt("NOT_USING_CORRECT_WEAPON");
                return(true);
            }

            PlayerCharacter pcEntity = _db.PlayerCharacters.Single(x => x.PlayerID == oPC.GlobalID);

            NWItem    oWeapon            = NWItem.Wrap(_.GetLastWeaponUsed(oPC.Object));
            Location  location           = oPC.Location;
            string    resourceItemResref = resource.GetLocalString("RESOURCE_RESREF");
            int       activityID         = resource.GetLocalInt("RESOURCE_ACTIVITY");
            string    resourceName       = resource.GetLocalString("RESOURCE_NAME");
            int       resourceCount      = resource.GetLocalInt("RESOURCE_COUNT");
            int       difficultyRating   = resource.GetLocalInt("RESOURCE_DIFFICULTY_RATING");
            int       weaponChanceBonus;
            SkillType skillType;
            int       perkChanceBonus;
            int       secondResourceChance;
            int       durabilityChanceReduction = 0;
            int       hasteChance;
            int       lucky = _perk.GetPCPerkLevel(oPC, PerkType.Lucky) + oPC.EffectiveLuckBonus;
            bool      hasBaggerPerk;

            if (activityID == 1) // 1 = Logging
            {
                weaponChanceBonus = oWeapon.LoggingBonus;
                if (weaponChanceBonus > 0)
                {
                    weaponChanceBonus        += _perk.GetPCPerkLevel(oPC, PerkType.LoggingAxeExpert) * 5;
                    durabilityChanceReduction = _perk.GetPCPerkLevel(oPC, PerkType.LoggingAxeExpert) * 10 + lucky;
                }

                skillType            = SkillType.Logging;
                perkChanceBonus      = _perk.GetPCPerkLevel(oPC, PerkType.Lumberjack) * 5 + lucky;
                secondResourceChance = _perk.GetPCPerkLevel(oPC, PerkType.PrecisionLogging) * 10;
                hasteChance          = _perk.GetPCPerkLevel(oPC, PerkType.SpeedyLogger) * 10 + lucky;

                if (pcEntity.BackgroundID == (int)BackgroundType.Lumberjack)
                {
                    hasteChance += 10;
                }

                hasBaggerPerk = _perk.GetPCPerkLevel(oPC, PerkType.WoodBagger) > 0;
            }
            else if (activityID == 2) // Mining
            {
                weaponChanceBonus = oWeapon.MiningBonus;
                if (weaponChanceBonus > 0)
                {
                    weaponChanceBonus        += _perk.GetPCPerkLevel(oPC, PerkType.PickaxeExpert) * 5;
                    durabilityChanceReduction = _perk.GetPCPerkLevel(oPC, PerkType.PickaxeExpert) * 10 + lucky;
                }
                skillType            = SkillType.Mining;
                perkChanceBonus      = _perk.GetPCPerkLevel(oPC, PerkType.Miner) * 5 + lucky;
                secondResourceChance = _perk.GetPCPerkLevel(oPC, PerkType.PrecisionMining) * 10;
                hasteChance          = _perk.GetPCPerkLevel(oPC, PerkType.SpeedyMiner) * 10 + lucky;

                if (pcEntity.BackgroundID == (int)BackgroundType.Miner)
                {
                    hasteChance += 10;
                }

                hasBaggerPerk = _perk.GetPCPerkLevel(oPC, PerkType.OreBagger) > 0;
            }
            else
            {
                return(false);
            }
            PCSkill skill = _skill.GetPCSkillByID(oPC.GlobalID, (int)skillType);
            int     durabilityLossChance = 100 - durabilityChanceReduction;

            if (_random.Random(100) <= durabilityLossChance)
            {
                _durability.RunItemDecay(oPC, oWeapon);
            }

            int baseChance = 10;
            int chance     = baseChance + weaponChanceBonus;

            chance += CalculateSuccessChanceDeltaModifier(difficultyRating, skill.Rank);
            chance += perkChanceBonus;

            bool givePityItem = false;

            if (chance > 0)
            {
                if (_random.Random(100) + 1 <= hasteChance)
                {
                    _.ApplyEffectToObject(DURATION_TYPE_TEMPORARY, _.EffectHaste(), oPC.Object, 8.0f);
                }

                // Give an item if the player hasn't gotten anything after 6-8 attempts.
                int      attemptFailureCount = oPC.GetLocalInt("RESOURCE_ATTEMPT_FAILURE_COUNT") + 1;
                NWObject failureResource     = NWObject.Wrap(oPC.GetLocalObject("RESOURCE_ATTEMPT_FAILURE_OBJECT"));

                if (!failureResource.IsValid || !Equals(failureResource, resource))
                {
                    failureResource     = resource;
                    attemptFailureCount = 1;
                }

                int pityItemChance = 0;
                if (attemptFailureCount == 6)
                {
                    pityItemChance = 60;
                }
                else if (attemptFailureCount == 7)
                {
                    pityItemChance = 80;
                }
                else if (attemptFailureCount >= 8)
                {
                    pityItemChance = 100;
                }

                if (_random.Random(100) + 1 <= pityItemChance)
                {
                    givePityItem        = true;
                    attemptFailureCount = 0;
                }

                oPC.SetLocalInt("RESOURCE_ATTEMPT_FAILURE_COUNT", attemptFailureCount);
                oPC.SetLocalObject("RESOURCE_ATTEMPT_FAILURE_OBJECT", failureResource.Object);
            }

            if (chance <= 0)
            {
                oPC.FloatingText("You do not have enough skill to harvest this resource...");
            }
            else if (_random.Random(100) <= chance || givePityItem)
            {
                if (hasBaggerPerk)
                {
                    _.CreateItemOnObject(resourceItemResref, oPC.Object);
                }
                else
                {
                    _.CreateObject(OBJECT_TYPE_ITEM, resourceItemResref, location);
                }


                oPC.FloatingText("You break off some " + resourceName + ".");
                resource.SetLocalInt("RESOURCE_COUNT", --resourceCount);
                _.ApplyEffectToObject(DURATION_TYPE_INSTANT, _.EffectHeal(10000), resource.Object);

                if (_random.Random(100) + 1 <= secondResourceChance)
                {
                    oPC.FloatingText("You break off a second piece.");

                    if (hasBaggerPerk)
                    {
                        _.CreateItemOnObject(resourceItemResref, oPC.Object);
                    }
                    else
                    {
                        _.CreateObject(OBJECT_TYPE_ITEM, resourceItemResref, location);
                    }
                }

                float deltaModifier = CalculateXPDeltaModifier(difficultyRating, skill.Rank);
                float baseXP        = (100 + _random.Random(20)) * deltaModifier;
                int   xp            = (int)_skill.CalculateRegisteredSkillLevelAdjustedXP(baseXP, oWeapon.RecommendedLevel, skill.Rank);
                _skill.GiveSkillXP(oPC, skillType, xp);

                oPC.DeleteLocalInt("RESOURCE_ATTEMPT_FAILURE_COUNT");
                oPC.DeleteLocalObject("RESOURCE_ATTEMPT_FAILURE_OBJECT");
            }

            if (resourceCount <= 0)
            {
                SpawnSeed(resource, oPC);

                NWObject prop = NWObject.Wrap(resource.GetLocalObject("RESOURCE_PROP_OBJ"));
                if (prop.IsValid)
                {
                    prop.Destroy();
                }
                resource.Destroy();
            }
            return(true);
        }