Example #1
0
    // Loads a map layout onto a map
    // Map layouts include spawn, artifact, resource and extraction zone locations
    // This function also removes certain aspects of the level that are already there e.g. wrecks
    public static void LoadMapLayout()
    {
        // No map loaded anymore
        MapXml     = "";
        LayoutName = "";

        Subsystem.AttributeLoader.PatchOverrideData = "";
        PatchName = "";

        if (CustomLayout)
        {
            // Move DoK engine objects
            foreach (Entity entity in Sim.Instance.EntitySystem)
            {
                if (entity.HasComponent(11))
                {
                    entity.GetComponent <Position>(10).Position2D = new Vector2r(Fixed64.FromInt(1000000), Fixed64.FromInt(1000000)); // Move off the map
                    entity.GetComponent <Resource>(11).Disabled   = true;                                                             // Make unminable, keeping these in just in case the AI tries to mine from these resources
                }
                else if (entity.HasComponent(36) || entity.HasComponent(14))
                {
                    entity.GetComponent <Position>(10).Position2D = new Vector2r(Fixed64.FromInt(1000000), Fixed64.FromInt(1000000));                    // Move off the map
                }
            }

            // Disable the pesky black box at the start of levels
            // Its there to be a transition from what I can tell
            GameObject blackBox = GameObject.Find("BlackPolygon");
            if (blackBox != null)
            {
                blackBox.transform.position = new Vector3(1000000.0f, 1000000.0f, 1000000.0f);
            }

            // Loading resource layout
            foreach (MapResourceData resource in resources)
            {
                DetectableAttributesData detectableAttributesData = new DetectableAttributesData()
                {
                    m_SetHasBeenSeenBeforeOnSpawn = true,
                };
                SceneEntityCreator.CreateResourcePoint((resource.type == 0) ? "Resource_CU" : "Resource_RU", resource.position, default(Orientation2), new string[0], new ResourceAttributesData((ResourceType)resource.type, resource.amount, resource.collectors), detectableAttributesData, false, default(ResourcePositionalVariations), false);
            }

            // Delete starting units of commanders with no starting fleet
            foreach (MapSpawnData spawn in spawns)
            {
                if (spawn.fleet)
                {
                    continue;
                }
                foreach (Commander commander in Sim.Instance.CommanderManager.Commanders)
                {
                    CommanderDirectorAttributes director = Sim.Instance.CommanderManager.GetCommanderDirectorFromID(commander.ID);
                    if (director.PlayerType == PlayerType.AI)
                    {
                        continue;                                                           // AI needs starting carrier
                    }
                    if (((GameMode == TeamSetting.Team) ? (1 - spawn.team) * 3 : spawn.team) + spawn.index == director.SpawnIndex)
                    {
                        foreach (Entity entity in Sim.Instance.EntitySystem.Query().Has(2))                           // All units
                        {
                            if (entity.GetComponent <OwningCommander>(5).ID == commander.ID)                          // Check if the faction is correct
                            {
                                entity.GetComponent <Unit>(2).RetireDespawn();
                            }
                        }
                    }
                }
            }

            // Loading units
            foreach (MapUnitData unit in units)
            {
                // Convert team + index to commander ID then spawn unit
                foreach (Commander commander in Sim.Instance.CommanderManager.Commanders)
                {
                    CommanderDirectorAttributes director = Sim.Instance.CommanderManager.GetCommanderDirectorFromID(commander.ID);
                    if (((GameMode == TeamSetting.Team) ? (1 - unit.team) * 3 : unit.team) + unit.index == director.SpawnIndex)
                    {
                        if (commander.CommanderAttributes.Name == "SPECTATOR")
                        {
                            continue;                             // Don't spawn units for spectators
                        }
                        else if (sobanUnits.Contains(unit.type) && commander.CommanderAttributes.Faction.ID != FactionID.Soban)
                        {
                            continue;                             // Don't spawn Soban units for non Soban players
                        }
                        else if (khaanUnits.Contains(unit.type) && commander.CommanderAttributes.Faction.ID != FactionID.Khaaneph)
                        {
                            continue;                             // Don't spawn Khaaneph units for non Khaaneph players
                        }
                        SceneEntityCreator.CreateEntity(unit.type, commander.ID, unit.position, unit.orientation);
                        break;
                    }
                }
            }

            // Loading wrecks
            foreach (MapWreckData wreck in wrecks)
            {
                DetectableAttributesData detectableAttributes = new DetectableAttributesData {
                    m_SetHasBeenSeenBeforeOnSpawn = true,
                };

                ResourcePositionalVariations positions = new ResourcePositionalVariations {
                    ModelOrientationEulersDegrees = new Vector3r(Fixed64.FromConstFloat(0.0f), Fixed64.FromConstFloat(wreck.angle), Fixed64.FromConstFloat(0.0f)),
                };

                ShapeAttributesData shape = new ShapeAttributesData {
                    m_Radius           = 100.0f,
                    m_BlocksLOF        = wreck.blockLof,
                    m_BlocksAllHeights = wreck.blockLof,
                };

                ResourceAttributesData res = new ResourceAttributesData {
                    m_ResourceType = ResourceType.Resource3,                     // Type = Wreck
                };

                SimWreckSectionResourceSpawnableAttributesData[] childResources = new SimWreckSectionResourceSpawnableAttributesData[wreck.resources.Count];
                for (int i = 0; i < wreck.resources.Count; i++)
                {
                    childResources[i] = new SimWreckSectionResourceSpawnableAttributesData {
                        m_DetectableAttributes         = new DetectableAttributesData(),
                        m_OverrideDetectableAttributes = true,
                        m_Tags = new string[0],
                        m_EntityTypeToSpawn                     = (wreck.resources[i].type == 1) ? "Resource_RU" : "Resource_CU",
                        m_ResourceAttributes                    = new ResourceAttributesData((ResourceType)wreck.resources[i].type, wreck.resources[i].amount, wreck.resources[i].collectors),
                        m_OverrideResourceAttributes            = true,
                        m_SpawnPositionOffsetFromSectionCenterX = Fixed64.IntValue((wreck.resources[i].position - wreck.position).X),
                        m_SpawnPositionOffsetFromSectionCenterY = Fixed64.IntValue((wreck.resources[i].position - wreck.position).Y),
                        m_UseNonRandomSpawnPositionOffset       = true,
                    };
                }

                SimWreckAttributesData wreckData = new SimWreckAttributesData {
                    m_WreckSections = new SimWreckSectionAttributesData[] {
                        new SimWreckSectionAttributesData {
                            m_ExplosionChance    = 100,
                            m_Health             = 1,
                            m_ResourceSpawnables = childResources,
                        },
                    },
                };

                // Orientation2.LocalForward -> (1.0, 0.0)
                SceneEntityCreator.CreateWreck("Resource_Wreck_MP", wreck.position, Orientation2.LocalForward, new string[0], wreckData, "", shape, res, detectableAttributes, false, positions, false);
            }
        }
    }
        // Token: 0x06000C55 RID: 3157 RVA: 0x00056FE4 File Offset: 0x000551E4
        private void UpdateDynamicDataForUnit(Entity entity)
        {
            UnitState unitState = ShipbreakersMain.CurrentSimFrame.FindObject <UnitState>(entity);

            if (unitState == null)
            {
                return;
            }
            if (this.mSelectedEntity.IsValid())
            {
                if (this.mLastUnitState == unitState)
                {
                    return;
                }
                if (this.mSettings.UnitHealthValueLabel == null || this.mSettings.UnitHealthBar == null || this.mSettings.UnitArmorValueLabel == null || this.mSettings.UnitFireRateLabel == null || this.mSettings.UnitDamageValueLabel == null || this.mSettings.SpeedValueLabel == null || this.mSettings.UnitShortDescriptionValueLabel == null)
                {
                    Log.Warn(Log.Channel.UI, "Information Panel: An information label was not configured correctly.  Check Unity Config.   Skipping Info Panel Update", new object[0]);
                    return;
                }
                string typeID = unitState.TypeID;
                bool   flag   = this.mLastUnitState == null || this.mLastUnitState.EntityID != this.mSelectedEntity;
                ExperienceViewAttributes entityTypeAttributes = ShipbreakersMain.GetEntityTypeAttributes <ExperienceViewAttributes>(typeID);
                if (entityTypeAttributes != null)
                {
                    ExperienceState experienceState = ShipbreakersMain.CurrentSimFrame.FindObject <ExperienceState>(entity);
                    if (experienceState != null && experienceState.Level > 0 && (flag || this.mLastExperienceState == null || this.mLastExperienceState.Level != experienceState.Level))
                    {
                        if (!string.IsNullOrEmpty(experienceState.NameSuffix))
                        {
                            RankViewAttributes rankViewAttributes = entityTypeAttributes.RankViews[experienceState.Level];
                            this.mTempLocalizationFormatObjects[0]             = rankViewAttributes.ShortRankName;
                            this.mTempLocalizationFormatObjects[1]             = experienceState.NameSuffix;
                            this.mSettings.UnitShortDescriptionValueLabel.text = this.mSettings.UnitLevelFormat.TokenFormat(this.mTempLocalizationFormatObjects, this.mLocMan);
                        }
                        this.mLastExperienceState = experienceState;
                    }
                }
                if (flag || unitState.OwnerCommander != this.mLastUnitState.OwnerCommander)
                {
                    Commander commanderFromID = this.mCommanderManager.GetCommanderFromID(unitState.OwnerCommander);
                    CommanderDirectorAttributes commanderDirectorFromID = this.mCommanderManager.GetCommanderDirectorFromID(unitState.OwnerCommander);
                    this.mTempLocalizationFormatObjects[0] = ((commanderFromID != null) ? SharedLocIDConstants.GetLocalizedCommanderName(commanderDirectorFromID.PlayerType, commanderFromID.Name, commanderDirectorFromID.AIDifficulty) : string.Empty);
                    this.mTempLocalizationFormatObjects[1] = null;
                    this.mSettings.PlayerNameLabel.text    = this.mSettings.PlayerNameLocID.TokenFormat(this.mTempLocalizationFormatObjects, this.mLocMan);
                }
                UnitAttributes typeAttributes = this.mSelectedEntity.GetTypeAttributes <UnitAttributes>();
                if (typeAttributes == null)
                {
                    Log.Warn(Log.Channel.UI, "Information Panel: Attribute data was missing for unit type {0}. Skipping info panel update", new object[]
                    {
                        this.mSelectedEntity.ToFriendlyString()
                    });
                    return;
                }
                UnitAttributes entityTypeAttributes2 = ShipbreakersMain.GetEntityTypeAttributes <UnitAttributes>(typeID);
                if (entityTypeAttributes2 == null)
                {
                    Log.Error(Log.Channel.Data | Log.Channel.UI, "Failed to find base UnitAttributes for entity type {0}", new object[]
                    {
                        typeID
                    });
                }
                if (flag || unitState.Hitpoints != this.mLastUnitState.Hitpoints)
                {
                    this.mTempLocalizationFormatObjects[0]   = unitState.Hitpoints;
                    this.mTempLocalizationFormatObjects[1]   = unitState.MaxHitpoints;
                    this.mSettings.UnitHealthValueLabel.text = ((unitState.MaxHitpoints > 0) ? this.mSettings.UnitHealthFormat.TokenFormat(this.mTempLocalizationFormatObjects, this.mLocMan) : string.Empty);
                    this.mSettings.UnitHealthBar.value       = ((unitState.MaxHitpoints > 0) ? ((float)unitState.Hitpoints / (float)unitState.MaxHitpoints) : 0f);
                    int buffComparison = 0;
                    if (entityTypeAttributes2 != null)
                    {
                        buffComparison = unitState.MaxHitpoints.CompareTo(entityTypeAttributes2.MaxHealth);
                    }
                    this.mSettings.UnitHealthValueLabel.color = this.mUnitInteractionAttributes.BuffInfo.BuffColor(buffComparison);
                }
                this.mSelectedEntity.GetTypeAttributes <UnitMovementAttributes>();
                int num = Fixed64.IntValue(unitState.MaxSpeed);
                if (flag || num != Fixed64.IntValue(this.mLastUnitState.MaxSpeed))
                {
                    this.mTempLocalizationFormatObjects[0] = num;
                    this.mTempLocalizationFormatObjects[1] = null;
                    this.mSettings.SpeedValueLabel.text    = this.mSettings.UnitSpeedFormat.TokenFormat(this.mTempLocalizationFormatObjects, this.mLocMan);
                    int buffComparison2 = 0;
                    UnitMovementAttributes entityTypeAttributes3  = ShipbreakersMain.GetEntityTypeAttributes <UnitMovementAttributes>(typeID);
                    UnitDynamicsAttributes unitDynamicsAttributes = (entityTypeAttributes3 != null) ? entityTypeAttributes3.Dynamics : null;
                    if (unitDynamicsAttributes != null)
                    {
                        buffComparison2 = unitState.MaxSpeed.CompareTo(unitDynamicsAttributes.MaxSpeed);
                    }
                    else
                    {
                        Log.Error(Log.Channel.Data | Log.Channel.UI, "Failed to find base UnitDynamicsAttributes for entity type {0}", new object[]
                        {
                            typeID
                        });
                    }
                    this.mSettings.SpeedValueLabel.color = this.mUnitInteractionAttributes.BuffInfo.BuffColor(buffComparison2);
                }
                int buffComparison3 = 0;
                // MOD
                int baseDamagePerRound   = 0;
                int damagePacketsPerShot = 1;
                // MOD
                if (!typeAttributes.WeaponLoadout.IsNullOrEmpty <WeaponBinding>())
                {
                    WeaponBinding weaponBinding = typeAttributes.WeaponLoadout[0];
                    if (weaponBinding != null)
                    {
                        // MOD
                        damagePacketsPerShot = weaponBinding.Weapon.DamagePacketsPerShot;
                        baseDamagePerRound   = Fixed64.IntValue(weaponBinding.Weapon.BaseDamagePerRound);
                        WeaponAttributes entityTypeAttributes4 = ShipbreakersMain.GetEntityTypeAttributes <WeaponAttributes>(typeID, weaponBinding.Weapon.Name);
                        if (entityTypeAttributes4 != null)
                        {
                            buffComparison3 = baseDamagePerRound.CompareTo(Fixed64.IntValue(entityTypeAttributes4.BaseDamagePerRound));
                        }
                        else
                        {
                            Log.Error(Log.Channel.Data | Log.Channel.UI, "Failed to find base WeaponAttributes with name {0} for entity type {1}", new object[]
                            {
                                weaponBinding.Weapon.Name,
                                typeID
                            });
                        }
                        // MOD
                    }
                    else
                    {
                        Log.Error(Log.Channel.Data | Log.Channel.UI, "First WeaponBinding in WeaponLoadout for unit type {0} is null! Unable to determine damage to show on info panel", new object[]
                        {
                            typeID
                        });
                    }
                }
                // MOD
                if (flag || this.mLastWeaponDamageValue != baseDamagePerRound || this.mLastWeaponPacketsValue != damagePacketsPerShot)
                {
                    this.mSettings.UnitDamageValueLabel.text = damagePacketsPerShot != 1 ? string.Format("{0} | {1}", baseDamagePerRound, damagePacketsPerShot) : string.Format("{0}", baseDamagePerRound);
                    this.mLastWeaponDamageValue  = baseDamagePerRound;
                    this.mLastWeaponPacketsValue = damagePacketsPerShot;
                    this.mSettings.UnitDamageValueLabel.color = this.mUnitInteractionAttributes.BuffInfo.BuffColor(buffComparison3);
                }
                // MOD
                if (flag || this.mLastUnitArmourValue != typeAttributes.Armour)
                {
                    this.mTempLocalizationFormatObjects[0]  = typeAttributes.Armour;
                    this.mTempLocalizationFormatObjects[1]  = null;
                    this.mSettings.UnitArmorValueLabel.text = this.mSettings.UnitArmorFormat.TokenFormat(this.mTempLocalizationFormatObjects, this.mLocMan);
                    this.mLastUnitArmourValue = typeAttributes.Armour;
                    int buffComparison4 = 0;
                    if (entityTypeAttributes2 != null)
                    {
                        buffComparison4 = typeAttributes.Armour.CompareTo(entityTypeAttributes2.Armour);
                    }
                    this.mSettings.UnitArmorValueLabel.color = this.mUnitInteractionAttributes.BuffInfo.BuffColor(buffComparison4);
                }
                if (flag || this.mLastFireRateDisplay != typeAttributes.FireRateDisplay)
                {
                    this.mTempLocalizationFormatObjects[0] = InformationPanelController.InformationPanelSettings.FireRateLocIDs[typeAttributes.FireRateDisplay];
                    this.mTempLocalizationFormatObjects[1] = null;
                    this.mSettings.UnitFireRateLabel.text  = this.mSettings.UnitFireRateFormat.TokenFormat(this.mTempLocalizationFormatObjects, this.mLocMan);
                    this.mLastFireRateDisplay = typeAttributes.FireRateDisplay;
                    int buffComparison5 = 0;
                    if (entityTypeAttributes2 != null)
                    {
                        buffComparison5 = typeAttributes.FireRateDisplay.CompareTo(entityTypeAttributes2.FireRateDisplay);
                    }
                    this.mSettings.UnitFireRateLabel.color = this.mUnitInteractionAttributes.BuffInfo.BuffColor(buffComparison5);
                }
                this.mLastUnitState = unitState;
            }
        }