package com.bernard.greposimu.engine.game;

import java.util.HashMap;
import java.util.Map;

import com.bernard.greposimu.model.FightStats;
import com.bernard.greposimu.model.game.Hero;

public class Heroes {

	Game g;
	
	
	
	public Heroes(Game g) {
		this.g = g;
	}



	/**
	 * Compute the bonus applied to each unit
	 * @param hero The uid of the hero
	 * @param level The level of the hero
	 * @param off true for the off stat, false for the def stat
	 * @return For each unit, the bonus that should be applied to it
	 */
	public Map<String,FightStats> heroFightBonuses(String hero, int level, boolean off){
		
		Map<String,FightStats> bonuses = new HashMap<>();
		
		if(hero == null)
			return new HashMap<>();
		
		double bonus = 0.0;
		Hero heroD = g.data.heroes.get(hero);
		if(heroD != null && heroD.description_args != null && heroD.description_args.containsKey("1")) {
			Hero.DescriptionArgs args = heroD.description_args.get("1");
			if(args.unit.equals("%"))
				bonus = args.value + level * args.level_mod;
			else
				throw new UnsupportedOperationException("I don't know about unit "+args.unit);
		}
		FightStats appliedBonus = null;
		switch(hero) {
		case "agamemnon":
			appliedBonus = FightStats.terrestre(bonus);
			bonuses.put("hoplite", appliedBonus);
			bonuses.put("archer", appliedBonus);
			break;
		case "ajax":
			appliedBonus = FightStats.terrestre(bonus);
			bonuses.put("hoplites", appliedBonus);
			break;
		case "alexandrios":
			appliedBonus = FightStats.terrestre(bonus);
			bonuses.put("archers", appliedBonus);
			break;
		case "deimos":
			appliedBonus = FightStats.cst(bonus);
			if(off)
				for(String uid : g.data.units.keySet())bonuses.put(uid,appliedBonus);
			break;
		case "hector":
			appliedBonus = FightStats.terrestre(bonus);
			bonuses.put("sword", appliedBonus);
			bonuses.put("slinger", appliedBonus);
			break;
		case "lysippe":
			appliedBonus = FightStats.terrestre(bonus);
			bonuses.put("rider", appliedBonus);
			break;
		case "leonidas":
			appliedBonus = FightStats.terrestre(bonus);
			if(!off)
				for(String uid : g.data.units.keySet())bonuses.put(uid,appliedBonus);
			break;
		case "mihalis":
			appliedBonus = new FightStats(bonus, bonus, 0.0, 0.0);
			for(String uid : g.data.units.keySet())bonuses.put(uid,appliedBonus);
			break;
		case "medea":
			appliedBonus = FightStats.terrestre(bonus);
			bonuses.put("slinger", appliedBonus);
			break;
		case "melousa":
			appliedBonus = FightStats.terrestre(bonus);
			bonuses.put("chariot", appliedBonus);
			break;
		case "pelops":
			appliedBonus = FightStats.terrestre(bonus);
			bonuses.put("hoplite", appliedBonus);
			bonuses.put("chariot", appliedBonus);
			break;
		case "themistokles":
			appliedBonus = FightStats.terrestre(bonus);
			bonuses.put("godsent", appliedBonus);
			bonuses.put("rider", appliedBonus);
			break;
		case "telemachos":
			appliedBonus = FightStats.terrestre(bonus);
			bonuses.put("sword", appliedBonus);
			break;
		case "urephon":
			appliedBonus = FightStats.terrestre(bonus);
			for(String uid : g.data.units.keySet())if(g.data.units.get(uid).isMythological())bonuses.put(uid,appliedBonus);
			break;
		case "zuretha":
			appliedBonus = new FightStats(0.0, 0.0, 0.0, bonus);
			for(String uid : g.data.units.keySet())bonuses.put(uid,appliedBonus);
			break;
		default:
			// No buff
			break;
		}
		return bonuses;
	}
	
}
