public IEnumerator DetermineCombat(EchelonBehavior defender) { battleHandlerObject.SetActive(true); attackerButton.GetComponentsInChildren <Image>()[1].sprite = selectedEchelon.GetComponent <Image>().sprite; attackerButton.GetComponent <Image>().color = Color.yellow; defenderButton.GetComponentsInChildren <Image>()[1].sprite = defender.gameObject.GetComponent <Image>().sprite; defenderButton.GetComponent <Image>().color = Color.white; attackerWins = true; combatSettled = false; while (!combatSettled) { yield return(new WaitForEndOfFrame()); } if (attackerWins) { selectedEchelon.SetNode(defender.GetNode()); selectedEchelon.gameObject.transform.position = defender.GetNode().gameObject.transform.position; RemoveEchelon(defender); } else { RemoveEchelon(selectedEchelon); if (defender.GetFaction() == Faction.Blue && (regularEchelons.Contains(defender) || parachuteEchelons.Contains(defender as ParachuteBehavior))) { UseCombatSupply(defender); } } DeselectEchelon(); battleHandlerObject.SetActive(false); }
private IEnumerator InputEchelonName(EchelonBehavior behavior) { InputFieldHolder.SetActive(true); InputFieldLabel.text = "Echelon Name:"; if (makingHOC) { HOCRangeInput.gameObject.SetActive(true); } submitted = false; while (!submitted) { yield return(new WaitForEndOfFrame()); } behavior.SetName(InputField.text); if (makingHOC) { (behavior as HOCBehavior).SetRange(int.Parse(HOCRangeInput.text)); HOCRangeInput.text = ""; HOCRangeInput.gameObject.SetActive(false); } InputFieldHolder.SetActive(false); InputField.text = ""; }
public void DeselectEchelon() { if (selectedEchelon != null) { if (selectedEchelon as HOCBehavior != null) { UnhighlightNodes(); } selectedEchelon.GetComponent <Image>().color = Color.white; selectedEchelon = null; SelectedEchelonDescription.text = ""; } }
private IEnumerator InputEnemyAttributes(EchelonBehavior behavior) { enemyCreatorHolder.SetActive(true); creatingNewEnemy = false; while (!creatingNewEnemy) { yield return(new WaitForEndOfFrame()); } if (enemyCreator.GetEnemyID().Length > 0) { behavior.SetID(int.Parse(enemyCreator.GetEnemyID())); } behavior.SetFaction(enemyCreator.GetEnemyFaction()); behavior.GetComponent <Image>().sprite = enemyCreator.GetChosenSprite(); enemyCreator.ResetInputField(); enemyCreatorHolder.SetActive(false); }
private void RemoveEchelon(EchelonBehavior echelon) { if (echelon != null) { allEchelons.Remove(echelon); if (echelon.GetFaction() != Faction.Blue) { enemies.Remove(echelon); } else { if (echelon as ParachuteBehavior != null) { retreatedEchelons.Enqueue(echelon.GetID()); parachuteEchelons.Remove(echelon as ParachuteBehavior); planner.RemoveEchelon(); } else if (echelon as HOCBehavior != null) { retreatedHOCs.Enqueue(echelon.GetID()); HOCs.Remove(echelon as HOCBehavior); planner.RemoveHOC(); } else { if (regularEchelons.Contains(echelon)) { retreatedEchelons.Enqueue(echelon.GetID()); regularEchelons.Remove(echelon); planner.RemoveEchelon(); } else { NPCs.Remove(echelon); } } } Destroy(echelon.gameObject); } }
public void SpawnEnemiesAtHelis(List <GameObject> nodes, Faction faction) { foreach (GameObject nodeObject in nodes) { NodeBehavior node = nodeObject.GetComponent <NodeBehavior>(); if (GetEchelonAtNode(node) == null) { if (node.GetOwner() == faction) { if (node.GetNodeType() == NodeType.Helipad || node.GetNodeType() == NodeType.HeavyHelipad) { GameObject newEchelon = Instantiate(enemySpawn, node.gameObject.transform.position, Quaternion.identity, mapImage.transform); if (faction == Faction.Red) { newEchelon.GetComponent <Image>().sprite = redSpawnPreview.GetComponentsInChildren <Image>()[1].sprite; } else if (faction == Faction.Yellow) { newEchelon.GetComponent <Image>().sprite = yellowSpawnPreview.GetComponentsInChildren <Image>()[1].sprite; } EchelonBehavior behavior = newEchelon.GetComponent <EchelonBehavior>(); enemies.Add(behavior); behavior.SetFaction(faction); behavior.SetNode(node); allEchelons.Add(behavior); newEchelon.transform.localScale = new Vector3(node.GetComponent <RectTransform>().rect.width / 200, node.GetComponent <RectTransform>().rect.height / 200, 1); EventTrigger.Entry ClickEntry = new EventTrigger.Entry(); ClickEntry.eventID = EventTriggerType.PointerClick; ClickEntry.callback.AddListener(delegate { SelectEchelon(behavior); }); newEchelon.GetComponent <EventTrigger>().triggers.Add(ClickEntry); } } } } }
public void SelectEchelon(EchelonBehavior echelon) { if (!MoveEcheToNode(echelon.GetNode())) { DeselectEchelon(); selectedEchelon = echelon; selectedEchelon.GetComponent <Image>().color = Color.yellow; SelectedEchelonDescription.text = "Echelon: " + echelon.GetID() + "\nFaction: " + echelon.GetFaction(); if (selectedEchelon.GetFaction() == Faction.Blue && !NPCs.Contains(selectedEchelon)) { SelectedEchelonDescription.text += "\nSupply: " + echelon.GetSupply().x + " / " + echelon.GetSupply().y; } if (selectedEchelon.GetName().Length > 0) { SelectedEchelonDescription.text = SelectedEchelonDescription.text.Insert(0, "Name: " + selectedEchelon.GetName() + "\n"); } ParachuteBehavior para = echelon as ParachuteBehavior; if (para != null) { SelectedEchelonDescription.text += "\nParachute CD: " + para.GetCooldown(); } else { HOCBehavior HOC = echelon as HOCBehavior; if (HOC != null) { SelectedEchelonDescription.text += "\nRange: " + HOC.GetRange(); nodesInSelectedHOCRange = HOC.GetAllNodesInRange(); HighlightNodesInHOCRange(); } } } }
public void AddEchelon(EchelonType type, NodeBehavior node) { bool valid = false; if (type == EchelonType.Enemy || type == EchelonType.NPC) { valid = true; } else if (node.GetOwner() == Faction.Blue) { if (node.GetNodeType() == NodeType.HeavyHelipad) { valid = true; } else if (type != EchelonType.HOC) { if (node.GetNodeType() == NodeType.HQ || node.GetNodeType() == NodeType.Helipad) { valid = true; } } } if (valid) { GameObject newEchelon = null; switch (type) { case EchelonType.RegularGriffin: newEchelon = Instantiate(regularEcheTemplate, node.gameObject.transform.position, Quaternion.identity, mapImage.transform); regularEchelons.Add(newEchelon.GetComponent <EchelonBehavior>()); planner.AddEchelon(); makingHOC = false; StartCoroutine(InputEchelonName(newEchelon.GetComponent <EchelonBehavior>())); break; case EchelonType.Parachute: newEchelon = Instantiate(parachuteTemplate, node.gameObject.transform.position, Quaternion.identity, mapImage.transform); parachuteEchelons.Add(newEchelon.GetComponent <ParachuteBehavior>()); planner.AddEchelon(); makingHOC = false; StartCoroutine(InputEchelonName(newEchelon.GetComponent <EchelonBehavior>())); break; case EchelonType.HOC: newEchelon = Instantiate(HOCTemplate, node.gameObject.transform.position, Quaternion.identity, mapImage.transform); HOCs.Add(newEchelon.GetComponent <HOCBehavior>()); planner.AddHOC(); makingHOC = true; StartCoroutine(InputEchelonName(newEchelon.GetComponent <EchelonBehavior>())); break; case EchelonType.NPC: newEchelon = Instantiate(NPCTemplate, node.gameObject.transform.position, Quaternion.identity, mapImage.transform); NPCs.Add(newEchelon.GetComponent <EchelonBehavior>()); break; case EchelonType.Enemy: newEchelon = Instantiate(regularEnemyTemplate, node.gameObject.transform.position, Quaternion.identity, mapImage.transform); enemies.Add(newEchelon.GetComponent <EchelonBehavior>()); StartCoroutine(InputEnemyAttributes(newEchelon.GetComponent <EchelonBehavior>())); break; } EchelonBehavior behavior = newEchelon.GetComponent <EchelonBehavior>(); behavior.SetNode(node); allEchelons.Add(behavior); if (type == EchelonType.RegularGriffin || type == EchelonType.Parachute) { if (retreatedEchelons.Count > 0) { behavior.SetID(retreatedEchelons.Dequeue()); } else { behavior.SetID(regularEchelons.Count + parachuteEchelons.Count); } } else if (type == EchelonType.HOC) { if (retreatedHOCs.Count > 0) { behavior.SetID(retreatedHOCs.Dequeue()); } else { behavior.SetID(HOCs.Count); } } if (gameStateManager.factionMoving == FactionTurn.Blue) { if (behavior.GetFaction() == Faction.Blue) { if (type != EchelonType.NPC) { planner.AdjustAP(-1); } } } newEchelon.transform.localScale = new Vector3(node.GetComponent <RectTransform>().rect.width / 200, node.GetComponent <RectTransform>().rect.height / 200, 1); EventTrigger.Entry ClickEntry = new EventTrigger.Entry(); ClickEntry.eventID = EventTriggerType.PointerClick; ClickEntry.callback.AddListener(delegate { SelectEchelon(behavior); }); newEchelon.GetComponent <EventTrigger>().triggers.Add(ClickEntry); } }
public bool MoveEcheToNode(NodeBehavior node) { if (selectedEchelon != null) { if (selectedEchelon.GetNode().GetConnectedNodes().Contains(node)) { EchelonBehavior blockingEchelon = GetEchelonAtNode(node); if (blockingEchelon == null) { if ((selectedEchelon.GetFaction() == Faction.Blue && planner.GetAP() > 0) || NPCs.Contains(selectedEchelon) || selectedEchelon.GetFaction() != Faction.Blue) { selectedEchelon.SetNode(node); selectedEchelon.gameObject.transform.position = node.gameObject.transform.position; if (selectedEchelon.GetFaction() == Faction.Blue && !NPCs.Contains(selectedEchelon)) { planner.AdjustAP(-1); } DeselectEchelon(); return(true); } } else { if (blockingEchelon.GetFaction() != selectedEchelon.GetFaction()) { if (selectedEchelon as HOCBehavior == null) { if ((selectedEchelon.GetFaction() == Faction.Blue && planner.GetAP() > 0) || NPCs.Contains(selectedEchelon) || selectedEchelon.GetFaction() != Faction.Blue) { if (selectedEchelon.GetFaction() == Faction.Blue && !NPCs.Contains(selectedEchelon)) { if (selectedEchelon.GetSupply().x > 0 && selectedEchelon.GetSupply().y > 0) { UseCombatSupply(selectedEchelon); planner.AdjustAP(-1); } else { return(false); } } if (blockingEchelon as HOCBehavior != null || ((regularEchelons.Contains(blockingEchelon) || blockingEchelon as ParachuteBehavior != null) && (blockingEchelon.GetSupply().x == 0 || blockingEchelon.GetSupply().y == 0))) { selectedEchelon.SetNode(node); selectedEchelon.gameObject.transform.position = node.gameObject.transform.position; RemoveEchelon(blockingEchelon); } else { if (blockingEchelon.GetFaction() == Faction.Blue || selectedEchelon.GetFaction() == Faction.Blue) { foreach (HOCBehavior HOC in HOCs) { if (HOC.IsNodeInRange(blockingEchelon.GetNode())) { HOC.UseSupply(new Vector2Int(1, 2)); } } } StartCoroutine(DetermineCombat(blockingEchelon)); } return(true); } } } else if (selectedEchelon.GetFaction() == Faction.Blue) { blockingEchelon.SetNode(selectedEchelon.GetNode()); blockingEchelon.gameObject.transform.position = selectedEchelon.GetNode().gameObject.transform.position; selectedEchelon.SetNode(node); selectedEchelon.gameObject.transform.position = node.gameObject.transform.position; DeselectEchelon(); return(true); } } } else if (selectedEchelon as ParachuteBehavior != null) { ParachuteBehavior para = selectedEchelon as ParachuteBehavior; if (para.GetCooldown() == 0) { if (GetEchelonAtNode(node) == null && (node.GetNodeType() == NodeType.Helipad || node.GetNodeType() == NodeType.HeavyHelipad || node.GetNodeType() == NodeType.ClosedHeli || node.GetNodeType() == NodeType.ClosedHeavyHeli)) { para.UsePara(); selectedEchelon.SetNode(node); selectedEchelon.gameObject.transform.position = node.gameObject.transform.position; DeselectEchelon(); return(true); } } } } return(false); }
private void UseCombatSupply(EchelonBehavior echelon) { echelon.UseSupply(new Vector2Int(1, 1)); }