/// <summary> /// Method makes turn transitions. It is called by player at the end of his turn. /// </summary> public void EndTurn() { if (Units.Select(u => u.PlayerNumber).Distinct().Count() == 1) { return; } CellGridState = new CellGridStateBase(this); // End turn for current unit and advance the init tracker InitTracker[0].OnTurnEnd(); AdvanceTracker(); // Set current player to next player in the initiative CurrentPlayerNumber = InitTracker[0].PlayerNumber; if (TurnEnded != null) { TurnEnded.Invoke(this, new EventArgs()); } // Start next unit's turn InitTracker[0].OnTurnStart(); Players.Find(p => p.PlayerNumber.Equals(CurrentPlayerNumber)).Play(this); // Select unit if (CurrentPlayerNumber == 0) { CellGridState = new CellGridStateUnitSelected(this, InitTracker[0]); } }
// Delay cellgrid state change to allow cell sprites to load first private IEnumerator StartGameSelect() { yield return(new WaitForSeconds(0.5f)); if (CurrentPlayerNumber == 0) { CellGridState = new CellGridStateUnitSelected(this, InitTracker[0]); } }
public void MovekSelection() { if (UnitList[Turn].ActionPoints == 1) { CellGridState = new CellGridStateUnitSelected(this, UnitList[Turn]); } else if (UnitList[Turn].Image == "Rogue") { CellGridState = new CellGridStateUnitSelected(this, UnitList[Turn]); } else { return; } }
private void OnUnitClicked(object sender, EventArgs e) { if (!EventSystem.current.IsPointerOverGameObject()) { GenericUnit unit = sender as GenericUnit; CellGridStateUnitSelected selected = CellGridState as CellGridStateUnitSelected; if (unit.PlayerNumber == 0) { } else { CellGridState.OnUnitClicked(sender as Unit); if (!isActionDone && selected.IsUnitInRange(sender as Unit)) { EndTurn(); } } } }
/// <summary> /// Method is called once, at the beggining of the game. /// </summary> public void StartGame() { if (GameStarted != null) { GameStarted.Invoke(this, new EventArgs()); } Units.FindAll(u => u.PlayerNumber.Equals(CurrentPlayerNumber)).ForEach(u => { u.OnTurnStart(); }); Players.Find(p => p.PlayerNumber.Equals(CurrentPlayerNumber)).Play(this); //Assign Unit Menu Methods foreach (Unit u in Units) { if (u.gameObject.tag == "Player") { u.selectUnitBtn = (x) => { /* * CellGridStateUnitSelected CGS = new CellGridStateUnitSelected(this,u); * CGS.OnStateEnter(); * CGS.OnCellClicked(u.Cell); * CGS.OnUnitClicked(u); * CGS.OnCellSelected(u.Cell); * u.Cell.MarkAsHighlighted(); * * u.OnUnitSelected(); * u.OnMouseEnter(); */ foreach (Cell c in Cells) { if (c.isWithinAbilityRange) { c.isWithinAbilityRange = false; if (c.returnCellUnit(c) != null) { c.returnCellUnit(c).GetComponent <Avatar>().RemoveAoeUI(); } } } foreach (Avatar gameObj in Avatar.avatarList) { if (gameObj != null) { if (gameObj.tag == "Player" && gameObj.GetComponent <Avatar>().AvatarIndex == x) { gameObj.GetComponent <Unit>().Cell.OnMouseDown(); gameObj.GetComponent <Unit>().OnMouseDown(); //gameObj.GetComponent<Unit>().abilityReadyToFire = false; } } } }; u.endTeamTurn = () => { EndTurn(); }; u.abilityRange = (x) => { foreach (Avatar gameObj in Avatar.avatarList) { if (gameObj != null) { if (gameObj.tag == "Player" && gameObj.GetComponent <Avatar>().AvatarIndex == x) { CellGridStateUnitSelected CGS = new CellGridStateUnitSelected(this, gameObj.GetComponent <Unit>()); CGS.showAbilityRange(); } } } }; } } }