public static void Main() { NWGameObject player = GetLastUsedBy(); if (!GetIsPlayer(player)) { return; } var position = GetPosition(player); var orientation = GetFacing(player); var area = GetArea(player); var areaResref = GetResRef(area); var playerID = GetGlobalID(player); var entity = PlayerRepo.Get(playerID); entity.RespawnAreaResref = areaResref; entity.RespawnLocationOrientation = orientation; entity.RespawnLocationX = position.X; entity.RespawnLocationY = position.Y; entity.RespawnLocationZ = position.Z; PlayerRepo.Set(entity); SendMessageToPC(player, "Your home point has been set to this location."); }
/// <summary> /// Deletes a player's character. Player must submit the command twice within 30 seconds. /// </summary> /// <param name="user"></param> /// <param name="target"></param> /// <param name="targetLocation"></param> /// <param name="args"></param> public void DoAction(NWGameObject user, NWGameObject target, Location targetLocation, params string[] args) { string lastSubmission = GetLocalString(user, "DELETE_CHARACTER_LAST_SUBMISSION"); bool isFirstSubmission = true; // Check for the last submission, if any. if (!string.IsNullOrWhiteSpace(lastSubmission)) { // Found one, parse it. DateTime dateTime = DateTime.Parse(lastSubmission); if (DateTime.UtcNow <= dateTime.AddSeconds(30)) { // Player submitted a second request within 30 seconds of the last one. // This is a confirmation they want to delete. isFirstSubmission = false; } } // Player hasn't submitted or time has elapsed if (isFirstSubmission) { SetLocalString(user, "DELETE_CHARACTER_LAST_SUBMISSION", DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)); FloatingTextStringOnCreature(user, "Please confirm your deletion by entering another \"/delete <CD Key>\" command within 30 seconds."); } else { var playerID = GetGlobalID(user); var entity = PlayerRepo.Get(playerID); entity.IsDeleted = true; PlayerRepo.Set(entity); BootPC(user, "Your character has been deleted."); NWNXAdmin.DeletePlayerCharacter(user, true); } }
public static void Main() { var data = Script.GetScriptData <JobChanged>(); var newJob = data.NewJob; var player = data.Player; var playerID = GetGlobalID(player); var playerEntity = PlayerRepo.Get(playerID); var jobEntity = JobRepo.Get(playerID, newJob); playerEntity.CurrentJob = newJob; NWNXCreature.SetClassByPosition(player, ClassPosition.First, newJob); NWNXCreature.SetLevelByPosition(player, ClassPosition.First, jobEntity.Level); SetXP(player, jobEntity.XP); PlayerRepo.Set(playerEntity); }
/// <summary> /// Handles the migration of player characters. /// </summary> public static void Main() { var player = _.GetEnteringObject(); if (!_.GetIsPlayer(player)) { return; } // Player doesn't have an ID assigned. Generate one and set it on them. string tag = _.GetTag(player); if (string.IsNullOrWhiteSpace(tag)) { var id = Guid.NewGuid(); _.SetTag(player, id.ToString()); } var playerID = _.GetGlobalID(player); var pcEntity = PlayerRepo.Get(playerID); // Iterate over the registered migrations. If player is below the migration version, that migration will be executed upon them. // If player is at or above that version, nothing will happen and they will move to the next migration in the list. foreach (var migration in _registeredMigrations) { if (pcEntity.Version < migration.Version) { try { migration.RunMigration(player); // The migration might have modified the entity. Pull back a fresh copy and update the version. pcEntity = PlayerRepo.Get(playerID); pcEntity.Version = migration.Version; PlayerRepo.Set(pcEntity); } catch (Exception ex) { throw new Exception($"Failed to apply migration {migration.GetType().FullName}", ex); } } } }
public void RunMigration(NWGameObject player) { var playerID = GetGlobalID(player); var entity = PlayerRepo.Get(playerID); var job = GetClassByPosition(ClassPosition.First, player); entity.Name = GetName(player); entity.CurrentJob = job; PlayerRepo.Set(entity); InitializeJobs(playerID); InitializeSkills(player); InitializeSavingThrows(player); RemoveNWNSpells(player); // Treat this initialization as a job change and a level-up. Publish.CustomEvent(player, JobEventPrefix.OnJobChanged, new JobChanged(player, job, job)); Publish.CustomEvent(player, JobEventPrefix.OnLeveledUp, new LeveledUp(player)); }
protected static void Recalculate(NWGameObject player) { var playerID = GetGlobalID(player); var playerEntity = PlayerRepo.Get(playerID); var @class = GetClassByPosition(ClassPosition.First, player); var level = GetLevelByPosition(ClassPosition.First, player); var jobDefinition = JobRegistry.Get(@class); // Retrieve the rating chart for the stat, then retrieve the value for that stat at this player's level. var hp = RatingRegistry.Get(jobDefinition.HPRating).Get(RatingStat.HP, level); var mp = RatingRegistry.Get(jobDefinition.MPRating).Get(RatingStat.MP, level); var ac = RatingRegistry.Get(jobDefinition.ACRating).Get(RatingStat.AC, level); var bab = RatingRegistry.Get(jobDefinition.BABRating).Get(RatingStat.BAB, level); var str = RatingRegistry.Get(jobDefinition.STRRating).Get(RatingStat.STR, level); var dex = RatingRegistry.Get(jobDefinition.DEXRating).Get(RatingStat.DEX, level); var con = RatingRegistry.Get(jobDefinition.CONRating).Get(RatingStat.CON, level); var wis = RatingRegistry.Get(jobDefinition.WISRating).Get(RatingStat.WIS, level); var @int = RatingRegistry.Get(jobDefinition.INTRating).Get(RatingStat.INT, level); var cha = RatingRegistry.Get(jobDefinition.CHARating).Get(RatingStat.CHA, level); // Now apply the changes to the player. ApplyHP(player, hp); playerEntity.MaxHP = hp; playerEntity.MaxMP = mp; playerEntity.HP = hp; playerEntity.MP = mp; NWNXCreature.SetBaseAC(player, ac); NWNXCreature.SetBaseAttackBonus(player, bab); NWNXCreature.SetRawAbilityScore(player, Ability.Strength, str); NWNXCreature.SetRawAbilityScore(player, Ability.Dexterity, dex); NWNXCreature.SetRawAbilityScore(player, Ability.Constitution, con); NWNXCreature.SetRawAbilityScore(player, Ability.Wisdom, wis); NWNXCreature.SetRawAbilityScore(player, Ability.Intelligence, @int); NWNXCreature.SetRawAbilityScore(player, Ability.Charisma, cha); PlayerRepo.Set(playerEntity); DelayCommand(1.0f, () => NWNXPlayer.UpdateCharacterSheet(player)); }
public static void Run(NWGameObject player) { if (!_.GetIsPlayer(player)) { return; } var area = _.GetArea(player); var position = _.GetPosition(player); var orientation = _.GetFacing(player); var playerID = _.GetGlobalID(player); var entity = PlayerRepo.Get(playerID); entity.LocationX = position.X; entity.LocationY = position.Y; entity.LocationZ = position.Z; entity.LocationOrientation = orientation; entity.LocationAreaResref = _.GetResRef(area); PlayerRepo.Set(entity); }
/// <summary> /// Applies all changes in stats to the database or creature local variables. /// </summary> /// <param name="stats">The current user stats.</param> private static void ApplyUserStatChanges(UserStats stats) { var delay = stats.AbilityDefinition.CooldownTime(stats.User); var dateUnlocks = DateTime.UtcNow.AddSeconds(delay); if (GetIsPlayer(stats.User)) { var playerID = GetGlobalID(stats.User); var player = PlayerRepo.Get(playerID); var cooldown = CooldownRepo.Get(playerID, stats.Feat); player.MP = stats.MP; cooldown.DateUnlocked = dateUnlocks; PlayerRepo.Set(player); CooldownRepo.Set(playerID, cooldown); } else if (GetIsNPC(stats.User)) { SetLocalInt(stats.User, "MP_CURRENT", stats.MP); SetLocalString(stats.User, $"ABILITY_COOLDOWN_{stats.Feat}", dateUnlocks.ToString("yyyy-MM-dd hh:mm:ss", CultureInfo.InvariantCulture)); } }