// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { // Raycast detect square click Ray ray = this.assignedPlayer.PlayerCamera.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo, 500, this.rayCastMask, QueryTriggerInteraction.UseGlobal)) { Square clickedSquare = hitInfo.transform.GetComponent <Square>(); if (clickedSquare == null) { Debug.Log("Non square detected"); return; } int actionPointsLeft = this.assignedPlayer.ActionPointLimit - this.currentBuiltPlan.ActionPointCost; switch (this.buildState) { case BuildingActionStates.NONE: // If the square clicked on is the player's square. Show Range if (this.assignedPlayer.CurrentSquare == clickedSquare) { // If can move if (actionPointsLeft > 0) { this.assignedPlayer.CurrentSquare.Range(actionPointsLeft); this.buildState = BuildingActionStates.CHOOSE_MOVEMENT; } } break; case BuildingActionStates.CHOOSE_MOVEMENT: // if you click the player then cancel all the plan, have same effect as click cancel button if (this.assignedPlayer.CurrentSquare == clickedSquare) { CancelPlan(); } else if (lastMovingSquare == clickedSquare) { goto case BuildingActionStates.CHOOSE_ACTION; } // if clicked square falls within player range Queue Action else if (clickedSquare.IsInRange() && !DialogSystem.Instance.IsOn()) { if (this.currentBuiltPlan.AddActionToPlanQueue( CreateMovementAction(clickedSquare, clickedSquare.ActionPointCost()))) { // HighlightRoot GridSystem.Instance.highlightRoot(assignedPlayer.CurrentSquare, clickedSquare); // Memorize the latest square the player clicked lastMovingSquare = clickedSquare; // Clear and update range UpdateMovingSquareRange(this.lastMovingSquare); } else { Debug.Log("Action not added to queue"); } } break; case BuildingActionStates.CHOOSE_ACTION: List <Actions> sendingactions = new List <Actions>(); if (actionPointsLeft <= 0) { this.buildState = BuildingActionStates.CHOOSE_MOVEMENT; break; } sendingactions.Add(Actions.SwapWeapon); sendingactions.Add(Actions.SwapComsumable); sendingactions.Add(Actions.Use); // Add Pickups if applicable if (clickedSquare.hasItemOnThis() && this.lastMovingSquare == clickedSquare) { sendingactions.Add(Actions.PickUpAndEquip); sendingactions.Add(Actions.PickUpAndStore); } // Add Attack if applicable if ((this.attackTargetedSquare = clickedSquare.getNearestAttackableZone()) != null && this.lastMovingSquare == clickedSquare) { sendingactions.Add(Actions.Attack); } // Display actions if (sendingactions.Count > 0) { sendingactions.Add(Actions.Cancel); DialogSystem.Instance.SendActionList(sendingactions); DialogSystem.Instance.TurnOnDialog(Input.mousePosition.x, Input.mousePosition.y); } break; // if outside of range. do nothing default: throw new ArgumentOutOfRangeException(); } // Update UI at the end of every action int currentCost = this.currentBuiltPlan.ActionPointCost; CanvasManager.Instance.UIInfoPanel.UpdateActionSpentValue(currentCost); if (currentCost > 0) { CanvasManager.Instance.UIActionPanel.ShowCancelPlanningButton(); CanvasManager.Instance.UIActionPanel.ShowEndPlanningButton(); } else { CanvasManager.Instance.UIActionPanel.HideCancelPlanningButton(); CanvasManager.Instance.UIActionPanel.HideEndPlanningButton(); } } } // //if (GridSystem.Instance.clickedSquare) // GridSystem.Instance.clickedSquare.Range(range); }