Beispiel #1
0
        private void ApplyItemFeatures(NWItem item)
        {
            Data.Entities.Item entity = GetItemEntity(item);

            if (entity == null)
            {
                return;
            }

            item.CustomAC               = entity.AC;
            item.CustomItemType         = (CustomItemType)entity.ItemTypeID;
            item.RecommendedLevel       = entity.RecommendedLevel;
            item.LoggingBonus           = entity.LoggingBonus;
            item.MiningBonus            = entity.MiningBonus;
            item.CastingSpeed           = entity.CastingSpeed;
            item.CraftBonusMetalworking = entity.CraftBonusMetalworking;
            item.CraftBonusArmorsmith   = entity.CraftBonusArmorsmith;
            item.CraftBonusWeaponsmith  = entity.CraftBonusWeaponsmith;
            item.CraftBonusCooking      = entity.CraftBonusCooking;
            item.CraftBonusWoodworking  = entity.CraftBonusWoodworking;
            item.AssociatedSkillID      = entity.AssociatedSkillID;
            item.CraftTierLevel         = entity.CraftTierLevel;
            item.HPBonus   = entity.HPBonus;
            item.ManaBonus = entity.ManaBonus;

            if (entity.Weight > 0)
            {
                _nwnxItem.SetWeight(item, entity.Weight);
            }

            if (entity.DurabilityPoints > 0)
            {
                _durability.SetMaxDurability(item, entity.DurabilityPoints);
            }
        }
Beispiel #2
0
        public void Apply(NWPlayer player, NWItem target, params string[] args)
        {
            var maxDurability = _durability.GetMaxDurability(target);
            var curDurability = _durability.GetDurability(target);

            int   value    = Convert.ToInt32(args[0]);
            float newValue = maxDurability + value;

            if (newValue > 100)
            {
                newValue = 100;
            }
            maxDurability  = newValue;
            curDurability += value;

            _durability.SetMaxDurability(target, maxDurability);
            _durability.SetDurability(target, curDurability);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }
Beispiel #5
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;
            }

            // Player is initialized but not in the DB. Wipe the tag and rerun them through initialization - something went wrong before.
            if (player.IsInitializedAsPlayer)
            {
                if (_data.GetAll <Player>().SingleOrDefault(x => x.ID == player.GlobalID) == null)
                {
                    _.SetTag(player, string.Empty);
                }
            }

            if (!player.IsInitializedAsPlayer)
            {
                player.DestroyAllInventoryItems();
                player.InitializePlayer();
                _.AssignCommand(player, () => _.TakeGoldFromCreature(_.GetGold(player), player, 1));

                _.DelayCommand(0.5f, () =>
                {
                    _.GiveGoldToCreature(player, 100);
                });

                // Capture original stats before we level up the player.
                int str  = _nwnxCreature.GetRawAbilityScore(player, ABILITY_STRENGTH);
                int con  = _nwnxCreature.GetRawAbilityScore(player, ABILITY_CONSTITUTION);
                int dex  = _nwnxCreature.GetRawAbilityScore(player, ABILITY_DEXTERITY);
                int @int = _nwnxCreature.GetRawAbilityScore(player, ABILITY_INTELLIGENCE);
                int wis  = _nwnxCreature.GetRawAbilityScore(player, ABILITY_WISDOM);
                int cha  = _nwnxCreature.GetRawAbilityScore(player, ABILITY_CHARISMA);

                // Take player to level 5 in NWN levels so that we have access to more HP slots
                _.GiveXPToCreature(player, 10000);

                for (int level = 1; level <= 5; level++)
                {
                    _.LevelUpHenchman(player, player.Class1);
                }

                // Set stats back to how they were on entry.
                _nwnxCreature.SetRawAbilityScore(player, ABILITY_STRENGTH, str);
                _nwnxCreature.SetRawAbilityScore(player, ABILITY_CONSTITUTION, con);
                _nwnxCreature.SetRawAbilityScore(player, ABILITY_DEXTERITY, dex);
                _nwnxCreature.SetRawAbilityScore(player, ABILITY_INTELLIGENCE, @int);
                _nwnxCreature.SetRawAbilityScore(player, ABILITY_WISDOM, wis);
                _nwnxCreature.SetRawAbilityScore(player, ABILITY_CHARISMA, cha);

                NWItem knife = (_.CreateItemOnObject("survival_knife", player));
                knife.Name     = player.Name + "'s Survival Knife";
                knife.IsCursed = true;
                _durability.SetMaxDurability(knife, 5);
                _durability.SetDurability(knife, 5);

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

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

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

                _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);
                _nwnxCreature.AddFeatByLevel(player, (int)CustomFeatType.StructureManagementTool, 1);
                _nwnxCreature.AddFeatByLevel(player, (int)CustomFeatType.OpenRestMenu, 1);
                _nwnxCreature.AddFeatByLevel(player, (int)CustomFeatType.RenameCraftedItem, 1);
                _nwnxCreature.AddFeatByLevel(player, (int)CustomFeatType.ChatCommandTargeter, 1);

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

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

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

                Player entity = CreateDBPCEntity(player);
                _data.SubmitDataChange(entity, DatabaseActionType.Insert);

                var skills = _data.GetAll <Skill>();
                foreach (var skill in skills)
                {
                    var pcSkill = new PCSkill
                    {
                        IsLocked = false,
                        SkillID  = skill.ID,
                        PlayerID = entity.ID,
                        Rank     = 0,
                        XP       = 0
                    };

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

                _race.ApplyDefaultAppearance(player);
                _nwnxCreature.SetAlignmentLawChaos(player, 50);
                _nwnxCreature.SetAlignmentGoodEvil(player, 50);
                _background.ApplyBackgroundBonuses(player);

                _stat.ApplyStatChanges(player, null, true);
                _language.InitializePlayerLanguages(player);

                _.DelayCommand(1.0f, () => _.ApplyEffectToObject(DURATION_TYPE_INSTANT, _.EffectHeal(999), player));

                InitializeHotBar(player);
            }
        }
        public void ApplyComponentBonus(NWItem product, ItemProperty sourceIP)
        {
            ComponentBonusType bonusType = (ComponentBonusType)_.GetItemPropertySubType(sourceIP);
            int          amount          = _.GetItemPropertyCostTableValue(sourceIP);
            ItemProperty prop            = null;
            string       sourceTag       = string.Empty;

            // A note about the sourceTags:
            // It's not currently possible to create custom item properties on items. To get around this,
            // we look in an inaccessible container which holds the custom item properties. Then, we get the
            // item that has the item property we want. From there we take that item property and copy it to
            // the crafted item.
            // This is a really roundabout way to do it, but it's the only option for now. Hopefully a feature to
            // directly add the item properties comes in to NWNX in the future.
            for (int x = 1; x <= amount; x++)
            {
                switch (bonusType)
                {
                case ComponentBonusType.ModSocketRed:
                    sourceTag = "rslot_red";
                    break;

                case ComponentBonusType.ModSocketBlue:
                    sourceTag = "rslot_blue";
                    break;

                case ComponentBonusType.ModSocketGreen:
                    sourceTag = "rslot_green";
                    break;

                case ComponentBonusType.ModSocketYellow:
                    sourceTag = "rslot_yellow";
                    break;

                case ComponentBonusType.ModSocketPrismatic:
                    sourceTag = "rslot_prismatic";
                    break;

                case ComponentBonusType.DurabilityUp:
                    var maxDur = _durability.GetMaxDurability(product) + amount;
                    _durability.SetMaxDurability(product, maxDur);
                    _durability.SetDurability(product, maxDur);
                    break;

                case ComponentBonusType.ChargesUp:
                    product.Charges += amount;
                    break;

                case ComponentBonusType.ACUp:
                    product.CustomAC += amount;
                    break;

                case ComponentBonusType.HarvestingUp:
                    product.HarvestingBonus += amount;
                    break;

                case ComponentBonusType.CastingSpeedUp:
                    product.CastingSpeed += amount;
                    break;

                case ComponentBonusType.ArmorsmithUp:
                    product.CraftBonusArmorsmith += amount;
                    break;

                case ComponentBonusType.WeaponsmithUp:
                    product.CraftBonusWeaponsmith += amount;
                    break;

                case ComponentBonusType.CookingUp:
                    product.CraftBonusCooking += amount;
                    break;

                case ComponentBonusType.EngineeringUp:
                    product.CraftBonusEngineering += amount;
                    break;

                case ComponentBonusType.FabricationUp:
                    product.CraftBonusFabrication += amount;
                    break;

                case ComponentBonusType.HPUp:
                    product.HPBonus += amount;
                    break;

                case ComponentBonusType.FPUp:
                    product.FPBonus += amount;
                    break;

                case ComponentBonusType.EnmityUp:
                    product.EnmityRate += amount;
                    break;

                case ComponentBonusType.EnmityDown:
                    product.EnmityRate -= amount;
                    break;

                case ComponentBonusType.DarkAbilityUp:
                    product.DarkAbilityBonus += amount;
                    break;

                case ComponentBonusType.LightAbilityUp:
                    product.LightAbilityBonus += amount;
                    break;

                case ComponentBonusType.LuckUp:
                    product.LuckBonus += amount;
                    break;

                case ComponentBonusType.MeditateUp:
                    product.MeditateBonus += amount;
                    break;

                case ComponentBonusType.RestUp:
                    product.RestBonus += amount;
                    break;

                case ComponentBonusType.MedicineUp:
                    product.MedicineBonus += amount;
                    break;

                case ComponentBonusType.HPRegenUp:
                    product.HPRegenBonus += amount;
                    break;

                case ComponentBonusType.FPRegenUp:
                    product.FPRegenBonus += amount;
                    break;

                case ComponentBonusType.BaseAttackBonusUp:
                    product.BaseAttackBonus += amount;
                    break;

                case ComponentBonusType.SneakAttackUp:
                    product.SneakAttackBonus += amount;
                    break;

                case ComponentBonusType.DamageUp:
                    product.DamageBonus += amount;
                    break;

                case ComponentBonusType.DarkAbilityDown:
                    product.DarkAbilityBonus -= amount;
                    break;

                case ComponentBonusType.LightAbilityDown:
                    product.LightAbilityBonus -= amount;
                    break;

                case ComponentBonusType.StructureBonusUp:
                    product.StructureBonus += amount;
                    break;

                case ComponentBonusType.StrengthUp:
                    product.StrengthBonus += amount;
                    break;

                case ComponentBonusType.DexterityUp:
                    product.DexterityBonus += amount;
                    break;

                case ComponentBonusType.ConstitutionUp:
                    product.ConstitutionBonus += amount;
                    break;

                case ComponentBonusType.WisdomUp:
                    product.WisdomBonus += amount;
                    break;

                case ComponentBonusType.IntelligenceUp:
                    product.IntelligenceBonus += amount;
                    break;

                case ComponentBonusType.CharismaUp:
                    product.CharismaBonus += amount;
                    break;

                case ComponentBonusType.AttackBonusUp:
                    prop = _.ItemPropertyAttackBonus(amount);
                    break;

                case ComponentBonusType.DurationUp:
                    product.DurationBonus += amount;
                    break;

                case ComponentBonusType.ScanningUp:
                    product.ScanningBonus += amount;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                if (!string.IsNullOrWhiteSpace(sourceTag))
                {
                    prop = _item.GetCustomItemPropertyByItemTag(sourceTag);
                }

                if (prop == null)
                {
                    return;
                }

                _biowareXP2.IPSafeAddItemProperty(product, prop, 0.0f, AddItemPropertyPolicy.IgnoreExisting, true, true);
            }
        }