Exemple #1
0
        public List <Entity> BuildEntity(Entity schedule, int length)
        {
            var             result = new List <Entity>();
            Action <Entity> push   = e => result.Add(CloneEntityForDialog(e));
            Func <Entity>   last   = () => result.Last();

            if (schedule.BeginSeriesDialogKey != null)
            {
                push(GameConfiguration.Root.FindByKey(schedule.BeginSeriesDialogKey));
            }

            var    totalGold   = 0;
            double lastAbility = 0;
            bool   eligible    = schedule.IsWorkSchdule;

            for (var dayCount = 0; dayCount < length; dayCount++)
            {
                if (dayCount != 0)
                {
                    last().IsDayOver = true;
                }

                var ability = GetAvility(schedule);
                lastAbility = ability;
                var rand    = RandomService.NextDouble(dayCount);
                var success = rand <= ability;
                if (success)
                {
                    push(GameConfiguration.Root.FindByKey(schedule.DaySuccessDialogKey));
                    var gold = GetGoldChange(schedule);

                    ApplyListChanges(schedule, last());
                    ApplyBlackFactoryChangesIfNeeded(schedule, last());

                    last().ChangeKeys.Add("Gold");
                    last().ChangeAmounts.Add(gold);
                    totalGold += gold;

                    PlayState.AddScheduleCount(schedule.Key);
                }
                else
                {
                    eligible = false;
                    push(GameConfiguration.Root.FindByKey(schedule.DayFailDialogKey));

                    ApplyListChanges(schedule, last());
                    ApplyBlackFactoryChangesIfNeeded(schedule, last());
                }
            }

            if (schedule.EndSeriesDialogKey != null)
            {
                for (var i = 0; i < schedule.EndSeriesDialogKey.Count; i++)
                {
                    if (schedule.EndSeriesThresholds[i] <= lastAbility)
                    {
                        push(GameConfiguration.Root.FindByKey(schedule.EndSeriesDialogKey[i]));
                        break;
                    }
                }
            }
            if (eligible)
            {
                last().ChangeKeys.Add("Gold");
                last().ChangeAmounts.Add(totalGold / 2);
            }
            last().IsDayOver = true;
            return(result);
        }