Beispiel #1
0
        public virtual string GetForestCampLaborerString(IStructure lumbermill)
        {
            int max = GetLumbermillMaxLabor(lumbermill);
            int cur = lumbermill.City.Where(s => ObjectTypeFactory.IsStructureType("ForestCamp", s)).Sum(x => x.Stats.Labor);

            return(string.Format("{0}/{1}", cur, max));
        }
Beispiel #2
0
        /// <summary>
        ///     Returns the amount of gold the user should get for the specified city
        /// </summary>
        /// <param name="city">City to recalculate resources for</param>
        /// <returns></returns>
        public virtual int GetGoldRate(ICity city)
        {
            int value = 0;

            var weaponExportMax =
                city.Technologies.GetEffects(EffectCode.WeaponExport)
                .DefaultIfEmpty()
                .Max(x => x == null ? 0 : (int)x.Value[0]);

            if (weaponExportMax > 0)
            {
                value += GetWeaponExportLaborProduce(weaponExportMax, city.Resource.Labor.Value, city.Resource.Gold.Value);
            }

            foreach (Structure structure in city.Where(x => ObjectTypeFactory.IsStructureType("Market", x)))
            {
                if (structure.Lvl >= 10)
                {
                    value += 50;
                }
                else if (structure.Lvl >= 6)
                {
                    value += 18;
                }
                else if (structure.Lvl >= 4)
                {
                    value += 4;
                }
            }
            return(value);
        }
Beispiel #3
0
 /// <summary>
 ///     Returns the amount of crop the user should get for the specified city
 /// </summary>
 /// <param name="city">City to recalculate resources for</param>
 /// <returns></returns>
 public virtual int GetCropRate(ICity city)
 {
     double[] lvlBonus = { 1, 1, 1, 1, 1, 1, 1, 1.1, 1.1, 1.2, 1.2, 1.3, 1.3, 1.4, 1.4, 1.5 };
     return(60 + city.Lvl * 5 +
            (int)
            city.Sum(x => ObjectTypeFactory.IsStructureType("Crop", x) ? x.Stats.Labor * lvlBonus[x.Lvl] : 0));
 }
Beispiel #4
0
        public static T Dump <T>(this T item)
        {
            var dumpItemBase = ObjectTypeFactory.Create(item);

            WriterDelegate(dumpItemBase.Value);

            return(item);
        }
Beispiel #5
0
        /// <summary>
        ///     Returns the rate that the specified structure should gather from the given forest.
        /// </summary>
        /// <param name="forestCamp"></param>
        /// <param name="efficiency"></param>
        /// <returns></returns>
        public virtual int GetWoodRateForForestCamp(IStructure forestCamp, float efficiency)
        {
            var lumbermill = forestCamp.City.FirstOrDefault(s => ObjectTypeFactory.IsStructureType("Lumbermill", s));

            if (lumbermill == null)
            {
                return(0);
            }

            double[] rate = { 0, .75, .75, 1, 1, 1, 1, 1.25, 1.25, 1.25, 1.25, 1.25, 1.5, 1.5, 1.5, 1.5 };
            return((int)(forestCamp.Stats.Labor * rate[lumbermill.Lvl] * (1f + efficiency)));
        }
Beispiel #6
0
        /// <summary>
        ///     Returns the amount of wood the user should get for the specified city.
        ///     Notice: This function looks at all the Forest Camps Rate property and adds them up.
        /// </summary>
        /// <param name="city">City to recalculate resources for</param>
        /// <returns></returns>
        public virtual int GetWoodRate(ICity city)
        {
            return(60 + city.Lvl * 5 + city.Sum(x =>
            {
                object rate;
                if (!ObjectTypeFactory.IsStructureType("ForestCamp", x) || x.Lvl == 0 ||
                    !x.Properties.TryGet("Rate", out rate))
                {
                    return 0;
                }

                return (int)rate;
            }));
        }
Beispiel #7
0
            public CollectionObject(IEnumerable items)
                : base(items)
            {
                _value = new Lazy <string>(() =>
                {
                    var sb = new StringBuilder();

                    var name      = TextForCollectionOf(Items.GetType(), Children.Count());
                    var dumpItems = (from object item in Items
                                     select ObjectTypeFactory.Create(item)).ToList();

                    var totalWidth       = name.Length;
                    var valueColumnWidth = dumpItems.Select(s => s.ValueWidth).Concat(new[] { totalWidth }).Max();

                    Action writeDividerLine = () =>
                    {
                        sb.Append("|");
                        sb.Append(new string('-', valueColumnWidth + 2));
                        sb.AppendLine("|");
                    };

                    Action <string> writeTextLine = lineToWrite =>
                    {
                        sb.Append("| ");
                        sb.Append(string.Format("{0,-" + (valueColumnWidth) + "}", lineToWrite));
                        sb.AppendLine(" |");
                    };

                    writeDividerLine();
                    writeTextLine(name);
                    writeDividerLine();


                    foreach (DumpItemBase dumpItem in dumpItems)
                    {
                        var eachRowInChildItem = dumpItem.Value.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

                        writeTextLine(eachRowInChildItem.First());

                        foreach (string row in eachRowInChildItem.Skip(1))
                        {
                            writeTextLine(row);
                        }

                        writeDividerLine();
                    }

                    return(sb.ToString());
                });
            }
        public void CreateObjectType()
        {
            // arrange
            var scalarType = new StringType();

            var          parser   = new Parser();
            DocumentNode document = parser.Parse(
                "type Simple { a: String b: [String] }");
            ObjectTypeDefinitionNode objectTypeDefinition = document
                                                            .Definitions.OfType <ObjectTypeDefinitionNode>().First();
            var resolverBinding = new DelegateResolverBinding(
                "Simple", "a",
                (c, r) => "hello");

            var serviceManager = new ServiceManager();
            var schemaContext  = new SchemaContext(serviceManager);

            schemaContext.Types.RegisterType(scalarType);
            schemaContext.Resolvers.RegisterResolver(resolverBinding);

            // act
            var        factory    = new ObjectTypeFactory();
            ObjectType objectType = factory.Create(objectTypeDefinition);

            schemaContext.Types.RegisterType(objectType);

            var initializationContext = new TypeInitializationContext(
                schemaContext, error => { }, objectType, false);

            ((INeedsInitialization)objectType)
            .RegisterDependencies(initializationContext);
            schemaContext.CompleteTypes();

            // assert
            Assert.Equal("Simple", objectType.Name);
            Assert.Equal(3, objectType.Fields.Count);
            Assert.True(objectType.Fields.ContainsField("a"));
            Assert.True(objectType.Fields.ContainsField("b"));
            Assert.False(objectType.Fields["a"].Type.IsNonNullType());
            Assert.False(objectType.Fields["a"].Type.IsListType());
            Assert.True(objectType.Fields["a"].Type.IsScalarType());
            Assert.Equal("String", objectType.Fields["a"].Type.TypeName());
            Assert.False(objectType.Fields["b"].Type.IsNonNullType());
            Assert.True(objectType.Fields["b"].Type.IsListType());
            Assert.False(objectType.Fields["b"].Type.IsScalarType());
            Assert.Equal("String", objectType.Fields["b"].Type.TypeName());
            Assert.Equal("hello", (objectType.Fields["a"]
                                   .Resolver(null, CancellationToken.None)));
        }
Beispiel #9
0
        public virtual int GetInstantTrainCount(IStructure structure)
        {
            var effectForStructureType =
                structure.City.Technologies.GetEffects(EffectCode.UnitTrainInstantTime).Where(x => (int)x.Value[0] == structure.Type).ToList();

            if (!effectForStructureType.Any())
            {
                return(0);
            }

            var units = structure.City.Troops.MyStubs().SelectMany(stub => stub.ToUnitList());

            var current = units.Sum(x => ObjectTypeFactory.IsObjectType((string)effectForStructureType[0].Value[1], x.Type) ? x.Count : 0);

            var threshold = Math.Min(effectForStructureType.Sum(x => (int)x.Value[2]), (int)effectForStructureType[0].Value[3]);

            return(Math.Max(threshold - current, 0));
        }
Beispiel #10
0
        public void ObjectFieldDeprecationReason()
        {
            // arrange
            ObjectTypeDefinitionNode typeDefinition =
                CreateTypeDefinition <ObjectTypeDefinitionNode>(@"
                    type Simple {
                        a: String @deprecated(reason: ""reason123"")
                    }");

            // act
            var        factory = new ObjectTypeFactory();
            ObjectType type    = factory.Create(typeDefinition);

            CompleteType(type);

            // assert
            Assert.True(type.Fields["a"].IsDeprecated);
            Assert.Equal("reason123", type.Fields["a"].DeprecationReason);
        }
Beispiel #11
0
        /// <summary>
        ///     Gets amount of resources that are hidden
        /// </summary>
        /// <param name="city"></param>
        /// <param name="checkAlignmentPointBonus"></param>
        /// <returns></returns>
        public virtual Resource HiddenResource(ICity city, bool checkAlignmentPointBonus = false)
        {
            int[] rateCrop = { 0, 100, 150, 220, 330, 500, 740, 1100, 1100, 1100, 1100 };
            int[] rateWood = { 0, 100, 150, 220, 330, 500, 740, 1100, 1100, 1100, 1100 };
            int[] rateGold = { 0, 0, 0, 0, 0, 100, 150, 220, 330, 500, 740 };
            int[] rateIron = { 0, 0, 0, 0, 0, 0, 0, 0, 200, 360, 660 };

            var resource = new Resource();

            foreach (var structure in city.Where(x => ObjectTypeFactory.IsStructureType("Basement", x)))
            {
                resource.Add(rateCrop[structure.Lvl],
                             rateGold[structure.Lvl],
                             rateIron[structure.Lvl],
                             rateWood[structure.Lvl],
                             0);
            }

            int[] tempRateCrop = { 0, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700 };
            int[] tempRateWood = { 0, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700 };
            int[] tempRateGold = { 0, 0, 0, 0, 0, 500, 600, 700, 800, 900, 1000 };
            int[] tempRateIron = { 0, 0, 0, 0, 0, 0, 0, 0, 500, 750, 1000 };
            foreach (var structure in city.Where(x => ObjectTypeFactory.IsStructureType("TempBasement", x)))
            {
                resource.Add(tempRateCrop[structure.Lvl],
                             tempRateGold[structure.Lvl],
                             tempRateIron[structure.Lvl],
                             tempRateWood[structure.Lvl],
                             0);
            }

            if (checkAlignmentPointBonus && city.AlignmentPoint >= 75m)
            {
                const double pct = .75;
                return(new Resource((int)Math.Max(city.Resource.Crop.Limit * pct, resource.Crop),
                                    (int)Math.Max(city.Resource.Gold.Limit * pct, resource.Gold),
                                    (int)Math.Max(city.Resource.Iron.Limit * pct, resource.Iron),
                                    (int)Math.Max(city.Resource.Wood.Limit * pct, resource.Wood),
                                    0));
            }
            return(resource);
        }
Beispiel #12
0
        public void CreateObjectType()
        {
            // arrange
            ObjectTypeDefinitionNode typeDefinition =
                CreateTypeDefinition <ObjectTypeDefinitionNode>(@"
                    type Simple { a: String b: [String] }");

            var resolverBinding = new FieldResolver(
                "Simple", "a",
                c => Task.FromResult <object>("hello"));

            // act
            var        factory = new ObjectTypeFactory();
            ObjectType type    = factory.Create(typeDefinition);

            CompleteType(type,
                         s => s.Resolvers.RegisterResolver(resolverBinding));

            // assert
            Assert.Equal("Simple", type.Name);
            Assert.Equal(3, type.Fields.Count);

            Assert.True(type.Fields.ContainsField("a"));
            Assert.False(type.Fields["a"].Type.IsNonNullType());
            Assert.False(type.Fields["a"].Type.IsListType());
            Assert.True(type.Fields["a"].Type.IsScalarType());
            Assert.Equal("String", type.Fields["a"].Type.TypeName());

            Assert.True(type.Fields.ContainsField("b"));
            Assert.False(type.Fields["b"].Type.IsNonNullType());
            Assert.True(type.Fields["b"].Type.IsListType());
            Assert.False(type.Fields["b"].Type.IsScalarType());
            Assert.Equal("String", type.Fields["b"].Type.TypeName());

            Assert.Equal("hello", (type.Fields["a"]
                                   .Resolver(null).Result));
        }
Beispiel #13
0
        /// <summary>
        ///     Returns the amount of iron the user should get for the specified city
        /// </summary>
        /// <param name="city">City to recalculate resources for.</param>
        /// <returns></returns>
        public virtual int GetIronRate(ICity city)
        {
            int[] multiplier = { int.MaxValue, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 5, 5, 5, 5, 4 };

            return(city.Sum(x => ObjectTypeFactory.IsStructureType("Iron", x) ? x.Stats.Labor / multiplier[x.Lvl] : 0));
        }
Beispiel #14
0
 public virtual ushort CalculateCityValue(ICity city)
 {
     return((ushort)city.Where(structure => !ObjectTypeFactory.IsStructureType("NoInfluencePoint", structure)).Sum(x => x.Lvl * x.Size));
 }
Beispiel #15
0
 /// <summary>
 /// Helper extension that allows you to easily capture the text value that was created.
 /// </summary>
 /// <param name="item">The instance of the object you would like to dump.</param>
 /// <returns>The ASCII representation of the object as generated by the DumpToText extension.</returns>
 public static string DumpAsString(this object item)
 {
     return(ObjectTypeFactory.Create(item).Value);
 }
Beispiel #16
0
        public virtual int BuildTime(int baseValue, ICity city, ITechnologyManager em)
        {
            IStructure university = city.FirstOrDefault(structure => ObjectTypeFactory.IsStructureType("University", structure));

            return((int)(baseValue * (100 - (university == null ? 0 : university.Stats.Labor) * 0.25) / 100));
        }