import { Injectable } from '@angular/core';
import { CoreGameMobFactories } from '../../games/massive-darkness2/factorys/mobs/CoreGame';
import { CoreGameRMFactories } from '../../games/massive-darkness2/factorys/roamingMonsters/CoreGame';
import { DrawingBag, MobInfo, TreasureItem, TreasureType } from '../../games/massive-darkness2/massive-darkness2.model';
import { MD2StateService } from './md2-state.service';

@Injectable({
  providedIn: 'root'
})
export class MD2InitService {

  constructor(
    private stateService: MD2StateService
  ) { }

  public initMobDecks() {
    this.stateService.mobDeck = new DrawingBag();
    this.stateService.roamingMobDeck = new DrawingBag();

    this.initCoreGameMobs();
    this.initCoreGameRoamingMonsters();
  }

  private initCoreGameRoamingMonsters() {
    CoreGameRMFactories.forEach(factory => {
      for (let i = 1; i <= 5; i++) {
        this.stateService.roamingMobDeck.AddItem(new MobInfo({ name: factory.mobName, level: i, drawingWeight: 1 }));
        i++;
      }
    });

  }
  private initCoreGameMobs() {
    CoreGameMobFactories.forEach(factory => {
      for (let i = 1; i <= 5; i++) {
        this.stateService.mobDeck.AddItem(new MobInfo({ name: factory.mobName, level: i, drawingWeight: 1 }));
        i++;
      }
    });
  }

  public initTreasureBag() {
    this.stateService.treasureBag.ClearAllItems();
    this.addTreasure(TreasureType.Common, 15);
    this.addTreasure(TreasureType.Rare, 5);
  }

  public addTreasure(type: TreasureType, amount: number = 1) {
    this.stateService.treasureBag.AddItem(new TreasureItem(type, amount));
  }
}
