mixedcards/Assets/Battle/BattleController.cs
2020-09-18 23:33:57 -04:00

87 lines
3.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BattleController : MonoBehaviour
{
public HeroId[] heroIds;
public MonsterId[] monsterIds;
public HeroInfoUI heroUIPrefab;
public GameObject uiCanvas;
public BattlePlayerControls battlePlayerControls;
public BattleHero[] heroes;
private GameObject[] heroSprites;
private HeroInfoUI[] heroUIs;
public BattleMonster[] monsters;
private GameObject[] monsterSprites;
private HeroInfoUI[] monsterUIs;
// Start is called before the first frame update
void Start()
{
heroes = new BattleHero[3];
heroSprites = new GameObject[3];
heroUIs = new HeroInfoUI[3];
for (int i = 0; i < 3; i++) {
HeroId id = heroIds[i];
heroes[i] = new BattleHero(id);
heroes[i].Init();
heroSprites[i] = HeroDatabase.createHeroSprite(id);
heroSprites[i].name = "Hero" + i + "_Sprite";
heroSprites[i].transform.position = new Vector3(-6 + 6 * i, 0, 0);
BattleParticipantSprite bps = heroSprites[i].AddComponent<BattleParticipantSprite>();
BattleParticipant participant = heroes[i];
bps.OnSpriteClicked += delegate() {battlePlayerControls.OnParticipantSpriteClicked(participant);};
heroUIs[i] = (HeroInfoUI) Instantiate(heroUIPrefab.gameObject, uiCanvas.transform).GetComponent(typeof(HeroInfoUI));
heroUIs[i].Init(heroSprites[i], heroes[i]);
}
monsters = new BattleMonster[3];
monsterSprites = new GameObject[3];
monsterUIs = new HeroInfoUI[3];
for (int i = 0; i < 3; i++) {
MonsterId id = monsterIds[i];
monsters[i] = MonsterDatabase.createMonsterScript(id);
monsters[i].Init();
monsterSprites[i] = MonsterDatabase.createMonsterSprite(id);
monsterSprites[i].name = "Monster" + i + "_Sprite";
monsterSprites[i].transform.position = new Vector3(-6 + 6 * i, 3, 0);
BattleParticipantSprite bps = monsterSprites[i].AddComponent<BattleParticipantSprite>();
BattleParticipant participant = monsters[i];
bps.OnSpriteClicked += delegate() {battlePlayerControls.OnParticipantSpriteClicked(participant);};
monsterUIs[i] = (HeroInfoUI) Instantiate(heroUIPrefab.gameObject, uiCanvas.transform).GetComponent(typeof(HeroInfoUI));
monsterUIs[i].Init(monsterSprites[i], monsters[i]);
}
this.battlePlayerControls.OnCardUsed += this.OnCardUsed;
this.battlePlayerControls.SetHand(5);
}
// Update is called once per frame
void Update()
{
}
public void HitRandomParticipant() {
if (Random.Range(0f, 1f) < 0.5f) {
heroes[Random.Range(0, heroes.Length)].DealDamage(1);
} else {
monsters[Random.Range(0, monsters.Length)].DealDamage(2);
}
}
public void OnCardUsed(BaseCard card) {
Debug.Log("OnCardClicked " + card);
StartCoroutine(card.Use(battlePlayerControls));
}
}