diff --git a/Assets/Prefabs/Buildings/StairBuilding.prefab b/Assets/Prefabs/Buildings/StairBuilding.prefab index 62d1b58..b2ed265 100644 --- a/Assets/Prefabs/Buildings/StairBuilding.prefab +++ b/Assets/Prefabs/Buildings/StairBuilding.prefab @@ -157,9 +157,9 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 2305386115665963243} - - component: {fileID: 4901325652048475046} + - component: {fileID: 4128879575467903701} m_Layer: 10 - m_Name: Colliders + m_Name: Collider m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -172,20 +172,20 @@ RectTransform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5089027117596162827} - m_LocalRotation: {x: 0, y: 0, z: 0.38268343, w: 0.92387956} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 7134460453558218992} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 45} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 100, y: 100} + m_SizeDelta: {x: 80, y: 80} m_Pivot: {x: 0.5, y: 0.5} ---- !u!61 &4901325652048475046 -BoxCollider2D: +--- !u!60 &4128879575467903701 +PolygonCollider2D: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} @@ -228,5 +228,9 @@ BoxCollider2D: drawMode: 0 adaptiveTiling: 0 m_AutoTiling: 0 - m_Size: {x: 114, y: 5} - m_EdgeRadius: 0 + m_Points: + m_Paths: + - - {x: 40, y: 40} + - {x: -40, y: -40} + - {x: 40, y: -40} + m_UseDelaunayMesh: 1 diff --git a/Assets/Scripts/Game/Buildings/Automation/MixerBuilding.cs b/Assets/Scripts/Game/Buildings/Automation/MixerBuilding.cs index e7cc1a1..075decb 100644 --- a/Assets/Scripts/Game/Buildings/Automation/MixerBuilding.cs +++ b/Assets/Scripts/Game/Buildings/Automation/MixerBuilding.cs @@ -1,13 +1,43 @@ -using Fruitomation.Game.Items; +using PashaBibko.Pacore.Attributes; +using System.Collections.Generic; +using System.Linq; +using Fruitomation.Game.Items; +using Fruitomation.Global; using UnityEngine; namespace Fruitomation.Game { public class MixerBuilding : Building { + private struct Recipe + { + public ItemType[] Ingredients; + public ItemType Product; + + public Recipe(ItemType[] ingredients, ItemType product) + { + Ingredients = ingredients; + Product = product; + } + } + + private static Recipe[] Recipes = new Recipe[1] + { + new + ( + new[] { ItemType.Apple, ItemType.Grape }, + ItemType.Banana + ), + }; + [Header("Mixer Specific")] [SerializeField] private RectTransform OutputLocation; [SerializeField] private TriggerDetector Trigger; + + [Header("Read Only")] + [SerializeField, InspectorReadOnly] private int StoredItemCount; + + private readonly Dictionary StoredItems = new(); private void Start() { @@ -18,11 +48,52 @@ namespace Fruitomation.Game { return; } - - item.transform.position = OutputLocation.position; - item.SendToTheGhostRealm(); - + + if (StoredItemCount < 50) + { + ItemType type = item.CurrentType; + int typeCount = StoredItems.GetValueOrDefault(type); + + item.TriggerDestruction(false); + StoredItems[type] = typeCount + 1; + StoredItemCount++; + } }, TriggerType.Enter); } + + private void Update() + { + if (!GameStateController.Is(GameState.Simulation)) + { + StoredItems.Clear(); + return; + } + + foreach (Recipe recipe in Recipes) + { + bool hasAllIngredients = recipe.Ingredients.Aggregate(true, + (current, ingredient) + => current && StoredItems.ContainsKey(ingredient) + ); + + if (hasAllIngredients) + { + foreach (ItemType ingredient in recipe.Ingredients) + { + int count = StoredItems[ingredient] - 1; + if (count <= 0) + { + StoredItems.Remove(ingredient); + } + else + { + StoredItems[ingredient] = count; + } + } + + FruitSpawner.SpawnItem(recipe.Product, OutputLocation.position); + } + } + } } } diff --git a/Assets/Scripts/Game/FruitSpawner.cs b/Assets/Scripts/Game/FruitSpawner.cs index ec7cd7b..efbeeaa 100644 --- a/Assets/Scripts/Game/FruitSpawner.cs +++ b/Assets/Scripts/Game/FruitSpawner.cs @@ -1,7 +1,9 @@ +using System; using System.Collections.Generic; using Fruitomation.Game.Items; using Fruitomation.Global; using UnityEngine; +using Random = UnityEngine.Random; namespace Fruitomation.Game { @@ -27,9 +29,14 @@ namespace Fruitomation.Game [SerializeField] private GameObject KiwiPrefab; [SerializeField] private GameObject BuddhasHandPrefab; + private static FruitSpawner Instance; + private float TimeUntilNextSpawn; private int CurrentItemCount => FruitSpawnParent.childCount; + + private void Awake() + => Instance = this; private void Update() { @@ -70,13 +77,25 @@ namespace Fruitomation.Game if (UpgradeManager.Is(BasicUpgrade.Pitayas)) unlocked.Add(ItemType.Pitaya); + SpawnItem(unlocked[Random.Range(0, unlocked.Count)]); + } + + public static ItemBehaviour SpawnItem(ItemType item, Vector3? pos = null) + => Instance.SpawnItemInternal(item, pos); + + private ItemBehaviour SpawnItemInternal(ItemType item, Vector3? pos = null) + { GameObject parent = Instantiate(BaseItemPrefab, FruitSpawnParent); - ItemType type = unlocked[Random.Range(0, unlocked.Count)]; - ItemBehaviour behaviour = parent.GetComponent(); Debug.Assert(behaviour is not null, "Could not find ItemBehaviour"); + + if (pos != null) + { + parent.transform.position = (Vector3)pos; + } - behaviour.InitBehaviour(GameCanvas, type); + behaviour.InitBehaviour(GameCanvas, item); + return behaviour; } } } diff --git a/Assets/Scripts/Game/Items/ItemBehaviour.cs b/Assets/Scripts/Game/Items/ItemBehaviour.cs index 61456c8..d06c009 100644 --- a/Assets/Scripts/Game/Items/ItemBehaviour.cs +++ b/Assets/Scripts/Game/Items/ItemBehaviour.cs @@ -36,17 +36,25 @@ namespace Fruitomation.Game.Items private IEnumerator SendToGhostRealmInternal() { - CurrentChild.SetActive(false); - Body2D.Sleep(); - + Sleep(); yield return new WaitForSeconds(0.5f); - - CurrentChild.SetActive(true); - Body2D.WakeUp(); + WakeUp(); } public void SendToTheGhostRealm() => StartCoroutine(SendToGhostRealmInternal()); + public void Sleep() + { + CurrentChild.SetActive(false); + Body2D.Sleep(); + } + + public void WakeUp() + { + CurrentChild.SetActive(true); + Body2D.WakeUp(); + } + public void InitBehaviour(Canvas canvas, ItemType startType) { RectTransform = transform.GetComponent();