| using System; |
| using System; |
| using UnityEngine; |
| using UnityEngine; |
| |
| |
| public class Beehive : MonoBehaviour, Hoverable, Interactable |
| public class Beehive : MonoBehaviour, Hoverable, Interactable |
| { |
| { |
| private void Awake() |
| private void Awake() |
| { |
| { |
| this.m_nview = base.GetComponent<ZNetView>(); |
| this.m_nview = base.GetComponent<ZNetView>(); |
| this.m_collider = base.GetComponentInChildren<Collider>(); |
| this.m_collider = base.GetComponentInChildren<Collider>(); |
| this.m_piece = base.GetComponent<Piece>(); |
| this.m_piece = base.GetComponent<Piece>(); |
| if (this.m_nview.GetZDO() == null) |
| if (this.m_nview.GetZDO() == null) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (this.m_nview.IsOwner() && this.m_nview.GetZDO().GetLong(ZDOVars.s_lastTime, 0L) == 0L) |
| if (this.m_nview.IsOwner() && this.m_nview.GetZDO().GetLong(ZDOVars.s_lastTime, 0L) == 0L) |
| { |
| { |
| this.m_nview.GetZDO().Set(ZDOVars.s_lastTime, ZNet.instance.GetTime().Ticks); |
| this.m_nview.GetZDO().Set(ZDOVars.s_lastTime, ZNet.instance.GetTime().Ticks); |
| } |
| } |
| this.m_nview.Register("RPC_Extract", new Action<long>(this.RPC_Extract)); |
| this.m_nview.Register("RPC_Extract", new Action<long>(this.RPC_Extract)); |
| base.InvokeRepeating("UpdateBees", 0f, 10f); |
| base.InvokeRepeating("UpdateBees", 0f, 10f); |
| } |
| } |
| |
| |
| public string GetHoverText() |
| public string GetHoverText() |
| { |
| { |
| if (!PrivateArea.CheckAccess(base.transform.position, 0f, false, false)) |
| if (!PrivateArea.CheckAccess(base.transform.position, 0f, false, false)) |
| { |
| { |
| return Localization.instance.Localize(this.m_name + "\n$piece_noaccess"); |
| return Localization.instance.Localize(this.m_name + "\n$piece_noaccess"); |
| } |
| } |
| int honeyLevel = this.GetHoneyLevel(); |
| int honeyLevel = this.GetHoneyLevel(); |
| if (honeyLevel > 0) |
| if (honeyLevel > 0) |
| { |
| { |
| return Localization.instance.Localize(string.Format("{0} ( {1} x {2} )\n[<color=yellow><b>$KEY_Use</b></color>] {3}", new object[] |
| return Localization.instance.Localize(string.Format("{0} ( {1} x {2} )\n[<color=yellow><b>$KEY_Use</b></color>] {3}", new object[] |
| { |
| { |
| this.m_name, |
| this.m_name, |
| this.m_honeyItem.m_itemData.m_shared.m_name, |
| this.m_honeyItem.m_itemData.m_shared.m_name, |
| honeyLevel, |
| honeyLevel, |
| this.m_extractText |
| this.m_extractText |
| })); |
| })); |
| } |
| } |
| return Localization.instance.Localize(this.m_name + " ( $piece_container_empty )\n[<color=yellow><b>$KEY_Use</b></color>] " + this.m_checkText); |
| return Localization.instance.Localize(this.m_name + " ( $piece_container_empty )\n[<color=yellow><b>$KEY_Use</b></color>] " + this.m_checkText); |
| } |
| } |
| |
| |
| public string GetHoverName() |
| public string GetHoverName() |
| { |
| { |
| return this.m_name; |
| return this.m_name; |
| } |
| } |
| |
| |
| public bool Interact(Humanoid character, bool repeat, bool alt) |
| public bool Interact(Humanoid character, bool repeat, bool alt) |
| { |
| { |
| if (repeat) |
| if (repeat) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| if (!PrivateArea.CheckAccess(base.transform.position, 0f, true, false)) |
| if (!PrivateArea.CheckAccess(base.transform.position, 0f, true, false)) |
| { |
| { |
| return true; |
| return true; |
| } |
| } |
| if (this.GetHoneyLevel() > 0) |
| if (this.GetHoneyLevel() > 0) |
| { |
| { |
| this.Extract(); |
| this.Extract(); |
| Game.instance.IncrementPlayerStat(PlayerStatType.BeesHarvested, 1f); |
| Game.instance.IncrementPlayerStat(PlayerStatType.BeesHarvested, 1f); |
| } |
| } |
| else |
| else |
| { |
| { |
| if (!this.CheckBiome()) |
| if (!this.CheckBiome()) |
| { |
| { |
| character.Message(MessageHud.MessageType.Center, this.m_areaText, 0, null); |
| character.Message(MessageHud.MessageType.Center, this.m_areaText, 0, null); |
| return true; |
| return true; |
| } |
| } |
| if (!this.HaveFreeSpace()) |
| if (!this.HaveFreeSpace()) |
| { |
| { |
| character.Message(MessageHud.MessageType.Center, this.m_freespaceText, 0, null); |
| character.Message(MessageHud.MessageType.Center, this.m_freespaceText, 0, null); |
| return true; |
| return true; |
| } |
| } |
| . | if (!EnvMan.instance.IsDaylight() && this.m_effectOnlyInDaylight) |
| if (!EnvMan.IsDaylight() && this.m_effectOnlyInDaylight) |
| { |
| { |
| character.Message(MessageHud.MessageType.Center, this.m_sleepText, 0, null); |
| character.Message(MessageHud.MessageType.Center, this.m_sleepText, 0, null); |
| return true; |
| return true; |
| } |
| } |
| character.Message(MessageHud.MessageType.Center, this.m_happyText, 0, null); |
| character.Message(MessageHud.MessageType.Center, this.m_happyText, 0, null); |
| } |
| } |
| return true; |
| return true; |
| } |
| } |
| |
| |
| public bool UseItem(Humanoid user, ItemDrop.ItemData item) |
| public bool UseItem(Humanoid user, ItemDrop.ItemData item) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| |
| |
| private void Extract() |
| private void Extract() |
| { |
| { |
| this.m_nview.InvokeRPC("RPC_Extract", Array.Empty<object>()); |
| this.m_nview.InvokeRPC("RPC_Extract", Array.Empty<object>()); |
| } |
| } |
| |
| |
| private void RPC_Extract(long caller) |
| private void RPC_Extract(long caller) |
| { |
| { |
| int honeyLevel = this.GetHoneyLevel(); |
| int honeyLevel = this.GetHoneyLevel(); |
| if (honeyLevel > 0) |
| if (honeyLevel > 0) |
| { |
| { |
| this.m_spawnEffect.Create(this.m_spawnPoint.position, Quaternion.identity, null, 1f, -1); |
| this.m_spawnEffect.Create(this.m_spawnPoint.position, Quaternion.identity, null, 1f, -1); |
| for (int i = 0; i < honeyLevel; i++) |
| for (int i = 0; i < honeyLevel; i++) |
| { |
| { |
| Vector2 vector = UnityEngine.Random.insideUnitCircle * 0.5f; |
| Vector2 vector = UnityEngine.Random.insideUnitCircle * 0.5f; |
| Vector3 vector2 = this.m_spawnPoint.position + new Vector3(vector.x, 0.25f * (float)i, vector.y); |
| Vector3 vector2 = this.m_spawnPoint.position + new Vector3(vector.x, 0.25f * (float)i, vector.y); |
| ItemDrop component = UnityEngine.Object.Instantiate<ItemDrop>(this.m_honeyItem, vector2, Quaternion.identity).GetComponent<ItemDrop>(); |
| ItemDrop component = UnityEngine.Object.Instantiate<ItemDrop>(this.m_honeyItem, vector2, Quaternion.identity).GetComponent<ItemDrop>(); |
| if (component != null) |
| if (component != null) |
| { |
| { |
| component.SetStack(Game.instance.ScaleDrops(this.m_honeyItem.m_itemData, 1)); |
| component.SetStack(Game.instance.ScaleDrops(this.m_honeyItem.m_itemData, 1)); |
| } |
| } |
| } |
| } |
| this.ResetLevel(); |
| this.ResetLevel(); |
| } |
| } |
| } |
| } |
| |
| |
| private float GetTimeSinceLastUpdate() |
| private float GetTimeSinceLastUpdate() |
| { |
| { |
| DateTime dateTime = new DateTime(this.m_nview.GetZDO().GetLong(ZDOVars.s_lastTime, ZNet.instance.GetTime().Ticks)); |
| DateTime dateTime = new DateTime(this.m_nview.GetZDO().GetLong(ZDOVars.s_lastTime, ZNet.instance.GetTime().Ticks)); |
| DateTime time = ZNet.instance.GetTime(); |
| DateTime time = ZNet.instance.GetTime(); |
| TimeSpan timeSpan = time - dateTime; |
| TimeSpan timeSpan = time - dateTime; |
| this.m_nview.GetZDO().Set(ZDOVars.s_lastTime, time.Ticks); |
| this.m_nview.GetZDO().Set(ZDOVars.s_lastTime, time.Ticks); |
| double num = timeSpan.TotalSeconds; |
| double num = timeSpan.TotalSeconds; |
| if (num < 0.0) |
| if (num < 0.0) |
| { |
| { |
| num = 0.0; |
| num = 0.0; |
| } |
| } |
| return (float)num; |
| return (float)num; |
| } |
| } |
| |
| |
| private void ResetLevel() |
| private void ResetLevel() |
| { |
| { |
| this.m_nview.GetZDO().Set(ZDOVars.s_level, 0, false); |
| this.m_nview.GetZDO().Set(ZDOVars.s_level, 0, false); |
| } |
| } |
| |
| |
| private void IncreseLevel(int i) |
| private void IncreseLevel(int i) |
| { |
| { |
| int num = this.GetHoneyLevel(); |
| int num = this.GetHoneyLevel(); |
| num += i; |
| num += i; |
| num = Mathf.Clamp(num, 0, this.m_maxHoney); |
| num = Mathf.Clamp(num, 0, this.m_maxHoney); |
| this.m_nview.GetZDO().Set(ZDOVars.s_level, num, false); |
| this.m_nview.GetZDO().Set(ZDOVars.s_level, num, false); |
| } |
| } |
| |
| |
| private int GetHoneyLevel() |
| private int GetHoneyLevel() |
| { |
| { |
| return this.m_nview.GetZDO().GetInt(ZDOVars.s_level, 0); |
| return this.m_nview.GetZDO().GetInt(ZDOVars.s_level, 0); |
| } |
| } |
| |
| |
| private void UpdateBees() |
| private void UpdateBees() |
| { |
| { |
| bool flag = this.CheckBiome() && this.HaveFreeSpace(); |
| bool flag = this.CheckBiome() && this.HaveFreeSpace(); |
| . | bool flag2 = flag && (!this.m_effectOnlyInDaylight || EnvMan.instance.IsDaylight()); |
| bool flag2 = flag && (!this.m_effectOnlyInDaylight || EnvMan.IsDaylight()); |
| this.m_beeEffect.SetActive(flag2); |
| this.m_beeEffect.SetActive(flag2); |
| if (this.m_nview.IsOwner() && flag) |
| if (this.m_nview.IsOwner() && flag) |
| { |
| { |
| float timeSinceLastUpdate = this.GetTimeSinceLastUpdate(); |
| float timeSinceLastUpdate = this.GetTimeSinceLastUpdate(); |
| float num = this.m_nview.GetZDO().GetFloat(ZDOVars.s_product, 0f); |
| float num = this.m_nview.GetZDO().GetFloat(ZDOVars.s_product, 0f); |
| num += timeSinceLastUpdate; |
| num += timeSinceLastUpdate; |
| if (num > this.m_secPerUnit) |
| if (num > this.m_secPerUnit) |
| { |
| { |
| int num2 = (int)(num / this.m_secPerUnit); |
| int num2 = (int)(num / this.m_secPerUnit); |
| this.IncreseLevel(num2); |
| this.IncreseLevel(num2); |
| num = 0f; |
| num = 0f; |
| } |
| } |
| this.m_nview.GetZDO().Set(ZDOVars.s_product, num); |
| this.m_nview.GetZDO().Set(ZDOVars.s_product, num); |
| } |
| } |
| } |
| } |
| |
| |
| private bool HaveFreeSpace() |
| private bool HaveFreeSpace() |
| { |
| { |
| if (this.m_maxCover <= 0f) |
| if (this.m_maxCover <= 0f) |
| { |
| { |
| return true; |
| return true; |
| } |
| } |
| float num; |
| float num; |
| bool flag; |
| bool flag; |
| Cover.GetCoverForPoint(this.m_coverPoint.position, out num, out flag, 0.5f); |
| Cover.GetCoverForPoint(this.m_coverPoint.position, out num, out flag, 0.5f); |
| return num < this.m_maxCover; |
| return num < this.m_maxCover; |
| } |
| } |
| |
| |
| private bool CheckBiome() |
| private bool CheckBiome() |
| { |
| { |
| return (Heightmap.FindBiome(base.transform.position) & this.m_biome) > Heightmap.Biome.None; |
| return (Heightmap.FindBiome(base.transform.position) & this.m_biome) > Heightmap.Biome.None; |
| } |
| } |
| |
| |
| public string m_name = ""; |
| public string m_name = ""; |
| |
| |
| public Transform m_coverPoint; |
| public Transform m_coverPoint; |
| |
| |
| public Transform m_spawnPoint; |
| public Transform m_spawnPoint; |
| |
| |
| public GameObject m_beeEffect; |
| public GameObject m_beeEffect; |
| |
| |
| public bool m_effectOnlyInDaylight = true; |
| public bool m_effectOnlyInDaylight = true; |
| |
| |
| public float m_maxCover = 0.25f; |
| public float m_maxCover = 0.25f; |
| |
| |
| [BitMask(typeof(Heightmap.Biome))] |
| [BitMask(typeof(Heightmap.Biome))] |
| public Heightmap.Biome m_biome; |
| public Heightmap.Biome m_biome; |
| |
| |
| public float m_secPerUnit = 10f; |
| public float m_secPerUnit = 10f; |
| |
| |
| public int m_maxHoney = 4; |
| public int m_maxHoney = 4; |
| |
| |
| public ItemDrop m_honeyItem; |
| public ItemDrop m_honeyItem; |
| |
| |
| public EffectList m_spawnEffect = new EffectList(); |
| public EffectList m_spawnEffect = new EffectList(); |
| |
| |
| [Header("Texts")] |
| [Header("Texts")] |
| public string m_extractText = "$piece_beehive_extract"; |
| public string m_extractText = "$piece_beehive_extract"; |
| |
| |
| public string m_checkText = "$piece_beehive_check"; |
| public string m_checkText = "$piece_beehive_check"; |
| |
| |
| public string m_areaText = "$piece_beehive_area"; |
| public string m_areaText = "$piece_beehive_area"; |
| |
| |
| public string m_freespaceText = "$piece_beehive_freespace"; |
| public string m_freespaceText = "$piece_beehive_freespace"; |
| |
| |
| public string m_sleepText = "$piece_beehive_sleep"; |
| public string m_sleepText = "$piece_beehive_sleep"; |
| |
| |
| public string m_happyText = "$piece_beehive_happy"; |
| public string m_happyText = "$piece_beehive_happy"; |
| |
| |
| public string m_notConnectedText; |
| public string m_notConnectedText; |
| |
| |
| public string m_blockedText; |
| public string m_blockedText; |
| |
| |
| private ZNetView m_nview; |
| private ZNetView m_nview; |
| |
| |
| private Collider m_collider; |
| private Collider m_collider; |
| |
| |
| private Piece m_piece; |
| private Piece m_piece; |
| |
| |
| private ZNetView m_connectedObject; |
| private ZNetView m_connectedObject; |
| |
| |
| private Piece m_blockingPiece; |
| private Piece m_blockingPiece; |
| } |
| } |
| |
| |