Exemplo n.º 1
0
        /// <summary>
        /// Returns objectbuilder of inventory
        /// </summary>
        /// <returns></returns>
        public MyMwcObjectBuilder_Inventory GetObjectBuilder(bool getExactCopy)
        {
            List <MyMwcObjectBuilder_InventoryItem> inventoryItemsObjectBuilders = new List <MyMwcObjectBuilder_InventoryItem>();

            foreach (MyInventoryItem item in m_inventoryItems)
            {
                //MyMwcObjectBuilder_InventoryItem inventoryItemBuilder = new MyMwcObjectBuilder_InventoryItem(item.GetInventoryItemObjectBuilder(getExactCopy), item.Amount);
                MyMwcObjectBuilder_InventoryItem inventoryItemBuilder = item.GetObjectBuilder();
                if (inventoryItemBuilder.ItemObjectBuilder is MyMwcObjectBuilder_PrefabBase)
                {
                    MyMwcObjectBuilder_PrefabBase prefabBuilder = inventoryItemBuilder.ItemObjectBuilder as MyMwcObjectBuilder_PrefabBase;
                    if (prefabBuilder.PrefabHealthRatio == 0f)
                    {
                        prefabBuilder.PrefabHealthRatio = MyGameplayConstants.HEALTH_RATIO_MAX;
                    }
                    if (prefabBuilder.PrefabMaxHealth == 0f)
                    {
                        prefabBuilder.PrefabMaxHealth = MyGameplayConstants.MAXHEALTH_PREFAB;
                    }
                }
                inventoryItemsObjectBuilders.Add(inventoryItemBuilder);
            }
            MyMwcObjectBuilder_Inventory inventoryBuilder = new MyMwcObjectBuilder_Inventory(inventoryItemsObjectBuilders, MaxItems, TemplateType, PriceCoeficient);

            inventoryBuilder.UnlimitedCapacity = UnlimitedCapacity;
            return(inventoryBuilder);
        }
Exemplo n.º 2
0
 public MyMwcObjectBuilder_SmallShip(MyMwcObjectBuilder_SmallShip_TypesEnum shipType,
                                     MyMwcObjectBuilder_Inventory inventory,
                                     List <MyMwcObjectBuilder_SmallShip_Weapon> weapons,
                                     MyMwcObjectBuilder_SmallShip_Engine engine,
                                     List <MyMwcObjectBuilder_AssignmentOfAmmo> assignmentOfAmmo,
                                     MyMwcObjectBuilder_SmallShip_Armor armor,
                                     MyMwcObjectBuilder_SmallShip_Radar radar,
                                     float?shipMaxHealth,
                                     float shipHealthRatio,
                                     float armorHealth,
                                     float oxygen,
                                     float fuel,
                                     bool reflectorLight,
                                     bool reflectorLongRange,
                                     float reflectorShadowDistance,
                                     int aiPriority)
     : base(inventory)
 {
     ShipType                = shipType;
     Weapons                 = weapons;
     Engine                  = engine;
     AssignmentOfAmmo        = assignmentOfAmmo;
     Armor                   = armor;
     Radar                   = radar;
     ShipMaxHealth           = shipMaxHealth;
     ShipHealthRatio         = shipHealthRatio;
     ArmorHealth             = armorHealth;
     Oxygen                  = oxygen;
     Fuel                    = fuel;
     ReflectorLight          = reflectorLight;
     ReflectorLongRange      = reflectorLongRange;
     ReflectorShadowDistance = reflectorShadowDistance;
     AIPriority              = aiPriority;
 }
Exemplo n.º 3
0
        public void Init(string hudLabelText, MyMwcObjectBuilder_CargoBox objectBuilder, Matrix matrix)
        {
            Flags |= EntityFlags.EditableInEditor;

            StringBuilder hudLabelTextSb = (hudLabelText == null) ? MyTextsWrapper.Get(MyTextsWrapperEnum.CargoBox) : new StringBuilder(hudLabelText);

            // We want to make cargo box "lazy" to prevent rapid movement
            const float cargoBoxMass        = 5000.0f;
            const float cargoAngularDamping = 0.5f;

            var modelLod0Enum = GetModelLod0EnumFromType(objectBuilder.CargoBoxType);

            base.Init(hudLabelTextSb, modelLod0Enum, null, null, null, objectBuilder);
            base.InitBoxPhysics(MyMaterialType.METAL, ModelLod0, cargoBoxMass, cargoAngularDamping, MyConstants.COLLISION_LAYER_DEFAULT, RigidBodyFlag.RBF_RBO_STATIC);
            this.Physics.LinearDamping      = 0.7f;
            this.Physics.MaxLinearVelocity  = 350;
            this.Physics.MaxAngularVelocity = 5;

            m_inventoryTemplate = objectBuilder.Inventory;
            if (m_inventoryTemplate != null)
            {
                Inventory.Init(m_inventoryTemplate);
            }
            CargoBoxType = objectBuilder.CargoBoxType;

            SetWorldMatrix(matrix);

            Save = true;
            this.Physics.Enabled = true;
            UpdateState();
        }
Exemplo n.º 4
0
        protected override MyMwcObjectBuilder_Base GetObjectBuilderInternal(bool getExactCopy)
        {
            List <MyMwcObjectBuilder_PrefabBase> prefabs   = new List <MyMwcObjectBuilder_PrefabBase>(m_prefabs.Count);
            MyMwcObjectBuilder_Inventory         inventory = null;

            if (Inventory != null)
            {
                inventory = Inventory.GetObjectBuilder(getExactCopy);
            }
            foreach (MyPrefabBase prefab in m_prefabs)
            {
                MyEntity entity = prefab;
                if (MyEntities.IsMarkedForClose(entity))
                {
                    continue;
                }

                MyMwcObjectBuilder_PrefabBase prefabOld = entity.GetObjectBuilder(getExactCopy) as MyMwcObjectBuilder_PrefabBase;
                prefabs.Add(prefabOld);
            }

            MyMwcObjectBuilder_PrefabContainer objectBuilder
                = new MyMwcObjectBuilder_PrefabContainer(null, MyMwcObjectBuilder_PrefabContainer_TypesEnum.INSTANCE, prefabs,
                                                         GetUserID(), Faction, inventory);

            objectBuilder.PositionAndOrientation.Position = this.GetPosition();
            objectBuilder.PositionAndOrientation.Forward  = this.GetOrientation().Forward;
            objectBuilder.PositionAndOrientation.Up       = this.GetOrientation().Up;
            objectBuilder.DisplayName   = DisplayName;
            objectBuilder.UseProperties = UseProperties.GetObjectBuilder();
            objectBuilder.AlarmOn       = AlarmOn;
            objectBuilder.RefillTime    = RefillTime;
            return(objectBuilder);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initialize inventory from objectbuilder
        /// </summary>
        /// <param name="inventoryObjectBuilder">Inventory objectbuilder</param>
        public void Init(MyMwcObjectBuilder_Inventory inventoryObjectBuilder, float defaultPriceCoeficient = DEFAULT_PRICE_COEFICIENT)
        {
            Debug.Assert(inventoryObjectBuilder != null);

            if (inventoryObjectBuilder.MaxItems == 0)
            {
                MaxItems = MyInventory.DEFAULT_MAX_ITEMS;
            }
            else
            {
                MaxItems = inventoryObjectBuilder.MaxItems;
            }

            PriceCoeficient   = inventoryObjectBuilder.PriceCoeficient != null ? inventoryObjectBuilder.PriceCoeficient.Value : defaultPriceCoeficient;
            TemplateType      = inventoryObjectBuilder.TemplateType;
            UnlimitedCapacity = inventoryObjectBuilder.UnlimitedCapacity;

            if (inventoryObjectBuilder.InventoryItems != null && inventoryObjectBuilder.InventoryItems.Count > 0)
            {
                RemoveAllInventoryItemsPrivate(true);
                List <MyInventoryItem> inventoryItemsToAdd = new List <MyInventoryItem>();
                foreach (MyMwcObjectBuilder_InventoryItem inventoryItemObjectBuilder in inventoryObjectBuilder.InventoryItems)
                {
                    if (inventoryItemsToAdd.Count >= MaxItems && !UnlimitedCapacity)
                    {
                        break;
                    }
                    // if old foundation factory is in inventory, we replace it with new prefab foundation factory
                    if (inventoryItemObjectBuilder.ItemObjectBuilder is MyMwcObjectBuilder_FoundationFactory)
                    {
                        inventoryItemObjectBuilder.ItemObjectBuilder = MyMwcObjectBuilder_Base.CreateNewObject(MyMwcObjectBuilderTypeEnum.PrefabFoundationFactory, (int)MyMwcObjectBuilder_PrefabFoundationFactory_TypesEnum.DEFAULT);
                    }

                    // hack: we need set default prefab health and max health to prefab object builder
                    if (inventoryItemObjectBuilder.ItemObjectBuilder is MyMwcObjectBuilder_PrefabBase)
                    {
                        MyMwcObjectBuilder_PrefabBase prefabBuilder = inventoryItemObjectBuilder.ItemObjectBuilder as MyMwcObjectBuilder_PrefabBase;
                        if (prefabBuilder.PrefabHealthRatio == 0f)
                        {
                            prefabBuilder.PrefabHealthRatio = MyGameplayConstants.HEALTH_RATIO_MAX;
                        }
                        if (prefabBuilder.PrefabMaxHealth == 0f)
                        {
                            prefabBuilder.PrefabMaxHealth = MyGameplayConstants.MAXHEALTH_PREFAB;
                        }
                    }

                    MyInventoryItem inventoryItem = CreateInventoryItemFromObjectBuilder(inventoryItemObjectBuilder.ItemObjectBuilder, inventoryItemObjectBuilder.Amount);
                    inventoryItem.TemporaryFlags = inventoryItemObjectBuilder.TemporaryFlags;
                    inventoryItemsToAdd.Add(inventoryItem);
                }
                AddInventoryItems(inventoryItemsToAdd);
            }
            else
            {
                ClearInventoryItems(true);
            }
        }
Exemplo n.º 6
0
 public MyMwcObjectBuilder_PrefabContainer(int?templateId, MyMwcObjectBuilder_PrefabContainer_TypesEnum containerType,
                                           List <MyMwcObjectBuilder_PrefabBase> prefabs, int userOwnerID, MyMwcObjectBuilder_FactionEnum faction, MyMwcObjectBuilder_Inventory inventory)
 {
     TemplateId    = templateId;
     ContainerType = containerType;
     Prefabs       = prefabs;
     UserOwnerID   = userOwnerID;
     Faction       = faction;
     Inventory     = inventory;
 }
Exemplo n.º 7
0
 private void InitInventory(MyMwcObjectBuilder_Inventory inventory)
 {
     if (inventory != null)
     {
         Inventory.Init(inventory);
         Inventory_OnInventoryContentChange(Inventory);
     }
     Inventory.MaxItems = 1;
     Inventory.OnInventoryContentChange += Inventory_OnInventoryContentChange;
 }
Exemplo n.º 8
0
 public MyMwcObjectBuilder_SmallShip_Player(MyMwcObjectBuilder_SmallShip_TypesEnum shipType,
                                            MyMwcObjectBuilder_Inventory inventory,
                                            List <MyMwcObjectBuilder_SmallShip_Weapon> weapons,
                                            MyMwcObjectBuilder_SmallShip_Engine engine,
                                            List <MyMwcObjectBuilder_AssignmentOfAmmo> assignmentOfAmmo,
                                            MyMwcObjectBuilder_SmallShip_Armor armor,
                                            MyMwcObjectBuilder_SmallShip_Radar radar,
                                            float?shipMaxHealth,
                                            float shipHealthRatio,
                                            float armorHealth,
                                            float electricity,
                                            float oxygen,
                                            float fuel,
                                            bool reflectorLight,
                                            bool reflectorLongRange,
                                            float reflectorShadowDistance,
                                            int aiPriority)
     : base(shipType, inventory, weapons, engine, assignmentOfAmmo, armor, radar, shipMaxHealth, shipHealthRatio, armorHealth, oxygen, fuel, reflectorLight, reflectorLongRange, reflectorShadowDistance, aiPriority)
 {
     DisplayName = "Player";
 }
Exemplo n.º 9
0
 public MyMwcObjectBuilder_SmallShip_Bot(MyMwcObjectBuilder_SmallShip_TypesEnum shipType,
                                         MyMwcObjectBuilder_Inventory inventory,
                                         List <MyMwcObjectBuilder_SmallShip_Weapon> weapons,
                                         MyMwcObjectBuilder_SmallShip_Engine engine,
                                         List <MyMwcObjectBuilder_AssignmentOfAmmo> assignmentOfAmmo,
                                         MyMwcObjectBuilder_SmallShip_Armor armor,
                                         MyMwcObjectBuilder_SmallShip_Radar radar,
                                         float?shipMaxHealth,
                                         float shipHealthRatio,
                                         float armorHealth,
                                         float oxygen,
                                         float fuel,
                                         bool reflectorLight,
                                         bool reflectorLongRange,
                                         MyMwcObjectBuilder_FactionEnum shipFaction,
                                         MyAITemplateEnum aiTemplate,
                                         float aggressivity,
                                         float seeDistance,
                                         float sleepDistance,
                                         MyPatrolMode patrolMode,
                                         uint?leader,
                                         BotBehaviorType idleBehavior,
                                         float reflectorShadowDistance,
                                         int aiPriority,
                                         bool leaderLostEnabled,
                                         bool activeAI)
     : base(shipType, inventory, weapons, engine, assignmentOfAmmo, armor, radar, shipMaxHealth, shipHealthRatio, armorHealth, oxygen, fuel, reflectorLight, reflectorLongRange, reflectorShadowDistance, aiPriority)
 {
     Faction           = shipFaction;
     AITemplate        = aiTemplate;
     Aggressivity      = aggressivity;
     SeeDistance       = seeDistance;
     SleepDistance     = sleepDistance;
     PatrolMode        = patrolMode;
     Leader            = leader;
     IdleBehavior      = idleBehavior;
     LeaderLostEnabled = leaderLostEnabled;
     ActiveAI          = activeAI;
     SlowDown          = 1;
 }
Exemplo n.º 10
0
 internal MyMwcObjectBuilder_PrefabContainer()
     : base()
 {
     Inventory = new MyMwcObjectBuilder_Inventory();
 }
Exemplo n.º 11
0
        //  Read this object from message-in
        internal override bool Read(BinaryReader binaryReader, EndPoint senderEndPoint, int gameVersion)
        {
            if (base.Read(binaryReader, senderEndPoint, gameVersion) == false)
            {
                return(NetworkError());
            }

            //  TemplateId
            bool?isTemplateId = MyMwcMessageIn.ReadBoolEx(binaryReader, senderEndPoint);

            if (isTemplateId == null)
            {
                return(NetworkError());
            }
            if (isTemplateId.Value)
            {
                TemplateId = MyMwcMessageIn.ReadInt32Ex(binaryReader, senderEndPoint);
            }
            else
            {
                TemplateId = null;
            }

            //  Container Type
            MyMwcObjectBuilder_PrefabContainer_TypesEnum?containerType = MyMwcMessageIn.ReadObjectBuilderPrefabContainerTypesEnumEx(binaryReader, senderEndPoint);

            if (containerType == null)
            {
                return(NetworkError());
            }
            ContainerType = containerType.Value;
            MyMwcLog.IfNetVerbose_AddToLog("ContainerType: " + ContainerType);

            // Faction
            Faction = (MyMwcObjectBuilder_FactionEnum)MyMwcMessageIn.ReadInt32Ex(binaryReader, senderEndPoint);
            // Faction must be defined
            System.Diagnostics.Debug.Assert(Enum.IsDefined(typeof(MyMwcObjectBuilder_FactionEnum), Faction));

            //  Prefabs
            int?countPrefabs = MyMwcMessageIn.ReadInt32Ex(binaryReader, senderEndPoint);

            if (countPrefabs == null)
            {
                return(NetworkError());
            }
            MyMwcLog.IfNetVerbose_AddToLog("countPrefabs: " + countPrefabs);
            Prefabs = new List <MyMwcObjectBuilder_PrefabBase>(countPrefabs.Value);
            for (int i = 0; i < countPrefabs; i++)
            {
                MyMwcObjectBuilder_PrefabBase prefab = MyMwcObjectBuilder_Base.ReadAndCreateNewObject(binaryReader, senderEndPoint) as MyMwcObjectBuilder_PrefabBase;
                if (prefab == null)
                {
                    return(NetworkError());
                }
                if (prefab.Read(binaryReader, senderEndPoint, gameVersion) == false)
                {
                    return(NetworkError());
                }
                Prefabs.Add(prefab);
            }

            //  Inventory
            bool?isInventory = MyMwcMessageIn.ReadBoolEx(binaryReader, senderEndPoint);

            if (isInventory == null)
            {
                return(NetworkError());
            }
            if (isInventory.Value)
            {
                Inventory = MyMwcObjectBuilder_Base.ReadAndCreateNewObject(binaryReader, senderEndPoint) as MyMwcObjectBuilder_Inventory;
                if (Inventory == null)
                {
                    return(NetworkError());
                }
                if (Inventory.Read(binaryReader, senderEndPoint, gameVersion) == false)
                {
                    return(NetworkError());
                }
            }
            else
            {
                Inventory = null;
            }


            bool?hasDisplayName = MyMwcMessageIn.ReadBoolEx(binaryReader, senderEndPoint);

            if (!hasDisplayName.HasValue)
            {
                return(NetworkError());
            }
            if (hasDisplayName.Value)
            {
                string displayName = MyMwcMessageIn.ReadStringEx(binaryReader, senderEndPoint);
                if (displayName == null)
                {
                    return(NetworkError());
                }
                MyMwcLog.IfNetVerbose_AddToLog("DisplayName: " + displayName);
                DisplayName = displayName;
            }
            else
            {
                MyMwcLog.IfNetVerbose_AddToLog("DisplayName: " + "null");
                DisplayName = null;
            }

            //  Use Properties
            bool?hasUseProperties = MyMwcMessageIn.ReadBoolEx(binaryReader, senderEndPoint);

            if (hasUseProperties == null)
            {
                return(NetworkError());
            }
            if (hasUseProperties.Value)
            {
                UseProperties = MyMwcObjectBuilder_Base.ReadAndCreateNewObject(binaryReader, senderEndPoint) as MyMwcObjectBuilder_EntityUseProperties;
                if (UseProperties == null)
                {
                    return(NetworkError());
                }
                if (UseProperties.Read(binaryReader, senderEndPoint, gameVersion) == false)
                {
                    return(NetworkError());
                }
            }
            else
            {
                UseProperties = null;
            }

            //  Alarm On
            bool?alarmOn = MyMwcMessageIn.ReadBoolEx(binaryReader, senderEndPoint);

            if (alarmOn == null)
            {
                return(NetworkError());
            }
            AlarmOn = alarmOn.Value;
            MyMwcLog.IfNetVerbose_AddToLog("AlarmOn: " + AlarmOn);

            //  Refill time
            bool?refillTime = MyMwcMessageIn.ReadBoolEx(binaryReader, senderEndPoint);

            if (refillTime == null)
            {
                return(NetworkError());
            }
            if (refillTime.Value)
            {
                RefillTime = MyMwcMessageIn.ReadInt32Ex(binaryReader, senderEndPoint);
            }
            else
            {
                RefillTime = null;
            }

            return(true);
        }
Exemplo n.º 12
0
        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 MyMwcObjectBuilder_Drone()
 {
     Inventory = new MyMwcObjectBuilder_Inventory(new List <MyMwcObjectBuilder_InventoryItem>(), 1);
     Faction   = MyMwcObjectBuilder_FactionEnum.None;
 }
Exemplo n.º 14
0
 public MyMwcObjectBuilder_CargoBox(MyMwcObjectBuilder_Inventory inventory)
 {
     Inventory = inventory;
 }
Exemplo n.º 15
0
 internal MyMwcObjectBuilder_CargoBox() : base()
 {
     Inventory = new MyMwcObjectBuilder_Inventory();
 }
Exemplo n.º 16
0
 protected MyMwcObjectBuilder_Ship(MyMwcObjectBuilder_Inventory inventory)
     : this()
 {
     Inventory = inventory;
 }