-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrainer.cs
61 lines (43 loc) · 1.89 KB
/
Trainer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using UnityEngine;
using System.Collections;
public class Trainer : MonoBehaviour {
public bool isDefeated;
public uint trainer_id;
public string[] beforeBattleMessage;
public string[] afterBattleMessage;
public int reward;
void OnTriggerEnter2D (Collider2D col) {
if (InterSceneData.main.defeatedTrainers.IndexOf (";" + trainer_id.ToString () + ";") != -1)
isDefeated = true;
if (!isDefeated) {
StartCoroutine (handleBattleRequest ());
}
}
IEnumerator handleBattleRequest () {
GameObject player = GameObject.FindGameObjectWithTag ("Player");
PlayerMovementController pmc = player.GetComponent<PlayerMovementController> ();
TalkController tcontroller = player.GetComponent<TalkController> ();
InterSceneData.main.battle_trainer = trainer_id;
pmc.isAllowedToMove = false;
foreach (string msg in beforeBattleMessage) {
yield return StartCoroutine (tcontroller.showMessage (msg, 2f));
}
InterSceneData.main.battle_friendly = InterSceneData.main.pokemons.GetAll ().ToArray () [0] as Pokemon;
InterSceneData.main.battle_opponent = player.GetComponent<TrainerPokemonDatabase> ().getPokemonForID (trainer_id);
Application.LoadLevel ("BattleScene");
}
public IEnumerator defeated () {
InterSceneData.main.defeatedTrainers += trainer_id.ToString () + ";";
GameObject player = GameObject.FindGameObjectWithTag ("Player");
TalkController tcontroller = player.GetComponent<TalkController> ();
PlayerMovementController pmc = player.GetComponent<PlayerMovementController> ();
pmc.isAllowedToMove = false;
foreach (string msg in afterBattleMessage) {
Debug.Log ("Printing " + msg);
yield return StartCoroutine (tcontroller.showMessage (msg, 2f));
}
InterSceneData.main.money += reward;
yield return StartCoroutine(tcontroller.showMessage (InterSceneData.main.playerName + " hat " + reward.ToString () + "$ erhalten!", 2f));
pmc.isAllowedToMove = true;
}
}