private void onCellClicked(object sender, EventArgs e) { if (!fsm.GetCurrentState().CellClickAllowed()) { Debug.Log("Cell click not allowed in this state"); return; } // Battleboard decides, what action to do if cell clicked (bc Battleboard is kinda CellManager) BattleboardCell cell = sender as BattleboardCell; if (currentRoute != null) { if (currentCharacter.APEnoughForWalk(currentRoute.Count - 1)) { fsm.GetCurrentState().GoToStateInputDisabled(); // it's much easier and clearer to make a copy of the route, and correct it, // taking into account amount of APs, than setting a bunch of conditions here, in Character, // and in Character's Moving State var routeCopy = currentRoute.ToList <BattleboardCell>(); // copying using linq currentCharacter.MoveByRoute(routeCopy); DestroyRoute(); // we don't need it anymore; in fact, we could emulate onMouseExit, but it would confuse code reading } else { Log.Output(Log.NOT_ENOUGH_AP); } } if (cell.IsOccupiedByCharacterOfParty(cell, enemyParty)) { // attempt to attack if (AreCellsAdjacent(cell.transform.position, currentCharacter.transform.position)) { if (currentCharacter.APEnoughForAttack()) { fsm.GetCurrentState().GoToStateInputDisabled(); if (null == charactersInAttack) { charactersInAttack = new List <Character>(); } else { charactersInAttack.Clear(); } charactersInAttack.Add(currentCharacter); charactersInAttack.Add(cell.Character); currentCharacter.AttackThe(cell.Character); (sender as BattleboardCell).ExternalModificatorColor = Color.clear; // in fact, we could emulate onMouseExit, but it would confuse code reading } else { Log.Output(Log.NOT_ENOUGH_AP); } } else { Log.Output("Target is too far"); // #localize } } // if cell is occupied by a character from player's party -- don't do anything }
private void onCellMouseEnter(object sender, EventArgs e) { if (!fsm.GetCurrentState().CellMouseEnterAllowed()) { Debug.Log("Cell mouse enter not allowed in this state"); return; } int APAmountRequired = 0; string cellInformationText = ""; bool cellInformationTextAchtung = false; // Battleboard decides, what action to do if cell clicked (bc Battleboard is kinda CellManager) BattleboardCell cell = sender as BattleboardCell; if (cell.IsVacant()) { BattleboardCell currentCell = FindCellOfCharacter(currentCharacter); currentRoute = BuildRoute(currentCell, cell); var routeRealLength = currentRoute.Count - 1; APAmountRequired = currentCharacter.WalkCost * routeRealLength; if (APAmountRequired > 0) // we need this check here in order not to create cellinfo when mouse is on current character's cell with 0 AP { // #localize: cellInformationText = currentCharacter.APEnoughForWalk(routeRealLength) ? "Walk here\nfor " + APAmountRequired + " AP" + Utility.GetIntegerEnding(APAmountRequired) : cellInformationText = String.Format("{0} to walk here\nRequired: {1}", Log.NOT_ENOUGH_AP, APAmountRequired); cellInformationTextAchtung = !currentCharacter.APEnoughForWalk(routeRealLength); } MarkInRouteCells(); } if (cell.IsOccupiedByCharacterOfParty(cell, enemyParty)) { if (AreCellsAdjacent(cell.transform.position, currentCharacter.transform.position)) { APAmountRequired = currentCharacter.AttackCost; cell.ExternalModificatorColor = currentCharacter.APEnoughForAttack() ? BattleboardCell.enoughAPColor : BattleboardCell.noAPColor; // #localize: cellInformationText = currentCharacter.APEnoughForAttack() ? String.Format("Attack {0} {3}\nfor {1} AP{2}", cell.Character.GetHealthStatus(), APAmountRequired, Utility.GetIntegerEnding(APAmountRequired), cell.Character.Name) : String.Format("{0} for attack {2} {3}\nRequired: {1}", Log.NOT_ENOUGH_AP, APAmountRequired, cell.Character.GetHealthStatus(), cell.Character.Name); cellInformationTextAchtung = !currentCharacter.APEnoughForAttack(); } else // show enemy's name and health status { // #localize: cellInformationText = String.Format("{0}\n{1}", cell.Character.Name, cell.Character.GetHealthStatus()); } } // if it's out teammate, show his/her name and exact HP if (cell.IsOccupiedByCharacterOfParty(cell, playerParty)) { // #localize: cellInformationText = String.Format("{0}\nHP: {1}", cell.Character.Name, cell.Character.HP); } if (!String.IsNullOrEmpty(cellInformationText)) { ShowCellInformation(cell, cellInformationText, cellInformationTextAchtung); } }