| using System; |
| using System; |
| using UnityEngine; |
| using UnityEngine; |
| |
| |
| public class Procreation : MonoBehaviour |
| public class Procreation : MonoBehaviour |
| { |
| { |
| private void Awake() |
| private void Awake() |
| { |
| { |
| this.m_nview = base.GetComponent<ZNetView>(); |
| this.m_nview = base.GetComponent<ZNetView>(); |
| this.m_baseAI = base.GetComponent<BaseAI>(); |
| this.m_baseAI = base.GetComponent<BaseAI>(); |
| this.m_character = base.GetComponent<Character>(); |
| this.m_character = base.GetComponent<Character>(); |
| this.m_tameable = base.GetComponent<Tameable>(); |
| this.m_tameable = base.GetComponent<Tameable>(); |
| base.InvokeRepeating("Procreate", UnityEngine.Random.Range(this.m_updateInterval, this.m_updateInterval + this.m_updateInterval * 0.5f), this.m_updateInterval); |
| base.InvokeRepeating("Procreate", UnityEngine.Random.Range(this.m_updateInterval, this.m_updateInterval + this.m_updateInterval * 0.5f), this.m_updateInterval); |
| } |
| } |
| |
| |
| private void Procreate() |
| private void Procreate() |
| { |
| { |
| if (!this.m_nview.IsValid() || !this.m_nview.IsOwner()) |
| if (!this.m_nview.IsValid() || !this.m_nview.IsOwner()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (!this.m_character.IsTamed()) |
| if (!this.m_character.IsTamed()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (this.m_offspringPrefab == null) |
| if (this.m_offspringPrefab == null) |
| { |
| { |
| string prefabName = Utils.GetPrefabName(this.m_offspring); |
| string prefabName = Utils.GetPrefabName(this.m_offspring); |
| this.m_offspringPrefab = ZNetScene.instance.GetPrefab(prefabName); |
| this.m_offspringPrefab = ZNetScene.instance.GetPrefab(prefabName); |
| int prefab = this.m_nview.GetZDO().GetPrefab(); |
| int prefab = this.m_nview.GetZDO().GetPrefab(); |
| this.m_myPrefab = ZNetScene.instance.GetPrefab(prefab); |
| this.m_myPrefab = ZNetScene.instance.GetPrefab(prefab); |
| } |
| } |
| if (this.IsPregnant()) |
| if (this.IsPregnant()) |
| { |
| { |
| if (this.IsDue()) |
| if (this.IsDue()) |
| { |
| { |
| this.ResetPregnancy(); |
| this.ResetPregnancy(); |
| GameObject gameObject = this.m_offspringPrefab; |
| GameObject gameObject = this.m_offspringPrefab; |
| if (this.m_noPartnerOffspring) |
| if (this.m_noPartnerOffspring) |
| { |
| { |
| int nrOfInstances = SpawnSystem.GetNrOfInstances(this.m_seperatePartner ? this.m_seperatePartner : this.m_myPrefab, base.transform.position, this.m_partnerCheckRange, false, true); |
| int nrOfInstances = SpawnSystem.GetNrOfInstances(this.m_seperatePartner ? this.m_seperatePartner : this.m_myPrefab, base.transform.position, this.m_partnerCheckRange, false, true); |
| if ((!this.m_seperatePartner && nrOfInstances < 2) || (this.m_seperatePartner && nrOfInstances < 1)) |
| if ((!this.m_seperatePartner && nrOfInstances < 2) || (this.m_seperatePartner && nrOfInstances < 1)) |
| { |
| { |
| gameObject = this.m_noPartnerOffspring; |
| gameObject = this.m_noPartnerOffspring; |
| } |
| } |
| } |
| } |
| GameObject gameObject2 = UnityEngine.Object.Instantiate<GameObject>(gameObject, base.transform.position - base.transform.forward * this.m_spawnOffset, Quaternion.LookRotation(-base.transform.forward, Vector3.up)); |
| GameObject gameObject2 = UnityEngine.Object.Instantiate<GameObject>(gameObject, base.transform.position - base.transform.forward * this.m_spawnOffset, Quaternion.LookRotation(-base.transform.forward, Vector3.up)); |
| Character component = gameObject2.GetComponent<Character>(); |
| Character component = gameObject2.GetComponent<Character>(); |
| if (component) |
| if (component) |
| { |
| { |
| component.SetTamed(this.m_character.IsTamed()); |
| component.SetTamed(this.m_character.IsTamed()); |
| component.SetLevel(Mathf.Max(this.m_minOffspringLevel, this.m_character.GetLevel())); |
| component.SetLevel(Mathf.Max(this.m_minOffspringLevel, this.m_character.GetLevel())); |
| } |
| } |
| . | |
| else |
| |
| { |
| |
| ItemDrop component2 = gameObject2.GetComponent<ItemDrop>(); |
| |
| if (component2 != null) |
| |
| { |
| |
| component2.SetQuality(Mathf.Max(this.m_minOffspringLevel, this.m_character.GetLevel())); |
| |
| } |
| |
| } |
| this.m_birthEffects.Create(gameObject2.transform.position, Quaternion.identity, null, 1f, -1); |
| this.m_birthEffects.Create(gameObject2.transform.position, Quaternion.identity, null, 1f, -1); |
| return; |
| return; |
| } |
| } |
| } |
| } |
| else |
| else |
| { |
| { |
| if (UnityEngine.Random.value <= this.m_pregnancyChance) |
| if (UnityEngine.Random.value <= this.m_pregnancyChance) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (this.m_baseAI.IsAlerted()) |
| if (this.m_baseAI.IsAlerted()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (this.m_tameable.IsHungry()) |
| if (this.m_tameable.IsHungry()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| int nrOfInstances2 = SpawnSystem.GetNrOfInstances(this.m_myPrefab, base.transform.position, this.m_totalCheckRange, false, false); |
| int nrOfInstances2 = SpawnSystem.GetNrOfInstances(this.m_myPrefab, base.transform.position, this.m_totalCheckRange, false, false); |
| int nrOfInstances3 = SpawnSystem.GetNrOfInstances(this.m_offspringPrefab, base.transform.position, this.m_totalCheckRange, false, false); |
| int nrOfInstances3 = SpawnSystem.GetNrOfInstances(this.m_offspringPrefab, base.transform.position, this.m_totalCheckRange, false, false); |
| if (nrOfInstances2 + nrOfInstances3 >= this.m_maxCreatures) |
| if (nrOfInstances2 + nrOfInstances3 >= this.m_maxCreatures) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| int nrOfInstances4 = SpawnSystem.GetNrOfInstances(this.m_seperatePartner ? this.m_seperatePartner : this.m_myPrefab, base.transform.position, this.m_partnerCheckRange, false, true); |
| int nrOfInstances4 = SpawnSystem.GetNrOfInstances(this.m_seperatePartner ? this.m_seperatePartner : this.m_myPrefab, base.transform.position, this.m_partnerCheckRange, false, true); |
| if (!this.m_noPartnerOffspring && ((!this.m_seperatePartner && nrOfInstances4 < 2) || (this.m_seperatePartner && nrOfInstances4 < 1))) |
| if (!this.m_noPartnerOffspring && ((!this.m_seperatePartner && nrOfInstances4 < 2) || (this.m_seperatePartner && nrOfInstances4 < 1))) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (nrOfInstances4 > 0) |
| if (nrOfInstances4 > 0) |
| { |
| { |
| this.m_loveEffects.Create(base.transform.position, base.transform.rotation, null, 1f, -1); |
| this.m_loveEffects.Create(base.transform.position, base.transform.rotation, null, 1f, -1); |
| } |
| } |
| int num = this.m_nview.GetZDO().GetInt(ZDOVars.s_lovePoints, 0); |
| int num = this.m_nview.GetZDO().GetInt(ZDOVars.s_lovePoints, 0); |
| num++; |
| num++; |
| this.m_nview.GetZDO().Set(ZDOVars.s_lovePoints, num, false); |
| this.m_nview.GetZDO().Set(ZDOVars.s_lovePoints, num, false); |
| if (num >= this.m_requiredLovePoints) |
| if (num >= this.m_requiredLovePoints) |
| { |
| { |
| this.m_nview.GetZDO().Set(ZDOVars.s_lovePoints, 0, false); |
| this.m_nview.GetZDO().Set(ZDOVars.s_lovePoints, 0, false); |
| this.MakePregnant(); |
| this.MakePregnant(); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| public bool ReadyForProcreation() |
| public bool ReadyForProcreation() |
| { |
| { |
| return this.m_character.IsTamed() && !this.IsPregnant() && !this.m_tameable.IsHungry(); |
| return this.m_character.IsTamed() && !this.IsPregnant() && !this.m_tameable.IsHungry(); |
| } |
| } |
| |
| |
| private void MakePregnant() |
| private void MakePregnant() |
| { |
| { |
| this.m_nview.GetZDO().Set(ZDOVars.s_pregnant, ZNet.instance.GetTime().Ticks); |
| this.m_nview.GetZDO().Set(ZDOVars.s_pregnant, ZNet.instance.GetTime().Ticks); |
| } |
| } |
| |
| |
| private void ResetPregnancy() |
| private void ResetPregnancy() |
| { |
| { |
| this.m_nview.GetZDO().Set(ZDOVars.s_pregnant, 0L); |
| this.m_nview.GetZDO().Set(ZDOVars.s_pregnant, 0L); |
| } |
| } |
| |
| |
| private bool IsDue() |
| private bool IsDue() |
| { |
| { |
| long @long = this.m_nview.GetZDO().GetLong(ZDOVars.s_pregnant, 0L); |
| long @long = this.m_nview.GetZDO().GetLong(ZDOVars.s_pregnant, 0L); |
| if (@long == 0L) |
| if (@long == 0L) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| DateTime dateTime = new DateTime(@long); |
| DateTime dateTime = new DateTime(@long); |
| return (ZNet.instance.GetTime() - dateTime).TotalSeconds > (double)this.m_pregnancyDuration; |
| return (ZNet.instance.GetTime() - dateTime).TotalSeconds > (double)this.m_pregnancyDuration; |
| } |
| } |
| |
| |
| private bool IsPregnant() |
| private bool IsPregnant() |
| { |
| { |
| return this.m_nview.IsValid() && this.m_nview.GetZDO().GetLong(ZDOVars.s_pregnant, 0L) != 0L; |
| return this.m_nview.IsValid() && this.m_nview.GetZDO().GetLong(ZDOVars.s_pregnant, 0L) != 0L; |
| } |
| } |
| |
| |
| public float m_updateInterval = 10f; |
| public float m_updateInterval = 10f; |
| |
| |
| public float m_totalCheckRange = 10f; |
| public float m_totalCheckRange = 10f; |
| |
| |
| public int m_maxCreatures = 4; |
| public int m_maxCreatures = 4; |
| |
| |
| public float m_partnerCheckRange = 3f; |
| public float m_partnerCheckRange = 3f; |
| |
| |
| public float m_pregnancyChance = 0.5f; |
| public float m_pregnancyChance = 0.5f; |
| |
| |
| public float m_pregnancyDuration = 10f; |
| public float m_pregnancyDuration = 10f; |
| |
| |
| public int m_requiredLovePoints = 4; |
| public int m_requiredLovePoints = 4; |
| |
| |
| public GameObject m_offspring; |
| public GameObject m_offspring; |
| |
| |
| public int m_minOffspringLevel; |
| public int m_minOffspringLevel; |
| |
| |
| public float m_spawnOffset = 2f; |
| public float m_spawnOffset = 2f; |
| |
| |
| public GameObject m_seperatePartner; |
| public GameObject m_seperatePartner; |
| |
| |
| public GameObject m_noPartnerOffspring; |
| public GameObject m_noPartnerOffspring; |
| |
| |
| public EffectList m_birthEffects = new EffectList(); |
| public EffectList m_birthEffects = new EffectList(); |
| |
| |
| public EffectList m_loveEffects = new EffectList(); |
| public EffectList m_loveEffects = new EffectList(); |
| |
| |
| private GameObject m_myPrefab; |
| private GameObject m_myPrefab; |
| |
| |
| private GameObject m_offspringPrefab; |
| private GameObject m_offspringPrefab; |
| |
| |
| private ZNetView m_nview; |
| private ZNetView m_nview; |
| |
| |
| private BaseAI m_baseAI; |
| private BaseAI m_baseAI; |
| |
| |
| private Character m_character; |
| private Character m_character; |
| |
| |
| private Tameable m_tameable; |
| private Tameable m_tameable; |
| } |
| } |
| |
| |