Beispiel #1
0
        private Ammo(MyAmmoMagazineDefinition ammoMagDef)
        {
            MyAmmoDefinition ammoDef = MyDefinitionManager.Static.GetAmmoDefinition(ammoMagDef.AmmoDefinitionId);
            this.myLogger = new Logger("Ammo", () => ammoMagDef.Id.ToString(), () => ammoDef.Id.ToString());

            this.AmmoDefinition = ammoDef;
            this.MissileDefinition = AmmoDefinition as MyMissileAmmoDefinition;
            this.MagazineDefinition = ammoMagDef;

            if (MissileDefinition != null && !MissileDefinition.MissileSkipAcceleration)
            {
                this.TimeToMaxSpeed = (MissileDefinition.DesiredSpeed - MissileDefinition.MissileInitialSpeed) / MissileDefinition.MissileAcceleration;
                this.DistanceToMaxSpeed = (MissileDefinition.DesiredSpeed + MissileDefinition.MissileInitialSpeed) / 2 * TimeToMaxSpeed;
            }
            else
            {
                this.TimeToMaxSpeed = 0;
                this.DistanceToMaxSpeed = 0;
            }

            Description = AmmoDescription.CreateFrom(AmmoDefinition);

            if (Description == null)
                return;

            if (Description.ClusterCooldown > 0f)
            {
                myLogger.debugLog("Is a cluster missile");
                IsCluster = true;
            }
            if (!string.IsNullOrWhiteSpace(Description.Radar))
            {
                try
                {
                    RadarDefinition = new RadarEquipment.Definition();
                    XML_Amendments<RadarEquipment.Definition> ammender = new XML_Amendments<RadarEquipment.Definition>(RadarDefinition);
                    ammender.primarySeparator = new char[] { ',' };
                    ammender.AmendAll(Description.Radar, true);
                    RadarDefinition = ammender.Deserialize();
                    myLogger.debugLog("Loaded description for radar", Logger.severity.DEBUG);
                }
                catch (Exception ex)
                {
                    Logger.debugNotify("Failed to load radar description for an ammo", 10000, Logger.severity.ERROR);
                    myLogger.alwaysLog("Failed to load radar description for an ammo", Logger.severity.ERROR);
                    myLogger.alwaysLog("Exception: " + ex, Logger.severity.ERROR);
                    RadarDefinition = null;
                }
            }
        }
Beispiel #2
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);
            MyObjectBuilder_WeaponDefinition definition = builder as MyObjectBuilder_WeaponDefinition;

            this.WeaponAmmoDatas = new MyWeaponAmmoData[Enum.GetValues(typeof(MyAmmoType)).Length];
            this.WeaponEffects   = new MyWeaponEffect[(definition.Effects == null) ? 0 : definition.Effects.Length];
            if (definition.Effects != null)
            {
                for (int j = 0; j < definition.Effects.Length; j++)
                {
                    this.WeaponEffects[j] = new MyWeaponEffect(definition.Effects[j].Action, definition.Effects[j].Dummy, definition.Effects[j].Particle, definition.Effects[j].Loop, definition.Effects[j].InstantStop);
                }
            }
            this.PhysicalMaterial      = MyStringHash.GetOrCompute(definition.PhysicalMaterial);
            this.UseDefaultMuzzleFlash = definition.UseDefaultMuzzleFlash;
            this.NoAmmoSound           = new MySoundPair(definition.NoAmmoSoundName, true);
            this.ReloadSound           = new MySoundPair(definition.ReloadSoundName, true);
            this.SecondarySound        = new MySoundPair(definition.SecondarySoundName, true);
            this.DeviateShotAngle      = MathHelper.ToRadians(definition.DeviateShotAngle);
            this.ReleaseTimeAfterFire  = definition.ReleaseTimeAfterFire;
            this.MuzzleFlashLifeSpan   = definition.MuzzleFlashLifeSpan;
            this.ReloadTime            = definition.ReloadTime;
            this.DamageMultiplier      = definition.DamageMultiplier;
            this.RangeMultiplier       = definition.RangeMultiplier;
            this.UseRandomizedRange    = definition.UseRandomizedRange;
            this.AmmoMagazinesId       = new MyDefinitionId[definition.AmmoMagazines.Length];
            for (int i = 0; i < this.AmmoMagazinesId.Length; i++)
            {
                MyObjectBuilder_WeaponDefinition.WeaponAmmoMagazine magazine = definition.AmmoMagazines[i];
                this.AmmoMagazinesId[i] = new MyDefinitionId(magazine.Type, magazine.Subtype);
                MyAmmoMagazineDefinition ammoMagazineDefinition = MyDefinitionManager.Static.GetAmmoMagazineDefinition(this.AmmoMagazinesId[i]);
                MyAmmoType ammoType = MyDefinitionManager.Static.GetAmmoDefinition(ammoMagazineDefinition.AmmoDefinitionId).AmmoType;
                string     str      = null;
                if (ammoType == MyAmmoType.HighSpeed)
                {
                    if (definition.ProjectileAmmoData != null)
                    {
                        this.WeaponAmmoDatas[0] = new MyWeaponAmmoData(definition.ProjectileAmmoData);
                    }
                    else
                    {
                        str = string.Format(ErrorMessageTemplate, "projectile", "Projectile");
                    }
                }
                else
                {
                    if (ammoType != MyAmmoType.Missile)
                    {
                        throw new NotImplementedException();
                    }
                    if (definition.MissileAmmoData != null)
                    {
                        this.WeaponAmmoDatas[1] = new MyWeaponAmmoData(definition.MissileAmmoData);
                    }
                    else
                    {
                        str = string.Format(ErrorMessageTemplate, "missile", "Missile");
                    }
                }
                if (!string.IsNullOrEmpty(str))
                {
                    MyDefinitionErrors.Add(base.Context, str, TErrorSeverity.Critical, true);
                }
            }
        }
Beispiel #3
0
		private Ammo(MyAmmoMagazineDefinition ammoMagDef)
		{
			MyAmmoDefinition ammoDef = MyDefinitionManager.Static.GetAmmoDefinition(ammoMagDef.AmmoDefinitionId);
			this.myLogger = new Logger("Ammo", () => ammoMagDef.Id.ToString(), () => ammoDef.Id.ToString());

			this.AmmoDefinition = ammoDef;
			this.MissileDefinition = AmmoDefinition as MyMissileAmmoDefinition;
			this.MagazineDefinition = ammoMagDef;

			if (MissileDefinition != null && !MissileDefinition.MissileSkipAcceleration)
			{
				this.TimeToMaxSpeed = (MissileDefinition.DesiredSpeed - MissileDefinition.MissileInitialSpeed) / MissileDefinition.MissileAcceleration;
				this.DistanceToMaxSpeed = (MissileDefinition.DesiredSpeed + MissileDefinition.MissileInitialSpeed) / 2 * TimeToMaxSpeed;
			}
			else
			{
				this.TimeToMaxSpeed = 0;
				this.DistanceToMaxSpeed = 0;
			}

			Description = AmmoDescription.CreateFrom(AmmoDefinition);

			if (Description == null)
				return;

			#region Check Cluster

			//if (Description.ClusterSplitRange < 1 || Description.ClusterCooldown < 1) // if any value is bad
			//{
			//	if (Description.ClusterSplitRange >= 1 || Description.ClusterCooldown >= 1) // if any value is good
			//	{
			//		Logger.debugNotify("Cluster description is incomplete", 10000, Logger.severity.ERROR);
			//		//myLogger.alwaysLog("Cluster description is incomplete: " + Description.ClusterSplitRange + ", " + Description.ClusterSpread + ", " + Description.ClusterCooldown, "VerifyCluster()", Logger.severity.ERROR);
			//	}
			//	return;
			//}

			if (Description.ClusterCooldown < 1)
				return;

			// BuildOffsets
			// ClusterOffset_Back can be +/-
			//Description.ClusterOffset_Radial = MathHelper.Max(Description.ClusterOffset_Radial, 0f);
			//Description.ClusterFormDistance = MathHelper.Max(Description.ClusterFormDistance, 1f);
			//ClusterOffsets = new Vector3[ammoMagDef.Capacity - 1];
			//float radius = ClusterOffsets.Length / MathHelper.TwoPi * Description.ClusterOffset_Radial;
			//float angle = MathHelper.TwoPi / ClusterOffsets.Length;

			//for (int i = 0; i < ClusterOffsets.Length; i++)
			//{
			//	float partAngle = angle * i;
			//	float right = (float)Math.Sin(partAngle) * radius;
			//	float up = (float)Math.Cos(partAngle) * radius;
			//	ClusterOffsets[i] = new Vector3(right, up, Description.ClusterOffset_Back);
			//}

			myLogger.debugLog("Is a cluster missile", "VerifyCluster()");
			IsCluster = true;

			#endregion
		}