예제 #1
0
        public Moment BuildNextMoment(Adventure adventure, Moment priorMoment, Event @event)
        {
            var flags = priorMoment.Flags.Concat(@event.FlagsToSet).Except(@event.FlagsToClear).Distinct().ToArray();
              var newMoment = new Moment {
            Adventure = adventure,
            EventName = @event.Name,
            StepsConsumed = @event.StepsConsumed,
            Ordinal = priorMoment.Ordinal + 1
              };
              this.DbContext.Moments.Add(newMoment);

              foreach (var flag in flags) {
            var momentFlag = new MomentFlag {
              Flag = flag
            };
            this.DbContext.MomentFlags.Add(momentFlag);
            newMoment.MomentFlags.Add(momentFlag);
              };

              adventure.Moments.Add(newMoment);

              this.DbContext.SaveChanges();

              adventure.CurrentMomentId = newMoment.Id;

              return newMoment;
        }
예제 #2
0
 private static bool EventCanExecute(Event @event, FlagDictionary flagDictionary)
 {
     return (@event.Repeatable || !flagDictionary[@event.Name]) && @event.CanExecute(flagDictionary);
 }