public void CanLaunchSubs() { 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); int initialDrillers = _outpost.GetDrillerCount(); _outpost.LaunchSub(game.TimeMachine.GetState(), new LaunchEvent(new GameEventModel() { EventData = new LaunchEventData() { DestinationId = _outpost.GetId(), DrillerCount = 10, SourceId = _outpost2.GetId(), }.ToByteString(), EventId = "123", EventType = EventType.LaunchEvent, OccursAtTick = 10, })); Assert.AreEqual(initialDrillers - 10, _outpost.GetDrillerCount()); Assert.AreEqual(1, game.TimeMachine.GetState().GetSubList().Count); }
public void CanLaunchSingleSub() { 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); 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()); }
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 SubsArriveAfterLaunch() { 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(5); 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 launch1 = new LaunchEvent(new GameEventModel() { EventData = new LaunchEventData() { DestinationId = outpost2.GetId(), DrillerCount = 10, SourceId = outpost1.GetId(), }.ToByteString(), EventId = "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.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(Math.Abs(outpostTwoInitial - outpostOneInitial), outpost2.GetDrillerCount()); }
// Update is called once per frame void Update() { Text text = gameObject.GetComponentInChildren <Text>(); text.text = "====Source Outpost====\n" + "Outpost Id: " + source.GetId() + "\n" + "Shields: " + source.GetShields() + "\n" + "Drillers: " + source.GetDrillerCount() + "\n" + "Specialists: " + source.GetSpecialistManager().GetSpecialistCount(); }
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 SubLaunchCreatesCombatEvents() { 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 launch1 = new LaunchEvent(new GameEventModel() { EventData = new LaunchEventData() { DestinationId = outpost2.GetId(), DrillerCount = 1, SourceId = outpost1.GetId(), }.ToByteString(), EventId = "a", EventType = EventType.LaunchEvent, OccursAtTick = 1, }); LaunchEvent launch2 = new LaunchEvent(new GameEventModel() { EventData = new LaunchEventData() { DestinationId = outpost1.GetId(), DrillerCount = 1, SourceId = outpost2.GetId(), }.ToByteString(), EventId = "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.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); }