/// <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 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"); } }
// For every loot table: // 1.) Look for a chance and attempt variable. Use defaults if not found. // 2.) Get the loot table from the cache. // 3.) Attempt to spawn an item if random checks are met. // Loot tables must be added as local variables on the creature. Prefix is LOOT_TABLE_ // Values are as follows: Name, Chance, Attempts public static void Main() { var creature = NWGameObject.OBJECT_SELF; var lootTableEntries = LocalVariableTool.FindByPrefix(creature, "LOOT_TABLE_"); foreach (var entry in lootTableEntries) { var data = entry.Split(','); string tableName = data[0].Trim(); int chance = 100; int attempts = 1; // Second argument: Chance to spawn if (data.Length > 1) { data[1] = data[1].Trim(); if (!int.TryParse(data[1], out chance)) { Log.Warning($"Loot Table '{entry}' on {GetName(creature)}, 'Chance' variable could not be processed. Must be an integer."); } } // Third argument: Attempts to pull from loot table if (data.Length > 2) { data[2] = data[2].Trim(); if (!int.TryParse(data[1], out attempts)) { Log.Warning($"Loot Table '{entry}' on {GetName(creature)}, 'Attempts' variable could not be processed. Must be an integer."); } } // Guards against bad data from builder. if (chance > 100) { chance = 100; } if (attempts <= 0) { attempts = 1; } var table = LootTableRegistry.Get(tableName); for (int x = 1; x <= attempts; x++) { if (Random.D100(1) > chance) { continue; } var item = table.GetRandomItem(); var quantity = Random.Next(item.MaxQuantity) + 1; CreateItemOnObject(item.Resref, creature, quantity); } } }
private static void LoadAreaScripts() { NWGameObject module = GetModule(); _onEnterScripts.AddRange(LocalVariableTool.FindByPrefix(module, $"AREA_{AreaPrefix.OnEnter}")); _onExitScripts.AddRange(LocalVariableTool.FindByPrefix(module, $"AREA_{AreaPrefix.OnExit}")); _onHeartbeatScripts.AddRange(LocalVariableTool.FindByPrefix(module, $"AREA_{AreaPrefix.OnHeartbeat}")); _onUserDefinedScripts.AddRange(LocalVariableTool.FindByPrefix(module, $"AREA_{AreaPrefix.OnUserDefined}")); }
/// <summary> /// Registers events for stores /// </summary> private static void RegisterStoreEvents(NWGameObject store) { SetEventScript(store, EventScriptStore.OnOpen, string.Empty); SetEventScript(store, EventScriptStore.OnClose, string.Empty); if (LocalVariableTool.FindByPrefix(store, StorePrefix.OnOpen).Any()) { SetEventScript(store, EventScriptStore.OnOpen, "store_on_open"); } if (LocalVariableTool.FindByPrefix(store, StorePrefix.OnClose).Any()) { SetEventScript(store, EventScriptStore.OnClose, "store_on_close"); } }
/// <summary> /// Registers events for triggers /// </summary> private static void RegisterTriggerEvents(NWGameObject trigger) { SetEventScript(trigger, EventScriptTrigger.OnHeartbeat, string.Empty); SetEventScript(trigger, EventScriptTrigger.OnClicked, string.Empty); SetEventScript(trigger, EventScriptTrigger.OnDisarmed, string.Empty); SetEventScript(trigger, EventScriptTrigger.OnObjectEnter, string.Empty); SetEventScript(trigger, EventScriptTrigger.OnObjectExit, string.Empty); SetEventScript(trigger, EventScriptTrigger.OnTrapTriggered, string.Empty); SetEventScript(trigger, EventScriptTrigger.OnUserDefinedEvent, string.Empty); if (LocalVariableTool.FindByPrefix(trigger, TriggerPrefix.OnHeartbeat).Any()) { SetEventScript(trigger, EventScriptTrigger.OnHeartbeat, "trig_on_hb"); } if (LocalVariableTool.FindByPrefix(trigger, TriggerPrefix.OnClicked).Any()) { SetEventScript(trigger, EventScriptTrigger.OnClicked, "trig_on_click"); } if (LocalVariableTool.FindByPrefix(trigger, TriggerPrefix.OnDisarmed).Any()) { SetEventScript(trigger, EventScriptTrigger.OnDisarmed, "trig_on_disarm"); } if (LocalVariableTool.FindByPrefix(trigger, TriggerPrefix.OnEnter).Any()) { SetEventScript(trigger, EventScriptTrigger.OnObjectEnter, "trig_on_enter"); } if (LocalVariableTool.FindByPrefix(trigger, TriggerPrefix.OnExit).Any()) { SetEventScript(trigger, EventScriptTrigger.OnObjectExit, "trig_on_exit"); } if (LocalVariableTool.FindByPrefix(trigger, TriggerPrefix.OnTriggerTrap).Any()) { SetEventScript(trigger, EventScriptTrigger.OnTrapTriggered, "trig_on_trap"); } if (LocalVariableTool.FindByPrefix(trigger, TriggerPrefix.OnUserDefined).Any()) { SetEventScript(trigger, EventScriptTrigger.OnUserDefinedEvent, "trig_on_userdef"); } }
/// <summary> /// Runs all scripts matching a given prefix, in the order they are found. /// </summary> /// <param name="caller">The object whose scripts we're checking</param> /// <param name="scriptPrefix">The prefix to look for.</param> /// <param name="scriptRegistrationObject">If the local variables are stored on a different object than the caller, you can use this argument to dictate where to look for the local variables</param> internal static void RunScriptEvents(NWGameObject caller, string scriptPrefix, NWGameObject scriptRegistrationObject = null) { if (scriptRegistrationObject == null) { scriptRegistrationObject = caller; } var scripts = LocalVariableTool.FindByPrefix(scriptRegistrationObject, scriptPrefix); foreach (var script in scripts) { try { Run(caller, script); } catch (Exception ex) { Audit.Write(AuditGroup.Error, ex.ToMessageAndCompleteStacktrace()); } } }
/// <summary> /// Registers events for placeables /// </summary> private static void RegisterPlaceableEvents(NWGameObject placeable) { SetEventScript(placeable, EventScriptPlaceable.OnMeleeAttacked, string.Empty); SetEventScript(placeable, EventScriptPlaceable.OnLeftClick, string.Empty); SetEventScript(placeable, EventScriptPlaceable.OnClosed, string.Empty); SetEventScript(placeable, EventScriptPlaceable.OnDialogue, string.Empty); SetEventScript(placeable, EventScriptPlaceable.OnDamaged, string.Empty); SetEventScript(placeable, EventScriptPlaceable.OnDeath, string.Empty); SetEventScript(placeable, EventScriptPlaceable.OnDisarm, string.Empty); SetEventScript(placeable, EventScriptPlaceable.OnInventoryDisturbed, string.Empty); SetEventScript(placeable, EventScriptPlaceable.OnHeartbeat, string.Empty); SetEventScript(placeable, EventScriptPlaceable.OnLock, string.Empty); SetEventScript(placeable, EventScriptPlaceable.OnOpen, string.Empty); SetEventScript(placeable, EventScriptPlaceable.OnSpellCastAt, string.Empty); SetEventScript(placeable, EventScriptPlaceable.OnTrapTriggered, string.Empty); SetEventScript(placeable, EventScriptPlaceable.OnUnlock, string.Empty); SetEventScript(placeable, EventScriptPlaceable.OnUsed, string.Empty); SetEventScript(placeable, EventScriptPlaceable.OnUserDefinedEvent, string.Empty); if (LocalVariableTool.FindByPrefix(placeable, PlaceablePrefix.OnAttacked).Any()) { SetEventScript(placeable, EventScriptPlaceable.OnMeleeAttacked, "plc_on_attack"); } if (LocalVariableTool.FindByPrefix(placeable, PlaceablePrefix.OnClicked).Any()) { SetEventScript(placeable, EventScriptPlaceable.OnLeftClick, "plc_on_click"); } if (LocalVariableTool.FindByPrefix(placeable, PlaceablePrefix.OnClosed).Any()) { SetEventScript(placeable, EventScriptPlaceable.OnClosed, "plc_on_close"); } if (LocalVariableTool.FindByPrefix(placeable, PlaceablePrefix.OnConversation).Any()) { SetEventScript(placeable, EventScriptPlaceable.OnDialogue, "plc_on_convo"); } if (LocalVariableTool.FindByPrefix(placeable, PlaceablePrefix.OnDamaged).Any()) { SetEventScript(placeable, EventScriptPlaceable.OnDamaged, "plc_on_damage"); } if (LocalVariableTool.FindByPrefix(placeable, PlaceablePrefix.OnDeath).Any()) { SetEventScript(placeable, EventScriptPlaceable.OnDeath, "plc_on_death"); } if (LocalVariableTool.FindByPrefix(placeable, PlaceablePrefix.OnDisarmed).Any()) { SetEventScript(placeable, EventScriptPlaceable.OnDisarm, "plc_on_disarm"); } if (LocalVariableTool.FindByPrefix(placeable, PlaceablePrefix.OnDisturbed).Any()) { SetEventScript(placeable, EventScriptPlaceable.OnInventoryDisturbed, "plc_on_disturb"); } if (LocalVariableTool.FindByPrefix(placeable, PlaceablePrefix.OnHeartbeat).Any()) { SetEventScript(placeable, EventScriptPlaceable.OnHeartbeat, "plc_on_hb"); } if (LocalVariableTool.FindByPrefix(placeable, PlaceablePrefix.OnLocked).Any()) { SetEventScript(placeable, EventScriptPlaceable.OnLock, "plc_on_lock"); } if (LocalVariableTool.FindByPrefix(placeable, PlaceablePrefix.OnOpened).Any()) { SetEventScript(placeable, EventScriptPlaceable.OnOpen, "plc_on_open"); } if (LocalVariableTool.FindByPrefix(placeable, PlaceablePrefix.OnSpellCastAt).Any()) { SetEventScript(placeable, EventScriptPlaceable.OnSpellCastAt, "plc_on_splcast"); } if (LocalVariableTool.FindByPrefix(placeable, PlaceablePrefix.OnTriggerTrap).Any()) { SetEventScript(placeable, EventScriptPlaceable.OnTrapTriggered, "plc_on_trap"); } if (LocalVariableTool.FindByPrefix(placeable, PlaceablePrefix.OnUnlocked).Any()) { SetEventScript(placeable, EventScriptPlaceable.OnUnlock, "plc_on_unlock"); } if (LocalVariableTool.FindByPrefix(placeable, PlaceablePrefix.OnUsed).Any()) { SetEventScript(placeable, EventScriptPlaceable.OnUsed, "plc_on_used"); } if (LocalVariableTool.FindByPrefix(placeable, PlaceablePrefix.OnUserDefined).Any()) { SetEventScript(placeable, EventScriptPlaceable.OnUserDefinedEvent, "plc_on_userdef"); } }
/// <summary> /// Registers events for doors /// </summary> private static void RegisterDoorEvents(NWGameObject door) { SetEventScript(door, EventScriptDoor.OnMeleeAttacked, string.Empty); SetEventScript(door, EventScriptDoor.OnClicked, string.Empty); SetEventScript(door, EventScriptDoor.OnClose, string.Empty); SetEventScript(door, EventScriptDoor.OnDialogue, string.Empty); SetEventScript(door, EventScriptDoor.OnDamage, string.Empty); SetEventScript(door, EventScriptDoor.OnDeath, string.Empty); SetEventScript(door, EventScriptDoor.OnDisarm, string.Empty); SetEventScript(door, EventScriptDoor.OnFailToOpen, string.Empty); SetEventScript(door, EventScriptDoor.OnHeartbeat, string.Empty); SetEventScript(door, EventScriptDoor.OnLock, string.Empty); SetEventScript(door, EventScriptDoor.OnOpen, string.Empty); SetEventScript(door, EventScriptDoor.OnSpellCastAt, string.Empty); SetEventScript(door, EventScriptDoor.OnTrapTriggered, string.Empty); SetEventScript(door, EventScriptDoor.OnUnlock, string.Empty); SetEventScript(door, EventScriptDoor.OnUserDefined, string.Empty); if (LocalVariableTool.FindByPrefix(door, DoorPrefix.OnAttacked).Any()) { SetEventScript(door, EventScriptDoor.OnMeleeAttacked, "door_on_attacked"); } if (LocalVariableTool.FindByPrefix(door, DoorPrefix.OnClicked).Any()) { SetEventScript(door, EventScriptDoor.OnClicked, "door_on_click"); } if (LocalVariableTool.FindByPrefix(door, DoorPrefix.OnClosed).Any()) { SetEventScript(door, EventScriptDoor.OnClose, "door_on_close"); } if (LocalVariableTool.FindByPrefix(door, DoorPrefix.OnConversation).Any()) { SetEventScript(door, EventScriptDoor.OnDialogue, "door_on_convo"); } if (LocalVariableTool.FindByPrefix(door, DoorPrefix.OnDamaged).Any()) { SetEventScript(door, EventScriptDoor.OnDamage, "door_on_damage"); } if (LocalVariableTool.FindByPrefix(door, DoorPrefix.OnDeath).Any()) { SetEventScript(door, EventScriptDoor.OnDeath, "door_on_death"); } if (LocalVariableTool.FindByPrefix(door, DoorPrefix.OnDisarmed).Any()) { SetEventScript(door, EventScriptDoor.OnDisarm, "door_on_disarm"); } if (LocalVariableTool.FindByPrefix(door, DoorPrefix.OnFailToOpen).Any()) { SetEventScript(door, EventScriptDoor.OnFailToOpen, "door_on_fail"); } if (LocalVariableTool.FindByPrefix(door, DoorPrefix.OnHeartbeat).Any()) { SetEventScript(door, EventScriptDoor.OnHeartbeat, "door_on_hb"); } if (LocalVariableTool.FindByPrefix(door, DoorPrefix.OnLocked).Any()) { SetEventScript(door, EventScriptDoor.OnLock, "door_on_lock"); } if (LocalVariableTool.FindByPrefix(door, DoorPrefix.OnOpened).Any()) { SetEventScript(door, EventScriptDoor.OnOpen, "door_on_open"); } if (LocalVariableTool.FindByPrefix(door, DoorPrefix.OnSpellCastAt).Any()) { SetEventScript(door, EventScriptDoor.OnSpellCastAt, "door_on_splcast"); } if (LocalVariableTool.FindByPrefix(door, DoorPrefix.OnTriggerTrap).Any()) { SetEventScript(door, EventScriptDoor.OnTrapTriggered, "door_on_trap"); } if (LocalVariableTool.FindByPrefix(door, DoorPrefix.OnUnlock).Any()) { SetEventScript(door, EventScriptDoor.OnUnlock, "door_on_unlock"); } if (LocalVariableTool.FindByPrefix(door, DoorPrefix.OnUserDefined).Any()) { SetEventScript(door, EventScriptDoor.OnUserDefined, "door_on_userdef"); } }