void SpawnObject(ObjectSpawn objectToSpawn) { GameObject spawn = ObjectPool.instance.GetObject(objectToSpawn.objectType.name); spawn.transform.position = objectToSpawn.postion; spawn.transform.rotation = objectToSpawn.objectType.transform.rotation; spawn.SetActive(true); spawn.SendMessage("Init", SendMessageOptions.DontRequireReceiver); }
void Start() { healthBar = FindObjectOfType <Scrollbar>(); spawner = GameObject.FindGameObjectWithTag("Player Spawn").GetComponent <ObjectSpawn>(); deathScreen = GameObject.Find("Death Parent").transform.GetChild(0).gameObject; inventoryUI = GameObject.Find("Inventory").transform.gameObject; counter = FindObjectOfType <PlayerRespawn>(); deathScreen.SetActive(false); isDead = false; health = 1f; }
private void SpawnWeapon() { int weaponIndex = Random.Range(0, spawnedPrefabs.Length); GameObject weaponPrefab = spawnedPrefabs[weaponIndex]; Vector3 pos = GetSpawnPosition(); GameObject spawnerObject = Instantiate(spawnerPrefab, pos, Quaternion.identity); ObjectSpawn spawner = spawnerObject.GetComponent <ObjectSpawn>(); spawner.SetPrefabToSpawn(weaponPrefab, this); }
/// <summary> /// decides if any mobs should be spawned int the room /// </summary> private void SpawnMobs(DungeonRoom room, MapInfo mapInfo) { int numEnemies = rng.getInt(mapInfo.minEnemies, mapInfo.maxEnemies); for (int i = 0; i < numEnemies; i++) { Vector2 spawnLoc = RandomSpawnInRoom(room); string type = MapInfo.GetRandomFrom(mapInfo.enemySpawnTable, rng); ObjectSpawn spawn = new ObjectSpawn(spawnLoc, type); objectSpawns.Add(spawn); } }
/// <summary> /// decides if a container should be spawned here /// </summary> private void SpawnContainers(DungeonRoom room, MapInfo mapInfo, ref int numChests) { if (numChests >= mapInfo.maxLootChests) { return; } Vector2 spawnLoc = RandomSpawnInRoom(room); ObjectSpawn spawn = new ObjectSpawn(spawnLoc, "Chest"); objectSpawns.Add(spawn); numChests += 1; }
void Awake() { ItemEquipments = new Dictionary <int, FPSItemEquipment>(ItemsList.Length); for (int i = 0; i < ItemsList.Length; i++) { ItemsList[i].ItemID = Suffix + i; ItemsList[i].ItemIndex = i; //每个物体分配ID if (ItemsList[i].ItemFPS) { FPSItemEquipment fpsItemEquipment = ItemsList[i].ItemFPS.GetComponent <FPSItemEquipment>(); if (fpsItemEquipment) { fpsItemEquipment.ItemID = ItemsList[i].ItemID; fpsItemEquipment.ItemIndex = i; ItemEquipments[i] = fpsItemEquipment; } FPSWeaponEquipment weapon = ItemsList[i].ItemFPS.GetComponent <FPSWeaponEquipment>(); if (weapon) { if (ItemsList[i].ItemEquip) { ItemsList[i].ItemEquip.UsingType = weapon.UsingType; } } //物品放置 FPSItemPlacing fpsItemPlacer = ItemsList[i].ItemFPS.GetComponent <FPSItemPlacing>(); if (fpsItemPlacer) { if (fpsItemPlacer.Item != null) { ObjectSpawn objSpawn = fpsItemPlacer.Item.GetComponent <ObjectSpawn>(); if (objSpawn) { objSpawn.ItemID = ItemsList[i].ItemID; if (objSpawn.Item) { ObjectPlacing objPlace = objSpawn.Item.GetComponent <ObjectPlacing>(); if (objPlace) { objPlace.ItemID = ItemsList[i].ItemID; } } } } } } } }
// Use this for initialization void Start() { playerSpawn = (ObjectSpawn)GameObject.FindGameObjectWithTag("Player Spawn").GetComponent("ObjectSpawn"); cam = GameObject.FindGameObjectWithTag("mmCam"); idScript = (IslandDrop)GameObject.FindGameObjectWithTag("EGO Island").GetComponent("IslandDrop"); nonMMObject = GameObject.FindGameObjectWithTag("Non Main Menu UI"); nonMMObject.SetActive(false); nonCredOrHs = GameObject.Find("NonCredOrHs"); credOrHs = GameObject.Find("CredOrHs"); credits = GameObject.Find("Credits"); highScores = GameObject.Find("High Scores"); credOrHs.SetActive(false); }
void ReadWaveNode(XmlNode waveNode, ref Wave wave) { if (string.Compare(waveNode.Name, "Time") == 0) { wave.time = float.Parse(waveNode.FirstChild.Value); } if (string.Compare(waveNode.Name, "Ship") == 0) { float pos = float.Parse(waveNode.FirstChild.Value); ObjectSpawn objectSpawn = new ObjectSpawn(); objectSpawn.objectType = shipPrefab; objectSpawn.postion = Camera.main.ViewportToWorldPoint(new Vector3(pos / 100.0f, 1.0f, 10.0f)); wave.objects.Add(objectSpawn); } if (string.Compare(waveNode.Name, "FireRate") == 0) { float pos = float.Parse(waveNode.FirstChild.Value); ObjectSpawn objectSpawn = new ObjectSpawn(); objectSpawn.objectType = fireRatePrefab; objectSpawn.postion = Camera.main.ViewportToWorldPoint(new Vector3(pos / 100.0f, 1.0f, 10.0f)); wave.objects.Add(objectSpawn); } if (string.Compare(waveNode.Name, "Health") == 0) { float pos = float.Parse(waveNode.FirstChild.Value); ObjectSpawn objectSpawn = new ObjectSpawn(); objectSpawn.objectType = healthPrefab; objectSpawn.postion = Camera.main.ViewportToWorldPoint(new Vector3(pos / 100.0f, 1.0f, 10.0f)); wave.objects.Add(objectSpawn); } }
// Start is called before the first frame update void Start() { isSpawning = false; if (spawnObject1) { spawnObject1.onClick.AddListener(() => objects.Enqueue(objectSpawn.object1_Prefab)); } if (spawnObject2) { spawnObject2.onClick.AddListener(() => objects.Enqueue(objectSpawn.object2_Prefab)); } if (spawnObject3) { spawnObject3.onClick.AddListener(() => objects.Enqueue(objectSpawn.object3_Prefab)); } objectSpawn = GameObject.FindObjectOfType <ObjectSpawn>(); }
//Start() is called before the first frame update //Inicializa Objetos e Variaveis void Start() { state = 0; itemHandleScript = GameObject.Find("Camera").GetComponent <ObjectInteraction>(); mediumFire.SetActive(false); currentTime = 0f; currentFireLevel = 0; clear = false; //SFX lid = GameObject.Find("tampa"); cup = GameObject.Find("caneca_agua"); fryingPan = GameObject.Find("frigideira"); ceiling = GameObject.Find("Teto"); levelChanger = FindObjectOfType <LevelChangerScript>(); objectSpawn = new ObjectSpawn(); objectSpawn.StartObject(); }
public override void GenerateMap(AreaMap.Tile[] tiles, int width, int height) { this.width = width; this.height = height; int startx = width / 2; int starty = height / 2; // list of tiles that were added to the cave, for choosing valid spawn locations Dictionary <Vector2, Vector2> caveTiles = new Dictionary <Vector2, Vector2>(); // Create a set of crawlers that will be guided around the space by the perlin noise, carving out an area of the map while they are at it int numCrawlers = rng.getInt(MIN_CRAWLERS, MAX_CRAWLERS); // intialize the crawler directions Crawler[] crawlers = new Crawler[numCrawlers]; for (int i = 0; i < numCrawlers; i++) { int dirx = rng.getInt(-1, 1); int diry = rng.getInt(-1, 1); if (dirx == 0 && diry == 0) { dirx = 1; } crawlers[i] = new Crawler(new Vector2(dirx, diry)); crawlers[i].x = rng.getInt(width / 2 - START_AREA_SIZE, width / 2 + START_AREA_SIZE); crawlers[i].y = rng.getInt(height / 2 - START_AREA_SIZE, height / 2 + START_AREA_SIZE); } // perform the actual dungeon digging. Update each crawler a set number of times for (int i = 0; i < NUM_ITERATIONS; i++) { for (int cIdx = 0; cIdx < numCrawlers; cIdx++) { UpdateCrawler(ref crawlers[cIdx]); // dig out the crawlers new area DigArea(tiles, crawlers[cIdx], caveTiles); } } // and send crawlers back to some central location in order to ensure a connected level Vector2 homeLoc = new Vector2( rng.getInt(width / 2 - START_AREA_SIZE, width / 2 + START_AREA_SIZE), rng.getInt(height / 2 - START_AREA_SIZE, height / 2 + START_AREA_SIZE) ); Crawler prevCrawler = crawlers[0]; for (int cIdx = 1; cIdx < numCrawlers; cIdx++) { ReturnCrawlerToHome(tiles, ref crawlers[cIdx], new Vector2(prevCrawler.x, prevCrawler.y), caveTiles); } // spawn some items, including palyer and entrance / exit List <Vector2> validSpawns = new List <Vector2>(caveTiles.Values); Vector2 playerSpawn = validSpawns[rng.getInt(0, validSpawns.Count - 1)]; objectSpawns = new List <ObjectSpawn>(); objectSpawns.Add(new ObjectSpawn(playerSpawn, "Player")); objectSpawns.Add(new ObjectSpawn(playerSpawn, ENTRANCE_ENTITY)); Vector2 exitSpawn = validSpawns[rng.getInt(0, validSpawns.Count - 1)]; objectSpawns.Add(new ObjectSpawn(exitSpawn, EXIT_ENTITY)); // spawn mobs for (int i = 0; i < mapInfo.maxEnemies; i++) { Vector2 spawnLoc = validSpawns[rng.getInt(0, validSpawns.Count - 1)]; string type = MapInfo.GetRandomFrom(mapInfo.enemySpawnTable, rng); ObjectSpawn spawn = new ObjectSpawn(spawnLoc, type); objectSpawns.Add(spawn); } // spawn chest Vector2 chestLoc = validSpawns[rng.getInt(0, validSpawns.Count - 1)]; Vector2 keyLoc = validSpawns[rng.getInt(0, validSpawns.Count - 1)]; objectSpawns.Add(new ObjectSpawn(chestLoc, "Chest")); objectSpawns.Add(new ObjectSpawn(keyLoc, KEY_ENTITY)); }
private static void InitializeAreaSpawns(NWArea area) { var areaSpawn = new AreaSpawn(); // Check for manually placed spawns NWObject obj = GetFirstObjectInArea(area.Object); while (obj.IsValid) { bool isSpawn = obj.ObjectType == OBJECT_TYPE_WAYPOINT && obj.GetLocalInt("IS_SPAWN") == TRUE; if (isSpawn) { int spawnType = obj.GetLocalInt("SPAWN_TYPE"); int objectType = spawnType == 0 || spawnType == OBJECT_TYPE_CREATURE ? OBJECT_TYPE_CREATURE : spawnType; int spawnTableID = obj.GetLocalInt("SPAWN_TABLE_ID"); int npcGroupID = obj.GetLocalInt("SPAWN_NPC_GROUP_ID"); string behaviourScript = obj.GetLocalString("SPAWN_BEHAVIOUR_SCRIPT"); if (string.IsNullOrWhiteSpace(behaviourScript)) { behaviourScript = obj.GetLocalString("SPAWN_BEHAVIOUR"); } string spawnResref = obj.GetLocalString("SPAWN_RESREF"); float respawnTime = obj.GetLocalFloat("SPAWN_RESPAWN_SECONDS"); string spawnRule = obj.GetLocalString("SPAWN_RULE"); int deathVFXID = obj.GetLocalInt("SPAWN_DEATH_VFX"); AIFlags aiFlags = (AIFlags)obj.GetLocalInt("SPAWN_AI_FLAGS"); bool useResref = true; // No resref specified but a table was, look in the database for a random record. if (string.IsNullOrWhiteSpace(spawnResref) && spawnTableID > 0) { // Pick a random record. var spawnObjects = DataService.SpawnObject.GetAllBySpawnTableID(spawnTableID).ToList(); int count = spawnObjects.Count; int index = count <= 0 ? 0 : RandomService.Random(count); var dbSpawn = spawnObjects[index]; if (dbSpawn != null) { spawnResref = dbSpawn.Resref; useResref = false; if (dbSpawn.NPCGroupID != null && dbSpawn.NPCGroupID > 0) { npcGroupID = Convert.ToInt32(dbSpawn.NPCGroupID); } if (!string.IsNullOrWhiteSpace(dbSpawn.BehaviourScript)) { behaviourScript = dbSpawn.BehaviourScript; } if (!string.IsNullOrWhiteSpace(dbSpawn.SpawnRule)) { spawnRule = dbSpawn.SpawnRule; } if (deathVFXID <= 0) { deathVFXID = dbSpawn.DeathVFXID; } if (aiFlags == AIFlags.None) { aiFlags = dbSpawn.AIFlags; } } } // If we found a resref, spawn the object and add it to the cache. if (!string.IsNullOrWhiteSpace(spawnResref)) { // Delay the creation so that the iteration through the area doesn't get thrown off by new entries. Location location = obj.Location; bool isInstance = area.IsInstance; ObjectSpawn newSpawn; if (useResref) { newSpawn = new ObjectSpawn(location, true, spawnResref, respawnTime); } else { newSpawn = new ObjectSpawn(location, true, spawnTableID, respawnTime); } if (npcGroupID > 0) { newSpawn.NPCGroupID = npcGroupID; } if (deathVFXID > 0) { newSpawn.DeathVFXID = deathVFXID; } if (!string.IsNullOrWhiteSpace(behaviourScript)) { newSpawn.BehaviourScript = behaviourScript; } if (!string.IsNullOrWhiteSpace(spawnRule)) { newSpawn.SpawnRule = spawnRule; } if (aiFlags == AIFlags.None) { newSpawn.AIFlags = aiFlags; } // Instance spawns are one-shot. if (isInstance) { newSpawn.Respawns = false; } if (objectType == OBJECT_TYPE_CREATURE) { areaSpawn.Creatures.Add(newSpawn); } else if (objectType == OBJECT_TYPE_PLACEABLE) { areaSpawn.Placeables.Add(newSpawn); } } } obj = GetNextObjectInArea(area.Object); } AreaSpawns.Add(area, areaSpawn); DelayCommand(1.0f, () => { SpawnResources(area, areaSpawn); }); }
private static void ProcessSpawn(ObjectSpawn spawn, int objectType, NWArea area, bool forceSpawn) { // Don't process anything that's valid. if (spawn.Spawn.IsValid) { return; } spawn.Timer += ObjectProcessingService.ProcessingTickInterval; // Time to respawn! if (spawn.Timer >= spawn.RespawnTime || forceSpawn) { string resref = spawn.Resref; int npcGroupID = spawn.NPCGroupID; int deathVFXID = spawn.DeathVFXID; string behaviour = spawn.BehaviourScript; NWLocation location = spawn.IsStaticSpawnPoint ? spawn.SpawnLocation : null; AIFlags aiFlags = spawn.AIFlags; spawn.HasSpawnedOnce = true; // Look for a spawn out of the database set. Update spawn data if one is found. if (string.IsNullOrWhiteSpace(resref)) { var dbSpawn = DataService.SpawnObject.GetAllBySpawnTableID(spawn.SpawnTableID) .OrderBy(o => Guid.NewGuid()).First(); resref = dbSpawn.Resref; npcGroupID = dbSpawn.NPCGroupID ?? 0; deathVFXID = dbSpawn.DeathVFXID; behaviour = dbSpawn.BehaviourScript; aiFlags = dbSpawn.AIFlags; if (!string.IsNullOrWhiteSpace(dbSpawn.SpawnRule)) { spawn.SpawnRule = dbSpawn.SpawnRule; } else { // Clear the saved spawn rule since we now have a new resref etc. spawn.SpawnRule = null; } } if (location == null) { location = GetRandomSpawnPoint(area); } spawn.Spawn = CreateObject(objectType, resref, location); if (!spawn.Spawn.IsValid) { Console.WriteLine("SPAWN SERVICE ERROR: Cannot locate object with resref " + resref + ". Error occurred in area " + area.Name + " (" + area.Resref + ")"); return; } if (npcGroupID > 0) { spawn.Spawn.SetLocalInt("NPC_GROUP", npcGroupID); } if (deathVFXID > 0) { spawn.Spawn.SetLocalInt("DEATH_VFX", deathVFXID); } if (!string.IsNullOrWhiteSpace(behaviour) && string.IsNullOrWhiteSpace(spawn.Spawn.GetLocalString("BEHAVIOUR"))) { spawn.Spawn.SetLocalString("BEHAVIOUR", behaviour); } spawn.Spawn.SetLocalInt("AI_FLAGS", (int)aiFlags); if (objectType == OBJECT_TYPE_CREATURE) { AssignScriptEvents(spawn.Spawn.Object); } if (!string.IsNullOrWhiteSpace(spawn.SpawnRule)) { var rule = GetSpawnRule(spawn.SpawnRule); rule.Run(spawn.Spawn); } ObjectVisibilityService.ApplyVisibilityForObject(spawn.Spawn); spawn.Timer = 0.0f; } }
private static void SpawnResources(NWArea area, AreaSpawn areaSpawn) { var dbArea = DataService.Area.GetByResref(area.Resref); if (dbArea.ResourceSpawnTableID <= 0 || !dbArea.AutoSpawnResources) { return; } var possibleSpawns = DataService.SpawnObject.GetAllBySpawnTableID(dbArea.ResourceSpawnTableID).ToList(); // 1024 size = 32x32 // 256 size = 16x16 // 64 size = 8x8 int size = area.Width * area.Height; int maxSpawns = 0; if (size <= 12) { maxSpawns = 2; } else if (size <= 32) { maxSpawns = 6; } else if (size <= 64) { maxSpawns = 10; } else if (size <= 256) { maxSpawns = 25; } else if (size <= 512) { maxSpawns = 40; } else if (size <= 1024) { maxSpawns = 50; } int[] weights = new int[possibleSpawns.Count()]; for (int x = 0; x < possibleSpawns.Count(); x++) { weights[x] = possibleSpawns.ElementAt(x).Weight; } for (int x = 1; x <= maxSpawns; x++) { int index = RandomService.GetRandomWeightedIndex(weights); var dbSpawn = possibleSpawns.ElementAt(index); Location location = GetRandomSpawnPoint(area); NWPlaceable plc = (CreateObject(OBJECT_TYPE_PLACEABLE, dbSpawn.Resref, location)); ObjectSpawn spawn = new ObjectSpawn(location, false, dbArea.ResourceSpawnTableID, 600.0f); spawn.Spawn = plc; ObjectVisibilityService.ApplyVisibilityForObject(plc); if (dbSpawn.NPCGroupID != null && dbSpawn.NPCGroupID > 0) { plc.SetLocalInt("NPC_GROUP", Convert.ToInt32(dbSpawn.NPCGroupID)); spawn.NPCGroupID = Convert.ToInt32(dbSpawn.NPCGroupID); } if (!string.IsNullOrWhiteSpace(dbSpawn.BehaviourScript) && string.IsNullOrWhiteSpace(plc.GetLocalString("BEHAVIOUR"))) { plc.SetLocalString("BEHAVIOUR", dbSpawn.BehaviourScript); spawn.BehaviourScript = dbSpawn.BehaviourScript; } if (!string.IsNullOrWhiteSpace(dbSpawn.SpawnRule)) { var rule = GetSpawnRule(dbSpawn.SpawnRule); rule.Run(plc); } areaSpawn.Placeables.Add(spawn); } }
private void ProcessSpawn(ObjectSpawn spawn, int objectType, NWArea area, bool forceSpawn) { // Don't process anything that's valid. if (spawn.Spawn.IsValid) { return; } spawn.Timer += _processor.ProcessingTickInterval; // Time to respawn! if (spawn.Timer >= spawn.RespawnTime || forceSpawn) { string resref = spawn.Resref; NWLocation location = spawn.IsStaticSpawnPoint ? spawn.SpawnLocation : null; spawn.HasSpawnedOnce = true; if (string.IsNullOrWhiteSpace(resref)) { var dbSpawn = _data.Where <SpawnObject>(x => x.SpawnID == spawn.SpawnTableID) .OrderBy(o => Guid.NewGuid()).First(); resref = dbSpawn.Resref; if (!string.IsNullOrWhiteSpace(dbSpawn.SpawnRule)) { spawn.SpawnRule = dbSpawn.SpawnRule; } } if (location == null) { location = _spawn.GetRandomSpawnPoint(area); } spawn.Spawn = _.CreateObject(objectType, resref, location); if (!spawn.Spawn.IsValid) { Console.WriteLine("ERROR: Cannot locate object with resref " + resref + ". Error occurred in area " + area.Name + " (" + area.Resref + ")"); return; } if (spawn.NPCGroupID > 0) { spawn.Spawn.SetLocalInt("NPC_GROUP", spawn.NPCGroupID); } if (spawn.DeathVFXID > 0) { spawn.Spawn.SetLocalInt("DEATH_VFX", spawn.DeathVFXID); } if (!string.IsNullOrWhiteSpace(spawn.BehaviourScript) && string.IsNullOrWhiteSpace(spawn.Spawn.GetLocalString("BEHAVIOUR"))) { spawn.Spawn.SetLocalString("BEHAVIOUR", spawn.BehaviourScript); } if (objectType == OBJECT_TYPE_CREATURE) { _spawn.AssignScriptEvents(spawn.Spawn.Object); } if (!string.IsNullOrWhiteSpace(spawn.SpawnRule)) { App.ResolveByInterface <ISpawnRule>("SpawnRule." + spawn.SpawnRule, rule => { rule.Run(spawn.Spawn); }); } App.Resolve <IObjectVisibilityService>(ovs => { ovs.ApplyVisibilityForObject(spawn.Spawn); }); spawn.Timer = 0.0f; } }
private void SpawnObject(ObjectSpawn spawn) { Enemy e = new Enemy(spawn.objectType, Constants.BehaviourType.Default, (int)position.X, (int)position.Y, player, 0, 0, 0, content); e.ChangeVelocity(spawn.spawnVelocity.X, spawn.spawnVelocity.Y); e.SetState(Constants.CharacterState.Spawning); if (initialScale != 0 && ultimateScale != 0 && scalingSpeed != 0) { e.SetScaling(initialScale, ultimateScale, scalingSpeed); } CollisionHandler.AddObject(e); gameObjects.Add(e); SoundEffectManager.Instance.PlaySpawnSound(position, e.Type); if (effect != null) VisualEffectManager.Instance.CreateEffect(effect.TextureAsset, this.position, 700); if (spawnSound != null) SoundEffectManager.Instance.PlaySoundFromPosition(this.position, spawnSound); }
/// <summary> /// Add an object to spawn. /// </summary> /// <param name="obj">The object</param> /// <param name="amount">How many objects</param> /// <param name="spawnVelocity">Starting velocity for object</param> public void AddObject(Constants.EnemyType type, int amount, Vector2 spawnVelocity) { ObjectSpawn spawn = new ObjectSpawn(); spawn.objectType = type; spawn.amount = amount; spawn.spawnVelocity = spawnVelocity; objectsToSpawn.Add(spawn); }
private static void ProcessSpawn(ObjectSpawn spawn, ObjectType objectType, NWArea area, bool forceSpawn) { // Spawn expiry. if (spawn.Expires < DateTime.UtcNow) { NWPlaceable prop = spawn.Spawn.GetLocalObject("RESOURCE_PROP_OBJ"); if (prop.IsValid) { DestroyObject(prop); } DestroyObject(spawn.Spawn); forceSpawn = true; } // Don't process anything that's valid. Put this in an else branch as object destruction // happens after script completion. else if (spawn.Spawn.IsValid) { return; } spawn.Timer += ObjectProcessingService.ProcessingTickInterval; // Time to respawn! if (spawn.Timer >= spawn.RespawnTime || forceSpawn) { string resref = spawn.Resref; int npcGroupID = spawn.NPCGroupID; int deathVFXID = spawn.DeathVFXID; string behaviour = spawn.BehaviourScript; NWLocation location = spawn.IsStaticSpawnPoint ? spawn.SpawnLocation : null; AIFlags aiFlags = spawn.AIFlags; spawn.HasSpawnedOnce = true; // Look for a spawn out of the database set. Update spawn data if one is found. if (string.IsNullOrWhiteSpace(resref)) { var dbSpawn = DataService.SpawnObject.GetAllBySpawnTableID(spawn.SpawnTableID) .OrderBy(o => Guid.NewGuid()).First(); resref = dbSpawn.Resref; npcGroupID = dbSpawn.NPCGroupID ?? 0; deathVFXID = dbSpawn.DeathVFXID; behaviour = dbSpawn.BehaviourScript; aiFlags = dbSpawn.AIFlags; if (!string.IsNullOrWhiteSpace(dbSpawn.SpawnRule)) { spawn.SpawnRule = dbSpawn.SpawnRule; } else { // Clear the saved spawn rule since we now have a new resref etc. spawn.SpawnRule = null; } } if (location == null) { location = GetRandomSpawnPoint(area); } spawn.Spawn = CreateObject(objectType, resref, location); if (!spawn.Spawn.IsValid) { Console.WriteLine("SPAWN SERVICE ERROR: Cannot locate object with resref " + resref + ". Error occurred in area " + area.Name + " (" + area.Resref + ")"); return; } if (npcGroupID > 0) { spawn.Spawn.SetLocalInt("NPC_GROUP", npcGroupID); } if (deathVFXID > 0) { spawn.Spawn.SetLocalInt("DEATH_VFX", deathVFXID); } if (!string.IsNullOrWhiteSpace(behaviour) && string.IsNullOrWhiteSpace(spawn.Spawn.GetLocalString("BEHAVIOUR"))) { spawn.Spawn.SetLocalString("BEHAVIOUR", behaviour); } spawn.Spawn.SetLocalInt("AI_FLAGS", (int)aiFlags); // Set expiry time for spawn. Set creatures to 26 hours (i.e. longer than the server reset // cycle, so never). Set placeables to 1 hour, so blocking objects will move and resources // will reset. if (objectType == ObjectType.Creature) { AssignScriptEvents(spawn.Spawn.Object); spawn.Expires = DateTime.UtcNow.AddHours(26); } else { spawn.Expires = DateTime.UtcNow.AddHours(1); } if (!string.IsNullOrWhiteSpace(spawn.SpawnRule)) { var rule = GetSpawnRule(spawn.SpawnRule); rule.Run(spawn.Spawn); } ObjectVisibilityService.ApplyVisibilityForObject(spawn.Spawn); spawn.Timer = 0.0f; } }