| using System; |
| using System; |
| using System.Collections.Generic; |
| using System.Collections.Generic; |
| using UnityEngine; |
| using UnityEngine; |
| |
| |
| public class CreatureSpawner : MonoBehaviour |
| public class CreatureSpawner : MonoBehaviour |
| { |
| { |
| private void Awake() |
| private void Awake() |
| { |
| { |
| CreatureSpawner.m_creatureSpawners.Add(this); |
| CreatureSpawner.m_creatureSpawners.Add(this); |
| this.m_nview = base.GetComponent<ZNetView>(); |
| this.m_nview = base.GetComponent<ZNetView>(); |
| if (this.m_nview.GetZDO() == null) |
| if (this.m_nview.GetZDO() == null) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| base.InvokeRepeating("UpdateSpawner", (float)UnityEngine.Random.Range(this.m_spawnInterval / 2, this.m_spawnInterval), (float)this.m_spawnInterval); |
| base.InvokeRepeating("UpdateSpawner", (float)UnityEngine.Random.Range(this.m_spawnInterval / 2, this.m_spawnInterval), (float)this.m_spawnInterval); |
| } |
| } |
| |
| |
| private void OnDestroy() |
| private void OnDestroy() |
| { |
| { |
| CreatureSpawner.m_creatureSpawners.Remove(this); |
| CreatureSpawner.m_creatureSpawners.Remove(this); |
| } |
| } |
| |
| |
| private void UpdateSpawner() |
| private void UpdateSpawner() |
| { |
| { |
| if (!this.m_nview.IsOwner()) |
| if (!this.m_nview.IsOwner()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (!this.m_checkedLocation) |
| if (!this.m_checkedLocation) |
| { |
| { |
| this.m_location = Location.GetLocation(base.transform.position, true); |
| this.m_location = Location.GetLocation(base.transform.position, true); |
| this.m_checkedLocation = true; |
| this.m_checkedLocation = true; |
| if (this.m_location && this.m_location.m_blockSpawnGroups.Contains(this.m_spawnGroupID)) |
| if (this.m_location && this.m_location.m_blockSpawnGroups.Contains(this.m_spawnGroupID)) |
| { |
| { |
| this.m_nview.Destroy(); |
| this.m_nview.Destroy(); |
| return; |
| return; |
| } |
| } |
| } |
| } |
| ZDOConnection connection = this.m_nview.GetZDO().GetConnection(); |
| ZDOConnection connection = this.m_nview.GetZDO().GetConnection(); |
| bool flag = connection != null && connection.m_type == ZDOExtraData.ConnectionType.Spawned; |
| bool flag = connection != null && connection.m_type == ZDOExtraData.ConnectionType.Spawned; |
| if (this.m_respawnTimeMinuts <= 0f && flag) |
| if (this.m_respawnTimeMinuts <= 0f && flag) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| ZDOID connectionZDOID = this.m_nview.GetZDO().GetConnectionZDOID(ZDOExtraData.ConnectionType.Spawned); |
| ZDOID connectionZDOID = this.m_nview.GetZDO().GetConnectionZDOID(ZDOExtraData.ConnectionType.Spawned); |
| if (this.SpawnedCreatureStillExists(connectionZDOID)) |
| if (this.SpawnedCreatureStillExists(connectionZDOID)) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (!this.CanRespawnNow(connectionZDOID)) |
| if (!this.CanRespawnNow(connectionZDOID)) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| . | if (!this.m_spawnAtDay && EnvMan.instance.IsDay()) |
| if (!this.m_spawnAtDay && EnvMan.IsDay()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| . | if (!this.m_spawnAtNight && EnvMan.instance.IsNight()) |
| if (!this.m_spawnAtNight && EnvMan.IsNight()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| bool requireSpawnArea = this.m_requireSpawnArea; |
| bool requireSpawnArea = this.m_requireSpawnArea; |
| if (!this.m_spawnInPlayerBase && EffectArea.IsPointInsideArea(base.transform.position, EffectArea.Type.PlayerBase, 0f)) |
| if (!this.m_spawnInPlayerBase && EffectArea.IsPointInsideArea(base.transform.position, EffectArea.Type.PlayerBase, 0f)) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (this.m_triggerNoise > 0f) |
| if (this.m_triggerNoise > 0f) |
| { |
| { |
| if (!Player.IsPlayerInRange(base.transform.position, this.m_triggerDistance, this.m_triggerNoise)) |
| if (!Player.IsPlayerInRange(base.transform.position, this.m_triggerDistance, this.m_triggerNoise)) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| } |
| } |
| else if (!Player.IsPlayerInRange(base.transform.position, this.m_triggerDistance)) |
| else if (!Player.IsPlayerInRange(base.transform.position, this.m_triggerDistance)) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (this.CheckGlobalKeys()) |
| if (this.CheckGlobalKeys()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (this.CheckGroupSpawnBlocked()) |
| if (this.CheckGroupSpawnBlocked()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (this.m_spawnGroup != null) |
| if (this.m_spawnGroup != null) |
| { |
| { |
| this.m_spawnGroup.SpawnWeighted(); |
| this.m_spawnGroup.SpawnWeighted(); |
| return; |
| return; |
| } |
| } |
| this.Spawn(); |
| this.Spawn(); |
| } |
| } |
| |
| |
| private bool CheckGlobalKeys() |
| private bool CheckGlobalKeys() |
| { |
| { |
| List<string> globalKeys = ZoneSystem.instance.GetGlobalKeys(); |
| List<string> globalKeys = ZoneSystem.instance.GetGlobalKeys(); |
| return (this.m_blockingGlobalKey != "" && globalKeys.Contains(this.m_blockingGlobalKey)) || (this.m_requiredGlobalKey != "" && !globalKeys.Contains(this.m_requiredGlobalKey)); |
| return (this.m_blockingGlobalKey != "" && globalKeys.Contains(this.m_blockingGlobalKey)) || (this.m_requiredGlobalKey != "" && !globalKeys.Contains(this.m_requiredGlobalKey)); |
| } |
| } |
| |
| |
| private bool SpawnedCreatureStillExists(ZDOID spawnID) |
| private bool SpawnedCreatureStillExists(ZDOID spawnID) |
| { |
| { |
| if (!spawnID.IsNone() && ZDOMan.instance.GetZDO(spawnID) != null) |
| if (!spawnID.IsNone() && ZDOMan.instance.GetZDO(spawnID) != null) |
| { |
| { |
| this.m_nview.GetZDO().Set(ZDOVars.s_aliveTime, ZNet.instance.GetTime().Ticks); |
| this.m_nview.GetZDO().Set(ZDOVars.s_aliveTime, ZNet.instance.GetTime().Ticks); |
| return true; |
| return true; |
| } |
| } |
| return false; |
| return false; |
| } |
| } |
| |
| |
| private bool CanRespawnNow(ZDOID spawnID) |
| private bool CanRespawnNow(ZDOID spawnID) |
| { |
| { |
| if (this.m_respawnTimeMinuts > 0f) |
| if (this.m_respawnTimeMinuts > 0f) |
| { |
| { |
| DateTime time = ZNet.instance.GetTime(); |
| DateTime time = ZNet.instance.GetTime(); |
| DateTime dateTime = new DateTime(this.m_nview.GetZDO().GetLong(ZDOVars.s_aliveTime, 0L)); |
| DateTime dateTime = new DateTime(this.m_nview.GetZDO().GetLong(ZDOVars.s_aliveTime, 0L)); |
| if ((time - dateTime).TotalMinutes < (double)this.m_respawnTimeMinuts) |
| if ((time - dateTime).TotalMinutes < (double)this.m_respawnTimeMinuts) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| } |
| } |
| return true; |
| return true; |
| } |
| } |
| |
| |
| private bool HasSpawned() |
| private bool HasSpawned() |
| { |
| { |
| if (this.m_nview == null || this.m_nview.GetZDO() == null) |
| if (this.m_nview == null || this.m_nview.GetZDO() == null) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| ZDOConnection connection = this.m_nview.GetZDO().GetConnection(); |
| ZDOConnection connection = this.m_nview.GetZDO().GetConnection(); |
| return connection != null && connection.m_type == ZDOExtraData.ConnectionType.Spawned; |
| return connection != null && connection.m_type == ZDOExtraData.ConnectionType.Spawned; |
| } |
| } |
| |
| |
| private ZNetView Spawn() |
| private ZNetView Spawn() |
| { |
| { |
| Vector3 position = base.transform.position; |
| Vector3 position = base.transform.position; |
| float num; |
| float num; |
| if (ZoneSystem.instance.FindFloor(position, out num)) |
| if (ZoneSystem.instance.FindFloor(position, out num)) |
| { |
| { |
| position.y = num; |
| position.y = num; |
| } |
| } |
| Quaternion quaternion = Quaternion.Euler(0f, UnityEngine.Random.Range(0f, 360f), 0f); |
| Quaternion quaternion = Quaternion.Euler(0f, UnityEngine.Random.Range(0f, 360f), 0f); |
| GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.m_creaturePrefab, position, quaternion); |
| GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.m_creaturePrefab, position, quaternion); |
| ZNetView component = gameObject.GetComponent<ZNetView>(); |
| ZNetView component = gameObject.GetComponent<ZNetView>(); |
| if (this.m_wakeUpAnimation) |
| if (this.m_wakeUpAnimation) |
| { |
| { |
| ZSyncAnimation component2 = gameObject.GetComponent<ZSyncAnimation>(); |
| ZSyncAnimation component2 = gameObject.GetComponent<ZSyncAnimation>(); |
| if (component2 != null) |
| if (component2 != null) |
| { |
| { |
| component2.SetBool("wakeup", true); |
| component2.SetBool("wakeup", true); |
| } |
| } |
| } |
| } |
| BaseAI component3 = gameObject.GetComponent<BaseAI>(); |
| BaseAI component3 = gameObject.GetComponent<BaseAI>(); |
| if (component3 != null && this.m_setPatrolSpawnPoint) |
| if (component3 != null && this.m_setPatrolSpawnPoint) |
| { |
| { |
| component3.SetPatrolPoint(); |
| component3.SetPatrolPoint(); |
| } |
| } |
| int num2 = this.m_minLevel; |
| int num2 = this.m_minLevel; |
| int num3 = this.m_maxLevel; |
| int num3 = this.m_maxLevel; |
| float num4 = this.m_levelupChance; |
| float num4 = this.m_levelupChance; |
| if (this.m_location != null && !this.m_location.m_excludeEnemyLevelOverrideGroups.Contains(this.m_spawnGroupID)) |
| if (this.m_location != null && !this.m_location.m_excludeEnemyLevelOverrideGroups.Contains(this.m_spawnGroupID)) |
| { |
| { |
| if (this.m_location.m_enemyMinLevelOverride >= 0) |
| if (this.m_location.m_enemyMinLevelOverride >= 0) |
| { |
| { |
| num2 = this.m_location.m_enemyMinLevelOverride; |
| num2 = this.m_location.m_enemyMinLevelOverride; |
| } |
| } |
| if (this.m_location.m_enemyMaxLevelOverride >= 0) |
| if (this.m_location.m_enemyMaxLevelOverride >= 0) |
| { |
| { |
| num3 = this.m_location.m_enemyMaxLevelOverride; |
| num3 = this.m_location.m_enemyMaxLevelOverride; |
| } |
| } |
| if (this.m_location.m_enemyLevelUpOverride >= 0f) |
| if (this.m_location.m_enemyLevelUpOverride >= 0f) |
| { |
| { |
| num4 = this.m_location.m_enemyLevelUpOverride; |
| num4 = this.m_location.m_enemyLevelUpOverride; |
| } |
| } |
| } |
| } |
| if (num3 > 1) |
| if (num3 > 1) |
| { |
| { |
| Character component4 = gameObject.GetComponent<Character>(); |
| Character component4 = gameObject.GetComponent<Character>(); |
| if (component4) |
| if (component4) |
| { |
| { |
| int num5 = num2; |
| int num5 = num2; |
| while (num5 < num3 && UnityEngine.Random.Range(0f, 100f) <= SpawnSystem.GetLevelUpChance(num4)) |
| while (num5 < num3 && UnityEngine.Random.Range(0f, 100f) <= SpawnSystem.GetLevelUpChance(num4)) |
| { |
| { |
| num5++; |
| num5++; |
| } |
| } |
| if (num5 > 1) |
| if (num5 > 1) |
| { |
| { |
| component4.SetLevel(num5); |
| component4.SetLevel(num5); |
| } |
| } |
| } |
| } |
| else |
| else |
| { |
| { |
| ItemDrop component5 = gameObject.GetComponent<ItemDrop>(); |
| ItemDrop component5 = gameObject.GetComponent<ItemDrop>(); |
| if (component5) |
| if (component5) |
| { |
| { |
| int num6 = num2; |
| int num6 = num2; |
| while (num6 < num3 && UnityEngine.Random.Range(0f, 100f) <= num4) |
| while (num6 < num3 && UnityEngine.Random.Range(0f, 100f) <= num4) |
| { |
| { |
| num6++; |
| num6++; |
| } |
| } |
| if (num6 > 1) |
| if (num6 > 1) |
| { |
| { |
| component5.SetQuality(num6); |
| component5.SetQuality(num6); |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| this.m_nview.GetZDO().SetConnection(ZDOExtraData.ConnectionType.Spawned, component.GetZDO().m_uid); |
| this.m_nview.GetZDO().SetConnection(ZDOExtraData.ConnectionType.Spawned, component.GetZDO().m_uid); |
| this.m_nview.GetZDO().Set(ZDOVars.s_aliveTime, ZNet.instance.GetTime().Ticks); |
| this.m_nview.GetZDO().Set(ZDOVars.s_aliveTime, ZNet.instance.GetTime().Ticks); |
| this.SpawnEffect(gameObject); |
| this.SpawnEffect(gameObject); |
| return component; |
| return component; |
| } |
| } |
| |
| |
| private void SpawnEffect(GameObject spawnedObject) |
| private void SpawnEffect(GameObject spawnedObject) |
| { |
| { |
| Character component = spawnedObject.GetComponent<Character>(); |
| Character component = spawnedObject.GetComponent<Character>(); |
| Vector3 vector = (component ? component.GetCenterPoint() : (base.transform.position + Vector3.up * 0.75f)); |
| Vector3 vector = (component ? component.GetCenterPoint() : (base.transform.position + Vector3.up * 0.75f)); |
| this.m_spawnEffects.Create(vector, Quaternion.identity, null, 1f, -1); |
| this.m_spawnEffects.Create(vector, Quaternion.identity, null, 1f, -1); |
| } |
| } |
| |
| |
| private float GetRadius() |
| private float GetRadius() |
| { |
| { |
| return 0.75f; |
| return 0.75f; |
| } |
| } |
| |
| |
| private void OnDrawGizmos() |
| private void OnDrawGizmos() |
| { |
| { |
| } |
| } |
| |
| |
| private bool CheckGroupSpawnBlocked() |
| private bool CheckGroupSpawnBlocked() |
| { |
| { |
| if (this.m_spawnGroupRadius <= 0f || this.m_maxGroupSpawned < 1) |
| if (this.m_spawnGroupRadius <= 0f || this.m_maxGroupSpawned < 1) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| if (this.m_spawnGroup == null) |
| if (this.m_spawnGroup == null) |
| { |
| { |
| CreatureSpawner.m_groupNew.Clear(); |
| CreatureSpawner.m_groupNew.Clear(); |
| CreatureSpawner.m_grouped.Clear(); |
| CreatureSpawner.m_grouped.Clear(); |
| CreatureSpawner.m_groupUnchecked.Clear(); |
| CreatureSpawner.m_groupUnchecked.Clear(); |
| CreatureSpawner.m_groupUnchecked.AddRange(CreatureSpawner.m_creatureSpawners); |
| CreatureSpawner.m_groupUnchecked.AddRange(CreatureSpawner.m_creatureSpawners); |
| CreatureSpawner.m_groupUnchecked.Remove(this); |
| CreatureSpawner.m_groupUnchecked.Remove(this); |
| CreatureSpawner.m_groupNew.Push(this); |
| CreatureSpawner.m_groupNew.Push(this); |
| CreatureSpawner.m_grouped.Add(this); |
| CreatureSpawner.m_grouped.Add(this); |
| while (CreatureSpawner.m_groupNew.Count > 0) |
| while (CreatureSpawner.m_groupNew.Count > 0) |
| { |
| { |
| CreatureSpawner creatureSpawner = CreatureSpawner.m_groupNew.Pop(); |
| CreatureSpawner creatureSpawner = CreatureSpawner.m_groupNew.Pop(); |
| for (int i = CreatureSpawner.m_groupUnchecked.Count - 1; i >= 0; i--) |
| for (int i = CreatureSpawner.m_groupUnchecked.Count - 1; i >= 0; i--) |
| { |
| { |
| CreatureSpawner creatureSpawner2 = CreatureSpawner.m_groupUnchecked[i]; |
| CreatureSpawner creatureSpawner2 = CreatureSpawner.m_groupUnchecked[i]; |
| if (creatureSpawner.m_spawnGroupID == creatureSpawner2.m_spawnGroupID && Vector3.Distance(creatureSpawner.transform.position, creatureSpawner2.transform.position) <= creatureSpawner.m_spawnGroupRadius + creatureSpawner2.m_spawnGroupRadius) |
| if (creatureSpawner.m_spawnGroupID == creatureSpawner2.m_spawnGroupID && Vector3.Distance(creatureSpawner.transform.position, creatureSpawner2.transform.position) <= creatureSpawner.m_spawnGroupRadius + creatureSpawner2.m_spawnGroupRadius) |
| { |
| { |
| CreatureSpawner.m_groupNew.Push(creatureSpawner2); |
| CreatureSpawner.m_groupNew.Push(creatureSpawner2); |
| CreatureSpawner.m_grouped.Add(creatureSpawner2); |
| CreatureSpawner.m_grouped.Add(creatureSpawner2); |
| CreatureSpawner.m_groupUnchecked.Remove(creatureSpawner2); |
| CreatureSpawner.m_groupUnchecked.Remove(creatureSpawner2); |
| } |
| } |
| } |
| } |
| } |
| } |
| CreatureSpawner.m_groups.Clear(); |
| CreatureSpawner.m_groups.Clear(); |
| foreach (CreatureSpawner creatureSpawner3 in CreatureSpawner.m_grouped) |
| foreach (CreatureSpawner creatureSpawner3 in CreatureSpawner.m_grouped) |
| { |
| { |
| if (creatureSpawner3.m_spawnGroup != null) |
| if (creatureSpawner3.m_spawnGroup != null) |
| { |
| { |
| CreatureSpawner.m_groups.Add(creatureSpawner3.m_spawnGroup); |
| CreatureSpawner.m_groups.Add(creatureSpawner3.m_spawnGroup); |
| } |
| } |
| } |
| } |
| CreatureSpawner.Group group = null; |
| CreatureSpawner.Group group = null; |
| if (CreatureSpawner.m_groups.Count > 0) |
| if (CreatureSpawner.m_groups.Count > 0) |
| { |
| { |
| if (CreatureSpawner.m_groups.Count > 1) |
| if (CreatureSpawner.m_groups.Count > 1) |
| { |
| { |
| ZLog.Log(string.Format("{0} {1} merged for {2} spawners.", CreatureSpawner.m_groups.Count, "Group", CreatureSpawner.m_grouped.Count)); |
| ZLog.Log(string.Format("{0} {1} merged for {2} spawners.", CreatureSpawner.m_groups.Count, "Group", CreatureSpawner.m_grouped.Count)); |
| } |
| } |
| group = CreatureSpawner.m_groups[0]; |
| group = CreatureSpawner.m_groups[0]; |
| } |
| } |
| else |
| else |
| { |
| { |
| group = new CreatureSpawner.Group(); |
| group = new CreatureSpawner.Group(); |
| } |
| } |
| foreach (CreatureSpawner creatureSpawner4 in CreatureSpawner.m_grouped) |
| foreach (CreatureSpawner creatureSpawner4 in CreatureSpawner.m_grouped) |
| { |
| { |
| group.Add(creatureSpawner4); |
| group.Add(creatureSpawner4); |
| creatureSpawner4.m_spawnGroup = group; |
| creatureSpawner4.m_spawnGroup = group; |
| } |
| } |
| ZLog.Log(string.Format("{0} created for {1} spawners.", "Group", group.Count)); |
| ZLog.Log(string.Format("{0} created for {1} spawners.", "Group", group.Count)); |
| } |
| } |
| int num; |
| int num; |
| int num2; |
| int num2; |
| this.m_spawnGroup.CountSpawns(out num, out num2); |
| this.m_spawnGroup.CountSpawns(out num, out num2); |
| if (this.m_respawnTimeMinuts <= 0f) |
| if (this.m_respawnTimeMinuts <= 0f) |
| { |
| { |
| if (num2 < this.m_maxGroupSpawned && num < this.m_maxGroupSpawned) |
| if (num2 < this.m_maxGroupSpawned && num < this.m_maxGroupSpawned) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| Terminal.Log(string.Format("Group spawnID #{0} blocked: I have not spawned, but someone else has made us reach the maximum, abort!", this.m_spawnGroupID)); |
| Terminal.Log(string.Format("Group spawnID #{0} blocked: I have not spawned, but someone else has made us reach the maximum, abort!", this.m_spawnGroupID)); |
| return true; |
| return true; |
| } |
| } |
| else |
| else |
| { |
| { |
| if (num < this.m_maxGroupSpawned) |
| if (num < this.m_maxGroupSpawned) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| Terminal.Log(string.Format("Group spawnID #{0} blocked: I allow respawning, but we are currently at our maxium, abort!", this.m_spawnGroupID)); |
| Terminal.Log(string.Format("Group spawnID #{0} blocked: I allow respawning, but we are currently at our maxium, abort!", this.m_spawnGroupID)); |
| return true; |
| return true; |
| } |
| } |
| } |
| } |
| |
| |
| private const float m_radius = 0.75f; |
| private const float m_radius = 0.75f; |
| |
| |
| public GameObject m_creaturePrefab; |
| public GameObject m_creaturePrefab; |
| |
| |
| [Header("Level")] |
| [Header("Level")] |
| public int m_maxLevel = 1; |
| public int m_maxLevel = 1; |
| |
| |
| public int m_minLevel = 1; |
| public int m_minLevel = 1; |
| |
| |
| public float m_levelupChance = 10f; |
| public float m_levelupChance = 10f; |
| |
| |
| [Header("Spawn settings")] |
| [Header("Spawn settings")] |
| public float m_respawnTimeMinuts = 20f; |
| public float m_respawnTimeMinuts = 20f; |
| |
| |
| public float m_triggerDistance = 60f; |
| public float m_triggerDistance = 60f; |
| |
| |
| public float m_triggerNoise; |
| public float m_triggerNoise; |
| |
| |
| public bool m_spawnAtNight = true; |
| public bool m_spawnAtNight = true; |
| |
| |
| public bool m_spawnAtDay = true; |
| public bool m_spawnAtDay = true; |
| |
| |
| public bool m_requireSpawnArea; |
| public bool m_requireSpawnArea; |
| |
| |
| public bool m_spawnInPlayerBase; |
| public bool m_spawnInPlayerBase; |
| |
| |
| public bool m_wakeUpAnimation; |
| public bool m_wakeUpAnimation; |
| |
| |
| public int m_spawnInterval = 5; |
| public int m_spawnInterval = 5; |
| |
| |
| public string m_requiredGlobalKey = ""; |
| public string m_requiredGlobalKey = ""; |
| |
| |
| public string m_blockingGlobalKey = ""; |
| public string m_blockingGlobalKey = ""; |
| |
| |
| public bool m_setPatrolSpawnPoint; |
| public bool m_setPatrolSpawnPoint; |
| |
| |
| [Header("Spawn group blocking")] |
| [Header("Spawn group blocking")] |
| [global::Tooltip("Spawners sharing the same ID within eachothers radiuses will be grouped together, and will never spawn more than the specified max group size. Weight will also be taken into account, prioritizing those with higher weight randomly.")] |
| [global::Tooltip("Spawners sharing the same ID within eachothers radiuses will be grouped together, and will never spawn more than the specified max group size. Weight will also be taken into account, prioritizing those with higher weight randomly.")] |
| public int m_spawnGroupID; |
| public int m_spawnGroupID; |
| |
| |
| public int m_maxGroupSpawned = 1; |
| public int m_maxGroupSpawned = 1; |
| |
| |
| public float m_spawnGroupRadius; |
| public float m_spawnGroupRadius; |
| |
| |
| public float m_spawnerWeight = 1f; |
| public float m_spawnerWeight = 1f; |
| |
| |
| [Space] |
| [Space] |
| public EffectList m_spawnEffects = new EffectList(); |
| public EffectList m_spawnEffects = new EffectList(); |
| |
| |
| private ZNetView m_nview; |
| private ZNetView m_nview; |
| |
| |
| private CreatureSpawner.Group m_spawnGroup; |
| private CreatureSpawner.Group m_spawnGroup; |
| |
| |
| private ZDOID m_lastSpawnID; |
| private ZDOID m_lastSpawnID; |
| |
| |
| private bool m_checkedLocation; |
| private bool m_checkedLocation; |
| |
| |
| private Location m_location; |
| private Location m_location; |
| |
| |
| private static List<CreatureSpawner> m_creatureSpawners = new List<CreatureSpawner>(); |
| private static List<CreatureSpawner> m_creatureSpawners = new List<CreatureSpawner>(); |
| |
| |
| private static List<CreatureSpawner> m_groupUnchecked = new List<CreatureSpawner>(); |
| private static List<CreatureSpawner> m_groupUnchecked = new List<CreatureSpawner>(); |
| |
| |
| private static HashSet<CreatureSpawner> m_grouped = new HashSet<CreatureSpawner>(); |
| private static HashSet<CreatureSpawner> m_grouped = new HashSet<CreatureSpawner>(); |
| |
| |
| private static Stack<CreatureSpawner> m_groupNew = new Stack<CreatureSpawner>(); |
| private static Stack<CreatureSpawner> m_groupNew = new Stack<CreatureSpawner>(); |
| |
| |
| private static List<CreatureSpawner.Group> m_groups = new List<CreatureSpawner.Group>(); |
| private static List<CreatureSpawner.Group> m_groups = new List<CreatureSpawner.Group>(); |
| |
| |
| public class Group : HashSet<CreatureSpawner> |
| public class Group : HashSet<CreatureSpawner> |
| { |
| { |
| public void CountSpawns(out int spawnedNow, out int spawnedEver) |
| public void CountSpawns(out int spawnedNow, out int spawnedEver) |
| { |
| { |
| spawnedNow = (spawnedEver = 0); |
| spawnedNow = (spawnedEver = 0); |
| foreach (CreatureSpawner creatureSpawner in this) |
| foreach (CreatureSpawner creatureSpawner in this) |
| { |
| { |
| if (!(creatureSpawner.m_nview == null) && creatureSpawner.m_nview.GetZDO() != null) |
| if (!(creatureSpawner.m_nview == null) && creatureSpawner.m_nview.GetZDO() != null) |
| { |
| { |
| creatureSpawner.m_lastSpawnID = creatureSpawner.m_nview.GetZDO().GetConnectionZDOID(ZDOExtraData.ConnectionType.Spawned); |
| creatureSpawner.m_lastSpawnID = creatureSpawner.m_nview.GetZDO().GetConnectionZDOID(ZDOExtraData.ConnectionType.Spawned); |
| if (creatureSpawner.m_nview.GetZDO().GetConnectionType() != ZDOExtraData.ConnectionType.None) |
| if (creatureSpawner.m_nview.GetZDO().GetConnectionType() != ZDOExtraData.ConnectionType.None) |
| { |
| { |
| spawnedEver++; |
| spawnedEver++; |
| creatureSpawner.m_lastSpawnID = creatureSpawner.m_nview.GetZDO().GetConnectionZDOID(ZDOExtraData.ConnectionType.Spawned); |
| creatureSpawner.m_lastSpawnID = creatureSpawner.m_nview.GetZDO().GetConnectionZDOID(ZDOExtraData.ConnectionType.Spawned); |
| if (ZDOMan.instance.GetZDO(creatureSpawner.m_lastSpawnID) != null) |
| if (ZDOMan.instance.GetZDO(creatureSpawner.m_lastSpawnID) != null) |
| { |
| { |
| spawnedNow++; |
| spawnedNow++; |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| public void SpawnWeighted() |
| public void SpawnWeighted() |
| { |
| { |
| this.m_activeSpawners.Clear(); |
| this.m_activeSpawners.Clear(); |
| float num = 0f; |
| float num = 0f; |
| foreach (CreatureSpawner creatureSpawner in this) |
| foreach (CreatureSpawner creatureSpawner in this) |
| { |
| { |
| if (creatureSpawner.m_lastSpawnID.IsNone() || (creatureSpawner.CanRespawnNow(creatureSpawner.m_lastSpawnID) && !creatureSpawner.SpawnedCreatureStillExists(creatureSpawner.m_lastSpawnID))) |
| if (creatureSpawner.m_lastSpawnID.IsNone() || (creatureSpawner.CanRespawnNow(creatureSpawner.m_lastSpawnID) && !creatureSpawner.SpawnedCreatureStillExists(creatureSpawner.m_lastSpawnID))) |
| { |
| { |
| this.m_activeSpawners.Add(creatureSpawner); |
| this.m_activeSpawners.Add(creatureSpawner); |
| num += creatureSpawner.m_spawnerWeight; |
| num += creatureSpawner.m_spawnerWeight; |
| } |
| } |
| } |
| } |
| float num2 = UnityEngine.Random.Range(0f, num); |
| float num2 = UnityEngine.Random.Range(0f, num); |
| float num3 = 0f; |
| float num3 = 0f; |
| foreach (CreatureSpawner creatureSpawner2 in this.m_activeSpawners) |
| foreach (CreatureSpawner creatureSpawner2 in this.m_activeSpawners) |
| { |
| { |
| num3 += creatureSpawner2.m_spawnerWeight; |
| num3 += creatureSpawner2.m_spawnerWeight; |
| if (num2 < num3) |
| if (num2 < num3) |
| { |
| { |
| creatureSpawner2.Spawn(); |
| creatureSpawner2.Spawn(); |
| return; |
| return; |
| } |
| } |
| } |
| } |
| ZLog.LogError("No active spawners for group but something is still calling it!"); |
| ZLog.LogError("No active spawners for group but something is still calling it!"); |
| } |
| } |
| |
| |
| private readonly List<CreatureSpawner> m_activeSpawners = new List<CreatureSpawner>(); |
| private readonly List<CreatureSpawner> m_activeSpawners = new List<CreatureSpawner>(); |
| } |
| } |
| } |
| } |
| |
| |