Example #1
0
        public void NextRound()
        {
            RoundTimer.Reset();
            int countBefore = Participants.Count;

            Participants.RemoveAll(creature => creature == null || creature.IsDead || creature.Status.Money < 10.0m || creature.Physics.IsInLiquid);
            int countAfter = Participants.Count;

            if (countAfter > 0 && countAfter < countBefore)
            {
                Participants[0].World.LogEvent(String.Format("Dice: {0} player(s) left the game.", countBefore - countAfter));
            }

            if (Participants.Count < 2)
            {
                EndGame();
                return;
            }


            foreach (var participant in Participants)
            {
                var money = participant.Status.Money;

                var bet = (decimal)(int)(MathFunctions.Rand(0.1f, 0.25f) * money);
                Pot += (DwarfBux)bet;
                participant.Status.Money -= (DwarfBux)bet;

                IndicatorManager.DrawIndicator((-(DwarfBux)bet).ToString(),
                                               participant.AI.Position + Microsoft.Xna.Framework.Vector3.Up, 4.0f,
                                               GameSettings.Default.Colors.GetColor("Negative", Microsoft.Xna.Framework.Color.Red));
            }
            Participants[0].World.LogEvent(String.Format("Dice: Entering round {0}/{1}. The Pot is {2}.", CurrentRound, MaxRounds, Pot.ToString()));

            List <Creature> winners = new List <Creature>();
            List <int>      rolls   = new List <int>();
            int             maxRoll = 0;

            foreach (var participant in Participants)
            {
                Microsoft.Xna.Framework.Vector3 vel = (participant.AI.Position - Location) + MathFunctions.RandVector3Cube() * 0.5f;
                vel.Normalize();
                vel *= 5;
                vel += Microsoft.Xna.Framework.Vector3.Up * 1.5f;
                participant.World.ParticleManager.Create("dice", participant.AI.Position, -vel, Microsoft.Xna.Framework.Color.White);
                int roll = MathFunctions.RandInt(1, 7);
                rolls.Add(roll);
                if (roll >= maxRoll)
                {
                    maxRoll = roll;
                }
            }

            for (int k = 0; k < rolls.Count; k++)
            {
                if (rolls[k] >= maxRoll)
                {
                    winners.Add(Participants[k]);
                }
            }

            if (winners.Count == 1)
            {
                var maxParticipant = winners[0];
                maxParticipant.Status.Money += Pot;
                winners[0].World.LogEvent(String.Format("{0} won {1} at dice.", maxParticipant.Stats.FullName, Pot));
                maxParticipant.NoiseMaker.MakeNoise("Pleased", maxParticipant.AI.Position, true, 0.5f);
                IndicatorManager.DrawIndicator((Pot).ToString(),
                                               maxParticipant.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;
                maxParticipant.AddThought(Thought.ThoughtType.WonGambling);
            }
            else
            {
                Participants[0].World.LogEvent(String.Format("Nobody won this round of dice. The Pot is {0}.", Pot.ToString()));
            }

            if (PotFixture != null)
            {
                PotFixture.SetFullness((float)(decimal)(Pot / 500.0m));
            }

            CurrentRound++;
            if (CurrentRound > MaxRounds)
            {
                CurrentRound = 1;
                EndGame();
            }
        }