Exemple #1
0
            /// <summary>
            /// Constructs a MissileDataWrapper instance for the given missile data.
            /// </summary>
            /// <param name="weaponDataUpgrade">The weapon data upgrade instance that this missile data wrapper belongs to.</param>
            /// <param name="originalMissileData">The wrapped missile data.</param>
            public MissileDataWrapper(WeaponDataUpgrade weaponDataUpgrade, IMissileData originalMissileData)
            {
                if (weaponDataUpgrade == null)
                {
                    throw new ArgumentNullException("weaponDataUpgrade");
                }
                if (originalMissileData == null)
                {
                    throw new ArgumentNullException("originalMissileData");
                }

                this.missileType         = new IMissileType(weaponDataUpgrade.metadataUpgrade.GetElementTypeUpgradeImpl(originalMissileData.MissileType.Name));
                this.originalMissileData = originalMissileData;
            }
Exemple #2
0
        /// <summary>
        /// Resets this instance.
        /// </summary>
        internal void Reset()
        {
            this.originalElementType  = null;
            this.originalAddonType    = null;
            this.originalBuildingType = null;
            this.originalMissileType  = null;
            this.originalUnitType     = null;
            this.originalUpgradeType  = null;
            this.originalUpgradeIface = null;

            this.armorModifier.AttachModifiedValue(null);
            this.maxEnergyModifier.AttachModifiedValue(null);
            this.sightRangeModifier.AttachModifiedValue(null);
            this.speedModifier.AttachModifiedValue(null);

            if (this.metadataUpgrade.AttachedMetadata != null)
            {
                IScenarioMetadata metadata = this.metadataUpgrade.AttachedMetadata;
                if (metadata.HasCustomType(this.elementTypeName))
                {
                    this.originalElementType = metadata.GetCustomType(this.elementTypeName).ElementTypeImpl;
                }
                else if (metadata.HasAddonType(this.elementTypeName))
                {
                    this.originalElementType = this.originalAddonType = metadata.GetAddonType(this.elementTypeName).AddonTypeImpl;
                }
                else if (metadata.HasBuildingType(this.elementTypeName))
                {
                    this.originalElementType = this.originalBuildingType = metadata.GetBuildingType(this.elementTypeName).BuildingTypeImpl;
                }
                else if (metadata.HasMissileType(this.elementTypeName))
                {
                    this.originalElementType = this.originalMissileType = metadata.GetMissileType(this.elementTypeName).MissileTypeImpl;
                }
                else if (metadata.HasUnitType(this.elementTypeName))
                {
                    this.originalElementType = this.originalUnitType = metadata.GetUnitType(this.elementTypeName).UnitTypeImpl;
                }
                else if (metadata.HasUpgradeType(this.elementTypeName))
                {
                    this.originalElementType = this.originalUpgradeType = metadata.GetUpgradeType(this.elementTypeName).UpgradeTypeImpl;
                }
                else
                {
                    throw new InvalidOperationException(string.Format("Scenario element type '{0}' is not defined in the metadata!", this.elementTypeName));
                }

                this.originalUpgradeIface = this.originalElementType as IScenarioElementTypeUpgrade;

                this.armorModifier.AttachModifiedValue(this.originalElementType.Armor);
                this.maxEnergyModifier.AttachModifiedValue(this.originalElementType.MaxEnergy);
                this.sightRangeModifier.AttachModifiedValue(this.originalElementType.SightRange);
                this.speedModifier.AttachModifiedValue(this.originalElementType.Speed);

                if (this.standardWeaponDataUpgrades == null && this.customWeaponDataUpgrades == null)
                {
                    /// First time attach -> create the weapon data upgrades.
                    this.standardWeaponDataUpgrades       = new List <WeaponDataUpgrade>();
                    this.standardWeaponDataUpgradesByName = new Dictionary <string, WeaponDataUpgrade>();
                    this.customWeaponDataUpgrades         = new List <WeaponDataUpgrade>();
                    this.customWeaponDataUpgradesByName   = new Dictionary <string, WeaponDataUpgrade>();

                    foreach (IWeaponData standardWeaponData in this.originalElementType.StandardWeapons)
                    {
                        WeaponDataUpgrade standardWeaponUpgrade = new WeaponDataUpgrade(this.metadataUpgrade, standardWeaponData);
                        this.standardWeaponDataUpgrades.Add(standardWeaponUpgrade);
                        this.standardWeaponDataUpgradesByName.Add(standardWeaponData.Name, standardWeaponUpgrade);
                    }

                    foreach (IWeaponData customWeaponData in this.originalElementType.CustomWeapons)
                    {
                        WeaponDataUpgrade customWeaponUpgrade = new WeaponDataUpgrade(this.metadataUpgrade, customWeaponData);
                        this.customWeaponDataUpgrades.Add(customWeaponUpgrade);
                        this.customWeaponDataUpgradesByName.Add(customWeaponData.Name, customWeaponUpgrade);
                    }
                }
                else
                {
                    /// Reattach -> check the compatibility of the existing weapon data upgrades and reset them.
                    if (this.standardWeaponDataUpgrades.Count != this.originalElementType.StandardWeapons.Count())
                    {
                        throw new InvalidOperationException("Unable to attach non-compatible scenario element type!");
                    }
                    if (this.customWeaponDataUpgrades.Count != this.originalElementType.CustomWeapons.Count())
                    {
                        throw new InvalidOperationException("Unable to attach non-compatible scenario element type!");
                    }

                    foreach (IWeaponData standardWeaponData in this.originalElementType.StandardWeapons)
                    {
                        if (!this.standardWeaponDataUpgradesByName.ContainsKey(standardWeaponData.Name))
                        {
                            throw new InvalidOperationException("Unable to attach non-compatible scenario element type!");
                        }
                        this.standardWeaponDataUpgradesByName[standardWeaponData.Name].Reset(standardWeaponData);
                    }

                    foreach (IWeaponData customWeaponData in this.originalElementType.CustomWeapons)
                    {
                        if (!this.customWeaponDataUpgradesByName.ContainsKey(customWeaponData.Name))
                        {
                            throw new InvalidOperationException("Unable to attach non-compatible scenario element type!");
                        }
                        this.customWeaponDataUpgradesByName[customWeaponData.Name].Reset(customWeaponData);
                    }
                }
            }
        }