public int ValidateObjectives(GridInventory outputInventory) { int points = 0; int objectivesCompleted = 0; foreach (ObjectiveSlot slot in ObjectivesSlots) { if (!slot.Occupied) { continue; } GridObject gObj = outputInventory.GetObjectWithData(slot.Configuration.Object); if (gObj != null) { Debug.Log("Completed objective for item " + gObj.name); outputInventory.RemoveObject(gObj, true); points += slot.Configuration.Points; ++objectivesCompleted; slot.Feedback.Complete(); slot.Occupied = false; slot.Configuration = null; slot.Feedback = null; --ActiveObjectives; } } switch (objectivesCompleted) { case 2: points = (int)((float)points * 1.15f); break; case 3: points = (int)((float)points * 1.5f); break; case 4: points = (int)((float)points * 2f); break; } points -= outputInventory.FlushItems() * 10; return(points); }
public bool EndMove(Vector2Int coords) { GridObject gObj = GridManager.Instance.UnregisterDragged(); if (gObj == null) { Debug.LogWarning("Tried to end a move while no object was dragged", gameObject); return(false); } GridSystem startGrid; GridSystem destinationGrid; GridManager.Instance.GetGridCoords(gObj.initialDragPosition, out startGrid, out _); GridManager.Instance.GetGridCoords(gObj.transform.position, out destinationGrid, out _); if (destinationGrid == null || destinationGrid.Inventory.Type == GridType.Input) { return(false); } if (!ObjectPositionValid(gObj, coords)) { // TODO feedback not in grid return(false); } GridObject collided = Collide(gObj, coords); if (collided != null) { if (startGrid.Inventory.Type == GridType.Input) { return(false); } if (InMenu) { MenuManager.Instance.Selected(collided); return(false); } return(RecipeManager.Instance.ApplyRecipe(gObj, collided)); // TODO feedback collide, and eventual interaction } // If dragged object was not in the same grid if (!_objects.Contains(gObj)) { GridInventory inventory = GridManager.Instance.FindGridWithObject(gObj); if (inventory == null) { Debug.LogError("Trying to move an object from an undefined grid"); return(false); } Vector2Int oldPosition = gObj.Position; inventory.RemoveObject(gObj, false); AddObject(gObj, coords); if (inventory.Type == GridType.Input) { ObjectFactory.Instance.GenerateObject(GridManager.Instance.GetInputGridSystem(), oldPosition, gObj.Data, true, true); } } gObj.Position = coords; return(true); }