상속: NpcState
예제 #1
0
    IEnumerator CheckFollowerState()
    {
        while (!is_dead)
        {
            yield return(new WaitForSeconds(0.2f));

            float dist = Vector2.Distance(player_tr.position, monster_tr.position);

            if (hp <= 0)
            {
                follower_state = FollowerState.die;
            }
            else if (dist <= attack_dist && is_angry)
            {
                follower_state = FollowerState.attack;
            }
            else if (field_of_view.isPlayerDetected() && is_angry && !player.stealth)
            {
                if (agro_gage > 0)
                {
                    agro_gage -= 0.2f;
                }
                else
                {
                    follower_state = FollowerState.trace;
                }
            }
            else
            {
                agro_gage      = 1f;
                is_angry       = false;
                follower_state = FollowerState.patrol;
            }
        }
    }
예제 #2
0
파일: bear.cs 프로젝트: rcnobles/SK
 private void ChangeState(FollowerState newState)
 {
     if (currentState != newState)
     {
         currentState = newState;
     }
 }
예제 #3
0
파일: bear.cs 프로젝트: rcnobles/SK
 // Start is called before the first frame update
 void Start()
 {
     currentState = FollowerState.idle;
     myRigidbody  = GetComponent <Rigidbody2D>();
     anim         = GetComponent <Animator>();
     // Where the bear needs to moving towards
     target = GameObject.FindWithTag("Player").transform;
 }
예제 #4
0
파일: PathFollower.cs 프로젝트: Glaze96/INO
 public void StartGoToDynamicTarget(Transform target)
 {
     StopPathWalk();
     Debug.Log(target);
     _renderer.color = Color.yellow;
     _currentTarget  = target;
     _followerState  = FollowerState.GoToDynamic;
 }
예제 #5
0
 private void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.gameObject.tag == "Obstacle")
     {
         Debug.Log("obstacle");
         set_patrol     = false;
         follower_state = FollowerState.patrol;
     }
 }
예제 #6
0
파일: PathFollower.cs 프로젝트: Glaze96/INO
    public void GoToStaticTarget(Vector2 staticTarget)
    {
        if (_currentWalkCoroutine != null)
        {
            StopCoroutine(_currentWalkCoroutine);
        }

        _followerState        = FollowerState.GoToStatic;
        _currentWalkCoroutine = StartCoroutine(CoGoToStaticTarget(staticTarget));
    }
예제 #7
0
    public IEnumerator itemEffect()
    {
        CharacterSpeedByItem = 1.5f;
        followerState        = FollowerState.Follow;

        yield return(new WaitForSeconds(4.1f));

        CharacterSpeedByItem = 1f;
        followerState        = FollowerState.UnFollow;
    }
예제 #8
0
파일: PathFollower.cs 프로젝트: Glaze96/INO
    public void StopPathWalk()
    {
        _renderer.color = Color.red;
        _currentPath    = null;
        _followerState  = FollowerState.Still;

        if (_currentWalkCoroutine != null)
        {
            StopCoroutine(_currentWalkCoroutine);
        }
    }
예제 #9
0
 public void Take_Damage(int dmg)
 {
     Instantiate(dmg_pop, new Vector2(transform.position.x + Random.Range(0, 0.5f),
                                      transform.position.y + Random.Range(0, 0.5f)),
                 transform.rotation);
     Instantiate(hit_effect, new Vector2(transform.position.x + Random.Range(-0.2f, 0.2f),
                                         transform.position.y + Random.Range(-0.2f, 0.2f)),
                 transform.rotation);
     follower_state = FollowerState.trace;
     StartCoroutine(Get_Angry());
     hp -= dmg;
 }
예제 #10
0
        // TODO: rethink this test, it does too much
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void leaderShouldSpawnMismatchCommandOnFailure() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void LeaderShouldSpawnMismatchCommandOnFailure()
        {
            // given

            /*
             * A leader who
             * - has an append index of 100
             * - knows about instance 2
             * - assumes that instance 2 is fully caught up
             */
            Leader        leader         = new Leader();
            MemberId      instance2      = member(2);
            FollowerState instance2State = CreateArtificialFollowerState(100);

            ReadableRaftState state = mock(typeof(ReadableRaftState));

            FollowerStates <MemberId> followerState = new FollowerStates <MemberId>();

            followerState = new FollowerStates <MemberId>(followerState, instance2, instance2State);

            RaftLog log = new InMemoryRaftLog();

            for (int i = 0; i <= 100; i++)
            {
                log.Append(new RaftLogEntry(0, valueOf(i)));
            }

            when(state.CommitIndex()).thenReturn(-1L);
            when(state.EntryLog()).thenReturn(log);
            when(state.FollowerStates()).thenReturn(followerState);
            when(state.Term()).thenReturn(4L);                 // both leader and follower are in the same term

            // when
            // that leader is asked to handle a response from that follower that says that the follower is still missing
            // things
            Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response response = appendEntriesResponse().failure().appendIndex(0).matchIndex(-1).term(4).from(instance2).build();

            Outcome outcome = leader.Handle(response, state, mock(typeof(Log)));

            // then
            int mismatchCount = 0;

            foreach (ShipCommand shipCommand in outcome.ShipCommands)
            {
                if (shipCommand is ShipCommand.Mismatch)
                {
                    mismatchCount++;
                }
            }

            assertThat(mismatchCount, greaterThan(0));
        }
예제 #11
0
파일: PathFollower.cs 프로젝트: Glaze96/INO
    void PathInterupted()
    {
        Debug.Log("PATH INTERUPTED");
        _renderer.color = Color.red;
        _currentPath    = null;
        _followerState  = FollowerState.Still;
        _pathInteruptAction.Invoke(transform.position);

        if (_currentWalkCoroutine != null)
        {
            StopCoroutine(_currentWalkCoroutine);
        }
    }
예제 #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void leaderShouldRespondToSuccessResponseThatIndicatesLaggingFollowerWithJustWhatItsMissing() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void LeaderShouldRespondToSuccessResponseThatIndicatesLaggingFollowerWithJustWhatItsMissing()
        {
            // given

            /*
             * A leader who
             * - has an append index of 100
             * - knows about instance 2
             * - assumes that instance 2 is at an index less than 100 -say 50
             */
            Leader        leader         = new Leader();
            MemberId      instance2      = member(2);
            FollowerState instance2State = CreateArtificialFollowerState(50);

            ReadableRaftState state = mock(typeof(ReadableRaftState));

            FollowerStates <MemberId> followerState = new FollowerStates <MemberId>();

            followerState = new FollowerStates <MemberId>(followerState, instance2, instance2State);

            ReadableRaftLog logMock = mock(typeof(ReadableRaftLog));

            when(logMock.AppendIndex()).thenReturn(100L);
            // with commit requests in this test

            when(state.CommitIndex()).thenReturn(-1L);
            when(state.EntryLog()).thenReturn(logMock);
            when(state.FollowerStates()).thenReturn(followerState);
            when(state.Term()).thenReturn(231L);                 // both leader and follower are in the same term

            // when that leader is asked to handle a response from that follower that says that the follower is still
            // missing things
            Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response response = appendEntriesResponse().success().matchIndex(89).term(231).from(instance2).build();

            Outcome outcome = leader.Handle(response, state, mock(typeof(Log)));

            // then
            int matchCount = 0;

            foreach (ShipCommand shipCommand in outcome.ShipCommands)
            {
                if (shipCommand is ShipCommand.Match)
                {
                    matchCount++;
                }
            }

            assertThat(matchCount, greaterThan(0));
        }
예제 #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void leaderShouldIgnoreSuccessResponseThatIndicatesLaggingWhileLocalStateIndicatesFollowerIsCaughtUp() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void LeaderShouldIgnoreSuccessResponseThatIndicatesLaggingWhileLocalStateIndicatesFollowerIsCaughtUp()
        {
            // given

            /*
             * A leader who
             * - has an append index of 100
             * - knows about instance 2
             * - assumes that instance 2 is fully caught up
             */
            Leader        leader         = new Leader();
            MemberId      instance2      = member(2);
            int           j              = 100;
            FollowerState instance2State = CreateArtificialFollowerState(j);

            ReadableRaftState state = mock(typeof(ReadableRaftState));

            FollowerStates <MemberId> followerState = new FollowerStates <MemberId>();

            followerState = new FollowerStates <MemberId>(followerState, instance2, instance2State);

            ReadableRaftLog logMock = mock(typeof(ReadableRaftLog));

            when(logMock.AppendIndex()).thenReturn(100L);
            //  with commit requests in this test

            when(state.CommitIndex()).thenReturn(-1L);
            when(state.EntryLog()).thenReturn(logMock);
            when(state.FollowerStates()).thenReturn(followerState);
            when(state.Term()).thenReturn(4L);                 // both leader and follower are in the same term

            // when that leader is asked to handle a response from that follower that says that the follower is still
            // missing things
            Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response response = appendEntriesResponse().success().matchIndex(80).term(4).from(instance2).build();

            Outcome outcome = leader.Handle(response, state, mock(typeof(Log)));

            // then the leader should not send anything, since this is a delayed, out of order response to a previous append
            // request
            assertTrue(outcome.OutgoingMessages.Count == 0);
            // The follower state should not be touched
            FollowerStates <MemberId> updatedFollowerStates = outcome.FollowerStates;

            assertEquals(100, updatedFollowerStates.Get(instance2).MatchIndex);
        }
예제 #14
0
파일: PathFollower.cs 프로젝트: Glaze96/INO
    public bool PathFindTo(Vector2 position)
    {
        StopPathWalk();

        if (_level.TryGetPath(transform.position, position, out _currentPath))
        {
            _followerState        = FollowerState.PathFollow;
            _renderer.color       = Color.green;
            _currentWalkCoroutine = StartCoroutine(CoWalkPath());
            return(true);
        }
        else
        {
            Debug.LogWarning("cannot get path");
            _pathNotFoundAction.Invoke();
            return(false);
        }
    }
예제 #15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void leaderShouldNotRespondToSuccessResponseThatIndicatesUpToDateFollower() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void LeaderShouldNotRespondToSuccessResponseThatIndicatesUpToDateFollower()
        {
            // given

            /*
             * A leader who
             * - has an append index of 100
             * - knows about instance 2
             * - assumes that instance 2 is at an index less than 100 -say 84
             */
            Leader        leader         = new Leader();
            MemberId      instance2      = member(2);
            FollowerState instance2State = CreateArtificialFollowerState(84);

            ReadableRaftState state = mock(typeof(ReadableRaftState));

            FollowerStates <MemberId> followerState = new FollowerStates <MemberId>();

            followerState = new FollowerStates <MemberId>(followerState, instance2, instance2State);

            ReadableRaftLog logMock = mock(typeof(ReadableRaftLog));

            when(logMock.AppendIndex()).thenReturn(100L);

            when(state.CommitIndex()).thenReturn(-1L);
            when(state.EntryLog()).thenReturn(logMock);
            when(state.FollowerStates()).thenReturn(followerState);
            when(state.Term()).thenReturn(4L);                 // both leader and follower are in the same term

            // when
            // that leader is asked to handle a response from that follower that says that the follower is up to date
            Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response response = appendEntriesResponse().success().matchIndex(100).term(4).from(instance2).build();

            Outcome outcome = leader.Handle(response, state, mock(typeof(Log)));

            // then
            // The leader should not be trying to send any messages to that instance
            assertTrue(outcome.OutgoingMessages.Count == 0);
            // And the follower state should be updated
            FollowerStates <MemberId> updatedFollowerStates = outcome.FollowerStates;

            assertEquals(100, updatedFollowerStates.Get(instance2).MatchIndex);
        }
예제 #16
0
        private void ChangeState(FollowerState state)
        {
            if (State == state)
            {
                return;
            }
            State = state;

            switch (state)
            {
            case FollowerState.Follow:

                break;

            case FollowerState.Stay:
                break;

            default:
                break;
            }
        }
예제 #17
0
파일: bear.cs 프로젝트: rcnobles/SK
 void CheckDistance()
 {
     // Only move towards player if inside of radius.
     if (Vector3.Distance(target.position,
                          transform.position) <= outerChaseRadius &&
         Vector3.Distance(target.position, transform.position) > innerChaseRadius)
     {
         currentState = FollowerState.walk;
         if (currentState == FollowerState.idle || currentState == FollowerState.walk)
         {
             Vector3 temp = Vector3.MoveTowards(transform.position, target.position, Math.Min(Vector3.Distance(target.position, transform.position) * Time.deltaTime * 2, moveSpeed * Time.deltaTime * 2));
             changeAnim(temp - transform.position);
             myRigidbody.MovePosition(temp);
             ChangeState(FollowerState.walk);
         }
     }
     else
     {
         anim.SetBool("moving", false);
         anim.SetFloat("moveX", 0);
         anim.SetFloat("moveY", 0);
     }
 }
예제 #18
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.causalclustering.core.consensus.outcome.Outcome handle(org.neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response response) throws java.io.IOException
            public override Outcome Handle(Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response response)
            {
                if (response.Term() < Ctx.term())
                {
                    /* Ignore responses from old terms! */
                    return(Outcome);
                }
                else if (response.Term() > Ctx.term())
                {
                    Outcome.NextTerm = response.Term();
                    StepDownToFollower(Outcome, Ctx);
                    Log.info("Moving to FOLLOWER state after receiving append response at term %d (my term is " + "%d) from %s", response.Term(), Ctx.term(), response.From());
                    Outcome.replaceFollowerStates(new FollowerStates <MemberId>());
                    return(Outcome);
                }

                FollowerState follower = Ctx.followerStates().get(response.From());

                if (response.Success())
                {
                    Debug.Assert(response.MatchIndex() <= Ctx.entryLog().appendIndex());

                    bool followerProgressed = response.MatchIndex() > follower.MatchIndex;

                    Outcome.replaceFollowerStates(Outcome.FollowerStates.onSuccessResponse(response.From(), max(response.MatchIndex(), follower.MatchIndex)));

                    Outcome.addShipCommand(new ShipCommand.Match(response.MatchIndex(), response.From()));

                    /*
                     * Matches from older terms can in complicated leadership change / log truncation scenarios
                     * be overwritten, even if they were replicated to a majority of instances. Thus we must only
                     * consider matches from this leader's term when figuring out which have been safely replicated
                     * and are ready for commit.
                     * This is explained nicely in Figure 3.7 of the thesis
                     */
                    bool matchInCurrentTerm = Ctx.entryLog().readEntryTerm(response.MatchIndex()) == Ctx.term();

                    /*
                     * The quorum situation may have changed only if the follower actually progressed.
                     */
                    if (followerProgressed && matchInCurrentTerm)
                    {
                        // TODO: Test that mismatch between voting and participating members affects commit outcome

                        long quorumAppendIndex = Followers.quorumAppendIndex(Ctx.votingMembers(), Outcome.FollowerStates);
                        if (quorumAppendIndex > Ctx.commitIndex())
                        {
                            Outcome.LeaderCommit = quorumAppendIndex;
                            Outcome.CommitIndex  = quorumAppendIndex;
                            Outcome.addShipCommand(new ShipCommand.CommitUpdate());
                        }
                    }
                }
                else                         // Response indicated failure.
                {
                    if (response.AppendIndex() > -1 && response.AppendIndex() >= Ctx.entryLog().prevIndex())
                    {
                        // Signal a mismatch to the log shipper, which will serve an earlier entry.
                        Outcome.addShipCommand(new ShipCommand.Mismatch(response.AppendIndex(), response.From()));
                    }
                    else
                    {
                        // There are no earlier entries, message the follower that we have compacted so that
                        // it can take appropriate action.
                        RaftMessages_LogCompactionInfo compactionInfo = new RaftMessages_LogCompactionInfo(Ctx.myself(), Ctx.term(), Ctx.entryLog().prevIndex());
                        Org.Neo4j.causalclustering.core.consensus.RaftMessages_Directed directedCompactionInfo = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Directed(response.From(), compactionInfo);

                        Outcome.addOutgoingMessage(directedCompactionInfo);
                    }
                }
                return(Outcome);
            }
예제 #19
0
파일: PathFollower.cs 프로젝트: Glaze96/INO
 void Start()
 {
     _followerState = FollowerState.Still;
 }
예제 #20
0
파일: PathFollower.cs 프로젝트: Glaze96/INO
 void PathDone(Vector3 endPos)
 {
     _followerState = FollowerState.Still;
     _pathDoneAction.Invoke(endPos);
 }
예제 #21
0
파일: PathFollower.cs 프로젝트: Glaze96/INO
 public void ResumeWalk()
 {
     _followerState        = FollowerState.PathFollow;
     _renderer.color       = Color.green;
     _currentWalkCoroutine = StartCoroutine(CoWalkPath());
 }
예제 #22
0
파일: PathFollower.cs 프로젝트: Glaze96/INO
 public void PauseWalk()
 {
     _followerState  = FollowerState.Still;
     _renderer.color = Color.red;
     StopCoroutine(_currentWalkCoroutine);
 }