public GameState ApplyOn(GameState gameState, Player owner, Minion caster)
 {
     return(Effects.Aggregate(gameState, (aggregState, eff) =>
                              TypeSwitchExpr.On <Effect, GameState>(eff)
                              .Case <CharacterEffect>(effect =>
     {
         var targets = GetValidTargets(aggregState, owner, caster).ToArray();
         var updatedChars = targets.Select(x => effect.ApplyOn((ITarget <Character>)x));
         return aggregState.UpdateCharacters(targets, updatedChars);
     })
                              .Case <NonCharacterEffect>(effect =>
     {
         if (Target.HasFlag(Target.FriendlyPlayer))
         {
             aggregState = effect.ApplyOn(aggregState, owner, caster);
         }
         if (Target.HasFlag(Target.EnemyPlayer))
         {
             aggregState = effect.ApplyOn(aggregState, aggregState.OpponentOf(owner), caster);
         }
         return aggregState;
     })
                              .ElseThrow()));
 }
示例#2
0
 public WorldState Apply(WorldState initialState)
 {
     return(Effects.Aggregate(initialState, (soFar, effect) => effect.ApplyTo(soFar)));
 }