//========================= // Clean Up: //========================= // cleans up when combat sequence has finished public void Finish() { GLOBAL.setLock(false); active = false; preCombat = true; retaliation = false; if (!attacker.isDead) { attacker.Deactivate(); } else { PlayerManager.Instance.getCurrentPlayer().selectedObject = null; } // refresh board status for combat buffs etc GameDirector.Instance.BoardStateChanged(); ObjectManager.Instance.EndTurnForPlayer(attacker.playerID); if (PlayerManager.Instance.getCurrentPlayer().playerType == Player.PLAYER_TYPE.Computer) { // this is an AI unit so continue the turn sequence after death if (AIManager.Instance.getNext(false) != null) { AIManager.Instance.callNextUnit(); } } }
// begins damage sequence public void Damage(int dmg) { GLOBAL.setLock(true); timer = 0; prevTimer = 0; // TODO: enable mini healthbar under board unit here (or always enabled if not too obstructive) if (health - dmg < 0) { // if there is overkill use it to offset final dmg amount finalDmg = dmg + (health - dmg); } else { finalDmg = dmg; } // get interval interval = GLOBAL.dmgTime / finalDmg; // DAMAGE TEXT: if (finalDmg < 1) { // TODO: instantiate "NO DAMAGE" text } else { // TODO: instantiate "-finalDmg" text } prevState = state; // store current state to revert after sequence state = UnitState.Damage; }
// called by attack button to instigate an AoE damage sequence public void AoEAttack() { //TileMarker.Instance.Clear(); TileMarker.Instance.HideMarkers(); // attacking unit has committed to this AoE weapon for the turn so equip it PlayerManager.Instance.getCurrentPlayer().selectedObject.GetComponent <Unit>().Equip(AoEWeapon); AoESequence = true; timer = 0; GLOBAL.setLock(true); // lock input during AoE sequence UIManager.Instance.setUnitUI(false); // disable unit UI (unit turn is done after attack sequence anyway) UIManager.Instance.deactivateConfirmButton(); // play animation, offset by half of tilesize to accommodate center anchor if (AoEWeapon.AoEanim != null) { Instantiate(AoEWeapon.AoEanim, GLOBAL.gridToWorld(AoERoot) + new Vector3((int)(IntConstants.TileSize) / 2, (int)(IntConstants.TileSize) / 2), Quaternion.identity); } else { AoEWeapon.StartAoEAnim(); } }
public bool CheckDead() { if (health <= 0) { isDead = true; GLOBAL.setLock(true); return(true); } return(false); }
public void endGame() { for (int i = 0; i < players.Count; i++) { Destroy(players[i]); } players.Clear(); currentPlayersTurn = 1; TurnLabelTop.GetComponent <Text>().text = "Your Turn"; TurnLabel.GetComponent <Text>().text = "Your Turn"; GLOBAL.setLock(false); }
public void setUpNPlayers(int n) { if (GameDirector.Instance.isSinglePlayer()) { for (int i = 0; i < 2; i++) { GameObject testPlayer = Instantiate(Resources.Load("Player")) as GameObject; // GameObject testPlayer = PhotonNetwork.Instantiate("Player", Vector3.zero, Quaternion.identity, 0) as GameObject; players.Add(testPlayer); testPlayer.transform.parent = gameObject.transform; string s = (i + 1) + "Player"; if (i == 0) { testPlayer.GetComponent <Player>().initPlayer(s, (i + 1), Color.red, false, Player.PLAYER_TYPE.Human); } else { Debug.Log("initing computer"); testPlayer.GetComponent <Player>().initPlayer(s, (i + 1), Color.red, false, Player.PLAYER_TYPE.Computer); } } } else { GameObject testPlayer = Instantiate(Resources.Load("Player")) as GameObject; //GameObject testPlayer = PhotonNetwork.Instantiate("Player", Vector3.zero, Quaternion.identity, 0) as GameObject; players.Add(testPlayer); testPlayer.transform.parent = gameObject.transform; string s = (PhotonNetwork.player.ID) + "Player"; testPlayer.GetComponent <Player>().initPlayer(s, (PhotonNetwork.player.ID), Color.red, true, Player.PLAYER_TYPE.Human); if (PhotonNetwork.player.ID != 1) { TurnLabelTop.GetComponent <Text>().text = "Enemy Turn"; TurnLabel.GetComponent <Text>().text = "Enemy Turn"; EndTurnButton.GetComponent <Button>().enabled = false; GLOBAL.setLock(true); } } }
public void NextTurn(int t) { PlayerManager.Instance.currentPlayersTurn = t; if (t == PhotonNetwork.player.ID) { PlayerManager.Instance.TurnLabelTop.GetComponent <Text>().text = "Your Turn"; PlayerManager.Instance.TurnLabel.GetComponent <Text>().text = "Your Turn"; PlayerManager.Instance.EndTurnButton.GetComponent <Button>().enabled = true; GLOBAL.setLock(false); } else { PlayerManager.Instance.TurnLabelTop.GetComponent <Text>().text = "Enemy Turn"; PlayerManager.Instance.TurnLabel.GetComponent <Text>().text = "Enemy Turn"; PlayerManager.Instance.EndTurnButton.GetComponent <Button>().enabled = false; GLOBAL.setLock(true); } UIManager.Instance.animateTurnPanel(); }
public void deactivateTurnPanel() { EndturnButton.enabled = true; this.gameObject.SetActive(false); if (GameDirector.Instance.isMultiPlayer() && PhotonNetwork.player.ID == PlayerManager.Instance.getCurrentPlayerTurn()) { GLOBAL.setLock(false); } else if (GameDirector.Instance.isSinglePlayer()) { if (PlayerManager.Instance.getCurrentPlayer().playerID == 1) { GLOBAL.setLock(false); } else { AIManager.Instance.startEnemyTurn(); } } }
// moves a unit along a path void Move() { if (path.Count > 0) { if (path[path.Count - 1].Distance(transform.position) <= 4) // magic number: move 2-4 pixels per frame. prevents passing destination (i hope.............) { // reached next node in list, update list and proceed to next destination snapToPos(path[path.Count - 1]); // snap to exact position before continuing prev = path[path.Count - 1]; path.RemoveAt(path.Count - 1); if (path.Count == 0) { // reached destination state = UnitState.Waiting; if (GameDirector.Instance.isMultiPlayer() || (isHuman() && GameDirector.Instance.isSinglePlayer())) { UIManager.Instance.setUnitUI(true); // display UI now that inputs are } ObjectManager.Instance.moveUnitToGridPos(gameObject, prev); TileMarker.Instance.markAttackTiles(this); GameDirector.Instance.BoardStateChanged(); if (GameDirector.Instance.isSinglePlayer() && !isHuman()) { AI.ReachedDestination(); } else { GLOBAL.setLock(false); // inputs are no longer locked } } } else { // haven't reached next node in path yet, continue lerping Vector2i dir = path[path.Count - 1] - prev; // next node in path is guaranteed to be neighbour, so displacement vector = dir vector transform.Translate((dir * (2 * (1 + Convert.ToInt32(Input.GetKey(KeyCode.Space))))) * (Time.deltaTime * 100)); // double speed if button held (space for temporarily) } } }
// makes the unit travel to its destination public void TravelToPos(Vector2i destination) { // disable UI until destination reached UIManager.Instance.setUnitUI(false); UIManager.Instance.deactivateAoEButton(); path = new List <Vector2i>(); // tile nodes of the path to be travelled Tile curr = TerrainLayer.Instance.Tiles[destination.x, destination.y]; // destination node path.Add(curr.pos); while (curr.parent != null) { path.Add(curr.parent.pos); curr = curr.parent; } // path has been computed, travel to node at end of list until at destination state = UnitState.Moving; // set unit state GLOBAL.setLock(true); // lock user input until path is traversed }
// cleans up when AoE sequence has finished public void FinishAoE() { GLOBAL.setLock(false); AoESequence = false; if (PlayerManager.Instance.getCurrentPlayer().selectedObject != null) { PlayerManager.Instance.getCurrentPlayer().selectedObject.GetComponent <Unit>().Deactivate(); } // refresh board status for combat buffs etc GameDirector.Instance.BoardStateChanged(); ObjectManager.Instance.EndTurnForPlayer(attacker.playerID); if (PlayerManager.Instance.getCurrentPlayer().playerType == Player.PLAYER_TYPE.Computer) { // this is an AI unit so continue the turn sequence after death if (AIManager.Instance.getNext() != null) { AIManager.Instance.callNextUnit(); } } }
public void deactivateTurnPanel() { turnPanel.SetActive(false); GLOBAL.setLock(false); }
public void animateTurnPanel() { turnPanel.SetActive(true); GLOBAL.setLock(true); }
// real-time damage sequence public void DamageSequence() { if (finalDmg > 0) { if (timer == 0) { // remove from lists at beginning of sequence so enemy AI doesnt process attacks before fully disappearing on death if (health - finalDmg <= 0) { GameObject unit = ObjectManager.Instance.ObjectGrid[pos.x, pos.y]; ObjectManager.Instance.ObjectGrid[pos.x, pos.y] = null; if (unit != null) { if (unit.GetComponent <Unit>().playerID == 1) { ObjectManager.Instance.PlayerOneUnits.Remove(unit); } else { ObjectManager.Instance.PlayerTwoUnits.Remove(unit); } } } health--; } if (timer - prevTimer >= interval) { prevTimer = timer; prevTimer -= (timer % interval); // round prevTimer to nearest interval multiple health--; } // flinch motion if (timer < 0.06f) { if (CombatSequence.Instance.active) { transform.position -= CombatSequence.Instance.displacement * Time.deltaTime * GLOBAL.attackSpeed * 0.5f; } else { transform.position += Vector3.left * Time.deltaTime * GLOBAL.attackSpeed * 0.75f; } } else if (timer < 0.12f) { if (CombatSequence.Instance.active) { transform.position += CombatSequence.Instance.displacement * Time.deltaTime * GLOBAL.attackSpeed * 0.5f; } else { transform.position += Vector3.right * Time.deltaTime * GLOBAL.attackSpeed * 0.75f; } } // done flinch else { snapToGridPos(); } } timer += Time.deltaTime; if (timer >= GLOBAL.dmgTime) { state = prevState; if (!CombatSequence.Instance.active) { // combat sequences have death checks integrated, only check if not combat (and unlock input) CheckDead(); GLOBAL.setLock(false); } } }
protected virtual void Update() { // fade out on death if (isDead) { if (gameObject.GetComponent <SpriteRenderer>().color.a > 0) { color.a -= Time.deltaTime; gameObject.GetComponent <SpriteRenderer>().color = color; } else { //destroyUnit(); if (GameDirector.Instance.isMultiPlayer()) { gameObject.GetPhotonView().RPC("DestroyUnit", PhotonTargets.AllBuffered, pos.x, pos.y); } else { GameObject unit = ObjectManager.Instance.ObjectGrid[pos.x, pos.y]; ObjectManager.Instance.ObjectGrid[pos.x, pos.y] = null; if (unit != null) { if (unit.GetComponent <Unit>().playerID == 1) { ObjectManager.Instance.PlayerOneUnits.Remove(unit); } else { ObjectManager.Instance.PlayerTwoUnits.Remove(unit); } } Destroy(this.gameObject); } if (PlayerManager.Instance.getCurrentPlayer().playerType == Player.PLAYER_TYPE.Human) { GLOBAL.setLock(false); // unlock user input } if (ObjectManager.Instance.isGameOver()) { GameDirector.Instance.endGame(false); } } } // move along path state else if (state == UnitState.Moving) { Move(); } else if (state == UnitState.Damage) { DamageSequence(); } // temp: grey out on inactive else if (state == UnitState.Inactive) { // gameObject.GetComponent<SpriteRenderer>().color = new Color(0.4f, 0.4f, 0.4f); } // TODO: move this color change to the frame this unit is reactivated else { gameObject.GetComponent <SpriteRenderer>().color = Color.white; } }