// if a peice comes within threatening range it should be measured against current threats public virtual void updateThreat(GameObject threat) { float oldThreatValue = 0; _threats.Add(threat); float newThreatValue = rankThreat(threat.GetComponent <ChessPieceBehaviour>()); if (_topThreat != null) { oldThreatValue = _topThreat.GetComponent <ChessPieceBehaviour> ()._attackRange *_topThreat.GetComponent <ChessPieceBehaviour> ()._hitPoints; if (newThreatValue > oldThreatValue) { _topThreat = threat; } transform.LookAt(_topThreat.transform.position); _currentBehavior = behaviorStates.THREATENED; anim.SetBool(_threatHash, true); } else { _topThreat = threat; transform.LookAt(_topThreat.transform.position); _currentBehavior = behaviorStates.THREATENED; anim.SetBool(_threatHash, true); } }
public virtual void takeDamage(int damage, ChessPieceBehaviour attacker) { Cursor.SetCursor(GameState.Instance.GUI.GetComponent <GameplayGUI> ()._pickTexture, Vector2.zero, CursorMode.Auto); _currentHP -= damage; if (_currentHP < 1) { //AIs piece was killed in an attack if (_owner == GameState.Instance.AIPlayer && GameState.Instance.CurrentPlayer == GameState.Instance.AIPlayer) { _AI_impaled = true; } death(); if (!attacker._name.Equals("Hydra")) //hydra makes multiple attacks and calls a victory check only once after all of them { GameState.Instance.checkForVictory(); //if an AIs attacking piece is killed it should still do a second action if available. if (GameState.Instance.GUI.GetComponent <GameplayGUI>().CurrentState == GameplayGUI.PickingStates.PICK_MODE && _AI_impaled == true) { _AI_impaled = false; GameState.Instance.AIPlayer.doSecondAction(); } } } else { anim.Play("Damaged"); _soundEffect.PlayOneShot(_DamagedSound, .75f); _currentBehavior = behaviorStates.THREATENED; anim.SetBool(_threatHash, true); //hydra makes multiple attacks and the calls a victory check which sets the gui state, and kings in duel mode should stay in that mode if (!attacker._name.Equals("Hydra") && GameState.Instance.GUI.GetComponent <GameplayGUI>().CurrentState != GameplayGUI.PickingStates.DUEL_MODE) { GameState.Instance.GUI.GetComponent <GameplayGUI>().CurrentState = GameplayGUI.PickingStates.PICK_MODE; } } }
public virtual void checkThreats() { float threatValue = 0; //rank threatening pieces _topThreat = null; Player opponent = null; if (GameState.Instance.getPlayer(true) == _owner) { opponent = GameState.Instance.getPlayer(false); } else { opponent = GameState.Instance.getPlayer(true); } if (opponent.King != null) { if (legitTarget(opponent.King)) //possible threat may also be possible target { _targets.Add(opponent.King); opponent.King.GetComponent <ChessPieceBehaviour>().updateThreat(gameObject); } if (opponent.King.GetComponent <ChessPieceBehaviour>().legitTarget(gameObject)) { if (!opponent.King.GetComponent <ChessPieceBehaviour>().Targets.Contains(gameObject)) { opponent.King.GetComponent <ChessPieceBehaviour>().Targets.Add(gameObject); } _threats.Add(opponent.King); threatValue = rankThreat(opponent.King.GetComponent <ChessPieceBehaviour>()); _topThreat = opponent.King; } } if (opponent.ChessPieceNames.Count > 0) { foreach (string piece in opponent.ChessPieceNames) { GameObject obj = opponent.ChessPieces[piece]; if (legitTarget(obj)) //possible threat may also be possible target { obj.GetComponent <ChessPieceBehaviour>().updateThreat(gameObject); _targets.Add(obj); } if (obj.GetComponent <ChessPieceBehaviour>().legitTarget(gameObject)) { obj.GetComponent <ChessPieceBehaviour>().Targets.Add(gameObject); //compare all threatening pieces.Mark the most threatening one _threats.Add(obj); float newThreatValue = rankThreat(obj.GetComponent <ChessPieceBehaviour>()); if (newThreatValue > threatValue) { threatValue = newThreatValue; _topThreat = obj; } } } } if (_topThreat != null) { transform.LookAt(_topThreat.transform.position); if (_currentBehavior != behaviorStates.THREATENED) { _soundEffect.PlayOneShot(_guardSound, .75f); } _currentBehavior = behaviorStates.THREATENED; anim.SetBool(_threatHash, true); } else { _currentBehavior = behaviorStates.WAITING; anim.SetBool(_threatHash, false); } }