private static void PackMothership() { MyTrace.Send(TraceWindow.Saving, "Player packing mothership"); MyPrefabHangar hangar = MySession.Static.Player.Ship.GetNearMotherShipContainer(); if (hangar == null) { //We are traveling in solar map but madelyn is far away. Assume we are travelling with Madelyn by default MyEntity madelynHangar; MyEntities.TryGetEntityByName(MyMission.MyMissionLocation.MADELYN_HANGAR, out madelynHangar); hangar = madelynHangar as MyPrefabHangar; } if (hangar != null) { // Move player start location dummy, so that next time player starts on same position UpdateStartDummy(MyDummyPointFlags.PLAYER_START, MySession.PlayerShip.WorldMatrix); // Move mothership start location dummy, so that next time mothership starts on same position UpdateStartDummy(MyDummyPointFlags.MOTHERSHIP_START, hangar.Parent.WorldMatrix); var container = hangar.Parent; MyInventoryItem item = MyInventory.CreateInventoryItemFromObjectBuilder(container.GetObjectBuilder(true)); MySession.Static.Inventory.AddInventoryItem(item); container.MarkForClose(); MyTrace.Send(TraceWindow.Saving, "Player mothership found and packed"); } }
private MyGuiControlListboxItem CreateCopy(MyGuiControlListboxItem original) { MyInventoryItem templateInventoryItem = m_inventoryItemsRepository.GetItem(original.Key); MyInventoryItem newInventoryItem = MyInventory.CreateInventoryItemFromObjectBuilder(templateInventoryItem.GetInventoryItemObjectBuilder(true)); newInventoryItem.Amount = templateInventoryItem.Amount; MyGuiControlListboxItem newItem = CreateListboxItemAndAddToRepository(newInventoryItem); newItem.IconTexts = original.IconTexts; m_itemsAdded.Add(newInventoryItem); return(newItem); }
private void PackDrones() { MyTrace.Send(TraceWindow.Saving, "Player packing drones"); var drones = MySession.PlayerShip.Drones; if (drones != null && drones.Count > 0) { for (int index = drones.Count - 1; index >= 0; index--) { var drone = drones[index]; var inventoryItem = MyInventory.CreateInventoryItemFromObjectBuilder(drone.GetObjectBuilder(true)); MySession.Static.Inventory.AddInventoryItem(inventoryItem); drone.MarkForClose(); } MyTrace.Send(TraceWindow.Saving, "Drones found and packed"); } }
private void GiveoutEquipmentOnOnMissionSuccess(MyMissionBase sender) { m_myInventory.Clear(); m_myInventory.AddRange(MyScriptWrapper.GetPlayerInventory().GetInventoryItems()); var cargobox = (MyCargoBox)MyScriptWrapper.GetEntity((uint)EntityID.FakeCargo); var builders = MySession.PlayerShip.Weapons.GetWeaponsObjectBuilders(true); foreach (var myMwcObjectBuilderSmallShipWeapon in builders) { var item = MyInventory.CreateInventoryItemFromObjectBuilder(myMwcObjectBuilderSmallShipWeapon); m_myInventory.Add(item); } cargobox.Inventory.AddInventoryItems(m_myInventory); MySession.PlayerShip.Weapons.RemoveAllWeapons(); var inventory = MyScriptWrapper.GetPlayerInventory(); inventory.ClearInventoryItems(false); }
public void PackFriends() { MyMwcLog.WriteLine("MyPlayerFriends::PackFriends - START"); MyMwcLog.IncreaseIndent(); while (m_playerFriends.Count > 0) { var friend = m_playerFriends[0]; if (friend is MySmallShipBot) { var inventoryItem = MyInventory.CreateInventoryItemFromObjectBuilder(friend.GetObjectBuilder(true)); MySession.Static.Inventory.AddInventoryItem(inventoryItem); } friend.MarkForClose(); // This causes remove from m_playerFriends m_playerFriends.Remove(friend); } MyMwcLog.DecreaseIndent(); MyMwcLog.WriteLine("MyPlayerFriends::PackFriends - END"); }
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); } }