From 6a22e27e09486560db9ea7fad239e572806ab0e9 Mon Sep 17 00:00:00 2001 From: oc Date: Thu, 14 Mar 2019 22:22:18 +0800 Subject: [PATCH] Adjust order --- libs/actions.js | 12 ++--- libs/enemys.js | 86 ++++++++++++++++----------------- libs/items.js | 124 ++++++++++++++++++++++++------------------------ libs/loader.js | 52 ++++++++++---------- libs/utils.js | 118 ++++++++++++++++++++++----------------------- 5 files changed, 196 insertions(+), 196 deletions(-) diff --git a/libs/actions.js b/libs/actions.js index 87bedddf..00650fe4 100644 --- a/libs/actions.js +++ b/libs/actions.js @@ -395,7 +395,7 @@ actions.prototype.ondown = function (loc) { actions.prototype._sys_ondown_paint = function (x, y, px, py) { // 画板 if (core.status.played && (core.status.event || {}).id == 'paint') { - this.ondownPaint(px, py); + this._ondownPaint(px, py); return true; } } @@ -452,7 +452,7 @@ actions.prototype.onmove = function (loc) { actions.prototype._sys_onmove_paint = function (x, y, px, py) { // 画板 if (core.status.played && (core.status.event || {}).id == 'paint') { - this.onmovePaint(px, py); + this._onmovePaint(px, py); return true; } } @@ -488,7 +488,7 @@ actions.prototype.onup = function () { actions.prototype._sys_onup_paint = function () { // 画板 if (core.status.played && (core.status.event || {}).id == 'paint') { - this.onupPaint(); + this._onupPaint(); return true; } } @@ -2327,7 +2327,7 @@ actions.prototype._keyUpCursor = function (keycode) { ////// 绘图相关 ////// -actions.prototype.ondownPaint = function (x, y) { +actions.prototype._ondownPaint = function (x, y) { x+=core.bigmap.offsetX; y+=core.bigmap.offsetY; if (!core.status.event.data.erase) { @@ -2338,7 +2338,7 @@ actions.prototype.ondownPaint = function (x, y) { core.status.event.data.y = y; } -actions.prototype.onmovePaint = function (x, y) { +actions.prototype._onmovePaint = function (x, y) { if (core.status.event.data.x==null) return; x+=core.bigmap.offsetX; y+=core.bigmap.offsetY; @@ -2353,7 +2353,7 @@ actions.prototype.onmovePaint = function (x, y) { core.status.event.data.y = y; } -actions.prototype.onupPaint = function () { +actions.prototype._onupPaint = function () { core.status.event.data.x = null; core.status.event.data.y = null; // 保存 diff --git a/libs/enemys.js b/libs/enemys.js index ba2ce156..c6ea882c 100644 --- a/libs/enemys.js +++ b/libs/enemys.js @@ -47,15 +47,6 @@ enemys.prototype.getSpecials = function () { return this.enemydata.getSpecials(); } -enemys.prototype._calSpecialContent = function (enemy, content) { - if (typeof content == 'string') return content; - if (typeof enemy == 'string') enemy = core.material.enemys[enemy]; - if (content instanceof Function) { - return content(enemy); - } - return ""; -} - ////// 获得所有特殊属性的名称 ////// enemys.prototype.getSpecialText = function (enemy) { if (typeof enemy == 'string') enemy = core.material.enemys[enemy]; @@ -95,6 +86,15 @@ enemys.prototype.getSpecialHint = function (enemy, special) { return ""; } +enemys.prototype._calSpecialContent = function (enemy, content) { + if (typeof content == 'string') return content; + if (typeof enemy == 'string') enemy = core.material.enemys[enemy]; + if (content instanceof Function) { + return content(enemy); + } + return ""; +} + ////// 能否获胜 ////// enemys.prototype.canBattle = function (enemy, x, y, floorId) { if (typeof enemy == 'string') enemy = core.material.enemys[enemy]; @@ -155,6 +155,40 @@ enemys.prototype.getDamageString = function (enemy, x, y, floorId) { }; } +////// 接下来N个临界值和临界减伤计算 ////// +enemys.prototype.nextCriticals = function (enemy, number, x, y, floorId) { + if (typeof enemy == 'string') enemy = core.material.enemys[enemy]; + number = number||1; + + if (this.hasSpecial(enemy.special, 10)) return []; // 模仿怪物临界 + var info = this.getDamageInfo(enemy, null, x, y, floorId); + if (info == null || this.hasSpecial(enemy.special, 3)) { // 未破防,或是坚固怪 + info = this.getEnemyInfo(enemy, null, x, y, floorId); + if (core.status.hero.atk<=info.def) { + return [[info.def+1-core.status.hero.atk,'?']]; + } + return []; + } + + // getDamageInfo直接返回数字;0伤且无负伤 + if (typeof info == 'number' || (info.damage<=0 && !core.flags.enableNegativeDamage)) { + return [[0,0]]; + } + + if (core.flags.useLoop) { + var LOOP_MAX_VALUE = 1; + if (core.status.hero.atk <= LOOP_MAX_VALUE) { + return this._nextCriticals_useLoop(enemy, info, number, x, y, floorId); + } + else { + return this._nextCriticals_useBinarySearch(enemy, info, number, x, y, floorId); + } + } + else { + return this._nextCriticals_useTurn(enemy, info, number, x, y, floorId); + } +} + enemys.prototype._nextCriticals_useLoop = function (enemy, info, number, x, y, floorId) { var mon_hp = info.mon_hp, hero_atk = core.status.hero.atk, mon_def = info.mon_def, pre = info.damage; var list = []; @@ -225,40 +259,6 @@ enemys.prototype._nextCriticals_useTurn = function (enemy, info, number, x, y, f return list; } -////// 接下来N个临界值和临界减伤计算 ////// -enemys.prototype.nextCriticals = function (enemy, number, x, y, floorId) { - if (typeof enemy == 'string') enemy = core.material.enemys[enemy]; - number = number||1; - - if (this.hasSpecial(enemy.special, 10)) return []; // 模仿怪物临界 - var info = this.getDamageInfo(enemy, null, x, y, floorId); - if (info == null || this.hasSpecial(enemy.special, 3)) { // 未破防,或是坚固怪 - info = this.getEnemyInfo(enemy, null, x, y, floorId); - if (core.status.hero.atk<=info.def) { - return [[info.def+1-core.status.hero.atk,'?']]; - } - return []; - } - - // getDamageInfo直接返回数字;0伤且无负伤 - if (typeof info == 'number' || (info.damage<=0 && !core.flags.enableNegativeDamage)) { - return [[0,0]]; - } - - if (core.flags.useLoop) { - var LOOP_MAX_VALUE = 1; - if (core.status.hero.atk <= LOOP_MAX_VALUE) { - return this._nextCriticals_useLoop(enemy, info, number, x, y, floorId); - } - else { - return this._nextCriticals_useBinarySearch(enemy, info, number, x, y, floorId); - } - } - else { - return this._nextCriticals_useTurn(enemy, info, number, x, y, floorId); - } -} - ////// N防减伤计算 ////// enemys.prototype.getDefDamage = function (enemy, k, x, y, floorId) { if (typeof enemy == 'string') enemy = core.material.enemys[enemy]; diff --git a/libs/items.js b/libs/items.js index ec445a3c..708acd6a 100644 --- a/libs/items.js +++ b/libs/items.js @@ -61,6 +61,21 @@ items.prototype.getItemEffectTip = function(itemId) { return ""; } +////// 使用道具 ////// +items.prototype.useItem = function (itemId, noRoute, callback) { + if (!this.canUseItem(itemId)) { + if (core.isset(callback)) callback(); + return; + } + // 执行道具效果 + this._useItemEffect(itemId); + // 执行完毕 + this._afterUseItem(itemId); + // 记录路线 + if (!noRoute) core.status.route.push("item:"+itemId); + if (core.isset(callback)) callback(); +} + items.prototype._useItemEffect = function (itemId) { if (itemId in this.useItemEffect) { try { @@ -88,21 +103,6 @@ items.prototype._afterUseItem = function (itemId) { core.updateStatusBar(); } -////// 使用道具 ////// -items.prototype.useItem = function (itemId, noRoute, callback) { - if (!this.canUseItem(itemId)) { - if (core.isset(callback)) callback(); - return; - } - // 执行道具效果 - this._useItemEffect(itemId); - // 执行完毕 - this._afterUseItem(itemId); - // 记录路线 - if (!noRoute) core.status.route.push("item:"+itemId); - if (core.isset(callback)) callback(); -} - ////// 当前能否使用道具 ////// items.prototype.canUseItem = function (itemId) { // 没有道具 @@ -266,53 +266,6 @@ items.prototype.canEquip = function (equipId, hint) { return true; } -////// 实际换装的效果 ////// -items.prototype._loadEquipEffect = function (equipId, unloadEquipId, isPercentage) { - // 比较能力值 - var result = core.compareEquipment(equipId, unloadEquipId); - - if (isPercentage) { - for (var v in result) - core.addFlag('__'+v+'_buff__', result[v]/100); - } - else { - for (var v in result) - core.status.hero[v] += result[v]; - } -} - -items.prototype._realLoadEquip = function (type, loadId, unloadId, callback) { - var loadEquip = core.material.items[loadId] || {}, unloadEquip = core.material.items[unloadId] || {}; - if (!core.isset(loadEquip.equip)) loadEquip.equip = {}; - if (!core.isset(unloadEquip.equip)) unloadEquip.equip = {}; - - var loadPercentage = loadEquip.equip.percentage, unloadPercentage = unloadEquip.equip.percentage; - - if (loadPercentage != null && unloadPercentage != null && loadPercentage != unloadPercentage) { - this.unloadEquip(type); - this.loadEquip(loadId); - if (core.isset(callback)) callback(); - return; - } - - // --- 音效 - core.playSound('equip.mp3'); - - // --- 实际换装 - this._loadEquipEffect(loadId, unloadId, loadPercentage==null?unloadPercentage:loadPercentage); - - // --- 加减 - if (loadId) core.removeItem(loadId); - if (unloadId) core.addItem(unloadId); - core.status.hero.equipment[type] = loadId||null; - - // --- 提示 - if (loadId) core.drawTip("已装备上"+loadEquip.name, core.material.icons.items[loadId]); - else if (unloadId) core.drawTip("已卸下"+unloadEquip.name, core.material.icons.items[unloadId]); - - if (core.isset(callback)) callback(); -} - ////// 换上 ////// items.prototype.loadEquip = function (equipId, callback) { if (!core.isset(core.status.hero)) return null; @@ -364,6 +317,53 @@ items.prototype.compareEquipment = function (compareEquipId, beComparedEquipId) return {"atk":compareAtk,"def":compareDef,"mdef":compareMdef}; } +////// 实际换装的效果 ////// +items.prototype._loadEquipEffect = function (equipId, unloadEquipId, isPercentage) { + // 比较能力值 + var result = core.compareEquipment(equipId, unloadEquipId); + + if (isPercentage) { + for (var v in result) + core.addFlag('__'+v+'_buff__', result[v]/100); + } + else { + for (var v in result) + core.status.hero[v] += result[v]; + } +} + +items.prototype._realLoadEquip = function (type, loadId, unloadId, callback) { + var loadEquip = core.material.items[loadId] || {}, unloadEquip = core.material.items[unloadId] || {}; + if (!core.isset(loadEquip.equip)) loadEquip.equip = {}; + if (!core.isset(unloadEquip.equip)) unloadEquip.equip = {}; + + var loadPercentage = loadEquip.equip.percentage, unloadPercentage = unloadEquip.equip.percentage; + + if (loadPercentage != null && unloadPercentage != null && loadPercentage != unloadPercentage) { + this.unloadEquip(type); + this.loadEquip(loadId); + if (core.isset(callback)) callback(); + return; + } + + // --- 音效 + core.playSound('equip.mp3'); + + // --- 实际换装 + this._loadEquipEffect(loadId, unloadId, loadPercentage==null?unloadPercentage:loadPercentage); + + // --- 加减 + if (loadId) core.removeItem(loadId); + if (unloadId) core.addItem(unloadId); + core.status.hero.equipment[type] = loadId||null; + + // --- 提示 + if (loadId) core.drawTip("已装备上"+loadEquip.name, core.material.icons.items[loadId]); + else if (unloadId) core.drawTip("已卸下"+unloadEquip.name, core.material.icons.items[unloadId]); + + if (core.isset(callback)) callback(); +} + ////// 保存装备 ////// items.prototype.quickSaveEquip = function (index) { if (!core.isset(core.status.hero.equipment)) core.status.hero.equipment = []; diff --git a/libs/loader.js b/libs/loader.js index 337c199a..4449c64e 100644 --- a/libs/loader.js +++ b/libs/loader.js @@ -13,12 +13,12 @@ loader.prototype._init = function () { } ////// 设置加载进度条进度 ////// -loader.prototype.setStartProgressVal = function (val) { +loader.prototype._setStartProgressVal = function (val) { core.dom.startTopProgress.style.width = val + '%'; } ////// 设置加载进度条提示文字 ////// -loader.prototype.setStartLoadTipText = function (text) { +loader.prototype._setStartLoadTipText = function (text) { core.dom.startTopLoadTips.innerHTML = text; } @@ -106,10 +106,10 @@ loader.prototype.loadImages = function (names, toSave, callback) { var items = 0; for (var i=0;i0) { + ans+=lastMove.substring(0,1).toUpperCase(); + if (cnt>1) ans+=cnt; + cnt=0; + } + lastMove=t; + cnt++; + } + else { + if (cnt>0) { + ans+=lastMove.substring(0,1).toUpperCase(); + if (cnt>1) ans+=cnt; + cnt=0; + } + ans += core.utils._encodeRoute_encodeOne(t); + } + }); + if (cnt>0) { + ans+=lastMove.substring(0,1).toUpperCase(); + if (cnt>1) ans+=cnt; + } + return LZString.compressToBase64(ans); +} + utils.prototype._encodeRoute_id2number = function (id) { var number = core.maps.getNumberById(id); return number==0?id:number; @@ -436,34 +466,23 @@ utils.prototype._encodeRoute_encodeOne = function (t) { return ''; } -////// 加密路线 ////// -utils.prototype.encodeRoute = function (route) { - var ans="", lastMove = "", cnt=0; +////// 解密路线 ////// +utils.prototype.decodeRoute = function (route) { + if (!core.isset(route)) return route; - route.forEach(function (t) { - if (t=='up' || t=='down' || t=='left' || t=='right') { - if (t!=lastMove && cnt>0) { - ans+=lastMove.substring(0,1).toUpperCase(); - if (cnt>1) ans+=cnt; - cnt=0; - } - lastMove=t; - cnt++; + // 解压缩 + try { + var v = LZString.decompressFromBase64(route); + if (core.isset(v) && /^[a-zA-Z0-9+\/=:]*$/.test(v)) { + route = v; } - else { - if (cnt>0) { - ans+=lastMove.substring(0,1).toUpperCase(); - if (cnt>1) ans+=cnt; - cnt=0; - } - ans += core.utils._encodeRoute_encodeOne(t); - } - }); - if (cnt>0) { - ans+=lastMove.substring(0,1).toUpperCase(); - if (cnt>1) ans+=cnt; + } catch (e) {} + + var decodeObj = {route: route, index: 0, ans: []}; + while (decodeObj.index < decodeObj.route.length) { + this._decodeRoute_decodeOne(decodeObj, decodeObj.route.charAt(decodeObj.index++)); } - return LZString.compressToBase64(ans); + return decodeObj.ans; } utils.prototype._decodeRoute_getNumber = function (decodeObj, noparse) { @@ -518,25 +537,6 @@ utils.prototype._decodeRoute_decodeOne = function (decodeObj, c) { } } -////// 解密路线 ////// -utils.prototype.decodeRoute = function (route) { - if (!core.isset(route)) return route; - - // 解压缩 - try { - var v = LZString.decompressFromBase64(route); - if (core.isset(v) && /^[a-zA-Z0-9+\/=:]*$/.test(v)) { - route = v; - } - } catch (e) {} - - var decodeObj = {route: route, index: 0, ans: []}; - while (decodeObj.index < decodeObj.route.length) { - this._decodeRoute_decodeOne(decodeObj, decodeObj.route.charAt(decodeObj.index++)); - } - return decodeObj.ans; -} - ////// 判断某对象是否不为undefined也不会null ////// utils.prototype.isset = function (val) { if (val == undefined || val == null || (typeof val=='number' && isNaN(val))) { @@ -624,21 +624,6 @@ utils.prototype.convertBase = function (str, fromBase, toBase) { return ans; } -utils.prototype.__init_seed = function () { - var rand = new Date().getTime()%34834795 + 3534; - rand = this.__next_rand(rand); - rand = this.__next_rand(rand); - rand = this.__next_rand(rand); - core.setFlag('__seed__', rand); - core.setFlag('__rand__', rand); -} - -utils.prototype.__next_rand = function (_rand) { - _rand=(_rand%127773)*16807-~~(_rand/127773)*2836; - _rand+=_rand<0?2147483647:0; - return _rand; -} - utils.prototype.rand = function (num) { var rand = core.getFlag('__rand__'); rand = this.__next_rand(rand); @@ -672,6 +657,21 @@ utils.prototype.rand2 = function (num) { return value; } +utils.prototype.__init_seed = function () { + var rand = new Date().getTime()%34834795 + 3534; + rand = this.__next_rand(rand); + rand = this.__next_rand(rand); + rand = this.__next_rand(rand); + core.setFlag('__seed__', rand); + core.setFlag('__rand__', rand); +} + +utils.prototype.__next_rand = function (_rand) { + _rand=(_rand%127773)*16807-~~(_rand/127773)*2836; + _rand+=_rand<0?2147483647:0; + return _rand; +} + ////// 读取一个本地文件内容 ////// utils.prototype.readFile = function (success, error, readType) {