// 公会权限
import { parseNumberList, readFileAndParse } from '../util'
import { FILENAME } from '../../consts'

export interface DicGuildAuction {

    // 活动类型 1-蛮夷入侵 2-诸侯混战 3-粮草先行
    readonly id: number;
    // 建筑物等级
    readonly struLv: number;
    // 最低名次
    readonly min: number;
    // 最高名次
    readonly max: number;
    // 奖励
    readonly rewards: number;
    // 城池
    readonly cityId: number;
    // 基础分红
    readonly basicDividend: number;
}

export const dicGuildAuction = new Map<string, DicGuildAuction[]>();
export function loadGuildAuction() {
    dicGuildAuction.clear();
    
    let arr = readFileAndParse(FILENAME.DIC_GUILD_AUCTION);

    arr.forEach(o => {
        let cityIds = parseNumberList(o.cityId);
        if(cityIds.length <= 0) { // 诸侯混战以外的活动
            cityIds = [0];
        }
        for(let cityId of cityIds) {
            let rank = dicGuildAuction.get(`${o.id}_${o.struLv}_${cityId}`)||[];
            rank.push(o);
            dicGuildAuction.set(`${o.id}_${o.struLv}_${cityId}`, rank);
        }
    });
    arr = undefined;
}