Ejemplo n.º 1
0
        public void GameUpdated()
        {
            if (WorldTick == 0)
            {
                WorldTick = 1;
            }
            var done = new List <Creature>();

            while (true)
            {
                var creature = CreatureManager.FirstActiveCreature;

                #region не давать ходить дважды до перерисовки);

                if (done.Contains(creature))
                {
                    break;
                }

                if (creature.Speed > 0)
                {
                    done.Add(creature);
                }

                #endregion

                if ((!creature.IsAvatar) && creature.ActResult != EActResults.NEED_ADDITIONAL_PARAMETERS &&
                    creature.NextAct == null)
                {
                    var thinkingResult = creature.Thinking();
                    switch (thinkingResult)
                    {
                    case EThinkingResult.NORMAL:
                        break;

                    case EThinkingResult.SHOULD_BE_REMOVED_FROM_QUEUE:
                        CreatureManager.CreatureIsDead(creature);
                        continue;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }

                if (creature.NextAct == null)
                {
                    break;
                }

                WorldTick = WorldTick < creature.BusyTill ? creature.BusyTill : WorldTick;

                EActResults actResult;

                if (creature.IsAvatar)
                {
                    MessageManager.SendMessage(this, WorldMessage.AvatarBeginsTurn);
                }
                do
                {
                    actResult = creature.DoAct();

                    switch (actResult)
                    {
                    case EActResults.NEED_ADDITIONAL_PARAMETERS:
                        return;

                    case EActResults.ACT_REPLACED:
                        break;

                    case EActResults.DONE:
                        break;

                    case EActResults.WORLD_STAYS_UNCHANGED:
                    case EActResults.FAIL:
                    case EActResults.QUICK_FAIL:
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                } while (actResult == EActResults.ACT_REPLACED);
                MessageManager.SendMessage(this, WorldMessage.MicroTurn);
            }
            if (done.Contains(Avatar) || Avatar.NextAct == null)
            {
                MessageManager.SendMessage(this, WorldMessage.Turn);
            }
        }