Example #1
0
	void InitializeMonsters() {
		GameObject canvas = GameObject.Find("Canvas");

		for (int i = 0; i < number_of_monsters; i++){
			int rand_id = ItemGenerator.LootIDGenerator("Monsters");
			Monster monster = CardLibrary.Instance().GetCardData(rand_id) as Monster;
			monster = new Monster(monster);
			monster.level = Random.Range(1, 3);
			monster.ScaleToLevel();
			monster.material = Factory.instance.TestBake(monster);
			GameObject monster_spawn = (GameObject)Instantiate(card_prefab, transform.GetChild(0).position, transform.GetChild(0).rotation);
			monster_spawn.GetComponent<CardScript>().Prepare(rand_id, monster.material);
			monster_spawn.AddComponent<Controller>();
			monster_spawn.GetComponent<Controller>().Clone(monster);
			monster_spawn.GetComponent<Controller>().currentPosition = i;
			monster_transforms.Add(monster_spawn.transform);
			PartyOfMonsters.Add (monster_spawn.GetComponent<Controller>());

			// Create UI Text //
			GameObject UI = (GameObject)Instantiate(EnemyUIPrefab, EnemyUIPrefab.transform.position, Quaternion.identity);
			UI.transform.SetParent(canvas.transform);
			UI.transform.FindChild("Title").GetComponent<Text>().text = monster.title;
			string maxHealth = "/" + monster.max_health.ToString();
			UI.transform.FindChild("MaxHealth").GetComponent<Text>().text = maxHealth;
			UI.transform.FindChild("HealthSlider").GetComponent<Slider>().maxValue = monster.max_health;
			UI.transform.FindChild("HealthSlider").GetComponent<Slider>().value = monster.max_health;
			//UI.transform.FindChild("SpeedSlider").GetComponent<Slider>().maxValue = monster.dexterity;
			UI.transform.FindChild("SpeedSlider").GetComponent<Slider>().value = 0;
			UI.transform.FindChild("CurrentHealth").GetComponent<Text>().text = monster.current_health.ToString();
			UI.transform.FindChild("Level").GetComponent<Text>().text = monster.level.ToString();
			Transform prefab = EnemyUIPrefab.transform as Transform;
			UI.transform.localScale = prefab.localScale;
			UI.transform.localPosition = prefab.localPosition;
			UI.transform.localPosition = new Vector3(UI.transform.localPosition.x, UI.transform.localPosition.y + (-130 * i), 0);
			monster_spawn.GetComponent<Controller>().UIReference = UI;
			StartCoroutine(UISetup(UI, i));

			/*
			GameObject UI = (GameObject)Instantiate(TextUIPrefab, TextUIPrefab.GetComponent<RectTransform>().anchoredPosition3D, Quaternion.identity);
			UI.transform.SetParent(canvas.transform);
			UI.GetComponent<Text>().text = monster.title;
			RectTransform prefab = TextUIPrefab.transform as RectTransform;

			// Re-initialize values to prefab values, so that parenting does not distort initial scale //
			RectTransform newRectTransform = UI.transform as RectTransform;
			newRectTransform.anchoredPosition = prefab.anchoredPosition;
			newRectTransform.anchorMax = prefab.anchorMax;
			newRectTransform.anchorMin = prefab.anchorMin;
			newRectTransform.localRotation = prefab.localRotation;
			newRectTransform.localScale = prefab.localScale;
			newRectTransform.pivot = prefab.pivot;
			newRectTransform.sizeDelta = prefab.sizeDelta;

			// Set custom position //
			UI.GetComponent<RectTransform>().anchoredPosition3D = new Vector3(-10, (-100 * i) - 40, 0);
			// Set alpha to 0, then fade in //
			Color color = UI.GetComponent<Text>().color;
			color.a = 0.0f;
			UI.GetComponent<Text>().color = color;
			StartCoroutine(FadeOutText(UI, i));
			*/

			string title = monster.title;
			title = title.Replace(" ", string.Empty);
			title = title.Replace(",", string.Empty);
			monster_spawn.AddComponent(title);
			monster_spawn.GetComponent<EnemyAI>().SetSkills();
			List<CardData> thisInventory = monster_spawn.GetComponent<EnemyAI>().CompileCards();
			List<Transform> thisList = new List<Transform>();
			Factory.instance.Clear();
			for (int q = 0; q < thisInventory.Count; q++){
				thisInventory[q].level = q + 2;
				thisInventory[q].cardpower = Random.Range(1, 10);
				Material mat = Factory.instance.AbilityBake(thisInventory[q], monster.picture);
				GameObject ability_spawn = (GameObject)Instantiate(card_prefab, transform.GetChild(0).position, transform.GetChild(0).rotation);
				ability_spawn.GetComponent<CardScript>().Prepare(thisInventory[q].id, mat);
				thisList.Add(ability_spawn.transform);
				if(thisInventory[q].GetType() == typeof(MonsterAbility)){
					ability_spawn.AddComponent<WeaponController>();
					ability_spawn.GetComponent<WeaponController>().EnemyClone(thisInventory[q]); 
					ability_spawn.GetComponent<WeaponController>().player = PartyOfMonsters[i];
					ability_spawn.GetComponent<WeaponController>().dmgMod = 1.0f;
				}
			}
			Factory.instance.Clear();
			enemyCards.Add(thisList);
		}
	}