public static void LoadAreas(CLRScriptBase s) { if (!ACR_Candlekeep.ArchivesInstance.WaitForResourcesLoaded(false)) { s.DelayCommand(6.0f, delegate { LoadAreas(s); }); return; } ALFA.Shared.Modules.InfoStore.ActiveAreas = new Dictionary<uint, ALFA.Shared.ActiveArea>(); List<uint> areas = new List<uint>(); foreach (uint area in s.GetAreas()) { ALFA.Shared.ActiveArea activeArea = new ALFA.Shared.ActiveArea(); activeArea.Id = area; activeArea.Name = s.GetName(area).Trim(); activeArea.Tag = s.GetTag(area); activeArea.GlobalQuests.Add("Infestation", s.GetLocalInt(area, "ACR_QST_MAX_INFESTATION")); ALFA.Shared.Modules.InfoStore.ActiveAreas.Add(area, activeArea); areas.Add(area); } int count = 0; foreach(KeyValuePair<string, string> keyValue in ALFA.Shared.Modules.InfoStore.AreaNames) { ALFA.Shared.Modules.InfoStore.ActiveAreas[areas[count]].LocalizedName = keyValue.Value; ALFA.Shared.Modules.InfoStore.ActiveAreas[areas[count]].ConfigureDisplayName(); s.SetLocalString(areas[count], "ACR_AREA_RESREF", keyValue.Key); count++; } foreach (ALFA.Shared.ActiveArea activeArea in ALFA.Shared.Modules.InfoStore.ActiveAreas.Values) { foreach (uint thing in s.GetObjectsInArea(activeArea.Id)) { uint target = s.GetTransitionTarget(thing); if (s.GetIsObjectValid(target) != FALSE) { ALFA.Shared.ActiveTransition activeTransition = new ALFA.Shared.ActiveTransition(); activeTransition.AreaTarget = ALFA.Shared.Modules.InfoStore.ActiveAreas[s.GetArea(target)]; activeTransition.Id = thing; activeTransition.Target = target; activeArea.ExitTransitions.Add(activeTransition, activeTransition.AreaTarget); } } } }
private void PopulateArea(CLRScriptBase script) { List<Vector3> trapsToSpawn = new List<Vector3>(); if (!DungeonStore.DungeonSpawns.ContainsKey(SpawnType)) return; foreach(uint wp in script.GetObjectsInArea(AreaId)) { if(script.GetTag(wp) == "MONSTER_LOW") { if (DungeonStore.DungeonSpawns[SpawnType].ContainsKey(CR / 3)) { script.CreateObject(CLRScriptBase.OBJECT_TYPE_CREATURE, DungeonStore.DungeonSpawns[SpawnType][CR/3][rand.Next(DungeonStore.DungeonSpawns[SpawnType][CR/3].Count)], script.GetLocation(wp), CLRScriptBase.TRUE, ""); } } else if(script.GetTag(wp) == "MONSTER_MED") { if (DungeonStore.DungeonSpawns[SpawnType].ContainsKey(CR / 2)) { script.CreateObject(CLRScriptBase.OBJECT_TYPE_CREATURE, DungeonStore.DungeonSpawns[SpawnType][CR/2][rand.Next(DungeonStore.DungeonSpawns[SpawnType][CR/2].Count)], script.GetLocation(wp), CLRScriptBase.TRUE, ""); } } else if(script.GetTag(wp) == "MONSTER_HIGH") { if (DungeonStore.DungeonSpawns[SpawnType].ContainsKey(CR)) { script.CreateObject(CLRScriptBase.OBJECT_TYPE_CREATURE, DungeonStore.DungeonSpawns[SpawnType][CR][rand.Next(DungeonStore.DungeonSpawns[SpawnType][CR].Count)], script.GetLocation(wp), CLRScriptBase.TRUE, ""); } if (!questSpawned) { questSpawned = true; NWEffect AoE = script.EffectAreaOfEffect(86, "acf_trg_onenter", "acf_trg_onheartbeat", "acf_trg_onexit", "AOE"+Quest); script.ApplyEffectAtLocation(CLRScriptBase.DURATION_TYPE_PERMANENT, script.SupernaturalEffect(AoE), script.GetLocation(wp), 0.0f); uint spawnedAoE = script.GetObjectByTag("AOE" + Quest, 0); script.SetLocalString(spawnedAoE, "ACR_QST_NAME", Quest); script.SetLocalInt(spawnedAoE, "ACR_QST_LOWER_STATE", 1); script.SetLocalInt(spawnedAoE, "ACR_QST_UPPER_STATE", 2); script.SetLocalString(spawnedAoE, "ACR_QST_MESSAGE", "This appears to be the end of the dungeon, and your path here is scouted."); } } else if (script.GetTag(wp) == "TRAP") { if(DungeonStore.DungeonTraps[TrapType].ContainsKey(CR)) { trapsToSpawn.Add(script.GetPosition(wp)); } } } foreach (Vector3 trap in trapsToSpawn) { script.ClearScriptParams(); script.AddScriptParameterInt(1); script.AddScriptParameterFloat(trap.x); script.AddScriptParameterFloat(trap.y); script.AddScriptParameterFloat(trap.z); script.AddScriptParameterObject(AreaId); script.AddScriptParameterInt(-1); script.AddScriptParameterInt(-1); script.AddScriptParameterFloat(-1.0f); script.AddScriptParameterInt(-1); script.AddScriptParameterInt(-1); script.AddScriptParameterInt(-1); script.AddScriptParameterInt(-1); script.AddScriptParameterInt(-1); script.AddScriptParameterInt(-1); script.AddScriptParameterObject(CLRScriptBase.OBJECT_INVALID); script.AddScriptParameterInt(-1); script.AddScriptParameterInt(-1); script.AddScriptParameterInt(-1); script.AddScriptParameterInt(-1); script.AddScriptParameterInt(-1); script.AddScriptParameterString(DungeonStore.DungeonTraps[TrapType][CR][rand.Next(DungeonStore.DungeonTraps[TrapType][CR].Count)]); script.ExecuteScriptEnhanced("ACR_Traps", script.GetModule(), CLRScriptBase.FALSE); } }
public void ClearArea(CLRScriptBase script) { foreach(uint obj in script.GetObjectsInArea(AreaId)) { if(script.GetObjectType(obj) == CLRScriptBase.OBJECT_TYPE_CREATURE || script.GetObjectType(obj) == CLRScriptBase.OBJECT_TYPE_AREA_OF_EFFECT) { script.DestroyObject(obj, 0.0f, CLRScriptBase.FALSE); } } }
public void TransitionToArea(CLRScriptBase script, ExitDirection exit) { string doorTag = "DOOR_NORTH"; switch(exit) { case ExitDirection.North: doorTag = "DOOR_NORTH"; break; case ExitDirection.East: doorTag = "DOOR_EAST"; break; case ExitDirection.South: doorTag = "DOOR_SOUTH"; break; case ExitDirection.West: doorTag = "DOOR_WEST"; break; case ExitDirection.Up: doorTag = "DOOR_UP"; break; case ExitDirection.Down: doorTag = "DOOR_DOWN"; break; } if(script.GetIsObjectValid(script.GetLocalObject(AreaId, doorTag)) == CLRScriptBase.TRUE) { uint door = script.GetLocalObject(AreaId, doorTag); script.JumpToObject(door, CLRScriptBase.TRUE); return; } foreach(uint obj in script.GetObjectsInArea(AreaId)) { if(script.GetTag(obj) == doorTag) { script.SetLocalObject(AreaId, doorTag, obj); script.JumpToObject(obj, CLRScriptBase.TRUE); return; } } script.SendMessageToPC(script.OBJECT_SELF, "I can't find a door to jump you to."); }
public static void DrawObjects(CLRScriptBase script, User currentUser, uint currentArea) { float fDelay = 0.1f; List<uint> ChooserAoEs = new List<uint>(); List<uint> ChooserCreatures = new List<uint>(); List<uint> ChooserDoors = new List<uint>(); List<uint> ChooserItems = new List<uint>(); List<uint> ChooserLights = new List<uint>(); List<uint> ChooserPlaceables = new List<uint>(); List<uint> ChooserPlacedEffects = new List<uint>(); List<uint> ChooserStores = new List<uint>(); List<uint> ChooserTriggers = new List<uint>(); List<uint> ChooserWaypoints = new List<uint>(); script.DelayCommand(fDelay, delegate { foreach (uint thing in script.GetObjectsInArea(currentArea)) { int objectType = script.GetObjectType(thing); switch (objectType) { case OBJECT_TYPE_AREA_OF_EFFECT: ChooserAoEs.Add(thing); break; case OBJECT_TYPE_CREATURE: ChooserCreatures.Add(thing); break; case OBJECT_TYPE_DOOR: ChooserDoors.Add(thing); break; case OBJECT_TYPE_ITEM: ChooserItems.Add(thing); break; case OBJECT_TYPE_LIGHT: ChooserLights.Add(thing); break; case OBJECT_TYPE_PLACEABLE: ChooserPlaceables.Add(thing); break; case OBJECT_TYPE_PLACED_EFFECT: ChooserPlacedEffects.Add(thing); break; case OBJECT_TYPE_STORE: ChooserStores.Add(thing); break; case OBJECT_TYPE_TRIGGER: ChooserTriggers.Add(thing); break; case OBJECT_TYPE_WAYPOINT: ChooserWaypoints.Add(thing); break; } } script.ClearListBox(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_OBJECTS"); if (ChooserAoEs.Count > 0 && currentUser.ChooserShowAOE) { fDelay += 0.1f; script.DelayCommand(fDelay, delegate { foreach (uint thing in ChooserAoEs) { script.AddListBoxRow(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_OBJECTS", thing.ToString(), "LISTBOX_ITEM_TEXT= " + script.GetTag(thing), "LISTBOX_ITEM_ICON=trap.tga", "5="+thing.ToString(), ""); } }); } if (ChooserCreatures.Count > 0 && currentUser.ChooserShowCreature) { fDelay += 0.1f; script.DelayCommand(fDelay, delegate { foreach (uint thing in ChooserCreatures) { script.AddListBoxRow(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_OBJECTS", thing.ToString(), "LISTBOX_ITEM_TEXT= " + script.GetName(thing), "LISTBOX_ITEM_ICON=creature.tga", "5=" + thing.ToString(), ""); } }); } if (ChooserDoors.Count > 0 && currentUser.ChooserShowDoor) { fDelay += 0.1f; script.DelayCommand(fDelay, delegate { foreach (uint thing in ChooserDoors) { script.AddListBoxRow(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_OBJECTS", thing.ToString(), "LISTBOX_ITEM_TEXT= " + script.GetName(thing), "LISTBOX_ITEM_ICON=door.tga", "5=" + thing.ToString(), ""); } }); } if (ChooserItems.Count > 0 && currentUser.ChooserShowItem) { fDelay += 0.1f; script.DelayCommand(fDelay, delegate { foreach (uint thing in ChooserItems) { script.AddListBoxRow(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_OBJECTS", thing.ToString(), "LISTBOX_ITEM_TEXT= " + script.GetName(thing), "LISTBOX_ITEM_ICON=item.tga", "5=" + thing.ToString(), ""); } }); } if (ChooserLights.Count > 0 && currentUser.ChooserShowLight) { fDelay += 0.1f; script.DelayCommand(fDelay, delegate { foreach (uint thing in ChooserLights) { script.AddListBoxRow(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_OBJECTS", thing.ToString(), "LISTBOX_ITEM_TEXT= " + script.GetName(thing) + ";LISTBOX_ITEM_TEXT2= Light", "LISTBOX_ITEM_ICON=light.tga", "5=" + thing.ToString(), ""); } }); } if (ChooserPlaceables.Count > 0 && currentUser.ChooserShowPlaceable) { fDelay += 0.1f; script.DelayCommand(fDelay, delegate { foreach (uint thing in ChooserPlaceables) { script.AddListBoxRow(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_OBJECTS", thing.ToString(), "LISTBOX_ITEM_TEXT= " + script.GetName(thing) + ";LISTBOX_ITEM_TEXT2= Placeable", "LISTBOX_ITEM_ICON=placeable.tga", "5=" + thing.ToString(), ""); } }); } if (ChooserPlacedEffects.Count > 0 && currentUser.ChooserShowPlacedEffect) { fDelay += 0.1f; script.DelayCommand(fDelay, delegate { foreach (uint thing in ChooserPlacedEffects) { script.AddListBoxRow(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_OBJECTS", thing.ToString(), "LISTBOX_ITEM_TEXT= " + script.GetName(thing) + ";LISTBOX_ITEM_TEXT2= Placed Effect", "LISTBOX_ITEM_ICON=vfx.tga", "5=" + thing.ToString(), ""); } }); } if (ChooserStores.Count > 0 && currentUser.ChooserShowStore) { fDelay += 0.1f; script.DelayCommand(fDelay, delegate { foreach (uint thing in ChooserStores) { script.AddListBoxRow(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_OBJECTS", thing.ToString(), "LISTBOX_ITEM_TEXT= " + script.GetName(thing) + ";LISTBOX_ITEM_TEXT2= Store", "LISTBOX_ITEM_ICON=store.tga", "5=" + thing.ToString(), ""); } }); } if (ChooserTriggers.Count > 0 && currentUser.ChooserShowTrigger) { fDelay += 0.1f; script.DelayCommand(fDelay, delegate { foreach (uint thing in ChooserTriggers) { script.AddListBoxRow(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_OBJECTS", thing.ToString(), "LISTBOX_ITEM_TEXT= " + script.GetName(thing) + ";LISTBOX_ITEM_TEXT2= Trigger", "LISTBOX_ITEM_ICON=trigger.tga", "5=" + thing.ToString(), ""); } }); } if (ChooserWaypoints.Count > 0 && currentUser.ChooserShowWaypoint) { fDelay += 0.1f; script.DelayCommand(fDelay, delegate { foreach (uint thing in ChooserWaypoints) { script.AddListBoxRow(currentUser.Id, "SCREEN_DMC_CHOOSER", "LISTBOX_ACR_CHOOSER_OBJECTS", thing.ToString(), "LISTBOX_ITEM_TEXT= " + script.GetName(thing) + ";LISTBOX_ITEM_TEXT2= Waypoint", "LISTBOX_ITEM_ICON=waypoint.tga", "5=" + thing.ToString(), ""); } }); } }); }
private static uint GetNearestTrapEmitter(CLRScriptBase script, NWLocation loc) { float nearestDist = -1.0f; uint nearestObject = CLRScriptBase.OBJECT_INVALID; Vector3 trapPos = script.GetPositionFromLocation(loc); foreach(uint obj in script.GetObjectsInArea(script.GetAreaFromLocation(loc))) { if(script.GetObjectType(obj) == OBJECT_TYPE_PLACEABLE && (script.GetTag(obj) == "TRAP_EMITTER" || script.GetTag(obj) == "TRAP_ORIGIN")) { Vector3 emitterPos = script.GetPosition(obj); float newDist = (trapPos.x - emitterPos.x)*(trapPos.x - emitterPos.x)+(trapPos.y - emitterPos.y)*(trapPos.y - emitterPos.y); if(nearestDist < 0 || nearestDist > newDist) { nearestDist = newDist; nearestObject = obj; } } } if(script.GetIsObjectValid(nearestObject) == CLRScriptBase.FALSE || nearestDist > 400.0f) // 20 meters; nearestDist is squared to be cheaper { nearestObject = CLRScriptBase.OBJECT_INVALID; } return nearestObject; }