/// <summary> /// Gets a list of all of the GameEvents for the specified gameroom /// </summary> /// <param name="gameRoom">The id of the game room to fetch events for.</param> /// <returns>A list of game events</returns> public async Task <List <GameEvent> > GetGameEvents(int gameRoom) { var formContent = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("session_id", _sessionId), new KeyValuePair <string, string>("type", "get_events"), new KeyValuePair <string, string>("room_id", gameRoom.ToString()), }); HttpResponseMessage response = await Client.PostAsync(_url, formContent); // Read the response string responseContent = await response.Content.ReadAsStringAsync(); List <NetworkGameEvent> gameEventResponse = JsonConvert.DeserializeObject <List <NetworkGameEvent> >(responseContent); List <GameEvent> gameEvents = new List <GameEvent>(); // Parse network game events to game events. foreach (NetworkGameEvent gameEvent in gameEventResponse) { gameEvents.Add(LaunchEvent.FromJson(gameEvent.EventMsg)); } return(gameEvents); }
public void LaunchingASubTriggersAnOnLaunchEvent() { MockSubLauncherEntity(10, initialOwner, 3); Assert.IsNotNull(_mockEntity.Object.GetComponent <SubLauncher>()); OnSubLaunchEventArgs subLaunchEventData = null; _mockEntity.Object.GetComponent <SubLauncher>().OnSubLaunch += (sender, args) => { subLaunchEventData = args; }; var mockGameState = new Mock <IGameState>(); var launchEventData = new LaunchEventData() { DestinationId = "1", DrillerCount = 5, SourceId = "2" }; var launchEvent = new LaunchEvent(new GameEventModel() { EventData = launchEventData.ToByteString(), EventType = EventType.LaunchEvent, Id = "asdf", IssuedBy = initialOwner.GetId(), OccursAtTick = 1, RoomId = "1", UnixTimeIssued = 1234123412341234, }); RftVector.Map = new Rft(100, 100); var destination = new Generator(launchEventData.DestinationId, new RftVector(0, 0)); var source = new Generator(launchEventData.SourceId, new RftVector(0, 0)); mockGameState.Setup(it => it.GetEntity(launchEventData.SourceId)).Returns(source); mockGameState.Setup(it => it.GetEntity(launchEventData.DestinationId)).Returns(destination); Sub capturedSub = null; mockGameState.Setup(it => it.AddSub(It.IsAny <Sub>())).Callback <Sub>(sub => { capturedSub = sub; }); _mockEntity.Object.GetComponent <SubLauncher>().LaunchSub(mockGameState.Object, launchEvent); // Verify the sub was added to the state mockGameState.Verify(it => it.AddSub(subLaunchEventData.LaunchedSub), Times.Once); Assert.IsNotNull(capturedSub); Assert.AreEqual(destination, capturedSub.GetComponent <PositionManager>().GetDestination()); Assert.AreEqual(launchEventData.DrillerCount, capturedSub.GetComponent <DrillerCarrier>().GetDrillerCount()); Assert.AreEqual(initialOwner, capturedSub.GetComponent <DrillerCarrier>().GetOwner()); Assert.AreEqual(0, capturedSub.GetComponent <SpecialistManager>().GetSpecialistCount()); // Verify event data Assert.IsNotNull(subLaunchEventData); Assert.AreEqual(destination, subLaunchEventData.Destination); Assert.AreEqual(source, subLaunchEventData.Source); Assert.IsNotNull(subLaunchEventData.LaunchedSub); Assert.AreEqual(launchEventData.DrillerCount, subLaunchEventData.LaunchedSub.GetComponent <DrillerCarrier>().GetDrillerCount()); Assert.AreEqual(initialOwner, subLaunchEventData.LaunchedSub.GetComponent <DrillerCarrier>().GetOwner()); Assert.AreEqual(0, subLaunchEventData.LaunchedSub.GetComponent <SpecialistManager>().GetSpecialistCount()); }
public Sub LaunchSub(IGameState state, LaunchEvent launchEvent) { // Determine any specialist effects if a specialist left the sub. LaunchEventData launchData = launchEvent.GetEventData(); Entity source = state.GetEntity(launchData.SourceId); Entity destination = state.GetEntity(launchData.DestinationId); if (destination != null && _drillerCarrier.HasDrillers(launchData.DrillerCount)) { _drillerCarrier.RemoveDrillers(launchData.DrillerCount); Sub launchedSub = new Sub(launchEvent.GetEventId(), source, destination, state.GetCurrentTick(), launchData.DrillerCount, this._drillerCarrier.GetOwner()); this._specialistManager.TransferSpecialistsById(launchedSub.GetComponent <SpecialistManager>(), launchData.SpecialistIds.ToList()); state.AddSub(launchedSub); launchEvent.SetLaunchedSub(launchedSub); OnSubLaunch?.Invoke(this, new OnSubLaunchEventArgs() { Destination = destination, LaunchedSub = launchedSub, LaunchEvent = launchEvent, Source = source }); return(launchedSub); } return(null); }
public void CanLaunchSingleSub() { Outpost outpost1 = new Generator("0", new RftVector(new Rft(300, 300), 0, 0)); Outpost outpost2 = new Generator("1", new RftVector(new Rft(300, 300), 0, 0)); outpost1.GetComponent <DrillerCarrier>().SetOwner(_game.TimeMachine.GetState().GetPlayers()[0]); outpost2.GetComponent <DrillerCarrier>().SetOwner(_game.TimeMachine.GetState().GetPlayers()[1]); outpost1.GetComponent <DrillerCarrier>().SetDrillerCount(10); outpost2.GetComponent <DrillerCarrier>().SetDrillerCount(10); int outpostOneInitial = outpost1.GetComponent <DrillerCarrier>().GetDrillerCount(); _game.TimeMachine.GetState().GetOutposts().Add(outpost1); _game.TimeMachine.GetState().GetOutposts().Add(outpost2); LaunchEvent launch = new LaunchEvent(new GameEventModel() { EventData = new LaunchEventData() { DestinationId = outpost2.GetComponent <IdentityManager>().GetId(), DrillerCount = 1, SourceId = outpost1.GetComponent <IdentityManager>().GetId(), }.ToByteString(), Id = "a", EventType = EventType.LaunchEvent, OccursAtTick = 1, }); Assert.AreEqual(true, launch.ForwardAction(_game.TimeMachine, _game.TimeMachine.GetState())); // Ensure the sub was launched, outpost lost drillers, etc. Assert.AreEqual(1, _game.TimeMachine.GetState().GetSubList().Count); Assert.AreEqual(outpostOneInitial - 1, outpost1.GetComponent <DrillerCarrier>().GetDrillerCount()); }
public IEnumerator Launch() { if (!StatMaster.GodTools.InfiniteAmmoMode) { BulletCurrentNumber = (int)Mathf.MoveTowards(BulletCurrentNumber, 0, 1); } if (BulletCurrentNumber < 0 || !LaunchEnable) { yield break; } Rigidbody.AddForce(-transform.TransformDirection(Direction) * KnockBack /** 4000f*/, ForceMode.Impulse); GameObject bullet = (GameObject)Instantiate(BulletObject, transform.TransformPoint(SpawnPoint), transform.rotation, transform.root); bullet.SetActive(true); //bullet.GetComponent<BulletScript>().FireEnabled = true; //bullet.GetComponent<BulletScript>().OnCollisionEvent += () => { Debug.Log("bullet colli"); }; LaunchEvent?.Invoke(bullet); yield return(new WaitForSeconds(Rate)); LaunchEnable = false; yield break; }
public void CannotLaunchFromNonGeneratedOutposts() { Outpost outpost1 = new Outpost("0", new RftVector(new Rft(300, 300), 0, 0)); Outpost outpost2 = new Outpost("1", new RftVector(new Rft(300, 300), 0, 0)); int outpostOneInitial = outpost1.GetDrillerCount(); int outpostTwoInitial = outpost2.GetDrillerCount(); _game.TimeMachine.GetState().GetOutposts().Add(outpost1); _game.TimeMachine.GetState().GetOutposts().Add(outpost2); LaunchEvent launch = new LaunchEvent(new GameEventModel() { EventData = new LaunchEventData() { DestinationId = outpost2.GetId(), DrillerCount = 1, SourceId = outpost1.GetId(), }.ToByteString(), EventId = "a", EventType = EventType.LaunchEvent, OccursAtTick = 1, }); Assert.AreEqual(false, launch.ForwardAction(_game.TimeMachine, _game.TimeMachine.GetState())); }
public void launchSub() { LaunchEvent launchEvent = new LaunchEvent(Game.TimeMachine.CurrentTick, launchOutpost, (int)drillerSlider.value, destinationOutpost); Game.TimeMachine.AddEvent(launchEvent); api.SubmitGameEvent(launchEvent, ApplicationState.currentGameRoom.RoomId); this.SetLaunchHub(false); }
public void SubsArriveAfterLaunch() { Outpost outpost1 = new Generator("0", new RftVector(new Rft(300, 300), 0, 0)); Outpost outpost2 = new Generator("1", new RftVector(new Rft(300, 300), 0, 0)); outpost1.GetComponent <DrillerCarrier>().SetDrillerCount(10); outpost2.GetComponent <DrillerCarrier>().SetDrillerCount(5); outpost1.GetComponent <DrillerCarrier>().SetOwner(_game.TimeMachine.GetState().GetPlayers()[0]); outpost2.GetComponent <DrillerCarrier>().SetOwner(_game.TimeMachine.GetState().GetPlayers()[1]); int outpostOneInitial = outpost1.GetComponent <DrillerCarrier>().GetDrillerCount(); int outpostTwoInitial = outpost2.GetComponent <DrillerCarrier>().GetDrillerCount(); _game.TimeMachine.GetState().GetOutposts().Add(outpost1); _game.TimeMachine.GetState().GetOutposts().Add(outpost2); LaunchEvent launch1 = new LaunchEvent(new GameEventModel() { EventData = new LaunchEventData() { DestinationId = outpost2.GetComponent <IdentityManager>().GetId(), DrillerCount = 10, SourceId = outpost1.GetComponent <IdentityManager>().GetId(), }.ToByteString(), Id = "a", EventType = EventType.LaunchEvent, OccursAtTick = 1, }); Assert.AreEqual(true, launch1.ForwardAction(_game.TimeMachine, _game.TimeMachine.GetState())); // Ensure the sub was launched, outpost lost drillers, etc. Assert.AreEqual(1, _game.TimeMachine.GetState().GetSubList().Count); Assert.AreEqual(outpostOneInitial - 10, outpost1.GetComponent <DrillerCarrier>().GetDrillerCount()); // Ensure a combat event has been added. int combatEvents = 0; GameEvent combat = null; foreach (GameEvent gameEvent in _game.TimeMachine.GetQueuedEvents()) { if (gameEvent is CombatEvent) { combat = gameEvent; combatEvents++; } } Assert.AreEqual(1, combatEvents); // Go to the event and ensure the arrival is successful _game.TimeMachine.GoTo(combat); _game.TimeMachine.Advance(1); Assert.AreEqual(true, combat != null && combat.WasEventSuccessful()); Assert.AreEqual(outpost1.GetComponent <DrillerCarrier>().GetOwner(), outpost2.GetComponent <DrillerCarrier>().GetOwner()); Assert.AreEqual(Math.Abs(outpostTwoInitial - outpostOneInitial), outpost2.GetComponent <DrillerCarrier>().GetDrillerCount()); }
public void CannotLaunchFromNonGeneratedOutposts() { Outpost outpost1 = new Outpost(new RftVector(new Rft(300, 300), 0, 0)); Outpost outpost2 = new Outpost(new RftVector(new Rft(300, 300), 0, 0)); int outpostOneInitial = outpost1.GetDrillerCount(); int outpostTwoInitial = outpost2.GetDrillerCount(); LaunchEvent launch = new LaunchEvent(new GameTick(), outpost1, 1, outpost2); Assert.AreEqual(false, launch.ForwardAction()); }
public void UndoLaunch(GameState state, LaunchEvent launchEventData) { // Determine any specialist effects if a specialist left the sub. LaunchEventData launchData = launchEventData.GetEventData(); if (launchEventData.GetActiveSub() != null && launchEventData.GetActiveSub() is Sub) { Sub launchedSub = launchEventData.GetActiveSub() as Sub; this.AddDrillers(launchData.DrillerCount); launchedSub.GetSpecialistManager().transferSpecialistsTo(this._specialistManager); state.RemoveSub(launchEventData.GetActiveSub() as Sub); } }
public Sub LaunchSub(GameState state, LaunchEvent launchEventData) { LaunchEventData eventData = launchEventData.GetEventData(); ICombatable destination = state.GetCombatableById(eventData.DestinationId); if (destination != null && this.HasDrillers(eventData.DrillerCount)) { this.RemoveDrillers(eventData.DrillerCount); Sub launchedSub = new Sub(this._id, this, destination, state.GetCurrentTick(), eventData.DrillerCount, this.GetOwner()); state.AddSub(launchedSub); return(launchedSub); } return(null); }
public void CanLaunchSingleSub() { Outpost outpost1 = Game.TimeMachine.GetState().GetOutposts()[0]; Outpost outpost2 = Game.TimeMachine.GetState().GetOutposts()[1]; int outpostOneInitial = outpost1.GetDrillerCount(); int outpostTwoInitial = outpost2.GetDrillerCount(); LaunchEvent launch = new LaunchEvent(new GameTick(), outpost1, 1, outpost2); Assert.AreEqual(true, launch.ForwardAction()); // Ensure the sub was launched, outpost lost drillers, etc. Assert.AreEqual(1, Game.TimeMachine.GetState().GetSubList().Count); Assert.AreEqual(outpostOneInitial - 1, outpost1.GetDrillerCount()); }
public Sub LaunchSub(GameState state, LaunchEvent launchEvent) { // Determine any specialist effects if a specialist left the sub. LaunchEventData launchData = launchEvent.GetEventData(); ICombatable destination = state.GetCombatableById(launchData.DestinationId); if (destination != null && this.HasDrillers(launchData.DrillerCount)) { this.RemoveDrillers(launchData.DrillerCount); Sub launchedSub = new Sub(launchEvent.GetEventId(), this, destination, state.GetCurrentTick(), launchData.DrillerCount, this._owner); state.AddSub(launchedSub); return(launchedSub); } return(null); }
public void SubLaunchCreatesCombatEvents() { Outpost outpost1 = Game.TimeMachine.GetState().GetOutposts()[0]; Outpost outpost2 = Game.TimeMachine.GetState().GetOutposts()[2]; int outpostOneInitial = outpost1.GetDrillerCount(); int outpostTwoInitial = outpost2.GetDrillerCount(); LaunchEvent launch1 = new LaunchEvent(new GameTick(), outpost1, 1, outpost2); LaunchEvent launch2 = new LaunchEvent(new GameTick(), outpost2, 1, outpost1); Assert.AreEqual(true, launch1.ForwardAction()); Assert.AreEqual(true, launch2.ForwardAction()); // Ensure the sub was launched, outpost lost drillers, etc. Assert.AreEqual(2, Game.TimeMachine.GetState().GetSubList().Count); Assert.AreEqual(outpostOneInitial - 1, outpost1.GetDrillerCount()); Assert.AreEqual(outpostTwoInitial - 1, outpost2.GetDrillerCount()); // Ensure a combat event has been added that includes both subs. int subToSubBattles = 0; int subToOutpostBattles = 0; GameEvent arriveEvent = null; CombatEvent combatEvent = null; foreach (GameEvent gameEvent in Game.TimeMachine.GetQueuedEvents()) { if (gameEvent is CombatEvent) { combatEvent = (CombatEvent)gameEvent; if (combatEvent.GetCombatants()[0] is Sub && combatEvent.GetCombatants()[1] is Sub) { subToSubBattles++; } else { subToOutpostBattles++; arriveEvent = gameEvent; } } } // There should be 3 combats, one on each outpost, one on both subs. Assert.AreEqual(1, subToSubBattles); Assert.AreEqual(2, subToOutpostBattles); }
public void launchSub() { LaunchEvent launchEvent = new LaunchEvent( new GameEventModel() { EventData = new LaunchEventData() { SourceId = launchOutpost.GetId(), DestinationId = destinationOutpost.GetId(), DrillerCount = (int)drillerSlider.value, SpecialistIds = { }, }.ToByteString(), OccursAtTick = ApplicationState.CurrentGame.TimeMachine.GetCurrentTick().GetTick(), }); ApplicationState.CurrentGame.TimeMachine.AddEvent(launchEvent); this.SetLaunchHub(false); // Submit event to online services. if (ApplicationState.CurrentGame.Configuration.IsMultiplayer) { var client = ApplicationState.Client.getClient(); var response = client.SubmitGameEvent(new SubmitGameEventRequest() { EventData = new GameEventRequest() { EventData = launchEvent.ToGameEventModel().ToByteString(), EventType = launchEvent.GetEventType(), OccursAtTick = launchEvent.GetOccursAt().GetTick(), }, RoomId = ApplicationState.currentGameRoom.RoomId }); if (!response.Status.IsSuccess) { ApplicationState.CurrentGame.TimeMachine.RemoveEvent(launchEvent); // Indicate an error, don't add to time machine. } } }
public void UndoLaunch(IGameState state, LaunchEvent launchEvent) { // Determine any specialist effects if a specialist left the sub. LaunchEventData launchData = launchEvent.GetEventData(); if (launchEvent.GetActiveSub() != null) { Sub launchedSub = launchEvent.GetActiveSub(); _drillerCarrier.AddDrillers(launchData.DrillerCount); launchedSub.GetComponent <SpecialistManager>().TransferSpecialistsTo(_specialistManager); state.RemoveSub(launchEvent.GetActiveSub()); OnUndoSubLaunch?.Invoke(this, new OnUndoSubLaunchEventArgs() { Destination = state.GetEntity(launchData.DestinationId), LaunchedSub = launchedSub, LaunchEvent = launchEvent, Source = state.GetEntity(launchData.SourceId) }); } }
public void CanGetTheLaunchedSub() { Outpost outpost1 = new Outpost("0", new RftVector(new Rft(300, 300), 0, 0)); Outpost outpost2 = new Outpost("1", new RftVector(new Rft(300, 300), 0, 0)); outpost1.SetDrillerCount(10); outpost2.SetDrillerCount(10); outpost1.SetOwner(_game.TimeMachine.GetState().GetPlayers()[0]); outpost2.SetOwner(_game.TimeMachine.GetState().GetPlayers()[1]); int outpostOneInitial = outpost1.GetDrillerCount(); int outpostTwoInitial = outpost2.GetDrillerCount(); _game.TimeMachine.GetState().GetOutposts().Add(outpost1); _game.TimeMachine.GetState().GetOutposts().Add(outpost2); LaunchEvent launch = new LaunchEvent(new GameEventModel() { EventData = new LaunchEventData() { DestinationId = outpost2.GetId(), DrillerCount = 1, SourceId = outpost1.GetId(), }.ToByteString(), EventId = "a", EventType = EventType.LaunchEvent, OccursAtTick = 1, }); Assert.AreEqual(true, launch.ForwardAction(_game.TimeMachine, _game.TimeMachine.GetState())); // Ensure the sub was launched, outpost lost drillers, etc. Assert.AreEqual(1, _game.TimeMachine.GetState().GetSubList().Count); Assert.AreEqual(outpostOneInitial - 1, outpost1.GetDrillerCount()); // Ensure can get the sub. Assert.IsNotNull(_game.TimeMachine.GetState().GetSubList()[0]); Assert.AreEqual(1, _game.TimeMachine.GetState().GetSubList()[0].GetDrillerCount()); Assert.AreEqual(outpost1, _game.TimeMachine.GetState().GetSubList()[0].GetSource()); Assert.AreEqual(outpost2, _game.TimeMachine.GetState().GetSubList()[0].GetDestination()); }
public void SubsArriveAfterLaunch() { Outpost outpost1 = Game.TimeMachine.GetState().GetOutposts()[0]; Outpost outpost2 = Game.TimeMachine.GetState().GetOutposts()[1]; int outpostOneInitial = outpost1.GetDrillerCount(); int outpostTwoInitial = outpost2.GetDrillerCount(); LaunchEvent launch1 = new LaunchEvent(new GameTick(), outpost1, 1, outpost2); Assert.AreEqual(true, launch1.ForwardAction()); // Ensure the sub was launched, outpost lost drillers, etc. Assert.AreEqual(1, Game.TimeMachine.GetState().GetSubList().Count); Assert.AreEqual(outpostOneInitial - 1, outpost1.GetDrillerCount()); // Ensure a combat event has been added. int combatEvents = 0; GameEvent combat = null; foreach (GameEvent gameEvent in Game.TimeMachine.GetQueuedEvents()) { if (gameEvent is CombatEvent) { combat = gameEvent; combatEvents++; } } Assert.AreEqual(1, combatEvents); // Go to the event and ensure the arrival is successful Game.TimeMachine.GoTo(combat); Game.TimeMachine.Advance(1); Assert.AreEqual(true, combat.WasEventSuccessful()); Assert.AreEqual(outpost1.GetOwner(), outpost2.GetOwner()); Assert.AreEqual(1, outpost2.GetDrillerCount()); }
public void CanUndoSubLaunch() { List <Player> players = new List <Player>(); players.Add(new Player("1")); GameConfiguration config = new GameConfiguration(players, DateTime.Now, new MapConfiguration(players)); Game game = new Game(config); game.TimeMachine.GetState().GetOutposts().Add(_outpost); game.TimeMachine.GetState().GetOutposts().Add(_outpost2); var launchEvent = new LaunchEvent(new GameEventModel() { EventData = new LaunchEventData() { DestinationId = _outpost2.GetId(), DrillerCount = 10, SourceId = _outpost.GetId(), }.ToByteString(), EventId = "123", EventType = EventType.LaunchEvent, OccursAtTick = 10, }); int initialDrillers = _outpost.GetDrillerCount(); launchEvent.ForwardAction(game.TimeMachine, game.TimeMachine.GetState()); Assert.AreEqual(initialDrillers - 10, _outpost.GetDrillerCount()); Assert.AreEqual(1, game.TimeMachine.GetState().GetSubList().Count); launchEvent.BackwardAction(game.TimeMachine, game.TimeMachine.GetState()); Assert.AreEqual(initialDrillers, _outpost.GetDrillerCount()); Assert.AreEqual(0, game.TimeMachine.GetState().GetSubList().Count); }
public void SubLaunchCreatesCombatEvents() { Outpost outpost1 = new Generator("0", new RftVector(new Rft(300, 300), 0, 0)); Outpost outpost2 = new Generator("1", new RftVector(new Rft(300, 300), 0, 0)); outpost1.GetComponent <DrillerCarrier>().SetDrillerCount(10); outpost2.GetComponent <DrillerCarrier>().SetDrillerCount(10); outpost1.GetComponent <DrillerCarrier>().SetOwner(_game.TimeMachine.GetState().GetPlayers()[0]); outpost2.GetComponent <DrillerCarrier>().SetOwner(_game.TimeMachine.GetState().GetPlayers()[1]); int outpostOneInitial = outpost1.GetComponent <DrillerCarrier>().GetDrillerCount(); int outpostTwoInitial = outpost2.GetComponent <DrillerCarrier>().GetDrillerCount(); _game.TimeMachine.GetState().GetOutposts().Add(outpost1); _game.TimeMachine.GetState().GetOutposts().Add(outpost2); LaunchEvent launch1 = new LaunchEvent(new GameEventModel() { EventData = new LaunchEventData() { DestinationId = outpost2.GetComponent <IdentityManager>().GetId(), DrillerCount = 1, SourceId = outpost1.GetComponent <IdentityManager>().GetId(), }.ToByteString(), Id = "a", EventType = EventType.LaunchEvent, OccursAtTick = 1, }); LaunchEvent launch2 = new LaunchEvent(new GameEventModel() { EventData = new LaunchEventData() { DestinationId = outpost1.GetComponent <IdentityManager>().GetId(), DrillerCount = 1, SourceId = outpost2.GetComponent <IdentityManager>().GetId(), }.ToByteString(), Id = "a", EventType = EventType.LaunchEvent, OccursAtTick = 1, }); Assert.AreEqual(true, launch1.ForwardAction(_game.TimeMachine, _game.TimeMachine.GetState())); Assert.AreEqual(true, launch2.ForwardAction(_game.TimeMachine, _game.TimeMachine.GetState())); // Ensure the sub was launched, outpost lost drillers, etc. Assert.AreEqual(2, _game.TimeMachine.GetState().GetSubList().Count); Assert.AreEqual(outpostOneInitial - 1, outpost1.GetComponent <DrillerCarrier>().GetDrillerCount()); Assert.AreEqual(outpostTwoInitial - 1, outpost2.GetComponent <DrillerCarrier>().GetDrillerCount()); // Ensure a combat event has been added that includes both subs. int subToSubBattles = 0; int subToOutpostBattles = 0; foreach (GameEvent gameEvent in _game.TimeMachine.GetQueuedEvents()) { if (gameEvent is CombatEvent) { var combatEvent = (CombatEvent)gameEvent; if (combatEvent.GetCombatants()[0] is Sub && combatEvent.GetCombatants()[1] is Sub) { subToSubBattles++; } else { subToOutpostBattles++; } } } // There should be 3 combats, one on each outpost, one on both subs. // TODO: Once subs on path is fixed, Update this. It should be 1. Assert.AreEqual(0, subToSubBattles); Assert.AreEqual(2, subToOutpostBattles); }
void HandleMessage(string msg, dynamic args, Request request) { LogDebug("(in) " + request.type + " " + msg); LogVerbose("... " + JsonConvert.SerializeObject(request)); args = args ?? new { }; try { switch (msg) { case "initialize": var cap = new Capabilities(); InitializeEvent?.Invoke(request, cap); Send(request, cap); Initialized(); break; case "configurationDone": ConfigurationDoneEvent?.Invoke(request); break; case "launch": LaunchEvent?.Invoke(request, JsonConvert.SerializeObject(args)); break; case "attach": AttachEvent?.Invoke(request, JsonConvert.SerializeObject(args)); break; case "disconnect": DisconnectEvent?.Invoke(request); break; case "next": StepOverEvent?.Invoke(request); break; case "continue": ContinueEvent?.Invoke(request); break; case "stepIn": StepInEvent?.Invoke(request); break; case "stepOut": StepOutEvent?.Invoke(request); break; case "pause": PauseEvent?.Invoke(request); break; case "threads": GetThreadsEvent?.Invoke(request); break; case "scopes": GetScopesEvent?.Invoke(request, (int)args.frameId); break; case "stackTrace": GetStackTraceEvent?.Invoke(request); break; case "variables": _tempVariables.Clear(); GetVariablesEvent?.Invoke(request, (int)args.variablesReference, _tempVariables); Send(request, new VariablesResponseBody(_tempVariables)); break; case "setVariable": var variable = new Variable((string)args.name, (string)args.value, "", (int)args.variablesReference); SetVariableEvent?.Invoke( request, variable ); Send( request, new SetVariableResponseBody(variable.value, variable.variablesReference) ); break; case "loadedSources": GetLoadedSourcesEvent?.Invoke(request); break; case "source": GetSourceEvent?.Invoke(request); break; case "evaluate": string resultEval = ""; EvaluateEvent?.Invoke( request, (int)args.frameId, (string)args.context, (string)args.expression, (bool)(args.format?.hex ?? false), ref resultEval ); Send( request, new EvaluateResponseBody( resultEval ) ); break; case "completions": GetCompletionsEvent?.Invoke( request, (int)args.frameId, (int)args.line, (int)args.column, (string )args.text ); break; case "setBreakpoints": SetBreakpointsEvent?.Invoke(request); break; // case "runInTerminal": // OnRunInTerminal?.Invoke( pRequest ); // break; // case "setFunctionBreakpoints": // SetFunctionBreakpoints( pResponse, pArgs ); // break; // case "setExceptionBreakpoints": // SetExceptionBreakpoints( pResponse, pArgs ); // break; default: CustomRequestEvent?.Invoke(request); if (!request.responded) { Log( Logging.Severity.Error, string.Format("Request not handled: '{0}' [{1}]", msg, Convert.Encode(request.arguments.ToString())) ); } break; } } catch (Exception e) { Log( Logging.Severity.Error, $"Error during request '{Convert.Encode( request.arguments.ToString() )}' [{msg}] (exception: {e.Message})\n{e}" ); Send(new Response(request, errorMsg: e.Message)); } }