/// <summary> /// Called when the ball has arrived a different city than its previous one. /// Changes the state to Free, making the ball back to their stand by position. /// </summary> public void Free(City city) { gatheredParent = null; SetDockCity(city); Vector3 targetPos; Quaternion dockOri; CalculateRoundTransform(currentRadius, false, out targetPos, out dockOri); NewMove(targetPos); ChangeState(RBallState.Free); enemyCheckTime = EnemyCheckTime; }
public void Gather(RGatheredBall ball, Vector3 endGatherPosition, Quaternion endGatherOrient) { gatheredParent = ball; NewMove(endGatherPosition); ChangeState(RBallState.Gathering); }
public RGatheredBall CreateRGatherBall(List<RBall> balls, City dockCity, List<City> result) { RGatheredBall ball = new RGatheredBall(balls, dockCity, result); gatherBalls.Add(ball); return ball; }
private void UpdateState(GameTime time) { float dt = time.ElapsedGameTimeSeconds; smoke.EmitEnabled = false; switch (currentState) { case CityState.Rotate: remainingRotationTime -= dt; if (remainingRotationTime < 0) { switch (rotationPurpose) { case CityRotationPurpose.Throw: ThrowNow(); break; case CityRotationPurpose.Receive: ReceiveNow(); break; case CityRotationPurpose.ThrowContinued: ThrowNowContinued(); break; case CityRotationPurpose.Fear: ChangeState(CityState.Fear); break; default: ChangeState(CityState.Stopped); break; } rotationPurpose = CityRotationPurpose.None; } float progress = MathEx.Saturate(1 - remainingRotationTime / rotationTime); currentFacing = Quaternion.Slerp(rotationSrc, rotationTarget, progress); if (isVisible) stopped[currentForm].Update(time); break; case CityState.PostCatch: catchingRelease[currentForm].Update(time); break; case CityState.Catch: catching[currentForm].Update(time); break; case CityState.Fear: fear[currentForm].Update(time); break; case CityState.Idle: idle[currentForm].Update(time); break; case CityState.Laugh: laugh[currentForm].Update(time); break; case CityState.Stopped: //if (reThrowDelay > 0) //{ // reThrowDelay -= dt; // if (reThrowDelay < 0) // { // ThrowContinued(throwRgball.FollowingCity, throwRgball.GetRemainingPath(), throwRgball.Balls); // } //} // handle the requrest in the throw queue first, if any if (throwQueue.Count > 0) { ThrowTask tt = throwQueue.Head(); Quaternion targetRot = GetOrientation(tt.throwPath[0].Position); RotateTo(targetRot, 0.5f); SetRotationPurpose(CityRotationPurpose.Throw); break; } // then if any balls to pass on, if any and throwContCheckCD is ready throwContCheckCD -= dt; if (receivedRGBall.Count > 0 && throwContCheckCD < 0) { RGatheredBall rgb = receivedRGBall.Dequeue(); if (!rgb.IsPathFinished) { ThrowContinued(rgb.FollowingCity, rgb.GetRemainingPath(), rgb.Balls); break; } throwContCheckCD = 0.5f; } smoke.EmitEnabled = true; // to idle if (nextIdleAnimationCD > 0) { nextIdleAnimationCD -= dt; } else { nextIdleAnimationCD = Randomizer.GetRandomSingle() * 3 + 2.5f; bool goIdle = Randomizer.GetRandomBool(); if (goIdle) { ChangeState(CityState.Idle); } else { float rotTime = Randomizer.GetRandomSingle() * 0.5f + 0.5f; float facingChange = Randomizer.GetRandomSingle() * MathEx.PIf - MathEx.PiOver2; Quaternion nextFacing = currentFacing * Quaternion.RotationAxis(Vector3.UnitY, facingChange); RotateTo(nextFacing, rotTime); } } if (isVisible) stopped[currentForm].Update(time); break; case CityState.Throw: throwing[currentForm].Update(time); break; case CityState.ThrowContinued: throwing[currentForm].Update(time); break; case CityState.WakeingUp: wakeingUp[currentForm].Update(time); break; case CityState.Sleeping: if (isVisible) sleeping[currentForm].Update(time); break; case CityState.WaitingGather: if (throwRgball.CurrentState == RGatheredBall.State.WaitingThrow) { ChangeState(CityState.Throw); } else if (throwRgball.CurrentState == RGatheredBall.State.Finished) { ChangeState(CityState.Stopped); throwRgball = null; } else { // check if the balls in the RGatheredBall is gone for some reason // the city should turn back to normal to aviod dead lock if (throwRgball.Balls.Count == 0) { ChangeState(CityState.Stopped); throwRgball = null; } else { bool passed = false; for (int i = 0; i < throwRgball.Balls.Count; i++) { if (!throwRgball.Balls[i].IsDied) { passed = true; } } if (!passed) { ChangeState(CityState.Stopped); throwRgball = null; } } } throwingPrepare[currentForm].Update(time); break; } }
private void ChangeState(CityState state) { switch (state) { case CityState.Catch: catching[currentForm].PlayAnimation(); break; case CityState.PostCatch: catchingRelease[currentForm].PlayAnimation(); break; case CityState.Fear: fear[currentForm].PlayAnimation(); PlayWord(WordType.Ouch); if (fearSound[currentForm] != null) { fearSound[currentForm].Fire(); } break; case CityState.Idle: idle[currentForm].PlayAnimation(); break; case CityState.Laugh: laugh[currentForm].PlayAnimation(); int t = Randomizer.GetRandomInt(3); if (t == 0) PlayWord(WordType.Woot); else if (t == 1) PlayWord(WordType.Yeah); else PlayWord(WordType.Haha); if (laughSound[currentForm] != null) { laughSound[currentForm].Fire(); } break; case CityState.Stopped: stopped[currentForm].PlayAnimation(); if (currentState == CityState.WakeingUp) { wakeingUp[currentForm].PauseAnimation(); } break; case CityState.Throw: throwing[currentForm].PlayAnimation(); throwRgball.NotifyThrow(); throwRgball = null; break; case CityState.WakeingUp: wakeingUp[currentForm].PlayAnimation(); if (currentState == CityState.Sleeping) { sleeping[currentForm].PauseAnimation(); } break; case CityState.Rotate: case CityState.Sleeping: sleeping[currentForm].PlayAnimation(); break; case CityState.WaitingGather: throwingPrepare[currentForm].PlayAnimation(); break; } currentState = state; }
void ThrowNowContinued() { List<RBall> toThrow = new List<RBall>(ballsToThrowCont.Count); for (int i = 0; i < ballsToThrowCont.Count; i++) { if (ballsToThrowCont[i].Owner == Owner && ballsToThrowCont[i].DockCity == this && !ballsToThrowCont[i].IsDied) { toThrow.Add(ballsToThrowCont[i]); } } if (toThrow.Count == 0) { return; } throwRgball = battleField.CreateRGatherBall(toThrow, this, throwPathCont); throwPathCont = null; ChangeState(CityState.WaitingGather); }
void ThrowNow() { ThrowTask task = throwQueue.Dequeue(); if (task.throwPath == null) { throw new InvalidOperationException(); } List<RBall> toThrow = new List<RBall>(nearbyBallList.Count); if (task.isTypedThrow) { if (task.isCountedThrow) { for (int i = 0; i < nearbyBallList.Count && toThrow.Count < task.throwCount; i++) { if (CheckBallThrowable(nearbyBallList[i]) && nearbyBallList[i].Type == task.typeToThrow) { toThrow.Add(nearbyBallList[i]); } } } else { for (int i = 0; i < nearbyBallList.Count; i++) { if (CheckBallThrowable(nearbyBallList[i]) && nearbyBallList[i].Type == task.typeToThrow) { toThrow.Add(nearbyBallList[i]); } } } } else { for (int i = 0; i < nearbyBallList.Count; i++) { if (CheckBallThrowable(nearbyBallList[i])) { toThrow.Add(nearbyBallList[i]); } } } if (toThrow.Count == 0) { return; } throwRgball = battleField.CreateRGatherBall(toThrow, this, task.throwPath); ChangeState(CityState.WaitingGather); }
public void NotifyIncomingBall(RGatheredBall rgball) { bool flag = false; if (currentState == CityState.Rotate) { if (rotationPurpose != CityRotationPurpose.None) { flag = true; } } bool flag2 = currentState == CityState.PostCatch || currentState == CityState.WaitingGather; if (currentState != CityState.Sleeping) { if (CanHandleCommand() && !flag && !flag2) { if (rgball.SourceCity != null && rgball.SourceCity.Owner != Owner) { Quaternion targetRot = GetOrientation(rgball.Position); RotateTo(targetRot, 0.5f); SetRotationPurpose(CityRotationPurpose.Fear); } else { Quaternion targetRot = GetOrientation(rgball.Position); RotateTo(targetRot, 0.5f); SetRotationPurpose(CityRotationPurpose.Receive); //this.throwRgball = rgball; receivedRGBall.Enqueue(rgball); } } else { if (rgball.SourceCity != null && rgball.SourceCity.Owner == Owner) { receivedRGBall.Enqueue(rgball); } } } }