/// <summary> /// Registers events for areas of effect /// </summary> private static void RegisterAreaOfEffectEvents(NWGameObject aoe) { SetEventScript(aoe, EventScriptAreaOfEffect.OnHeartbeat, string.Empty); SetEventScript(aoe, EventScriptAreaOfEffect.OnUserDefinedEvent, string.Empty); SetEventScript(aoe, EventScriptAreaOfEffect.OnObjectEnter, string.Empty); SetEventScript(aoe, EventScriptAreaOfEffect.OnObjectExit, string.Empty); if (LocalVariableTool.FindByPrefix(aoe, AreaOfEffectPrefix.OnHeartbeat).Any()) { SetEventScript(aoe, EventScriptAreaOfEffect.OnHeartbeat, "aoe_on_hb"); } if (LocalVariableTool.FindByPrefix(aoe, AreaOfEffectPrefix.OnUserDefined).Any()) { SetEventScript(aoe, EventScriptAreaOfEffect.OnUserDefinedEvent, "aoe_on_userdef"); } if (LocalVariableTool.FindByPrefix(aoe, AreaOfEffectPrefix.OnEnter).Any()) { SetEventScript(aoe, EventScriptAreaOfEffect.OnObjectEnter, "aoe_on_enter"); } if (LocalVariableTool.FindByPrefix(aoe, AreaOfEffectPrefix.OnExit).Any()) { SetEventScript(aoe, EventScriptAreaOfEffect.OnObjectExit, "aoe_on_exit"); } }
/// <summary> /// Registers events for encounters /// </summary> private static void RegisterEncounterEvents(NWGameObject encounter) { SetEventScript(encounter, EventScriptEncounter.OnObjectEnter, string.Empty); SetEventScript(encounter, EventScriptEncounter.OnObjectExit, string.Empty); SetEventScript(encounter, EventScriptEncounter.OnHeartbeat, string.Empty); SetEventScript(encounter, EventScriptEncounter.OnEncounterExhausted, string.Empty); SetEventScript(encounter, EventScriptEncounter.OnUserDefinedEvent, string.Empty); if (LocalVariableTool.FindByPrefix(encounter, EncounterPrefix.OnEnter).Any()) { SetEventScript(encounter, EventScriptEncounter.OnObjectEnter, "enc_on_enter"); } if (LocalVariableTool.FindByPrefix(encounter, EncounterPrefix.OnExit).Any()) { SetEventScript(encounter, EventScriptEncounter.OnObjectExit, "enc_on_exit"); } if (LocalVariableTool.FindByPrefix(encounter, EncounterPrefix.OnHeartbeat).Any()) { SetEventScript(encounter, EventScriptEncounter.OnHeartbeat, "enc_on_hb"); } if (LocalVariableTool.FindByPrefix(encounter, EncounterPrefix.OnExhausted).Any()) { SetEventScript(encounter, EventScriptEncounter.OnEncounterExhausted, "enc_on_exhaust"); } if (LocalVariableTool.FindByPrefix(encounter, EncounterPrefix.OnUserDefined).Any()) { SetEventScript(encounter, EventScriptEncounter.OnUserDefinedEvent, "enc_on_userdef"); } }
/// <summary> /// Registers the events of a specific object. /// </summary> /// <param name="obj">The objects whose scripts are being adjusted</param> private static void RegisterObjectEvent(NWGameObject obj) { var type = GetObjectType(obj); switch (type) { case ObjectType.Creature: RegisterCreatureEvents(obj); break; case ObjectType.Trigger: RegisterTriggerEvents(obj); break; case ObjectType.Door: RegisterDoorEvents(obj); break; case ObjectType.AreaOfEffect: RegisterAreaOfEffectEvents(obj); break; case ObjectType.Placeable: RegisterPlaceableEvents(obj); break; case ObjectType.Store: RegisterStoreEvents(obj); break; case ObjectType.Encounter: RegisterEncounterEvents(obj); break; } }
/// <summary> /// Registers the events of an area. /// </summary> /// <param name="area"></param> private static void RegisterAreaEvent(NWGameObject area) { SetEventScript(area, EventScriptArea.OnEnter, "area_on_enter"); SetEventScript(area, EventScriptArea.OnExit, "area_on_exit"); SetEventScript(area, EventScriptArea.OnHeartbeat, "area_on_hb"); SetEventScript(area, EventScriptArea.OnUserDefinedEvent, "area_on_user"); }
/// <summary> /// Assigns registered scripts to a specific area. /// These scripts may come from various sources, such as Startup scripts in other projects. /// </summary> /// <param name="area">The area to assign scripts to.</param> internal static void AssignScripts(NWGameObject area) { foreach (var onEnter in _onEnterScripts) { var varName = AreaPrefix.OnEnter + LocalVariableTool.GetOpenScriptID(area, AreaPrefix.OnEnter); SetLocalString(area, varName, onEnter); } foreach (var onExit in _onExitScripts) { var varName = AreaPrefix.OnExit + LocalVariableTool.GetOpenScriptID(area, AreaPrefix.OnExit); SetLocalString(area, varName, onExit); } foreach (var onHeartbeat in _onHeartbeatScripts) { var varName = AreaPrefix.OnHeartbeat + LocalVariableTool.GetOpenScriptID(area, AreaPrefix.OnHeartbeat); SetLocalString(area, varName, onHeartbeat); } foreach (var onUserDefined in _onUserDefinedScripts) { var varName = AreaPrefix.OnUserDefined + LocalVariableTool.GetOpenScriptID(area, AreaPrefix.OnUserDefined); SetLocalString(area, varName, onUserDefined); } }
private static void SetMapPin(NWGameObject oPC, string text, float positionX, float positionY, NWGameObject area) { int numberOfMapPins = GetNumberOfMapPins(oPC); int storeAtIndex = -1; for (int index = 0; index < numberOfMapPins; index++) { var mapPin = GetMapPinDetails(oPC, index); if (string.IsNullOrWhiteSpace(mapPin.Text)) { storeAtIndex = index; break; } } if (storeAtIndex == -1) { numberOfMapPins++; storeAtIndex = numberOfMapPins - 1; } storeAtIndex++; SetLocalString(oPC, "NW_MAP_PIN_NTRY_" + storeAtIndex, text); SetLocalFloat(oPC, "NW_MAP_PIN_XPOS_" + storeAtIndex, positionX); SetLocalFloat(oPC, "NW_MAP_PIN_YPOS_" + storeAtIndex, positionY); SetLocalObject(oPC, "NW_MAP_PIN_AREA_" + storeAtIndex, area); SetLocalInt(oPC, "NW_TOTAL_MAP_PINS", numberOfMapPins); }
/// <summary> /// Writes an audit entry to the Death audit group. /// </summary> /// <param name="player">The player who respawned</param> /// <param name="xpLost">The amount of XP lost</param> private static void WriteAudit(NWGameObject player, int xpLost) { var name = GetName(player); var log = $"RESPAWN - {name} - {xpLost} XP lost"; Audit.Write(AuditGroup.Death, log); }
/// <summary> /// Get total effect bonus /// </summary> /// <param name="creature"></param> /// <param name="bonusType"></param> /// <param name="target"></param> /// <param name="isElemental"></param> /// <param name="isForceMax"></param> /// <param name="savetype"></param> /// <param name="saveSpecificType"></param> /// <param name="skill"></param> /// <param name="abilityScore"></param> /// <param name="isOffhand"></param> /// <returns></returns> public static int GetTotalEffectBonus( NWCreature creature, CreatureBonusType bonusType = CreatureBonusType.Attack, NWObject target = null, int isElemental = 0, int isForceMax = 0, int savetype = -1, int saveSpecificType = -1, int skill = -1, int abilityScore = -1, int isOffhand = FALSE) { if (target == null) { target = new NWGameObject(); } string sFunc = "GetTotalEffectBonus"; NWNX_PushArgumentInt(NWNX_Creature, sFunc, isOffhand); NWNX_PushArgumentInt(NWNX_Creature, sFunc, abilityScore); NWNX_PushArgumentInt(NWNX_Creature, sFunc, skill); NWNX_PushArgumentInt(NWNX_Creature, sFunc, saveSpecificType); NWNX_PushArgumentInt(NWNX_Creature, sFunc, savetype); NWNX_PushArgumentInt(NWNX_Creature, sFunc, isForceMax); NWNX_PushArgumentInt(NWNX_Creature, sFunc, isElemental); NWNX_PushArgumentObject(NWNX_Creature, sFunc, target); NWNX_PushArgumentInt(NWNX_Creature, sFunc, (int)bonusType); NWNX_PushArgumentObject(NWNX_Creature, sFunc, creature); NWNX_CallFunction(NWNX_Creature, sFunc); return(NWNX_GetReturnValueInt(NWNX_Creature, sFunc)); }
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."); }
public static void Main() { NWGameObject player = GetExitingObject(); if (!GetIsPlayer(player)) { return; } var playerID = GetGlobalID(player); var area = GetArea(player); if (!GetIsObjectValid(area)) { area = NWGameObject.OBJECT_SELF; } var areaResref = GetResRef(area); var progress = NWNXPlayer.GetAreaExplorationState(player, area); var progression = MapProgressionRepo.Get(playerID, areaResref); progression.Progression = progress; MapProgressionRepo.Set(playerID, progression); }
/// <summary> /// Gives all rewards for this quest to the player. /// </summary> /// <param name="player">The player receiving the rewards.</param> internal void GiveRewards(NWGameObject player) { foreach (var reward in Rewards) { reward.GiveReward(player); } }
/// <summary> /// Returns true if player can complete this quest. Returns false otherwise. /// </summary> /// <param name="player">The player to check</param> /// <returns>true if player can complete, false otherwise</returns> private bool CanComplete(NWGameObject player) { // Has the player even accepted this quest? var playerID = GetGlobalID(player); var pcStatus = QuestProgressRepo.Get(playerID, QuestID); if (pcStatus == null) { return(false); } // Is the player on the final state of this quest? if (pcStatus.CurrentState != GetStates().Count()) { return(false); } var state = GetState(pcStatus.CurrentState); // Are all objectives complete? foreach (var objective in state.GetObjectives()) { if (!objective.IsComplete(player, QuestID)) { return(false); } } // Met all requirements. We can complete this quest. return(true); }
private void InitializeSkills(NWGameObject player) { for (int iCurSkill = 1; iCurSkill <= 27; iCurSkill++) { NWNXCreature.SetSkillRank(player, iCurSkill - 1, 0); } }
private static bool CanHandleChat(NWGameObject sender, string message) { bool validTarget = GetIsPlayer(sender) || GetIsDungeonMaster(sender); bool validMessage = message.Length >= 2 && message[0] == '/' && message[1] != '/'; return(validTarget && validMessage); }
public void DoAction(NWGameObject user, NWGameObject target, Location targetLocation, params string[] args) { var amount = _.GetMaxHitPoints(target) + 11; var damage = _.EffectDamage(amount); _.ApplyEffectToObject(DurationType.Instant, damage, target); }
/// <summary> /// Runs a C# script's Main() method. /// "script" should be specified with the project name. /// Example: 'Death.OnPlayerDeath' is valid. Just 'OnPlayerDeath' is not. /// Exclude the root namespace when specifying script. /// </summary> /// <param name="script">Name of the script's namespace</param> /// <param name="caller">The caller of this script</param> /// <param name="data">Arbitrary data to pass to the script.</param> public static void Run <T>(NWGameObject caller, string script, T data) { if (!_cachedScripts.ContainsKey(script)) { var settings = ApplicationSettings.Get(); var scriptNamespace = settings.NamespaceRoot + "." + script; var type = Type.GetType(scriptNamespace); if (type == null) { // Check the loaded assemblies for the type. type = AssemblyLoader.FindType(scriptNamespace); if (type == null) { Log.Warning($"Could not locate script: {scriptNamespace} from caller {GetName(caller)}"); return; } } var method = type.GetMethod("Main", BindingFlags.Static | BindingFlags.Public); if (method == null) { Log.Warning("Could not locate method 'Main' on script: " + script); return; } _cachedScripts[script] = method; } _cachedScripts[script].Invoke(null, data == null ? null : new object[] { data }); }
public static void Apply(NWGameObject player) { var playerID = _.GetGlobalID(player); var jobType = _.GetClassByPosition(ClassPosition.First, player); var jobDefinition = JobRegistry.Get(jobType); var job = JobRepo.Get(playerID, jobType); var abilityList = jobDefinition.GetAbilityListByLevel(job.Level); var allFeats = new List <Feat>(DefaultFeats); allFeats.AddRange(abilityList); // Remove any feats the player shouldn't have. var featCount = NWNXCreature.GetFeatCount(player); for (int x = featCount; x >= 0; x--) { var feat = NWNXCreature.GetFeatByIndex(player, x - 1); if (!allFeats.Contains(feat)) { NWNXCreature.RemoveFeat(player, feat); } } // Add any feats the player needs. foreach (var feat in allFeats) { if (_.GetHasFeat(feat, player)) { continue; } NWNXCreature.AddFeatByLevel(player, feat, 1); } }
/// <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 void DoAction(NWGameObject user, NWGameObject target, Location targetLocation, params string[] args) { string command = args[0].ToLower(); switch (command) { case "help": DoHelp(user); break; case "d2": case "d4": case "d6": case "d8": case "d10": case "d20": case "d100": int sides = Convert.ToInt32(command.Substring(1)); int count = 1; if (args.Length > 1) { if (!int.TryParse(args[1], out count)) { count = 1; } } DoDiceRoll(user, sides, count); break; default: SendMessageToPC(user, _genericError); return; } }
/// <summary> /// Signals an event. This will dispatch a notification to all subscribed handlers. /// Returns TRUE if anyone was subscribed to the event, FALSE otherwise. /// </summary> /// <param name="evt"></param> /// <param name="target"></param> /// <returns></returns> public static int SignalEvent(string evt, NWGameObject target) { NWNXCore.NWNX_PushArgumentObject("NWNX_Events", "SIGNAL_EVENT", target); NWNXCore.NWNX_PushArgumentString("NWNX_Events", "SIGNAL_EVENT", evt); NWNXCore.NWNX_CallFunction("NWNX_Events", "SIGNAL_EVENT"); return(NWNXCore.NWNX_GetReturnValueInt("NWNX_Events", "SIGNAL_EVENT")); }
public static void Main() { NWGameObject container = NWGameObject.OBJECT_SELF; _.DestroyAllInventoryItems(container); _.SetLocked(container, false); }
public void DoAction(NWGameObject user, NWGameObject target, Location targetLocation, params string[] args) { DateTime now = DateTime.UtcNow; string nowText = now.ToString("yyyy-MM-dd hh:mm:ss"); _.SendMessageToPC(user, "Current Server Date: " + nowText); }
/// <summary> /// Starts displaying a timing bar. /// Will run a script at the end of the timing bar, if specified. /// </summary> /// <param name="creature">The creature who will see the timing bar.</param> /// <param name="seconds">How long the timing bar should come on screen.</param> /// <param name="script">The script to run at the end of the timing bar.</param> public static void StartGuiTimingBar(NWGameObject creature, float seconds, string script) { // only one timing bar at a time! if (_.GetLocalInt(creature, "NWNX_PLAYER_GUI_TIMING_ACTIVE") == 1) { return; } string sFunc = "StartGuiTimingBar"; NWNXCore.NWNX_PushArgumentFloat(NWNX_Player, sFunc, seconds); NWNXCore.NWNX_PushArgumentObject(NWNX_Player, sFunc, creature); NWNXCore.NWNX_CallFunction(NWNX_Player, sFunc); int id = _.GetLocalInt(creature, "NWNX_PLAYER_GUI_TIMING_ID") + 1; _.SetLocalInt(creature, "NWNX_PLAYER_GUI_TIMING_ACTIVE", id); _.SetLocalInt(creature, "NWNX_PLAYER_GUI_TIMING_ID", id); _.DelayCommand(seconds, () => { StopGuiTimingBar(creature, script, -1); }); }
/// <summary> /// Stops displaying a timing bar. /// Runs a script if specified. /// </summary> /// <param name="creature">The creature's timing bar to stop.</param> /// <param name="script">The script to run once ended.</param> /// <param name="id">ID number of this timing bar.</param> public static void StopGuiTimingBar(NWGameObject creature, string script, int id) { int activeId = _.GetLocalInt(creature, "NWNX_PLAYER_GUI_TIMING_ACTIVE"); // Either the timing event was never started, or it already finished. if (activeId == 0) { return; } // If id != -1, we ended up here through DelayCommand. Make sure it's for the right ID if (id != -1 && id != activeId) { return; } _.DeleteLocalInt(creature, "NWNX_PLAYER_GUI_TIMING_ACTIVE"); string sFunc = "StopGuiTimingBar"; NWNXCore.NWNX_PushArgumentObject(NWNX_Player, sFunc, creature); NWNXCore.NWNX_CallFunction(NWNX_Player, sFunc); if (!string.IsNullOrWhiteSpace(script)) { _.ExecuteScript(script, creature); } }
/// <summary> /// Gets the player's quickbar slot info /// </summary> /// <param name="player"></param> /// <param name="slot"></param> /// <returns></returns> public static QuickBarSlot GetQuickBarSlot(NWGameObject player, int slot) { string sFunc = "GetQuickBarSlot"; QuickBarSlot qbs = new QuickBarSlot(); NWNXCore.NWNX_PushArgumentInt(NWNX_Player, sFunc, slot); NWNXCore.NWNX_PushArgumentObject(NWNX_Player, sFunc, player); NWNXCore.NWNX_CallFunction(NWNX_Player, sFunc); qbs.Associate = (NWNXCore.NWNX_GetReturnValueObject(NWNX_Player, sFunc)); qbs.AssociateType = NWNXCore.NWNX_GetReturnValueInt(NWNX_Player, sFunc); qbs.DomainLevel = NWNXCore.NWNX_GetReturnValueInt(NWNX_Player, sFunc); qbs.MetaType = NWNXCore.NWNX_GetReturnValueInt(NWNX_Player, sFunc); qbs.INTParam1 = NWNXCore.NWNX_GetReturnValueInt(NWNX_Player, sFunc); qbs.ToolTip = NWNXCore.NWNX_GetReturnValueString(NWNX_Player, sFunc); qbs.CommandLine = NWNXCore.NWNX_GetReturnValueString(NWNX_Player, sFunc); qbs.CommandLabel = NWNXCore.NWNX_GetReturnValueString(NWNX_Player, sFunc); qbs.Resref = NWNXCore.NWNX_GetReturnValueString(NWNX_Player, sFunc); qbs.MultiClass = NWNXCore.NWNX_GetReturnValueInt(NWNX_Player, sFunc); qbs.ObjectType = (QuickBarSlotType)NWNXCore.NWNX_GetReturnValueInt(NWNX_Player, sFunc); qbs.SecondaryItem = (NWNXCore.NWNX_GetReturnValueObject(NWNX_Player, sFunc)); qbs.Item = (NWNXCore.NWNX_GetReturnValueObject(NWNX_Player, sFunc)); return(qbs); }
public bool MeetsPrerequisite(NWGameObject player) { var playerID = GetGlobalID(player); var quest = QuestProgressRepo.Get(playerID, _questID); return(quest.TimesCompleted > 0); }
public override void SetUp(NWGameObject player, PlayerDialog dialog) { DialogPage mainPage = new DialogPage( "Please select a reward." ); dialog.AddPage("MainPage", mainPage); }
/// <summary> /// // Refreshes the players character sheet /// Note: You may need to use DelayCommand if you're manipulating values /// through nwnx and forcing a UI refresh, 0.5s seemed to be fine /// </summary> /// <param name="player"></param> public static void UpdateCharacterSheet(NWGameObject player) { string sFunc = "UpdateCharacterSheet"; NWNXCore.NWNX_PushArgumentObject(NWNX_Player, sFunc, player); NWNXCore.NWNX_CallFunction(NWNX_Player, sFunc); }
/// <summary> /// Get the name of the .bic file associated with the player's character. /// </summary> /// <param name="player"></param> /// <returns></returns> public static string GetBicFileName(NWGameObject player) { string sFunc = "GetBicFileName"; NWNXCore.NWNX_PushArgumentObject(NWNX_Player, sFunc, player); NWNXCore.NWNX_CallFunction(NWNX_Player, sFunc); return(NWNXCore.NWNX_GetReturnValueString(NWNX_Player, sFunc)); }
/// <summary> /// Returns the X and Y position, in tiles, of the user. /// </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) { Vector position = GetPosition(user); int cellX = (int)(position.X / 10); int cellY = (int)(position.Y / 10); SendMessageToPC(user, $"Current Area Coordinates: ({cellX}, {cellY})"); }