/// <summary> /// Validates an outpost /// </summary> /// <param name="outpost">The outpost to validate</param> /// <returns>If the outpost is valid</returns> public static bool ValidateOutpost(GameState state, Outpost outpost) { if (outpost == null) { return(false); } if (!state.OutpostExists(outpost)) { return(false); } if (outpost.GetDrillerCount() < 0) { return(false); } if (outpost.GetSpecialistManager() == null) { return(false); } if (outpost.GetSpecialistManager().GetSpecialistCount() < 0) { return(false); } if (outpost.GetSpecialistManager().GetSpecialistCount() > outpost.GetSpecialistManager().GetCapacity()) { return(false); } if (outpost.GetOwner() != null && !state.PlayerExists(outpost.GetOwner())) { return(false); } return(true); }
/// <summary> /// Transfers ownership between outpost or specialists. /// </summary> /// <returns>If the event was successful</returns> public bool ForwardAction() { _originalOutpostOwner = _outpost.GetOwner(); _originalDrillerCount = _outpost.GetDrillerCount(); // Tie or sub won. if (_outpost.GetDrillerCount() < 0) { this.TransferOwnership(); } else { if (_outpost.GetDrillerCount() == 0) { // Was a tie. if (_sub.GetSpecialistManager().GetSpecialistCount() > _outpost.GetSpecialistManager().GetSpecialistCount()) { this.TransferOwnership(); } else { this.CaptureSub(); } } } this._eventSuccess = true; return(true); }
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()); }
void Update() { if (Input.GetMouseButtonDown(0)) { // Check if the pressed location was an outpost. If it was, the user is trying to launch a sub. RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); if (hit.collider != null && hit.collider.gameObject.tag == "Outpost") { // Clicked object is an outpost, don't move the camera. launchOutpost = hit.collider.gameObject.GetComponent <OutpostManager>().outpost; return; } } // If the mouse button is released, apply velocity to the map to scroll if (Input.GetMouseButtonUp(0)) { // If the first click was on an outpost, check if the second is on another outpost for a launch. if (launchOutpost != null && showLaunchHud == false) { // Check if the pressed location was an outpost. If it was, the user is trying to launch a sub. RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); if (hit.collider != null && hit.collider.gameObject.tag == "Outpost") { // Clicked object is an outpost, don't move the camera. destinationOutpost = hit.collider.gameObject.GetComponent <OutpostManager>().outpost; // only show the hud if the souce outpost is owned by the current player & the destination is not the source. if (launchOutpost != destinationOutpost && launchOutpost.GetOwner().GetId() == ApplicationState.player.GetId()) { SouceLaunchInformation sourcePanel = launchHud.GetComponentInChildren <SouceLaunchInformation>(); sourcePanel.source = launchOutpost; SubLaunchInformation informationPanel = launchHud.GetComponentInChildren <SubLaunchInformation>(); informationPanel.destination = destinationOutpost; informationPanel.sourceOutpost = launchOutpost; drillerSlider.maxValue = launchOutpost.GetDrillerCount(); this.SetLaunchHub(true); } else { launchOutpost = null; } } } else if (showLaunchHud) { // Determine if the click was in the panel if (EventSystem.current.IsPointerOverGameObject()) { return; } this.SetLaunchHub(false); } } }
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()); }
// Update is called once per frame void Update() { // Set color based on the owner textMesh.text = outpost.GetDrillerCount().ToString(); SpriteRenderer renderer = GetComponent <SpriteRenderer>(); int playerId = 0; if (outpost.GetOwner() != null) { playerId = Game.TimeMachine.GetState().GetPlayers().IndexOf(outpost.GetOwner()) + 1; } switch (playerId) { case 0: renderer.color = subSky; break; case 1: renderer.color = subRed; break; case 2: renderer.color = subOlive; break; case 3: renderer.color = subOrange; break; case 4: renderer.color = subPink; break; case 5: renderer.color = subBrown; break; case 6: renderer.color = subPurple; break; case 7: renderer.color = subBiege; break; } if (Input.GetMouseButtonDown(0)) { downtime = Time.time; return; } if (Input.GetMouseButtonUp(0)) { downtime = Time.time - downtime; } if (Input.GetMouseButton(0)) { return; } if (downtime < 0.25 && downtime > 0) { RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); if (hit.collider != null) { if (hit.collider.gameObject == gameObject && expanded == false) { hit.collider.gameObject.GetComponent <OutpostManager>().Expand(); //gameManager.SelectedOutpost = hit.transform.GetComponent<OutpostManager>().ID; } else { gameObject.GetComponent <OutpostManager>().Contract(); } } else { gameObject.GetComponent <OutpostManager>().Contract(); } downtime = 0; } }
// Update is called once per frame void Update() { // Set color based on the owner textMesh.text = outpost.GetDrillerCount().ToString(); // Determine the outpost vision mask. if (outpost.GetOwner()?.GetId() == ApplicationState.player.GetId()) { // Apply vision mask. gameObject.GetComponentInChildren <SpriteMask>().transform.localScale = new Vector3(outpost.getVisionRange() / 15.0f, outpost.getVisionRange() / 15.0f, 1); gameObject.GetComponentInChildren <TextMeshPro>().transform.localScale = new Vector3(1, 1, 1); } else { // remove vision mask. gameObject.GetComponentInChildren <SpriteMask>().transform.localScale = new Vector3(0, 0, 1); if (ApplicationState.CurrentGame.TimeMachine.GetState().isInVisionRange(outpost, ApplicationState.player)) { gameObject.GetComponentInChildren <TextMeshPro>().transform.localScale = new Vector3(1, 1, 1); } else { gameObject.GetComponentInChildren <TextMeshPro>().transform.localScale = new Vector3(0, 0, 1); } } SpriteRenderer renderer = GetComponent <SpriteRenderer>(); int playerId = 0; if (outpost.GetOwner() != null) { playerId = ApplicationState.CurrentGame.TimeMachine.GetState().GetPlayers().IndexOf(outpost.GetOwner()) + 1; } switch (playerId) { case 0: renderer.color = subGrey; break; case 1: renderer.color = subRed; break; case 2: renderer.color = subOlive; break; case 3: renderer.color = subOrange; break; case 4: renderer.color = subPink; break; case 5: renderer.color = subBrown; break; case 6: renderer.color = subPurple; break; case 7: renderer.color = subBiege; break; case 8: renderer.color = subSky; break; } if (Input.GetMouseButtonDown(0)) { downtime = Time.time; return; } if (Input.GetMouseButtonUp(0)) { downtime = Time.time - downtime; } if (Input.GetMouseButton(0)) { return; } if (downtime < 0.25 && downtime > 0) { RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); if (hit.collider != null) { if (hit.collider.gameObject == gameObject && expanded == false) { hit.collider.gameObject.GetComponent <OutpostManager>().Expand(); //gameManager.SelectedOutpost = hit.transform.GetComponent<OutpostManager>().ID; } else { gameObject.GetComponent <OutpostManager>().Contract(); } } else { gameObject.GetComponent <OutpostManager>().Contract(); } downtime = 0; } }