import { ABI_TYPE } from "./abilityConst";

export const IT_TYPE = {
    BLUEPRT: 28,
    EQUIP_PIECE: 40,
    HERO_PIECE: 25,
    PAPER: 41,
}


// 背包页签
export const GOOD_TYPE = {
    ITEM: 1,
    EQUIP: 2,
    PIECE: 3,
    BLUEPRT: 4,
    JEWEL: 5,
    PICTURE: 6
};

// 存到消耗品表内显示的类型
export const CONSUME_TYPE = {
    CONSUME: 1, // 消耗品
    SOUL: 2, // 将魂
    BLUEPRT: 3, // 藏宝图
    POINT: 4, // 远征币等
    EXP: 5, // 经验书
    FAVOUR: 6, // 好感度道具
    SKIN: 7,  // 时装
    PIECE: 8, // 装备碎片
    JEWEL: 9, //宝石
    FRIEND_FAVOUR: 10, // 好友道具
    HEAD: 11, // 头像
    FRAME: 12, // 相框
    SPINE: 13, // 形象
    GIFT_PACKAGE: 14, // 礼包
    AP: 15,     // 回复体力道具
    DICE: 16,     // 骰子
    DRAWING: 17,   // 图纸
    VOUCHER: 18,   // 代金券
    ARTIFACT_GENERAL: 19,   // 宝物通用
};

export enum ROLE_TERAPH {
    START = 1,
    END = 4
}

export enum PVP_PLAYER_POS {
    START = 1,
    END = 3
}

export enum PVP_HERO_POS {
    START = 2001,
    END = 2009
}

export enum PVP_HERO_ORDER {
    START = 1,
    END = 9
}

export enum EQUIP_TYPE {
    START = 1,
    WEAPON = 1,      // 神兵（武器）
    CLOTHES = 2,     // 宝甲（上装）
    SHOES = 3,       // 行具（下装）
    CAP = 4,         // 冠冕（头部）
    BOOK = 5,        // 典籍（饰品）
    ACCESSORY = 6,   // 礼器（饰品）
    END = 6
}

export const equipTypeToSortAttr = new Map([
    [EQUIP_TYPE.WEAPON, ABI_TYPE.ABI_ATK],
    [EQUIP_TYPE.CLOTHES, ABI_TYPE.ABI_HP],
    [EQUIP_TYPE.SHOES, ABI_TYPE.ABI_ATK],
    [EQUIP_TYPE.CAP, ABI_TYPE.ABI_HP],
    [EQUIP_TYPE.ACCESSORY, ABI_TYPE.ABI_DEF],
    [EQUIP_TYPE.BOOK, ABI_TYPE.ABI_MDEF]
]);

export enum JEWEL_TYPE {
    WEAPON = 42,      // 神兵（武器）
    CLOTHES = 43,     // 宝甲（上装）
    SHOES = 45,       // 行具（下装）
    CAP = 44,         // 冠冕（头部）
    BOOK = 46,        // 典籍（饰品）
    ACCESSORY = 47,   // 礼器（饰品）
}

export const ITEM_TABLE = {
    EQUIP: 'equip',
    ITEM: 'item',
    ROLE: 'role',
    HERO: 'hero',
    SKIN: 'skin',
    JEWEL: 'jewel',
    ARTIFACT: 'artifact',
}

const itid_array = [
    { id: 1, name: '神兵', table: 'equip', type: EQUIP_TYPE.WEAPON, equipJewel: JEWEL_TYPE.WEAPON }, //
    { id: 2, name: '宝甲', table: 'equip', type: EQUIP_TYPE.CLOTHES, equipJewel: JEWEL_TYPE.CLOTHES }, //
    { id: 3, name: '冠冕', table: 'equip', type: EQUIP_TYPE.SHOES, equipJewel: JEWEL_TYPE.CAP }, //
    { id: 4, name: '行具', table: 'equip', type: EQUIP_TYPE.CAP, equipJewel: JEWEL_TYPE.SHOES }, //
    { id: 5, name: '典籍', table: 'equip', type: EQUIP_TYPE.BOOK, equipJewel: JEWEL_TYPE.BOOK }, //
    { id: 6, name: '饰品', table: 'equip', type: EQUIP_TYPE.ACCESSORY, equipJewel: JEWEL_TYPE.ACCESSORY }, //
 
    { id: 24, name: '消耗品', table: 'item', type: CONSUME_TYPE.CONSUME },

    { id: 37, name: '消耗类物品（图纸类）', table: 'item', type: CONSUME_TYPE.CONSUME },
    { id: 35, name: '消耗类物品（经验书）', table: 'item', type: CONSUME_TYPE.EXP },
    { id: 36, name: '消耗类物品（好感道具）', table: 'item', type: CONSUME_TYPE.FAVOUR },
    { id: 38, name: '消耗类物品（材料类）', table: 'item', type: CONSUME_TYPE.CONSUME },
    { id: 24, name: '使用类物品（宝箱类）', table: 'item', type: CONSUME_TYPE.GIFT_PACKAGE },
    { id: 25, name: '武将碎片', table: 'item', type: CONSUME_TYPE.SOUL },

    { id: 26, name: '剧情物品', table: 'item', type: CONSUME_TYPE.CONSUME },

    { id: 27, name: '货币', table: 'role', isCurrency: true },
    { id: 28, name: '藏宝图', table: 'item', type: CONSUME_TYPE.BLUEPRT },

    { id: 29, name: '礼器', table: 'equip', type: EQUIP_TYPE.ACCESSORY }, //
    { id: 30, name: '宝甲', table: 'equip', type: EQUIP_TYPE.CLOTHES }, //
    { id: 31, name: '名驹', table: 'equip', type: EQUIP_TYPE.SHOES }, //
    { id: 32, name: '典籍', table: 'equip', type: EQUIP_TYPE.BOOK }, //
    { id: 33, name: '神兵', table: 'equip', type: EQUIP_TYPE.WEAPON }, //
    { id: 34, name: '代币', table: 'item', type: CONSUME_TYPE.POINT },
    { id: 53, name: '武将招募券', table: 'item', type: CONSUME_TYPE.POINT },
    { id: 39, name: '时装', table: 'skin', type: CONSUME_TYPE.SKIN },
    { id: 40, name: '装备碎片', table: 'item', type: CONSUME_TYPE.PIECE },
    { id: 41, name: '图纸', table: 'item', type: CONSUME_TYPE.DRAWING },
    { id: 42, name: '神兵宝石', table: 'item', type: CONSUME_TYPE.JEWEL },
    { id: 43, name: '宝甲宝石', table: 'item', type: CONSUME_TYPE.JEWEL },
    { id: 44, name: '免冠宝石', table: 'item', type: CONSUME_TYPE.JEWEL },
    { id: 45, name: '足具宝石', table: 'item', type: CONSUME_TYPE.JEWEL },
    { id: 46, name: '礼器宝石', table: 'item', type: CONSUME_TYPE.JEWEL }, //
    { id: 47, name: '典籍宝石', table: 'item', type: CONSUME_TYPE.JEWEL }, //
    { id: 48, name: '灵玄石', table: 'item', type: CONSUME_TYPE.JEWEL },
    { id: 49, name: '玩家好感道具', table: 'item', type: CONSUME_TYPE.FRIEND_FAVOUR },
    { id: 50, name: '形象', table: 'role', type: CONSUME_TYPE.HEAD },
    { id: 51, name: '相框', table: 'role', type: CONSUME_TYPE.FRAME },
    { id: 52, name: '玩家形象', table: 'role', type: CONSUME_TYPE.SPINE },
    { id: 55, name: '回复体力道具', table: 'item', type: CONSUME_TYPE.AP },
    { id: 56, name: '骰子', table: 'item', type: CONSUME_TYPE.DICE },
    { id: 58, name: '主公经验', table: 'role' },
    { id: 59, name: '武器天晶石', table: 'jewel' },
    { id: 60, name: '衣服天晶石', table: 'jewel' },
    { id: 61, name: '头饰天晶石', table: 'jewel' },
    { id: 62, name: '行具天晶石', table: 'jewel' },
    { id: 63, name: '代金券', table: 'item', type: CONSUME_TYPE.VOUCHER },
    { id: 64, name: '宝物', table: 'artifact' },
    { id: 65, name: '宝物通用材料', table: 'item', type: CONSUME_TYPE.ARTIFACT_GENERAL },
];

export const ITID = new Map<number, { id: number, name: string, table: string, type?: number, isCurrency?: boolean, equipJewel?: number }>();
for (let obj of itid_array) {
    ITID.set(obj.id, obj);
}

export const CURRENCY_TYPE = {
    GOLD: "gold",
    COIN: "coin",
    ACTION_POINT: "ap",
    TREASURE_POINT: "treasurePoint",
    EXPEDITION_POINT: "expeditionPoint",
    DUNGEON_POINT: "dungeonPoint",
    FRIEND_POINT: "frdCnt",
    HONOUR: "honour",
    SKIN_COIN: "skinCoin",
    DUNGEON: "dungeon",
    NORMAL_DICE: "normalDice",
    SPECIAL_DICE: "specialDice",
    KING_EXP: 'kingExp',
    VOUCHER: 'voucher',
}

const currencyArr = [
    { "gid": 31001, "name": "铜钱", "type": CURRENCY_TYPE.COIN },
    { "gid": 31002, "name": "元宝", "type": CURRENCY_TYPE.GOLD },
    { "gid": 31003, "name": "体力", "type": CURRENCY_TYPE.ACTION_POINT },
    { "gid": 40001, "name": "远征币", "type": CURRENCY_TYPE.EXPEDITION_POINT },
    { "gid": 40002, "name": "寻宝币", "type": CURRENCY_TYPE.TREASURE_POINT },
    { "gid": 40003, "name": "情谊点", "type": CURRENCY_TYPE.FRIEND_POINT },
    { "gid": 40004, "name": "秘境币", "type": CURRENCY_TYPE.DUNGEON_POINT },
    { "gid": 40005, "name": "功勋", "type": CURRENCY_TYPE.HONOUR },
    { "gid": 40006, "name": "蜀锦", "type": CURRENCY_TYPE.SKIN_COIN },
    { "gid": 40007, "name": "秘境币", "type": CURRENCY_TYPE.DUNGEON },
    { "gid": 72011, "name": "普通骰子", "type": CURRENCY_TYPE.NORMAL_DICE },
    { "gid": 72021, "name": "天机骰子", "type": CURRENCY_TYPE.SPECIAL_DICE },
    { "gid": 72030, "name": "主公经验", "type": CURRENCY_TYPE.KING_EXP },
    { "gid": 81000, "name": "代金券", "type": CURRENCY_TYPE.VOUCHER}
];
export const CURRENCY = new Map<number, { gid: number, name: string, type: string }>();
export const CURRENCY_BY_TYPE = new Map<string, number>();
for (let obj of currencyArr) {
    CURRENCY.set(obj.gid, obj);
    CURRENCY_BY_TYPE.set(obj.type, obj.gid);
}

export function getCurNameById(gid: number) {
    let currency = CURRENCY.get(gid);
    if (!currency) {
        return '';
    }
    return currency.type;
}

export function getHeadItid() {
    let dicItid = itid_array.find(cur => cur.table == 'role' && cur.type == CONSUME_TYPE.HEAD);
    return dicItid?.id;
}

export function getFrameItid() {
    let dicItid = itid_array.find(cur => cur.table == 'role' && cur.type == CONSUME_TYPE.FRAME);
    return dicItid?.id;
}

export function getSpineItid() {
    let dicItid = itid_array.find(cur => cur.table == 'role' && cur.type == CONSUME_TYPE.SPINE);
    return dicItid?.id;
}

export enum QUALITY_TYPE {
    BLUE = 1, // 蓝
    PURPLE = 2, // 紫
    ORANGE = 3, // 橙
    RED = 4, // 红
    GOLD = 5 // 金
}

export const GOOD_QUALITY = [QUALITY_TYPE.BLUE, QUALITY_TYPE.PURPLE, QUALITY_TYPE.ORANGE, QUALITY_TYPE.RED, QUALITY_TYPE.GOLD];
export const COM_BTL_QUALITY = [QUALITY_TYPE.BLUE, QUALITY_TYPE.PURPLE, QUALITY_TYPE.ORANGE, QUALITY_TYPE.RED];


export enum HERO_QUALITY_TYPE {
    BLUE = 1, // 蓝将
    PURPLE = 2, // 紫将
    GOLD = 3, // 金
    UR = 4,  // ur武将
}

export const FIX_ATTRIBUTES_RAN = 20; // 固定属性值+-20%随机

export function getDropItems() {
    let items = [
        { id: 25, count: 1 }, { id: 225, count: 1 }, { id: 625, count: 1 }, { id: 2025, count: 1 }, { id: 3025, count: 1 }, { id: 4025, count: 1 }, { id: 5025, count: 1 }, { id: 6025, count: 1 },
        { id: 1, count: 1 }, { id: 2, count: 1 }, { id: 101, count: 1 }, { id: 102, count: 1 }, { id: 201, count: 1 }, { id: 202, count: 1 }, { id: 301, count: 1 }, { id: 302, count: 1 },
        { id: 401, count: 1 }, { id: 501, count: 1 }, { id: 601, count: 1 }, { id: 602, count: 1 }, { id: 701, count: 1 }, { id: 702, count: 1 }, { id: 2001, count: 1 }, { id: 2002, count: 1 },
        { id: 2101, count: 1 }, { id: 2102, count: 1 }, { id: 2201, count: 1 }, { id: 2202, count: 1 }, { id: 3001, count: 1 }, { id: 3002, count: 1 }, { id: 3101, count: 1 }, { id: 3102, count: 1 },
        { id: 3201, count: 1 }, { id: 3202, count: 1 }, { id: 4001, count: 1 }, { id: 4002, count: 1 }, { id: 4101, count: 1 }, { id: 4102, count: 1 }, { id: 4201, count: 1 }, { id: 4202, count: 1 },
        { id: 5001, count: 1 }, { id: 5002, count: 1 }, { id: 5101, count: 1 }, { id: 5102, count: 1 }, { id: 5201, count: 1 }, { id: 5202, count: 1 }, { id: 6001, count: 1 }, { id: 6002, count: 1 },
        { id: 6101, count: 1 }, { id: 6102, count: 1 }, { id: 11001, count: 10000 }, { id: 11002, count: 10000 }, { id: 11003, count: 10000 }, { id: 11004, count: 100000 }, { id: 11011, count: 100000 },
        { id: 11012, count: 100000 }, { id: 11013, count: 100000 }, { id: 11014, count: 100000 }, { id: 11015, count: 100000 }, { id: 11016, count: 100000 }, { id: 11017, count: 100000 },
        { id: 17001, count: 100000 }, { id: 17002, count: 100000 }, { id: 17003, count: 100000 }, { id: 17004, count: 100000 }, { id: 17005, count: 100000 }, { id: 17006, count: 100000 },
        { id: 17007, count: 100000 }, { id: 17008, count: 100000 }, { id: 17009, count: 100000 }, { id: 17010, count: 100000 }, { id: 17011, count: 100000 }, { id: 17012, count: 100000 },
        { id: 17013, count: 100000 }, { id: 17014, count: 100000 }, { id: 17015, count: 100000 }, { id: 17016, count: 100000 }, { id: 17016, count: 100000 }, { id: 17017, count: 100000 },
        { id: 17018, count: 100000 }, { id: 17019, count: 100000 }, { id: 17020, count: 100000 }, { id: 17021, count: 100000 }, { id: 17022, count: 100000 }, { id: 17023, count: 100000 },
        { id: 17024, count: 100000 }, { id: 17025, count: 100000 }, { id: 17026, count: 100000 }, { id: 17027, count: 100000 }, { id: 17028, count: 100000 }, { id: 17029, count: 100000 },
        { id: 17030, count: 100000 }, { id: 17031, count: 100000 }, { id: 17032, count: 100000 }, { id: 17033, count: 100000 }, { id: 17034, count: 100000 }, { id: 17035, count: 100000 },
        { id: 17036, count: 100000 }, { id: 17037, count: 100000 }, { id: 17038, count: 100000 }, { id: 17039, count: 100000 }, { id: 17040, count: 100000 }, { id: 17041, count: 100000 },
        { id: 17042, count: 100000 }, { id: 17043, count: 100000 }, { id: 17044, count: 100000 }, { id: 17045, count: 100000 }, { id: 17046, count: 100000 }, { id: 17047, count: 100000 },
        { id: 21001, count: 100000 }, { id: 21002, count: 100000 }, { id: 31001, count: 100000 }, { id: 31002, count: 100000 }, { id: 31003, count: 100000 }, { id: 33001, count: 100000 },
        { id: 33002, count: 100000 }, { id: 33003, count: 100000 }, { id: 40001, count: 100000 }, { id: 40002, count: 100000 }, { id: 42001, count: 100000 }, { id: 42002, count: 100000 },
        { id: 50009, count: 100000 }, { id: 50010, count: 100000 }, { id: 60001, count: 100000 }, { id: 60002, count: 100000 }, { id: 4, count: 2 }, { id: 2004, count: 2 }, { id: 220, count: 2 },
        { id: 2008, count: 2 }, { id: 2012, count: 2 }, { id: 2208, count: 2 }, { id: 2016, count: 2 }, { id: 2120, count: 2 }, { id: 2220, count: 2 }, { id: 50031, count: 1000 }
    ]
    return items;
}


// 头像/相框 获取条件
export enum FIGURE_UNLOCK_CONDITION {
    GET_HERO = 1,      // 获取武将
    HERO_FAVOR = 2,    // 武将好感度达到
    PVP_WIN_SERIES = 3, // pvp连胜
    GET_SKIN = 7,    // 获得时装
}

// 神像随机属性数量
export const TERAPH_RANDOM = {
    MIN: 2,
    MAX: 4
}

// 道具特殊属性，如藏宝图等
export const SPECIAL_ATTR = {
    WAR_ID: 1,
    TREASURE_ID: 2,
    TREASURE_TYPE: 3
}

// 淬火类型
export enum QUENCH_TYPE {
    ONCE = 1,            // 升一级
    ONE_GRADE = 2,       // 升一品
}

// 精炼类型
export enum REFINE_TYPE {
    ONCE = 1,             // 精炼一次
    ONE_LEVEL = 2,        // 精炼一级
}