Пример #1
0
        public void Merge(MyBattleDefinition src)
        {
            DefaultToolbar = src.DefaultToolbar;
            DefenderEntityDamage = src.DefenderEntityDamage;
            DefaultBlueprints = src.DefaultBlueprints;

            if (src.SpawnBlocks != null && src.SpawnBlocks.Length > 0)
            {
                SpawnBlocks = new MyDefinitionId[src.SpawnBlocks.Length];

                for (int i = 0; i < src.SpawnBlocks.Length; ++i)
                    SpawnBlocks[i] = src.SpawnBlocks[i];
            }
        }
Пример #2
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);
            var ob = builder as MyObjectBuilder_BattleDefinition;

            DefaultToolbar = ob.DefaultToolbar;
            DefenderEntityDamage = ob.DefenderEntityDamage;
            DefaultBlueprints = ob.DefaultBlueprints;

            if (ob.SpawnBlocks != null && ob.SpawnBlocks.Length > 0)
            {
                SpawnBlocks = new MyDefinitionId[ob.SpawnBlocks.Length];

                for (int i = 0; i < ob.SpawnBlocks.Length; ++i)
                    SpawnBlocks[i] = ob.SpawnBlocks[i];
            }
        }
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);
            var ob = (MyObjectBuilder_ScenarioDefinition) builder;

            GameDefinition = ob.GameDefinition;

            AsteroidClustersEnabled = ob.AsteroidClusters.Enabled;
            AsteroidClustersOffset  = ob.AsteroidClusters.Offset;
            CentralClusterEnabled   = ob.AsteroidClusters.CentralCluster;
            DefaultEnvironment      = ob.DefaultEnvironment;
            CreativeDefaultToolbar  = ob.CreativeDefaultToolbar;
            SurvivalDefaultToolbar  = ob.SurvivalDefaultToolbar;
            MainCharacterModel = MyStringId.GetOrCompute(ob.MainCharacterModel);

            GameDate = new DateTime(ob.GameDate);

            SunDirection = ob.SunDirection;
            
            if (ob.PossibleStartingStates != null && ob.PossibleStartingStates.Length > 0)
            {
                PossiblePlayerStarts = new MyWorldGeneratorStartingStateBase[ob.PossibleStartingStates.Length];
                for (int i = 0; i < ob.PossibleStartingStates.Length; ++i)
                {
                    PossiblePlayerStarts[i] = MyWorldGenerator.StartingStateFactory.CreateInstance(ob.PossibleStartingStates[i]);
                }
            }

            if (ob.WorldGeneratorOperations != null && ob.WorldGeneratorOperations.Length > 0)
            {
                WorldGeneratorOperations = new MyWorldGeneratorOperationBase[ob.WorldGeneratorOperations.Length];
                for (int i = 0; i < ob.WorldGeneratorOperations.Length; ++i)
                {
                    WorldGeneratorOperations[i] = MyWorldGenerator.OperationFactory.CreateInstance(ob.WorldGeneratorOperations[i]);
                }
            }

            if (ob.CreativeModeWeapons != null && ob.CreativeModeWeapons.Length > 0)
            {
                CreativeModeWeapons = new MyStringId[ob.CreativeModeWeapons.Length];
                for (int i = 0; i < ob.CreativeModeWeapons.Length; ++i)
                {
                    CreativeModeWeapons[i] = MyStringId.GetOrCompute(ob.CreativeModeWeapons[i]);
                }
            }

            if (ob.SurvivalModeWeapons != null && ob.SurvivalModeWeapons.Length > 0)
            {
                SurvivalModeWeapons = new MyStringId[ob.SurvivalModeWeapons.Length];
                for (int i = 0; i < ob.SurvivalModeWeapons.Length; ++i)
                {
                    SurvivalModeWeapons[i] = MyStringId.GetOrCompute(ob.SurvivalModeWeapons[i]);
                }
            }

            if (ob.CreativeModeComponents != null && ob.CreativeModeComponents.Length > 0)
            {
                CreativeModeComponents = new StartingItem[ob.CreativeModeComponents.Length];
                for (int i = 0; i < ob.CreativeModeComponents.Length; ++i)
                {
                    CreativeModeComponents[i].amount = (MyFixedPoint)ob.CreativeModeComponents[i].amount;
                    CreativeModeComponents[i].itemName = MyStringId.GetOrCompute(ob.CreativeModeComponents[i].itemName);
                }
            }

            if (ob.SurvivalModeComponents != null && ob.SurvivalModeComponents.Length > 0)
            {
                SurvivalModeComponents = new StartingItem[ob.SurvivalModeComponents.Length];
                for (int i = 0; i < ob.SurvivalModeComponents.Length; ++i)
                {
                    SurvivalModeComponents[i].amount = (MyFixedPoint)ob.SurvivalModeComponents[i].amount;
                    SurvivalModeComponents[i].itemName = MyStringId.GetOrCompute(ob.SurvivalModeComponents[i].itemName);
                }
            }

            if (ob.CreativeModePhysicalItems != null && ob.CreativeModePhysicalItems.Length > 0)
            {
                CreativeModePhysicalItems = new StartingPhysicalItem[ob.CreativeModePhysicalItems.Length];
                for (int i = 0; i < ob.CreativeModePhysicalItems.Length; ++i)
                {
                    CreativeModePhysicalItems[i].amount = (MyFixedPoint)ob.CreativeModePhysicalItems[i].amount;
                    CreativeModePhysicalItems[i].itemName = MyStringId.GetOrCompute(ob.CreativeModePhysicalItems[i].itemName);
                    CreativeModePhysicalItems[i].itemType = MyStringId.GetOrCompute(ob.CreativeModePhysicalItems[i].itemType);
                }
            }

            if (ob.SurvivalModePhysicalItems != null && ob.SurvivalModePhysicalItems.Length > 0)
            {
                SurvivalModePhysicalItems = new StartingPhysicalItem[ob.SurvivalModePhysicalItems.Length];
                for (int i = 0; i < ob.SurvivalModePhysicalItems.Length; ++i)
                {
                    SurvivalModePhysicalItems[i].amount = (MyFixedPoint)ob.SurvivalModePhysicalItems[i].amount;
                    SurvivalModePhysicalItems[i].itemName = MyStringId.GetOrCompute(ob.SurvivalModePhysicalItems[i].itemName);
                    SurvivalModePhysicalItems[i].itemType = MyStringId.GetOrCompute(ob.SurvivalModePhysicalItems[i].itemType);
                }
            }

            if (ob.CreativeModeAmmoItems != null && ob.CreativeModeAmmoItems.Length > 0)
            {
                CreativeModeAmmoItems = new StartingItem[ob.CreativeModeAmmoItems.Length];
                for (int i = 0; i < ob.CreativeModeAmmoItems.Length; ++i)
                {
                    CreativeModeAmmoItems[i].amount = (MyFixedPoint)ob.CreativeModeAmmoItems[i].amount;
                    CreativeModeAmmoItems[i].itemName = MyStringId.GetOrCompute(ob.CreativeModeAmmoItems[i].itemName);
                }
            }

            if (ob.SurvivalModeAmmoItems != null && ob.SurvivalModeAmmoItems.Length > 0)
            {
                SurvivalModeAmmoItems = new StartingItem[ob.SurvivalModeAmmoItems.Length];
                for (int i = 0; i < ob.SurvivalModeAmmoItems.Length; ++i)
                {
                    SurvivalModeAmmoItems[i].amount = (MyFixedPoint)ob.SurvivalModeAmmoItems[i].amount;
                    SurvivalModeAmmoItems[i].itemName = MyStringId.GetOrCompute(ob.SurvivalModeAmmoItems[i].itemName);
                }
            }

            CreativeInventoryItems = ob.CreativeInventoryItems;
            SurvivalInventoryItems = ob.SurvivalInventoryItems;

            WorldBoundaries.Min = ob.WorldBoundaries.Min;
            WorldBoundaries.Max = ob.WorldBoundaries.Max;
        }
 public static void InitToolbar(MyToolbarType type, MyObjectBuilder_Toolbar builder)
 {
     if (builder != null)
     {
         Debug.Assert(type == builder.ToolbarType, string.Format("Toolbar type mismatch during init. {0} != {1}", type, builder.ToolbarType));
         if (builder.ToolbarType != type)
             builder.ToolbarType = type;
     }
     m_instance.m_currentToolbar.Init(builder, null, true);
 }
 public static void InitCharacterToolbar(MyObjectBuilder_Toolbar characterToolbar)
 {
     m_instance.m_universalCharacterToolbar.Init(characterToolbar, null, true);
 }
        private static void SendWorldData( ulong steamId )
        {
            try
            {
                MemoryStream ms = new MemoryStream( );
                if ( MyAPIGateway.Session != null )
                {
                    DateTime start = DateTime.Now;
                    ApplicationLog.BaseLog.Info( "...responding to user: {0}", steamId );
                    SendPreamble( steamId, 1 );
                    SendFlush( steamId );

                    // Let's sleep for 5 seconds and let plugins know we're online -- let's not after all, causing sync issues
                    //Thread.Sleep(5000);
                    MyObjectBuilder_World myObjectBuilderWorld = null;
                    lock ( m_inGame )
                    {
                        if ( !m_inGame.Contains( steamId ) )
                        {
                            ApplicationLog.BaseLog.Info( "Cancelled send to user: {0}", steamId );
                            return;
                        }
                    }

                    // This is probably safe to do outside of the game instance, but let's just make sure.
                    SandboxGameAssemblyWrapper.Instance.GameAction( ( ) =>
                    {
                        myObjectBuilderWorld = MyAPIGateway.Session.GetWorld( );
                    } );

                    if ( replaceData )
                    {
                        for ( int r = myObjectBuilderWorld.Sector.SectorObjects.Count - 1; r >= 0; r-- )
                        {
                            MyObjectBuilder_EntityBase entity = (MyObjectBuilder_EntityBase)myObjectBuilderWorld.Sector.SectorObjects[ r ];

                            if ( !( entity is MyObjectBuilder_CubeGrid ) && !( entity is MyObjectBuilder_VoxelMap ) && !( entity is MyObjectBuilder_Character ) )
                                continue;

                            if ( ( entity is MyObjectBuilder_CubeGrid ) && ( (MyObjectBuilder_CubeGrid)entity ).DisplayName.Contains( "CommRelay" ) )
                                continue;

                            /*
                            if (!(entity is MyObjectBuilder_CubeGrid))
                                continue;

                            if ((entity.PersistentFlags & MyPersistentEntityFlags2.InScene) == MyPersistentEntityFlags2.InScene)
                                continue;
                            */

                            myObjectBuilderWorld.Sector.SectorObjects.RemoveAt( r );
                        }

                        myObjectBuilderWorld.Sector.Encounters = null;

                        myObjectBuilderWorld.VoxelMaps.Dictionary.Clear( );
                        myObjectBuilderWorld.Checkpoint.Settings.ProceduralDensity = 0f;
                        myObjectBuilderWorld.Checkpoint.Settings.ProceduralSeed = 0;

                        // Check if this is OK?
                        //myObjectBuilderWorld.Checkpoint.ConnectedPlayers.Dictionary.Clear();
                        myObjectBuilderWorld.Checkpoint.DisconnectedPlayers.Dictionary.Clear( );

                        long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId( steamId );

                        MyObjectBuilder_Toolbar blankToolbar = new MyObjectBuilder_Toolbar( );
                        foreach ( KeyValuePair<MyObjectBuilder_Checkpoint.PlayerId, MyObjectBuilder_Player> p in myObjectBuilderWorld.Checkpoint.AllPlayersData.Dictionary )
                        {
                            if ( p.Value.EntityCameraData != null )
                                p.Value.EntityCameraData.Clear( );

                            if ( p.Value.CameraData != null )
                                p.Value.CameraData.Dictionary.Clear( );

                            if ( p.Key.ClientId == steamId )
                            {
                                continue;
                            }

                            p.Value.Toolbar = null;
                            p.Value.CharacterCameraData = null;
                        }

                        for ( int r = myObjectBuilderWorld.Checkpoint.Gps.Dictionary.Count - 1; r >= 0; r-- )
                        {
                            KeyValuePair<long, MyObjectBuilder_Gps> p = myObjectBuilderWorld.Checkpoint.Gps.Dictionary.ElementAt( r );

                            if ( p.Key == playerId )
                                continue;

                            myObjectBuilderWorld.Checkpoint.Gps.Dictionary.Remove( p.Key );
                        }

                        myObjectBuilderWorld.Checkpoint.ChatHistory.RemoveAll( x => x.IdentityId != playerId );

                        long factionId = 0;
                        if ( myObjectBuilderWorld.Checkpoint.Factions.Players.Dictionary.ContainsKey( playerId ) )
                        {
                            factionId = myObjectBuilderWorld.Checkpoint.Factions.Players.Dictionary[ playerId ];
                            myObjectBuilderWorld.Checkpoint.FactionChatHistory.RemoveAll( x => x.FactionId1 != factionId && x.FactionId2 != factionId );
                            myObjectBuilderWorld.Checkpoint.Factions.Requests.RemoveAll( x => x.FactionId != factionId );
                        }
                        else
                        {
                            myObjectBuilderWorld.Checkpoint.FactionChatHistory.Clear( );
                            myObjectBuilderWorld.Checkpoint.Factions.Requests.Clear( );
                        }

                        foreach ( MyObjectBuilder_Faction faction in myObjectBuilderWorld.Checkpoint.Factions.Factions )
                        {
                            if ( faction.FactionId != factionId )
                            {
                                faction.PrivateInfo = "";
                            }
                        }
                    }

                    // This will modify the world data to remove voxels and turn off procedural for the player.  The
                    // server controls procedural anyway, and doesn't require the user to know about it.  If we don't
                    // turn it off, the objects will still generate on the server.  Possible issue: turning on voxel
                    // management + procedural encounters may be an issue, as I don't think the server sends procedural
                    // encounters to the client.  This may be a gotcha issue when it comes to using this option
                    if (WorldVoxelModify)
                    {
                        for (int r = myObjectBuilderWorld.Sector.SectorObjects.Count - 1; r >= 0; r--)
                        {
                            MyObjectBuilder_EntityBase entity = (MyObjectBuilder_EntityBase)myObjectBuilderWorld.Sector.SectorObjects[r];

                            if (!(entity is MyObjectBuilder_VoxelMap))
                                continue;

                            myObjectBuilderWorld.Sector.SectorObjects.RemoveAt(r);
                        }

                        myObjectBuilderWorld.Sector.Encounters = null;

                        myObjectBuilderWorld.VoxelMaps.Dictionary.Clear();
                        myObjectBuilderWorld.Checkpoint.Settings.ProceduralDensity = 0f;
                        myObjectBuilderWorld.Checkpoint.Settings.ProceduralSeed = 0;
                    }

                    MyObjectBuilder_Checkpoint checkpoint = myObjectBuilderWorld.Checkpoint;
                    checkpoint.WorkshopId = null;
                    checkpoint.CharacterToolbar = null;
                    DateTime cs = DateTime.Now;
                    MyObjectBuilderSerializer.SerializeXML( ms, myObjectBuilderWorld, MyObjectBuilderSerializer.XmlCompression.Gzip, null );

                    /*
                    MemoryStream vms = new MemoryStream();
                    MyObjectBuilderSerializer.SerializeXML(vms, myObjectBuilderWorld, MyObjectBuilderSerializer.XmlCompression.Uncompressed, null);
                    FileStream file = new FileStream("e:\\temp\\test.txt", FileMode.Create);
                    vms.WriteTo(file);
                    file.Close();
                    */

                    ApplicationLog.BaseLog.Info( "...response construction took {0}ms (cp - {1}ms) size - {2} bytes", ( DateTime.Now - start ).TotalMilliseconds, ( DateTime.Now - cs ).TotalMilliseconds, ms.Length );
                }

                TransferWorld( ms, steamId );
            }
            catch ( Exception ex )
            {
                ApplicationLog.BaseLog.Error( ex, "SendWorldData Error: {0}", ex );
            }
        }
Пример #7
0
 private void RenumberToolbar(MyObjectBuilder_Toolbar toolbar, ref Dictionary<Int64, Int64> idReplacementTable)
 {
     if (toolbar == null)
         return;
     foreach (var item in toolbar.Slots)
     {
         var terminalGroup = item.Data as MyObjectBuilder_ToolbarItemTerminalGroup;
         if (terminalGroup != null)
         {
             // GridEntityId does not require remapping. accoring to IL on ToolbarItemTerminalGroup.
             //terminalGroup.GridEntityId = MergeId(terminalGroup.GridEntityId, ref idReplacementTable);
             terminalGroup.BlockEntityId = MergeId(terminalGroup.BlockEntityId, ref idReplacementTable);
         }
         var terminalBlock = item.Data as MyObjectBuilder_ToolbarItemTerminalBlock;
         if (terminalBlock != null)
         {
             terminalBlock.BlockEntityId = MergeId(terminalBlock.BlockEntityId, ref idReplacementTable);
         }
     }
 }
Пример #8
0
        public void Init(MyObjectBuilder_Toolbar builder, MyEntity owner, bool skipAssert = false)
        {
            // TODO: remove skipAssert when spectator is MyEntity
            Debug.Assert(skipAssert || owner != null, "Toolbar has no owner");
            Owner = owner;

            if (builder == null)
                return;

            if (builder.Slots != null)
            {
                Clear();
                foreach (var slot in builder.Slots)
                {
                    SetItemAtSerialized(slot.Index, slot.Item, slot.Data);
                }
            }

            MyCockpit cockpit = Owner as MyCockpit;
            if (cockpit != null && cockpit.CubeGrid != null)
                cockpit.CubeGrid.OnBlockRemoved += OnBlockRemoved;
        }