Exemplo n.º 1
0
    // Determines what levels of alertness trigger which states
    void updateState()
    {
        switch (alertness)
        {
        // Patrolling
        case 0:
        case 1:
        case 2:
        case 3:
            guardState = GuardState.PATROLING;
            break;

        // Investigating
        case 4:
        case 5:
            guardState = GuardState.INVESTIGATING;
            break;

        // Searching
        case 6:
        case 7:
            guardState = GuardState.ATTACKING;
            break;

        // Alerting
        case 8:
        case 9:
            guardState = GuardState.ALERTING;
            break;
        }
    }
Exemplo n.º 2
0
    protected virtual void Start(CharacterLevel data)
    {
        baseHealth    = data.healthPoints;
        baseEndurance = data.endurancePoints;
        //baseMovementSpeed = data.movementSpeed;

        m_Health      = baseHealth;
        mEndurance    = baseEndurance;
        mShield       = baseShield;
        movementSpeed = baseMovementSpeed;

        guardState  = GuardState.Open;
        isDead      = false;
        hurtBox     = null;
        refillDelay = 0;

        staminaRegenTimer = Time.time;

        if (gameObject.tag == Utility.playerStr)
        {
            isPlayer = true;
        }
        else
        {
            isPlayer = false;
        }

        invulnerabilityTimer = Time.time + 0.5f;

        OnDeath += AIManager.instance.gameManager.OnEnemyDeath;
    }
Exemplo n.º 3
0
    protected virtual void FixedUpdate()
    {
        if (!AIManager.instance.GetActive())
        {
            invulnerable = true;
        }
        else if (invulnerabilityTimer > Time.time)
        {
            invulnerable = true;
        }
        else
        {
            invulnerable = false;
        }

        if (animator.GetCurrentAnimatorStateInfo(1).IsName(Utility.def))
        {
            guardState = GuardState.OnGuard;
        }
        else if (animator.GetCurrentAnimatorStateInfo(1).IsName(Utility.par))
        {
            guardState = GuardState.Parry;
        }
        else
        {
            guardState = GuardState.Open;
        }

        if (Time.time > staminaRegenTimer)
        {
            StaminaRegen();
            staminaRegenTimer = Time.time + 0.025f;
        }
    }
Exemplo n.º 4
0
    public void scared(Vector2 v)
    {
        ChildScareIcon.SetActive(true);
        state = GuardState.Scared;
        float x      = transform.position.x - v.x;
        float y      = transform.position.y - v.y;
        float xyDiff = Mathf.Abs(x) - Mathf.Abs(y);

        if (xyDiff < 0)
        {
            if (y > Mathf.Abs(x)) //ghost is under guard
            {
                myRigidbody.velocity = vectorUp;
                lastMoveDirection    = vectorUp;
            }
            else if (y < Mathf.Abs(x)) //ghost is over guard
            {
                myRigidbody.velocity = vectorDown;
                lastMoveDirection    = vectorDown;
            }
        }
        else
        {
            if (x > Mathf.Abs(y)) //ghost is left of guard
            {
                myRigidbody.velocity = vectorRight;
                lastMoveDirection    = vectorRight;
            }
            else if (x < Mathf.Abs(y)) //ghost is right guard
            {
                myRigidbody.velocity = vectorLeft;
                lastMoveDirection    = vectorLeft;
            }
        }
    }
Exemplo n.º 5
0
    private void FixedUpdate()
    {
        bool inSigth = IsInSight(Vector3.forward);

        float margin = 0.5f;
        float steps  = 5;
        float angle  = margin / steps;

        for (int i = 0; i <= steps; i++)
        {
            inSigth |= IsInSight(new Vector3(-angle * i, 0, 1));
            inSigth |= IsInSight(new Vector3(angle * i, 0, 1));
        }

        if (inSigth)
        {
            flashlight.DOLookAt(SeenTransform.position, 0.3f, AxisConstraint.Y);

            currentState = seenPlayer ? GuardState.Chase : GuardState.Alert;
        }
        else
        {
            seenPlayer = false;

            if (currentState != GuardState.Idle)
            {
                currentState = GuardState.Patrol;
            }
        }
    }
Exemplo n.º 6
0
    public void GetStunned()
    {
        if (!unstunnable)
        {
            StopRaisingAlarm();
            attackRangeMarker.SetActive(false);
            alarmEffect.SetActive(false);
            searchEffect.SetActive(false);
            state = GuardState.Stunned;
            print(gameObject.name + " stunned");
            fovSensor.enabled = false;
            GetComponent <NavMeshAgent>().enabled = false;
            animator.SetBool("kuolee", true);
            visibility.HideFromPlayer();
        }

        if (activator)
        {
            activateTarget.SetActive(true);
        }

        if (unlocker)
        {
            door.type = OpenableDoor.DoorType.Normal;
        }
    }
Exemplo n.º 7
0
    void Start()
    {
        myRigidbody = GetComponent <Rigidbody2D>();
        anim        = GetComponent <Animator>();

        lastMoveDirection = new Vector2(0f, 0f);
        vectorUp          = new Vector2(0, 1 * scareMoveSpeed);
        vectorDown        = new Vector2(0, -1 * scareMoveSpeed);
        vectorRight       = new Vector2(1 * scareMoveSpeed, 0);
        vectorLeft        = new Vector2(-1 * scareMoveSpeed, 0);

        state      = GuardState.Standing;
        startPoint = transform.position;

        spriteR = gameObject.GetComponent <SpriteRenderer>();
        sprites = Resources.LoadAll <Sprite>("guard");

        ChildCatchPlayer = this.gameObject.transform.GetChild(0).GetComponent <CatchPlayer>();
        ChildScareIcon   = this.gameObject.transform.GetChild(2).gameObject;
        ChildCatchIcon   = this.gameObject.transform.GetChild(3).gameObject;

        turnValue      = moveSpeed / 100;
        scareTurnValue = scareMoveSpeed / 80;
        catchingPlayer = false;
    }
Exemplo n.º 8
0
    private void MakeFSM()
    {
        PatrolState patrol = new PatrolState(player, transform, path);

        patrol.AddTransition(Transition.GuardPlayer, StateID.GuardID);

        GuardState guard = new GuardState(player, transform);

        guard.AddTransition(Transition.AutoPatrol, StateID.PatrolID);
        guard.AddTransition(Transition.ChasingPlayer, StateID.ChasingID);

        ChaseState chase = new ChaseState(player, transform);

        chase.AddTransition(Transition.GuardPlayer, StateID.GuardID);
        chase.AddTransition(Transition.AttackPlayer, StateID.AttackID);

        AttackState attack = new AttackState(player, transform);

        attack.AddTransition(Transition.GuardPlayer, StateID.GuardID);
        attack.AddTransition(Transition.ChasingPlayer, StateID.ChasingID);

        fsm = new FSMSystem();

        fsm.AddState(patrol);
        fsm.AddState(guard);
        fsm.AddState(chase);
        fsm.AddState(attack);
    }
Exemplo n.º 9
0
 public void SetAlert(Vector3 alertPosition)
 {
     _playerLastKnownPosition = alertPosition;
     State = GuardState.Alerted;
     _fieldOfViewIndicator.color = Color.red;
     GoToPosition(alertPosition);
     _roomManager.CheckForOtherGuardsState();
 }
Exemplo n.º 10
0
    public IEnumerator waitAtWall()
    {
        yield return(new WaitForSecondsRealtime(secondsAtWall));

        anim.enabled = true;
        state        = GuardState.BackFromWall;
        StopCoroutine(waitAtWall());
    }
    void Start()
    {
        _navMeshAgent  = GetComponent <NavMeshAgent>();
        _renderer      = GetComponent <Renderer>();
        _originalColor = _renderer.material.color;

        _currentGuardState = GuardState.Patrol;
    }
Exemplo n.º 12
0
 private void Detect()
 {
     PickTarget();
     if (target != null && (DistanceFromMe(target) < sightRange + target.detectionRange))
     {
         guardState = GuardState.Chase;
     }
 }
Exemplo n.º 13
0
 void FriendlyDown(GuardBehaviour downedGuard)
 {
     if (state != GuardState.Stunned && state != GuardState.Distracted)
     {
         state = GuardState.Search;
         lastPlayerSighting = downedGuard.transform.position;
         RaiseAlarm();
     }
 }
Exemplo n.º 14
0
        void UpdateIdle()
        {
            PlayAnim(GuardAnimation.idle);
            var dist = Vec2.Distance(position, Game.player.position);

            if (dist <= range)
            {
                state = GuardState.roar;
            }
        }
Exemplo n.º 15
0
 public void SetSuspicious(Vector3 position, bool isGlobal)
 {
     if (!isGlobal)
     {
         StartCoroutine(_evasionHandle);
     }
     GoToPosition(position);
     State = GuardState.Suspicious;
     _fieldOfViewIndicator.color = Color.yellow;
 }
Exemplo n.º 16
0
    IEnumerator AssignRoutineWithDelay(Routine r, float maxDelay)
    {
        yield return(new WaitForSeconds(Random.Range(0, maxDelay)));

        lastGuardState  = guardState;
        guardState      = r.state;
        guardNumber     = r.route;
        place.placeType = r.goTo;
        StopAllCoroutines();
    }
Exemplo n.º 17
0
    IEnumerator WaitThenPatrol(float seconds)
    {
        // Change guardstate to waiting.
        guardState = GuardState.waiting;
        // Wait for waitTime seconds before choosing next waypoint.
        yield return(new WaitForSeconds(seconds));

        // Resume patrolling.
        guardState = GuardState.patrolling;
    }
Exemplo n.º 18
0
    IEnumerator Wait()
    {
        // Change guardstate to waiting so it does not keep calling ArrivedAtWaypoint.
        guardState   = GuardState.waiting;
        isPatrolling = false;
        // Wait for waitTime seconds before choosing next waypoint.
        yield return(new WaitForSeconds(waitTime));

        //NextWaypoint();
        guardState = GuardState.patrolling;
    }
Exemplo n.º 19
0
 void Investigate()
 {
     if (Vector3.Distance(this.transform.position, lastPlaceSeen) <= chasingAccuracy)
     {
         currentState = GuardState.Patrol;
     }
     else
     {
         this.GetComponent <UnityEngine.AI.NavMeshAgent>().SetDestination(lastPlaceSeen);
     }
 }
Exemplo n.º 20
0
    private void backToPatroll()
    {
        ChildScareIcon.SetActive(false);
        float step = moveSpeed * Time.deltaTime;

        transform.position = Vector3.MoveTowards(transform.position, lastScarePoint, step);
        if (transform.position == lastScarePoint)
        {
            state = GuardState.Patrolling;
        }
    }
Exemplo n.º 21
0
 public void ApplyEvent(Event @event)
 {
     if (@event.Type == EventType.FallsAsleep)
     {
         State = GuardState.Asleep;
     }
     else if (@event.Type == EventType.WakesUp)
     {
         State = GuardState.Awake;
     }
 }
Exemplo n.º 22
0
Arquivo: Guard.cs Projeto: Glaze96/INO
    private void OnPathInterupt(Vector2 position)
    {
        Debug.Log("ON PATH INTERUPT");
        if (_moveRoutine != null)
        {
            StopCoroutine(_moveRoutine);
        }

        _guardState = GuardState.Searching;
        UpdateState();
    }
Exemplo n.º 23
0
 public void resetGuard()
 {
     transform.position   = startPoint;
     myRigidbody.velocity = new Vector2(0f, 0f);
     state = GuardState.Standing;
     ChildScareIcon.SetActive(false);
     standWatch();
     catchingPlayer = false;
     ChildCatchIcon.SetActive(false);
     PlayerState.canCatch = PlayerState.GuardCanCatch.Yes;
 }
Exemplo n.º 24
0
    private void backToStanding()
    {
        ChildScareIcon.SetActive(false);
        float step = moveSpeed * Time.deltaTime;

        transform.position = Vector3.MoveTowards(transform.position, startPoint, step);
        if (transform.position == startPoint)
        {
            state = GuardState.Standing;
        }
    }
Exemplo n.º 25
0
Arquivo: Guard.cs Projeto: Glaze96/INO
    void HuntPlayer()
    {
        if (_moveRoutine != null)
        {
            StopCoroutine(_moveRoutine);
        }

        UpdateViewCone(_huntViewDistance, _huntViewAngle);

        _pathFollower.StartGoToDynamicTarget(_playerTransform);
        _guardState = GuardState.HuntPlayer;
    }
Exemplo n.º 26
0
 public void resetGuard()
 {
     transform.position   = startPoint;
     currentPoint         = endPoint;
     myRigidbody.velocity = new Vector2(0f, 0f);
     state = GuardState.Patrolling;
     ChildScareIcon.SetActive(false);
     ChildCatchIcon.SetActive(false);
     catchingPlayer       = false;
     anim.enabled         = true;
     PlayerState.canCatch = PlayerState.GuardCanCatch.Yes;
 }
Exemplo n.º 27
0
    private void ChangeState(GuardState newState)
    {
        if (activeState != null)
        {
            activeState.Exit();
        }

        activeState = guardStates[newState];
        activeState.Enter();

        previousState = currentState;
    }
Exemplo n.º 28
0
        public DTController(DTenemy e, Orb o, Tree tree, ChaseState cS, GuardState gS, ScoreState sS, Goal pG, Goal eG)
        {
            this.e       = e;
            this.tree    = tree;
            this.cS      = cS;
            this.gS      = gS;
            this.sS      = sS;
            this.o       = o;
            currentState = new State(e, o, pG, eG);

            MakeDtree();
        }
Exemplo n.º 29
0
 private void Chase()
 {
     if (DistanceFromMe(target) > shootDistance * 0.8)
     {
         Pathfind(target.transform.position);
     }
     else
     {
         shotWaitTime = shotDelay;
         guardState   = GuardState.Shoot;
     }
 }
Exemplo n.º 30
0
 void CheckRoutine()
 {
     CheckClock();
     foreach (Routine r in routine)
     {
         if (hour == r.time.x && minute == r.time.y)
         {
             lastGuardState  = guardState;
             guardState      = r.state;
             guardNumber     = r.route;
             place.placeType = r.goTo;
         }
     }
 }
Exemplo n.º 31
0
    public void CheckCrime(Vector3 crimePosition, Quaternion crimeRotation)
    {
        if (State == GuardState.Patrolling)
        {
            float distanceFromCrime = Vector3.Magnitude(crimePosition - Position);
            // check max distance, and then if this crime is more near than saved one
            if (distanceFromCrime < maxCrimeDistance &&
                (targetDistanceFromCrime.ApproximatelyZero() || distanceFromCrime < targetDistanceFromCrime))
            {
                // save the distance, as we will compare to the new crimes
                targetDistanceFromCrime = distanceFromCrime;

                // Move to checking state
                State = GuardState.CheckingVictim;
                (movingController as GuardMovingController).StartChecking(crimeRotation);
            }
        }
    }
Exemplo n.º 32
0
    void Attack()
    {
        lastSawPlayerAtPos = playerObj.transform.position;
        if (agent)
        {
            agent.destination = lastSawPlayerAtPos;

            Vector3 dist = agent.destination - transform.position;
            if (dist.sqrMagnitude > 2.0f)
            {
                guardState = GuardState.Pursue;
                return;
            }
        }

        //		if (GetPlayerHealth() <= 0)
        //		{
        //			guardState = GuardState.Patrol;
        //		}
    }
Exemplo n.º 33
0
    void FixedUpdate() {
        if(gs.health <= 0) {
            Destroy(gameObject);
        }
        if(currentState == GuardState.Attacking) {
            if(Vector3.Distance(transform.position, player.transform.position) <= 1f) {
                Vector3 _direction = (player.transform.position - transform.position).normalized;
                Quaternion _lookRotation = Quaternion.LookRotation(_direction);
                transform.rotation = Quaternion.Slerp(transform.rotation, _lookRotation, Time.fixedDeltaTime * 2f);

                if(attackTimer <= 0f) {
                    player.takeDamage(Random.Range(gs.minAttackDamage, gs.maxAttackDamage));
                    attackTimer = 2.5f;
                } else {
                    attackTimer -= Time.deltaTime;
                }

            } else {
                currentState = GuardState.Patrol;
            }
        } else if(currentState == GuardState.Alarmed) {
            if(agent.speed == 2.5f)
                agent.speed = 3f;
            if(Vector3.Distance(transform.position, GC.getLastKnownLocation()) <= 1f) {
                currentState = GuardState.Attacking;
            }
        } else if(currentState == GuardState.Patrol) {
            if(agent.speed != 2.5f)
                agent.speed = 2.5f;
            if(guardActions.Count != 0)
                DoAction(guardActions[onCurrentAction]);
        }

        if(GC.hasLastKnownLocation() && currentState != GuardState.Attacking && Vector3.Distance(transform.position, GC.getLastKnownLocation()) <= GC.alarmRadius) {
            currentState = GuardState.Alarmed;
            Vector3 lastLoc = GC.getLastKnownLocation();
            if(agent.destination != lastLoc)
                agent.SetDestination(GC.getLastKnownLocation());
        }
	}
Exemplo n.º 34
0
    void Patrol()
    {
        if (agent)
        {
            agent.destination = waypoint[ nextWaypoint ].position;

            Vector3 dist = agent.destination - transform.position;
            if (dist.sqrMagnitude < 1.0f)
            {
                nextWaypoint++;
                if (!waypoint[ nextWaypoint ])
                    nextWaypoint = 0;
            }
        }

        if (CanSeePlayer())
        {
            guardState = GuardState.Pursue;
        }
    }
Exemplo n.º 35
0
    void Pursue()
    {
        lastSawPlayerAtPos = playerObj.transform.position;
        if (agent)
        {
            agent.destination = lastSawPlayerAtPos;

            Vector3 dist = agent.destination - transform.position;
            if (dist.sqrMagnitude < 3.0f)
            {
                gui.SetState( GameGUI.GUIState.Death );
                guardState = GuardState.Patrol;
                return;
            }
        }

        if (!CanSeePlayer())
        {
            guardState = GuardState.Investigate;
        }
    }
Exemplo n.º 36
0
    private void Awake()
    {
        chaseState = new ChaseState(this);
        patrolState = new PatrolState(this);
        guardState = new GuardState(this);
        dazedState = new DazedState(this);
        distractedState = new DistractedState(this);
        searchingState = new SearchingState(this);
        suspiciousState = new SuspiciousState(this);
        koState = new KOState(this);
        walkState = new WalkState(this);
        pointSearchState = new PointSearchState(this);

        navMeshAgent = GetComponent<NavMeshAgent>();
        player = GameObject.FindGameObjectWithTag("Player");
        Path = Pathways[0];
        AIPath CheckpointScript = Path.GetComponent<AIPath>();
        navPoint = CheckpointScript.getPoints()[0];
        currentState = patrolState; //sets the current state
        NoOcclusionLM = 1 << noOcclusionLayer;
        NoOcclusionLM = ~NoOcclusionLM;
    }
Exemplo n.º 37
0
    void Investigate()
    {
        if (agent)
        {
            agent.destination = lastSawPlayerAtPos;

            Vector3 dist = agent.destination - transform.position;
            if (dist.sqrMagnitude < 2.0f)
            {
                guardState = GuardState.Patrol;
                return;
            }
        }

        if (CanSeePlayer())
        {
            guardState = GuardState.Pursue;
        }
    }
Exemplo n.º 38
0
 public void StartPatrolling()
 {
     State = GuardState.Patrolling;
     targetDistanceFromCrime = 0f;
     SetRandomMoveIntensity();
 }
Exemplo n.º 39
0
 public void StartChasing()
 {
     State = GuardState.Chasing;
 }