コード例 #1
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);
            var ob = builder as MyObjectBuilder_ScenarioDefinition;

            AsteroidClustersEnabled = ob.AsteroidClusters.Enabled;
            AsteroidClustersOffset  = ob.AsteroidClusters.Offset;
            CentralClusterEnabled   = ob.AsteroidClusters.CentralCluster;
            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]);
                }
            }

            WorldBoundaries.Min = ob.WorldBoundaries.Min;
            WorldBoundaries.Max = ob.WorldBoundaries.Max;
        }
コード例 #2
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];
            }
        }
コード例 #3
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];
            }
        }
コード例 #4
0
		private static void SendWorldData(ulong steamId)
		{
			try
			{
				MemoryStream ms = new MemoryStream();
				if (MyAPIGateway.Session != null)
				{
					DateTime start = DateTime.Now;
					LogManager.APILog.WriteLineAndConsole(string.Format("...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))
						{
							LogManager.APILog.WriteLineAndConsole(string.Format("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 = "";
							}
						}
					}

					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();
					*/

					LogManager.APILog.WriteLineAndConsole(string.Format("...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)
			{
				LogManager.APILog.WriteLineAndConsole(string.Format("SendWorldData Error: {0}", ex.ToString()));
			}
		}
コード例 #5
0
ファイル: MyToolbar.cs プロジェクト: Krulac/SpaceEngineers
        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);
                }
            }
        }
コード例 #6
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);
                }
            }

            if ((builder.ColorMaskHSVList == null) || (builder.ColorMaskHSVList.Count == 0))
            {
                SetDefaultColors();
            }
            else if (builder.ColorMaskHSVList.Count == m_colorMaskSlotCount)
            {
                if(ColorsSetToDefaults(m_colorMaskHSVSlots))
                    m_colorMaskHSVSlots = builder.ColorMaskHSVList;
            }
            else if (builder.ColorMaskHSVList.Count > m_colorMaskSlotCount)
            {
                m_colorMaskHSVSlots = new List<Vector3>(m_colorMaskSlotCount);
                for (int i = 0; i < m_colorMaskSlotCount; i++)
                    m_colorMaskHSVSlots.Add(builder.ColorMaskHSVList[i]);
            }
            else
            {
                m_colorMaskHSVSlots = builder.ColorMaskHSVList;
                for (int i = m_colorMaskHSVSlots.Count - 1; i < m_colorMaskSlotCount; i++)
                    m_colorMaskHSVSlots.Add(MyRenderComponentBase.OldBlackToHSV);
            }
        }
コード例 #7
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);
            var ob = builder as MyObjectBuilder_ScenarioDefinition;

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

            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]);
                }
            }

            WorldBoundaries.Min = ob.WorldBoundaries.Min;
            WorldBoundaries.Max = ob.WorldBoundaries.Max;

            if (MyFakes.ENABLE_BATTLE_SYSTEM && ob.Battle != null)
            {
                Battle = new MyBattleSettings();

                Battle.DefenderSlot = ob.Battle.DefenderSlot;
                Battle.DefenderEntityId = ob.Battle.DefenderEntityId;

                if (ob.Battle.AttackerSlots != null && ob.Battle.AttackerSlots.Length > 0)
                {
                    Battle.AttackerSlots = new BoundingBoxD[ob.Battle.AttackerSlots.Length];
                    for (int i = 0; i < ob.Battle.AttackerSlots.Length; ++i)
                    {
                        Battle.AttackerSlots[i] = ob.Battle.AttackerSlots[i];
                    }
                }
            }
        }
コード例 #8
0
 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);
 }
コード例 #9
0
 public static void InitCharacterToolbar(MyObjectBuilder_Toolbar characterToolbar)
 {
     m_instance.m_universalCharacterToolbar.Init(characterToolbar, null, true);
 }
コード例 #10
0
ファイル: ExplorerModel.cs プロジェクト: Stevolk/SEToolbox
 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);
         }
     }
 }