/// <summary> /// All weapons cheat implementation /// </summary> static void AllWeaponsEnabled(MyGameplayCheat cheat) { if (MySession.PlayerShip == null) { return; } List <MyMwcObjectBuilder_SmallShip_Weapon> weapons = new List <MyMwcObjectBuilder_SmallShip_Weapon>(); List <MyMwcObjectBuilder_AssignmentOfAmmo> ammoAssignment = new List <MyMwcObjectBuilder_AssignmentOfAmmo>(); List <MyMwcObjectBuilder_InventoryItem> inventoryItems = new List <MyMwcObjectBuilder_InventoryItem>(); // weapons foreach (MyMwcObjectBuilder_SmallShip_Weapon_TypesEnum weapon in Enum.GetValues(typeof(MyMwcObjectBuilder_SmallShip_Weapon_TypesEnum))) { weapons.Add(new MyMwcObjectBuilder_SmallShip_Weapon(weapon)); // we want have 2x autocanon if (weapon == MyMwcObjectBuilder_SmallShip_Weapon_TypesEnum.Autocanon) { weapons.Add(new MyMwcObjectBuilder_SmallShip_Weapon(weapon)); } } // ammo assignment ammoAssignment.Add(new MyMwcObjectBuilder_AssignmentOfAmmo(MyMwcObjectBuilder_FireKeyEnum.Primary, MyMwcObjectBuilder_AmmoGroupEnum.Bullet, MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Autocannon_Basic)); ammoAssignment.Add(new MyMwcObjectBuilder_AssignmentOfAmmo(MyMwcObjectBuilder_FireKeyEnum.Secondary, MyMwcObjectBuilder_AmmoGroupEnum.Missile, MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Missile_Basic)); ammoAssignment.Add(new MyMwcObjectBuilder_AssignmentOfAmmo(MyMwcObjectBuilder_FireKeyEnum.Third, MyMwcObjectBuilder_AmmoGroupEnum.UniversalLauncherFront, MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Universal_Launcher_Mine_Basic)); ammoAssignment.Add(new MyMwcObjectBuilder_AssignmentOfAmmo(MyMwcObjectBuilder_FireKeyEnum.Fourth, MyMwcObjectBuilder_AmmoGroupEnum.UniversalLauncherBack, MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Universal_Launcher_Mine_Smart)); ammoAssignment.Add(new MyMwcObjectBuilder_AssignmentOfAmmo(MyMwcObjectBuilder_FireKeyEnum.Fifth, MyMwcObjectBuilder_AmmoGroupEnum.Bullet, MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Autocannon_Basic)); MySession.PlayerShip.Weapons.Init(weapons, ammoAssignment); foreach (MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum ammo in Enum.GetValues(typeof(MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum))) { MyMwcObjectBuilder_InventoryItem item = new MyMwcObjectBuilder_InventoryItem(new MyMwcObjectBuilder_SmallShip_Ammo(ammo), MyGameplayConstants.GetGameplayProperties(MyMwcObjectBuilderTypeEnum.SmallShip_Ammo, (int)ammo, MySession.PlayerShip.Faction).MaxAmount); if (!MySession.PlayerShip.Inventory.IsFull) { MySession.PlayerShip.Inventory.AddInventoryItem(MyInventory.CreateInventoryItemFromInventoryItemObjectBuilder(item)); } } }
private static void Save(MyGuiScreenInventory sender, MyGuiScreenInventorySaveResult saveResult) { // save money if (m_tradeForMoney) { m_player.Money = saveResult.Money; } bool isTradingWithMotherShip = IsTradingWithMothership(); List <MyInventoryItem> itemsToMothership = new List <MyInventoryItem>(); // save ships for (int i = 0; i < saveResult.SmallShipsObjectBuilders.Count; i++) { MyMwcObjectBuilder_SmallShip shipBuilder = saveResult.SmallShipsObjectBuilders[i].Builder; if (i == saveResult.CurrentIndex) { if (m_curentIndex == saveResult.CurrentIndex) { // we want init weapons only when weapons are not same if (!WeaponBuildersAreSame(m_player.Ship.Weapons.GetWeaponsObjectBuilders(true), shipBuilder.Weapons)) { m_player.Ship.Weapons.Init(shipBuilder.Weapons, shipBuilder.AssignmentOfAmmo); } m_player.Ship.Inventory.Init(shipBuilder.Inventory); m_player.Ship.Armor = shipBuilder.Armor; m_player.Ship.Engine = shipBuilder.Engine; } else { var oldShip = m_player.Ship; m_player.Ship.MarkForClose(); if (MyMultiplayerGameplay.IsRunning) { MyMultiplayerGameplay.Static.Respawn(shipBuilder, m_player.Ship.WorldMatrix); } else { var ship = MyEntities.CreateFromObjectBuilderAndAdd(null, shipBuilder, m_player.Ship.WorldMatrix); } // Update bots - bot logic runs on host MyBotCoordinator.ChangeShip(oldShip, m_player.Ship); } } else { if (isTradingWithMotherShip) { MyInventoryItem shipInventoryItem = MyInventory.CreateInventoryItemFromObjectBuilder(shipBuilder); itemsToMothership.Add(shipInventoryItem); //m_shipsInventoryOwner.Inventory.AddInventoryItem(shipInventoryItem); } } } // save other side inventory if (m_inventoryScreenType != MyGuiScreenInventoryType.GodEditor) { if (m_otherSideInventoryOwner != null) { if (isTradingWithMotherShip) { for (int i = saveResult.OtherSideInventoryObjectBuilder.InventoryItems.Count - 1; i >= 0; i--) { MyMwcObjectBuilder_InventoryItem itemBuilder = saveResult.OtherSideInventoryObjectBuilder.InventoryItems[i]; if (itemBuilder.IsTemporaryItem) { saveResult.OtherSideInventoryObjectBuilder.InventoryItems.RemoveAt(i); // because smallships was added when ships were saved if (itemBuilder.ItemObjectBuilder.GetObjectBuilderType() != MyMwcObjectBuilderTypeEnum.SmallShip_Player) { itemsToMothership.Add(MyInventory.CreateInventoryItemFromInventoryItemObjectBuilder(itemBuilder)); } } } } m_otherSideInventoryOwner.Inventory.Init(saveResult.OtherSideInventoryObjectBuilder); } } if (isTradingWithMotherShip) { m_shipsInventoryOwner.Inventory.AddInventoryItems(itemsToMothership); } }