void MouseDown(ref GameObject mouseSelection) { mouseSelection = CheckForObjectUnderMouse(); if (mouseSelection == null) { Debug.Log("nothing selected by mouse"); } else { //onMouseDown //Debug.Log("picked: " + mouseSelection.gameObject); var deck = mouseSelection.GetComponent <PlayerDeck>(); var infectDeck = mouseSelection.GetComponent <InfectDeck>(); if (mouseSelection.tag == "Player") { //no need to record position, just move back to parent on illegal move } else if (infectDeck != null) { Debug.Log("Got infect deck"); PlayerDeck bDeck = infectDeck; //if <= 9 cards drawn OR no longer in setup mode if (playerCardsDrawn <= 9 || pawns.ExitSetup(false)) { playerCardsDrawn++; bDeck.Draw(); } } else if (deck != null) { Debug.Log("picked playerDeck"); if (pawns.ExitSetup(true) == false) { Debug.Log("Can't draw cards until players chosen"); return; } deck.Draw(); return; } else if (mouseSelection.tag == "InfectCity") { //setup //SetupGame(); //InfectCity("Madrid", 3); } else if (mouseSelection.transform.parent != null && mouseSelection.transform.parent.name == "Cities") { var sr = mouseSelection.GetComponent <SpriteRenderer>(); selectedCity = mouseSelection; sr.color = new Color(.1f, 1f, .1f, 1f); //bright green Debug.Log("clicked on city: " + mouseSelection.name); var neighbors = cg.GetNeighbors(mouseSelection); foreach (var node in neighbors) { Debug.Log("Neighbor: " + node.GetObj().name); } //testing var cube = GameObject.Find("disease_blue"); InfectCity(mouseSelection, 1); } } }
public void InfectCity(GameObject targetCity, int infectCount = 1, string type = null) { if (targetCity == null) { Debug.Log("can't find city to infect??"); return; } //draw an infect card, move card to discard pile //infect city //string target = "Madrid"; if (type == null) { type = Cities.GetType(targetCity.name); } GameObject diseaseType; if (type == "blue") { diseaseType = dBlue; } else if (type == "red") { diseaseType = dRed; } else if (type == "black") { diseaseType = dBlack; } else if (type == "yellow") { diseaseType = dYellow; } else { diseaseType = dRed; } //check number of infections already in city int diseaseCount = 0; foreach (Transform tChild in targetCity.transform) { if (tChild.gameObject.tag == "disease" && tChild.gameObject.name.Contains("disease_" + type)) { diseaseCount++; } } bool outbreak = ((diseaseCount + infectCount) > 3); if ((3 - diseaseCount) < infectCount) { infectCount = 3 - diseaseCount; } var cityPosition = targetCity.transform.position; for (int i = 0; i < infectCount; i++) { //add offset to position float x = (float)UnityEngine.Random.Range(-30, 30); x = x / 3f + Mathf.Sign(x) * 20f; float y = (float)UnityEngine.Random.Range(-30, 30); y = y / 3f + Mathf.Sign(y) * 20f; cityPosition += new Vector3(x / 100f, y / 100f, 0); var newDisease = Instantiate(diseaseType, cityPosition, targetCity.transform.rotation); newDisease.transform.parent = targetCity.transform; newDisease.GetComponent <Attraction>().pullSource = targetCity; } if (outbreak && !cg.GetNode(targetCity.name).hasOutbreak) { cg.GetNode(targetCity.name).hasOutbreak = true; //set self as having outbreak //find neighbors and add infect 1 to each of them var neighbors = cg.GetNeighbors(targetCity.name); foreach (var node in neighbors) { Debug.Log("Infecting Neighbor: " + node.GetObj().name); InfectCity(node.GetObj(), 1, type); } } }