public WeaponDefinitionExpanded(MyWeaponDefinition weaponDefn) { this.WeaponDefinition = weaponDefn; for (int i = 0; i < weaponDefn.WeaponAmmoDatas.Length; i++) { if (weaponDefn.WeaponAmmoDatas[i] != null) { AmmoType = (MyAmmoType)i; FirstAmmo = Ammo.GetAmmo(WeaponDefinition.AmmoMagazinesId[0]); RequiredAccuracy = (float)Math.Cos(0.02f + Math.Min(weaponDefn.WeaponAmmoDatas[i].RateOfFire, 1000) / 72000f); return; } } AmmoType = MyAmmoType.Unknown; RequiredAccuracy = 2f; }
public static Ammo GetAmmo(MyDefinitionId magazineId) { Ammo value; if (KnownDefinitions_Ammo.TryGetValue(magazineId, out value)) { return(value); } MyAmmoMagazineDefinition magDef = MyDefinitionManager.Static.GetAmmoMagazineDefinition(magazineId); if (magDef == null) { throw new InvalidOperationException("not a magazine: " + magazineId); } value = new Ammo(magDef); KnownDefinitions_Ammo.Add(magazineId, value); return(value); }
private WeaponDefinitionExpanded(MyWeaponDefinition weaponDefn) { this.WeaponDefinition = weaponDefn; for (int i = 0; i < weaponDefn.WeaponAmmoDatas.Length; i++) { if (weaponDefn.WeaponAmmoDatas[i] != null) { AmmoType = (MyAmmoType)i; FirstAmmo = Ammo.GetAmmo(WeaponDefinition.AmmoMagazinesId[0]); RequiredAccuracyRadians = FirstAmmo.Description != null ? 0.15f : // fire guided missile with less accuracy, despite slower RoF 0.02f + Math.Min(weaponDefn.WeaponAmmoDatas[i].RateOfFire, 1000) / 72000f; RequiredAccuracyCos = (float)Math.Cos(RequiredAccuracyRadians); return; } } AmmoType = MyAmmoType.Unknown; RequiredAccuracyCos = 2f; }
public static Ammo GetLoadedAmmo(IMyCubeBlock weapon) { var invOwn = (weapon as IMyInventoryOwner); if (invOwn == null) throw new InvalidOperationException("not an IMyInventoryOwner: " + weapon.getBestName()); var inv = invOwn.GetInventory(0).GetItems(); if (inv.Count == 0) return null; Ammo value; MyDefinitionId magazineId = inv[0].Content.GetId(); if (KnownDefinitions_Ammo.TryGetValue(magazineId, out value)) return value; MyAmmoMagazineDefinition magDef = MyDefinitionManager.Static.GetAmmoMagazineDefinition(magazineId); if (magDef == null) throw new InvalidOperationException("inventory contains item that is not a magazine: " + weapon.getBestName()); value = new Ammo(magDef); KnownDefinitions_Ammo.Add(magazineId, value); return value; }
private void UpdateAmmo() { Ammo newAmmo = Ammo.GetLoadedAmmo(CubeBlock); if (newAmmo != null && newAmmo != LoadedAmmo) { LoadedAmmo = newAmmo; myLogger.debugLog("loaded ammo: " + LoadedAmmo.AmmoDefinition, "UpdateLoadedMissile()"); } }
public static Ammo GetAmmo(MyDefinitionId magazineId) { Ammo value; if (KnownDefinitions_Ammo.TryGetValue(magazineId, out value)) return value; MyAmmoMagazineDefinition magDef = MyDefinitionManager.Static.GetAmmoMagazineDefinition(magazineId); if (magDef == null) throw new InvalidOperationException("not a magazine: " + magazineId); value = new Ammo(magDef); KnownDefinitions_Ammo.Add(magazineId, value); return value; }