예제 #1
0
        public static bool IsUnitWithCategoryInRange(this IZone zone, CategoryFlags categoryFlags, Position position, int range)
        {
            var unitsInCategory = zone.Units.Where(u => u.IsCategory(categoryFlags) || u is PBSEgg).ToList();

            foreach (var unit in unitsInCategory)
            {
                var egg = unit as PBSEgg;

                if (egg != null)
                {
                    if (egg.TargetPBSNodeDefault.CategoryFlags.IsCategory(categoryFlags))
                    {
                        if (position.IsInRangeOf2D(egg.CurrentPosition, range))
                        {
                            return(true);
                        }
                    }
                }

                if (position.IsInRangeOf2D(unit.CurrentPosition, range))
                {
                    return(true);
                }
            }

            return(false);
        }
 public WeightInfo(EntityDefault lotteryItem, CategoryFlags categoryFlags, TierInfo tier, double weight)
 {
     this.lotteryItem   = lotteryItem;
     this.categoryFlags = categoryFlags;
     this.tier          = tier;
     this.weight        = weight;
 }
예제 #3
0
 public DrillerModule(CategoryFlags ammoCategoryFlags, RareMaterialHandler rareMaterialHandler, MaterialHelper materialHelper) : base(ammoCategoryFlags, true)
 {
     _rareMaterialHandler  = rareMaterialHandler;
     _materialHelper       = materialHelper;
     _miningAmountModifier = new MiningAmountModifierProperty(this);
     AddProperty(_miningAmountModifier);
 }
예제 #4
0
        public static bool IsOverlappingWithCategory(this IZone zone, CategoryFlags categoryFlags, Position position, int typeExclusiveRange)
        {
            var unitsInCategory = zone.Units.Where(u => u.IsCategory(categoryFlags) || u is PBSEgg).ToList();

            var isInRange =
                unitsInCategory.Any(u =>
            {
                var matchRange = u.ED.Config.typeExclusiveRange;

                var egg = u as PBSEgg;
                if (egg != null && egg.TargetPBSNodeDefault.CategoryFlags.IsCategory(categoryFlags))
                {
                    matchRange = egg.TargetPBSNodeDefault.Config.typeExclusiveRange;
                }

                if (matchRange == null)
                {
                    return(false);
                }

                var range = typeExclusiveRange + (int)matchRange;

                return(position.IsInRangeOf2D(u.CurrentPosition, range));
            });

            return(isInRange);
        }
 public BlobEmissionModulatorModule(CategoryFlags ammoCategoryFlags) : base(ammoCategoryFlags, true)
 {
     optimalRange.AddEffectModifier(AggregateField.effect_ew_optimal_range_modifier);
     _blobEmission = new BlobEmissionProperty(this);
     AddProperty(_blobEmission);
     _blobEmissionRadius = new BlobEmissionRadiusProperty(this);
     AddProperty(_blobEmissionRadius);
 }
 public MissileWeaponModule(CategoryFlags ammoCategoryFlags) : base(ammoCategoryFlags)
 {
     _propertyExplosionRadius = new ExplosionRadiusProperty(this);
     AddProperty(_propertyExplosionRadius);
     MissileRangeModifier = new ModuleProperty(this, AggregateField.module_missile_range_modifier);
     MissileRangeModifier.AddEffectModifier(AggregateField.effect_missile_range_modifier);
     AddProperty(MissileRangeModifier);
 }
예제 #7
0
        public HarvesterModule(CategoryFlags ammoCategoryFlags, PlantHarvester.Factory plantHarvesterFactory) : base(ammoCategoryFlags, true)
        {
            _plantHarvesterFactory     = plantHarvesterFactory;
            _harverstingAmountModifier = new HarvestingAmountModifierProperty(this);
            AddProperty(_harverstingAmountModifier);

            cycleTime.AddEffectModifier(AggregateField.effect_harvesting_cycle_time_modifier);
        }
 public long[] GetFirstLevelChildrenByCategoryflags(long eid, CategoryFlags categoryFlags)
 {
     return(Db.Query().CommandText("select e.eid from entities e join entitydefaults d on e.definition=d.definition  where e.parent=@parent and (d.categoryflags & @cfMask)=@cf")
            .SetParameter("@parent", eid)
            .SetParameter("@cfMask", (long)categoryFlags.GetCategoryFlagsMask())
            .SetParameter("@cf", (long)categoryFlags)
            .Execute()
            .Select(r => r.GetValue <long>(0)).ToArray());
 }
예제 #9
0
        public WeaponModule(CategoryFlags ammoCategoryFlags) : base(ammoCategoryFlags, true)
        {
            _action         = new ModuleAction(this);
            _damageModifier = new ModuleProperty(this, AggregateField.damage_modifier);
            AddProperty(_damageModifier);
            _accuracy = new ModuleProperty(this, AggregateField.accuracy);
            AddProperty(_accuracy);

            cycleTime.AddEffectModifier(AggregateField.effect_weapon_cycle_time_modifier);
        }
예제 #10
0
        /// <summary>
        /// Returns true if the current flag is in a tree that is set to unique
        /// This function is used to determine if a module is unique -> only one can be fit on a robot.
        /// </summary>
        public static bool IsUniqueCategoryFlags(this CategoryFlags categoryFlag, out CategoryFlags uniqueCategoryFlag)
        {
            foreach (var cf in GetCategoryFlagsTree(categoryFlag).Reverse().Where(cf => _uniqueCategoryFlags.Values.Contains(cf)))
            {
                uniqueCategoryFlag = cf;
                return(true);
            }

            uniqueCategoryFlag = CategoryFlags.undefined;
            return(false);
        }
예제 #11
0
        public static CategoryFlags GetCategoryFlagsMask(this CategoryFlags categoryFlags)
        {
            var mask = 0xffffffffffffffffL;

            while (((ulong)categoryFlags & mask) > 0)
            {
                mask <<= 8;
            }

            return((CategoryFlags)(~mask));
        }
        public void ScaleComponentsAmount(double scale, CategoryFlags targetCategoryFlag, CategoryFlags componentCategory)
        {
            var descriptions = _productionDescriptions.Values.Where(productionDescription => EntityDefault.Get(productionDescription.definition).CategoryFlags.IsCategory(targetCategoryFlag));

            foreach (var productionDescription in descriptions)
            {
                productionDescription.ScaleComponents(scale, componentCategory);
            }

            _productionDescriptionCache = null;
            _productionDescriptions.Clear();
            InitProductionDescriptions();
        }
예제 #13
0
        /// <summary>
        /// Returns the category flags above the current one
        /// </summary>
        public static IEnumerable <CategoryFlags> GetCategoryFlagsTree(this CategoryFlags categoryFlags)
        {
            var mask = (long)GetCategoryFlagsMask(categoryFlags);

            while (mask > 0)
            {
                yield return((CategoryFlags)((long)categoryFlags & mask));

                mask >>= 8;
            }

            yield return(CategoryFlags.undefined);
        }
예제 #14
0
        private static void CheckAddCategory(CategoryFlags categories, params string[] expectedCategories)
        {
            // Arrange
            var log = Log.LogEntry;

            // Act
            log.Categories(categories);

            foreach (var expectedCategory in expectedCategories)
            {
                // Assert
                Assert.IsTrue(log.CategoryStrings.Contains(expectedCategory), $"Category {expectedCategory} expected");
            }
        }
        protected ActiveModule(CategoryFlags ammoCategoryFlags, bool ranged = false)
        {
            IsRanged  = ranged;
            coreUsage = new ModuleProperty(this, AggregateField.core_usage);
            AddProperty(coreUsage);
            cycleTime = new CycleTimeProperty(this);
            AddProperty(cycleTime);

            if (ranged)
            {
                optimalRange = new OptimalRangeProperty(this);
                AddProperty(optimalRange);
                _falloff = new FalloffProperty(this);
                AddProperty(_falloff);
            }

            _ammoCategoryFlags = ammoCategoryFlags;
        }
예제 #16
0
        public void RemoveItemsByCategoryFlags(CategoryFlags categoryFlag, bool withVendor = false)
        {
            var definitions = _entityServices.Defaults.GetAll().GetDefinitionsByCategoryFlag(categoryFlag);

            var defArrayString = definitions.ArrayToString();

            var query = "SELECT marketitemid FROM dbo.marketitems WHERE itemdefinition IN (" + defArrayString + ") and isvendoritem=0";

            var orders = Db.Query().CommandText(query)
                         .Execute()
                         .Select(r => _marketOrderRepository.Get(r.GetValue <int>("marketitemid")))
                         .Where(o => o != null)
                         .ToArray();

            var count = 0;

            Logger.Info("cancelling " + orders.Length + " market items for cf:" + categoryFlag);

            foreach (var order in orders)
            {
                Logger.Info("cancelling " + order.EntityDefault.Name + " quantity:" + order.quantity);
                order.Cancel(_marketOrderRepository);
                count++;
            }

            Logger.Info("cancelled " + count + " market items for cf:" + categoryFlag);

            if (!withVendor)
            {
                return;
            }
            Logger.Info("removing vendor market items for cf:" + categoryFlag);

            query = "delete marketitems WHERE itemdefinition IN (" + defArrayString + ") and isvendoritem=1";
            count = Db.Query().CommandText(query).ExecuteNonQuery();

            Logger.Info("removed " + count + " vendor market items for cf:" + categoryFlag);
        }
예제 #17
0
        public void ScaleComponents(double scale, CategoryFlags componentCategoryFlag)
        {
            Logger.Info("scaling description: " + definition + " " + EntityDefault.Get(definition).Name);

            foreach (var component in Components)
            {
                //if not the defined category for example raw material
                var tmpFlag = EntityDefault.Get(component.EntityDefault.Definition).CategoryFlags;

                if ((tmpFlag & componentCategoryFlag.GetCategoryFlagsMask()) != componentCategoryFlag)
                {
                    Logger.Info("component skipped: " + component.EntityDefault.Definition + " " + EntityDefault.Get(component.EntityDefault.Definition).Name);
                    continue;
                }

                Db.Query().CommandText("update components set componentamount=@camount where definition=@definition and componentdefinition=@cdefinition")
                .SetParameter("@camount", (int)(component.Amount * scale))
                .SetParameter("@cdefinition", component.EntityDefault.Definition)
                .SetParameter("@definition", definition)
                .ExecuteNonQuery();

                Logger.Info("component " + component.EntityDefault.Definition + " scaled from: " + component.Amount + " to " + (int)(component.Amount * scale));
            }
        }
예제 #18
0
        /// <summary>
        /// The create categories base.
        /// </summary>
        /// <param name="boardId">
        /// The board id.
        /// </param>
        /// <param name="numForums">
        /// The num forums.
        /// </param>
        /// <param name="numTopics">
        /// The num topics.
        /// </param>
        /// <param name="numMessages">
        /// The num messages.
        /// </param>
        /// <param name="numCategories">
        /// The num categories.
        /// </param>
        /// <returns>
        /// The create categories base.
        /// </returns>
        private string CreateCategoriesBase(
            int boardId,
            int numForums,
            int numTopics,
            int numMessages,
            int numCategories)
        {
            int i;

            for (i = 0; i < numCategories; i++)
            {
                var catName = this.CategoryPrefixTB.Text.Trim() + Guid.NewGuid();

                var categoryFlags = new CategoryFlags {
                    IsActive = true
                };

                var newCategoryId = this.GetRepository <Category>().Save(null, catName, null, 100, categoryFlags, boardId);

                this.CreateForums(boardId, newCategoryId, null, numForums, numTopics, numMessages);
            }

            return($"{i} Categories, ");
        }
예제 #19
0
 public static bool IsAny(this CategoryFlags source, IEnumerable <CategoryFlags> targets)
 {
     return(targets.Any(target => IsCategory(source, target)));
 }
예제 #20
0
 protected GathererModule(CategoryFlags ammoCategoryFlags, bool ranged = false) : base(ammoCategoryFlags, ranged)
 {
     coreUsage.AddEffectModifier(AggregateField.effect_core_usage_gathering_modifier);
     cycleTime.AddEffectModifier(AggregateField.effect_gathering_cycle_time_modifier);
 }
 public CoreBoosterModule(CategoryFlags ammoCategoryFlags, bool ranged = false) : base(ammoCategoryFlags, ranged)
 {
 }
예제 #22
0
 public static IEnumerable <EntityDefault> GetByCategoryFlags(this IEnumerable <EntityDefault> entityDefaults, CategoryFlags categoryFlags)
 {
     return(entityDefaults.Where(ed => ed.CategoryFlags.IsCategory(categoryFlags)));
 }
예제 #23
0
 public static int[] GetDefinitionsByCategoryFlag(this IEnumerable <EntityDefault> entityDefaults, CategoryFlags categoryFlags)
 {
     return(entityDefaults.GetByCategoryFlags(categoryFlags).Select(ed => ed.Definition).ToArray());
 }
예제 #24
0
        private int GetCombinedDefinitionFromPools(MissionInProgress missionInProgress, CategoryFlags categoryFlags)
        {
            if (Type == MissionTargetType.lock_unit)
            {
                Log("intel document was generated.");
                return(EntityDefault.GetByName(DefinitionNames.MISSION_RND_INTEL_DOCUMENT).Definition);
            }

            if (Type == MissionTargetType.drill_mineral)
            {
                Log("mining proof was generated.");
                return(EntityDefault.GetByName(DefinitionNames.MISSION_RND_MINING_PROOF).Definition);
            }

            if (Type == MissionTargetType.harvest_plant)
            {
                Log("harvesting proof was generated.");
                return(EntityDefault.GetByName(DefinitionNames.MISSION_RND_HARVESTING_PROOF).Definition);
            }


            if (generateResearchKit)
            {
                Log("random research kit was generated.");
                return(EntityDefault.GetByName(DefinitionNames.MISSION_RND_RESEARCH_KIT).Definition);
            }

            if (generateCalibrationProgram)
            {
                return(GetCalibrationProgramFromPool(missionInProgress));
            }

            return(GetDefinitionFromMissionItemsPool(missionInProgress, categoryFlags));
        }
예제 #25
0
        private int GetDefinitionFromMissionItemsPool(MissionInProgress missionInProgress, CategoryFlags categoryFlags)
        {
            var possibleDefinitions = EntityDefault.All.GetByCategoryFlags(categoryFlags).Select(d => d.Definition).ToList();

            Log("possible mission item definitions:" + categoryFlags + " " + possibleDefinitions.Count);

            possibleDefinitions = possibleDefinitions.Except(missionInProgress.SelectedItemDefinitions).ToList();

            Log("except choosen: " + possibleDefinitions.Count);

            if (possibleDefinitions.Count == 0)
            {
                Logger.Error("no mission item definition to select from. " + this + " " + missionInProgress);
                throw new PerpetuumException(ErrorCodes.ConsistencyError);
            }

            var choosenDefinition = possibleDefinitions.RandomElement();

            missionInProgress.AddToSelectedItems(choosenDefinition);

            Log("selected item definition " + choosenDefinition);

            return(choosenDefinition);
        }
예제 #26
0
 public bool IsCategory(CategoryFlags targetCategoryFlags)
 {
     return(ED.CategoryFlags.IsCategory(targetCategoryFlags));
 }
 public TerraformMultiModule(CategoryFlags ammoCategoryFlags) : base(ammoCategoryFlags, true)
 {
 }
 public static IEnumerable <T> GetAllByCategoryFlags <T>(this IEnumerable <T> units, CategoryFlags cf) where T : Unit
 {
     return(units.Where(u => u.ED.CategoryFlags.IsCategory(cf)).ToArray());
 }
예제 #29
0
        public static bool IsCategory(this CategoryFlags sourceCategoryFlags, CategoryFlags targetCategoryFlags)
        {
            var mask = GetCategoryFlagsMask(targetCategoryFlags);

            return((sourceCategoryFlags & mask) == targetCategoryFlags);
        }
예제 #30
0
 public static bool IsCategoryExists(this CategoryFlags categoryFlags)
 {
     return(Enum.IsDefined(typeof(CategoryFlags), categoryFlags));
 }