public IEnumerator Play(Transform grid) { bool isTurn = AIController.GetInstance().AITurn(); int index = AIController.GetInstance().AICard(grid); if (LeaderController.GetInstance().obj[1].GetComponent <EnemyLeaderBehavior>().IsEnabled) { LeaderController.GetInstance().obj[1].GetComponent <EnemyLeaderBehavior>().Play(); yield return(PlayOver(LeaderController.GetInstance().obj[1].transform)); CoroutineManager.GetInstance().Finish(); yield break; } if (isTurn || index == -1) { yield return(TurnController.GetInstance().EnemyTurn()); CoroutineManager.GetInstance().Finish(); yield break; } Transform card; try { card = grid.GetChild(index); } catch { card = grid.GetChild(Random.Range(0, grid.childCount)); } CardProperty cardProperty = card.GetComponent <CardProperty>(); switch (cardProperty.effect) { case Global.Effect.spy: card.SetTarget(PlayerController.GetInstance().grids[(int)cardProperty.line + 2]); DrawCards(2); break; case Global.Effect.clear_sky: WeatherController.GetInstance().ClearSky(); card.SetTarget(grids[5]); break; case Global.Effect.frost: if (!WeatherController.GetInstance().weather[0]) { WeatherController.GetInstance().Frost(); card.SetTarget(WeatherController.GetInstance().grid); break; } else { goto default; } case Global.Effect.fog: if (!WeatherController.GetInstance().weather[1]) { WeatherController.GetInstance().Fog(); card.SetTarget(WeatherController.GetInstance().grid); break; } else { goto default; } case Global.Effect.rain: if (!WeatherController.GetInstance().weather[2]) { WeatherController.GetInstance().Rain(); card.SetTarget(WeatherController.GetInstance().grid); break; } else { goto default; } case Global.Effect.nurse: if (grids[5].childCount != 0) { card.SetTarget(grids[(int)cardProperty.line + 2]); yield return(TweenCard.GetInstance().Play(card)); yield return(Play(grids[5])); PlayerController.GetInstance().obj.SetActive(false); obj.SetActive(false); PlayerController.GetInstance().obj.SetActive(true); obj.SetActive(true); yield break; } else { goto default; } case Global.Effect.scorch: int maxPower = 0; for (int i = 2; i < 5; i++) { for (int ii = 0; ii < PlayerController.GetInstance().grids[i].childCount; ii++) { int power = PlayerController.GetInstance().grids[i].GetChild(ii).GetComponent <CardBehavior>().totalPower; if (power > maxPower) { maxPower = power; } } } for (int i = 2; i < 5; i++) { for (int ii = 0; ii < grids[i].childCount; ii++) { int power = grids[i].GetChild(ii).GetComponent <CardBehavior>().totalPower; if (power > maxPower) { maxPower = power; } } } for (int i = 2; i < 5; i++) { for (int ii = PlayerController.GetInstance().grids[i].childCount - 1; ii >= 0; ii--) { Transform scorchCard = PlayerController.GetInstance().grids[i].GetChild(ii); if (scorchCard.GetComponent <CardBehavior>().totalPower == maxPower && !scorchCard.GetComponent <CardProperty>().gold) { scorchCard.SetTarget(PlayerController.GetInstance().grids[5]); } } } for (int i = 2; i < 5; i++) { for (int ii = grids[i].childCount - 1; ii >= 0; ii--) { Transform scorchCard = grids[i].GetChild(ii); if (scorchCard.GetComponent <CardBehavior>().totalPower == maxPower && !scorchCard.GetComponent <CardProperty>().gold) { scorchCard.SetTarget(grids[5]); } } } goto default; case Global.Effect.dummy: if (grids[2].childCount == 0 && grids[3].childCount == 0 && grids[4].childCount == 0) { card.SetTarget(grids[5]); break; } int dummyGrid = 0; int dummyIndex = 0; for (int i = 2; i < 5; i++) { for (int ii = 0; ii < grids[i].childCount; ii++) { if (grids[i].GetChild(ii).GetComponent <CardProperty>().effect == Global.Effect.spy || grids[i].GetChild(ii).GetComponent <CardProperty>().effect == Global.Effect.nurse || grids[i].GetChild(ii).GetComponent <CardProperty>().effect == Global.Effect.scorch || grids[i].GetChild(ii).GetComponent <CardProperty>().effect == Global.Effect.warhorn) { dummyGrid = i; dummyIndex = ii; } } } card.SetTarget(grids[dummyGrid]); grids[dummyGrid].GetChild(dummyIndex).SetTarget(grid); break; case Global.Effect.warhorn: if (cardProperty.line == Global.Line.empty) { if (grids[2].childCount == 0 && grids[3].childCount == 0 && grids[4].childCount == 0) { card.SetTarget(grids[5]); break; } int line = 0; int maxCount = 0; for (int i = 2; i < 5; i++) { if (grids[i].childCount >= maxCount && !WarhornController.GetInstance().enemyWarhorn[i - 2]) { line = i - 2; maxCount = grids[i].childCount; } } WarhornController.GetInstance().enemyWarhorn[line] = true; card.SetTarget(WarhornController.GetInstance().enemyGrids[line]); break; } else { WarhornController.GetInstance().enemyWarhorn[(int)cardProperty.line] = true; goto default; } case Global.Effect.muster: int musterIndex = 0; for (int i = 0; i < MusterController.GetInstance().musterCards.Length; i++) { for (int ii = 0; ii < MusterController.GetInstance().musterCards[i].Length; ii++) { if (grid.GetChild(index).GetComponent <UISprite>().spriteName == MusterController.GetInstance().musterCards[i][ii]) { musterIndex = i; } } } for (int i = 0; i < MusterController.GetInstance().musterCards[musterIndex].Length; i++) { for (int ii = grids[0].childCount - 1; ii >= 0; ii--) { Transform musterCard = grids[0].GetChild(ii); if (musterCard.GetComponent <UISprite>().spriteName == MusterController.GetInstance().musterCards[musterIndex][i]) { musterCard.SetTarget(grids[(int)musterCard.GetComponent <CardProperty>().line + 2]); } } } goto default; case Global.Effect.agile: int agileIndex = 0; for (int i = 0; i < 2; i++) { if (!WeatherController.GetInstance().weather[i]) { agileIndex = i; } } card.SetTarget(grids[agileIndex + 2]); break; default: card.SetTarget(grids[(int)cardProperty.line + 2]); break; } yield return(PlayOver(card)); CoroutineManager.GetInstance().Finish(); }
public void Play() { int index = 0; for (int i = 0; i < ShowCards.GetInstance().totalGrid.childCount; i++) { if (string.Format("{0}(Clone)", ShowCards.GetInstance().totalGrid.GetChild(i).name) == name) { index = i; } } ShowCards.GetInstance().card = ShowCards.GetInstance().totalGrid.GetChild(index); switch (cardProperty.effect) { case Global.Effect.spy: ShowCards.GetInstance().card.SetTarget(EnemyController.GetInstance().grids[(int)cardProperty.line + 2]); PlayerController.GetInstance().DrawCards(2); break; case Global.Effect.clear_sky: WeatherController.GetInstance().ClearSky(); goto default; case Global.Effect.frost: if (!WeatherController.GetInstance().weather[0]) { WeatherController.GetInstance().Frost(); ShowCards.GetInstance().card.SetTarget(WeatherController.GetInstance().grid); break; } else { goto default; } case Global.Effect.fog: if (!WeatherController.GetInstance().weather[1]) { WeatherController.GetInstance().Fog(); ShowCards.GetInstance().card.SetTarget(WeatherController.GetInstance().grid); break; } else { goto default; } case Global.Effect.rain: if (!WeatherController.GetInstance().weather[2]) { WeatherController.GetInstance().Rain(); ShowCards.GetInstance().card.SetTarget(WeatherController.GetInstance().grid); break; } else { goto default; } case Global.Effect.scorch: if (cardProperty.effect == Global.Effect.scorch) { int maxPower = 0; for (int i = 2; i < 5; i++) { for (int ii = 0; ii < PlayerController.GetInstance().grids[i].childCount; ii++) { Transform scorchCard = PlayerController.GetInstance().grids[i].GetChild(ii); if (!scorchCard.GetComponent <CardProperty>().gold) { int power = scorchCard.GetComponent <CardBehavior>().totalPower; if (power > maxPower) { maxPower = power; } } } } for (int i = 2; i < 5; i++) { for (int ii = 0; ii < EnemyController.GetInstance().grids[i].childCount; ii++) { Transform scorchCard = EnemyController.GetInstance().grids[i].GetChild(ii); if (!scorchCard.GetComponent <CardProperty>().gold) { int power = scorchCard.GetComponent <CardBehavior>().totalPower; if (power > maxPower) { maxPower = power; } } } } for (int i = 2; i < 5; i++) { for (int ii = PlayerController.GetInstance().grids[i].childCount - 1; ii >= 0; ii--) { Transform scorchCard = PlayerController.GetInstance().grids[i].GetChild(ii); if (scorchCard.GetComponent <CardBehavior>().totalPower == maxPower && !scorchCard.GetComponent <CardProperty>().gold) { scorchCard.SetTarget(PlayerController.GetInstance().grids[5]); } } } for (int i = 2; i < 5; i++) { for (int ii = EnemyController.GetInstance().grids[i].childCount - 1; ii >= 0; ii--) { Transform scorchCard = EnemyController.GetInstance().grids[i].GetChild(ii); if (scorchCard.GetComponent <CardBehavior>().totalPower == maxPower && !scorchCard.GetComponent <CardProperty>().gold) { scorchCard.SetTarget(EnemyController.GetInstance().grids[5]); } } } } goto default; case Global.Effect.dummy: ShowCards.GetInstance().Show(ShowCards.ShowBehavior.dummy, PlayerController.GetInstance().grids[2], true); return; case Global.Effect.muster: MusterController.GetInstance().Muster(); goto default; case Global.Effect.warhorn: if (cardProperty.line == Global.Line.empty) { ShowCards.GetInstance().Show(ShowCards.ShowBehavior.warhorn, PlayerController.GetInstance().grids[2], true); return; } else { WarhornController.GetInstance().playerWarhorn[(int)cardProperty.line] = true; goto default; } case Global.Effect.agile: ShowCards.GetInstance().Show(ShowCards.ShowBehavior.agile, PlayerController.GetInstance().grids[2], true); return; default: ShowCards.GetInstance().card.SetTarget(PlayerController.GetInstance().grids[(int)cardProperty.line + 2]); break; } if (cardProperty.effect == Global.Effect.nurse) { CoroutineManager.GetInstance().AddTask(TweenCard.GetInstance().Play(ShowCards.GetInstance().card)); ShowCards.GetInstance().Show(ShowCards.ShowBehavior.nurse, PlayerController.GetInstance().grids[5], true); return; } ShowCards.GetInstance().Hide(); PlayerController.GetInstance().PlayOver(ShowCards.GetInstance().card); }