コード例 #1
0
ファイル: Health.cs プロジェクト: heed13/PokemonBattleArena
	// -------- Public Functions --------
	public void TakeDamage(AttackInfo atk)
	{
		HitInfo hitInfo = new HitInfo(); // Create new hitInfo to pass back to attacker
		float appliedDmg = atk.damage;

		// Figure out weaknesses
		if (weakAgainst.Contains(atk.type)) {
			appliedDmg *= weaknessMultiplier;
			hitInfo.weaknessDmg = appliedDmg - atk.damage;
		} // Figre out Resitances
		else if (resistantTo.Contains(atk.type)) {
			appliedDmg *= resistanceMultiplier;
			hitInfo.weaknessDmg =  atk.damage - appliedDmg;
		}

		// Set total DMG
		hitInfo.totalDmgDealt = appliedDmg;

		// Apply damage
		currentHP -= appliedDmg;

		// Let others know -- display stuff and whatnot
		UpdateBar ();
		playHitSound (atk.type);
		atk.hitCallback (hitInfo);
		ShowFloatingText (appliedDmg);
		StartCoroutine ("FlashOnHit");

		// Check Death
		if (currentHP <= 0) {
			
			// Set vars, call onHit of attacker
			currentHP = 0;
			hitInfo.killed = true;
			atk.killCallback (hitInfo);

			// End our misery
			Die ();
		}
	}