Esempio n. 1
0
	IEnumerator handleChoices(GameObject[] ents, int unitCount, int i){
		bool done = false;

		for (int p = 0; p < unitCount; p++) {
			done = false;

			// It goes through the null slots too.
			// The try prevents a crash for null slots.
			if (ents [p] != null) {
				try {
					entity = ents [p].GetComponent<Entities> (); 
					if (entity.Choice == i) {
						hit = entity.accuracyCheck ();
						if (entity.Target != null){
							switch (entity.Choice) {
							case Entities.CHOICE_ATTACK:
								entity.Attack (hit);
								//Debug.Log("" + entity.ToString() + " Choice: ATTACK");
								break;
							case Entities.CHOICE_DEFEND:
								entity.Defend ();
								//Debug.Log("" + entity.ToString() + " Choice: DEFEND");
								break;
							case Entities.CHOICE_ITEM:
								entity.Item ();
								//Debug.Log("" + entity.ToString() + " Choice: ITEM");
								break;
							case Entities.CHOICE_SKILL:
								entity.Skill (hit);
								//Debug.Log("" + entity.ToString() + " Choice: SKILL");
								break;
							default:
								Debug.Log("" + entity.ToString() + " Choice: ERROR");
								break;
							}
							if (entity.Damage > 0 && hit) {
								floatingNumbers (entity.Damage.ToString (), entity.Target.transform.position);
								Debug.Log ("Hit! " + entity.Damage);
							}
							if (!hit) {
								floatingNumbers ("Miss!", entity.Target.transform.position);
							}
							//Debug.Log ("" + entity.ToString () + " || " + entity.Choice);
							done = true;
						}
					}
				} catch (Exception ex) {
					Debug.Log (ex);
				}
				if (done == true) {
					yield return new WaitForSeconds (1.5f);
				}

				done = false;
			}
		}
	}