Example #1
0
        public static void InitializePlayer(NWPlayer player)
        {
            if (player == null)
            {
                throw new ArgumentNullException(nameof(player));
            }
            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 (!DataService.Player.ExistsByID(player.GlobalID))
                {
                    SetTag(player, string.Empty);
                }
            }

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

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

                // Capture original stats before we level up the player.
                int str  = NWNXCreature.GetRawAbilityScore(player, AbilityType.Strength);
                int con  = NWNXCreature.GetRawAbilityScore(player, AbilityType.Constitution);
                int dex  = NWNXCreature.GetRawAbilityScore(player, AbilityType.Dexterity);
                int @int = NWNXCreature.GetRawAbilityScore(player, AbilityType.Intelligence);
                int wis  = NWNXCreature.GetRawAbilityScore(player, AbilityType.Wisdom);
                int cha  = NWNXCreature.GetRawAbilityScore(player, AbilityType.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, AbilityType.Strength, str);
                NWNXCreature.SetRawAbilityScore(player, AbilityType.Constitution, con);
                NWNXCreature.SetRawAbilityScore(player, AbilityType.Dexterity, dex);
                NWNXCreature.SetRawAbilityScore(player, AbilityType.Intelligence, @int);
                NWNXCreature.SetRawAbilityScore(player, AbilityType.Wisdom, wis);
                NWNXCreature.SetRawAbilityScore(player, AbilityType.Charisma, cha);

                NWItem knife = (CreateItemOnObject("survival_knife", player));
                knife.Name     = player.Name + "'s Survival Knife";
                knife.IsCursed = true;
                DurabilityService.SetMaxDurability(knife, 5);
                DurabilityService.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.ArmorProficiencyLight, 1);
                NWNXCreature.AddFeatByLevel(player, Feat.ArmorProficiencyMedium, 1);
                NWNXCreature.AddFeatByLevel(player, Feat.ArmorProficiencyHeavy, 1);
                NWNXCreature.AddFeatByLevel(player, Feat.ShieldProficiency, 1);
                NWNXCreature.AddFeatByLevel(player, Feat.WeaponProficiencyExotic, 1);
                NWNXCreature.AddFeatByLevel(player, Feat.WeaponProficiencyMartial, 1);
                NWNXCreature.AddFeatByLevel(player, Feat.WeaponProficiencySimple, 1);
                NWNXCreature.AddFeatByLevel(player, Feat.UncannyDodge1, 1);
                NWNXCreature.AddFeatByLevel(player, Feat.StructureManagementTool, 1);
                NWNXCreature.AddFeatByLevel(player, Feat.OpenRestMenu, 1);
                NWNXCreature.AddFeatByLevel(player, Feat.RenameCraftedItem, 1);
                NWNXCreature.AddFeatByLevel(player, Feat.ChatCommandTargeter, 1);

                foreach (var skillType in Enum.GetValues(typeof(Skill)))
                {
                    var skill = (Skill)skillType;
                    if (skill == Skill.Invalid || skill == Skill.AllSkills)
                    {
                        continue;
                    }

                    NWNXCreature.SetSkillRank(player, skill, 0);
                }
                SetFortitudeSavingThrow(player, 0);
                SetReflexSavingThrow(player, 0);
                SetWillSavingThrow(player, 0);

                var classType = GetClassByPosition(1, player);

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

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

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

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

                RaceService.ApplyDefaultAppearance(player);
                NWNXCreature.SetAlignmentLawChaos(player, 50);
                NWNXCreature.SetAlignmentGoodEvil(player, 50);
                BackgroundService.ApplyBackgroundBonuses(player);

                PlayerStatService.ApplyStatChanges(player, null, true);
                LanguageService.InitializePlayerLanguages(player);

                DelayCommand(1.0f, () => ApplyEffectToObject(DurationType.Instant, EffectHeal(999), player));

                InitializeHotBar(player);
            }
        }
Example #2
0
        public static 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 (DataService.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;
                DurabilityService.SetMaxDurability(knife, 5);
                DurabilityService.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, FEAT_UNCANNY_DODGE_1, 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);
                DataService.SubmitDataChange(entity, DatabaseActionType.Insert);

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

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

                RaceService.ApplyDefaultAppearance(player);
                NWNXCreature.SetAlignmentLawChaos(player, 50);
                NWNXCreature.SetAlignmentGoodEvil(player, 50);
                BackgroundService.ApplyBackgroundBonuses(player);

                PlayerStatService.ApplyStatChanges(player, null, true);
                LanguageService.InitializePlayerLanguages(player);

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

                InitializeHotBar(player);
            }
        }
Example #3
0
        private static Player CreateDBPCEntity(NWPlayer player)
        {
            RacialType      race = (RacialType)player.RacialType;
            AssociationType assType;
            var             goodEvil = GetAlignmentGoodEvil(player);
            var             lawChaos = GetAlignmentLawChaos(player);

            // Jedi Order -- Mandalorian -- Sith Empire
            if (goodEvil == Alignment.Good && lawChaos == Alignment.Lawful)
            {
                assType = AssociationType.JediOrder;
            }
            else if (goodEvil == Alignment.Good && lawChaos == Alignment.Neutral)
            {
                assType = AssociationType.Mandalorian;
            }
            else if (goodEvil == Alignment.Good && lawChaos == Alignment.Chaotic)
            {
                assType = AssociationType.SithEmpire;
            }

            // Smugglers -- Unaligned -- Hutt Cartel
            else if (goodEvil == Alignment.Neutral && lawChaos == Alignment.Lawful)
            {
                assType = AssociationType.Smugglers;
            }
            else if (goodEvil == Alignment.Neutral && lawChaos == Alignment.Neutral)
            {
                assType = AssociationType.Unaligned;
            }
            else if (goodEvil == Alignment.Neutral && lawChaos == Alignment.Chaotic)
            {
                assType = AssociationType.HuttCartel;
            }

            // Republic -- Czerka -- Sith Order
            else if (goodEvil == Alignment.Evil && lawChaos == Alignment.Lawful)
            {
                assType = AssociationType.Republic;
            }
            else if (goodEvil == Alignment.Evil && lawChaos == Alignment.Neutral)
            {
                assType = AssociationType.Czerka;
            }
            else if (goodEvil == Alignment.Evil && lawChaos == Alignment.Chaotic)
            {
                assType = AssociationType.SithOrder;
            }
            else
            {
                throw new Exception("Association type not found. GoodEvil = " + goodEvil + ", LawChaos = " + lawChaos);
            }

            int sp = 5;

            if (race == RacialType.Human)
            {
                sp++;
            }

            Player entity = new Player
            {
                ID                                = player.GlobalID,
                CharacterName                     = player.Name,
                HitPoints                         = player.CurrentHP,
                LocationAreaResref                = GetResRef(GetAreaFromLocation(player.Location)),
                LocationX                         = player.Position.X,
                LocationY                         = player.Position.Y,
                LocationZ                         = player.Position.Z,
                LocationOrientation               = player.Facing,
                CreateTimestamp                   = DateTime.UtcNow,
                UnallocatedSP                     = sp,
                HPRegenerationAmount              = 1,
                RegenerationTick                  = 20,
                RegenerationRate                  = 0,
                VersionNumber                     = 1,
                MaxFP                             = 0,
                CurrentFP                         = 0,
                CurrentFPTick                     = 20,
                RespawnAreaResref                 = string.Empty,
                RespawnLocationX                  = 0.0f,
                RespawnLocationY                  = 0.0f,
                RespawnLocationZ                  = 0.0f,
                RespawnLocationOrientation        = 0.0f,
                DateSanctuaryEnds                 = DateTime.UtcNow + TimeSpan.FromDays(3),
                IsSanctuaryOverrideEnabled        = false,
                STRBase                           = NWNXCreature.GetRawAbilityScore(player, AbilityType.Strength),
                DEXBase                           = NWNXCreature.GetRawAbilityScore(player, AbilityType.Dexterity),
                CONBase                           = NWNXCreature.GetRawAbilityScore(player, AbilityType.Constitution),
                INTBase                           = NWNXCreature.GetRawAbilityScore(player, AbilityType.Intelligence),
                WISBase                           = NWNXCreature.GetRawAbilityScore(player, AbilityType.Wisdom),
                CHABase                           = NWNXCreature.GetRawAbilityScore(player, AbilityType.Charisma),
                TotalSPAcquired                   = 0,
                DisplayHelmet                     = true,
                PrimaryResidencePCBaseStructureID = null,
                PrimaryResidencePCBaseID          = null,
                AssociationID                     = (int)assType,
                DisplayHolonet                    = true,
                DisplayDiscord                    = true,
                XPBonus                           = 0,
                LeaseRate                         = 0,
                ModeDualPistol                    = false
            };

            return(entity);
        }
Example #4
0
        private static Player CreateDBPCEntity(NWPlayer player)
        {
            CustomRaceType  race = (CustomRaceType)player.RacialType;
            AssociationType assType;
            int             goodEvil = _.GetAlignmentGoodEvil(player);
            int             lawChaos = _.GetAlignmentLawChaos(player);

            // Jedi Order -- Mandalorian -- Sith Empire
            if (goodEvil == ALIGNMENT_GOOD && lawChaos == ALIGNMENT_LAWFUL)
            {
                assType = AssociationType.JediOrder;
            }
            else if (goodEvil == ALIGNMENT_GOOD && lawChaos == ALIGNMENT_NEUTRAL)
            {
                assType = AssociationType.Mandalorian;
            }
            else if (goodEvil == ALIGNMENT_GOOD && lawChaos == ALIGNMENT_CHAOTIC)
            {
                assType = AssociationType.SithEmpire;
            }

            // Smugglers -- Unaligned -- Hutt Cartel
            else if (goodEvil == ALIGNMENT_NEUTRAL && lawChaos == ALIGNMENT_LAWFUL)
            {
                assType = AssociationType.Smugglers;
            }
            else if (goodEvil == ALIGNMENT_NEUTRAL && lawChaos == ALIGNMENT_NEUTRAL)
            {
                assType = AssociationType.Unaligned;
            }
            else if (goodEvil == ALIGNMENT_NEUTRAL && lawChaos == ALIGNMENT_CHAOTIC)
            {
                assType = AssociationType.HuttCartel;
            }

            // Republic -- Czerka -- Sith Order
            else if (goodEvil == ALIGNMENT_EVIL && lawChaos == ALIGNMENT_LAWFUL)
            {
                assType = AssociationType.Republic;
            }
            else if (goodEvil == ALIGNMENT_EVIL && lawChaos == ALIGNMENT_NEUTRAL)
            {
                assType = AssociationType.Czerka;
            }
            else if (goodEvil == ALIGNMENT_EVIL && lawChaos == ALIGNMENT_CHAOTIC)
            {
                assType = AssociationType.SithOrder;
            }
            else
            {
                throw new Exception("Association type not found. GoodEvil = " + goodEvil + ", LawChaos = " + lawChaos);
            }

            int sp = 5;

            if (race == CustomRaceType.Human)
            {
                sp++;
            }

            Player entity = new Player
            {
                ID                                = player.GlobalID,
                CharacterName                     = player.Name,
                HitPoints                         = player.CurrentHP,
                LocationAreaResref                = _.GetResRef(_.GetAreaFromLocation(player.Location)),
                LocationX                         = player.Position.m_X,
                LocationY                         = player.Position.m_Y,
                LocationZ                         = player.Position.m_Z,
                LocationOrientation               = player.Facing,
                CreateTimestamp                   = DateTime.UtcNow,
                UnallocatedSP                     = sp,
                HPRegenerationAmount              = 1,
                RegenerationTick                  = 20,
                RegenerationRate                  = 0,
                VersionNumber                     = 1,
                MaxFP                             = 0,
                CurrentFP                         = 0,
                CurrentFPTick                     = 20,
                RespawnAreaResref                 = string.Empty,
                RespawnLocationX                  = 0.0f,
                RespawnLocationY                  = 0.0f,
                RespawnLocationZ                  = 0.0f,
                RespawnLocationOrientation        = 0.0f,
                DateSanctuaryEnds                 = DateTime.UtcNow + TimeSpan.FromDays(3),
                IsSanctuaryOverrideEnabled        = false,
                STRBase                           = NWNXCreature.GetRawAbilityScore(player, ABILITY_STRENGTH),
                DEXBase                           = NWNXCreature.GetRawAbilityScore(player, ABILITY_DEXTERITY),
                CONBase                           = NWNXCreature.GetRawAbilityScore(player, ABILITY_CONSTITUTION),
                INTBase                           = NWNXCreature.GetRawAbilityScore(player, ABILITY_INTELLIGENCE),
                WISBase                           = NWNXCreature.GetRawAbilityScore(player, ABILITY_WISDOM),
                CHABase                           = NWNXCreature.GetRawAbilityScore(player, ABILITY_CHARISMA),
                TotalSPAcquired                   = 0,
                DisplayHelmet                     = true,
                PrimaryResidencePCBaseStructureID = null,
                PrimaryResidencePCBaseID          = null,
                AssociationID                     = (int)assType,
                DisplayHolonet                    = true,
                DisplayDiscord                    = true,
                XPBonus                           = 0,
                LeaseRate                         = 0
            };

            return(entity);
        }