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; } } }
private void ChangeState(FollowerState newState) { if (currentState != newState) { currentState = newState; } }
// 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; }
public void StartGoToDynamicTarget(Transform target) { StopPathWalk(); Debug.Log(target); _renderer.color = Color.yellow; _currentTarget = target; _followerState = FollowerState.GoToDynamic; }
private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Obstacle") { Debug.Log("obstacle"); set_patrol = false; follower_state = FollowerState.patrol; } }
public void GoToStaticTarget(Vector2 staticTarget) { if (_currentWalkCoroutine != null) { StopCoroutine(_currentWalkCoroutine); } _followerState = FollowerState.GoToStatic; _currentWalkCoroutine = StartCoroutine(CoGoToStaticTarget(staticTarget)); }
public IEnumerator itemEffect() { CharacterSpeedByItem = 1.5f; followerState = FollowerState.Follow; yield return(new WaitForSeconds(4.1f)); CharacterSpeedByItem = 1f; followerState = FollowerState.UnFollow; }
public void StopPathWalk() { _renderer.color = Color.red; _currentPath = null; _followerState = FollowerState.Still; if (_currentWalkCoroutine != null) { StopCoroutine(_currentWalkCoroutine); } }
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; }
// 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)); }
void PathInterupted() { Debug.Log("PATH INTERUPTED"); _renderer.color = Color.red; _currentPath = null; _followerState = FollowerState.Still; _pathInteruptAction.Invoke(transform.position); if (_currentWalkCoroutine != null) { StopCoroutine(_currentWalkCoroutine); } }
//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)); }
//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); }
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); } }
//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); }
private void ChangeState(FollowerState state) { if (State == state) { return; } State = state; switch (state) { case FollowerState.Follow: break; case FollowerState.Stay: break; default: break; } }
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); } }
//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); }
void Start() { _followerState = FollowerState.Still; }
void PathDone(Vector3 endPos) { _followerState = FollowerState.Still; _pathDoneAction.Invoke(endPos); }
public void ResumeWalk() { _followerState = FollowerState.PathFollow; _renderer.color = Color.green; _currentWalkCoroutine = StartCoroutine(CoWalkPath()); }
public void PauseWalk() { _followerState = FollowerState.Still; _renderer.color = Color.red; StopCoroutine(_currentWalkCoroutine); }