/// <summary> /// Adds weapon. First try find first empty preferred slot and then try find first empty slot /// </summary> /// <param name="weaponObjectBuilder">Weapon's object builder</param> public MySmallShipGunBase AddWeapon(MyMwcObjectBuilder_SmallShip_Weapon weaponObjectBuilder) { if (!MySession.Is25DSector) { if (weaponObjectBuilder.WeaponType == MyMwcObjectBuilder_SmallShip_Weapon_TypesEnum.Drilling_Device_Nuclear) { weaponObjectBuilder.WeaponType = MyMwcObjectBuilder_SmallShip_Weapon_TypesEnum.Drilling_Device_Crusher; } } MySmallShipGunBase newWeapon = MySmallShipWeaponFactory.GenerateWeapon(weaponObjectBuilder.WeaponType); if (newWeapon is MyDrillBase) { AddDrill(newWeapon as MyDrillBase, weaponObjectBuilder); } else if (newWeapon is MyHarvestingDevice) { AddHarvestingDevice(newWeapon as MyHarvestingDevice, weaponObjectBuilder); } else { AddWeapon(newWeapon, weaponObjectBuilder); } var parentShip = newWeapon.Parent as MySmallShip; if (parentShip != null) { newWeapon.NearFlag = parentShip.IsCameraInsideMinerShip(); } return(newWeapon); }
/// <summary> /// Adds weapon /// </summary> /// <param name="weapon">Weapon</param> /// <param name="weaponObjectBuilder">Weapon's object builder</param> /// <param name="maxWeapons"> </param> private void AddWeapon(MySmallShipGunBase weapon, MyMwcObjectBuilder_SmallShip_Weapon weaponObjectBuilder) { SetAutoMountIfExceededLimit(weaponObjectBuilder); MyWeaponSlot emptyWeaponSlot = GetEmptySlotToAdd(weaponObjectBuilder); if (emptyWeaponSlot != null) { switch (emptyWeaponSlot.SlotLocation) { case MySlotLocationEnum.None: break; case MySlotLocationEnum.LeftSide: weaponObjectBuilder.SetAutoMountLeft(); break; case MySlotLocationEnum.RightSide: weaponObjectBuilder.SetAutoMountRight(); break; default: throw new ArgumentOutOfRangeException(); } AddWeaponToSlot(emptyWeaponSlot, weapon, weaponObjectBuilder); } }
/// <summary> /// Mounts weapon to this slot /// </summary> /// <param name="weapon"></param> public void Mount(MySmallShipGunBase weapon) { if (OnWeaponMounting != null) { OnWeaponMounting(this, weapon); } MountedWeapon = weapon; }
/// <summary> /// Inits weapon and mount to this slot /// </summary> /// <param name="weapon">Weapon</param> /// <param name="objectBuilder">Weapon's objectbuilder</param> /// <param name="parentShip">Parent ship</param> public void InitAndMount(MySmallShipGunBase weapon, MyMwcObjectBuilder_SmallShip_Weapon objectBuilder, MySmallShip parentShip) { Debug.Assert(WeaponSubObject != null); weapon.Init(null, parentShip, GetPosition(), GetForwardVector(), GetUpVector(), objectBuilder); float?yOffset = GetOffsetFromWeaponSubObject(SUB_OBJECT_Y_OFFSET_KEY); if (yOffset != null) { weapon.YOffset = yOffset.Value; } float?zOffset = GetOffsetFromWeaponSubObject(SUB_OBJECT_Z_OFFSET_KEY); if (zOffset != null) { weapon.ZOffset = zOffset.Value; } Mount(weapon); }
/// <summary> /// Inits weapon and mount to this slot /// </summary> /// <param name="weapon">Weapon</param> /// <param name="objectBuilder">Weapon's objectbuilder</param> /// <param name="parentShip">Parent ship</param> public void InitAndMount(MySmallShipGunBase weapon, MyMwcObjectBuilder_SmallShip_Weapon objectBuilder, MySmallShip parentShip) { Debug.Assert(WeaponSubObject != null); weapon.Init(null, parentShip, GetPosition(), GetForwardVector(), GetUpVector(), objectBuilder); float? yOffset = GetOffsetFromWeaponSubObject(SUB_OBJECT_Y_OFFSET_KEY); if (yOffset != null) { weapon.YOffset = yOffset.Value; } float? zOffset = GetOffsetFromWeaponSubObject(SUB_OBJECT_Z_OFFSET_KEY); if (zOffset != null) { weapon.ZOffset = zOffset.Value; } Mount(weapon); }
public void WeaponShot(MySmallShipGunBase gun, MyAmmoAssignment ammoAssignment) { //Electricity -= MySmallShipConstants.WEAPON_ELECTRICITY_CONSUMPTION; }
private void OnWeaponDismounting(MyWeaponSlot sender, MySmallShipGunBase weapon) { m_allMountedWeapons.Remove(weapon); }
private void OnWeaponMounting(MyWeaponSlot sender, MySmallShipGunBase weapon) { m_allMountedWeapons.Add(weapon); }
/// <summary> /// Adds weapon to slot /// </summary> /// <param name="weaponSlot">Weapon's slot</param> /// <param name="weapon">Weapon</param> /// <param name="weaponObjectBuilder">Weapon's object builder</param> private void AddWeaponToSlot(MyWeaponSlot weaponSlot, MySmallShipGunBase weapon, MyMwcObjectBuilder_SmallShip_Weapon weaponObjectBuilder) { weaponSlot.InitAndMount(weapon, weaponObjectBuilder, Ship); }