package rpgEngine.Logic.Game;

import java.util.Random;

import rpgEngine.Data.Abstract.Enemy.Enemy;
import rpgEngine.Data.Abstract.Party.HumanPlayer;


public class PlayerFightUse {
	private HumanPlayer player;
	private Enemy enemy;
	
	public PlayerFightUse(HumanPlayer p, Enemy e) {
		player = p;
		enemy = e;
	}
	
	
	public String fight() {
		String resultMessage = "";
		Random random = new Random();
		Double randomMultiplier = 1.0;
		Double skillMultiplier = 1.0;
		Integer damagePoints = 0;
		
		//miss check
		if(random.nextDouble() > 0.95) {
			resultMessage = "Attack Missed!";
			return resultMessage;
		}
		
		//Random Multiplier
		randomMultiplier = 0.8 + (Math.random() * (1.2 - 0.8));
		
		//Skill Multiplier
		skillMultiplier = ((double)player.getAttack()) / ((double)player.getSkill());
		
		if(skillMultiplier < 0.8) {
			skillMultiplier = 0.8;
		}
		if(skillMultiplier > 1.2) {
			skillMultiplier = 1.2;
		}
		
		//Determine Damage
		damagePoints = (int)((double)player.getAttack() * randomMultiplier * skillMultiplier);
		
		//Defense Consideration
		damagePoints = damagePoints - (enemy.getDefense() / 2);
		
		if(damagePoints <= 0) {
			damagePoints = 1;
		}
		
		enemy.setHP(enemy.getHP() - damagePoints);
		
		if(enemy.getHP() < 0) {
			enemy.setHP(0);
		}
		
		resultMessage = "Attack caused " + damagePoints + " damage";
		
		return resultMessage;
	}
	
	
}
