"use strict"; cc._RF.push(module, 'af61brTEgRKtK6v74O2RVze', 'new_battle_role'); // Scripts/mod/battle/act/new_battle_role.js "use strict"; var _require = require("define"), PlayerAction = _require.PlayerAction, SCREEN_WIDTH = _require.SCREEN_WIDTH, SCREEN_HEIGHT = _require.SCREEN_HEIGHT; var BattleEvent = require("battle_event"); var PathTool = require("pathtool"); var BattleConst = require("battle_const"); var BattleLoop = require("battle_loop"); var BattleController = require("battle_controller"); var SkilAct = require("skill_act"); var NxSpine = require("nx.fx.spine"); cc.Class({ "extends": cc.Component, properties: { role_node: { "default": null, type: cc.Node }, container: { //常规人物 "default": null, type: cc.Node }, hallow_node: { //星舰和僚机 "default": null, type: cc.Node }, spine_renderer: { //僚机技能节点 "default": null, type: cc.Node }, buff_container: { "default": null, type: cc.Node }, //角色信息相关 camp: { "default": null, type: cc.Sprite }, level: { "default": null, type: cc.Label }, //血条相关 once: { "default": null, type: cc.Node }, red: { "default": null, type: cc.Node }, progress: { "default": null, type: cc.ProgressBar }, boss_bar: { "default": null, type: cc.ProgressBar }, shadow: { "default": null, type: cc.Node }, top_container: { "default": null, type: cc.Node }, hp_rule: { //血條刻度 "default": null, type: cc.Node }, hp_joint: { "default": [], type: [cc.Node] }, //伴随特效添加节点 role_effect: { "default": null, type: cc.Node }, role_died_sp: { "default": null, type: NxSpine }, roleSp: { "default": null, type: NxSpine }, otherSp: { "default": null, type: NxSpine } }, // LIFE-CYCLE CALLBACKS: onLoad: function onLoad() {}, start: function start() {}, init: function init() { this.model = BattleController.getInstance().getModel(); this.hook_model = BattleController.getInstance().getHookModel(); // 假战斗才需要,当前这一排是否有其他单位,确定初始位置 this.is_next_offset = false; this.initConfig(); }, //加战斗固定参数 setHookNextOffset: function setHookNextOffset(args) { this.is_next_offset = args; }, initConfig: function initConfig() { this.role = null; this.role_data = null; this.top_off_y = 10; // 血条向上的偏移量 this.is_real = false; // 是否是真战斗单位 this.play_enter = false; // 是否需要播放进场动画 this.talk_back = false; // 是否需要通知播放完成 this.grid_pos = null; // 格子坐标, this.scene_pos = null; // 场景坐标 this.is_friend = false; // 是否是友方 this.obj_type = 0; // 是己方还是敌方 this.model_height = 120; // 模型的高度 this.model_width = 60; // 模型的宽度,暂时先这样,后面加接口计算 this.pos = 0; // 当前站位 this.group = 0; // 当前分组 this.spine_name = ""; // 单位资源名字 ,H10000这种 this.spine_name_1 = ""; // 单位资源名字 ,H10000这种 this.base_spine_name = ""; // 单位初始资源模型,防止变身后无法转换回来 this.play_action_name = ""; // 当前动作名字, this.is_aid = false; //变身参数 this.change_spine_res = ""; this.change_spine_action = ""; this.is_change_status = false; this.buff_spine = null; this.is_round = false; // 当前技能播报是否播放完成 this.effect_list = {}; // 挂在身上的特效列表 this.hp_show_status = true; // 是否显示或者隐藏血条 this.is_die = false; // 该单位是否是死亡 == role_data.hp == 0 this.role_cur_zorder = 0; // 当前单位深度值 this.in_hurt_act = false; // 是否在播放受击效果中 this.need_play_die = false; // 需要播放死亡动作 this.is_use_skill = false; // 是否使用皮肤 this.fashion_id = 0; // 皮肤映射id this.wait_action_name = null; this.wait_res_name = null; this.wait_is_loop = null; this.tips_list = {}; // 当前飘字记录 this.buff_list = {}; // 当前buff列表信息,以唯一id作为key this.buff_list_data = {}; // 当前buff信息,以buff_config.icon作为key this.buff_list_item = {}; // 当前buff的实例化显示对象,以buff_config.icon作为key this.action_call_list = {}; // 制动动作回调 this.wait_add_effect_list = {}; // 待添加特效 this.dmg_index = 0; // 当前伤害数字的个数 this.elfin_list = []; }, /** * 创建战斗单位 * @param {*} parent 所在父节点 * @param {*} battle_role_data 对象基础数据,BattleRoleData * @param {*} play_enter 是否需要播放进场动画 * @param {*} talk_back 是否需要通知进场完成 * @param {*} is_real 是否是真实战斗 * @param {*} finish_cb 创建完成之后的回调 */ createRole: function createRole(parent, battle_role_data, play_enter, talk_back, is_real, finish_cb) { this.node.parent = parent; this.role_data = battle_role_data; this.play_enter = false; this.finish_cb = finish_cb; if (!is_real) this.play_enter = false; this.talk_back = talk_back || false; this.is_real = is_real || false; this.pos = battle_role_data.pos; this.group = battle_role_data.group; this.sprites = battle_role_data.sprites || []; this.skills = battle_role_data.skills || []; this.is_camera = false; //每次战斗每回合敌我双方只有一个加镜头特效 this.is_not_hide = false; this.createRootWnd(); }, //繼續使用假戰鬥單位 createUnrealRole: function createUnrealRole(parent, battle_role_data, play_enter, talk_back, is_real, finish_cb) { this.role_data = battle_role_data; this.play_enter = false; this.finish_cb = finish_cb; if (!is_real) this.play_enter = false; this.talk_back = talk_back || false; this.is_real = is_real || false; this.pos = battle_role_data.pos; this.group = battle_role_data.group; this.sprites = battle_role_data.sprites || []; this.skills = battle_role_data.skills || []; this.is_die = false; if (this.role_data && this.role_data.group && this.role_data.group == BattleConst.Group_Type.Enemgy) { this.playUnrealEnterAction(); } }, // 初始化状态 resetInitStatus: function resetInitStatus() { if (this.skeleton) { this.skeleton.setToSetupPose(); this.skeleton.clearTracks(); } }, createRootWnd: function createRootWnd() { this.role_died_sp.node.active = false; this.spine_renderer.active = false; // 神器和模型区分 if (this.role_data.object_type == BattleConst.Unit_Type.Hallows) { this.spine = this.hallow_node.getChildByName("spine"); this.skeleton = this.spine.getComponent(sp.Skeleton); this.role_node.active = false; this.hallow_node.active = true; this.spine_renderer.active = false; this.spine.scale = 0.8; } else if (this.role_data.object_type == BattleConst.Unit_Type.Elfin) { this.spine = this.hallow_node.getChildByName("spine"); this.skeleton = this.spine.getComponent(sp.Skeleton); this.role_node.active = false; this.hallow_node.active = false; // 初始化精灵节点 this.initSpineRenderer(); } else { this.is_allow_black = true; //只有角色允许黑屏处理 this.spine_renderer.active = false; this.spine = this.container.getChildByName("spine"); this.spine.active = false; this.skeleton = this.spine.getComponent(sp.Skeleton); this.skeleton.clearTracks(); this.effect = this.container.getChildByName("effect"); // 10星光环特效 this.hallow_node.active = false; this.role_node.active = true; // 真实战斗才需要显示这些东西 if (this.is_real) { this.level.string = "Lv." + this.role_data.lev; } else { this.node.active = false; this.updateBossHp(); } } this.spine_zorder = this.spine.zIndex; // 设置当前的模型速率 if (this.skeleton_time_scale) { this.skeleton.timeScale = this.skeleton_time_scale; this.skeleton_time_scale = null; } else { var timeScale = this.model.getTimeScale(); this.skeleton.timeScale = timeScale; this.skeleton_time_scale = timeScale; } // 监听事件 this.registerEvent(); // 初始化 this.resetInitStatus(); // 设置当前位置 this.setGridPos(); if (this.role_data.object_type == BattleConst.Unit_Type.Hallows) { // 更新神器 gcore.GlobalEvent.fire(BattleEvent.BATTLE_FORM_VIEW_HALLOW, true, this, this.is_friend, this.role_data.hallows_val, this.role_data.hallows_max); } // 实例化模型 this.instantModelRole(); // 设置气血 this.setHP(0); this.setHpRules(this.role_data.hp_max); }, registerEvent: function registerEvent() { this.skeleton.setCompleteListener(function (trackEntry, loopCount) { var animationName = trackEntry.animation ? trackEntry.animation.name : ""; if (this.action_call_list) { var action_object = this.action_call_list[animationName]; if (action_object && action_object.over) { action_object.over(animationName); this.action_call_list[animationName] = null; } } }.bind(this)); this.skeleton.setEventListener(function (trackEntry, event) { var animationName = trackEntry.animation ? trackEntry.animation.name : ""; if (this.action_call_list) { var action_object = this.action_call_list[animationName]; if (action_object && action_object.event) { action_object.event(event.data.name); } } }.bind(this)); }, // 设置角色格子位置,这个是要确定站位是在左边还是在右边 setGridPos: function setGridPos() { var is_friend = false; if (this.role_data == null) return; // 站位要区分真假战斗 if (this.is_real) { is_friend = this.model.isFriend(this.role_data.group); } else { is_friend = this.role_data.group == 1; } if (is_friend) { this.obj_type = BattleConst.Battle_Type_Conf.TYPE_ROLE; } else { this.obj_type = BattleConst.Battle_Type_Conf.TYPE_ENEMY; } this.is_friend = is_friend; // 非己方的需要反转处理 if (this.role_data.object_type == BattleConst.Unit_Type.Hallows) { if (!this.is_friend) {} else {} } else { if (!this.is_friend) { this.spine.scaleX = -1; this.spine_renderer.x = 0; } else { this.spine.scaleX = 1; this.spine_renderer.x = 25; } } // 获取当前格子站位 this.grid_pos = SkilAct.newPos2Gird(this.role_data.pos, is_friend, this.role_data.group, this.is_real); this.scene_pos = SkilAct.gridPosToScreenPos(this.grid_pos); this.node.setPosition(this.scene_pos); this.resetZOrder(); }, // 设置坐标 setScenePos: function setScenePos(pos) { this.node.setPosition(pos); }, // 是否需要反转劫色,因为可能存在背刺技能 reverse: function reverse(rev) { rev = rev || -1; if (this.rev_value == rev) return; this.rev_value = rev; if (this.spine) { this.spine.scaleX = rev; } if (this.role_data.object_type == BattleConst.Unit_Type.Hallows) { if (this.spine) { this.spine.scaleX = rev * 0.8; } } else { if (this.spine) { this.spine.scaleX = rev; } } }, // 实例化角色模型数据 instantModelRole: function instantModelRole() { if (this.role_data == null) { return; } // 去配置表数据 var camp_type = 0; // 当前阵营 var spine_name = ""; var encircle_effect = ""; // 10星英雄特效 var fashion = 0; // 时装数据 if (this.role_data.object_type == BattleConst.Unit_Type.Hero) { var key = Utils.getNorKey(this.role_data.object_bid, this.role_data.star); var config_data = gdata("partner_data", "data_partner_star", key); if (config_data) { spine_name = config_data.res_id; encircle_effect = config_data.fight_effect; } var base_config = game.configs.partner_data.data_partner_base[this.role_data.object_bid]; if (base_config) { camp_type = base_config.camp_type; } } else if (this.role_data.object_type == BattleConst.Unit_Type.Hallows) { var config_data = game.configs.hallows_data.data_base[this.role_data.object_bid]; if (config_data) { spine_name = config_data.c_res_id; } } else if (this.role_data.object_type == BattleConst.Unit_Type.Elfin) { spine_name = "H70000"; } else { var config_data = Utils.getUnitConfig(this.role_data.object_bid); if (config_data) { spine_name = config_data.body_id; camp_type = config_data.camp_type; encircle_effect = config_data.fight_effect; } } // 真是战斗就从服务端那边去,否则从battleloop2里面去数值 if (this.is_real == true) { this.node.setAnchorPoint(0.5, 0.5); fashion = this.getBattleRoleExtendData(5); // 时装数据 } else { if (!this.is_friend) { //挂机boss需要重设锚点 this.node.setAnchorPoint(0.7, 0.5); } else { this.node.setAnchorPoint(0.5, 0.5); } fashion = this.role_data.fashion; } this.role_data.face_id = this.role_data.object_bid; if (fashion != 0) { var skin_config = game.configs.partner_skin_data.data_skin_info[fashion]; if (skin_config) { spine_name = skin_config.res_id; this.role_data.face_id = skin_config.head_id; if (skin_config.fight_effect != "" && encircle_effect != "") { encircle_effect = skin_config.fight_effect; } } this.is_use_skill = true; this.fashion_id = fashion; } if (spine_name == "") { return; } this.spine_name = spine_name; this.base_spine_name = spine_name; // 设置阵营 if (this.is_real && this.role_data.object_type != BattleConst.Unit_Type.Hallows) { this.setCampIcon(camp_type); } // 设置模型的高度 var config_model = game.configs.skill_data.data_get_model_data[spine_name]; if (config_model) { this.model_height = config_model.model_height; // 模型的高度再上浮20个像素 } this.top_container.y = this.model_height + this.top_off_y; //是否需要播放进场动作 if (this.play_enter) { this.showEnterAction(); } else { if (this.is_real) { this.doRunToStand(function () { if (!this.node) return; this.node.active = true; this.setActive(true); }.bind(this)); } else { this.doStand(function () { if (!this.node) return; if (!this.is_real) { this.node.active = true; if (this.finish_cb) this.finish_cb(); } this.setActive(true); if (this.role_data.group == BattleConst.Group_Type.Enemgy) { this.playUnrealEnterAction(); } }.bind(this)); } } }, // 获取指定类型的额外数据 getBattleRoleExtendData: function getBattleRoleExtendData(key) { if (this.role_data == null) return 0; for (var index = 0; index < this.role_data.extra_data.length; index++) { var element = this.role_data.extra_data[index]; if (element.extra_key == key) { return element.extra_value; } } return 0; }, // 是否需要播放进场动作 showEnterAction: function showEnterAction() { if (this.role_data && this.role_data.object_type == BattleConst.Unit_Type.Hallows || this.role_data.object_type == BattleConst.Unit_Type.Elfin) { // 神器不需要走任何处理 this.doStand(); return; } var time = 0.5; var start_x = this.scene_pos.x; var offset_x = SCREEN_WIDTH * 0.25; var move_by = null; if (this.is_friend == true) { start_x = start_x - offset_x; move_by = cc.moveTo(time, this.scene_pos.x, this.scene_pos.y); } else { start_x = start_x + offset_x; move_by = cc.moveTo(time, this.scene_pos.x, this.scene_pos.y); } this.doRun(); this.node.x = start_x; this.node.runAction(cc.sequence(move_by, cc.callFunc(function () { this.doStand(); }.bind(this)))); }, // 设置阵营 setCampIcon: function setCampIcon(camp_type) { var cfg = game.configs.combat_halo_data.data_halo_icon[camp_type]; if (!cfg) return; var camp_icon = cc.js.formatStr("prefab/battle/ui/camps%s", cfg.id); nx.gui.setSpriteFrame(this.camp, "", camp_icon); }, // 假战斗地方的进场效果 playUnrealEnterAction: function playUnrealEnterAction() { if (this.node == null) return; this.clearNextActTimer(); this.clearNextCallTimer(); var skill_plays_data = BattleLoop.play(this.pos); if (skill_plays_data) { // cc.log("开始准备假战斗"); var skill_plays_list = this.hook_model.getSkillPlayData(skill_plays_data.actor); if (skill_plays_list == null || skill_plays_list.length == 0) { this.hook_model.handleSkillPlayData(skill_plays_data, function (start_cb) { if (this.hook_model) { var wait_time = 2500 - this.hook_model.getFinalMoveTime(); if (!this.next_ack_mon_timer) { this.next_ack_mon_timer = gcore.Timer.set(function () { // cc.log("准备攻击1"); if (start_cb) start_cb(); }.bind(this), wait_time, 1); } } }.bind(this)); } this.hook_model.updateActorPlaysList(skill_plays_data); } }, // 清楚下一个攻击的定时器 clearNextActTimer: function clearNextActTimer() { if (this.next_ack_mon_timer) { gcore.Timer.del(this.next_ack_mon_timer); this.next_ack_mon_timer = null; } }, // 清除下一波怪物刷新定时器 clearNextCallTimer: function clearNextCallTimer() { if (this.next_call_mon_timer) { gcore.Timer.del(this.next_call_mon_timer); this.next_call_mon_timer = null; } }, doRun: function doRun(cb) { this.playActionOnce(PlayerAction.run, this.spine_name, null, null, cb); }, doStand: function doStand(finish_cb) { this.playActionOnce(PlayerAction.battle_stand, this.spine_name, null, null, finish_cb); if (this.pos < 40 && this.talk_back) { this.talk_back = false; this.model.addReadySum(); } }, doRunToStand: function doRunToStand(finish_cb) { var _this = this; if (!this.node) return; if (this.role_data && this.role_data.object_type == BattleConst.Unit_Type.Hallows || this.role_data.object_type == BattleConst.Unit_Type.Elfin) { // 神器不需要走任何处理 this.doStand(finish_cb); return; } var time = 0.2; var start_x = this.scene_pos.x; var offset_x = SCREEN_WIDTH * 0.5; var move_by = null; if (this.is_friend == true) { start_x = start_x - offset_x; move_by = cc.moveTo(time, this.scene_pos.x, this.scene_pos.y); } else { start_x = start_x + offset_x; move_by = cc.moveTo(time, this.scene_pos.x, this.scene_pos.y); } this.node.x = start_x; this.doRun(function () { if (!_this.node) return; _this.node.runAction(cc.sequence(move_by, cc.delayTime(0.1), cc.callFunc(function () { this.node.position = this.scene_pos; this.playActionOnce(PlayerAction.battle_stand, this.spine_name, null, null, finish_cb); if (this.pos < 40 && this.talk_back) { this.talk_back = false; this.model.addReadySum(); } }.bind(_this)))); }); }, // 设置动作伴随事件和动作结束事件回调 setAnimationActionFunc: function setAnimationActionFunc(event_func, over_func, action_name) { if (action_name == null) return; if (this.action_call_list[action_name] == null) { this.action_call_list[action_name] = { over: null, event: null }; } this.action_call_list[action_name].over = over_func; this.action_call_list[action_name].event = event_func; }, isCHeckDel30075: function isCHeckDel30075(key) { var is_del = false; if (key == "H30075_jineng21" || key == "H30075_jineng22" || key == "H30075_jineng23" || key == "H30075_jineng24" || key == "H30075_jineng25") { is_del = true; } return is_del; }, /** * 切换动作,由于处于待机的时候,可能马上切换到其他动作,所以这里要看看要不要处理成待机播放完成之后 * @param {*} action_name 目标动作名字 * @param {*} res_name 目标资源名字 */ playActionOnce: function playActionOnce(action_name, res_name2, is_loop, force, load_fini) { var _this2 = this; if (!this.node) return; if (res_name2 != "" && res_name2 != null) { this.spine_name = res_name2; } var self = this; //|| "H99999"; if (is_loop == null) { is_loop = true; } if (!this.skeleton) { return false; } var skeleton_path = PathTool.getSpinePath(self.spine_name, self.spine_name, false); if (this.play_action_res == skeleton_path) { self.play_action_name = action_name; // self.skeleton.setAnimation(0, action_name, is_loop); self.spine.active = true; self.skeleton.node.opacity = 255; // self.model.getRoleMgr().setResAssets(skeleton_path,this.skeleton.skeletonData._ref); if (this.role_data.object_type == BattleConst.Unit_Type.Hero || this.role_data.object_type == BattleConst.Unit_Type.Monster) { this.roleSp.action(action_name, is_loop, null, this.skeleton_time_scale); } else { this.otherSp.action(action_name, is_loop, null, this.skeleton_time_scale); } } else { self.play_action_res = skeleton_path; if (this.role_data.object_type == BattleConst.Unit_Type.Hero || this.role_data.object_type == BattleConst.Unit_Type.Monster) { this.roleSp.load(skeleton_path, function (_e) { if (!_e) { _this2.roleSp.action(action_name, is_loop, null, _this2.skeleton_time_scale); nx.dt.fnInvoke(load_fini); } }); } else { this.otherSp.load(skeleton_path, function (_e) { if (!_e) { _this2.otherSp.action(action_name, is_loop, null, _this2.skeleton_time_scale); nx.dt.fnInvoke(load_fini); } }); } self.spine.active = true; self.skeleton.node.opacity = 255; } }, // 重设基础数据,包含切换到战力动作等 resetBaseInfo: function resetBaseInfo() { if (!this.node) return; this.playActionOnce(PlayerAction.battle_stand, this.spine_name); if (this.scene_pos) { this.node.setPosition(this.scene_pos); } this.resetZOrder(); this.reverse(this.obj_type); }, // 设置深度值 resetZOrder: function resetZOrder() { if (this.role_data == null) return; if (this.role_base_zorder) { if (this.role_cur_zorder != this.role_base_zorder) { this.role_cur_zorder = this.role_base_zorder; this.node.zIndex = this.role_base_zorder; } return; } var zorder = 0; var group = this.role_data.group - 1; var pos = this.role_data.pos - 1; if (this.role_data.group == BattleConst.Group_Type.Enemgy) { zorder = BattleConst.BattleRoleZorder[group][pos - BattleConst.GIRD_POS_OFFSET]; } else { zorder = BattleConst.BattleRoleZorder[group][pos]; } this.role_base_zorder = zorder; this.role_cur_zorder = zorder; this.node.zIndex = zorder; }, // 设置深度 setLocalZOrder: function setLocalZOrder(zIndex) { if (this.role_cur_zorder == zIndex) return; this.role_cur_zorder = zIndex; if (this.node) { this.node.zIndex = zIndex; } }, // 当前深度值 getLocalZOrder: function getLocalZOrder() { return this.role_cur_zorder || 0; }, // 战斗动作播报 runAction: function runAction(action) { if (action) { this.node.runAction(action); } else { this.model.forceActFinish(this.role_data.pos); } }, // 添加一个战斗特效,可能是buff, index:0 为上层特效 1:为下层特效 addBattleEfffect: function addBattleEfffect(fix, fiy, effect_id, action_name, index, obj_type, tag_pos) { if (!this.node) return; // 这个确定是否要反转特效 if (obj_type == null) { obj_type = this.obj_type; } if (this.effect_list[effect_id] == null) { this.effect_list[effect_id] = {}; } if (this.effect_list[effect_id][action_name] == null) { this.effect_list[effect_id][action_name] = { num: 1, object: null }; } var effect_object = this.effect_list[effect_id][action_name]; if (effect_object.object == null) { effect_object.object = this.model.getEftMgr().createRoleEft(this.pos + effect_id + action_name, this.role_effect, cc.v2(fix, fiy), obj_type, effect_id); } else { //临时 effect_object.object = this.model.getEftMgr().findRoleEft(this.pos + effect_id + action_name); //临时 effect_object.num += 1; if (effect_object.num > 0) { effect_object.object.setActiveEffect(true); } } // 设置特效的深度值 var zorder = this.spine_zorder + 1; if (index == 1) { zorder = this.spine_zorder - 1; } effect_object.object.setLocalZOrder(zorder); return effect_object; }, // 移除一个特效,并不是强制移除,只是把计数器-1,如果计数器为0,才是彻底移除 delBattleEffect: function delBattleEffect(effect_id, action_name, tag_pos) { if (this.wait_add_effect_list[effect_id]) { if (this.wait_add_effect_list[effect_id][action_name] != null) { this.wait_add_effect_list[effect_id][action_name] = null; } } if (this.effect_list[effect_id] == null) { return; } var effect_object = this.effect_list[effect_id][action_name]; if (effect_object == null) { return; } effect_object.num -= 1; if (effect_object.num <= 0) { effect_object.object.setActiveEffect(false); } }, // 显示或者隐藏掉血条 showHpRoot: function showHpRoot(status) { if (!this.node) return; if (!this.is_real) return; // 假战斗不需要管这个 if (this.hp_show_status == status) return; this.hp_show_status = status; if (this.top_container) { this.red.active = false; this.top_container.active = status; } }, /** * 血量变化的值 * @param {*} dmg 正数是治疗,负数是扣血 * @param {*} is_die 是否死亡 * @param {*} without 是否提出掉非死亡状态 * @param {*} is_must_die 如果为0,就标识可以移除了.否则就算死了也不移除.因为可能在连击中 */ updateHP: function updateHP(dmg, is_die, without, is_must_die) { if (!this.node) return; if (this.role_data == null) return; if (this.role_data && this.role_data.object_type == BattleConst.Unit_Type.Hallows) return; this.setHP(dmg); if (without == null) { without = false; } if (is_die == 1 && is_must_die == 0) { if (!this.is_die) { if (this.is_real) { this.died(); } else { this.unrealDied(); } } } else { if (this.is_die && !without) { this.relive(); } } }, // 处理角色复活 relive: function relive() { if (!this.is_die) return; this.is_die = false; this.showHpRoot(true); this.setActive(true); this.resetBaseInfo(); var cur_hp = this.role_data.hp; var per = Math.min(1, Math.max(cur_hp / this.role_data.hp_max)); this.progress.progress = per; }, // 立刻移除对象 doDied: function doDied() { if (this.is_die) { return; } this.is_die = true; this.showHpRoot(false); this.setActive(false); this.clearAllEffect(); }, //處理假戰鬥角色死亡 unrealDied: function unrealDied() { this.need_play_die = false; if (this.is_die) { return; } this.is_die = true; this.assetJumpTo(); if (this.next_call_mon_timer == null) { this.next_call_mon_timer = gcore.Timer.set(function () { this.hook_model.playEnd(this.pos); this.hook_model.updateNextRoundData(); }.bind(this), 300, 1); } this.updateBossHp(); }, updateBossHp: function updateBossHp() { if (!this.node) return; var drama_ctrl = require("battle_drama_controller"); var hookTime = drama_ctrl.getInstance().getModel().getHookAccumulateInfo().hook_time || 0; var totalTime = game.configs.dungeon_data.data_drama_const.profit_time_max.val; var role_ctrl = require("role_controller").getInstance(); var afkTime = 1; if (role_ctrl.getRoleVo().vip_lev > 0) { console.log(role_ctrl.getRoleVo().vip_lev); afkTime = game.configs.vip_data.data_get_vip_info[role_ctrl.getRoleVo().vip_lev].val[1][1]; } var vipTime = afkTime * 3600; var progress = (totalTime + vipTime - hookTime) / (totalTime + vipTime); this.boss_bar.progress = progress; }, // 处理角色死亡 died: function died() { var _this3 = this; if (this.in_hurt_act == true) { this.need_play_die = true; return; } if (this.is_die) { return; } this.showHpRoot(false); this.role_died_sp.node.active = true; this.role_died_sp.stop(); // this.role_died_sp.setToSetupPose(); // this.role_died_sp.clearTracks(); var die_func = function die_func(delay) { _this3.is_die = true; var callFunc_1 = cc.callFunc(function () { this.role_died_sp.node.active = false; this.is_act_die = true; this.setActive(false); }.bind(_this3)); var act = cc.sequence(cc.delayTime(delay), callFunc_1); _this3.runAction(act); // 清除所有的特效 _this3.clearAllEffect(false); _this3.removeBuffList(); }; var res_path = PathTool.getSpinePath("E65010", "action", false); this.role_died_sp.load(res_path, function (_e) { if (!_e) { _this3.role_died_sp.action("action", false); } else { _this3.role_died_sp.stop(); } die_func(0.2); }); }, // 设置是否激活 setActive: function setActive(status) { var _this4 = this; if (this.is_real) { if (status) { this.active_timer = setTimeout(function () { if (!_this4.node) return; if (!_this4.is_real) { _this4.top_container.active = false; if (!_this4.is_friend) { _this4.boss_bar.node.active = true; } } _this4.node.opacity = status ? 255 : 0; _this4.skeleton.markForRender(status); _this4.shadow.active = status; _this4.reTryChangeSpine(); }, 400); } else { if (!this.node) return; if (!this.is_real) { this.top_container.active = false; if (!this.is_friend) { this.boss_bar.node.active = true; } } this.node.opacity = status ? 255 : 0; this.skeleton.markForRender(status); this.shadow.active = status; } } else { if (!this.node) return; if (!this.is_real) { this.top_container.active = false; if (!this.is_friend) { this.boss_bar.node.active = true; } } this.node.opacity = status ? 255 : 0; this.skeleton.markForRender(status); this.shadow.active = status; } }, // 受击动作播放完成之后的处理 checkIsDied: function checkIsDied() { if (this.need_play_die) { this.need_play_die = false; this.died(); } else { this.doStand(); } }, setHpRules: function setHpRules(hp_max) { if (this.role_data == null) return; if (this.role_data.pos > 20) return; //10w小結 50w大結 var all = Math.ceil(hp_max / 100000); if (all > 100) { all = 50; } var _x = this.hp_rule.width / all; for (var i = 0; i < all; i++) { var is_big = i % 5 == 0 && i != 0; var r = null; if (i != 0) { if (is_big) { r = this.hp_joint[1]; } else { r = this.hp_joint[0]; } } if (r) { var nd = cc.instantiate(r); nd.parent = this.hp_rule; nd.x = _x * i; nd.active = true; } } }, // 设置气血 setHP: function setHP(dmg) { if (!this.node) return; if (this.role_data == null) return; var cur_hp = 0; if (dmg <= 0) { // 伤害 cur_hp = Math.max(0, dmg + this.role_data.hp); } else { // 恢复 cur_hp = Math.min(this.role_data.hp_max, dmg + this.role_data.hp); } this.role_data.hp = cur_hp; var per = Math.min(1, Math.max(cur_hp / this.role_data.hp_max)); this.progress.progress = per; nx.gui.setActive(this.once, "", per == 1); if (per <= 0.3) { this.red.active = true; this.red.width = this.progress.totalLength * per; } else { this.red.active = false; } }, // 下一波怪如果是己方需要清掉所有的buff之类的 updataNextBattleRole: function updataNextBattleRole(data) { if (!this.node) return; if (this.role_data) { if (this.role_data.updateData) { this.role_data.updateData(data); } this.clearAllEffect(false); this.removeBuffList(); if (this.role_data.hp <= 0) { this.died(); } else { var per = Math.min(1, Math.max(this.role_data.hp / this.role_data.hp_max)); this.progress.progress = per; this.red.width = this.progress.totalLength * per; if (per <= 0.3) { if (per != 0) { this.red.active = true; this.progress.barSprite.node.active = false; } } else { this.red.active = false; this.progress.barSprite.node.active = true; } } } }, // 变身操作 // --- BattleRole:changeSpine 變出處理,後續會用到 // -- @param bool 是否變身 // -- @param spine 變身資源 // -- @param anima_name 變身動作資源 changeSpine: function changeSpine(bool, spine2, anima_name2) { var self = this; // 如果是在播放動作過程中,切換模型這個時候不處理 if (bool && this.in_animation) { self.change_spine_res = spine2; self.change_spine_action = anima_name2; return; } var spine = spine2 || self.base_spine_name; if (bool) { self.is_change_status = true; self.buff_spine = spine2; } else { self.is_change_status = false; self.buff_spine = null; spine = self.base_spine_name; self.change_spine_res = self.base_spine_name; this.change_spine_action = "stand2"; } this.spine_name = spine; var anima_name = anima_name2 || PlayerAction.battle_stand; this.playActionOnce(anima_name, this.spine_name, null, null, null); }, // 動作播放完成之後,嘗試切換模型 reTryChangeSpine: function reTryChangeSpine() { var self = this; if (self.change_spine_res && self.change_spine_action) { self.changeSpine(true, self.change_spine_res, self.change_spine_action); if (!self.is_change_status) { self.change_spine_action = null; self.change_spine_res = null; } } }, // 通知播放假战斗资源掉落 assetJumpTo: function assetJumpTo() { var node_root_pos = this.node.convertToWorldSpaceAR(cc.v2(0, 0)); // 转到世界坐标 this.model.playResourceCollect(node_root_pos.x + this.model_width * 2, node_root_pos.y + this.model_height * 0.5); }, setVisbale: function setVisbale(status) { if (!this.node) return; if (status) { this.node.setPosition(this.scene_pos); } else { this.node.x = this.is_friend ? -2000 : 3000; } }, // 隐身 setOpacity: function setOpacity(status, value) { if (!this.node) return; if (status) { this.node.opacity = value; } else { this.node.opacity = 0; } }, // 更新buff,包含更新buff列表 updateBuffList: function updateBuffList(buff, buff_cfg) { if (buff == null || buff_cfg == null) { return; } this.buff_list[buff.id] = null; this.buff_list[buff.id] = { buff: buff, config: buff_cfg, res_id: buff_cfg.icon }; var temp_group_list = {}; var res_id = buff_cfg.icon; if (res_id != 0) { var buff_data = this.buff_list_data[res_id]; if (buff_data == null) { buff_data = { res_id: res_id, num: 0, list: [] }; this.buff_list_data[res_id] = buff_data; } if (buff_data.num == 0 || buff_cfg.join_type && buff_cfg.join_type != 3) { buff_data.num += 1; if (buff_cfg.group) { temp_group_list[buff_cfg.group] = true; } } else if (buff_cfg.join_type && buff_cfg.join_type == 3 && buff_cfg.group && !temp_group_list[buff_cfg.group]) { temp_group_list[buff_cfg.group] = true; buff_data.num += 1; } buff_data.list.push(buff.id); var temp_ary = []; for (var key in this.buff_list_data) { var data = this.buff_list_data[key]; if (data) { temp_ary.push(data); } } if (temp_ary.length > 0) { temp_ary.sort(Utils.tableLowerSorter(["res_id"])); for (var index = 0; index < temp_ary.length; index++) { var data = temp_ary[index]; var buff_object = this.buff_list_item[data.res_id]; if (buff_object == null) { buff_object = this.createBuffItem(); this.buff_list_item[data.res_id] = buff_object; } buff_object.label.string = data.num; nx.bridge.setIcon(buff_object.icon.node, "", data.res_id); buff_object.node.active = true; } } } }, // 移除buff没如果没有传参数,就是移除全部 removeBuffList: function removeBuffList(buff_id) { if (buff_id == null) { this.buff_list = {}; this.buff_list_data = {}; this.buff_list_item = {}; nx.bridge.NodeChidrenDestroy(this.buff_container); } else { var data = this.buff_list[buff_id]; // {buff:buff, config:buff_data, res_id: buff_data.icon}; if (data) { var buff_object = this.buff_list_item[data.res_id]; if (buff_object) { var buff_data = this.buff_list_data[data.res_id]; // 取出具体数字 if (buff_data) { buff_data.num -= 1; // 将该buff从列表中删除 for (var index = 0; index < buff_data.list.length; index++) { var element = buff_data.list[index]; if (element == buff_id) { buff_data.list.splice(index, 1); break; } } // 当前没有可用于显示的buff了,把buff节点丢到对象池里面去 if (buff_data.num <= 0) { this.buff_list_item[data.res_id] = null; this.buff_list_data[data.res_id] = null; delete this.buff_list_item[data.res_id]; delete this.buff_list_data[data.res_id]; buff_object.node.destroy(); } else { buff_object.label.string = buff_data.num; } } } } this.buff_list[buff_id] = null; } }, // 创建buff,手动创建,但是对象池获取,包含 node, label, path icon createBuffItem: function createBuffItem() { var buff_object = { node: null, label: null, icon: null, path: "" }; var node = null; var label = null; var icon = null; node = new cc.Node(); node.setAnchorPoint(0, 0.5); node.width = 22; node.height = 22; var icon_node = new cc.Node(); icon_node.setAnchorPoint(0, 0.5); icon_node.name = "icon_sprite"; node.addChild(icon_node); icon = icon_node.addComponent(cc.Sprite); var font_node = new cc.Node(); font_node.color = new cc.Color(cc.Color.WHITE); font_node.setAnchorPoint(1, 0.5); font_node.x = 20; font_node.y = -3; font_node.name = "font_label"; node.addChild(font_node); label = font_node.addComponent(cc.Label); label.lineHeight = 14; label.fontSize = 14; label.horizontalAlign = cc.macro.TextAlignment.RIGHT; var outline_label = font_node.addComponent(cc.LabelOutline); outline_label.color = new cc.Color(cc.Color.BLACK); buff_object.node = node; this.buff_container.addChild(node); buff_object.label = label; buff_object.icon = icon; return buff_object; }, // 判断是否拥有当前id的buff hadBuff: function hadBuff(buff_id) { return this.buff_list && this.buff_list[buff_id] != null; }, getRoleData: function getRoleData() { return this.role_data; }, addTips: function addTips(bid) { if (this && this.tips_list) { this.tips_list[bid] = true; } }, removeTips: function removeTips(bid) { if (this && this.tips_list) { this.tips_list[bid] = false; } }, // 设置当前模型和绑在模型上面的特效播放速率 setTimeScale: function setTimeScale(speed) { if (!this.node) return; this.skeleton_time_scale = speed; if (this.role_data.object_type == BattleConst.Unit_Type.Hero || this.role_data.object_type == BattleConst.Unit_Type.Monster) { this.roleSp.setTimeScale(speed); } else { this.otherSp.setTimeScale(speed); } // 设置特效 for (var effect_id in this.effect_list) { var effect_object = this.effect_list[effect_id]; for (var action_name in effect_object) { var effect = effect_object[action_name]; if (effect && effect.object) { effect.object.setTimeScale(speed); } } } }, // 清空所有特效 clearAllEffect: function clearAllEffect(is_force) { for (var effect_id in this.effect_list) { var effect_object = this.effect_list[effect_id]; for (var action_name in effect_object) { var effect = effect_object[action_name]; if (effect && effect.object) { this.model.getEftMgr().delRoleEft(this.pos + effect_id + action_name); this.effect_list[effect_id][action_name] = null; } } } if (is_force) { this.effect_list = null; this.wait_add_effect_list = null; } else { this.effect_list = {}; this.wait_add_effect_list = {}; } }, checkIsScenePos: function checkIsScenePos() { if (!this || !this.scene_pos) return; var cur_pos = this.node.position; if (cur_pos != this.scene_pos) { this.node.runAction(cc.moveTo(0.08, this.scene_pos)); return; } return; }, /** * 从场景中移除这个单位,回收掉所有的创建节点和预制,并且删除掉所有的资源纹理信息 */ deleteRole: function deleteRole() { if (this.node) { this.node.stopAllActions(); } this.clearAllEffect(true); this.clearNextActTimer(); this.clearNextCallTimer(); if (this.active_timer) { clearTimeout(this.active_timer); this.active_timer = 0; } this.initConfig(); this.node.parent = null; this.node.destroy(); }, getResPath: function getResPath(action_name) { var spine_name = this.spine_name; if (this.spine_name == "") { var key = Utils.getNorKey(this.role_data.object_bid, this.role_data.star); var config_data = gdata("partner_data", "data_partner_star", key); spine_name = config_data.res_id; } return PathTool.getSpinePath(spine_name, spine_name, false); }, initSpineRenderer: function initSpineRenderer() { var _this5 = this; if (!this.node) return; var path = "prefab/battle/elfin_real_role"; nx.res.loadPrefab(path, function (_err, _fab) { // 载入错误 if (_err) { _this5.is_err_elfin = true; return; } _this5.is_err_elfin = false; // 实例化 var elfin = cc.instantiate(_fab); if (_this5.spine_renderer) { _this5.spine_renderer.addChild(elfin); var container = nx.gui.find(_this5.spine_renderer, "elfin_real_role/skills"); _this5.elfin_list = []; for (var i = 0; i < 4; i++) { var elfin_panel = {}; var itemNode = container.children[i]; elfin_panel.icon = itemNode.getChildByName("skill"); //技能图标 elfin_panel.icon.active = false; elfin_panel.mask = itemNode.getChildByName("mask"); //技能图标 elfin_panel.mask.active = false; elfin_panel.cd_lab = elfin_panel.mask.getChildByName("cd_lab").getComponent(cc.Label); //技能CD _this5.elfin_list.push(elfin_panel); } _this5.showElfinSkillIcon(_this5.sprites, _this5.skills); } }); }, showElfinSkillIcon: function showElfinSkillIcon(data, skills) { if (!this.node) return; if (!this.elfin_list) { return; } this.all_elfin_data = data || []; if (Utils.next(this.all_elfin_data) != null) { var bool = false; for (var i = 0; i < 4; i++) { var elfin_object = this.elfin_list[i]; var elfin_data = this.getElfinDataByPos(i + 1); if (elfin_data) { var item_bid = elfin_data.item_bid || 0; if (item_bid == 0) { // 解鎖了,但是未佈置精靈 elfin_object.icon.active = false; elfin_object.mask.active = false; elfin_object.cd_lab.node.active = false; } else { bool = true; var elfin_cfg = game.configs.sprite_data.data_elfin_data[item_bid]; if (elfin_cfg && elfin_cfg[1]) { var skill_cfg = gskilldata("data_get_skill", [elfin_cfg[1]]); if (skill_cfg) { elfin_object.skill_bid = elfin_cfg[1]; // 記錄一下技能bid,用於更新技能cd時間 } } elfin_object.icon.active = true; elfin_object.mask.active = false; elfin_object.cd_lab.node.active = true; elfin_object.cd_lab.string = ""; } } else { // 未解鎖 elfin_object.icon.active = false; elfin_object.mask.active = false; elfin_object.cd_lab.node.active = false; } } if (skills) { this.updateElfinSkillState(skills); } this.spine_renderer.active = bool; } else { // 全都未解鎖 this.spine_renderer.active = false; } }, addSpriteRole: function addSpriteRole(sp_skill_bid, is_left) { if (!this.node) return; var cmp = nx.gui.getComponent(this.spine_renderer, "elfin_real_role", "battle_elfin"); if (cmp) { cmp.setRoleSp(sp_skill_bid); cmp.setNameString(this.skill_data.name || ""); } }, spriteAction: function spriteAction() { if (!this.node) return; var spCmp = nx.gui.getComponent(this.spine_renderer, "elfin_real_role/mask/ef", "nx.fx.spine"); if (spCmp) { spCmp.node.active = true; spCmp.action("action", false, function (_key, _name) { if (_key == "complete") { spCmp.node.active = false; return; } }); } }, // 更新精靈技能CD時間 updateElfinSkillState: function updateElfinSkillState(data) { if (!this.elfin_list) return; for (var _ in data) { var v = data[_]; var skill_bid = v.skill_bid; var end_round = v.end_round; for (var k in this.elfin_list) { var elfin_object = this.elfin_list[k]; if (elfin_object.skill_bid == skill_bid) { var cur_round = this.model.getFightActionCount(); var cd_round = end_round - cur_round; if (cd_round <= 0) { // 無CD時間,當前回合播放 elfin_object.mask.active = false; } else { elfin_object.cd_lab.string = cd_round; elfin_object.mask.active = true; } break; } } } }, //根據位置獲取精靈數據 getElfinDataByPos: function getElfinDataByPos(pos) { if (!this.all_elfin_data) return; for (var k in this.all_elfin_data) { var v = this.all_elfin_data[k]; if (v.pos == pos) return v; } } // update (dt) {}, }); cc._RF.pop();