584 lines
19 KiB
JavaScript
584 lines
19 KiB
JavaScript
// ////////////////////////////////////////////////////////////////////
|
|
// 这里填写简要说明(必填),
|
|
//
|
|
// @author. xxx@syg.com(必填, 创建模块的人员)
|
|
// @editor. xxx@syg.com(必填, 后续维护以及修改的人员)
|
|
// @description.
|
|
// 这里填写详细说明,主要填写该模块的功能简要
|
|
// <br/>Create. 2019-04-10
|
|
// ////////////////////////////////////////////////////////////////////
|
|
const BridgeClass = require( "bridge.class" );
|
|
var RoleController = require("role_controller");
|
|
var HeavenEvent = require("heaven_event");
|
|
var HeavenEvent = require("heaven_event");
|
|
var HeavenChapterVo = require("heaven_chapter_vo");
|
|
var HeavenConst = require("heaven_const");
|
|
var HeavenCustomsVo = require("heaven_customs_vo");
|
|
|
|
var HeavenModel = cc.Class({
|
|
extends: BridgeClass,
|
|
|
|
ctor: function () {
|
|
this.initConfig()
|
|
},
|
|
|
|
initConfig: function () {
|
|
this.left_challenge_count = 0 // 剩余挑战次数
|
|
this.today_buy_count = 0 // 今日购买次数
|
|
this.chapter_list = [] // 章节数据
|
|
this.customs_list = [] // 关卡数据
|
|
this.max_pass_chapter_id = 0 // 最大通关(普通通关)章节id
|
|
this.max_dun_id = 0 // 最大通关关卡的配置副本id
|
|
|
|
this.dial_data = [] // 神装转盘相关数据
|
|
this.myself_record_data = [] // 玩家自己的抽奖记录
|
|
this.all_record_data = [] // 全服抽奖记录
|
|
|
|
this.heaven_red_list = []
|
|
|
|
this.all_score = 0 //战力前五神装总评分
|
|
},
|
|
|
|
clearData: function () {
|
|
this.initConfig()
|
|
},
|
|
|
|
// 设置剩余挑战次数
|
|
setLeftChallengeCount: function (count) {
|
|
this.left_challenge_count = count || 0
|
|
this.checkHeavenRedStatus()
|
|
},
|
|
// 获取剩余挑战次数
|
|
getLeftChallengeCount: function () {
|
|
return this.left_challenge_count
|
|
},
|
|
|
|
// 设置今日购买次数
|
|
setTodayBuyCount: function (count) {
|
|
this.today_buy_count = count || 0
|
|
},
|
|
// 获取今日购买次数
|
|
getTodayBuyCount: function () {
|
|
return this.today_buy_count
|
|
},
|
|
// 获取今日剩余购买次数
|
|
getTodayLeftBuyCount: function () {
|
|
let max_count = game.configs.dungeon_heaven_data.data_count_buy_length || 0
|
|
let left_count = max_count - this.today_buy_count
|
|
if (left_count < 0) left_count = 0
|
|
return left_count
|
|
},
|
|
|
|
// 设置最大通关关卡副本id
|
|
setMaxDunId: function (dun_id) {
|
|
if (!this.max_dun_id || this.max_dun_id < dun_id)
|
|
this.max_dun_id = dun_id
|
|
},
|
|
|
|
getMaxDunId: function () {
|
|
return this.max_dun_id
|
|
},
|
|
|
|
// 设置章节数据
|
|
setChapterData: function (data) {
|
|
this.chapter_list = []
|
|
for (const k in data) {
|
|
const cData = data[k];
|
|
let chapter_vo = new HeavenChapterVo()
|
|
chapter_vo.updateData(cData)
|
|
this.chapter_list.push(chapter_vo)
|
|
}
|
|
this.updateMaxPassChapterId()
|
|
this.checkHeavenRedStatus()
|
|
},
|
|
|
|
// 更新章节数据
|
|
updateChapterData: function (data) {
|
|
let is_add = false
|
|
for (const i in data) {
|
|
const cData = data[i];
|
|
|
|
let is_have = false
|
|
for (const key in this.chapter_list) {
|
|
const chapter_vo = this.chapter_list[key];
|
|
if (chapter_vo.id == cData.id) {
|
|
is_have = true
|
|
chapter_vo.updateData(cData)
|
|
}
|
|
}
|
|
if (!is_have) { // 新增
|
|
is_add = true
|
|
let chapter_vo = new HeavenChapterVo()
|
|
chapter_vo.updateData(cData)
|
|
this.chapter_list.push(chapter_vo)
|
|
}
|
|
}
|
|
this.updateMaxPassChapterId()
|
|
this.checkHeavenRedStatus()
|
|
gcore.GlobalEvent.fire(HeavenEvent.Add_Chapter_Data_Event)
|
|
},
|
|
|
|
// 更新某一章节数据
|
|
updateOneChapterDataById: function (id, data) {
|
|
for (const i in this.chapter_list) {
|
|
const chapter_vo = this.chapter_list[i];
|
|
if (chapter_vo.id == id) {
|
|
chapter_vo.updateData(data)
|
|
break
|
|
}
|
|
}
|
|
this.updateMaxPassChapterId()
|
|
this.checkHeavenRedStatus()
|
|
},
|
|
|
|
// 是否有章节数据缓存
|
|
checkIsHaveChapterCache: function () {
|
|
if (this.chapter_list && Utils.next(this.chapter_list) != null)
|
|
return true
|
|
else
|
|
return false
|
|
},
|
|
|
|
// 更新最大通关章节id
|
|
updateMaxPassChapterId: function () {
|
|
for (const i in this.chapter_list) {
|
|
const chapter_vo = this.chapter_list[i];
|
|
if (chapter_vo.is_finish != HeavenConst.Chapter_Pass_Status.NotPass && chapter_vo.id > this.max_pass_chapter_i) d
|
|
this.max_pass_chapter_id = chapter_vo.id
|
|
}
|
|
},
|
|
|
|
// 获取某一章节的通关状态 HeavenConst.Chapter_Pass_Status
|
|
getChapterPassStatus: function (chapter_id) {
|
|
let pass_status = HeavenConst.Chapter_Pass_Status.NotPass
|
|
for (const key in this.chapter_list) {
|
|
const chapter_vo = this.chapter_list[key];
|
|
if (chapter_vo.id == chapter_id)
|
|
pass_status = chapter_vo.is_finish
|
|
}
|
|
return pass_status
|
|
},
|
|
|
|
// 根据章节id和星级奖励id获取奖励状态
|
|
getChapterStarAwardStatus: function (chapter_id, award_id) {
|
|
let award_status = 0
|
|
let chapter_vo = this.getChapterDataById(chapter_id)
|
|
if (chapter_vo) {
|
|
for (const k in chapter_vo.award_info) {
|
|
const v = chapter_vo.award_info[k];
|
|
|
|
if (v.id == award_id) {
|
|
award_status = v.flag
|
|
break
|
|
}
|
|
}
|
|
}
|
|
return award_status
|
|
},
|
|
|
|
// 获取最大通关章节id
|
|
getMaxPassChapterId: function () {
|
|
return this.max_pass_chapter_id
|
|
},
|
|
|
|
// 获取当前开启的最大章节id
|
|
getOpenMaxChapterId: function () {
|
|
let chapter_id = 0
|
|
for (const k in this.chapter_list) {
|
|
const chapter_vo = this.chapter_list[k];
|
|
if (chapter_id < chapter_vo.id)
|
|
chapter_id = chapter_vo.id
|
|
}
|
|
return chapter_id
|
|
},
|
|
|
|
// 根据章节id获取章节数据
|
|
getChapterDataById: function (id) {
|
|
for (const key in this.chapter_list) {
|
|
const chapter_vo = this.chapter_list[key];
|
|
if (chapter_vo.id == id)
|
|
return chapter_vo
|
|
}
|
|
},
|
|
|
|
// 根据章节id判断该章节是否开启
|
|
checkHeavenChapterIsOpen: function (chapter_id) {
|
|
let config_data = game.configs.dungeon_heaven_data.data_chapter[chapter_id]
|
|
if (!config_data) return false
|
|
|
|
let is_open = true
|
|
let close_msg = ""
|
|
// 先判断上一章节是否通关
|
|
if (chapter_id > 1) {
|
|
let pre_pass_status = this.getChapterPassStatus(chapter_id - 1)
|
|
if (pre_pass_status == HeavenConst.Chapter_Pass_Status.NotPass)
|
|
is_open = false
|
|
}
|
|
close_msg = Utils.TI18N("Clear the previous chapter Enable")
|
|
for (const k in config_data.cond_info) {
|
|
const cond = config_data.cond_info[k];
|
|
let chap_id = cond[0]
|
|
let star = cond[1]
|
|
let chap_vo = this.getChapterDataById(chap_id)
|
|
if (!chap_vo || chap_vo.all_star < star) {
|
|
is_open = false
|
|
if (close_msg == "") {
|
|
close_msg = cc.js.formatStr(Utils.TI18N("Get %d stars in chapter %d and"), star, chap_id)
|
|
} else
|
|
close_msg = close_msg + cc.js.formatStr(Utils.TI18N("get %d stars in chapter %d"), star, chap_id)
|
|
}
|
|
break
|
|
}
|
|
return { is_open, close_msg }
|
|
},
|
|
|
|
// 设置关卡数据
|
|
setCustomsData: function (data, chapter_id) {
|
|
this.updateCustomsData(data, chapter_id)
|
|
},
|
|
|
|
// 更新关卡数据
|
|
updateCustomsData: function (data, chapter_id) {
|
|
for (const key in data) {
|
|
const cData = data[key];
|
|
cData.chapter_id = chapter_id
|
|
let is_have = false
|
|
for (const i in this.customs_list) {
|
|
const customs_vo = this.customs_list[i];
|
|
if (customs_vo.id == cData.id && customs_vo.chapter_id == chapter_id) {
|
|
is_have = true
|
|
customs_vo.updateData(cData)
|
|
}
|
|
}
|
|
if (!is_have) { // 新增
|
|
var customs_vo = new HeavenCustomsVo();
|
|
customs_vo.updateData(cData)
|
|
this.customs_list.push(customs_vo)
|
|
}
|
|
}
|
|
},
|
|
|
|
// 根据章节id判断是否有关卡数据
|
|
checkIsHaveCustomsCache: function (chapter_id) {
|
|
let is_have = false
|
|
if (this.customs_list) {
|
|
let customs_num = 0
|
|
for (const key in this.customs_list) {
|
|
const customs_vo = this.customs_list[key];
|
|
if (customs_vo.chapter_id == chapter_id) {
|
|
customs_num = customs_num + 1
|
|
}
|
|
}
|
|
if (game.configs.dungeon_heaven_data.data_customs_num[chapter_id] == customs_num) {
|
|
is_have = true
|
|
}
|
|
}
|
|
return is_have
|
|
},
|
|
|
|
// 根据章节id获取该章节所有可以显示关卡数据(乱序)
|
|
getAllCanShowCustomsDataById: function (chapter_id) {
|
|
let all_customs = []
|
|
for (const k in this.customs_list) {
|
|
const customs_vo = this.customs_list[k];
|
|
customs_vo.chapter_id == chapter_id
|
|
if (customs_vo.chapter_id == chapter_id && customs_vo.state != 0)
|
|
all_customs.push(customs_vo)
|
|
}
|
|
return all_customs
|
|
},
|
|
|
|
// 根据章节id和关卡id获取关卡数据
|
|
getCustomsDataById: function (chapter_id, customes_id) {
|
|
for (const key in this.customs_list) {
|
|
const customs_vo = this.customs_list[key];
|
|
if (customs_vo.id == customes_id && customs_vo.chapter_id == chapter_id)
|
|
return customs_vo
|
|
}
|
|
},
|
|
|
|
// 根据章节id和关卡id获取是否为boss关
|
|
getCustomsIsBossType: function (chapter_id, customes_id) {
|
|
let is_boss = false
|
|
let chapter_cfg = game.configs.dungeon_heaven_data.data_customs[chapter_id]
|
|
if (chapter_cfg && chapter_cfg[customes_id])
|
|
is_boss = (chapter_cfg[customes_id].type == 1)
|
|
return is_boss
|
|
},
|
|
|
|
// 根据关卡配置表唯一id判断该关卡是否通关
|
|
checkCustomsIsPassByDunId: function (dun_id) {
|
|
let is_pass = false
|
|
if (dun_id <= this.max_dun_id)
|
|
is_pass = true
|
|
return is_pass
|
|
},
|
|
|
|
// 根据章节id获取该章节最大星数
|
|
getChapterMaxStarNum: function (chapter_id) {
|
|
let max_star_num = 0
|
|
if (game.configs.dungeon_heaven_data.data_customs_num[chapter_id])
|
|
max_star_num = game.configs.dungeon_heaven_data.data_customs_num[chapter_id] * 3
|
|
|
|
return max_star_num
|
|
},
|
|
|
|
// 缓存最后一次打开的章节id
|
|
setHeavenLastShowChapterId: function (chapter_id) {
|
|
this.last_show_chapter_id = chapter_id
|
|
},
|
|
|
|
getHeavenLastShowChapterId: function () {
|
|
return this.last_show_chapter_id
|
|
},
|
|
|
|
// 天界副本开启判断
|
|
checkHeavenIsOpen: function (not_tips) {
|
|
let role_vo = RoleController.getInstance().getRoleVo()
|
|
if (role_vo == null)
|
|
return false
|
|
let is_open = false
|
|
let world_lev_cfg = game.configs.dungeon_heaven_data.data_const.open_world_lev;
|
|
let role_lev_cfg = game.configs.dungeon_heaven_data.data_const.open_lev;
|
|
let open_lev_second_cfg = game.configs.dungeon_heaven_data.data_const.open_lev_second;
|
|
let msg = ""
|
|
if (world_lev_cfg && role_lev_cfg) {
|
|
let world_lv = RoleController.getInstance().getModel().getWorldLev()
|
|
is_open = true
|
|
if (world_lev_cfg.val > world_lv) {
|
|
is_open = false
|
|
msg = world_lev_cfg.desc
|
|
} else if (role_lev_cfg.val > role_vo.lev) {
|
|
is_open = false
|
|
msg = role_lev_cfg.desc
|
|
}
|
|
}
|
|
// 条件二(与条件一为或的关系)
|
|
if (!is_open && open_lev_second_cfg) {
|
|
is_open = true
|
|
if (open_lev_second_cfg.val > role_vo.lev) {
|
|
is_open = false
|
|
msg = open_lev_second_cfg.desc
|
|
}
|
|
}
|
|
if (!is_open && !not_tips) {
|
|
nx.tbox(msg)
|
|
}
|
|
return is_open
|
|
},
|
|
|
|
// 神装转盘是否开启
|
|
checkHeavenDialIsOpen: function (not_tips) {
|
|
let is_open = false
|
|
let world_lev_cfg = game.configs.holy_eqm_lottery_data.data_const["world_lev_condition"]
|
|
let role_lev_cfg = game.configs.holy_eqm_lottery_data.data_const["player_lev_condition"]
|
|
let second_condition_cfg = game.configs.holy_eqm_lottery_data.data_const["player_lev_second_condition"]
|
|
let dun_id_cfg = game.configs.holy_eqm_lottery_data.data_const["heaven_dun_condition"]
|
|
if (world_lev_cfg && role_lev_cfg && dun_id_cfg) {
|
|
let world_lv = RoleController.getInstance().getModel().getWorldLev()
|
|
let role_vo = RoleController.getInstance().getRoleVo()
|
|
is_open = true
|
|
let msg = ""
|
|
if (world_lev_cfg.val > world_lv) {
|
|
is_open = false
|
|
msg = world_lev_cfg.desc
|
|
} else if (role_lev_cfg.val > role_vo.lev) {
|
|
is_open = false
|
|
msg = role_lev_cfg.desc
|
|
}
|
|
// 条件二(与条件一为或的关系)
|
|
if (!is_open && second_condition_cfg)
|
|
is_open = true
|
|
if (second_condition_cfg.val > role_vo.lev) {
|
|
is_open = false
|
|
msg = second_condition_cfg.desc
|
|
// if is_open && ! this.checkCustomsIsPassByDunId(dun_id_cfg.val)
|
|
// is_open = false
|
|
// msg = dun_id_cfg.desc
|
|
// }
|
|
if (!is_open && !not_tips)
|
|
nx.tbox(msg)
|
|
}
|
|
}
|
|
return is_open
|
|
},
|
|
|
|
// 设置神装转盘相关数据
|
|
setHeavenDailData: function (data) {
|
|
this.dial_data = data || []
|
|
this.checkHeavenRedStatus()
|
|
},
|
|
|
|
// 根据神装转盘的组id获取是否有免费次数
|
|
getHeavenDialIsFreeById: function (group_id) {
|
|
let is_free = false
|
|
for (const key in this.dial_data) {
|
|
const v = this.dial_data[key];
|
|
if (v.group_id == group_id && v.free_times >= 1) {
|
|
is_free = true
|
|
break
|
|
}
|
|
}
|
|
return is_free
|
|
},
|
|
|
|
// 根据组id判断该石像是否开启
|
|
checkHeavenDialIsOpenByGId: function (group_id) {
|
|
let is_open = false
|
|
for (const k in this.dial_data) {
|
|
const v = this.dial_data[k];
|
|
if (v.group_id == group_id && v.is_open == 1) {
|
|
is_open = true
|
|
break
|
|
}
|
|
}
|
|
return is_open
|
|
},
|
|
|
|
// 根据神装转盘的组id获取是否有奖励可领取
|
|
getHeavenDialAwardRedById: function (group_id) {
|
|
let is_free = false
|
|
for (const k in this.dial_data) {
|
|
const v = this.dial_data[k];
|
|
if (v.group_id == group_id) {
|
|
let award_config = game.configs.holy_eqm_lottery_data.data_award[v.group_id]
|
|
if (award_config)
|
|
for (const i in award_config) {
|
|
const j = award_config[i];
|
|
let _un_enabled = false
|
|
for (const l in v.do_awards) {
|
|
const m = v.do_awards[l];
|
|
if (j.id == m.award_id) {
|
|
_un_enabled = true
|
|
break
|
|
}
|
|
}
|
|
if (_un_enabled == false && j.times <= v.all_award_count)
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
return is_free
|
|
},
|
|
|
|
// 获取神装组id数据
|
|
getHeavenDialById: function (group_id) {
|
|
for (const k in this.dial_data) {
|
|
const v = this.dial_data[k];
|
|
if (v.group_id == group_id)
|
|
return v
|
|
}
|
|
return null
|
|
},
|
|
|
|
|
|
// 根据神装转盘的组id获取再抽X次触发保底
|
|
getHeavenDialBaodiCountById: function (group_id) {
|
|
let count = 0
|
|
for (const k in this.dial_data) {
|
|
const v = this.dial_data[k];
|
|
if (v.group_id == group_id) {
|
|
count = v.baodi_count || 0
|
|
break
|
|
}
|
|
}
|
|
return count
|
|
},
|
|
|
|
// 玩家自己的抽奖记录
|
|
setMyselfDialRecordData: function (data) {
|
|
this.myself_record_data = data || {}
|
|
},
|
|
|
|
getMyselfDialRecordData: function () {
|
|
return this.myself_record_data
|
|
},
|
|
|
|
// 全服抽奖记录
|
|
setAllDialRecordData: function (data, group_id) {
|
|
this.all_record_data[group_id] = data
|
|
},
|
|
|
|
getAllDialRecordData: function (group_id) {
|
|
return this.all_record_data[group_id] || {}
|
|
},
|
|
|
|
// 根据组id判断本地是否有缓存全服记录数据
|
|
checkIsHaveDialRecordData: function (group_id) {
|
|
if (this.all_record_data[group_id] && Utils.next(this.all_record_data[group_id]) != null)
|
|
return true
|
|
return false
|
|
},
|
|
|
|
//////////////// 红点相关
|
|
updateHeavenRedStatus: function (bid, status) {
|
|
this.heaven_red_list[bid] = status
|
|
let red_status = this.getHeavenRedStatus()
|
|
|
|
gcore.GlobalEvent.fire(HeavenEvent.Update_Heaven_Red_Status, bid, status)
|
|
},
|
|
|
|
getHeavenRedStatus: function () {
|
|
let red_status = false
|
|
for (const k in this.heaven_red_list) {
|
|
const status = this.heaven_red_list[k];
|
|
if (status == true) {
|
|
red_status = true
|
|
break
|
|
}
|
|
}
|
|
return red_status
|
|
},
|
|
|
|
getHeavenRedStatusByBid: function (bid) {
|
|
let red_status = false
|
|
for (const k in this.heaven_red_list) {
|
|
const status = this.heaven_red_list[k];
|
|
if (bid == k) {
|
|
red_status = status
|
|
break
|
|
}
|
|
}
|
|
return red_status
|
|
},
|
|
|
|
checkHeavenRedStatus: function () {
|
|
if (!this.checkHeavenIsOpen(true)) return
|
|
|
|
// 剩余挑战次数
|
|
let count_red_status = false
|
|
if (this.left_challenge_count > 0)
|
|
count_red_status = true
|
|
// this.updateHeavenRedStatus(HeavenConst.Red_Index.Count, count_red_status)
|
|
|
|
// 章节奖励
|
|
let award_red_status = false
|
|
for (const k in this.chapter_list) {
|
|
const chapter_vo = this.chapter_list[k];
|
|
if (chapter_vo.getRedStatus() == true) {
|
|
award_red_status = true
|
|
break
|
|
}
|
|
}
|
|
// this.updateHeavenRedStatus(HeavenConst.Red_Index.Award, award_red_status)
|
|
},
|
|
|
|
setAllScore: function (score) {
|
|
this.all_score = score
|
|
gcore.GlobalEvent.fire(HeavenEvent.Update_All_Score)
|
|
},
|
|
|
|
getAllScore: function () {
|
|
return this.all_score
|
|
},
|
|
|
|
// 根据关卡配置表唯一id判断该关卡是否通关
|
|
checkIsOpenByScore: function (score) {
|
|
let is_open = false
|
|
if (score <= this.all_score) {
|
|
is_open = true
|
|
}
|
|
return is_open
|
|
},
|
|
|
|
}); |