Exemple #1
0
    bool Hit(float damage)
    {
        if (UnityEngine.Random.Range(0, 100) > (_guarding ? _baseDodgeChance * 2 : _baseDodgeChance))
        {
            _currentHealth -= damage;
            if (_currentHealth <= 0)
            {
                _currentHealth = 0;
                _alive         = false;
                StateTracker.WriteHistory(gameObject);

                rigidbody.useGravity  = true;
                rigidbody.constraints = RigidbodyConstraints.None;
                this.transform.Rotate(Vector3.forward, 1.5f);

                Steering.SetSteeringActive(this.transform, false);

                if (Team == Teams.Team1)
                {
                    TurnManager.OnTeam1 -= NewTurn;
                }
                if (Team == Teams.Team2)
                {
                    TurnManager.OnTeam2 -= NewTurn;
                }
            }
            return(true);
        }
        return(false);
    }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        if (currentPlayerDone)
        {
            if (_useAI && _teamUsingAI == CurrentTeam)
            {
                bool AIDone = true;
                foreach (Unit unit in _teamAI)
                {
                    Steering.SteeringUpdate(unit.transform);
                    if (!Steering.GetSteeringActive(unit.transform))
                    {
                        if (unit.LeftMoves > 0)
                        {
                            //Debug.Log("Previous: " + _unitCurrentState[unit].StateName);

                            AIDone = false;

                            /*
                             * if (_unitCurrentState[unit].GetExitActionList() != null)
                             * {
                             *      //Der er ikke noget i den her liste smarte...
                             *
                             *      foreach(IAction action in _unitCurrentState[unit].GetExitActionList())
                             *      {
                             *              action.act(unit.gameObject);
                             *      }
                             * }*/

                            State s = AIWrapper.GetDecision(unit.gameObject, ((State)UnitFSM.FSM.CurrentState));
                            if (s != UnitFSM.FSM.CurrentState && s.StateName != "default")
                            {
                                StateTracker.AddTransition((State)UnitFSM.FSM.CurrentState, s, unit.gameObject);
                                UnitFSM.FSM.CurrentState = s;
                            }
                            List <IAction> acti = ((State)UnitFSM.FSM.CurrentState).GetActionList();
                            foreach (IAction ac in acti)
                            {
                                ac.act(unit.gameObject);
                            }

                            //TODO Get action
                            //DefendAction att = new DefendAction();
                            unit.UseTurn(UnitActions.Move, null);
                            //att.act(unit.gameObject);
                        }
                    }
                    else
                    {
                        AIDone = false;
                    }
                    //TODO do AI stuff
                }
                if (AIDone)
                {
                    SwitchPlayer();
                }
            }
            else if (CurrentTeam == Teams.Team1)
            {
                if (Camera.main.transform.rotation.eulerAngles.y < 10 || Camera.main.transform.rotation.eulerAngles.y > 350)
                {
                    Camera.main.transform.eulerAngles = new Vector3(90, 0, 0);
                    currentPlayerDone = false;
                }
                else
                {
                    Camera.main.transform.Rotate(new Vector3(0, 0, -1) * rotationPerSecond * Time.deltaTime);
                }
            }
            else if (CurrentTeam == Teams.Team2)
            {
                if (Camera.main.transform.rotation.eulerAngles.y < 190 && Camera.main.transform.rotation.eulerAngles.y > 170)
                {
                    Camera.main.transform.eulerAngles = new Vector3(90, 180, 0);
                    currentPlayerDone = false;
                }
                else
                {
                    Camera.main.transform.Rotate(new Vector3(0, 0, 1) * rotationPerSecond * Time.deltaTime);
                }
            }
        }
        if (OnTeam1 == null && !GameOver)
        {
            GameOver = true;
            if (_teamUsingAI == Teams.Team1)
            {
                foreach (Unit u in _teamAI)
                {
                    StateTracker.WriteHistory(u.parent);
                }
            }
            Debug.Log("Team 2 won");
        }
        else if (OnTeam2 == null && !GameOver)
        {
            GameOver = true;
            if (_teamUsingAI == Teams.Team2)
            {
                foreach (Unit u in _teamAI)
                {
                    StateTracker.WriteHistory(u.parent);
                }
            }
            Debug.Log("Team 1 WON");
        }
        //rotate camera
    }