Пример #1
0
    public void RemoveEffectFromUnits(MapBoostDefinition definition, Unit[] units, global::Empire empire)
    {
        List <SimulationDescriptorReference> list = new List <SimulationDescriptorReference>();

        definition.GetValidDescriptors(empire, out list);
        if (list != null)
        {
            for (int i = 0; i < list.Count; i++)
            {
                SimulationDescriptor simulationDescriptor;
                if (this.simulationDescriptorsDatabase.TryGetValue(list[i].Name, out simulationDescriptor))
                {
                    for (int j = 0; j < units.Length; j++)
                    {
                        if (units[j] != null)
                        {
                            units[j].RemoveMapBoost(definition.Name, simulationDescriptor);
                            if (units[j].AppliedBoosts.Count <= 0)
                            {
                                units[j].HasMapBoost = false;
                            }
                        }
                    }
                }
            }
        }
    }
Пример #2
0
    private void AddEffectsToUnits(MapBoostDefinition definition, Unit[] units, global::Empire empire)
    {
        List <MapBoostEffect> list = new List <MapBoostEffect>();

        definition.GetValidEffects(empire, out list);
        if (list != null)
        {
            for (int i = 0; i < units.Length; i++)
            {
                for (int j = 0; j < list.Count; j++)
                {
                    SimulationDescriptorReference[] simulationDescriptorReferences = list[j].SimulationDescriptorReferences;
                    for (int k = 0; k < simulationDescriptorReferences.Length; k++)
                    {
                        SimulationDescriptor simulationDescriptor;
                        if (this.simulationDescriptorsDatabase.TryGetValue(simulationDescriptorReferences[k].Name, out simulationDescriptor) && !units[i].SimulationObject.Tags.Contains(simulationDescriptor.Name))
                        {
                            units[i].AddMapBoost(definition.Name, simulationDescriptor);
                            units[i].HasMapBoost = true;
                        }
                    }
                    if (list[j].ExperienceReward > 0f)
                    {
                        units[i].GainXp(list[j].ExperienceReward, false, true);
                    }
                }
            }
        }
    }
Пример #3
0
    protected MapBoost AddMapBoost(GameEntityGUID guid, MapBoostDefinition mapBoostDefinition, WorldPosition position)
    {
        MapBoost mapBoost = new MapBoost(guid, position, mapBoostDefinition, this);

        this.Register(mapBoost);
        this.worldPositionSimulationEvaluatorService.SetSomethingChangedOnRegion(this.worldPositionService.GetRegionIndex(mapBoost.WorldPosition));
        return(mapBoost);
    }
Пример #4
0
    public void DistributeMapBoosts()
    {
        List <WorldPosition> list  = new List <WorldPosition>();
        List <string>        list2 = new List <string>();
        List <int>           list3 = new List <int>();
        float value = Amplitude.Unity.Runtime.Runtime.Registry.GetValue <float>(this.mapBoostPerTile, 0.3f);
        int   num   = (int)((float)(base.Game.World.WorldParameters.Rows * base.Game.World.WorldParameters.Columns) * value);
        int   num2  = 0;

        for (int i = 0; i < base.Game.World.Regions.Length; i++)
        {
            List <WorldPosition> regionSpawns = this.GetRegionSpawns(base.Game.World.Regions[i]);
            int regionAttractiveness          = this.GetRegionAttractiveness(regionSpawns);
            if (this.OverallAttractiveness > 0)
            {
                num2 = num * regionAttractiveness / this.OverallAttractiveness;
            }
            else
            {
                Diagnostics.LogWarning("overall attractiveness is equal to zero 0, it should not be.");
            }
            for (int j = 0; j < num2; j++)
            {
                int num3 = UnityEngine.Random.Range(0, regionAttractiveness);
                for (int k = 0; k < regionSpawns.Count; k++)
                {
                    if (!list.Contains(regionSpawns[k]))
                    {
                        num3 -= (int)this.attractivenessMap.GetValue(regionSpawns[k]);
                        if (num3 < 0)
                        {
                            MapBoostDefinition randomDefinitionForPosition = this.GetRandomDefinitionForPosition(regionSpawns[k]);
                            if (randomDefinitionForPosition != null)
                            {
                                list.Add(regionSpawns[k]);
                                list2.Add(randomDefinitionForPosition.XmlSerializableName);
                                break;
                            }
                        }
                    }
                }
            }
        }
        OrderSpawnMapBoosts order = new OrderSpawnMapBoosts(list.ToArray(), list2.ToArray());

        this.PlayerController.PostOrder(order);
    }
Пример #5
0
    public void ApplyBoostToArmy(Army army, MapBoost boost)
    {
        if (!boost.IsBuffAvailable)
        {
            return;
        }
        boost.IsBuffAvailable = false;
        MapBoostDefinition mapBoostDefinition = boost.MapBoostDefinition;

        Unit[] array = army.Units.ToArray <Unit>();
        this.AddEffectsToUnits(mapBoostDefinition, array, army.Empire);
        boost.AffectedUnits       = array;
        boost.AffectedEmpireIndex = army.Empire.Index;
        boost.CreateAffectedUnitsData();
        army.CheckMapBoostOnUnits();
        this.eventService.Notify(new EventMapBoostApplied(army.Empire, army.GUID, boost.MapBoostDefinition));
    }
Пример #6
0
 private bool GetTerrainCompatibilityAtPosition(MapBoostDefinition mapBoostDefinition, WorldPosition worldPosition)
 {
     if (mapBoostDefinition.TerrainTypeMappings != null && mapBoostDefinition.TerrainTypeMappings.Length > 0)
     {
         byte         terrainType            = this.worldPositionService.GetTerrainType(worldPosition);
         StaticString terrainTypeMappingName = this.worldPositionService.GetTerrainTypeMappingName(terrainType);
         bool         flag = false;
         for (int i = 0; i < mapBoostDefinition.TerrainTypeMappings.Length; i++)
         {
             if (terrainTypeMappingName.Equals(mapBoostDefinition.TerrainTypeMappings[i]))
             {
                 flag = true;
                 break;
             }
         }
         if (!flag)
         {
             return(false);
         }
     }
     return(this.pathfindingService.IsTileStopable(worldPosition, PathfindingMovementCapacity.All, (PathfindingFlags)0));
 }
Пример #7
0
    public void AddMapBoosts(GameEntityGUID[] GUIDs, string[] mapBoostDefinitionNames, WorldPosition[] positions)
    {
        if (positions.Length != GUIDs.Length || positions.Length != mapBoostDefinitionNames.Length)
        {
            return;
        }
        IDatabase <MapBoostDefinition> database = Databases.GetDatabase <MapBoostDefinition>(false);

        for (int i = 0; i < positions.Length; i++)
        {
            MapBoostDefinition mapBoostDefinition = null;
            if (!database.TryGetValue(mapBoostDefinitionNames[i], out mapBoostDefinition))
            {
                Diagnostics.LogError("MapBoostManager::AddMapBoosts  Boost definition could not be found");
            }
            else
            {
                this.AddMapBoost(GUIDs[i], mapBoostDefinition, positions[i]);
            }
        }
        this.CheckArmiesOverMapBoostAfterDistribution();
    }