예제 #1
0
        private void ReapplyBackgroundBonus(PerkType perkType)
        {
            var player = GetPC();

            if (IsGrantedByBackground(perkType))
            {
                _background.ApplyBackgroundBonuses(player);
            }
        }
예제 #2
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);
            }
        }