public void EndGame() { State = Status.Ended; if (Participants.Count > 0 && Pot > 0.0m) { Participants[0].World.LogEvent(String.Format("Dice: {0} dwarfs split a pot of {1}", Participants.Count, Pot)); DwarfBux potDistribution = Pot / (decimal)Participants.Count; foreach (var participant in Participants) { participant.Status.Money += potDistribution; IndicatorManager.DrawIndicator((potDistribution).ToString(), participant.AI.Position + Microsoft.Xna.Framework.Vector3.Up + Microsoft.Xna.Framework.Vector3.Forward * 0.1f, 10.0f, GameSettings.Default.Colors.GetColor("Positive", Microsoft.Xna.Framework.Color.Green)); } Pot = 0.0m; } if (PotFixture != null) { PotFixture.Delete(); PotFixture = null; } }
public void Update(DwarfTime time) { Participants.RemoveAll(r => r == null || r.IsDead || r.Physics == null || r.AI == null || r.IsAsleep || !r.Active); if (Participants.Count == 0) { if (PotFixture != null) { PotFixture.Delete(); PotFixture = null; } } PushParticipants(); switch (State) { case Status.WaitingForPlayers: { Participants.RemoveAll(creature => creature == null || creature.IsDead || creature.Status.Money < 10.0m || creature.Physics.IsInLiquid); WaitTimer.Update(time); if (WaitTimer.HasTriggered || Participants.Count >= 4) { if (Participants.Count >= 2) { foreach (var participant in Participants) { if ((Location - participant.AI.Position).Length() > 4) { return; } } Participants[0].World.LogEvent("A new game of dice has started.", String.Format("There are {0} players.", Participants.Count)); State = Status.Gaming; RoundTimer.Reset(); CurrentRound = 1; if (PotFixture == null) { PotFixture = new CoinPileFixture(Participants[0].Manager, Location) { Name = "Gambling pot" }; PotFixture.SetFullness(0); Participants[0].Manager.RootComponent.AddChild(PotFixture); } } else { if (Participants.Count > 0) { Participants[0].World.LogEvent("The dice game ended prematurely.", "The dice players couldn't meet up."); } EndGame(); } return; } break; } case Status.Gaming: { RoundTimer.Update(time); if (RoundTimer.HasTriggered) { NextRound(); } return; } case Status.Ended: { WaitTimer.Reset(); return; } } }