コード例 #1
0
        //  Write this object into message-out
        internal override void Write(BinaryWriter binaryWriter)
        {
            base.Write(binaryWriter);

            //  Template ID
            MyMwcMessageOut.WriteBool(TemplateId.HasValue, binaryWriter);
            if (TemplateId.HasValue)
            {
                MyMwcLog.IfNetVerbose_AddToLog("TemplateId: " + TemplateId);
                MyMwcMessageOut.WriteInt32(TemplateId.Value, binaryWriter);
            }

            //  Container Type
            MyMwcLog.IfNetVerbose_AddToLog("ContainerType: " + (int)ContainerType);
            MyMwcMessageOut.WriteObjectBuilderPrefabContainerTypesEnum(ContainerType, binaryWriter);

            // Faction must be defined
            System.Diagnostics.Debug.Assert(Enum.IsDefined(typeof(MyMwcObjectBuilder_FactionEnum), Faction));
            // Faction
            MyMwcLog.IfNetVerbose_AddToLog("Faction: " + (int)Faction);
            MyMwcMessageOut.WriteInt32((int)Faction, binaryWriter);

            // Prefabs
            int countPrefabs = Prefabs == null ? 0 : Prefabs.Count;

            MyMwcLog.IfNetVerbose_AddToLog("countPrefabs: " + countPrefabs);
            MyMwcMessageOut.WriteInt32(countPrefabs, binaryWriter);
            for (int i = 0; i < countPrefabs; i++)
            {
                Prefabs[i].Write(binaryWriter);
            }

            // Inventory
            bool isInventory = Inventory != null;

            MyMwcMessageOut.WriteBool(isInventory, binaryWriter);
            if (isInventory)
            {
                Inventory.Write(binaryWriter);
            }

            if (DisplayName != null)
            {
                MyMwcMessageOut.WriteBool(true, binaryWriter);
                MyMwcLog.IfNetVerbose_AddToLog("DisplayName: " + this.DisplayName);
                MyMwcMessageOut.WriteString(DisplayName, binaryWriter);
            }
            else
            {
                MyMwcLog.IfNetVerbose_AddToLog("DisplayName: " + "null");
                MyMwcMessageOut.WriteBool(false, binaryWriter);
            }

            //  Use Properties
            bool hasUseProperties = UseProperties != null;

            MyMwcMessageOut.WriteBool(hasUseProperties, binaryWriter);
            if (hasUseProperties)
            {
                UseProperties.Write(binaryWriter);
            }

            //  Alarm On
            MyMwcLog.IfNetVerbose_AddToLog("AlarmOn: " + AlarmOn);
            MyMwcMessageOut.WriteBool(AlarmOn, binaryWriter);

            //  Refill time
            MyMwcMessageOut.WriteBool(RefillTime.HasValue, binaryWriter);
            if (RefillTime.HasValue)
            {
                MyMwcLog.IfNetVerbose_AddToLog("RefillTime: " + RefillTime);
                MyMwcMessageOut.WriteInt32(RefillTime.Value, binaryWriter);
            }
        }
コード例 #2
0
        //  Write this object into message-out
        internal override void Write(BinaryWriter binaryWriter)
        {
            base.Write(binaryWriter);

            // PrefabType
            MyMwcLog.IfNetVerbose_AddToLog("PrefabObjectBuilderId: " + PrefabObjectBuilderId);
            MyMwcMessageOut.WriteInt32(PrefabObjectBuilderId, binaryWriter);

            // PositionInContainer
            MyMwcLog.IfNetVerbose_AddToLog("PositionInContainer: " + PositionInContainer);
            MyMwcMessageOut.WriteVector3Short(PositionInContainer, binaryWriter);

            // AnglesInContainer
            MyMwcLog.IfNetVerbose_AddToLog("AnglesInContainer: " + AnglesInContainer.ToString());
            MyMwcMessageOut.WriteVector3(AnglesInContainer, binaryWriter);

            bool hasMaxHealth = PrefabMaxHealth != null;

            MyMwcMessageOut.WriteBool(hasMaxHealth, binaryWriter);

            if (hasMaxHealth)
            {
                if (float.IsNaN(PrefabMaxHealth.Value) || float.IsInfinity(PrefabMaxHealth.Value))
                {
                    System.Diagnostics.Debug.Fail("PrefabMaxHealth is: " + PrefabMaxHealth.Value);
                    PrefabMaxHealth = null; // MyGameplayConstants.MAX_HEALTH_MAX;
                }

                MyMwcLog.IfNetVerbose_AddToLog("PrefabMaxHealth: " + PrefabMaxHealth.Value.ToString());
                binaryWriter.Write(PrefabMaxHealth.Value);
            }

            //health ratio cannot be 0, prefab is dead
            System.Diagnostics.Debug.Assert(PrefabHealthRatio != 0, "Prefab health ratio is 0");
            System.Diagnostics.Debug.Assert(PrefabHealthRatio <= 1f, "Prefab health ratio is greater than 1f");
            System.Diagnostics.Debug.Assert(PrefabHealthRatio >= 0f, "Prefab health ratio is lesser than 0f");

            // PrefabHealthRatio
            MyMwcLog.IfNetVerbose_AddToLog("PrefabHealthRatio: " + PrefabHealthRatio.ToString());
            binaryWriter.Write(PrefabHealthRatio);

            if (DisplayName != null)
            {
                MyMwcMessageOut.WriteBool(true, binaryWriter);
                MyMwcLog.IfNetVerbose_AddToLog("DisplayName: " + this.DisplayName);
                MyMwcMessageOut.WriteString(DisplayName, binaryWriter);
            }
            else
            {
                MyMwcLog.IfNetVerbose_AddToLog("DisplayName: " + "null");
                MyMwcMessageOut.WriteBool(false, binaryWriter);
            }

            // faction appearance (texture set)
            MyMwcLog.IfNetVerbose_AddToLog("FactionAppearance: " + FactionAppearance);
            MyMwcMessageOut.WriteInt16((short)FactionAppearance, binaryWriter);

            //  Use Properties
            bool hasUseProperties = UseProperties != null;

            MyMwcMessageOut.WriteBool(hasUseProperties, binaryWriter);
            if (hasUseProperties)
            {
                UseProperties.Write(binaryWriter);
            }

            //  Causes Alarm
            bool hasCausesAlarm = CausesAlarm.HasValue;

            MyMwcMessageOut.WriteBool(hasCausesAlarm, binaryWriter);
            if (hasCausesAlarm)
            {
                MyMwcMessageOut.WriteBool(CausesAlarm.Value, binaryWriter);
            }

            // Requires Energy
            bool hasRequiresEnergy = RequiresEnergy.HasValue;

            MyMwcMessageOut.WriteBool(hasRequiresEnergy, binaryWriter);
            if (hasRequiresEnergy)
            {
                MyMwcMessageOut.WriteBool(RequiresEnergy.Value, binaryWriter);
            }

            //MyMwcLog.IfNetVerbose_AddToLog("ElectricCapacity: " + ElectricCapacity.ToString());
            //binaryWriter.Write(ElectricCapacity);

            // AI Priority
            MyMwcLog.IfNetVerbose_AddToLog("AIPriority: " + AIPriority);
            MyMwcMessageOut.WriteInt32(AIPriority, binaryWriter);
        }