/// <summary> /// Enters defend state when the docking city is owned /// </summary> void Defend() { if (dockCity.NearbyEnemyBallCount > 0) { int tries = 0; int idx = Randomizer.GetRandomInt(dockCity.NearbyEnemyBallCount); while (tries < dockCity.NearbyEnemyBallCount && dockCity.GetNearbyEnemyBall(idx).IsDied) { tries++; idx++; idx %= dockCity.NearbyEnemyBallCount; } if (tries < dockCity.NearbyEnemyBallCount) { target = dockCity.GetNearbyEnemyBall(idx); if (target != null) { ChangeState(RBallState.Defend); } } } }
/// <summary> /// Try attack other ememy balls in the docking city /// </summary> void Attack() { if (dockCity.NearbyOwnedBallCount > 0) { // The enemy from the same side as the city's int tries = 0; int idx = Randomizer.GetRandomInt(dockCity.NearbyOwnedBallCount); while (tries < dockCity.NearbyOwnedBallCount && dockCity.GetNearbyOwnedBall(idx).IsDied) { tries++; idx++; idx %= dockCity.NearbyOwnedBallCount; } if (tries < dockCity.NearbyOwnedBallCount) { target = dockCity.GetNearbyOwnedBall(idx); if (target != null) { ChangeState(RBallState.Attack); } } } else if (dockCity.NearbyEnemyBallCount > 0) { // The enemy from other sides than the city's int tries = 0; int idx = Randomizer.GetRandomInt(dockCity.NearbyEnemyBallCount); while (tries < dockCity.NearbyEnemyBallCount && dockCity.GetNearbyEnemyBall(idx).IsDied && dockCity.GetNearbyEnemyBall(idx).Owner == Owner) { idx++; idx %= dockCity.NearbyEnemyBallCount; } if (tries < dockCity.NearbyEnemyBallCount) { target = dockCity.GetNearbyEnemyBall(idx); if (target != null) { ChangeState(RBallState.Attack); } } } }
public ResourceBallEventArg(bool bornOrDie, RBall ball) { BornOrDie = bornOrDie; ResourceBall = ball; }
public void CreateResourceBall(Player owner, City city, RBallType type) { RBall ball = new RBall(owner, city, type); resBalls.Add(ball); if (ResourceBallChanged != null) { ResourceBallChanged(this, new ResourceBallEventArg(true, ball)); } }
public void DestroyResourceBall(RBall ball) { resBalls.Remove(ball); if (ResourceBallChanged != null) { ResourceBallChanged(this, new ResourceBallEventArg(false, ball)); } }
/// <summary> /// Enters defend state when the docking city is owned /// </summary> void Defend() { if (dockCity.NearbyEnemyBallCount > 0) { int tries = 0; int idx = Randomizer.GetRandomInt(dockCity.NearbyEnemyBallCount); while (tries<dockCity.NearbyEnemyBallCount && dockCity.GetNearbyEnemyBall(idx).IsDied) { tries++; idx++; idx %=dockCity.NearbyEnemyBallCount; } if (tries < dockCity.NearbyEnemyBallCount) { target = dockCity.GetNearbyEnemyBall(idx); if (target != null) { ChangeState(RBallState.Defend); } } } }
/// <summary> /// Try attack other ememy balls in the docking city /// </summary> void Attack() { if (dockCity.NearbyOwnedBallCount > 0) { // The enemy from the same side as the city's int tries = 0; int idx = Randomizer.GetRandomInt(dockCity.NearbyOwnedBallCount); while (tries < dockCity.NearbyOwnedBallCount && dockCity.GetNearbyOwnedBall(idx).IsDied) { tries++; idx++; idx %= dockCity.NearbyOwnedBallCount; } if (tries < dockCity.NearbyOwnedBallCount) { target = dockCity.GetNearbyOwnedBall(idx); if (target != null) { ChangeState(RBallState.Attack); } } } else if (dockCity.NearbyEnemyBallCount > 0) { // The enemy from other sides than the city's int tries = 0; int idx = Randomizer.GetRandomInt(dockCity.NearbyEnemyBallCount); while (tries < dockCity.NearbyEnemyBallCount && dockCity.GetNearbyEnemyBall(idx).IsDied && dockCity.GetNearbyEnemyBall(idx).Owner == Owner) { idx++; idx %= dockCity.NearbyEnemyBallCount; } if (tries < dockCity.NearbyEnemyBallCount) { target = dockCity.GetNearbyEnemyBall(idx); if (target != null) { ChangeState(RBallState.Attack); } } } }
bool CheckBallThrowable(RBall ball) { if (ball.Owner != Owner) { return false; } if (ball.State == RBallState.Gathered) { return false; } if (ball.State == RBallState.Gathering) { return false; } if (ball.IsDied) { return false; } return true; }
public void NotifyResourceBallMoveOut(RBall ball) { nearbyBallList.Remove(ball); if (ball.Owner == Owner) { nearbyOwnedBalls.Remove(ball); } else { nearbyEnemyBalls.Remove(ball); } }
public void NotifyResourceBallMoveIn(RBall ball) { nearbyBallList.Add(ball); if (ball.Owner == Owner) { nearbyOwnedBalls.Add(ball); } else { nearbyEnemyBalls.Add(ball); } }