81 lines
2.5 KiB
C#
81 lines
2.5 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);
|
|
|
|
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);
|
|
|
|
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(int index) {
|
|
Debug.Log("OnCardClicked " + index);
|
|
HitRandomParticipant();
|
|
}
|
|
}
|