Exemplo n.º 1
0
 public override void DoAction(GameUnit unit, AI_State state)
 {
     if (unit.stateC.SlowUpdate())
     {
         unit.agent.SetDestination(unit.agent.destination);
     }
 }
Exemplo n.º 2
0
    private void CheckForStateName()
    {
        bool isdown = Input.GetKeyDown(KeyCode.C);


        if (isdown == true)
        {
            currentState = AI_State.CHASE;
            //Debug.Log("chasing");
        }

        isdown = Input.GetKeyDown(KeyCode.G);

        if (isdown == true)
        {
            currentState = AI_State.GUARD;
            //Debug.Log("guarding");
        }
        isdown = Input.GetKeyDown(KeyCode.H);


        if (isdown == true)
        {
            currentState = AI_State.HIDE;
            //Debug.Log("hiding");
        }
    }
 public override void DoAction(GameUnit unit, AI_State state)
 {
     if (unit.stateC.SlowUpdate())
     {
         unit.stateC.AcquireTarget(unit.transform.position, unit.preset.aggroRange, unit.preset.faction.aggro);
     }
 }
Exemplo n.º 4
0
 public void ChangeState(AI_State nextState)
 {
     currentState.EndStateForBrain(this);
     previousState = currentState;
     currentState  = nextState;
     currentState.InitializeStateForBrain(this);
 }
Exemplo n.º 5
0
    void Update()
    {
        if (selectedTarget != null)
        {
            EH = selectedTarget.GetComponent <AI_State>();
            selectedTarget.GetComponent <AI_State>().UI.SetActive(true);
            //EH.UI.transform.localRotation = Quaternion.Slerp(transform.rotation,
            //                                   Quaternion.LookRotation(Self.transform.position - transform.position),
            //                                   turnSpeed * Time.deltaTime);
            targetactive = true;

            if (EH.GetComponent <AI_State>().curHeatlh <= 0)
            {
                selectedTarget.GetComponent <AI_State>().UI.SetActive(false);
                Destroy(selectedTarget.gameObject);
            }
        }

        if (selectedTarget == null)
        {
            targetactive = false;
        }

        FollowTarget();
    }
Exemplo n.º 6
0
    private IEnumerator Die()
    {
        _CurrentSate = StunState;
        yield return(new WaitForSeconds(1f));

        PhotonNetwork.Destroy(gameObject);
    }
Exemplo n.º 7
0
    public void refAIState(string state)
    {
        switch (state)
        {
        case "Spawn":
            ai_State = AI_State.Spawn;
            break;

        case "Moving":
            ai_State = AI_State.Moving;
            break;

        case "Stun":
            ai_State = AI_State.Stunned;
            break;

        case "Dead":
            ai_State = AI_State.Dead;
            break;

        default:
            Debug.Log("Broke ai_State");
            break;
        }
    }
Exemplo n.º 8
0
    IEnumerator AI_Update()
    {
        //  List<MapTile> CurrentPath = new List<MapTile>();

        //  UnitState = DetectState(); //the first detect state
        // StartCoroutine(MoveGenerator());
        //Have it update everytime the unit moves to a new tile
        yield return(new WaitForSeconds(0.5f));

        while (true)
        {
            yield return(new WaitForSeconds(RefreshRate)); //prevents it from updating too much

            //   Debug.Log("Its updating");

            if (ShouldChangePath(UnitState))
            {
                UnitState = DetectState();
                //UnitState = AI_State.Chase;
                UpdateMovementNow = true;
                // Debug.Log("Changing state to ");
            }
            else
            {
                //just let it continue their path to wherever
            }
            //So first it is gonna check if it needs to change paths or not
            // The shoudl chage path should update everytime the AI changes tiles
        }
    }
Exemplo n.º 9
0
 // Use this for initialization
 void Start()
 {
     myTrans   = GetComponent <Transform> ();
     startJump = myTrans.position;
     myState   = AI_State.None;
     direction = Vector3.one;
 }
Exemplo n.º 10
0
    private void SetStates(AI_BehaviorBrain brain, AI_BehaviorBrain[] brainList, AI_State state)
    {
        foreach (AI_BehaviorBrain currbrain in brainList)
        {
            //Debug.Log(currbrain.gameObject.name+" from:"+ currbrain.currentState.ToString()+" to:"+state.ToString());
            AI_State currBrainState = currbrain.currentState;
            if (currBrainState != state)
            {
                bool replace = true;
                foreach (AI_State curState in noReplacedState)
                {
                    if (currBrainState == curState)
                    {
                        replace = false;
                        break;
                    }
                }
                if (replace)
                {
                    currbrain.ChangeState(state);
                    //currbrain.currentState = state;
                }
            }

            AI_GoToData goToData = currbrain.GetComponent <AI_GoToData>();
            if (goToData != null)
            {
                if (goToData.destination != brain.transform.position)
                {
                    goToData.destination = brain.transform.position;
                }
                goToData.stopDist = stopDist;
            }
        }
    }
Exemplo n.º 11
0
    void Attack(LivingBeing target)
    {
        State = AI_State.ATTACK;
        Target = target;
        TargetPos = Target.Pos;

        Animator.SetBool("Agressive", true);
    }
Exemplo n.º 12
0
    public override void DoAction(GameUnit unit, AI_State state)
    {
        unit.agent.avoidancePriority = castAvoidancePriority;
        unit.stateC.nextAbility      = Time.time + unit.preset.ability[unit.stateC.activeAbility].coolDownDuration;
        unit.stateC.castLockTime     = Time.time + unit.preset.ability[unit.stateC.activeAbility].castLockDuration;

        unit.preset.ability[unit.stateC.activeAbility].ability.Cast(unit, unit.stateC.currentTarget.transform.position);
    }
Exemplo n.º 13
0
    public override void DoAction(GameUnit unit, AI_State state)
    {
        unit.agent.avoidancePriority = castAvoidancePriority;
        unit.stateC.nextAbility      = Time.time + unit.preset.ability[unit.stateC.activeAbility].coolDownDuration;
        unit.stateC.castLockTime     = Time.time + unit.preset.ability[unit.stateC.activeAbility].castLockDuration;

        unit.preset.ability[unit.stateC.activeAbility].ability.Cast(unit, unit.controller.worldTarget);
    }
Exemplo n.º 14
0
 void Returning()
 {
     agent.destination = patrolPoints[0].transform.position;
     if (distanceToTarget < 2)
     {
         currentState = AI_State.Patrolling;
     }
 }
Exemplo n.º 15
0
 public override void DoAction(GameUnit unit, AI_State state)
 {
     if (unit.stateC.currentTarget == null)
     {
         return;
     }
     unit.stateC.distanceToTarget = unit.stateC.CalculateDistToUnit(unit.stateC.currentTarget);
 }
Exemplo n.º 16
0
	// Use this for initialization
	void Start ()
	{
		myTrans = GetComponent<Transform> ();
		startJump = myTrans.position;
		myState = AI_State.None;
		direction = Vector3.one;
		 
	}
Exemplo n.º 17
0
 public override void DoAction(GameUnit unit, AI_State state)
 {
     if (unit.stateC.currentTarget == null)
     {
         return;
     }
     unit.spriteC.faceDirection(unit.transform.position.x <= unit.stateC.currentTarget.transform.position.x);
 }
Exemplo n.º 18
0
    void Follow()
    {
        agent.destination = Target.transform.position;

        if (!playerInSight && followDistance > distanceToPlayer)
        {
            currentState = AI_State.Returning;
        }
    }
Exemplo n.º 19
0
 void OnEnable()
 {
     b       = true;
     _target = (AI_State)target;
     if (_target._animator != null)
     {
         _runtimeAnimatorController = (_target._animator.runtimeAnimatorController as AnimatorController);
     }
 }
Exemplo n.º 20
0
 public void TransitionToState(AI_State nextState)
 {
     if (nextState != m_currentState)
     {
         OnExitState();
         m_currentState = nextState;
         OnEnterState();
     }
 }
Exemplo n.º 21
0
 public override void DoAction(GameUnit unit, AI_State state)
 {
     if (unit.stateC.currentTarget == null)
     {
         return;
     }
     unit.agent.SetDestination(unit.stateC.currentTarget.transform.position);
     unit.spriteC.faceDirection(unit.spriteC.moveRight);
 }
Exemplo n.º 22
0
    public void ChangeState(string actionName)
    {
        AI_State changeState = aiStates.Find(x => x.aiAction.actionName == actionName);

        if (changeState != null)
        {
            aiMachine.ChangeState(changeState);
        }
    }
Exemplo n.º 23
0
 public void TransitionToState(AI_State nextState)
 {
     if (nextState != remainState)
     {
         currentState = nextState;
         OnExitState();
         ResetPath();
     }
 }
Exemplo n.º 24
0
 public void updateFromState(NPCStateData data)
 {
     maxHealth      = data.maxHP;
     currentHealth  = data.curHP;
     targetPosition = data.position;
     targetRotation = data.rotation;
     State          = (AI_State)data.state;
     UI_Nameplate.updateFromState(data);
 }
Exemplo n.º 25
0
 private bool IsLinked(AI_Behaviour behaviour, AI_State state)
 {
     if (behaviour.GetType().Name == state.GetType().Name.Substring(3) ||
         behaviour.LinkedStateName == state.GetType().Name)
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 26
0
 public override void DoAction(GameUnit unit, AI_State state)
 {
     if (unit.stateC.cmdTarget != null)
     {
         unit.stateC.currentTarget = unit.stateC.cmdTarget;
         return;
     }
     unit.stateC.currentTarget = null;
 }
Exemplo n.º 27
0
    void Start ()
    {
        m_CharacterController = GetComponent<CharacterController>();
        m_Jumping = false;
        currentState = AI_State.GUARD;

        bTempUsePlayerPosAsCrystal = true;
        crystal = new Vector3(-1, -1, -1);
	}
Exemplo n.º 28
0
    void Start()
    {
        m_CharacterController = GetComponent <CharacterController>();
        m_Jumping             = false;
        currentState          = AI_State.GUARD;

        bTempUsePlayerPosAsCrystal = true;
        crystal = new Vector3(-1, -1, -1);
    }
Exemplo n.º 29
0
 void Start()
 {
     precision = 12;
     alive     = true;
     state     = AI_State.Stand;
     StartCoroutine(FSM());
     m_Nav       = gameObject.GetComponent <NavMeshAgent>();
     m_transform = gameObject.GetComponent <Transform>();
 }
Exemplo n.º 30
0
    // If the Crab isn't within reach of the player, but is detected by the aggro_range collider move towards it. Otherwise it is close enough to attack.
    // Gameobject Player is assigned when the player is in range of the aggro colliders inside the crab's hiearchy FOV_Range and Aggro Radius
    void Chase()
    {
        Current_State = AI_State.Walking;
        turnDirection = Aggro_Target.transform.position - rigidBody.position;
        turnDirection.Normalize();
        transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(turnDirection), turnSpeed * Time.deltaTime);

        transform.position += transform.forward * moveSpeed * Time.deltaTime;
    }
Exemplo n.º 31
0
 public override void TransitionToState(AI_State nextAIState)
 {
     if (nextAIState != remainInAIState)
     {
         currentAIState.ExitState(this);
         OnExitState();
         currentAIState = nextAIState;
         currentAIState.EnterState(this);
     }
 }
Exemplo n.º 32
0
 void Update()
 {
     m_distance = Vector3.Distance(transform.position, m_Nav.destination);
     if (m_distance < m_Nav.stoppingDistance)
     {
         state  = AI_State.Stand;
         isMove = false;
     }
     Attack_Check();
 }
Exemplo n.º 33
0
 private void Awake()
 {
     currentState    = initialState;
     navMeshAgent    = this.transform.GetComponent <NavMeshAgent>();
     brain_animator  = this.transform.GetComponent <Animator>();
     brain_rigidbody = this.transform.GetComponent <Rigidbody>();
     if (currentState != null)
     {
         currentState.InitializeStateForBrain(this);
     }
 }
Exemplo n.º 34
0
	// Use this for initialization
	void Start () 
    {
        //FollowState = new AI_State_Follow();
        FollowState.Create(UtilityComponents);
        //TODO rest of the states
        AllStates = new AI_State[Enum.GetNames(typeof(AI_GUARD_STATE)).Length];
        // new List<AI_State>(Enum.GetNames(typeof(AI_GUARD_STATE)).Length);
        AllStates[(int)AI_GUARD_STATE.Normal] = NormalPatrol;
        AllStates[(int)AI_GUARD_STATE.Alerted] = AlertedPatrol;
        AllStates[(int)AI_GUARD_STATE.Follow] = FollowState;

        State = AI_GUARD_STATE.Normal;
        curState = NormalPatrol;
	}
Exemplo n.º 35
0
 // Method to change AI state
 public void ChangeState(aiEngineStates newState)
 {
     switch(newState)
     {
         case aiEngineStates.Attacking:
             ProcessState = new AI_State(State_Attacking);
             break;
         case aiEngineStates.Wandering:
             ProcessState = new AI_State(State_Wandering);
             break;
         default:
             ProcessState = new AI_State(State_Nothing);
             break;
     }
 }
Exemplo n.º 36
0
    void ChangeState()
    {
        if(playerDist < ai_attack_range && playerDist > ai_retreat_range)
        {
            grubState = AI_State.ATTACK;
        }

        else if(playerDist > ai_attack_range && distFromStart < ai_max_movement)
        {
            grubState = AI_State.HUNT;
        }

        else if(playerDist < ai_retreat_range)
        {
            grubState = AI_State.RETREAT;
        }
        else
        {
            grubState = AI_State.PATROL;
        }
    }
Exemplo n.º 37
0
 void OnAwake()
 {
     grubState = AI_State.PATROL;
 }
Exemplo n.º 38
0
    void Idle()
    {
        Target = null;
        Path.Clear();
        State = AI_State.IDLE;

        Animator.SetBool("Agressive", false);
    }
Exemplo n.º 39
0
 public void MoveTo(LocalPos pos)
 {
     State = AI_State.MOVE;
     TargetPos = pos;
 }
Exemplo n.º 40
0
 // Passt die Verhaltensweise der KI je nach Alarmstatus an
 void UpdateState()
 {
     if(!allowToPatrol && !allowToLook && !allowToFollow && !allowToShoot)
     {
         npcState = AI_State.idle;
     }
     else
     {
         if (alert >= breakpointFollow)
         {
             if (npcSight.playerInSight)
             {
                 if (allowToShoot)
                     npcState = AI_State.shooting;
             }
             else
             {
                 if (allowToFollow)
                     npcState = AI_State.following;
             }
         }
         else if (alert >= breakpointLooking)
         {
             if (allowToLook)
                 npcState = AI_State.looking;
         }
         else
         {
             if (patrolWayPoints.Length > 0 && NoNullWaypoints() == true) {
                 if (allowToPatrol)
                     npcState = AI_State.patrolling;
             }
             else
                 npcState = AI_State.idle;
         }
     }
 }
Exemplo n.º 41
0
    private void CheckForStateName()
    {
        bool isdown = Input.GetKeyDown(KeyCode.C);


        if (isdown == true)
        {
            currentState = AI_State.CHASE;
            //Debug.Log("chasing");
        }

        isdown = Input.GetKeyDown(KeyCode.G);

        if (isdown == true)
        {
            currentState = AI_State.GUARD;
            //Debug.Log("guarding");
        }
        isdown = Input.GetKeyDown(KeyCode.H);


        if (isdown == true)
        {
            currentState = AI_State.HIDE;
            //Debug.Log("hiding");
        }
    }
Exemplo n.º 42
0
	void Update ()
    {
        if(bTempUsePlayerPosAsCrystal)
        {
            crystal = Player.Inst.transform.position;
        }

        CheckForStateName();
        if (currentState == AI_State.GUARD)
        {
            Vector2 loc = Random.insideUnitCircle * 5;

            Vector3 newLocation = new Vector3(crystal.x + loc.x,
                            crystal.y,
                            crystal.z + loc.y);

            Debug.Log(newLocation);

            Vector3 playerlocation = Player.Inst.transform.position;
            Vector3 difference = playerlocation - transform.position;
            float length = difference.magnitude;

            Vector3 crystalDifference = crystal - transform.position;
            float crystalDist = crystalDifference.magnitude;

            // If the player gets too close, run towards them
            // But only if we are still close to the crystal (otherwise stay near the crystal instead)
            if( crystalDist < 8 )
            {
                if(length < 8)
                {
                    Debug.Log("Player is close to gem! Gonna chase them!");
                    newLocation = playerlocation;
                }
            }
            else
            {
                Debug.Log("Too far from crystal! Heading back!");
            }
            move(newLocation);
        }
        else if (currentState == AI_State.CHASE)
        {
            move(Target.position);

            Vector3 playerlocation = Player.Inst.transform.position;
            Vector3 difference = playerlocation - transform.position;
            float length = difference.magnitude;

            if (length < 2)
            {
                currentState = AI_State.HIDE;
                bool searchingforlocation = true;
                while (searchingforlocation)
                {
                    int depth = VoxelWorld.Inst.VoxelDepth;
                    int width = VoxelWorld.Inst.VoxelWidth;
                    int choicex = Random.RandomRange(0, depth - 1);
                    int choicey = Random.RandomRange(0, width - 1);
                    
                    IntVec3 startinglocation = new IntVec3(choicex, 0, choicey);
                    Voxel v = VoxelWorld.Inst.GetVoxel(startinglocation);

                    bool blockisvalid = true;
                    while (blockisvalid)
                    {
                        startinglocation.Y += 1;
                        if(VoxelWorld.Inst.IsVoxelWorldIndexValid(startinglocation.X, startinglocation.Y, startinglocation.Z))
                        {
                            Voxel v2 = VoxelWorld.Inst.GetVoxel(startinglocation);
                            if (v2.TypeDef.Type == VoxelType.Air)
                            {
                                hidelocation = startinglocation;

                                searchingforlocation = false;

                                currentState = AI_State.HIDE;

                                Debug.Log("Found a good place to hide the block! Switching to HIDE");
                            }
                        }
                        else
                        {
                            blockisvalid = false;
                        }
                    }
                }
            }
        }
        else if (currentState == AI_State.HIDE)
        {
            Vector3 hideworldlocation = new Vector3(hidelocation.X, hidelocation.Y, hidelocation.Z);

            move(hideworldlocation);

            Vector3 difference = hideworldlocation - transform.position;
            float length = difference.magnitude;

            if (length < 4)
            {
                Debug.Log("Object hidden! Going back to guarding!");
                currentState = AI_State.GUARD;
                crystal = hideworldlocation;
                bTempUsePlayerPosAsCrystal = false;
            }
        }

        m_PreviouslyGrounded = m_CharacterController.isGrounded;  
	}
Exemplo n.º 43
0
        /// <summary>
        /// 刷新数据
        /// </summary>
        public void Reload(AI_State state)
        {
            editSuccess = false;
            allEventTree.Nodes.Clear();
            registedEventTree.Nodes.Clear();

            this.m_state = state;
            flowChartInteractor = Interactor.GetInteractor().CurrentFlowChartInteractor;

            // 初始化名称
            if (string.IsNullOrEmpty(state.Ename))
            {
                state.Ename = string.Format("State{0}", graphElementID.ToString());
            }

            txtName.Text = state.Name;

            // 初始化所有事件
            foreach (AI_Event ai_event in EventTable.EventItems)
            {
                // 取消已注册的事件
                if (!state.EventList.Contains(ai_event))
                {
                    Node node = new Node();
                    node.Text = ai_event.ToString();
                    node.Tag = ai_event;
                    if (int.Parse(ai_event.eventid) < 1000) // 系统事件
                    {
                        node.Image = imageList1.Images[0];
                    }
                    else
                    {
                        node.Image = imageList1.Images[2];
                    }
                    allEventTree.Nodes.Add(node);
                }
            }

            // 初始化自定义事件
            List<AI_Event> customEventList = flowChartInteractor.CustomTable["CustomEventList"] as List<AI_Event>;

            if (customEventList != null)
            {
                foreach (AI_Event aiEvent in customEventList)
                {
                    // 去掉已注册的事件
                    if (!state.EventList.Contains(aiEvent))
                    {
                        Node node = new Node();
                        node.Text = aiEvent.ToString();
                        node.Tag = aiEvent;
                        node.Image = imageList1.Images[2];
                        allEventTree.Nodes.Add(node);
                    }
                }
            }

            // 初始化选中的事件         
            foreach (AI_Event aiEvent in state.EventList)
            {
                Node node = new Node();
                node.Text = aiEvent.ToString();
                node.Tag = aiEvent;

                if (int.Parse(aiEvent.eventid) < 1000) // 系统事件
                {
                    node.Image = imageList1.Images[0];
                }
                else
                {
                    node.Image = imageList1.Images[2];
                }

                registedEventTree.Nodes.Add(node);
            }

            // 切换焦点
            txtName.Focus();
        }