public static void endActionPhase() { if (MatchDatas.getCurrentPhase().Equals(MatchDatas.phases.ACTION) && !prevPhase.Equals(MatchDatas.phases.NONE)) { MatchDatas.setCurrentPhase(prevPhase); prevPhase = MatchDatas.phases.NONE; } }
void OnMouseDrag() { if (target == null) { RaycastHit hitInfo; target = ReturnClickedObject(out hitInfo); } float moveX = Input.GetAxis("Mouse X"); float moveY = Input.GetAxis("Mouse Y"); if (target.GetComponent <ShipProperties>() != null) { if (MatchDatas.getCurrentPhase() == MatchDatas.phases.SQUADRON_PLACEMENT && shipCanBeMoved()) { Vector3 newPos = new Vector3(transform.position.x + (moveX * dragSpeedMultiplier), transform.position.y, transform.position.z + (moveY * dragSpeedMultiplier)); transform.position = newPos; /*Prototype to highlight setup field boundaries when ship is not inside them. POLISH!!!!*/ if (!GameObject.Find("Player1SetupField").GetComponent <Collider>().bounds.Contains(target.transform.position)) { GameObject.Find("Player1SetupField/New Sprite").gameObject.GetComponent <SpriteRenderer>().color = new Color(1.0f, 0.0f, 0.0f, 0.31f); } else { GameObject.Find("Player1SetupField/New Sprite").gameObject.GetComponent <SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, 0.31f); } /*Prototype to highlight setup field boundaries when ship is not inside them. POLISH!!!!*/ } } if (target.GetComponent <AsteroidProperties>() != null) { if (MatchDatas.getCurrentPhase() == MatchDatas.phases.ASTEROIDS_PLACEMENT && asteroidCanBeMoved()) { Vector3 newPos = new Vector3(transform.position.x + (moveX * dragSpeedMultiplier), transform.position.y, transform.position.z + (moveY * dragSpeedMultiplier)); transform.position = newPos; } } }
// TODO Make this class handle all phase changes and the required checks, cleanups, inits, etc..... public static void nextPhase() { Debug.Log("Initiating next phase from " + MatchDatas.getCurrentPhase()); switch (MatchDatas.getCurrentPhase()) { case MatchDatas.phases.INITIATIVE_ROLL: startAsteroidPlacementPhase(); break; case MatchDatas.phases.ASTEROIDS_PLACEMENT: startSquadronPlacementPhase(); break; case MatchDatas.phases.SQUADRON_PLACEMENT: startPlanningPhase(); break; case MatchDatas.phases.PLANNING: startActivationPhase(); break; case MatchDatas.phases.ACTIVATION: startAttackPhase(); break; case MatchDatas.phases.ATTACK: startEndPhase(); break; case MatchDatas.phases.END: if (!isMatchOver()) { startPlanningPhase(); } else { // TODO Finish game! } break; } }
void Update() { if (Input.GetMouseButtonDown(0)) { RaycastHit hitInfo; target = ReturnClickedObject(out hitInfo); if (target != null) { if (!grabbed) { if ((MatchDatas.getActiveShip() == null || MatchDatas.getActiveShip() != target) && target.GetComponent <ShipProperties>() != null) { MatchHandlerUtil.hideActiveShipHighlighters(); MatchHandlerUtil.hideFiringArcs(); LoadedShip activeShip = new LoadedShip(); ShipProperties sp = target.GetComponent <ShipProperties>(); activeShip = sp.getLoadedShip(); MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].setActiveShip(activeShip); MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].setSelectedShip(activeShip); MatchHandlerUtil.setShipHighlighters(target, true); MatchDatas.setActiveShip(target); } } if (MatchDatas.getCurrentPhase() == MatchDatas.phases.SQUADRON_PLACEMENT || MatchDatas.getCurrentPhase() == MatchDatas.phases.ASTEROIDS_PLACEMENT) { Cursor.visible = false; grabbed = true; prevPos = target.transform.position; } else if (MatchDatas.getCurrentPhase() == MatchDatas.phases.ACTIVATION && target.GetComponent <ShipProperties>() != null) { foreach (LoadedShip ship in MatchHandler.getAvailableShips()) { if ( target.transform.GetComponent <ShipProperties>().getLoadedShip().getShip().ShipId.Equals(ship.getShip().ShipId) && target.transform.GetComponent <ShipProperties>().getLoadedShip().getPilotId() == ship.getPilotId() && !target.transform.GetComponent <ShipProperties>().getLoadedShip().isHasBeenActivatedThisRound() ) { target.transform.GetComponent <ShipProperties>().getLoadedShip().setHasBeenActivatedThisRound(true); StartCoroutine(GameObject.Find("ScriptHolder").GetComponent <CoroutineHandler>().MoveShipOverTime(target, target.transform.GetComponent <ShipProperties>().getLoadedShip().getPlannedManeuver())); } } } } } if (Input.GetMouseButtonUp(0) && grabbed) { Cursor.visible = true; grabbed = false; if (target.GetComponent <ShipProperties>() != null) { GameObject shipCollection = GameObject.Find("ShipCollection1"); GameObject setupField = GameObject.Find("Player1SetupField"); // TODO check if this part can be simplyfied.... if (!shipCollection.GetComponent <Collider>().bounds.Contains(target.transform.position) && !setupField.GetComponent <Collider>().bounds.Contains(target.transform.position)) { target.transform.position = prevPos; } else { if (setupField.GetComponent <Collider>().bounds.Contains(target.transform.position) && shipCanBeMoved()) { togglePositionConfirmButton(true); } } if (!setupField.GetComponent <Collider>().bounds.Contains(target.transform.position)) { togglePositionConfirmButton(false); } // TODO check if this part can be simplyfied.... } if (target.GetComponent <AsteroidProperties>() != null) { GameObject playField = GameObject.Find("Playfield"); // TODO Check distance from playfield borders and other asteroids!! if (!playField.GetComponent <Collider>().bounds.Contains(target.transform.position) || isAsteroidTooClose()) { target.transform.position = prevPos; } else { if (allAsteroidsAreInsidePlayfield()) { togglePositionConfirmButton(true); } } } } if (grabbed && MatchDatas.getCurrentPhase() == MatchDatas.phases.SQUADRON_PLACEMENT && shipCanBeMoved()) { if (Input.GetAxis("Mouse ScrollWheel") > 0f) // forward { target.transform.RotateAround(target.transform.position, target.transform.TransformDirection(Vector3.up), 2.5f); } else if (Input.GetAxis("Mouse ScrollWheel") < 0f) // backwards { target.transform.RotateAround(target.transform.position, target.transform.TransformDirection(Vector3.up), -2.5f); } } }
public static void initActionPhase() { prevPhase = MatchDatas.getCurrentPhase(); MatchDatas.setCurrentPhase(MatchDatas.phases.ACTION); }
// TODO Can we make the method calls inside to run only ONCE(!), when necessary?? Custom eventhandling maybe???? void Update() { matchHandlerService.levitateShips(); matchHandlerService.rotateAsteroids(); if (Input.GetKey("escape")) { // TODO Not active player, LOCAL PLAYER!!! (Maybe simply hiding the panel on the client side is enough....) MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].setSelectedShip(null); //guiHandler.hideGameObject(PilotCardPanel); } //THIS IS ONLY FOR TESTING MOVEMENTS!!!!!! DELETE LATER ON!!!! (Also, ADD UNIQUE IDs during squad building to ships and pilots!!!! [use something like: playerIndex_shipIndex]) Maneuver man = new Maneuver(); man.Difficulty = "1"; for (int i = 0; i < keyCodes.Length; i++) { if (Input.GetKeyDown(keyCodes[i])) { int n; bool isNumeric = int.TryParse(keyCodes[i], out n); if (isNumeric) { int s = Int32.Parse(keyCodes[i]); if (s < 6) { man.Bearing = "straight"; man.Speed = keyCodes[i]; } else { man.Bearing = "koiogran"; man.Speed = (s - 5).ToString(); } } else { switch (keyCodes[i]) { case "v": case "g": case "t": case "i": case "k": case "m": man.Bearing = "turn_left"; man.Speed = "1"; if (keyCodes[i].Equals("i") || keyCodes[i].Equals("k") || keyCodes[i].Equals("m")) { man.Bearing = "turn_right"; } if (keyCodes[i].Equals("g") || keyCodes[i].Equals("k")) { man.Speed = "2"; } if (keyCodes[i].Equals("t") || keyCodes[i].Equals("i")) { man.Speed = "3"; } break; case "b": case "h": case "z": case "u": case "j": case "n": man.Bearing = "bank_left"; man.Speed = "1"; if (keyCodes[i].Equals("u") || keyCodes[i].Equals("j") || keyCodes[i].Equals("n")) { man.Bearing = "bank_right"; } if (keyCodes[i].Equals("h") || keyCodes[i].Equals("j")) { man.Speed = "2"; } if (keyCodes[i].Equals("z") || keyCodes[i].Equals("u")) { man.Speed = "3"; } break; } } } } //THIS IS ONLY FOR TESTING MOVEMENTS!!!!!! DELETE LATER ON!!!! //StartCoroutine(GameObject.Find("ScriptHolder").GetComponent<CoroutineHandler>().MoveShipOverTime(GameObject.FindGameObjectsWithTag("SmallShipContainer")[1], man)); //THIS IS ONLY FOR TESTING MOVEMENTS!!!!!! DELETE LATER ON!!!! if (MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].getSelectedhip() != null) { //TODO Check if comparing pilot names is enough/the right way!!!!!!! if (!PilotCardPanel.transform.Find("PilotName").gameObject.GetComponent <UnityEngine.UI.Text>().text.Equals(MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].getSelectedhip().getPilot().Name.ToLower())) { guiHandler.hideGameObject(PilotCardPanel); } if (!PilotCardPanel.activeSelf) { guiHandler.showPilotCard(PilotCardPanel); matchHandlerService.showFiringArc(matchHandlerService.getShipHolderForShip(MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].getSelectedhip())); if (MatchDatas.getCurrentPhase() == MatchDatas.phases.PLANNING && MatchHandlerUtil.isPlayersOwnShip()) { guiHandler.showManeuverSelector(PilotCardPanel); } } } else { MatchHandlerUtil.hideActiveShipHighlighters(); MatchHandlerUtil.hideFiringArcs(); MatchDatas.setActiveShip(null); guiHandler.hideGameObject(PilotCardPanel); } if (MatchDatas.getCurrentPhase() == MatchDatas.phases.SQUADRON_PLACEMENT) { updateInfoPanel(SQUADRON_PLACEMENT_INFO); } if (MatchDatas.getCurrentPhase() == MatchDatas.phases.PLANNING) { updateInfoPanel(PLANNING_INFO); if (MatchHandlerUtil.maneuversPlanned()) { updateInfoPanel(EMPTY_TEXT); PhaseHandlerService.nextPhase(); } } if (MatchDatas.getCurrentPhase() == MatchDatas.phases.ACTIVATION) { // TODO Only show this to the current player!! if (availableShips.Count > 1) { foreach (LoadedShip ship in availableShips) { foreach (GameObject go in GameObject.FindGameObjectsWithTag("SmallShipContainer")) { if (go.transform.GetComponent <ShipProperties>().getLoadedShip().getShip().ShipId.Equals(ship.getShip().ShipId) && go.transform.GetComponent <ShipProperties>().getLoadedShip().getPilotId() == ship.getPilotId()) { updateInfoPanel(MULTIPLE_AVAILABLE_SHIPS_INFO); MatchHandlerUtil.setShipHighlighters(go, true); } } } } else if (availableShips.Count == 1) { // DUPLICATED IN GameObjectDragAndDrop!! foreach (GameObject go in GameObject.FindGameObjectsWithTag("SmallShipContainer")) { if ( go.transform.GetComponent <ShipProperties>().getLoadedShip().getShip().ShipId.Equals(availableShips[0].getShip().ShipId) && go.transform.GetComponent <ShipProperties>().getLoadedShip().getPilotId() == availableShips[0].getPilotId() && !go.transform.GetComponent <ShipProperties>().getLoadedShip().isHasBeenActivatedThisRound() ) { go.transform.GetComponent <ShipProperties>().getLoadedShip().setHasBeenActivatedThisRound(true); StartCoroutine(GameObject.Find("ScriptHolder").GetComponent <CoroutineHandler>().MoveShipOverTime(go, go.transform.GetComponent <ShipProperties>().getLoadedShip().getPlannedManeuver())); } } } else { updateInfoPanel(EMPTY_TEXT); MatchHandlerUtil.hideActiveShipHighlighters(); PhaseHandlerService.nextPhase(); } } }
public static void collectUpcomingAvailableShips(bool ascending) { List <LoadedShip> ships1 = MatchDatas.getPlayers()[0].getNextShips(MatchDatas.getCurrentLevel(), ascending); List <LoadedShip> ships2 = MatchDatas.getPlayers()[1].getNextShips(MatchDatas.getCurrentLevel(), ascending); // TODO add this bit when 3 player rules are getting included! //LoadedShip ship3 = MatchDatas.getPlayers()[2].getNextShip(MatchDatas.getCurrentLevel(), ascending); bool ship1IsEmpty = ships1 == null || ships1.Capacity == 0; bool ship2IsEmpty = ships2 == null || ships2.Capacity == 0; if (ship1IsEmpty && ship2IsEmpty) { PhaseHandlerService.nextPhase(); } else { if (ship1IsEmpty && !ship2IsEmpty) { availableShips = ships2; MatchDatas.setActivePlayerIndex(1); } if (ship2IsEmpty && !ship1IsEmpty) { availableShips = ships1; MatchDatas.setActivePlayerIndex(0); } if (!ship1IsEmpty && !ship2IsEmpty) { if (ships1[0].getPilot().Level == ships2[0].getPilot().Level) { foreach (LoadedShip ship in ships1) { if (!ship.isHasBeenActivatedThisRound() && MatchDatas.getPlayers()[0].getHasInitiative()) { availableShips = ships1; MatchDatas.setActivePlayerIndex(0); break; } } foreach (LoadedShip ship in ships2) { if (!ship.isHasBeenActivatedThisRound() && MatchDatas.getPlayers()[1].getHasInitiative()) { availableShips = ships2; MatchDatas.setActivePlayerIndex(1); break; } } } else { if (ascending) { if (ships1[0].getPilot().Level < ships2[0].getPilot().Level) { availableShips = ships1; MatchDatas.setActivePlayerIndex(0); } else { availableShips = ships2; MatchDatas.setActivePlayerIndex(1); } } else { if (ships1[0].getPilot().Level > ships2[0].getPilot().Level) { availableShips = ships1; MatchDatas.setActivePlayerIndex(0); } else { availableShips = ships2; MatchDatas.setActivePlayerIndex(1); } } } } if (MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].isAI() && MatchDatas.getCurrentPhase() == MatchDatas.phases.SQUADRON_PLACEMENT) { moveAIShips(ascending); } } }
public void OnPointerClick(PointerEventData eventData) { Debug.Log("Action name: " + this.actionName); Debug.Log("PHASE: " + MatchDatas.getCurrentPhase()); if (MatchDatas.getCurrentPhase() == MatchDatas.phases.ACTION) { IToken token = null; switch (this.actionName) { case "focus": token = new FocusToken(); break; case "evade": token = new EvadeToken(); break; case "target lock": break; case "boost": break; case "barrel roll": break; case "slam": break; case "reinforce": break; case "cloak": break; case "decloak": break; case "coordinate": break; case "jam": break; case "recover": break; case "reload": break; case "rotate arc": break; } if (token != null) { Debug.Log("Adding token..."); MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].getActiveShip().addToken(token); MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].getActiveShip().registerPreviousAction(this.actionName); } // TODO Check if multiple actions can be chosen! // TODO Deactivate actions!!!! } if (GameObject.Find("ActionChoserPopup") != null && MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].getActiveShip().getNumOfActions() == 0) { GameObject.Find("ActionChoserPopup").gameObject.SetActive(false); PhaseHandlerService.endActionPhase(); } }