Exemple #1
0
    // private bool isGround = false;

    //ゲーム開始時に一度
    void Start()
    {
        hp_manager_ = GetComponent<HPManager>();
        enemy_stater_ = GetComponent<EnemyStater>();

        //Playerオブジェクトを検索し、参照を代入
        player = GameObject.FindGameObjectWithTag("Player").transform;
        distance_state = DISTANCE_STATE.LONG;
        attack_state = ATTACK_STATE.WAIT;
    }
 private void Ai_Reset( )
 {
     Player          = null;
     FollowingPlayer = null;
     Breadcrumb      = null;
     FollowingAi     = null;
     Waypoint        = null;
     wanderTimer     = 0;
     moveState       = MOVEMENT_STATE.IsIdle;
     attackState     = ATTACK_STATE.CanNotAttack;
 }
Exemple #3
0
    //ゲーム開始時に一度
    void Start()
    {
        hp_manager_ = GetComponent<HPManager>();
        enemy_stater_ = GetComponent<EnemyStater>();

        //Playerオブジェクトを検索し、参照を代入
        player = GameObject.FindGameObjectWithTag("Player").transform;
        distance_state = DISTANCE_STATE.LONG;
        attack_state = ATTACK_STATE.WAIT;

        right_weapon_ = right_weapon_object_.GetComponentInChildren<Weapon>();
        left_weapon_ = left_weapon_object_.GetComponentInChildren<Weapon>();

        var id = GetComponent<Identificationer>().id;
        var air_frame_parameter = FindObjectOfType<AirFrameParameter>();
        speed = air_frame_parameter.GetMoveSpeed(id);
        JUMP_POWER = air_frame_parameter.GetJumpPower(id);
        BOOST_POWER = air_frame_parameter.GetBoostPower(id);

        foreach (var room in FindObjectsOfType<EnterRoom>())
        {
            if (room.transform.parent.name.GetHashCode() != roomName.GetHashCode()) continue;
            enter_room_ = room;
            Debug.Log(gameObject.name);
        }
    }
    // Start is called before the first frame update
    void Start()
    {
        parameters.Clear();

        detect = new Parameter(Parameter.ParamTypes.BOOLEAN, "DetectPlayer");
        life   = new Parameter(Parameter.ParamTypes.INTEGER, "Life");
        parameters.Add(detect);
        parameters.Add(life);



        //States


        IDLE_STATE waitForPlayer = new IDLE_STATE();

        waitForPlayer.name = "WaitForPlayer";


        tranformToDemon      = new TRANSFORM_STATE();
        tranformToDemon.name = "BECOME DEMON";


        ATTACK_STATE attackPlayer = new ATTACK_STATE();

        attackPlayer.name = "AttackPlayer";


        FLEE_STATE fleeFromPlayer = new FLEE_STATE();

        fleeFromPlayer.name = "FLEE";


        returnBackToNormal      = new TRANSFORM_STATE();
        returnBackToNormal.name = "BECOME HUMAN";



        deathReturnNormalForm      = new TRANSFORM_STATE();
        deathReturnNormalForm.name = "REVERT FORM";

        IDLE_STATE deadDemon = new IDLE_STATE();

        deadDemon.name = "DEAD";

        //Transitions

        Transition waitToTransform_T = new Transition();

        waitToTransform_T.nextState = tranformToDemon;


        Transition transformToAttack_T = new Transition();

        transformToAttack_T.nextState = attackPlayer;

        //Return back transition

        Transition AttackToNormalForm_T = new Transition();

        AttackToNormalForm_T.nextState = returnBackToNormal;


        Transition AttackToFlee_T = new Transition();

        AttackToFlee_T.nextState = fleeFromPlayer;



        Transition normalFormToWait_T = new Transition();

        normalFormToWait_T.nextState = waitForPlayer;

        Transition attackToRevertForm_T = new Transition();

        attackToRevertForm_T.nextState = deathReturnNormalForm;

        Transition fleeToReverForm_T = new Transition();

        fleeToReverForm_T           = new Transition();
        fleeToReverForm_T.nextState = deathReturnNormalForm;

        Transition RevertFormToDeath_T = new Transition();

        RevertFormToDeath_T.nextState = deadDemon;



        //Condition

        Condition checkDetectPlayer_CON = new Condition(Condition.ConditionTypes.TRUE, detect);


        //PLUG CONDITIONS TO TRANSITIONS

        waitToTransform_T.conditions.Add(checkDetectPlayer_CON);

        waitForPlayer.transitions.Add(waitToTransform_T);


        tranformToDemon.transitions.Add(transformToAttack_T);

        //waitToAttack_T.conditions.Add(checkDetectPlayer_CON);

        //waitForPlayer.transitions.Add(waitToAttack_T);



        //-------------------

        Condition checkLostPlayer_CON = new Condition(Condition.ConditionTypes.FALSE, detect);

        AttackToNormalForm_T.conditions.Add(checkLostPlayer_CON);


        //normalFormToWait.conditions.Add(checkLostPlayer_CON);

        attackPlayer.transitions.Add(AttackToNormalForm_T);


        returnBackToNormal.transitions.Add(normalFormToWait_T);



        Condition checkLife_CON = new Condition(Condition.ConditionTypes.EQUAL, life);

        checkLife_CON.intValue = 0;


        attackToRevertForm_T.conditions.Add(checkLife_CON);

        attackPlayer.transitions.Add(attackToRevertForm_T);


        deathReturnNormalForm.transitions.Add(RevertFormToDeath_T);


        Condition LowLifeFlee_CON = new Condition(Condition.ConditionTypes.LESS, life);

        LowLifeFlee_CON.intValue = 2;


        AttackToFlee_T.conditions.Add(LowLifeFlee_CON);
        attackPlayer.transitions.Add(AttackToFlee_T);



        fleeToReverForm_T.conditions.Add(checkLife_CON);
        fleeFromPlayer.transitions.Add(fleeToReverForm_T);


        //Piece them together

        currentState = waitForPlayer;

        states.Add(waitForPlayer);
        states.Add(attackPlayer);
        states.Add(tranformToDemon);
        states.Add(returnBackToNormal);
        states.Add(fleeFromPlayer);
        states.Add(deathReturnNormalForm);
        states.Add(deadDemon);



        //parameters.Add()
    }
        private void Ai_Controller( )
        {
            // Checks if following player is enabled and a player has been found
            if (_CanFollowPlayer && this.Ai_FindPlayer( ))
            {
                _HasWanderPos = false;                 // TODO: this needs to be fixed
                visionState   = VISION_STATE.CanSeePlayer;


                // CHANGE THIS TO FLEE (_CanFlee)
                if (_IsRanged)                     // Is this a ranged ground unit?
                {
                    if (Vector3.Distance(transform.position, Player.position) > followDistance)
                    {
                        moveState   = MOVEMENT_STATE.IsFollowingPlayer;
                        attackState = ATTACK_STATE.CanNotAttack;
                        Ai_Movement(Player.position, followSpeed);
                    }
                    else if (_CanFlee && Vector3.Distance(transform.position, Player.position) <= attackDistance)
                    {
                        moveState   = MOVEMENT_STATE.IsFollowingPlayer;
                        attackState = ATTACK_STATE.CanNotAttack;
                        Ai_Flee( );
                    }
                    else
                    {
                        moveState   = MOVEMENT_STATE.IsIdle;
                        attackState = ATTACK_STATE.CanAttackPlayer;
                        Ai_Rotation(Player.position);
                    }
                }
                else if (_IsMelee)                       // Is this a melee ground unit?
                {
                    if (Vector3.Distance(transform.position, Player.position) > followDistance)
                    {
                        moveState   = MOVEMENT_STATE.IsFollowingPlayer;
                        attackState = ATTACK_STATE.CanNotAttack;
                        Ai_Movement(Player.position, followSpeed);
                    }
                    else if (Vector3.Distance(transform.position, Player.position) <= attackDistance)
                    {
                        moveState   = MOVEMENT_STATE.IsIdle;
                        attackState = ATTACK_STATE.CanAttackPlayer;
                        Ai_Rotation(Player.position);
                    }
                }
                Debug.DrawLine(transform.position, Player.position, Color.red);

                // Checks if following breadcrumbs is enabled as well as if a player was spotted and a breadcrumb has been found
            }
            else if (_CanFollowBreadcrumbs && FollowingPlayer && this.Ai_FindBreadcrumb( ))
            {
                _HasWanderPos = false;                 // TODO: this needs to be fixed
                visionState   = VISION_STATE.CanSeeBreadcrumb;
                moveState     = MOVEMENT_STATE.IsFollowingBreadcrumb;
                attackState   = ATTACK_STATE.CanNotAttack;
                Ai_Movement(Breadcrumb.position, followSpeed);
                Debug.DrawLine(transform.position, Breadcrumb.position, Color.green);

                // Checks if following other ai is enabled and if an ai has been found
            }
            else if (_CanFollowAi && this.Ai_FindAi( ))
            {
                _HasWanderPos = false;                 // TODO: this needs to be fixed
                visionState   = VISION_STATE.CanSeeFollowAi;
                moveState     = MOVEMENT_STATE.IsFollowingAi;
                attackState   = ATTACK_STATE.CanNotAttack;
                if (Vector3.Distance(transform.position, FollowingAi.position) > otherAiDistance)
                {
                    Ai_Movement(FollowingAi.position, followSpeed);
                }
                else
                {
                    moveState = MOVEMENT_STATE.IsIdle;
                }
                Debug.DrawLine(transform.position, FollowingAi.position, Color.magenta);

                // Checks if following other ai is enabled and if a tier two ai has been found
            }
            else if (_CanFollowAi && this.Ai_FindAiTierTwo( ))
            {
                _HasWanderPos = false;                 // TODO: this needs to be fixed
                visionState   = VISION_STATE.CanSeeFollowAiTierTwo;
                moveState     = MOVEMENT_STATE.IsFollowingAiTierTwo;
                attackState   = ATTACK_STATE.CanNotAttack;
                if (Vector3.Distance(transform.position, FollowingAi.position) > otherAiDistance)
                {
                    Ai_Movement(FollowingAi.position, followSpeed);
                }
                else
                {
                    moveState = MOVEMENT_STATE.IsIdle;
                }
                Debug.DrawLine(transform.position, FollowingAi.position, Color.white);

                // Checks if wandering is enabled and if the timer has reached its limit
            }
            else if (_CanWander && wanderTimer < wanderTimeLimit)
            {
                visionState = VISION_STATE.CanSeeNothing;
                attackState = ATTACK_STATE.CanNotAttack;
                Ai_Wander( );

                // Checks if patrolling is enabled and a waypoing has been found
            }
            else if (_CanPatrol && this.Ai_FindWaypoint( ))
            {
                _HasWanderPos = false;                 // TODO: this needs to be fixed
                visionState   = VISION_STATE.CanSeeWaypoint;
                moveState     = MOVEMENT_STATE.IsPatrolling;
                attackState   = ATTACK_STATE.CanNotAttack;
                Ai_Movement(Waypoint.position, patrolSpeed);
                Debug.DrawLine(transform.position, Waypoint.position, Color.yellow);

                // Nothing is found, reset all variables
            }
            else
            {
                Ai_Reset( );
            }
        }
Exemple #6
0
 // private bool isGround = false;
 //ゲーム開始時に一度
 void Start()
 {
     //Playerオブジェクトを検索し、参照を代入
     player = GameObject.FindGameObjectWithTag("Player").transform;
     distance_state = DISTANCE_STATE.LONG;
     attack_state = ATTACK_STATE.WAIT;
 }