import { Observable, Subject } from "rxjs";
import { environment } from "../../../environments/environment";
import { MsgBoxService } from "../../services/msg-box.service";
import { ObjectUtils } from "../../utilities/object-utils";
import { StringUtils } from "../../utilities/string-utils";
import { GamePlayer } from "../games.model";
import { MD2HeroInfo, AttackTarget, HeroClass } from "./massive-darkness2.model";
import { MobSkill } from "./massive-darkness2.model.boss";
export class MD2Logic {
    public static getTargetHeroByFilter(heros: MD2HeroInfo[], targetType: AttackTarget) {
        return this.getTargetHerosByFilter(heros, targetType, true)[0];
    }
    public static getTargetHerosByFilter(heros: MD2HeroInfo[], targetType: AttackTarget, onlyOne: boolean = false) {
        let beenAttackedHero = [] as MD2HeroInfo[];
        switch (targetType) {
            case AttackTarget.LeastHp:
                let lowestHp = Math.min(...heros.map(h => h.hp));
                beenAttackedHero = heros.filter(h => h.hp == lowestHp);
                //this.otherAttackTarget = 'attacking the other <b>Lowest HP</b> hero.';
                break;
            case AttackTarget.LeastMp:
                let lowestMp = Math.min(...heros.map(h => h.mp));
                beenAttackedHero = heros.filter(h => h.hp == lowestMp);
                //this.otherAttackTarget = 'attacking the other <b>Lowest HP</b> hero.';
                break;

            case AttackTarget.HighestHp:
                let highestHp = Math.max(...heros.map(h => h.hp));
                beenAttackedHero = heros.filter(h => h.hp == highestHp);
                //this.otherAttackTarget = 'attacking the other <b>Highest HP</b> hero.';
                break;
            case AttackTarget.HighestMp:
                let highestMp = Math.max(...heros.map(h => h.mp));
                beenAttackedHero = heros.filter(h => h.mp == highestMp);
                //this.otherAttackTarget = 'attacking the other <b>Highest Mp</b> hero.';
                break;
            case AttackTarget.LowestLevel:
                let lowestLevel = Math.max(...heros.map(h => h.level));
                beenAttackedHero = heros.filter(h => h.level == lowestLevel);
                //this.otherAttackTarget = 'attacking the other <b>Lowest Level</b> hero.';
                break;
            case AttackTarget.LeastCorruption:

                let leastCor = Math.min(...heros.map(h => h.corruptionToken));
                beenAttackedHero = heros.filter(h => h.corruptionToken == leastCor);
                break;
            case AttackTarget.MostCorruption:
                let mostCor = Math.max(...heros.map(h => h.corruptionToken));
                beenAttackedHero = heros.filter(h => h.corruptionToken == mostCor);
                break;
            case AttackTarget.Random:
            default:
                beenAttackedHero = [heros[Math.round(Math.random() * (heros.length - 1))]];
                //this.otherAttackTarget = 'Just act like normal.';
                break;
        }
        if (onlyOne && beenAttackedHero.length > 1) {
            beenAttackedHero = [beenAttackedHero[Math.round(Math.random() * (beenAttackedHero.length - 1))]];
        }
        return beenAttackedHero;
    }

    public static getTargetHerosHtml(beenAttackedHero: MD2HeroInfo[]) {
        return `<b>${StringUtils.makeCommaSeparatedString(beenAttackedHero.map(h => this.heroFullName(h)), false, true)}</b>`;
    }

    public static heroFullName(hero: MD2HeroInfo) {
        if (!hero) return '';
        return `${hero.playerInfo.name} (${HeroClass[hero.class]} - ${hero.name})`
    }
}