private IEnumerable <IStat> BuildStats(BuildParameters parameters)
        {
            var entities = _entityBuilder.Build(parameters.ModifierSourceEntity);
            var t        = _coreBuilder.Build(parameters);

            return(entities.SelectMany(e => _statFactory(parameters, e, t)));
        }
示例#2
0
        public int ImportEntitiesFromFile(string filePath)
        {
            var existingEntitiesCount = _repository.GetAll().Count();

            if (existingEntitiesCount > 0)
            {
                _logger.LogInformation($"Entities of type '{typeof(T).Name}' have been already imported.");
                return(0);
            }

            _logger.LogInformation($"Reading file with {typeof(T).Name}s . . .");

            var entityLines = File.ReadLines(filePath).ToList();

            _entityBuilder.ReadEntityMappings(entityLines.First());
            entityLines.RemoveAt(0);

            _logger.LogInformation($"Mapping to {typeof(T).Name} objects . . .");
            var mappedEntities = entityLines.Select(line => _entityBuilder.Build(line)).ToList();

            _logger.LogInformation($"Read {mappedEntities.Count} lines of {typeof(T).Name}.");
            SortEntities(mappedEntities);
            var entitiesCount = SaveEntities(mappedEntities);

            _logger.LogInformation($"{entitiesCount} entities of type '{typeof(T).Name}' have been successfully saved.");

            return(entitiesCount);
        }
示例#3
0
        public static T BuildAndPersist <T>(this IEntityBuilder <T> builder, ISession session) where T : SystemEntity
        {
            var entity = builder.Build();

            session.Transact(s => s.Save(entity));
            return(entity);
        }
        public IStatBuilder EffectOn(IEntityBuilder target)
        {
            return(new StatBuilder(StatFactory, FromStatFactory(BuildStats)));

            IEnumerable <IStat> BuildStats(BuildParameters parameters, Entity source, string identity)
            => target.Build(parameters.ModifierSourceEntity)
            .Select(t => BuildEffectStat(source, t, identity));
        }
示例#5
0
        private IEnumerable <IStat> ConvertStat(BuildParameters parameters, ICoreBuilder <string> identity, IStat stat)
        {
            var builtIdentity = identity.Build(parameters);

            return(from e in _entity.Build(stat.Entity)
                   let i = $"On({builtIdentity}).By({e})"
                           let registrationType = GainOnAction(stat, builtIdentity, e)
                                                  select StatFactory.CopyWithSuffix(stat, i, stat.DataType, registrationType));
        }
        private IConditionBuilder IsFromSource(IEntityBuilder source, IEntityBuilder target)
        {
            var core = FromStatFactory(BuildStats);

            return(new StatBuilder(StatFactory, core).For(target).IsSet);

            IEnumerable <IStat> BuildStats(BuildParameters parameters, Entity t, string identity)
            => source.Build(parameters.ModifierSourceEntity)
            .Select(s => BuildBuffSourceStat(s, t, identity));
        }
        public IEnumerable <StatBuilderResult> Build(BuildParameters parameters)
        {
            var results  = new List <StatBuilderResult>();
            var entities = _entity.Build(parameters.ModifierSourceEntity);

            foreach (var entity in entities)
            {
                var resultsForEntity = _inner.WithEntity(new EntityBuilder(entity)).Build(parameters);
                foreach (var(stats, source, valueConverter) in resultsForEntity)
                {
                    results.Add(new StatBuilderResult(stats, source, valueConverter.AndThen(ConvertValue)));
                }
                IValueBuilder ConvertValue(IValueBuilder left) => _combineValues(left, _createValue(entity));
            }
            return(results);
        }
示例#8
0
        private IEnumerable <IValue> CreateValues(BuildParameters parameters)
        {
            var restrictions   = _restrictionsBuilder.Build();
            var sourceEntities = _source.Build(parameters.ModifierSourceEntity);
            var targetEntities = _target.Build(parameters.ModifierSourceEntity);

            return(from b in _buffs
                   where restrictions.AllowsBuff(b)
                   let buffIdentity = b.Buff.Build()
                                      from t in targetEntities
                                      let activeStat = _statFactory.BuffIsActive(t, buffIdentity)
                                                       let activeCondition = new StatValue(activeStat)
                                                                             let buffSourceCondition = BuffSourceIsAny(t, buffIdentity, sourceEntities)
                                                                                                       select new ConditionalValue(
                       c => activeCondition.Calculate(c).IsTrue() && buffSourceCondition.Calculate(c).IsTrue(),
                       $"{activeCondition} && {buffSourceCondition}"));
        }
        public IEnumerable <StatBuilderResult> Build(BuildParameters parameters)
        {
            var results  = new List <StatBuilderResult>();
            var entities = _entity.Build(parameters.ModifierSourceEntity);

            foreach (var entity in entities)
            {
                var resultsForEntity = _inner.WithEntity(new EntityBuilder(entity))
                                       .Build(parameters)
                                       .Select(r
                                               => new StatBuilderResult(r.Stats, r.ModifierSource, r.ValueConverter.AndThen(ConvertValue)));
                results.AddRange(resultsForEntity);

                IValueBuilder ConvertValue(IValueBuilder left)
                {
                    var right = new ValueBuilderImpl(_buildValue(parameters, entity));

                    return(_combineValues(left, right));
                }
            }
            return(results);
        }
 private IValueBuilder CreateAddStatMultiplier(IEntityBuilder source, Entity target)
 => new ValueBuilderImpl(
     ps => BuildAddStatMultiplier(Build(ps), source.Build(ps.ModifierSourceEntity), target),
     c => ((BuffBuilder)Resolve(c)).CreateAddStatMultiplier(source, target));
示例#11
0
        private static Game ReadRound()
        {
            var game = new Game
            {
                Players = new[]
                {
                    new Player(),
                    new Player(),
                    new Player()
                }
            };

            game.Players[0].Score = int.Parse(ConsoleHelper.ReadLine());
            game.Players[1].Score = int.Parse(ConsoleHelper.ReadLine());
            game.Players[2].Score = int.Parse(ConsoleHelper.ReadLine());

            game.Players[0].Rage = ConsoleHelper.ReadLineAs <int>();
            game.Players[1].Rage = ConsoleHelper.ReadLineAs <int>();
            game.Players[2].Rage = ConsoleHelper.ReadLineAs <int>();

            var unitCount = ConsoleHelper.ReadLineAs <int>();

            for (var i = 0; i < unitCount; i++)
            {
                var inputs = ConsoleHelper.ReadLineAndSplit();
                var entity = EntityBuilder.Build(inputs);
                if (Trace > 0)
                {
                    ConsoleHelper.Debug(entity);
                }

                // Not enabled on CG !
                //switch (entity)
                if (entity is Reaper reaper)
                {
                    game.Players[reaper.Player].Reaper = reaper;
                }
                else if (entity is Destroyer destroyer)
                {
                    game.Players[destroyer.Player].Destroyer = destroyer;
                }
                else if (entity is Doof doof)
                {
                    game.Players[doof.Player].Doof = doof;
                }
                else if (entity is Tanker tanker)
                {
                    game.Tankers.Add(tanker);
                }
                else if (entity is Wreck wreck)
                {
                    game.Wrecks.Add(wreck);
                }
                else if (entity is Tar tar)
                {
                    game.Tars.Add(tar);
                }
                else if (entity is Oil oil)
                {
                    game.Oils.Add(oil);
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            return(game);
        }
示例#12
0
        public IStatBuilder AddStatForSource(IStatBuilder stat, IEntityBuilder source)
        {
            var baseCoreBuilder = new StatBuilderAdapter(base.AddStat(stat));
            var coreBuilder     = new StatBuilderWithValueConverter(baseCoreBuilder,
                                                                    (ps, target) => BuildAddStatMultiplier(source.Build(ps.ModifierSourceEntity), target),
                                                                    (l, r) => l.Multiply(r));

            return(new StatBuilder(StatFactory, coreBuilder));
        }
示例#13
0
 private static Entity BuildEntity(BuildParameters parameters, IEntityBuilder entity) =>
 entity.Build(parameters.ModifierSourceEntity).Single();
示例#14
0
        private IReadOnlyList <IStat> BuildStats(BuildParameters parameters)
        {
            var entities = _entityBuilder.Build(parameters.ModifierSourceEntity);

            return(entities.Select(_statFactory).ToList());
        }