| using System; |
| using System; |
| using System.Collections.Generic; |
| using System.Collections.Generic; |
| using System.Text; |
| using System.Text; |
| using UnityEngine; |
| using UnityEngine; |
| |
| |
| public class Smelter : MonoBehaviour |
| public class Smelter : MonoBehaviour |
| { |
| { |
| private void Awake() |
| private void Awake() |
| { |
| { |
| this.m_nview = base.GetComponent<ZNetView>(); |
| this.m_nview = base.GetComponent<ZNetView>(); |
| . | |
| if (this.m_nview == null) |
| |
| { |
| |
| this.m_nview = base.GetComponentInParent<ZNetView>(); |
| |
| } |
| if (this.m_nview == null || this.m_nview.GetZDO() == null) |
| if (this.m_nview == null || this.m_nview.GetZDO() == null) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (this.m_addOreSwitch) |
| if (this.m_addOreSwitch) |
| { |
| { |
| Switch addOreSwitch = this.m_addOreSwitch; |
| Switch addOreSwitch = this.m_addOreSwitch; |
| addOreSwitch.m_onUse = (Switch.Callback)Delegate.Combine(addOreSwitch.m_onUse, new Switch.Callback(this.OnAddOre)); |
| addOreSwitch.m_onUse = (Switch.Callback)Delegate.Combine(addOreSwitch.m_onUse, new Switch.Callback(this.OnAddOre)); |
| this.m_addOreSwitch.m_onHover = new Switch.TooltipCallback(this.OnHoverAddOre); |
| this.m_addOreSwitch.m_onHover = new Switch.TooltipCallback(this.OnHoverAddOre); |
| } |
| } |
| if (this.m_addWoodSwitch) |
| if (this.m_addWoodSwitch) |
| { |
| { |
| Switch addWoodSwitch = this.m_addWoodSwitch; |
| Switch addWoodSwitch = this.m_addWoodSwitch; |
| addWoodSwitch.m_onUse = (Switch.Callback)Delegate.Combine(addWoodSwitch.m_onUse, new Switch.Callback(this.OnAddFuel)); |
| addWoodSwitch.m_onUse = (Switch.Callback)Delegate.Combine(addWoodSwitch.m_onUse, new Switch.Callback(this.OnAddFuel)); |
| this.m_addWoodSwitch.m_onHover = new Switch.TooltipCallback(this.OnHoverAddFuel); |
| this.m_addWoodSwitch.m_onHover = new Switch.TooltipCallback(this.OnHoverAddFuel); |
| } |
| } |
| if (this.m_emptyOreSwitch) |
| if (this.m_emptyOreSwitch) |
| { |
| { |
| Switch emptyOreSwitch = this.m_emptyOreSwitch; |
| Switch emptyOreSwitch = this.m_emptyOreSwitch; |
| emptyOreSwitch.m_onUse = (Switch.Callback)Delegate.Combine(emptyOreSwitch.m_onUse, new Switch.Callback(this.OnEmpty)); |
| emptyOreSwitch.m_onUse = (Switch.Callback)Delegate.Combine(emptyOreSwitch.m_onUse, new Switch.Callback(this.OnEmpty)); |
| Switch emptyOreSwitch2 = this.m_emptyOreSwitch; |
| Switch emptyOreSwitch2 = this.m_emptyOreSwitch; |
| emptyOreSwitch2.m_onHover = (Switch.TooltipCallback)Delegate.Combine(emptyOreSwitch2.m_onHover, new Switch.TooltipCallback(this.OnHoverEmptyOre)); |
| emptyOreSwitch2.m_onHover = (Switch.TooltipCallback)Delegate.Combine(emptyOreSwitch2.m_onHover, new Switch.TooltipCallback(this.OnHoverEmptyOre)); |
| } |
| } |
| . | this.m_nview.Register<string>("AddOre", new Action<long, string>(this.RPC_AddOre)); |
| this.m_nview.Register<string>("RPC_AddOre", new Action<long, string>(this.RPC_AddOre)); |
| this.m_nview.Register("AddFuel", new Action<long>(this.RPC_AddFuel)); |
| this.m_nview.Register("RPC_AddFuel", new Action<long>(this.RPC_AddFuel)); |
| this.m_nview.Register("EmptyProcessed", new Action<long>(this.RPC_EmptyProcessed)); |
| this.m_nview.Register("RPC_EmptyProcessed", new Action<long>(this.RPC_EmptyProcessed)); |
| WearNTear component = base.GetComponent<WearNTear>(); |
| WearNTear component = base.GetComponent<WearNTear>(); |
| if (component) |
| if (component) |
| { |
| { |
| WearNTear wearNTear = component; |
| WearNTear wearNTear = component; |
| wearNTear.m_onDestroyed = (Action)Delegate.Combine(wearNTear.m_onDestroyed, new Action(this.OnDestroyed)); |
| wearNTear.m_onDestroyed = (Action)Delegate.Combine(wearNTear.m_onDestroyed, new Action(this.OnDestroyed)); |
| } |
| } |
| base.InvokeRepeating("UpdateSmelter", 1f, 1f); |
| base.InvokeRepeating("UpdateSmelter", 1f, 1f); |
| } |
| } |
| |
| |
| private void DropAllItems() |
| private void DropAllItems() |
| { |
| { |
| this.SpawnProcessed(); |
| this.SpawnProcessed(); |
| if (this.m_fuelItem != null) |
| if (this.m_fuelItem != null) |
| { |
| { |
| float num = ((this.m_nview.GetZDO() == null) ? 0f : this.m_nview.GetZDO().GetFloat(ZDOVars.s_fuel, 0f)); |
| float num = ((this.m_nview.GetZDO() == null) ? 0f : this.m_nview.GetZDO().GetFloat(ZDOVars.s_fuel, 0f)); |
| for (int i = 0; i < (int)num; i++) |
| for (int i = 0; i < (int)num; i++) |
| { |
| { |
| Vector3 vector = base.transform.position + Vector3.up + UnityEngine.Random.insideUnitSphere * 0.3f; |
| Vector3 vector = base.transform.position + Vector3.up + UnityEngine.Random.insideUnitSphere * 0.3f; |
| Quaternion quaternion = Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 360), 0f); |
| Quaternion quaternion = Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 360), 0f); |
| ItemDrop.OnCreateNew(UnityEngine.Object.Instantiate<GameObject>(this.m_fuelItem.gameObject, vector, quaternion)); |
| ItemDrop.OnCreateNew(UnityEngine.Object.Instantiate<GameObject>(this.m_fuelItem.gameObject, vector, quaternion)); |
| } |
| } |
| } |
| } |
| while (this.GetQueueSize() > 0) |
| while (this.GetQueueSize() > 0) |
| { |
| { |
| string queuedOre = this.GetQueuedOre(); |
| string queuedOre = this.GetQueuedOre(); |
| this.RemoveOneOre(); |
| this.RemoveOneOre(); |
| Smelter.ItemConversion itemConversion = this.GetItemConversion(queuedOre); |
| Smelter.ItemConversion itemConversion = this.GetItemConversion(queuedOre); |
| if (itemConversion != null) |
| if (itemConversion != null) |
| { |
| { |
| Vector3 vector2 = base.transform.position + Vector3.up + UnityEngine.Random.insideUnitSphere * 0.3f; |
| Vector3 vector2 = base.transform.position + Vector3.up + UnityEngine.Random.insideUnitSphere * 0.3f; |
| Quaternion quaternion2 = Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 360), 0f); |
| Quaternion quaternion2 = Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 360), 0f); |
| ItemDrop.OnCreateNew(UnityEngine.Object.Instantiate<GameObject>(itemConversion.m_from.gameObject, vector2, quaternion2)); |
| ItemDrop.OnCreateNew(UnityEngine.Object.Instantiate<GameObject>(itemConversion.m_from.gameObject, vector2, quaternion2)); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| private void OnDestroyed() |
| private void OnDestroyed() |
| { |
| { |
| if (this.m_nview.IsOwner()) |
| if (this.m_nview.IsOwner()) |
| { |
| { |
| this.DropAllItems(); |
| this.DropAllItems(); |
| } |
| } |
| } |
| } |
| |
| |
| private bool IsItemAllowed(ItemDrop.ItemData item) |
| private bool IsItemAllowed(ItemDrop.ItemData item) |
| { |
| { |
| return this.IsItemAllowed(item.m_dropPrefab.name); |
| return this.IsItemAllowed(item.m_dropPrefab.name); |
| } |
| } |
| |
| |
| private bool IsItemAllowed(string itemName) |
| private bool IsItemAllowed(string itemName) |
| { |
| { |
| using (List<Smelter.ItemConversion>.Enumerator enumerator = this.m_conversion.GetEnumerator()) |
| using (List<Smelter.ItemConversion>.Enumerator enumerator = this.m_conversion.GetEnumerator()) |
| { |
| { |
| while (enumerator.MoveNext()) |
| while (enumerator.MoveNext()) |
| { |
| { |
| if (enumerator.Current.m_from.gameObject.name == itemName) |
| if (enumerator.Current.m_from.gameObject.name == itemName) |
| { |
| { |
| return true; |
| return true; |
| } |
| } |
| } |
| } |
| } |
| } |
| return false; |
| return false; |
| } |
| } |
| |
| |
| private ItemDrop.ItemData FindCookableItem(Inventory inventory) |
| private ItemDrop.ItemData FindCookableItem(Inventory inventory) |
| { |
| { |
| foreach (Smelter.ItemConversion itemConversion in this.m_conversion) |
| foreach (Smelter.ItemConversion itemConversion in this.m_conversion) |
| { |
| { |
| ItemDrop.ItemData item = inventory.GetItem(itemConversion.m_from.m_itemData.m_shared.m_name, -1, false); |
| ItemDrop.ItemData item = inventory.GetItem(itemConversion.m_from.m_itemData.m_shared.m_name, -1, false); |
| if (item != null) |
| if (item != null) |
| { |
| { |
| return item; |
| return item; |
| } |
| } |
| } |
| } |
| return null; |
| return null; |
| } |
| } |
| |
| |
| private bool OnAddOre(Switch sw, Humanoid user, ItemDrop.ItemData item) |
| private bool OnAddOre(Switch sw, Humanoid user, ItemDrop.ItemData item) |
| { |
| { |
| if (item == null) |
| if (item == null) |
| { |
| { |
| item = this.FindCookableItem(user.GetInventory()); |
| item = this.FindCookableItem(user.GetInventory()); |
| if (item == null) |
| if (item == null) |
| { |
| { |
| user.Message(MessageHud.MessageType.Center, "$msg_noprocessableitems", 0, null); |
| user.Message(MessageHud.MessageType.Center, "$msg_noprocessableitems", 0, null); |
| return false; |
| return false; |
| } |
| } |
| } |
| } |
| if (!this.IsItemAllowed(item.m_dropPrefab.name)) |
| if (!this.IsItemAllowed(item.m_dropPrefab.name)) |
| { |
| { |
| user.Message(MessageHud.MessageType.Center, "$msg_wontwork", 0, null); |
| user.Message(MessageHud.MessageType.Center, "$msg_wontwork", 0, null); |
| return false; |
| return false; |
| } |
| } |
| ZLog.Log("trying to add " + item.m_shared.m_name); |
| ZLog.Log("trying to add " + item.m_shared.m_name); |
| if (this.GetQueueSize() >= this.m_maxOre) |
| if (this.GetQueueSize() >= this.m_maxOre) |
| { |
| { |
| user.Message(MessageHud.MessageType.Center, "$msg_itsfull", 0, null); |
| user.Message(MessageHud.MessageType.Center, "$msg_itsfull", 0, null); |
| return false; |
| return false; |
| } |
| } |
| user.Message(MessageHud.MessageType.Center, "$msg_added " + item.m_shared.m_name, 0, null); |
| user.Message(MessageHud.MessageType.Center, "$msg_added " + item.m_shared.m_name, 0, null); |
| user.GetInventory().RemoveItem(item, 1); |
| user.GetInventory().RemoveItem(item, 1); |
| . | this.m_nview.InvokeRPC("AddOre", new object[] { item.m_dropPrefab.name }); |
| this.m_nview.InvokeRPC("RPC_AddOre", new object[] { item.m_dropPrefab.name }); |
| this.m_addedOreTime = Time.time; |
| this.m_addedOreTime = Time.time; |
| if (this.m_addOreAnimationDuration > 0f) |
| if (this.m_addOreAnimationDuration > 0f) |
| { |
| { |
| this.SetAnimation(true); |
| this.SetAnimation(true); |
| } |
| } |
| return true; |
| return true; |
| } |
| } |
| |
| |
| private float GetBakeTimer() |
| private float GetBakeTimer() |
| { |
| { |
| if (!this.m_nview.IsValid()) |
| if (!this.m_nview.IsValid()) |
| { |
| { |
| return 0f; |
| return 0f; |
| } |
| } |
| return this.m_nview.GetZDO().GetFloat(ZDOVars.s_bakeTimer, 0f); |
| return this.m_nview.GetZDO().GetFloat(ZDOVars.s_bakeTimer, 0f); |
| } |
| } |
| |
| |
| private void SetBakeTimer(float t) |
| private void SetBakeTimer(float t) |
| { |
| { |
| if (!this.m_nview.IsValid()) |
| if (!this.m_nview.IsValid()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| this.m_nview.GetZDO().Set(ZDOVars.s_bakeTimer, t); |
| this.m_nview.GetZDO().Set(ZDOVars.s_bakeTimer, t); |
| } |
| } |
| |
| |
| private float GetFuel() |
| private float GetFuel() |
| { |
| { |
| if (!this.m_nview.IsValid()) |
| if (!this.m_nview.IsValid()) |
| { |
| { |
| return 0f; |
| return 0f; |
| } |
| } |
| return this.m_nview.GetZDO().GetFloat(ZDOVars.s_fuel, 0f); |
| return this.m_nview.GetZDO().GetFloat(ZDOVars.s_fuel, 0f); |
| } |
| } |
| |
| |
| private void SetFuel(float fuel) |
| private void SetFuel(float fuel) |
| { |
| { |
| if (!this.m_nview.IsValid()) |
| if (!this.m_nview.IsValid()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| this.m_nview.GetZDO().Set(ZDOVars.s_fuel, fuel); |
| this.m_nview.GetZDO().Set(ZDOVars.s_fuel, fuel); |
| } |
| } |
| |
| |
| private int GetQueueSize() |
| private int GetQueueSize() |
| { |
| { |
| if (!this.m_nview.IsValid()) |
| if (!this.m_nview.IsValid()) |
| { |
| { |
| return 0; |
| return 0; |
| } |
| } |
| return this.m_nview.GetZDO().GetInt(ZDOVars.s_queued, 0); |
| return this.m_nview.GetZDO().GetInt(ZDOVars.s_queued, 0); |
| } |
| } |
| |
| |
| private void RPC_AddOre(long sender, string name) |
| private void RPC_AddOre(long sender, string name) |
| { |
| { |
| if (!this.m_nview.IsOwner()) |
| if (!this.m_nview.IsOwner()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (!this.IsItemAllowed(name)) |
| if (!this.IsItemAllowed(name)) |
| { |
| { |
| ZLog.Log("Item not allowed " + name); |
| ZLog.Log("Item not allowed " + name); |
| return; |
| return; |
| } |
| } |
| this.QueueOre(name); |
| this.QueueOre(name); |
| this.m_oreAddedEffects.Create(base.transform.position, base.transform.rotation, null, 1f, -1); |
| this.m_oreAddedEffects.Create(base.transform.position, base.transform.rotation, null, 1f, -1); |
| ZLog.Log("Added ore " + name); |
| ZLog.Log("Added ore " + name); |
| } |
| } |
| |
| |
| private void QueueOre(string name) |
| private void QueueOre(string name) |
| { |
| { |
| int queueSize = this.GetQueueSize(); |
| int queueSize = this.GetQueueSize(); |
| this.m_nview.GetZDO().Set("item" + queueSize.ToString(), name); |
| this.m_nview.GetZDO().Set("item" + queueSize.ToString(), name); |
| this.m_nview.GetZDO().Set(ZDOVars.s_queued, queueSize + 1, false); |
| this.m_nview.GetZDO().Set(ZDOVars.s_queued, queueSize + 1, false); |
| } |
| } |
| |
| |
| private string GetQueuedOre() |
| private string GetQueuedOre() |
| { |
| { |
| if (this.GetQueueSize() == 0) |
| if (this.GetQueueSize() == 0) |
| { |
| { |
| return ""; |
| return ""; |
| } |
| } |
| return this.m_nview.GetZDO().GetString(ZDOVars.s_item0, ""); |
| return this.m_nview.GetZDO().GetString(ZDOVars.s_item0, ""); |
| } |
| } |
| |
| |
| private void RemoveOneOre() |
| private void RemoveOneOre() |
| { |
| { |
| int queueSize = this.GetQueueSize(); |
| int queueSize = this.GetQueueSize(); |
| if (queueSize == 0) |
| if (queueSize == 0) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| for (int i = 0; i < queueSize; i++) |
| for (int i = 0; i < queueSize; i++) |
| { |
| { |
| string @string = this.m_nview.GetZDO().GetString("item" + (i + 1).ToString(), ""); |
| string @string = this.m_nview.GetZDO().GetString("item" + (i + 1).ToString(), ""); |
| this.m_nview.GetZDO().Set("item" + i.ToString(), @string); |
| this.m_nview.GetZDO().Set("item" + i.ToString(), @string); |
| } |
| } |
| this.m_nview.GetZDO().Set(ZDOVars.s_queued, queueSize - 1, false); |
| this.m_nview.GetZDO().Set(ZDOVars.s_queued, queueSize - 1, false); |
| } |
| } |
| |
| |
| private bool OnEmpty(Switch sw, Humanoid user, ItemDrop.ItemData item) |
| private bool OnEmpty(Switch sw, Humanoid user, ItemDrop.ItemData item) |
| { |
| { |
| if (this.GetProcessedQueueSize() <= 0) |
| if (this.GetProcessedQueueSize() <= 0) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| . | this.m_nview.InvokeRPC("EmptyProcessed", Array.Empty<object>()); |
| this.m_nview.InvokeRPC("RPC_EmptyProcessed", Array.Empty<object>()); |
| return true; |
| return true; |
| } |
| } |
| |
| |
| private void RPC_EmptyProcessed(long sender) |
| private void RPC_EmptyProcessed(long sender) |
| { |
| { |
| if (!this.m_nview.IsOwner()) |
| if (!this.m_nview.IsOwner()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| this.SpawnProcessed(); |
| this.SpawnProcessed(); |
| } |
| } |
| |
| |
| private bool OnAddFuel(Switch sw, Humanoid user, ItemDrop.ItemData item) |
| private bool OnAddFuel(Switch sw, Humanoid user, ItemDrop.ItemData item) |
| { |
| { |
| if (item != null && item.m_shared.m_name != this.m_fuelItem.m_itemData.m_shared.m_name) |
| if (item != null && item.m_shared.m_name != this.m_fuelItem.m_itemData.m_shared.m_name) |
| { |
| { |
| user.Message(MessageHud.MessageType.Center, "$msg_wrongitem", 0, null); |
| user.Message(MessageHud.MessageType.Center, "$msg_wrongitem", 0, null); |
| return false; |
| return false; |
| } |
| } |
| if (this.GetFuel() > (float)(this.m_maxFuel - 1)) |
| if (this.GetFuel() > (float)(this.m_maxFuel - 1)) |
| { |
| { |
| user.Message(MessageHud.MessageType.Center, "$msg_itsfull", 0, null); |
| user.Message(MessageHud.MessageType.Center, "$msg_itsfull", 0, null); |
| return false; |
| return false; |
| } |
| } |
| if (!user.GetInventory().HaveItem(this.m_fuelItem.m_itemData.m_shared.m_name, true)) |
| if (!user.GetInventory().HaveItem(this.m_fuelItem.m_itemData.m_shared.m_name, true)) |
| { |
| { |
| user.Message(MessageHud.MessageType.Center, "$msg_donthaveany " + this.m_fuelItem.m_itemData.m_shared.m_name, 0, null); |
| user.Message(MessageHud.MessageType.Center, "$msg_donthaveany " + this.m_fuelItem.m_itemData.m_shared.m_name, 0, null); |
| return false; |
| return false; |
| } |
| } |
| user.Message(MessageHud.MessageType.Center, "$msg_added " + this.m_fuelItem.m_itemData.m_shared.m_name, 0, null); |
| user.Message(MessageHud.MessageType.Center, "$msg_added " + this.m_fuelItem.m_itemData.m_shared.m_name, 0, null); |
| user.GetInventory().RemoveItem(this.m_fuelItem.m_itemData.m_shared.m_name, 1, -1, true); |
| user.GetInventory().RemoveItem(this.m_fuelItem.m_itemData.m_shared.m_name, 1, -1, true); |
| . | this.m_nview.InvokeRPC("AddFuel", Array.Empty<object>()); |
| this.m_nview.InvokeRPC("RPC_AddFuel", Array.Empty<object>()); |
| return true; |
| return true; |
| } |
| } |
| |
| |
| private void RPC_AddFuel(long sender) |
| private void RPC_AddFuel(long sender) |
| { |
| { |
| if (!this.m_nview.IsOwner()) |
| if (!this.m_nview.IsOwner()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| float fuel = this.GetFuel(); |
| float fuel = this.GetFuel(); |
| this.SetFuel(fuel + 1f); |
| this.SetFuel(fuel + 1f); |
| this.m_fuelAddedEffects.Create(base.transform.position, base.transform.rotation, base.transform, 1f, -1); |
| this.m_fuelAddedEffects.Create(base.transform.position, base.transform.rotation, base.transform, 1f, -1); |
| } |
| } |
| |
| |
| private double GetDeltaTime() |
| private double GetDeltaTime() |
| { |
| { |
| DateTime time = ZNet.instance.GetTime(); |
| DateTime time = ZNet.instance.GetTime(); |
| . | DateTime dateTime = new DateTime(this.m_nview.GetZDO().GetLong("StartTime", time.Ticks)); |
| DateTime dateTime = new DateTime(this.m_nview.GetZDO().GetLong(ZDOVars.s_startTime, time.Ticks)); |
| double totalSeconds = (time - dateTime).TotalSeconds; |
| double totalSeconds = (time - dateTime).TotalSeconds; |
| this.m_nview.GetZDO().Set(ZDOVars.s_startTime, time.Ticks); |
| this.m_nview.GetZDO().Set(ZDOVars.s_startTime, time.Ticks); |
| return totalSeconds; |
| return totalSeconds; |
| } |
| } |
| |
| |
| private float GetAccumulator() |
| private float GetAccumulator() |
| { |
| { |
| if (!this.m_nview.IsValid()) |
| if (!this.m_nview.IsValid()) |
| { |
| { |
| return 0f; |
| return 0f; |
| } |
| } |
| return this.m_nview.GetZDO().GetFloat(ZDOVars.s_accTime, 0f); |
| return this.m_nview.GetZDO().GetFloat(ZDOVars.s_accTime, 0f); |
| } |
| } |
| |
| |
| private void SetAccumulator(float t) |
| private void SetAccumulator(float t) |
| { |
| { |
| if (!this.m_nview.IsValid()) |
| if (!this.m_nview.IsValid()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| this.m_nview.GetZDO().Set(ZDOVars.s_accTime, t); |
| this.m_nview.GetZDO().Set(ZDOVars.s_accTime, t); |
| } |
| } |
| |
| |
| private void UpdateRoof() |
| private void UpdateRoof() |
| { |
| { |
| if (this.m_requiresRoof) |
| if (this.m_requiresRoof) |
| { |
| { |
| this.m_haveRoof = Cover.IsUnderRoof(this.m_roofCheckPoint.position); |
| this.m_haveRoof = Cover.IsUnderRoof(this.m_roofCheckPoint.position); |
| } |
| } |
| } |
| } |
| |
| |
| private void UpdateSmoke() |
| private void UpdateSmoke() |
| { |
| { |
| if (this.m_smokeSpawner != null) |
| if (this.m_smokeSpawner != null) |
| { |
| { |
| this.m_blockedSmoke = this.m_smokeSpawner.IsBlocked(); |
| this.m_blockedSmoke = this.m_smokeSpawner.IsBlocked(); |
| return; |
| return; |
| } |
| } |
| this.m_blockedSmoke = false; |
| this.m_blockedSmoke = false; |
| } |
| } |
| |
| |
| private void UpdateSmelter() |
| private void UpdateSmelter() |
| { |
| { |
| if (!this.m_nview.IsValid()) |
| if (!this.m_nview.IsValid()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| this.UpdateRoof(); |
| this.UpdateRoof(); |
| this.UpdateSmoke(); |
| this.UpdateSmoke(); |
| this.UpdateState(); |
| this.UpdateState(); |
| if (!this.m_nview.IsOwner()) |
| if (!this.m_nview.IsOwner()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| double deltaTime = this.GetDeltaTime(); |
| double deltaTime = this.GetDeltaTime(); |
| float num = this.GetAccumulator(); |
| float num = this.GetAccumulator(); |
| num += (float)deltaTime; |
| num += (float)deltaTime; |
| if (num > 3600f) |
| if (num > 3600f) |
| { |
| { |
| num = 3600f; |
| num = 3600f; |
| } |
| } |
| float num2 = (this.m_windmill ? this.m_windmill.GetPowerOutput() : 1f); |
| float num2 = (this.m_windmill ? this.m_windmill.GetPowerOutput() : 1f); |
| while (num >= 1f) |
| while (num >= 1f) |
| { |
| { |
| num -= 1f; |
| num -= 1f; |
| float num3 = this.GetFuel(); |
| float num3 = this.GetFuel(); |
| string queuedOre = this.GetQueuedOre(); |
| string queuedOre = this.GetQueuedOre(); |
| if ((this.m_maxFuel == 0 || num3 > 0f) && (this.m_maxOre == 0 || queuedOre != "") && this.m_secPerProduct > 0f && (!this.m_requiresRoof || this.m_haveRoof) && !this.m_blockedSmoke) |
| if ((this.m_maxFuel == 0 || num3 > 0f) && (this.m_maxOre == 0 || queuedOre != "") && this.m_secPerProduct > 0f && (!this.m_requiresRoof || this.m_haveRoof) && !this.m_blockedSmoke) |
| { |
| { |
| float num4 = 1f * num2; |
| float num4 = 1f * num2; |
| if (this.m_maxFuel > 0) |
| if (this.m_maxFuel > 0) |
| { |
| { |
| float num5 = this.m_secPerProduct / (float)this.m_fuelPerProduct; |
| float num5 = this.m_secPerProduct / (float)this.m_fuelPerProduct; |
| num3 -= num4 / num5; |
| num3 -= num4 / num5; |
| if (num3 < 0.0001f) |
| if (num3 < 0.0001f) |
| { |
| { |
| num3 = 0f; |
| num3 = 0f; |
| } |
| } |
| this.SetFuel(num3); |
| this.SetFuel(num3); |
| } |
| } |
| if (queuedOre != "") |
| if (queuedOre != "") |
| { |
| { |
| float num6 = this.GetBakeTimer(); |
| float num6 = this.GetBakeTimer(); |
| num6 += num4; |
| num6 += num4; |
| this.SetBakeTimer(num6); |
| this.SetBakeTimer(num6); |
| if (num6 >= this.m_secPerProduct) |
| if (num6 >= this.m_secPerProduct) |
| { |
| { |
| this.SetBakeTimer(0f); |
| this.SetBakeTimer(0f); |
| this.RemoveOneOre(); |
| this.RemoveOneOre(); |
| this.QueueProcessed(queuedOre); |
| this.QueueProcessed(queuedOre); |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| if (this.GetQueuedOre() == "" || ((float)this.m_maxFuel > 0f && this.GetFuel() == 0f)) |
| if (this.GetQueuedOre() == "" || ((float)this.m_maxFuel > 0f && this.GetFuel() == 0f)) |
| { |
| { |
| this.SpawnProcessed(); |
| this.SpawnProcessed(); |
| } |
| } |
| this.SetAccumulator(num); |
| this.SetAccumulator(num); |
| } |
| } |
| |
| |
| private void QueueProcessed(string ore) |
| private void QueueProcessed(string ore) |
| { |
| { |
| if (!this.m_spawnStack) |
| if (!this.m_spawnStack) |
| { |
| { |
| this.Spawn(ore, 1); |
| this.Spawn(ore, 1); |
| return; |
| return; |
| } |
| } |
| if (!this.m_nview.IsValid()) |
| if (!this.m_nview.IsValid()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| string @string = this.m_nview.GetZDO().GetString(ZDOVars.s_spawnOre, ""); |
| string @string = this.m_nview.GetZDO().GetString(ZDOVars.s_spawnOre, ""); |
| int num = this.m_nview.GetZDO().GetInt(ZDOVars.s_spawnAmount, 0); |
| int num = this.m_nview.GetZDO().GetInt(ZDOVars.s_spawnAmount, 0); |
| if (@string.Length <= 0) |
| if (@string.Length <= 0) |
| { |
| { |
| this.m_nview.GetZDO().Set(ZDOVars.s_spawnOre, ore); |
| this.m_nview.GetZDO().Set(ZDOVars.s_spawnOre, ore); |
| this.m_nview.GetZDO().Set(ZDOVars.s_spawnAmount, 1, false); |
| this.m_nview.GetZDO().Set(ZDOVars.s_spawnAmount, 1, false); |
| return; |
| return; |
| } |
| } |
| if (@string != ore) |
| if (@string != ore) |
| { |
| { |
| this.SpawnProcessed(); |
| this.SpawnProcessed(); |
| this.m_nview.GetZDO().Set(ZDOVars.s_spawnOre, ore); |
| this.m_nview.GetZDO().Set(ZDOVars.s_spawnOre, ore); |
| this.m_nview.GetZDO().Set(ZDOVars.s_spawnAmount, 1, false); |
| this.m_nview.GetZDO().Set(ZDOVars.s_spawnAmount, 1, false); |
| return; |
| return; |
| } |
| } |
| num++; |
| num++; |
| Smelter.ItemConversion itemConversion = this.GetItemConversion(ore); |
| Smelter.ItemConversion itemConversion = this.GetItemConversion(ore); |
| if (itemConversion == null || num >= itemConversion.m_to.m_itemData.m_shared.m_maxStackSize) |
| if (itemConversion == null || num >= itemConversion.m_to.m_itemData.m_shared.m_maxStackSize) |
| { |
| { |
| this.Spawn(ore, num); |
| this.Spawn(ore, num); |
| this.m_nview.GetZDO().Set(ZDOVars.s_spawnOre, ""); |
| this.m_nview.GetZDO().Set(ZDOVars.s_spawnOre, ""); |
| this.m_nview.GetZDO().Set(ZDOVars.s_spawnAmount, 0, false); |
| this.m_nview.GetZDO().Set(ZDOVars.s_spawnAmount, 0, false); |
| return; |
| return; |
| } |
| } |
| this.m_nview.GetZDO().Set(ZDOVars.s_spawnAmount, num, false); |
| this.m_nview.GetZDO().Set(ZDOVars.s_spawnAmount, num, false); |
| } |
| } |
| |
| |
| private void SpawnProcessed() |
| private void SpawnProcessed() |
| { |
| { |
| if (!this.m_nview.IsValid()) |
| if (!this.m_nview.IsValid()) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| int @int = this.m_nview.GetZDO().GetInt(ZDOVars.s_spawnAmount, 0); |
| int @int = this.m_nview.GetZDO().GetInt(ZDOVars.s_spawnAmount, 0); |
| if (@int > 0) |
| if (@int > 0) |
| { |
| { |
| string @string = this.m_nview.GetZDO().GetString(ZDOVars.s_spawnOre, ""); |
| string @string = this.m_nview.GetZDO().GetString(ZDOVars.s_spawnOre, ""); |
| this.Spawn(@string, @int); |
| this.Spawn(@string, @int); |
| this.m_nview.GetZDO().Set(ZDOVars.s_spawnOre, ""); |
| this.m_nview.GetZDO().Set(ZDOVars.s_spawnOre, ""); |
| this.m_nview.GetZDO().Set(ZDOVars.s_spawnAmount, 0, false); |
| this.m_nview.GetZDO().Set(ZDOVars.s_spawnAmount, 0, false); |
| } |
| } |
| } |
| } |
| |
| |
| private int GetProcessedQueueSize() |
| private int GetProcessedQueueSize() |
| { |
| { |
| if (!this.m_nview.IsValid()) |
| if (!this.m_nview.IsValid()) |
| { |
| { |
| return 0; |
| return 0; |
| } |
| } |
| return this.m_nview.GetZDO().GetInt(ZDOVars.s_spawnAmount, 0); |
| return this.m_nview.GetZDO().GetInt(ZDOVars.s_spawnAmount, 0); |
| } |
| } |
| |
| |
| private void Spawn(string ore, int stack) |
| private void Spawn(string ore, int stack) |
| { |
| { |
| Smelter.ItemConversion itemConversion = this.GetItemConversion(ore); |
| Smelter.ItemConversion itemConversion = this.GetItemConversion(ore); |
| . | if (itemConversion != null) |
| if (itemConversion != null && itemConversion.m_to != null) |
| { |
| { |
| this.m_produceEffects.Create(base.transform.position, base.transform.rotation, null, 1f, -1); |
| this.m_produceEffects.Create(base.transform.position, base.transform.rotation, null, 1f, -1); |
| ItemDrop component = UnityEngine.Object.Instantiate<GameObject>(itemConversion.m_to.gameObject, this.m_outputPoint.position, this.m_outputPoint.rotation).GetComponent<ItemDrop>(); |
| ItemDrop component = UnityEngine.Object.Instantiate<GameObject>(itemConversion.m_to.gameObject, this.m_outputPoint.position, this.m_outputPoint.rotation).GetComponent<ItemDrop>(); |
| component.m_itemData.m_stack = stack; |
| component.m_itemData.m_stack = stack; |
| ItemDrop.OnCreateNew(component); |
| ItemDrop.OnCreateNew(component); |
| } |
| } |
| } |
| } |
| |
| |
| private Smelter.ItemConversion GetItemConversion(string itemName) |
| private Smelter.ItemConversion GetItemConversion(string itemName) |
| { |
| { |
| foreach (Smelter.ItemConversion itemConversion in this.m_conversion) |
| foreach (Smelter.ItemConversion itemConversion in this.m_conversion) |
| { |
| { |
| if (itemConversion.m_from.gameObject.name == itemName) |
| if (itemConversion.m_from.gameObject.name == itemName) |
| { |
| { |
| return itemConversion; |
| return itemConversion; |
| } |
| } |
| } |
| } |
| return null; |
| return null; |
| } |
| } |
| |
| |
| private void UpdateState() |
| private void UpdateState() |
| { |
| { |
| bool flag = this.IsActive(); |
| bool flag = this.IsActive(); |
| this.m_enabledObject.SetActive(flag); |
| this.m_enabledObject.SetActive(flag); |
| if (this.m_disabledObject) |
| if (this.m_disabledObject) |
| { |
| { |
| this.m_disabledObject.SetActive(!flag); |
| this.m_disabledObject.SetActive(!flag); |
| } |
| } |
| if (this.m_haveFuelObject) |
| if (this.m_haveFuelObject) |
| { |
| { |
| this.m_haveFuelObject.SetActive(this.GetFuel() > 0f); |
| this.m_haveFuelObject.SetActive(this.GetFuel() > 0f); |
| } |
| } |
| if (this.m_haveOreObject) |
| if (this.m_haveOreObject) |
| { |
| { |
| this.m_haveOreObject.SetActive(this.GetQueueSize() > 0); |
| this.m_haveOreObject.SetActive(this.GetQueueSize() > 0); |
| } |
| } |
| if (this.m_noOreObject) |
| if (this.m_noOreObject) |
| { |
| { |
| this.m_noOreObject.SetActive(this.GetQueueSize() == 0); |
| this.m_noOreObject.SetActive(this.GetQueueSize() == 0); |
| } |
| } |
| if (this.m_addOreAnimationDuration > 0f && Time.time - this.m_addedOreTime < this.m_addOreAnimationDuration) |
| if (this.m_addOreAnimationDuration > 0f && Time.time - this.m_addedOreTime < this.m_addOreAnimationDuration) |
| { |
| { |
| flag = true; |
| flag = true; |
| } |
| } |
| this.SetAnimation(flag); |
| this.SetAnimation(flag); |
| } |
| } |
| |
| |
| private void SetAnimation(bool active) |
| private void SetAnimation(bool active) |
| { |
| { |
| foreach (Animator animator in this.m_animators) |
| foreach (Animator animator in this.m_animators) |
| { |
| { |
| if (animator.gameObject.activeInHierarchy) |
| if (animator.gameObject.activeInHierarchy) |
| { |
| { |
| animator.SetBool("active", active); |
| animator.SetBool("active", active); |
| animator.SetFloat("activef", active ? 1f : 0f); |
| animator.SetFloat("activef", active ? 1f : 0f); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| public bool IsActive() |
| public bool IsActive() |
| { |
| { |
| return (this.m_maxFuel == 0 || this.GetFuel() > 0f) && (this.m_maxOre == 0 || this.GetQueueSize() > 0) && (!this.m_requiresRoof || this.m_haveRoof) && !this.m_blockedSmoke; |
| return (this.m_maxFuel == 0 || this.GetFuel() > 0f) && (this.m_maxOre == 0 || this.GetQueueSize() > 0) && (!this.m_requiresRoof || this.m_haveRoof) && !this.m_blockedSmoke; |
| } |
| } |
| |
| |
| private string OnHoverAddFuel() |
| private string OnHoverAddFuel() |
| { |
| { |
| float fuel = this.GetFuel(); |
| float fuel = this.GetFuel(); |
| return Localization.instance.Localize(string.Format("{0} ({1} {2}/{3})\n[<color=yellow><b>$KEY_Use</b></color>] $piece_smelter_add {4}", new object[] |
| return Localization.instance.Localize(string.Format("{0} ({1} {2}/{3})\n[<color=yellow><b>$KEY_Use</b></color>] $piece_smelter_add {4}", new object[] |
| { |
| { |
| this.m_name, |
| this.m_name, |
| this.m_fuelItem.m_itemData.m_shared.m_name, |
| this.m_fuelItem.m_itemData.m_shared.m_name, |
| Mathf.Ceil(fuel), |
| Mathf.Ceil(fuel), |
| this.m_maxFuel, |
| this.m_maxFuel, |
| this.m_fuelItem.m_itemData.m_shared.m_name |
| this.m_fuelItem.m_itemData.m_shared.m_name |
| })); |
| })); |
| } |
| } |
| |
| |
| private string OnHoverEmptyOre() |
| private string OnHoverEmptyOre() |
| { |
| { |
| int processedQueueSize = this.GetProcessedQueueSize(); |
| int processedQueueSize = this.GetProcessedQueueSize(); |
| return Localization.instance.Localize(string.Format("{0} ({1} $piece_smelter_ready) \n[<color=yellow><b>$KEY_Use</b></color>] {2}", this.m_name, processedQueueSize, this.m_emptyOreTooltip)); |
| return Localization.instance.Localize(string.Format("{0} ({1} $piece_smelter_ready) \n[<color=yellow><b>$KEY_Use</b></color>] {2}", this.m_name, processedQueueSize, this.m_emptyOreTooltip)); |
| } |
| } |
| |
| |
| private string OnHoverAddOre() |
| private string OnHoverAddOre() |
| { |
| { |
| this.m_sb.Clear(); |
| this.m_sb.Clear(); |
| int queueSize = this.GetQueueSize(); |
| int queueSize = this.GetQueueSize(); |
| this.m_sb.Append(string.Format("{0} ({1}/{2}) ", this.m_name, queueSize, this.m_maxOre)); |
| this.m_sb.Append(string.Format("{0} ({1}/{2}) ", this.m_name, queueSize, this.m_maxOre)); |
| if (this.m_requiresRoof && !this.m_haveRoof && Mathf.Sin(Time.time * 10f) > 0f) |
| if (this.m_requiresRoof && !this.m_haveRoof && Mathf.Sin(Time.time * 10f) > 0f) |
| { |
| { |
| this.m_sb.Append(" <color=yellow>$piece_smelter_reqroof</color>"); |
| this.m_sb.Append(" <color=yellow>$piece_smelter_reqroof</color>"); |
| } |
| } |
| this.m_sb.Append("\n[<color=yellow><b>$KEY_Use</b></color>] " + this.m_addOreTooltip); |
| this.m_sb.Append("\n[<color=yellow><b>$KEY_Use</b></color>] " + this.m_addOreTooltip); |
| return Localization.instance.Localize(this.m_sb.ToString()); |
| return Localization.instance.Localize(this.m_sb.ToString()); |
| } |
| } |
| |
| |
| public string m_name = "Smelter"; |
| public string m_name = "Smelter"; |
| |
| |
| public string m_addOreTooltip = "$piece_smelter_additem"; |
| public string m_addOreTooltip = "$piece_smelter_additem"; |
| |
| |
| public string m_emptyOreTooltip = "$piece_smelter_empty"; |
| public string m_emptyOreTooltip = "$piece_smelter_empty"; |
| |
| |
| public Switch m_addWoodSwitch; |
| public Switch m_addWoodSwitch; |
| |
| |
| public Switch m_addOreSwitch; |
| public Switch m_addOreSwitch; |
| |
| |
| public Switch m_emptyOreSwitch; |
| public Switch m_emptyOreSwitch; |
| |
| |
| public Transform m_outputPoint; |
| public Transform m_outputPoint; |
| |
| |
| public Transform m_roofCheckPoint; |
| public Transform m_roofCheckPoint; |
| |
| |
| public GameObject m_enabledObject; |
| public GameObject m_enabledObject; |
| |
| |
| public GameObject m_disabledObject; |
| public GameObject m_disabledObject; |
| |
| |
| public GameObject m_haveFuelObject; |
| public GameObject m_haveFuelObject; |
| |
| |
| public GameObject m_haveOreObject; |
| public GameObject m_haveOreObject; |
| |
| |
| public GameObject m_noOreObject; |
| public GameObject m_noOreObject; |
| |
| |
| public Animator[] m_animators; |
| public Animator[] m_animators; |
| |
| |
| public ItemDrop m_fuelItem; |
| public ItemDrop m_fuelItem; |
| |
| |
| public int m_maxOre = 10; |
| public int m_maxOre = 10; |
| |
| |
| public int m_maxFuel = 10; |
| public int m_maxFuel = 10; |
| |
| |
| public int m_fuelPerProduct = 4; |
| public int m_fuelPerProduct = 4; |
| |
| |
| public float m_secPerProduct = 10f; |
| public float m_secPerProduct = 10f; |
| |
| |
| public bool m_spawnStack; |
| public bool m_spawnStack; |
| |
| |
| public bool m_requiresRoof; |
| public bool m_requiresRoof; |
| |
| |
| public Windmill m_windmill; |
| public Windmill m_windmill; |
| |
| |
| public SmokeSpawner m_smokeSpawner; |
| public SmokeSpawner m_smokeSpawner; |
| |
| |
| public float m_addOreAnimationDuration; |
| public float m_addOreAnimationDuration; |
| |
| |
| public List<Smelter.ItemConversion> m_conversion = new List<Smelter.ItemConversion>(); |
| public List<Smelter.ItemConversion> m_conversion = new List<Smelter.ItemConversion>(); |
| |
| |
| public EffectList m_oreAddedEffects = new EffectList(); |
| public EffectList m_oreAddedEffects = new EffectList(); |
| |
| |
| public EffectList m_fuelAddedEffects = new EffectList(); |
| public EffectList m_fuelAddedEffects = new EffectList(); |
| |
| |
| public EffectList m_produceEffects = new EffectList(); |
| public EffectList m_produceEffects = new EffectList(); |
| |
| |
| private ZNetView m_nview; |
| private ZNetView m_nview; |
| |
| |
| private bool m_haveRoof; |
| private bool m_haveRoof; |
| |
| |
| private bool m_blockedSmoke; |
| private bool m_blockedSmoke; |
| |
| |
| private float m_addedOreTime = -1000f; |
| private float m_addedOreTime = -1000f; |
| |
| |
| private StringBuilder m_sb = new StringBuilder(); |
| private StringBuilder m_sb = new StringBuilder(); |
| |
| |
| [Serializable] |
| [Serializable] |
| public class ItemConversion |
| public class ItemConversion |
| { |
| { |
| public ItemDrop m_from; |
| public ItemDrop m_from; |
| |
| |
| public ItemDrop m_to; |
| public ItemDrop m_to; |
| } |
| } |
| } |
| } |
| |
| |