Example #1
0
 public UnitDynamicsAttributesWrapper(UnitDynamicsAttributes other)
 {
     DriveType                = other.DriveType;
     Length                   = other.Length;
     Width                    = other.Width;
     MaxSpeed                 = other.MaxSpeed;
     ReverseFactor            = other.ReverseFactor;
     AccelerationTime         = other.AccelerationTime;
     BrakingTime              = other.BrakingTime;
     MaxSpeedTurnRadius       = other.MaxSpeedTurnRadius;
     MaxEaseIntoTurnTime      = other.MaxEaseIntoTurnTime;
     DriftType                = other.DriftType;
     ReverseDriftMultiplier   = other.ReverseDriftMultiplier;
     DriftOvershootFactor     = other.DriftOvershootFactor;
     FishTailingTimeIntervals = other.FishTailingTimeIntervals;
     FishTailControlRecover   = other.FishTailControlRecover;
     MinDriftSlipSpeed        = other.MinDriftSlipSpeed;
     MaxDriftRecoverTime      = other.MaxDriftRecoverTime;
     MinCruiseSpeed           = other.MinCruiseSpeed;
     DeathDriftTime           = other.DeathDriftTime;
     PermanentlyImmobile      = other.PermanentlyImmobile;
     CruiseSpeedVariation     = other.CruiseSpeedVariation?.ToArray();
     CruiseDirectionVariation = other.CruiseDirectionVariation?.ToArray();
 }
        // 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;
            }
        }