private MyToolKit(MySmallShip smallShipOwner, MyPlayer playerOwner, MyInventoryItem toolInventoryItem, MyToolKitDelegates[] delegates) { m_smallShipOwner = smallShipOwner; m_playerOwner = playerOwner; m_toolInventoryItem = toolInventoryItem; m_delegates = delegates; }
public MyToolKits(MySmallShip smallShipOwner, MyPlayer playerOwner) { OnInventoryContentChangedHandler = new OnInventoryContentChange(SmallShipInventory_OnInventoryContentChange); m_smallShipOwner = smallShipOwner; m_playerOwner = playerOwner; m_inventoryItemsHelper = new List<MyInventoryItem>(); m_toolKits = new List<MyToolKit>(); m_smallShipOwner.Inventory.OnInventoryContentChange += OnInventoryContentChangedHandler; RefreshToolKits(); }
public static MyGuiScreenInventory OpenInventory(MyGuiScreenInventoryType inventoryScreenType, MyEntity otherSide = null, MySmallShipInteractionActionEnum? action = null) { MyMwcLog.WriteLine("OpenInventory()"); // return harvester when opening inventory, harvester can update inventory, which would not propagete to inventory screen and closing inventory would override those changes var harvester = MySession.PlayerShip.Weapons.GetMountedHarvestingDevice(); if (harvester != null && harvester.CurrentState != MyHarvestingDeviceEnum.InsideShip) harvester.Shot(null); StringBuilder otherSideInventoryName = null; MyInventory otherSideInventory = null; List<MySmallShipBuilderWithName> shipsObjectBuilders = null; bool closeOtherSideInventory = false; m_inventoryScreenType = inventoryScreenType; m_shipsInventoryOwner = MySession.Static; m_player = MySession.Static.Player; m_detectedEntity = otherSide; m_detectedAction = action; shipsObjectBuilders = new List<MySmallShipBuilderWithName>(); shipsObjectBuilders.Add(new MySmallShipBuilderWithName(MySession.PlayerShip.GetObjectBuilder(true) as MyMwcObjectBuilder_SmallShip_Player)); switch(m_inventoryScreenType) { case MyGuiScreenInventoryType.GodEditor: LoadGodEditorInventory(ref otherSideInventory, ref otherSideInventoryName, ref shipsObjectBuilders); closeOtherSideInventory = true; break; case MyGuiScreenInventoryType.InGameEditor: LoadIngameEditorInventory(ref otherSideInventory, ref otherSideInventoryName); break; case MyGuiScreenInventoryType.Game: LoadGameInventory(ref otherSideInventory, ref otherSideInventoryName, ref shipsObjectBuilders); break; } var currentShipBuilder = shipsObjectBuilders[0]; shipsObjectBuilders.Sort((x, y) => ((int)x.Builder.ShipType).CompareTo((int)y.Builder.ShipType)); m_curentIndex = shipsObjectBuilders.IndexOf(currentShipBuilder); MyMwcObjectBuilder_Inventory otherSideInventoryBuilder = otherSideInventory != null ? otherSideInventory.GetObjectBuilder(true) : null; if (closeOtherSideInventory) { Debug.Assert(otherSideInventory != null); otherSideInventory.Close(); } m_currentInventoryScreen = new MyGuiScreenInventory(shipsObjectBuilders, m_curentIndex, m_player.Money, m_tradeForMoney, otherSideInventoryBuilder, otherSideInventoryName, m_inventoryScreenType); m_currentInventoryScreen.OnSave += Save; m_currentInventoryScreen.Closed += OnInventoryScreenClosed; MyGuiScreenGamePlay.Static.HideSelectAmmo(); return m_currentInventoryScreen; }
public void Close() { m_smallShipOwner.Inventory.OnInventoryContentChange -= OnInventoryContentChangedHandler; OnInventoryContentChangedHandler = null; m_toolKits.Clear(); m_toolKits = null; m_inventoryItemsHelper.Clear(); m_inventoryItemsHelper = null; m_smallShipOwner = null; m_playerOwner = null; }
private static void Clear() { m_otherSideInventoryOwner = null; m_player = null; m_shipsInventoryOwner = null; m_tradeForMoney = false; m_entityDetector = null; m_detectedAction = null; m_currentInventoryScreen.OnSave -= Save; m_currentInventoryScreen.Closed -= OnInventoryScreenClosed; m_currentInventoryScreen = null; }
public virtual void Init() { //Create player if it was not loaded from DB if (Player == null) { Player = new MyPlayer(); } //Create player if it was not loaded from DB if (EventLog == null) { EventLog = new MyEventLog(); } if (FactionRelationChanges == null) { FactionRelationChanges = new MyFactionRelationChanges(); } GameDateTime = new DateTime(2081, 1, 1); if (Inventory == null) { Inventory = new MyInventory(); } if (PlayerFriends == null) { PlayerFriends = new MyPlayerFriends(); } if (MotherShipPosition == null) { MotherShipPosition = new MyMotherShipPosition(); } Is2DSector = false; ////Create playership if it was not loaded from DB //if (Player.Ship == null) //{ // Player.Ship = new MySmallShip(1.0f, MyClientServer.LoggedPlayer.GetDisplayName().ToString()); // Player.Ship.Init("MyShip", MySmallShip.CreateDefaultSmallShipObjectBuilder(Matrix.CreateWorld(Vector3.Zero, Vector3.Forward, Vector3.Up))); // //Player.Ship.WorldMatrix = Matrix.CreateTranslation(0, 0, 0); // Player.Ship.Inventory.MaxItems = 1500; // Player.Ship.Inventory.FillInventoryWithAllItems(); //} }
/// <summary> /// Creates new foundation factory from player's inventory. When player has no foundation factory in inventory, then returns result false. /// </summary> /// <param name="result">Result of foundation factory creation</param> /// <returns>Instance of new foundation factory</returns> public static MyPrefabFoundationFactory TryCreateFoundationFactory(MyPlayer player, out bool result) { MyPrefabFoundationFactory foundationFactory = null; MyInventoryItem foundationFactoryItem = player.Ship.Inventory.GetInventoryItem(MyMwcObjectBuilderTypeEnum.PrefabFoundationFactory, (int)MyMwcObjectBuilder_PrefabFoundationFactory_TypesEnum.DEFAULT); if (foundationFactoryItem == null) { foundationFactoryItem = player.Ship.Inventory.GetInventoryItem(MyMwcObjectBuilderTypeEnum.FoundationFactory, null); } if (foundationFactoryItem == null) { result = false; } else { MyMwcObjectBuilder_PrefabFoundationFactory foundationFactoryBuilder = MyMwcObjectBuilder_Base.CreateNewObject(MyMwcObjectBuilderTypeEnum.PrefabFoundationFactory, (int)MyMwcObjectBuilder_PrefabFoundationFactory_TypesEnum.DEFAULT) as MyMwcObjectBuilder_PrefabFoundationFactory; MyMwcObjectBuilder_PrefabContainer prefabContainerBuilder = new MyMwcObjectBuilder_PrefabContainer( null, MyMwcObjectBuilder_PrefabContainer_TypesEnum.INSTANCE, new List<MyMwcObjectBuilder_PrefabBase>(), MyClientServer.LoggedPlayer.GetUserId(), player.Faction, new MyMwcObjectBuilder_Inventory(new List<MyMwcObjectBuilder_InventoryItem>(), 1000)); Matrix ffWorld = Matrix.Identity; ffWorld.Translation = player.Ship.WorldMatrix.Translation + player.Ship.WorldMatrix.Forward * 20; MyPrefabContainer prefabContainer = new MyPrefabContainer(); prefabContainer.Init(null, prefabContainerBuilder, ffWorld); MyEntities.Add(prefabContainer); MyPrefabConfiguration ffConfiguration = MyPrefabConstants.GetPrefabConfiguration(MyMwcObjectBuilderTypeEnum.PrefabFoundationFactory, (int)MyMwcObjectBuilder_PrefabFoundationFactory_TypesEnum.DEFAULT); foundationFactory = new MyPrefabFoundationFactory(prefabContainer); foundationFactory.Init(null, new Vector3(0f, 0f, 0f), Matrix.Identity, foundationFactoryBuilder, ffConfiguration); prefabContainer.AddPrefab(foundationFactory); player.Ship.Inventory.RemoveInventoryItemAmount(ref foundationFactoryItem, 1f); result = true; } return foundationFactory; }
public static MyToolKit CreateInstance(MySmallShip smallShipOwner, MyPlayer playerOwner, MyInventoryItem toolInventoryItem) { Debug.Assert(smallShipOwner != null); Debug.Assert(playerOwner != null); Debug.Assert(IsSupportedToolKitItem(toolInventoryItem)); MyToolKitDelegates[] delegates = m_delegatesPerToolKitType[toolInventoryItem.ObjectBuilderId.Value]; Debug.Assert(delegates.Length > 0); return new MyToolKit(smallShipOwner, playerOwner, toolInventoryItem, delegates); }