import { ACTIVITY_TYPE, PUSH_ROUTE, TASK_SUM_TYPE, TASK_TYPE, WAR_TYPE } from "../../consts";
import { ActivityModelType } from "../../db/Activity";
import { ActivityBuyRecordsModel } from "../../db/ActivityBuyRecords";
import { ActivityDailyChallengesModel } from "../../db/ActivityDailyChallenges";
import { ActivityGrowthModel } from "../../db/ActivityGrowth";
import { ActivityGrowthFundModel } from "../../db/ActivityGrowthFund";
import { ActivityRefreshTaskModel } from "../../db/ActivityRefreshTask";
import { ActivityThirtyDaysModel } from "../../db/ActivityThirtyDays";
import { ActivityTreasureHuntTaskModel } from "../../db/ActivityTreasureHuntTask";
import { RoleModel, RoleType } from "../../db/Role";
import { UserTaskRecModel } from "../../db/UserTaskRec";
import { GrowthFundData } from "../../domain/activityField/growthFundField";
import { RefreshTaskData } from "../../domain/activityField/refreshTaskField";
import { SevenDaysData } from "../../domain/activityField/sevenDaysField";
import { ThirtyDaysData } from "../../domain/activityField/thirtyDaysField";
import { TreasureHuntData } from "../../domain/activityField/treasureHuntField";
import { TaskListReturn, TaskParam, TaskParamInter, UpdateTaskParam } from "../../domain/roleField/task";
import { gameData, getDicBlueprtById, getEquipSuitByHero, getGVGTasksByType } from "../../pubUtils/data";
import { getZeroPoint } from "../../pubUtils/timeUtil";
import { getActivityByServerId } from "../activity/activityService";
import { getRoleCreateTime, getRoleOnlineInfo, getServerCreateTime } from "../redisService";
import { getEquipById, getJewelByEquip, isRandSeUnLock } from "../equipService";
import { sendMessageToUserWithSuc } from "../pushService";
import { GVGUserTaskModel } from "../../db/GVGUserTask";

export class CheckTask {
    serverId: number;       // 区id
    roleId: string;         // 玩家id
    role?: RoleType;
    roleCreateTime: number; // 玩家的创建时间
    serverCreateTime: number; // 服务器的创建时间

    configId?: number;
    leagueCode?: string;

    taskPushMessages: TaskListReturn[] = [];
    activityTaskPushMessages = [];
    gvgTaskPushMessages = [];

    tasks: CheckSingleTask[] = [];
    
    constructor(serverId: number, roleId: string) {
        this.serverId = serverId;
        this.roleId = roleId;
    }

    public setParam(taskType: TASK_TYPE, param: TaskParamInter) {
        let task = new CheckSingleTask(taskType, this);
        task.param.setParam(param);
        this.tasks.push(task);
    }

    setLeague(configId: number, leagueCode: string) {
        this.configId = configId;
        this.leagueCode = leagueCode;
    }

    public async saveAndPush(sid?: string) {
        for(let task of this.tasks) {
            await task.check();
        }
        await this.pushMessage(sid);
    }

    public setRole(role: RoleType) {
        this.role = role;
    }

    // 用于活动任务：获取服务器开服时间
    async getServerCreateTime() {
        if(!this.serverCreateTime) {
            this.serverCreateTime = await getServerCreateTime(this.serverId);
        }
        return this.serverCreateTime;
    }

    // 用于活动任务：获取玩家创建时间
    async getRoleCreateTime() {
        if(!this.roleCreateTime) {
            if(this.role) {
                this.roleCreateTime = this.role?.createTime;
            } else {
                this.roleCreateTime = await getRoleCreateTime(this.roleId);
            }
        }
        if(!this.roleCreateTime) {
            let role = await RoleModel.findByRoleId(this.roleId);
            this.role = role;
            this.roleCreateTime = role.createTime;
        }
        return this.roleCreateTime;
    }

    // 推送
    public async pushMessage(sid?: string) {
        let roleId = this.roleId;
        if (!sid) {
            let onlineUser = await getRoleOnlineInfo(roleId);
            sid = onlineUser.sid;
        }
        if(!!sid) {
            if (this.taskPushMessages.length > 0) {
                sendMessageToUserWithSuc(roleId, PUSH_ROUTE.TASK_UPDATE,this.taskPushMessages, sid);
            }
            if(this.gvgTaskPushMessages.length > 0) {
                sendMessageToUserWithSuc(roleId, PUSH_ROUTE.GVG_TASK_UPDATE,this.gvgTaskPushMessages, sid);
            }
            if (this.activityTaskPushMessages.length > 0) {
                sendMessageToUserWithSuc(roleId, PUSH_ROUTE.ACTIVITY_TASK_UPDATE, this.activityTaskPushMessages, sid);
            }
        }
    }

}

/**
 * @class CheckTask
 * @classdesc 检查某个玩家任务的达成情况
 */
export class CheckSingleTask {
    serverId: number;       // 区id
    roleId: string;         // 玩家id
    taskType: TASK_TYPE;    // 任务type
    parent: CheckTask;
    param: TaskParam;           // 检查任务时传入的参数

    constructor(taskType: TASK_TYPE, parent: CheckTask) {
        this.taskType = taskType;
        this.parent = parent;
        this.serverId = parent.serverId;
        this.roleId = parent.roleId;
        this.param = new TaskParam();
    }

    private addTaskPushMessage(...param: TaskListReturn[]) {
        this.parent.taskPushMessages.push(...param);
    }

    private addGVGTaskPushMessage(...param: {id: number, count: number}[]) {
        this.parent.gvgTaskPushMessages.push(...param);
    }

    private addActivityTaskPushMessage(...param: any[]) {
        this.parent.activityTaskPushMessages.push(...param);
    }

    private getServerCreateTime() {
        return this.parent.getServerCreateTime();
    }

    private getRoleCreateTime() {
        return this.parent.getRoleCreateTime();
    }

    private getRole() {
        return this.parent.role;
    }

    /**
     * @description 检查任务的主程序
     */
    public async check() {
        let { taskType, roleId, serverId } = this;
        let serverCreateTime = await this.getServerCreateTime();
        let roleCreateTime = await this.getRoleCreateTime();
        let param = this.param;
        let dicTaskTypeDesc = gameData.taskDescByType.get(taskType);
        
        // 检查一般任务
        let dicTasks = gameData.taskType.get(taskType)||[];
        let groups = new Map<string, { type: number, group: string, taskParam: number[], taskIds: number[] }>(); // 以group做区分
        for (let { id, type, group, taskParam } of dicTasks) {
            if (!groups.has(`${type}_${group}`)) {
                groups.set(`${type}_${group}`, { type, group, taskParam, taskIds: [] });
            }
            groups.get(`${type}_${group}`).taskIds.push(id);
        }
        for (let [_typeAndGroup, { type, group, taskParam, taskIds }] of groups) {
    
            let taskUpdateParam = await this.checkIsMatch(taskParam, async () => {
                let data = await UserTaskRecModel.findByRoleAndGroup(roleId, type, taskType, group);
                return data?.records ?? [];
            });
            if (taskUpdateParam) {
                let rec = await UserTaskRecModel.setOrIncTask(roleId, type, taskType, group, taskUpdateParam);
                if (!rec) continue;

                for (let id of taskIds) {
                    if (rec.received && rec.received.includes(id)) continue; // 已领取，不再推送
                    let received = rec.received || [];
                    this.addTaskPushMessage({ type, id: id, count: rec.count, received: received.includes(id) });
                }

            }
        }

        // 联军任务
        let dicGVGTasks = getGVGTasksByType(taskType);
        for(let { taskId, taskType, taskParam } of dicGVGTasks) {
            let taskUpdateParam = await this.checkIsMatch(taskParam, async () => []);
            if (taskUpdateParam) {
                let rec = await GVGUserTaskModel.setOrIncTask(this.parent.configId, this.parent.leagueCode, roleId, taskType, taskId, taskUpdateParam);
                if (!rec) continue;

                if(rec.status == 1) {
                    this.addGVGTaskPushMessage({ id: taskId, count: rec.count });
                }
            }
        }

        // 检查活动任务
        let activities = await getActivityByServerId(serverId);
        for(let activity of activities) {
            let { activityId, type: activityType } = activity;
            switch(activityType) {
                case ACTIVITY_TYPE.SEVEN_DAY:
                case ACTIVITY_TYPE.FOURTEEN_DAY://十四天乐活动 28
                case ACTIVITY_TYPE.COMMON_SEVEN_DAY://通用七天乐活动 29
                    {
                        //成长活动统计
                        let playerData = new SevenDaysData(activity, roleCreateTime, serverCreateTime);
                        let growthTaskArray = playerData.growth.findTaskByType(taskType); // 所有任务
                        for (let task of growthTaskArray) {
                            if(dicTaskTypeDesc.sumType == TASK_SUM_TYPE.DO && !playerData.canShow()) {
                                continue;
                            }
                            let taskUpdateParam = await this.checkIsMatch(task.taskParamArray, async () => {
                                let data = await ActivityGrowthModel.findDataByCellIndex(serverId, activityId, roleId, task.dayIndex, task.cellIndex);
                                return data?.records ?? [];
                            });
                            if(taskUpdateParam) {
                                let rec = await ActivityGrowthModel.setOrIncTask(serverId, activityId, roleId, task.dayIndex, task.cellIndex, taskType, taskUpdateParam);
                                if(!rec) continue;
                                this.addActivityTaskPushMessage({...task, totalCount: rec.totalCount, receiveRewardCount: rec.receiveRewardCount||0, activityId, activityType: "growth" });
                            }
                        }
                        //今日挑战统计
                        let dailyChallengeTaskArray = playerData.dailyChallenge.findTaskByType(taskType);
                        for (let task of dailyChallengeTaskArray) {
                            if(dicTaskTypeDesc.sumType == TASK_SUM_TYPE.DO && task.dayIndex != playerData.today()) {
                                continue;
                            } else if(dicTaskTypeDesc.sumType == TASK_SUM_TYPE.SUM && task.dayIndex < playerData.today()) {
                                continue;
                            }
                            let taskUpdateParam = await this.checkIsMatch(task.taskParamArray, async () => {
                                let data = await ActivityDailyChallengesModel.findDataByCellIndex(serverId, activityId, roleId, task.dayIndex, task.cellIndex);
                                return data?.records ?? [];
                            });
                            if(taskUpdateParam) {
                                let rec = await ActivityDailyChallengesModel.setOrIncTask(serverId, activityId, roleId, task.dayIndex, task.cellIndex, taskType, taskUpdateParam);
                                if(!rec) continue;
                                this.addActivityTaskPushMessage({...task, totalCount: rec.totalCount, receiveRewardCount: rec.receiveRewardCount||0, activityId, activityType: "daily" });
                            }
                        }
                        break;
                    }
                case ACTIVITY_TYPE.REFRESH_TASK:
                    {
                        // 通用的刷新任务
                        let taskActivity = new RefreshTaskData(activity, roleCreateTime, serverCreateTime);
                        let taskArray = taskActivity.findTaskByType(taskType);
                        for (let task of taskArray) {
                            if(dicTaskTypeDesc.sumType == TASK_SUM_TYPE.DO && !taskActivity.canShow()) {
                                continue;
                            }
                            let taskUpdateParam = await this.checkIsMatch(task.taskParamArray, async () => {
                                let data = await ActivityRefreshTaskModel.findDataById(serverId, activityId, roleId, taskActivity.roundIndex, task.pageIndex, task.id, task.getRefTime());
                                return data?.records ?? [];
                            });
                            if(taskUpdateParam) {
                                let rec = await ActivityRefreshTaskModel.setOrIncTask(serverId, activityId, roleId, taskActivity.roundIndex, task.pageIndex, task.id, task.getRefTime(), taskType, taskUpdateParam);
                                if(!rec) continue;
                                this.addActivityTaskPushMessage({...task, totalCount: rec.totalCount, receiveRewardCount: rec.receiveRewardCount||0, activityId });
                            }
                        }
                        break;
                    }
                case ACTIVITY_TYPE.TREASURE_HUNT:
                    {
                        // 寻宝奇兵任务
                        let playerData = new TreasureHuntData(activity, roleCreateTime, serverCreateTime);
                        let taskArray = playerData.tasks.findItemByTaskType(taskType);
                        for (let task of taskArray) {
                            if(dicTaskTypeDesc.sumType == TASK_SUM_TYPE.DO && !playerData.canShow()) {
                                continue;
                            }
                            let taskUpdateParam = await this.checkIsMatch(task.taskParamArray, async () => {
                                let data = await ActivityTreasureHuntTaskModel.findDataByCellIndex(serverId, activityId, roleId, playerData.roundIndex, task.cellIndex);
                                return data?.records ?? [];
                            });
                            if(taskUpdateParam) {
                                let rec = await ActivityTreasureHuntTaskModel.setOrIncTask(serverId, activityId, roleId, playerData.roundIndex, task.cellIndex, taskType, taskUpdateParam);
                                if(!rec) continue;
                                this.addActivityTaskPushMessage({ ...task, isReceive: rec.receiveRewardCount > 0? true: false, totalCount: rec.totalCount, activityId });
                            }
                        }
                        break;
                    }
                case ACTIVITY_TYPE.THIRTY_DAYS:
                    {
                        //30天任务统计
                        let thirtyDaysActivity = new ThirtyDaysData(activity, roleCreateTime, serverCreateTime);
                        let taskArray = thirtyDaysActivity.findTaskByType(taskType);
                        for (let task of taskArray) {
                            if(dicTaskTypeDesc.sumType == TASK_SUM_TYPE.DO && !thirtyDaysActivity.canShow()) {
                                continue;
                            }
                            let taskUpdateParam = await this.checkIsMatch(task.taskParamArray, async () => {
                                let data = await ActivityThirtyDaysModel.findDataByCellIndex(serverId, thirtyDaysActivity.activityId, roleId, task.pageIndex, task.cellIndex, task.tab);
                                return data?.records ?? [];
                            });
                            if(taskUpdateParam) {
                                let rec = await ActivityThirtyDaysModel.setOrIncTask(serverId, thirtyDaysActivity.activityId, roleId, task.pageIndex, task.cellIndex, task.tab, taskType, taskUpdateParam);
                                if(!rec) continue;
                                task.setPlayerRecord(rec);
                                this.addActivityTaskPushMessage({ ...task, totalCount: rec.totalCount, activityId });
                            }
                        }
                        break;
                    }
                case ACTIVITY_TYPE.GROWTH_FUND_MAIN:
                case ACTIVITY_TYPE.GROWTH_FUND_MAIN_VIP:
                    {
                        //主线成长基金
                        if(taskType != TASK_TYPE.BATTLE_MAIN) continue;
                        let dicWar = gameData.war.get(param.warId);
                        if(!dicWar || dicWar.warType != WAR_TYPE.NORMAL) continue;
                        await this.checkFundAcctivityTask(activity, param.warId);
                        break;
                    }
                case ACTIVITY_TYPE.GROWTH_FUND_TOWER:
                case ACTIVITY_TYPE.GROWTH_FUND_TOWER_VIP:
                    {
                        //镇念塔成长基金
                        if(taskType != TASK_TYPE.BATTLE_TOWER_LV) continue;
                        await this.checkFundAcctivityTask(activity, param.towerLv);
                        break;
                    }
                case ACTIVITY_TYPE.GROWTH_FUND_MAIN_ELITE:
                case ACTIVITY_TYPE.GROWTH_FUND_MAIN_ELITE_VIP:
                    {
                        //精英成长基金
                        if(taskType != TASK_TYPE.BATTLE_MAIN_ELITE) continue;
                        let dicWar = gameData.war.get(param.warId);
                        if(!dicWar || dicWar.warType != WAR_TYPE.MAIN_ELITE) continue;
                        await this.checkFundAcctivityTask(activity, param.warId);
                        break;
                    }
            }
        }

    }

    private async checkFundAcctivityTask(activity: ActivityModelType, unlockParam: number) {
        let serverCreateTime = await this.getServerCreateTime();
        let roleCreateTime = await this.getRoleCreateTime();
        let growthFundActivity = new GrowthFundData(activity, roleCreateTime, serverCreateTime);
        let playerRecords = await ActivityGrowthFundModel.findData(activity.activityId, this.roleId);
        growthFundActivity.setPlayerRecords(playerRecords);
        if (growthFundActivity.isVipActivity()) {//vip高阶需要购买
            let buyRecords = await ActivityBuyRecordsModel.findRecordsByActivityId(activity.activityId, this.roleId);
            growthFundActivity.initBuyRecords(buyRecords);
        }
        let taskArray = growthFundActivity.unLockItem(unlockParam);
        //推送
        this.addActivityTaskPushMessage(...taskArray);
    }

    public async checkIsMatch(dicTaskParam: number[], getRecord: () => Promise<string[]>) {
        let param = this.param;
        let result: UpdateTaskParam = null;

        if(this.param.debugInfo) {
            return { set: this.param.debugInfo.condition }
        }

        switch(this.taskType) {
            case TASK_TYPE.LOGIN_SUM: // 1. 累计登录 x 天
                {
                    let records = await getRecord();
                    let today = `${getZeroPoint()}`;
                    if (records.indexOf(today) == -1) {
                        result = { inc: 1, records: [...records, today] }
                    }
                    break;
                }
            case TASK_TYPE.LOGIN_SERIES: // 2. 连续登录 x 天
                {
                    let records = await getRecord();
                    let today = `${getZeroPoint()}`;
                    let yesterday = `${getZeroPoint() - 24 * 60 * 60}`
                    if (records.indexOf(today) == -1) {
                        if (records.indexOf(yesterday) == -1) {
                            result = { set: 1, records: [...records, today] }
                        } else {
                            result = { inc: 1, records: [...records, today] }
                        }
                    }
                    break;
                }
            case TASK_TYPE.ROLE_LV: // 3. 主公达x级
                {
                    let { lv, oldLv } = param;
                    if(lv > oldLv) {
                        result = { set: lv }
                    }
                    break;
                }
            case TASK_TYPE.GACHA: // 4. 招募x次
                {
                    let { count } = param;
                    result = { inc: count };
                    break;
                }
            case TASK_TYPE.HERO_NUM: // 5. 拥有x名武将
                {
                    let { heroNum } = param;
                    result = { inc: heroNum };
                    break;
                }
            case TASK_TYPE.HERO_STAR_UP: // 6. x名武将升星x次
                {
                    let { hero } = param;
                    let records = await getRecord();
                    let count = 0, index = -1;
                    for(let i = 0; i < records.length; i++) {
                        let arr = records[i].split('_');
                        if(parseInt(arr[0]) == hero.hid) {
                            count = parseInt(arr[1]);
                            index = i;
                            break;
                        }
                    }
                    if(index == -1) {
                        records.push(`${hero.hid}_${count + 1}`);
                    } else {
                        records[index] = `${hero.hid}_${count + 1}`;
                    }
                    if(count + 1 >= dicTaskParam[1]) {
                        result = { inc: 1, records }
                    } else {
                        result = { records }
                    }
                    break;
                }
            case TASK_TYPE.HERO_QUALITY: // 7. 拥有x名初始x品质武将
                {
                    let { heroes } = param;
                    let num = 0;
                    for(let { hid } of heroes) {
                        let dicHero = gameData.hero.get(hid);
                        if(dicHero.quality == dicTaskParam[1] ) {
                            num ++;
                        }
                    }
                    result = { inc: num };
                    break;
                }
            case TASK_TYPE.HERO_QUALITY_STAR_UP: // 8. x名x品质升至x星
                {
                    let { heroes, hero, oldStar, oldColorStar } = param;
                    if(param.heroes) { // 创建武将的时候
                        let records = await getRecord();
                        let num = 0;
                        for(let { hid, star, colorStar } of heroes) {
                            let dicHero = gameData.hero.get(hid);
                            if(dicHero.quality == dicTaskParam[1] && (star + colorStar) == dicTaskParam[2] && records.indexOf(`${hid}`) == -1) {
                                records.push(`${hid}`);
                                num ++;
                            }
                        }
                        result = { records, inc: num };
                    } else { // 武将升星的时候
                        let hid = hero.hid;
                        let dicHero = gameData.hero.get(hid);
                        if(dicHero.quality == dicTaskParam[1] && (hero.star + hero.colorStar) >= dicTaskParam[2] && (oldStar + oldColorStar) < dicTaskParam[2] ) {
                            let records = await getRecord();
                            if(records.indexOf(`${hid}`) == -1) {
                                records.push(`${hid}`);
                                result = { records, inc: 1 }
                            }
                        }
                    }
                    break;
                }
            case TASK_TYPE.HERO_LV: // 9. x名武将升至x级
                {
                    let { heroes, hero, oldLv } = param;
                    if(heroes) { // 创建武将的时候
                        let num = 0;
                        for(let { lv } of heroes) {
                            if(lv >= dicTaskParam[1]) {
                                num ++;
                            }
                        }
                        result = { inc: num };
                    } else { // 武将升级的时候
                        if(hero.lv >= dicTaskParam[1] && oldLv < dicTaskParam[1]) {
                            result = { inc: 1 }
                        }
                    }
                    break;
                }
            case TASK_TYPE.HERO_TRAIN: // 10. x名武将各训练x次
                {
                    let { hero, trainCount } = param;
                    let records = await getRecord();
                    let count = 0, index = -1;
                    for(let i = 0; i < records.length; i++) {
                        let arr = records[i].split('_');
                        if(parseInt(arr[0]) == hero.hid) {
                            count = parseInt(arr[1]);
                            index = i;
                            break;
                        }
                    }
                    if(index == -1) {
                        records[index] = `${hero.hid}_${count + trainCount}`;
                    } else {
                        records.push(`${hero.hid}_${count + trainCount}`);
                    }
                    if( count < dicTaskParam[1] && count + trainCount >= dicTaskParam[1]) {
                        result = { inc: 1, records }
                    } else {
                        result = { records }
                    }
                    break;
                }
            case TASK_TYPE.HERO_QUALITY_UP: // 11. x名武将进行升品
                {
                    let { hero } = param;
                    let records = await getRecord();
                    if(records.indexOf(`${hero.hid}`) == -1) {
                        records.push(`${hero.hid}`);
                        result = { records, inc: 1 };
                    }
                    break;
                }
            case TASK_TYPE.HERO_WAKE_UP: // 12.武将觉醒x次
                {
                    let { hero, oldColorStar } = param;
                    if(oldColorStar == 0 && hero.colorStar > 0) {
                        result = { inc: 1 };
                    }
                    break;
                }
            case TASK_TYPE.HERO_TRAIN_SUM: // 13. 训练x次
                {
                    let { trainCount } = param;
                    result = { inc: trainCount };
                    break;
                }
            case TASK_TYPE.HERO_STAGE_UP: // 14. x名武将各兵种进阶x次
                {
                    let { hero, stageUpCnt } = param;
                    let records = await getRecord();
                    let count = 0, index = -1;
                    for(let i = 0; i < records.length; i++) {
                        let arr = records[i].split('_');
                        if(parseInt(arr[0]) == hero.hid) {
                            count = parseInt(arr[1]);
                            index = i;
                            break;
                        }
                    }
                    if(index == -1) {
                        records.push(`${hero.hid}_${count + stageUpCnt}`);
                    } else {
                        records[index] = `${hero.hid}_${count + stageUpCnt}`;
                    }
                    if( count < dicTaskParam[1] && count + stageUpCnt >= dicTaskParam[1]) {
                        result = { inc: 1, records }
                    } else {
                        result = { records }
                    }
                    break;
                }
            // case TASK_TYPE.HERO_FAVOUR_LV: // 15. 
            //     {
            //         let { hero, oldFavourLv } = param;
            //         if(dicTaskParam[1] > oldFavourLv && dicTaskParam[1] <= hero.favourLv) {
            //             result = { inc: 1 };
            //         }
            //         break;
            //     }
            case TASK_TYPE.HERO_CONNECT: // 16. 激活x次 x星 武将羁绊
                {
                    let { shipId, connections, oldConnections } = param;
                    let oldConnectLv = oldConnections.find(cur => cur.shipId == shipId)?.level||0;
                    let connectLv = connections.find(cur => cur.shipId == shipId)?.level||0;
                    if(dicTaskParam[1] <= connectLv && dicTaskParam[1] > oldConnectLv) {
                        result = { inc: 1 };
                    }
                    break;
                }
            case TASK_TYPE.ROLE_SCHOOL_UNLOCK: // 17. 百家学宫解锁x个安置位
                {
                    result = { inc: 1 };
                    break;
                }
            case TASK_TYPE.ROLE_SCHOOL_PUT_HERO: // 18. 百家学宫放置x个武将
                {
                    let records = await getRecord();
                    let { hid } = param;
                    if(records.indexOf(`${hid}`) == -1) {
                        records.push(`${hid}`)
                        result = { records, inc: 1 };
                    }
                    break;
                }
            case TASK_TYPE.ROLE_TITLE: // 19. 爵位升至x
                {
                    let { title, oldTitle } = param;
                    if(title > oldTitle) {
                        result = { set: title };
                    }
                    break;
                }
            case TASK_TYPE.ROLE_TERAPH_STRENGTHEN: // 20. 神像强化x次
                {
                    let { count } = param;
                    result = { inc: count };
                    break;
                }
            case TASK_TYPE.ROLE_SCROLL_ACTIVE: // 21. 名将谱激活x武将
                {
                    result = { inc: 1 };
                    break;
                }
            case TASK_TYPE.FRIEND_NUM: // 34. 拥有x名好友
                {
                    let role = this.getRole();
                    result = { set: role.friendCnt };
                    break;
                }
            case TASK_TYPE.FRIEND_SEND_HEART: // 35. 赠送x次友情点
                {
                    let { count } = param;
                    if(count > 0) {
                        result = { inc: count };
                    }
                    break;
                }
            case TASK_TYPE.CHAT: // 36. 聊天频道发言x次
                {
                    let { chatType, count = 1 } = param;
                    if (dicTaskParam[0] == 0 || dicTaskParam[0] == chatType) {
                        result = { inc: count };
                    }
                    break;
                }
            case TASK_TYPE.BATTLE_COST_AP: // 37. 消耗体力
                {
                    let { count } = param;
                    if(count > 0) {
                        result = { inc: count };
                    }
                    break;
                }
            case TASK_TYPE.BATTLE_WITH_HERO: // 38. 使用hId武将挑战x关卡x次
                {
                    let { warId, battleHeroes } = param;
                    if(this.checkIdList(dicTaskParam, 2, warId) && battleHeroes.indexOf(dicTaskParam[0]) != -1) {
                        result = { inc: 1 };
                    }
                    break;
                }
            case TASK_TYPE.BATTLE_MAIN: // 39. 主线通关第x关
                {
                    let { warId, count } = param;
                    let dicWar = gameData.war.get(warId);
                    if (dicWar.warType == WAR_TYPE.NORMAL && this.checkIdList(dicTaskParam, 0, warId)) {
                        result = { inc: count };
                    }
                    break;
                }
            case TASK_TYPE.BATTLE_MAIN_SWEEP: // 40. 主线扫荡X次
                {
                    let { warId, count } = param;
                    let dicWar = gameData.war.get(warId);
                    if (dicWar.warType == WAR_TYPE.NORMAL) {
                        result = { inc: count }
                    }
                    break;
                }
            case TASK_TYPE.BATTLE_EVENT: // 41. 奇遇(答题/解救百姓/劫匪) x 次
                {
                    let { eventType } = param;
                    if(dicTaskParam[0] == 0|| dicTaskParam[0] == eventType) {
                        result = { inc: 1 };
                    }
                    break;
                }
            case TASK_TYPE.BATTLE_DAILY_STAR: // 42. 每日x星通关 x 次
                {
                    let { warId, battleStar } = param;
                    let dicWar = gameData.war.get(warId);
                    if (dicWar.warType == WAR_TYPE.DAILY && (dicTaskParam[0] == 0|| battleStar >= dicTaskParam[0]) && this.checkIdList(dicTaskParam, 2, warId)) {
                        result = { inc: 1 }
                    }
                    break;
                }
            case TASK_TYPE.BATTLE_DAILY: // 43. 每日关卡挑战x次
                {
                    let { warId, count } = param;
                    let dicWar = gameData.war.get(warId);
                    if(dicWar.warType == WAR_TYPE.DAILY && (dicTaskParam[0] == 0 || dicTaskParam[0] == dicWar.dailyType)) {
                        result = { inc: count };
                    }
                    break;
                }
            case TASK_TYPE.BATTLE_DUNGEON: // 44. 参与秘境x次
                {
                    let { warId, count } = param;
                    let dicWar = gameData.war.get(warId);
                    if(dicWar.warType == WAR_TYPE.MYSTERY) {
                        result = { inc: count };
                    }
                    break;
                }
            case TASK_TYPE.BATTLE_DUNGEON_WAR: // 45. 秘境通关x关x难度
                {
                    let { warId, count } = param;
                    let dicWar = gameData.war.get(warId);
                    if ((dicWar.warType == WAR_TYPE.MYSTERY) && this.checkIdList(dicTaskParam, 0, warId)) {
                        result = { inc: count };
                    }
                    break;
                }
            case TASK_TYPE.BATTLE_TOWER_LV: // 46. 通关镇念塔x层
                {
                    let { towerLv } = param;
                    result = { set: towerLv };
                    break;
                }
            case TASK_TYPE.BATTLE_TOWER: // 47. 通关镇念塔x次
                {
                    let { warId, count = 1, skipTower } = param;
                    let dicWar = gameData.war.get(warId);
                    // console.log('##### skipTower', skipTower)
                    if (skipTower || dicWar.warType == WAR_TYPE.TOWER) {
                        result = { inc: count };
                    }
                    break;
                }
            case TASK_TYPE.BATTLE_VESTIGE: // 48. 挑战遗迹x次
                {
                    let { warId, count } = param;
                    let dicWar = gameData.war.get(warId);
                    if (dicWar.warType == WAR_TYPE.VESTIGE && this.checkIdList(dicTaskParam, 0, warId)) {
                        result = { inc: count };
                    }
                    break;
                }
            case TASK_TYPE.BATTLE_EXPEDITION: // 49. 开启远征x次
                {
                    let { warId, count } = param;
                    let dicWar = gameData.war.get(warId);
                    if (dicWar.warType == WAR_TYPE.EXPEDITION) {
                        result = { inc: count };
                    }
                    break;
                }
            case TASK_TYPE.BATTLE_EXPEDITION_BOX: // 50. 领取x次远征 x宝箱
                {
                    let { point } = param;
                    if(dicTaskParam[1] == 0 || dicTaskParam[1] == point) {
                        result = { inc: 1 };
                    }
                    break;
                }
            case TASK_TYPE.COM_BATTLE_CREATE_TEAM: // 51. 寻宝招募队友x次
                {
                    result = { inc: 1 };
                    break;
                }

            case TASK_TYPE.COM_BATTLE_ASSIST_TEAM: // 53. 协助寻宝x次
                {
                    result = { inc: 1 };
                    break;
                }
            case TASK_TYPE.COM_BATTLE: // 54. 组队寻宝
                {
                    result = { inc: 1 };
                    break;
                }
            case TASK_TYPE.PVP: // 57. pvp挑战 x 次
                {
                    result = { inc: 1 };
                    break;
                }
            case TASK_TYPE.PVP_WIN: // 58. pvp胜利 x 次
                {
                    let { isSuccess } = param;
                    if(isSuccess) {
                        result = { inc: 1 };
                    }
                    break;
                }
            case TASK_TYPE.PVP_RECEIVE_BOX: // 59. 领取x次pvp巅峰之路宝箱
                {
                    result = { inc: 1 };
                    break;
                }
            case TASK_TYPE.PVP_WIN_SERIES: // 60. pvp连胜x次
                {
                    let { isSuccess } = param;
                    if (isSuccess) {
                        result = { inc: 1 };
                    } else {
                        result = { set: 0 };
                    }
                    break;
                }
            case TASK_TYPE.PVP_HERO_SCORE: // 61. pvp拥有x个积分达到x的武将
                {
                    let { heroScores } = param;
                    let count = 0;
                    for (let { score } of heroScores) {
                        if (score >= dicTaskParam[0]) {
                            count++;
                        }
                    }
                    if (count > 0) {
                        result = { set: count };
                    }
                    break;
                    
                }
            case TASK_TYPE.PVP_RANK: // 62. pvp赛季排名达到 x 名
                {
                    let { pvpRank } = param;

                    let records = await getRecord();
                    let oldPvpRank = parseInt(records[0]);
                    if(isNaN(oldPvpRank)) oldPvpRank = 0;
                    if(pvpRank > oldPvpRank) {
                        records[0] = `${pvpRank}`;
                        result = { set: pvpRank, records }
                    }
                    break;
                }
            case TASK_TYPE.GUILD_JOB: // 63. 军团官职晋升为x
                {
                    let { guildJob } = param;

                    let records = await getRecord();
                    let oldGuildJob = parseInt(records[0]);
                    if(isNaN(oldGuildJob)) oldGuildJob = 0;
                    if(guildJob > oldGuildJob) {
                        records[0] = `${guildJob}`;
                        result = { set: guildJob, records }
                    }
                    break;
                }
            case TASK_TYPE.GUILD_DONATE: // 64. 军团捐献x次
                {
                    result = { inc: 1 };
                    break;
                }
            case TASK_TYPE.GUILD_RECEIVE_BOX: //65. 领取x次军团活跃宝箱
                {
                    result = { inc: 1 };
                    break;
                }
            case TASK_TYPE.GUILD_ASSIST_REFINE: // 67. 助力炼器堂研发加速x次
                {
                    result = { inc: 1 };
                    break;
                }
            case TASK_TYPE.GUILD_TRAIN_SUCESS: // 68. 练兵场军团成功压制x次
                {
                    let { isSuccess } = param;
                    if(isSuccess) {
                        result = { inc: 1 };
                    }
                    break;
                }
            case TASK_TYPE.GUILD_BOSS: // 69. 演武台军团挑战x次boss
                {
                    result = { inc: 1 };
                    break;
                }
            case TASK_TYPE.GUILD_TRAIN: // 70. 挑战练兵场X次
                {
                    result = { inc: 1 };
                    break;
                }
            case TASK_TYPE.GUILD_ACTIVITY: // 71. 参与 xxx 军团活动 x 次
                {
                    let { aid } = param;
                    if (dicTaskParam[0] == 0 || aid == dicTaskParam[0]) {
                        result = { inc: 1 };
                    }
                    break;
                }
            case TASK_TYPE.GUILD_JOIN: // 72. 加入军团
                {
                    result = { set: 1 };
                    break;
                }
            case TASK_TYPE.BATTLE_MAIN_ELITE: // 73. 精英通关第x关
                {
                    let { warId, count } = param;
                    let dicWar = gameData.war.get(warId);
                    if (dicWar.warType == WAR_TYPE.MAIN_ELITE && this.checkIdList(dicTaskParam, 0, warId)) {
                        result = { inc: count };
                    }
                    break;
                }
            case TASK_TYPE.HERO_QUALITY_TO_QUALITY_COUNT: // 74. x名初始x品质武将升至X品质
                {
                    let { hero } = param;
                    let dicHero = gameData.hero.get(hero.hid);
                    if(dicHero.quality == dicTaskParam[1] && hero.quality == dicTaskParam[2]) {
                        let records = await getRecord();
                        if(records.indexOf(`${hero.hid}`) == -1) {
                            records.push(`${hero.hid}`)
                            result = { records, inc: 1 };
                        }
                    }
                    break;
                }
            case TASK_TYPE.HERO_QUALITY_WAKE_UP_COUNT: // 75. x名初始x品质武将觉醒
                {
                    let { hero, oldColorStar } = param;
                    let dicHero = gameData.hero.get(hero.hid);
                    if(dicTaskParam[1] == dicHero.quality && oldColorStar == 0 && hero.colorStar > 0) {
                        let records = await getRecord();
                        if(records.indexOf(`${hero.hid}`) == -1) {
                            records.push(`${hero.hid}`)
                            result = { records, inc: 1 };
                        }
                    }
                    break;
                }
            case TASK_TYPE.HERO_WAKE_UP_STAR_UP_COUNT: // 76. x名武将觉醒后升至x星
                {
                    let { hero, oldColorStar } = param;
                    if(dicTaskParam[1] > oldColorStar && hero.colorStar >= dicTaskParam[1]) {
                        let records = await getRecord();
                        if(records.indexOf(`${hero.hid}`) == -1) {
                            records.push(`${hero.hid}`)
                            result = { records, inc: 1 };
                        }
                    }
                    break;
                }
            case TASK_TYPE.GUILD_TRAIN_COUNT: // 79. 练兵场通关x关x次
                {
                    let { warId, isComplete } = param;
                    if(isComplete && this.checkIdList(dicTaskParam, 0, warId)) {
                        result = { inc: 1 };
                    }
                    break;
                }
            case TASK_TYPE.HERO_UNLOCK: // 80. 名将谱x阵营全部激活
                {
                    let { hero } = param;
                    let dicHero = gameData.hero.get(hero.hid);
                    if(dicHero && dicHero.camp == dicTaskParam[1]) {
                        result = { inc: 1 };
                    }
                    break;
                }
            case TASK_TYPE.GACHA_QUALITY_COUNT: // 81. 抽到*次品质*武将
                {
                    let { heroes } = param;
                    let count = 0;
                    for (let hero of heroes) {
                        let dicHero = gameData.hero.get(hero.hid);
                        if(dicHero.quality == dicTaskParam[1]) count++;
                    }
                    if(count > 0) {
                        result = { inc: count };
                    }
                    break;
                }
            case TASK_TYPE.ROLE_TERAPH_STAGE_UP: // 82. 神像进阶
                {
                    result = { inc: 1 };
                    break;
                }
            case TASK_TYPE.HERO_WAKE_UP_COUNT: // 84. x名武将觉醒
                {
                    let { hero, oldColorStar } = param;
                    if(oldColorStar == 0 && hero.colorStar > 0) {
                        let records = await getRecord();
                        if(records.indexOf(`${hero.hid}`) == -1) {
                            records.push(`${hero.hid}`);
                            result = { records, inc: 1 };
                        }
                    }
                    break;
                }
            case TASK_TYPE.ACTIVITY_RMB: // 86. 某个活动充值*元
                {
                    let { count } = param;
                    result = { inc: count };
                    break;
                }
            case TASK_TYPE.EQUIP_LV_TO: // 87. x件装备强化至x级
                {
                    let { oldEplace, newEplace, ePlaceIds } = param;
                    let addCount = 0;
                    for(let eplaceId of ePlaceIds) {
                        let { oldEquip, newEquip } = getEquipById(oldEplace, newEplace, eplaceId);
                        // console.log('##### oldEquip', oldEquip.lv, newEquip.lv, dicTaskParam[1])
                        if(oldEquip.lv < dicTaskParam[1] && newEquip.lv >= dicTaskParam[1]) {
                            addCount += 1;
                        }
                    }
                    if(addCount != 0) {
                        result = { inc: addCount };
                    }
                    break;
                }
            case TASK_TYPE.EQUIP_PUT_JEWEL: // 88. x件装备镶嵌X阶天晶石
                {
                    let { hid, newEquip, jewels } = param;
                    if(!newEquip) break;

                    let jewel = getJewelByEquip(newEquip, jewels);
                    let lv = gameData.jewel.get(jewel?.id)?.lv || 0;
                    if(lv < dicTaskParam[1]) break;

                    let records = await getRecord();
                    if(records.indexOf(`${hid}_${newEquip.id}`) == -1) {
                        records.push(`${hid}_${newEquip.id}`)
                        result = { records, inc: 1 };
                    }

                    break;
                }
            case TASK_TYPE.EQUIP_PUT_STONE: // 89. x件装备镶嵌X个地玉石
                {
                    let { hid, newEquip } = param;
                    if(!newEquip) break;
                    let newStoneCnt = newEquip.stones.filter(cur => cur.stone != 0).length;
                    if(newStoneCnt < dicTaskParam[1]) break;

                    let records = await getRecord();
                    if(records.indexOf(`${hid}_${newEquip.id}`) == -1) {
                        records.push(`${hid}_${newEquip.id}`);
                        result = { records, inc: 1 };
                    }

                    break;
                }
            case TASK_TYPE.EQUIP_STAR_UP_TO: // 90. x件装备升至X星
                {
                    let { oldEquip, newEquip } = param;
                    let oldStar = oldEquip?.star||0;
                    let star = newEquip?.star||0
                    if(oldStar < dicTaskParam[1] && star >= dicTaskParam[1]) {
                        result = { inc: 1 };
                    };
                    break;
                }
            case TASK_TYPE.EQUIP_STAR_UP_CNT: // 91. x件装备升星X次
                {
                    let { hid, ePlaceId, count: paramCount } = param;
                    let records = await getRecord();
                    let count = 0, index = -1;
                    for(let i = 0; i < records.length; i++) {
                        let arr = records[i].split('_');
                        if(parseInt(arr[0]) == hid && parseInt(arr[1]) == ePlaceId) {
                            count = parseInt(arr[2]);
                            index = i;
                            break;
                        }
                    }

                    if(index == -1) {
                        records.push(`${hid}_${ePlaceId}_${count + paramCount}`);
                    } else {
                        records[index] = `${hid}_${ePlaceId}_${count + paramCount}`;
                    }
                    if(count < dicTaskParam[1] && count + paramCount >= dicTaskParam[1]) {
                        result = { inc: 1, records }
                    } else {
                        result = { records }
                    }
                    break;
                }
            case TASK_TYPE.EQUIP_SUIT_SEID_NUM: // 92. x名武将激活X条套装属性
                {
                    let { oldEplace, newEplace, skinId } = param;
                    let dicEquipSuit = getEquipSuitByHero(skinId);
                    let oldSuitStars: number[] = [], newSuitStars: number[] = [];
                    for(let equipId of dicEquipSuit.equips) {
                        let oldEquip = oldEplace.find(cur => cur.equipId == equipId);
                        oldSuitStars.push(oldEquip? oldEquip.star: 0);
                        let newEquip = newEplace.find(cur => cur.equipId == equipId);
                        newSuitStars.push(newEquip? newEquip.star: 0);
                    }
                    let oldStar = Math.min(...oldSuitStars);
                    let newStar = Math.min(...newSuitStars);
                    let oldCount = 0, count = 0;
                    for(let { star } of dicEquipSuit.effect) {
                        if(oldStar >= star) oldCount++;
                        if(newStar >= star) count++;
                    }
                    if(oldCount < dicTaskParam[1] && count >= dicTaskParam[1]) {
                        result = { inc: 1 };
                    }
                    break;
                }
            case TASK_TYPE.EQUIP_QUALITY_UP: // 93. x件装备进行升品
                {
                    let { hid, ePlaceId } = param;
                    let records = await getRecord();
                    if(records.indexOf(`${hid}_${ePlaceId}`) == -1) {
                        result = { inc: 1 };
                    }
                    break;
                }
            case TASK_TYPE.EQUIP_QUALITY_UP_CNT: // 94. 装备升品X次
                {
                    let { count } = param;
                    result = { inc: count };
                    break;
                }
            case TASK_TYPE.EQUIP_QUALITY_UP_TO: // 95. X件装备升品至Y品质
                {
                    let { oldEquip, newEquip } = param;
                    let oldQuality = oldEquip?.quality||0;
                    let quality = newEquip?.quality||0;
                    if(oldQuality < dicTaskParam[1] && quality >= dicTaskParam[1]) {
                        result = { inc: 1 };
                    }
                    break;
                }
            case TASK_TYPE.EQUIP_COMPOSE: // 96. 装备X件装备
                {
                    let { count } = param;
                    result = { inc: count };
                    break;
                }
            case TASK_TYPE.EQUIP_COMPOSE_CNT: // 97. x名武将各装备x件装备
                {
                    let { oldEplace, newEplace } = param;
                    if(oldEplace.length < dicTaskParam[1] && newEplace.length >= dicTaskParam[1]) {
                        result = { inc: 1 };
                    }
                    break;
                }
            case TASK_TYPE.EQUIP_LV_UP: // 98. 装备强化X次
                {
                    let { count } = param;
                    result = { inc: count };
                    break;
                }
            case TASK_TYPE.EQUIP_PUT_JEWEL_CNT: // 99. X件装备镶嵌天晶
                {
                    let { newEquip } = param;
                    if(!newEquip || !newEquip.jewel) break;
                    let records = await getRecord();
                    if(records.indexOf(`${newEquip.jewel}`) == -1) {
                        records.push(`${newEquip.jewel}`);
                        result = { records, inc: 1 };
                    }
                    break;
                }
            case TASK_TYPE.EQUIP_PUT_STONE_CNT: // 100. X件装备镶嵌地玉
                {
                    let { hid, newEquip } = param;
                    if(!newEquip) break;
                    let newStoneCnt = newEquip.stones.filter(cur => cur.stone != 0).length;
                    if(newStoneCnt <= 0) break;
                    let records = await getRecord();

                    if(records.indexOf(`${hid}_${newEquip.id}`) == -1) {
                        records.push(`${hid}_${newEquip.id}`);
                        result = { records, inc: 1 };
                    }
                    break;
                }
            case TASK_TYPE.EQUIP_STONE_CNT: // 101. 镶嵌X个地玉
                {
                    let { oldEquip, newEquip } = param;
                    let oldStoneCnt = oldEquip.stones.filter(cur => cur.stone != 0).length;
                    let newStoneCnt = newEquip.stones.filter(cur => cur.stone != 0).length;
                    result = { inc: newStoneCnt - oldStoneCnt };
                    break;
                }
            case TASK_TYPE.EQUIP_STONE_CNT_LV: // 102. X件装备镶嵌X个大于等于X阶地玉
                {
                    let { hid, newEquip } = param;
                    if(!newEquip) break;
                    let newStoneLvs = newEquip.stones.map(cur => {
                        let dicStone = gameData.stone.get(cur.stone);
                        return dicStone?dicStone.lv: 0;
                    });
                    let newCount = newStoneLvs.filter(lv => lv >= dicTaskParam[2]).length;
                    if(newCount < dicTaskParam[1]) break;

                    let records = await getRecord();
                    if(records.indexOf(`${hid}_${newEquip.id}`) == -1) {
                        records.push(`${hid}_${newEquip.id}`);
                        result = { records, inc: 1 };
                    }
                    break;
                }
            case TASK_TYPE.EQUIP_JEWEL_RANDSE_CNT: // 103.X个天晶的Y条特性词条被激活
                {
                    let { newEquip, jewels } = param;
                    let newJewel = getJewelByEquip(newEquip, jewels);
                    if(!newJewel) break;
            
                    let newRandSe = newJewel?.randSe||[];
                    let newUnlockSeCnt = newRandSe.filter(se => {
                        return isRandSeUnLock(newJewel.id, se.id, newEquip.stones);
                    }).length;
            
                    if(newUnlockSeCnt < dicTaskParam[1]) break;
                    let records = await getRecord();
                    if(records.indexOf(`${newJewel.seqId}`) == -1) {
                        records.push(`${newJewel.seqId}`);
                        result = { records, inc: 1 };
                    }
                    break; 
                }
            case TASK_TYPE.STONE_COMPOSE: // 104. 地玉合成X次
                {
                    let { count } = param;
                    result = { inc: count };
                    break;
                }
            case TASK_TYPE.JEWEL_RESET: // 105. 天晶洗炼X次
                {
                    result = { inc: 1 };
                    break;
                }
            case TASK_TYPE.JEWEL_QUENCH: // 106. 天晶淬炼X次
                {
                    result = { inc: 1 };
                    break;
                }
            case TASK_TYPE.JEWEL_QUENCH_SUCCESS: // 107. 天晶成功淬炼X次
                {
                    let { isSuccess } = param;
                    if(isSuccess) {
                        result = { inc: 1 };
                    }
                    break;
                }
            case TASK_TYPE.COM_BATTLE_LV: // 108. 寻宝x品阶x次
                {
                    let { gid } = param;
                    let dicJewel = getDicBlueprtById(gid);
                    if(dicTaskParam[0] == dicJewel.lv) {
                        result = { inc: 1 };
                    }
                    break
                }
            case TASK_TYPE.GUILD_REFINE: // 109. 炼器堂兑换X品阶天晶X次
                {
                    let { quality, count } = param;
                    if(dicTaskParam[0] == quality) {
                        result = { inc: count };
                    }
                    break;
                }
            case TASK_TYPE.EQUIP_STAR_UP_CNT_SUM: // 110. 装备总共升星x次
                {
                    let { count } = param;
                    result = { inc: count };
                    break;
                }
            case TASK_TYPE.BATTLE_MAIN_START: // 111. 挑战主线X次
                {
                    let { warId, count } = param;
                    let dicWar = gameData.war.get(warId);
                    if (dicWar.warType == WAR_TYPE.NORMAL) {
                        result = { inc: count };
                    }
                    break;
                }
            case TASK_TYPE.BATTLE_TOWER_START: // 112. 挑战镇念塔X次
                {
                    let { warId, count = 1, skipTower } = param;
                    let dicWar = gameData.war.get(warId);
                    if (skipTower || dicWar.warType == WAR_TYPE.TOWER ) {
                        result = { inc: count };
                    }
                    break;
                }
            case TASK_TYPE.BATTLE_VESTIGE_START: // 113. 挑战遗迹X次
                {
                    let { warId, count } = param;
                    let dicWar = gameData.war.get(warId);
                    if (dicWar.warType == WAR_TYPE.VESTIGE) {
                        result = { inc: count };
                    }
                    break;
                }
            case TASK_TYPE.BATTLE_DAILY_START: // 114. 挑战每日关卡X次
                {
                    let { warId, count } = param;
                    let dicWar = gameData.war.get(warId);
                    if(dicWar.warType == WAR_TYPE.DAILY && (dicTaskParam[0] == 0 || dicTaskParam[0] == dicWar.dailyType)) {
                        result = { inc: count };
                    }
                    break;
                }
            case TASK_TYPE.COM_BATTLE_CREATE_TEAM_WIN: // 115. 寻宝招募队友x次
                {
                    result = { inc: 1 };
                    break;
                }

            case TASK_TYPE.COM_BATTLE_ASSIST_TEAM_WIN: // 116. 协助寻宝x次
                {
                    result = { inc: 1 };
                    break;
                }
            case TASK_TYPE.COM_BATTLE_WIN: // 117. 组队寻宝
                {
                    result = { inc: 1 };
                    break;
                }
            case TASK_TYPE.BATTLE_EXPEDITION_START: // 118. 远征挑战X次
                {
                    let { warId, count } = param;
                    let dicWar = gameData.war.get(warId);
                    if (dicWar.warType == WAR_TYPE.EXPEDITION) {
                        result = { inc: count };
                    }
                    break;
                }
            case TASK_TYPE.BATTLE_DUNGEON_START: // 119. 秘境挑战X次
                {
                    let { warId, count } = param;
                    let dicWar = gameData.war.get(warId);
                    if(dicWar.warType == WAR_TYPE.MYSTERY) {
                        result = { inc: count };
                    }
                    break;
                }
            case TASK_TYPE.GUILD_GOLD_DONATE: // 120. 军团元宝捐献x次
                {
                    result = { inc: 1 };
                    break;
                }
            case TASK_TYPE.LADDER_CNT: // 121. 名将擂台挑战x次
                {
                    let { count } = param;
                    result = { inc: count };
                    break;
                }
            case TASK_TYPE.LADDER_SUCCESS_CNT: // 122. 名将擂台挑战胜利x次
                {
                    let { isSuccess, count } = param;
                    if(isSuccess) {
                        result = { inc: count };
                    }
                    break;
                }
            case TASK_TYPE.LADDER_RANK: // 123. 名将擂台排名
                {
                    let { oldLadderRank, ladderRank } = param;
                    if(ladderRank < oldLadderRank && dicTaskParam[0] >= ladderRank) {
                        result = { inc: 1 };
                    }
                    break;
                }
            case TASK_TYPE.CONNECT_ONE_HERO_MAX_LV: // 124. 单个武将其中最高等级的羁绊达X级
                {
                    let { connections } = param;
                    let records = await getRecord();
                    let oldLv = records.length > 0? parseInt(records[0]): 0;

                    let maxLv = Math.max(...connections.map(cur => cur.level))||0;
                    // console.log('##### TASK_TYPE.CONNECT_ONE_HERO_MAX_LV', oldLv, maxLv )
                    if(oldLv < maxLv) {
                        result = { set: maxLv, records: [`${maxLv}`] };
                    }
                    break;
                }
            case TASK_TYPE.CONNECT_ONE_HERO_SUM_LV: // 125. 单个武将3条羁绊总共提升X级
                {
                    let { connections } = param;
                    let records = await getRecord();
                    let oldLv = records.length > 0? parseInt(records[0]): 0;
                    let sumLv = connections.reduce((pre, cur) => pre + cur.level, 0);
                    if(oldLv < sumLv) {
                        result = { set: sumLv, records: [`${sumLv}`] };
                    }
                    break;
                }
            case TASK_TYPE.ARTIFACT_LV: // 127. 强化X件宝物至X级
                {
                    let { artifacts } = param;
                    let records = await getRecord();
                    for(let { seqId, lv, hid } of artifacts) {
                        if(hid > 0 && lv >= dicTaskParam[1] && records.indexOf(`${seqId}`) == -1) {
                            records.push(`${seqId}`);
                        }
                    }
                    result = { records, set: records.length };
                    break;
                }
            case TASK_TYPE.ARTIFACT_QUALITY_EQUIP: // 128. 穿戴X件品质为X的宝物
                {
                    let { artifacts } = param;
                    let records = await getRecord();
                    for(let { seqId, quality, hid } of artifacts) {
                        if(hid > 0 && quality >= dicTaskParam[1] && records.indexOf(`${seqId}`) == -1) {
                            records.push(`${seqId}`);
                        }
                    }
                    result = { records, set: records.length };
                    break;
                }
            case TASK_TYPE.ARTIFACT_COMPOSE: // 129. 合成X次宝物
                {
                    let { count } = param;
                    result = { inc: count };
                    break;
                }
            case TASK_TYPE.STAR_UP_SUM: // 130. 升星总和
                {
                    let { count } = param;
                    result = { inc: count };
                    break;
                }
            case TASK_TYPE.BATTLE_BRANCH_ELITE: // 131. 主线梦魇支线
                {
                    let { warId, count } = param;
                    let dicWar = gameData.war.get(warId);
                    if (dicWar.warType == WAR_TYPE.BRANCH_ELITE && this.checkIdList(dicTaskParam, 0, warId)) {
                        result = { inc: count };
                    }
                    break;
                }
            case TASK_TYPE.GVG_FARM: // 132. 农庄种植/矿山采集/木堆砍柴
                {
                    let { count } = param;
                    result = { inc: count };
                    break;
                }
            case TASK_TYPE.GVG_VESTIGE: // 133. 中原遗迹挑战
                {
                    let { count } = param;
                    result = { inc: count };
                    break;
                }
            case TASK_TYPE.GVG_TECH: // 134. 千机阁捐献
                {
                    let { count } = param;
                    result = { inc: count };
                    break;
                }
        }
        return result
    }
    
    private checkIdList(taskParam: number[], index: number, id: number) {
        let count = taskParam[index];
        if (!count) return false;
        let idList = taskParam.slice(index + 1, index + 1 + count);
        return idList.indexOf(id) != -1;
    }
    
}
