void Awake()
 {
     Behaviour = new AIStateMachine(this);
     m_state = new AIStateZombie(this);
     Behaviour.AddState(m_state);
     Behaviour.ChangeState(m_state);
 }
Example #2
0
 protected override void OnEnable()
 {
     base.OnEnable();
     currentHP = maxHP;
     isDead    = false;
     body      = GetComponent <Rigidbody>();
     enemyAI   = GetComponent <AIStateMachine>();
 }
Example #3
0
 public void Step()
 {
     if (AIMode == EAIMode.Hand || Owner.IsDead())
     {
         return;
     }
     AIStateMachine.Step();
 }
 /// <summary>
 /// Checks for type compliance and stores the reference as the derived type
 /// </summary>
 /// <param name="stateMachine"></param>
 public override void SetStateMachine(AIStateMachine stateMachine)
 {
     if (stateMachine.GetType() == typeof(AIWerewolfStateMachine))
     {
         base.SetStateMachine(stateMachine);
         _werewolfStateMachine = (AIWerewolfStateMachine)stateMachine;
     }
 }
Example #5
0
 private void SetComponents()
 {
     _agent                      = this.gameObject.GetComponent <NavMeshAgent>();
     _anim                       = this.gameObject.transform.GetChild(0).GetComponent <Animator>();
     _aiStateMachine             = _anim.GetBehaviour <AIStateMachine>();
     _aiStateMachine.AIBehaviour = this;
     _aiFOV                      = this.gameObject.GetComponent <AiFieldOfView>();
 }
Example #6
0
 private void Start()
 {
     ai                = GetComponent <IAstarAI>();
     machine           = GetComponent <AIStateMachine>();
     scan              = GetComponent <ScanForTargets>();
     playerSpawnBounds = GameObject.Find("Priest Spawn").GetComponent <Collider2D>().bounds;
     ai.destination    = GetRandomPoint();
 }
Example #7
0
 public override void SetStateMachine(AIStateMachine stateMachine)
 {
     if (stateMachine.GetType() == typeof(AIZombieStateMachine))
     {
         base.SetStateMachine(stateMachine);
         zombieStateMachine = (AIZombieStateMachine)stateMachine;
     }
 }
 public override void SetStateMachine(AIStateMachine stateMachine)
 {
     if (stateMachine.GetType() == typeof(AINPCStateMachine))
     {
         base.SetStateMachine(stateMachine);
         _npcStateMachine = (AINPCStateMachine)stateMachine;
     }
 }
Example #9
0
 public void ChangeAIState(EAIState pAIState)
 {
     if (AIState != pAIState)
     {
         AIState = pAIState;
         AIStateMachine.ChangeState(pAIState);
     }
 }
Example #10
0
 public override void SetAIStateMachine(AIStateMachine aIStateMachine)
 {
     if (aIStateMachine.GetType() == typeof(AIZombieStateMachine))
     {
         _zombieStateMachine = (AIZombieStateMachine)aIStateMachine;
     }
     base.SetAIStateMachine(aIStateMachine);
 }
Example #11
0
    // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        AIStateMachine stateMachine = animator.GetComponent <AIStateMachine>();

        if (stateMachine != null)
        {
            stateMachine.takingDamage = true;
        }
    }
Example #12
0
    // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    //override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    //{
    //
    //}

    // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
    override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        AIStateMachine stateMachine = animator.GetComponent <AIStateMachine>();

        if (stateMachine != null && _setToFalseOnEnd)
        {
            stateMachine.takingDamage = false;
        }
    }
    private void OnTriggerEnter(Collider collider)
    {
        AIStateMachine machine = GameSceneManager.Instance.GetAIStateMachine(collider.GetInstanceID());

        if (machine)
        {
            machine.InMeleeRange = true;
        }
    }
Example #14
0
    private void OnTriggerExit(Collider other)
    {
        AIStateMachine machine = GameSceneManager.instance.GetAIStateMachine(other.GetInstanceID());

        if (machine)
        {
            machine.inMeleeRange = false;
        }
    }
Example #15
0
        /// <param name="desc">The description data (i.e. healthpoints, strength).</param>
        public KamidroneAI(ICanyonShooterGame game, EnemyDescription desc)
            : base(game, "Enemy-KamidroneAI")
        {
            EnemyNr   = EnemiesCreated++;
            this.game = game;

            // Physics Config
            ConnectedToXpa      = true;
            ContactGroup        = ContactGroup.Enemies;
            InfluencedByGravity = false;


            InfoMessage(string.Format("Created at: {0}", desc.RelativeSpawnLocation));

            currentHitpoints = desc.MaxHitpoints;
            LocalPosition    = desc.RelativeSpawnLocation;
            // System

            typeDesc = game.Content.Load <EnemyTypeDescription>("Content\\Enemies\\" + desc.Type);
            SetModel(typeDesc.Model);

            // Initiate AI-System:
            AI         = new AIStateMachine(game, this);
            AI.DebugAI = false;

            // Add States to Machine:

            AI.AddState(new Patrol()); // Init-State
            AI.AddState(new FlyToWaypoint(desc.SegmentId));
            AI.AddState(new FlyToPlayer());


            // SquadronFormations

            if (desc.SquadronCount > 1) //Enemy-Squadron erzeugen.
            {
                // Create EnemyFormation and join it
                EnemyFormation formation = new EnemyFormation(game, LocalPosition, desc.SegmentId, desc.Speed, typeDesc.Formation);
                JoinFormation(formation);
                desc.SquadronCount = 1;
                int count = typeDesc.Formation.Count - 1; // dieser enemy hat sich bereits selbst hinzugefügt.
                for (int i = 0; i < count; i++)
                {
                    // Versezte den nächsten Enemy in Richtung des Canyons
                    Vector3 canyonDirection = game.World.Level.Cache[desc.SegmentId].ADir;
                    canyonDirection.Normalize();
                    desc.RelativeSpawnLocation = desc.RelativeSpawnLocation + canyonDirection * 100;

                    // Nächsten Enemy im Squadron erzeugen:

                    KamidroneAI enemyForFormation = new KamidroneAI(game, desc);
                    //enemyFollowing.FollowEnemy(this); // follow ME!
                    enemyForFormation.JoinFormation(formation);
                    game.World.AddObject(enemyForFormation);
                }
            }
        }
Example #16
0
    // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    //override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    //{
    //
    //}

    // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
    override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        AIStateMachine stateMachine = animator.GetComponent <AIStateMachine>();

        if (stateMachine != null)
        {
            stateMachine.TerminateAllAttacks();
        }
    }
Example #17
0
    // Use this for initialization
    void Start()
    {
        machine = GetComponent <AIStateMachine>();
        anim    = GetComponent <Animator>();
        sr      = GetComponent <SpriteRenderer>();
        ai      = GetComponent <IAstarAI>();

        InvokeRepeating("ChangeFacing", 0.0f, 1.5f);
    }
Example #18
0
    void OnTriggerEnter(Collider col)
    {
        AIStateMachine machine = GameManager.instance.GetAIStateMachine(col.GetInstanceID());

        if (machine)
        {
            machine.inMeleeRange = true;
        }
    }
Example #19
0
    //通过key,来得到AIStateMachine
    public AIStateMachine GetAiStateMachine(int key)
    {
        AIStateMachine _aIStateMachine = null;

        if (_stateMachines.ContainsKey(key))
        {
            _stateMachines.TryGetValue(key, out _aIStateMachine);
        }
        return(_aIStateMachine);
    }
    private void InitializeStateMachine(AIStateMachine _sm)
    {
        var _states = new Dictionary <Type, BaseState>()
        {
            { typeof(PatrolState), new PatrolState(_me: this) },
            { typeof(ChaseState), new ChaseState(_me: this) }
        };

        _sm.SetStates(_states);
    }
Example #21
0
    new private void Start()
    {
        stateMachine = new AIStateMachine <AI>(this);
        stateMachine.ChangeState(idleState.Instance);
        rigid        = gameObject.GetComponent <Rigidbody2D>();
        whatIsGround = LayerMask.GetMask("Default");


        spawn.transform.position = transform.position;
    }
Example #22
0
    private void StartCrawling()
    {
        AIStateMachine stateMachine = GetComponentInParent <AIStateMachine>();

        if (stateMachine != null)
        {
            stateMachine.Animator.SetBool("IsCrawling", true);
            stateMachine.IsCrawling = true;
        }
    }
Example #23
0
    void OnTriggerEnter(Collider other)
    {
        // Testing if we collide with a something that has IState within itself
        AIStateMachine machine = GameSceneManager.instance.GetAIStateMachine(other.GetInstanceID());

        if (machine)
        {
            machine.inMeleeRange = true;
        }
    }
Example #24
0
    // -------------------------------------------------------------------------
    // 类	    :	GetAIStateMachine
    // 介绍		:	获取目标值的AIStateMachine
    // -------------------------------------------------------------------------
    public AIStateMachine GetAIStateMachine(int key)
    {
        AIStateMachine machine = null;

        if (_stateMachines.TryGetValue(key, out machine))
        {
            return(machine);
        }
        return(null);
    }
Example #25
0
 // Start is called before the first frame update
 void Start()
 {
     fov            = GetComponent <FieldOfView>();
     stateMachine   = GetComponent <AIStateMachine>();
     anim           = GetComponent <Animator>();
     myNavMeshAgent = GetComponent <UnityEngine.AI.NavMeshAgent>();
     character      = GetComponent <ThirdPersonCharacterNoCrouch>();
     setNextWaypoint();
     previousYRotate = this.transform.eulerAngles.y;
 }
Example #26
0
    public override void Enter(AIStateMachine stateMachine, Action SuccessCallback, Action FailureCallback)
    {
        base.Enter(stateMachine, SuccessCallback, FailureCallback);

        target = GameObject.Find("Store").transform;

        moveState = stateMachine.AddState <MoveState>();
        moveState.SetTarget(target);

        stateMachine.OnComplete += Success;
    }
Example #27
0
    /**
     * Start should be used to create any states that you want the StateMachine
     * to run. The states will control the AIs behavior, then ideally all
     * you have to do is update the machine forever.
     */
    void Start()
    {
        //Random.InitState((int)(Time.realtimeSinceStartup * 1000));
        machine = new AIStateMachine(player, gameObject);
        IState wanderState = new AIWanderState(machine);
        IState chaseState  = new AIChaseState(machine);

        machine.SetInitialState(wanderState);
        machine.AddTransition(wanderState, chaseState);
        machine.AddTransition(chaseState, wanderState);
    }
Example #28
0
    void OnTriggerStay(Collider other)
    {
        AIStateMachine machine = GameSceneManager.instance.GetAIStateMachine(other.GetInstanceID());

        if (machine != null && _controller != null)
        {
            _controller.DoStickiness();
            machine.VisualThreat.Set(AITargetType.Visual_Player, _controller.characterController, _controller.transform.position, Vector3.Distance(machine.transform.position, _controller.transform.position));
            machine.SetStateOverride(AIStateType.Attack);
        }
    }
Example #29
0
    private void Start()
    {
        _stateMachine = transform.root.GetComponentInChildren <AIStateMachine>();
        if (_stateMachine != null)
        {
            _animator = _stateMachine.animator;
        }
        _parameterHash = Animator.StringToHash(_parameter);

        _gameSceneManager = GameSceneManager.instance;
    }
 // Use this for initialization
 void Start()
 {
     CorePieces   = GameObject.FindGameObjectsWithTag("Core");
     OutsideWalls = GameObject.FindGameObjectsWithTag("Wall");
     EnemyAgent   = GetComponent <NavMeshAgent>();
     stateMachine = new AIStateMachine <EnemyActionsManagerScript>(this);
     stateMachine.ChangeState(ChasePlayer.Instance);
     //SpawnPosition = transform.position;
     CurrentHealth     = MaximumHealth;
     IsAlive           = true;
     AllCorePiecesGone = false;
 }
Example #31
0
    // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        _currentAnimationIndex = 0;
        _timer = 0f;

        if (_values.Count > 0)
        {
            animator.SetFloat(_parameter, _values[0]);
        }

        _stateMachine = animator.GetComponent <AIStateMachine>();
    }
    protected override void Begin()
    {
        Behaviour = new AIStateMachine(this);
        AIStateCompanion state = new AIStateCompanion(this);

        state.target = followTarget;
        state.minRange = minFollowRange;
        state.maxRange = maxFollowRange;
        state.chaseRange = chaseRange;
        state.attackRange = attackRange;

        Behaviour.AddState(state);
        Behaviour.ChangeState(state);
    }
Example #33
0
    void Start()
    {
        initializeEntityLists();
		turnsCompleted = 0;
        gameManager = this;
        currentPlayers = new LinkedList<Entity>();
        currentTurn = JANITOR;
        cameraManager = GetComponent<CameraManager>();
        undoManager = GetComponent<UndoManager>();
        uiManager = GameObject.FindObjectOfType<UIManager>();
        aiStateMachine = GameObject.FindObjectOfType<AIStateMachine>();
        turnsLeft = turnsPerPlayer;
        updateEntitiesPresent();
    }
Example #34
0
    public override List<MoveInfo> getBestMoves(AIStateMachine aiStateMachine)
    {
        List<MoveInfo> bestMoves = new List<MoveInfo>();
        List<MoveInfo> lastMoves = new List<MoveInfo>();
        List<TurnInfo> lastTurns = new List<TurnInfo>();
        float bestScore = -10000;

        for (int i = 0; i < testCount; i++)
        {
            lastMoves = new List<MoveInfo>();
            lastTurns.Clear();
            while (lastMoves.Count < 3)
            {
                MoveInfo move = getRandomMove(aiStateMachine.mapInfo);
                Actions action = move.entity.getEntityActionManager().actions[move.actionSelected];

                List<Point2> validTiles = action.getValidMoves(move.entity.getCurrentLocation(), aiStateMachine.mapInfo);
                if (validTiles.Count > 0)
                {
                    Point2 tileSelected = validTiles[Random.Range(0, validTiles.Count)];
                    lastTurns.Add(saveTurn(move.entity, move.actionSelected, tileSelected, aiStateMachine.mapInfo));

                    if (!action.performAction(validTiles[Random.Range(0, validTiles.Count)], aiStateMachine.mapInfo))
                    {
                        lastMoves.RemoveAt(lastMoves.Count);
                    }
                }
                

            }
            float mapScore = scoreMap(aiStateMachine.mapInfo);

            if (mapScore > bestScore)
            {
                bestMoves = lastMoves;
                bestScore = mapScore;
            }
            aiStateMachine.mapInfo.resetMap();
        }
        
        return bestMoves;
    }
Example #35
0
 public abstract List<MoveInfo> getBestMoves(AIStateMachine aiStateMachine);
Example #36
0
 void Awake()
 {
     currentStateMachine = GetComponent<AIStateMachine>();
     OnAwake();
 }