public StringBuilder GetName() { switch (EventType) { case EventTypeEnum.GlobalEvent: var globalEvent = MyGlobalEvents.GetGlobalEventByType((MyGlobalEventEnum)EventTypeID); if (globalEvent != null) { return(MyTextsWrapper.Get(globalEvent.Name)); } break; case EventTypeEnum.MissionStarted: case EventTypeEnum.MissionFinished: case EventTypeEnum.SubmissionAvailable: case EventTypeEnum.SubmissionFinished: //case EventTypeEnum.Story: var mission = MyMissions.GetMissionByID((MyMissionID)EventTypeID); if (mission != null) { return(mission.NameTemp); } break; } return(null); //return MyTextsWrapperEnum.Null; }
public override void RecreateControls(bool contructor) { Controls.Clear(); m_scale = 0.7f; AddCaption(new System.Text.StringBuilder("Global Events Debug"), Color.Yellow.ToVector4()); MyGuiControlLabel label = new MyGuiControlLabel(this, new Vector2(0.01f, -m_size.Value.Y / 2.0f + 0.07f), null, new System.Text.StringBuilder("(press ALT to share focus)"), Color.Yellow.ToVector4(), MyGuiConstants.LABEL_TEXT_SCALE * 0.7f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_TOP); Controls.Add(label); m_currentPosition = -m_size.Value / 2.0f + new Vector2(0.12f, 0.15f); var globalEventEnumValues = Enum.GetValues(typeof(MyGlobalEventEnum)); foreach (MyGlobalEventEnum globalEventEnum in globalEventEnumValues) { var globalEvent = MyGlobalEvents.GetGlobalEventByType(globalEventEnum); var button = AddButton(MyTextsWrapper.Get(globalEvent.Name), OnGlobalEvent); button.UserData = globalEventEnum; } }
private void OnGlobalEvent(MyGuiControlButton sender) { if (MyGuiScreenGamePlay.Static != null) { var globalEventEnum = (MyGlobalEventEnum)sender.UserData; MyGlobalEvents.StartGlobalEvent(globalEventEnum); } }
void OnEvent(ref MyEventEvent msg) { var eventType = (MyGlobalEventEnum)msg.EventTypeEnum; if (!MyMwcEnums.IsValidValue(eventType)) { Alert("Invalid global event type", msg.SenderEndpoint, msg.EventType); } // TODO: When required, add position and seed MyGlobalEvents.StartGlobalEvent(eventType); }
public override void BeforeStart() { base.BeforeStart(); if (!Sync.IsServer) { return; } var meteorEvent = MyGlobalEvents.GetEventById(new MyDefinitionId(typeof(MyObjectBuilder_GlobalEventBase), "MeteorWave")); if (meteorEvent == null) { meteorEvent = MyGlobalEvents.GetEventById(new MyDefinitionId(typeof(MyObjectBuilder_GlobalEventBase), "MeteorWaveCataclysm")); } if (meteorEvent == null) { meteorEvent = MyGlobalEvents.GetEventById(new MyDefinitionId(typeof(MyObjectBuilder_GlobalEventBase), "MeteorWaveCataclysmUnreal")); } if (meteorEvent == null && MySession.Static.EnvironmentHostility != MyEnvironmentHostilityEnum.SAFE && MyFakes.ENABLE_METEOR_SHOWERS) { var globalEvent = MyGlobalEventFactory.CreateEvent(new MyDefinitionId(typeof(MyObjectBuilder_GlobalEventBase), "MeteorWave")); globalEvent.SetActivationTime(MyMeteorShower.CalculateShowerTime(MySession.Static.EnvironmentHostility)); MyGlobalEvents.AddGlobalEvent(globalEvent); } else if (meteorEvent != null) { if (MySession.Static.EnvironmentHostility == MyEnvironmentHostilityEnum.SAFE || !MyFakes.ENABLE_METEOR_SHOWERS) { meteorEvent.Enabled = false; } else { meteorEvent.Enabled = true; if (MySession.Static.PreviousEnvironmentHostility.HasValue) { if (MySession.Static.EnvironmentHostility != MySession.Static.PreviousEnvironmentHostility.Value) { meteorEvent.SetActivationTime( MyMeteorShower.CalculateShowerTime( MySession.Static.EnvironmentHostility, MySession.Static.PreviousEnvironmentHostility.Value, meteorEvent.ActivationTime)); MySession.Static.PreviousEnvironmentHostility = null; } } } } }
private static void RescheduleEvent(object senderEvent) { if (m_waveCounter > WAVES_IN_SHOWER) { TimeSpan time = CalculateShowerTime(MySession.Static.EnvironmentHostility); MyGlobalEvents.RescheduleEvent((MyGlobalEventBase)senderEvent, time); m_waveCounter = -1; m_currentTarget = null; MySyncMeteorShower.UpdateShowerTarget(m_currentTarget); } else { TimeSpan nextWave = TimeSpan.FromSeconds(m_meteorcount / 5f + MyUtils.GetRandomFloat(2, 5)); MyGlobalEvents.RescheduleEvent((MyGlobalEventBase)senderEvent, nextWave); } }
public StringBuilder GetDescription() //TODO: change this to MyTextsWrapperEnum { switch (EventType) { case EventTypeEnum.GlobalEvent: var globalEvent = MyGlobalEvents.GetGlobalEventByType((MyGlobalEventEnum)EventTypeID); return(MyTextsWrapper.Get(globalEvent.Description)); case EventTypeEnum.MissionStarted: case EventTypeEnum.MissionFinished: case EventTypeEnum.SubmissionAvailable: case EventTypeEnum.SubmissionFinished: //case EventTypeEnum.Story: var mission = MyMissions.GetMissionByID((MyMissionID)EventTypeID); return(mission.DescriptionTemp); } return(null); }
public override void BeforeStart() { base.BeforeStart(); if (!Sync.IsServer) { return; } var april2014Event = MyGlobalEvents.GetEventById(new MyDefinitionId(typeof(MyObjectBuilder_GlobalEventDefinition), "April2014")); bool eventEnabled = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day) == new DateTime(2014, 4, 1) || MyFakes.APRIL2014_ENABLED; if (april2014Event == null && eventEnabled) { var globalEvent = MyGlobalEventFactory.CreateEvent <MyGlobalEventBase>(new MyDefinitionId(typeof(MyObjectBuilder_GlobalEventDefinition), "April2014")); MyGlobalEvents.AddGlobalEvent(globalEvent); } else if (april2014Event != null) { april2014Event.Enabled &= eventEnabled; } }
public override bool HandleCommand(ulong userId, string[] words) { if (words.Length == 1 && words[0].ToLower( ) == "atmosphere") { CargoShips.SpawnCargoShip(false); return(true); } var cargoShipEvent = MyGlobalEvents.GetEventById(new MyDefinitionId(typeof(MyObjectBuilder_GlobalEventBase), "SpawnCargoShip")); if (cargoShipEvent == null) { //we can't force the game to spawn a ship if the option is off, so use our own method CargoShips.SpawnCargoShip(true); } else { MyGlobalEvents.RemoveGlobalEvent(cargoShipEvent); cargoShipEvent.SetActivationTime(TimeSpan.Zero); MyGlobalEvents.AddGlobalEvent(cargoShipEvent); } return(true); }
public MyTomasInputComponent() { AddShortcut(MyKeys.Delete, true, true, false, false, () => "Delete all characters", delegate { foreach (var obj in MyEntities.GetEntities().OfType <MyCharacter>()) { if (obj == MySession.ControlledEntity) { MySession.SetCameraController(MyCameraControllerEnum.Spectator); } obj.Close(); } foreach (var obj in MyEntities.GetEntities().OfType <MyCubeGrid>()) { foreach (var obj2 in obj.GetBlocks()) { if (obj2.FatBlock is MyCockpit) { var cockpit = obj2.FatBlock as MyCockpit; if (cockpit.Pilot != null) { cockpit.Pilot.Close(); } } } } return(true); }); AddShortcut(MyKeys.NumPad4, true, false, false, false, () => "Spawn cargo ship or barbarians", delegate { var theEvent = MyGlobalEvents.GetEventById(new MyDefinitionId(typeof(MyObjectBuilder_GlobalEventBase), "SpawnCargoShip")); if (theEvent == null) { theEvent = MyGlobalEvents.GetEventById(new MyDefinitionId(typeof(MyObjectBuilder_GlobalEventBase), "SpawnBarbarians")); } if (theEvent != null) { MyGlobalEvents.RemoveGlobalEvent(theEvent); theEvent.SetActivationTime(TimeSpan.FromSeconds(1)); MyGlobalEvents.AddGlobalEvent(theEvent); } return(true); }); AddShortcut(MyKeys.NumPad5, true, false, false, false, () => "Spawn random meteor", delegate { var camera = MySector.MainCamera; var target = camera.Position + MySector.MainCamera.ForwardVector * 20.0f; var spawnPosition = target + MySector.DirectionToSunNormalized * 1000.0f; if (MyUtils.GetRandomFloat(0.0f, 1.0f) < 0.2f) { MyMeteor.SpawnRandomLarge(spawnPosition, -MySector.DirectionToSunNormalized); } else { MyMeteor.SpawnRandomSmall(spawnPosition, -MySector.DirectionToSunNormalized); } return(true); }); AddShortcut(MyKeys.NumPad8, true, false, false, false, () => "Switch control to next entity", delegate { if (MySession.ControlledEntity != null) { //we already are controlling this object var cameraController = MySession.GetCameraControllerEnum(); if (cameraController != MyCameraControllerEnum.Entity && cameraController != MyCameraControllerEnum.ThirdPersonSpectator) { MySession.SetCameraController(MyCameraControllerEnum.Entity, MySession.ControlledEntity.Entity); } else { var entities = MyEntities.GetEntities().ToList(); int lastKnownIndex = entities.IndexOf(MySession.ControlledEntity.Entity); var entitiesList = new List <MyEntity>(); if (lastKnownIndex + 1 < entities.Count) { entitiesList.AddRange(entities.GetRange(lastKnownIndex + 1, entities.Count - lastKnownIndex - 1)); } if (lastKnownIndex != -1) { entitiesList.AddRange(entities.GetRange(0, lastKnownIndex + 1)); } MyCharacter newControlledObject = null; for (int i = 0; i < entitiesList.Count; i++) { var character = entitiesList[i] as MyCharacter; if (character != null) { newControlledObject = character; break; } } if (newControlledObject != null) { MySession.LocalHumanPlayer.Controller.TakeControl(newControlledObject); } } } return(true); }); AddShortcut(MyKeys.NumPad7, true, false, false, false, () => "Use next ship", delegate { MyCharacterInputComponent.UseNextShip(); return(true); }); AddShortcut(MyKeys.NumPad9, true, false, false, false, () => "Debug new grid screen", delegate { MyGuiSandbox.AddScreen(new DebugNewGridScreen()); return(true); }); AddShortcut(MyKeys.N, true, false, false, false, () => "Refill all batteries", delegate { foreach (var entity in MyEntities.GetEntities()) { MyCubeGrid grid = entity as MyCubeGrid; if (grid != null) { foreach (var block in grid.GetBlocks()) { MyBatteryBlock battery = block.FatBlock as MyBatteryBlock; if (battery != null) { battery.CurrentStoredPower = battery.MaxStoredPower; } } } } return(true); }); AddShortcut(MyKeys.U, true, false, false, false, () => "Spawn new character", delegate { var character = MyCharacterInputComponent.SpawnCharacter(); return(true); }); AddShortcut(MyKeys.NumPad2, true, false, false, false, () => "Merge static grids", delegate { // Try to merge all static large grids HashSet <MyCubeGrid> ignoredGrids = new HashSet <MyCubeGrid>(); while (true) { // Flag that we need new entities enumeration bool needNewEntitites = false; foreach (var entity in MyEntities.GetEntities()) { MyCubeGrid grid = entity as MyCubeGrid; if (grid != null && grid.IsStatic && grid.GridSizeEnum == MyCubeSize.Large) { if (ignoredGrids.Contains(grid)) { continue; } List <MySlimBlock> blocks = grid.GetBlocks().ToList(); foreach (var block in blocks) { var mergedGrid = grid.DetectMerge(block); if (mergedGrid == null) { continue; } needNewEntitites = true; // Grid merged to other grid? Then break and loop all entities again. if (mergedGrid != grid) { break; } } if (!needNewEntitites) { ignoredGrids.Add(grid); } } if (needNewEntitites) { break; } } if (!needNewEntitites) { break; } } return(true); }); AddShortcut(MyKeys.Add, true, false, false, false, () => "Increase wheel animation speed", delegate { USE_WHEEL_ANIMATION_SPEED += 0.05f; return(true); }); AddShortcut(MyKeys.Subtract, true, false, false, false, () => "Decrease wheel animation speed", delegate { USE_WHEEL_ANIMATION_SPEED -= 0.05f; return(true); }); AddShortcut(MyKeys.Divide, true, false, false, false, () => "Show model texture names", delegate { MyFakes.ENABLE_DEBUG_DRAW_TEXTURE_NAMES = !MyFakes.ENABLE_DEBUG_DRAW_TEXTURE_NAMES; return(true); }); AddShortcut(MyKeys.NumPad1, true, false, false, false, () => "Throw from spectator: " + Sandbox.Game.Components.MySessionComponentThrower.USE_SPECTATOR_FOR_THROW, delegate { Sandbox.Game.Components.MySessionComponentThrower.USE_SPECTATOR_FOR_THROW = !Sandbox.Game.Components.MySessionComponentThrower.USE_SPECTATOR_FOR_THROW; return(true); }); AddShortcut(MyKeys.F2, true, false, false, false, () => "Spectator to next small grid", () => SpectatorToNextGrid(MyCubeSize.Small)); AddShortcut(MyKeys.F3, true, false, false, false, () => "Spectator to next large grid", () => SpectatorToNextGrid(MyCubeSize.Large)); }
public void Resume() { if (MyFakes.MULTIPLAYER_DISABLED) { return; } IsWaiting = false; if (!IsHost) { // When host is disconnected in resume, he disconnected in load, so shutdown MP MyPlayerRemote host; if (!Peers.TryGetPlayer(Peers.HostUserId, out host)) { var handler = OnShutdown; if (handler != null) { handler(); } return; } } if (!IsHost) { MyGlobalEvents.DisableAllGlobalEvents(); } if (!IsHost || OtherPlayersConnected) //TODO: remove { RemoveUnsupportedEntities(); } if (!IsHost) { MakeAllEntitiesDummy(); } if (IsSandBox()) { LoadRespawnPoints(); } RegisterCallbacks(); if (!IsHost) { foreach (var p in Peers.Players) { if (p.Ship == null) // Ship can be already assigned (player has respawned before we finished loading) { var newShip = FindPlayerShip(p.PlayerId); if (newShip != null) { p.Ship = newShip; p.Faction = newShip.Faction; OnNewPlayerShip(p.Ship); } } } } if (!IsHost) { if (IsStory()) { MyMissions.Unload(); m_followMission = MyMissions.GetMissionByID(MyMissionID.COOP_FOLLOW_HOST) as MyFollowHostMission; if (m_followMission == null) { m_followMission = new MyFollowHostMission(); m_followMission.Location = new MyMissionBase.MyMissionLocation(MyGuiScreenGamePlay.Static.GetSectorIdentifier().Position, 0); MyMissions.AddMission(m_followMission); } m_followMission.SetHudName(Peers[Peers.HostUserId].GetDisplayName()); UpdateCoopTarget(); m_followMission.Accept(); } } m_processingBuffer = true; Peers.NetworkClient.ProcessBuffered(); m_processingBuffer = false; if (IsSandBox()) { if (IsHost) { MySession.Static.Player.Faction = ChooseFaction(); } } //DisableCheats(); if (!IsHost) { if (IsSandBox()) { // No faction, prevents respawn until server assigns faction MySession.Static.Player.Faction = MyMwcObjectBuilder_FactionEnum.None; } RequestFaction(MyMwcObjectBuilder_FactionEnum.None); } if (!IsStory() || !IsHost) { // Player's ship is dummy MySession.PlayerShip.IsDummy = true; m_respawnTime = MyMinerGame.TotalGamePlayTimeInMilliseconds; } else { m_respawnTime = Int32.MaxValue; } if (IsHost) { // Why is this set only for host? MySession.PlayerShip.ConfigChanged += m_onConfigChanged; MySession.PlayerShip.OnDie += m_onEntityDie; MySession.PlayerShip.InventoryChanged += m_onInventoryChanged; } // Hook entities (hook required events) foreach (var entity in MyEntities.GetEntities().OfType <MyCargoBox>()) { HookEntity(entity); } foreach (var entity in MyEntities.GetEntities().OfType <MyPrefabContainer>()) { HookEntity(entity); } SendGlobalFlag(MyGlobalFlagsEnum.REQUEST_INFO); }