Reformat code

This commit is contained in:
oc 2019-03-16 22:58:57 +08:00
parent 8144ca8d17
commit 02934cad46
10 changed files with 1104 additions and 1030 deletions

File diff suppressed because it is too large Load Diff

View File

@ -172,9 +172,9 @@ function core() {
'textAttribute': { 'textAttribute': {
'position': "center", 'position': "center",
"offset": 0, "offset": 0,
"title": [255,215,0,1], "title": [255, 215, 0, 1],
"background": [0,0,0,0.85], "background": [0, 0, 0, 0.85],
"text": [255,255,255,1], "text": [255, 255, 255, 1],
"titlefont": 22, "titlefont": 22,
"textfont": 16, "textfont": 16,
"bold": false, "bold": false,
@ -242,7 +242,7 @@ core.prototype.init = function (coreData, callback) {
core.material.enemys = core.enemys.getEnemys(); core.material.enemys = core.enemys.getEnemys();
core.material.icons = core.icons.getIcons(); core.material.icons = core.icons.getIcons();
core.platform.isOnline = location.protocol.indexOf("http")==0; core.platform.isOnline = location.protocol.indexOf("http") == 0;
if (core.platform.isOnline) { if (core.platform.isOnline) {
window.AudioContext = window.AudioContext || window.webkitAudioContext || window.mozAudioContext || window.msAudioContext; window.AudioContext = window.AudioContext || window.webkitAudioContext || window.mozAudioContext || window.msAudioContext;
try { try {
@ -256,10 +256,10 @@ core.prototype.init = function (coreData, callback) {
} }
["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"].forEach(function (t) { ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"].forEach(function (t) {
if (navigator.userAgent.indexOf(t)>=0) { if (navigator.userAgent.indexOf(t) >= 0) {
if (t=='iPhone' || t=='iPad' || t=='iPod') core.platform.isIOS = true; if (t == 'iPhone' || t == 'iPad' || t == 'iPod') core.platform.isIOS = true;
if (t=='Android') core.platform.isAndroid=true; if (t == 'Android') core.platform.isAndroid = true;
core.platform.isPC=false; core.platform.isPC = false;
} }
}); });
@ -270,8 +270,8 @@ core.prototype.init = function (coreData, callback) {
core.platform.supportCopy = false; core.platform.supportCopy = false;
} }
var chrome=/Chrome\/(\d+)\./i.exec(navigator.userAgent); var chrome = /Chrome\/(\d+)\./i.exec(navigator.userAgent);
if (core.isset(chrome) && parseInt(chrome[1])>=50) if (core.isset(chrome) && parseInt(chrome[1]) >= 50)
core.platform.isChrome = true; core.platform.isChrome = true;
core.platform.isSafari = /Safari/i.test(navigator.userAgent) && !/Chrome/i.test(navigator.userAgent); core.platform.isSafari = /Safari/i.test(navigator.userAgent) && !/Chrome/i.test(navigator.userAgent);
core.platform.isQQ = /QQ/i.test(navigator.userAgent); core.platform.isQQ = /QQ/i.test(navigator.userAgent);
@ -279,26 +279,41 @@ core.prototype.init = function (coreData, callback) {
core.platform.useLocalForage = core.getLocalStorage('useLocalForage', !core.platform.isIOS); core.platform.useLocalForage = core.getLocalStorage('useLocalForage', !core.platform.isIOS);
if (core.platform.useLocalForage) { if (core.platform.useLocalForage) {
try { try {
core.setLocalForage("__test__", lzw_encode("__test__"), function() { core.setLocalForage("__test__", lzw_encode("__test__"), function () {
try { try {
core.getLocalForage("__test__", null, function(data) { core.getLocalForage("__test__", null, function (data) {
try { try {
if (lzw_decode(data)!="__test__") { if (lzw_decode(data) != "__test__") {
console.log("localForage unsupported!"); console.log("localForage unsupported!");
core.platform.useLocalForage=false; core.platform.useLocalForage = false;
} }
else { else {
console.log("localForage supported!") console.log("localForage supported!")
core.removeLocalForage("__test__"); core.removeLocalForage("__test__");
} }
} }
catch (e) {main.log(e); core.platform.useLocalForage=false;} catch (e) {
}, function(e) {main.log(e); core.platform.useLocalForage=false;}) main.log(e);
core.platform.useLocalForage = false;
}
}, function (e) {
main.log(e);
core.platform.useLocalForage = false;
})
} }
catch (e) {main.log(e); core.platform.useLocalForage=false;} catch (e) {
}, function(e) {main.log(e); core.platform.useLocalForage=false;}) main.log(e);
core.platform.useLocalForage = false;
}
}, function (e) {
main.log(e);
core.platform.useLocalForage = false;
})
}
catch (e) {
main.log(e);
core.platform.useLocalForage = false;
} }
catch (e) {main.log(e); core.platform.useLocalForage=false;}
} }
core.platform.extendKeyboard = core.getLocalStorage("extendKeyboard", false); core.platform.extendKeyboard = core.getLocalStorage("extendKeyboard", false);
@ -316,7 +331,7 @@ core.prototype.init = function (coreData, callback) {
// 先从存储中读取BGM状态 // 先从存储中读取BGM状态
core.musicStatus.bgmStatus = core.getLocalStorage('bgmStatus', true); core.musicStatus.bgmStatus = core.getLocalStorage('bgmStatus', true);
if (!core.platform.isPC && (navigator.connection||{}).type!='wifi') if (!core.platform.isPC && (navigator.connection || {}).type != 'wifi')
core.musicStatus.bgmStatus = false; core.musicStatus.bgmStatus = false;
core.musicStatus.soundStatus = core.getLocalStorage('soundStatus', true); core.musicStatus.soundStatus = core.getLocalStorage('soundStatus', true);
@ -336,7 +351,7 @@ core.prototype.init = function (coreData, callback) {
core.animateFrame.weather.fog.src = "project/images/fog.png"; core.animateFrame.weather.fog.src = "project/images/fog.png";
core.material.images.keyboard = new Image(); core.material.images.keyboard = new Image();
core.material.images.keyboard.onerror = function () { core.material.images.keyboard.onerror = function () {
core.material.images.keyboard = null; core.material.images.keyboard = null;
} }
core.material.images.keyboard.src = "project/images/keyboard.png"; core.material.images.keyboard.src = "project/images/keyboard.png";
@ -351,14 +366,14 @@ core.prototype.init = function (coreData, callback) {
core.loader._load(function () { core.loader._load(function () {
// 设置勇士高度 // 设置勇士高度
core.material.icons.hero.height = core.material.images.hero.height/4; core.material.icons.hero.height = core.material.images.hero.height / 4;
// 行走图 // 行走图
core.control.updateHeroIcon(); core.control.updateHeroIcon();
core.initStatus.maps = core.maps.initMaps(core.floorIds); core.initStatus.maps = core.maps.initMaps(core.floorIds);
core.setRequestAnimationFrame(); core.setRequestAnimationFrame();
if (main.mode=='play') if (main.mode == 'play')
core.events.initGame(); core.events.initGame();
if (core.isset(functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a.plugins)) { if (core.isset(functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a.plugins)) {
@ -396,13 +411,13 @@ core.prototype._forwardFunc = function (name, funcname) {
} }
if (core[funcname]) { if (core[funcname]) {
console.error("ERROR: Cannot forward function "+funcname+" from "+name+"!"); console.error("ERROR: Cannot forward function " + funcname + " from " + name + "!");
return; return;
} }
var parameterInfo = /^\s*function\s*[\w_$]*\(([\w_,$\s]*)\)\s*\{/.exec(core[name][funcname].toString()); var parameterInfo = /^\s*function\s*[\w_$]*\(([\w_,$\s]*)\)\s*\{/.exec(core[name][funcname].toString());
var parameters = (parameterInfo==null?"":parameterInfo[1]).replace(/\s*/g, '').replace(/,/g, ', '); var parameters = (parameterInfo == null ? "" : parameterInfo[1]).replace(/\s*/g, '').replace(/,/g, ', ');
// core[funcname] = new Function(parameters, "return core."+name+"."+funcname+"("+parameters+");"); // core[funcname] = new Function(parameters, "return core."+name+"."+funcname+"("+parameters+");");
eval("core."+funcname+" = function ("+parameters+") {\n\treturn core."+name+"."+funcname+"("+parameters+");\n}"); eval("core." + funcname + " = function (" + parameters + ") {\n\treturn core." + name + "." + funcname + "(" + parameters + ");\n}");
} }
/** /**

View File

@ -4,13 +4,13 @@ function data() {
this._init(); this._init();
} }
data.prototype._init = function() { data.prototype._init = function () {
this.firstData = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.firstData; this.firstData = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.firstData;
this.values = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.values; this.values = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.values;
this.flags = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.flags; this.flags = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.flags;
//delete(data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d); //delete(data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d);
} }
data.prototype.getFirstData = function() { data.prototype.getFirstData = function () {
return core.clone(this.firstData); return core.clone(this.firstData);
} }

View File

@ -8,8 +8,10 @@ function enemys() {
enemys.prototype._init = function () { enemys.prototype._init = function () {
this.enemys = enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80; this.enemys = enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80;
this.enemydata = functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a.enemys; this.enemydata = functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a.enemys;
if (main.mode=='play') { if (main.mode == 'play') {
this.enemydata.hasSpecial = function (a, b) {return core.enemys.hasSpecial(a, b)}; this.enemydata.hasSpecial = function (a, b) {
return core.enemys.hasSpecial(a, b)
};
for (var enemyId in this.enemys) { for (var enemyId in this.enemys) {
this.enemys[enemyId].id = enemyId; this.enemys[enemyId].id = enemyId;
} }
@ -54,9 +56,9 @@ enemys.prototype.getSpecialText = function (enemy) {
var special = enemy.special; var special = enemy.special;
var text = []; var text = [];
var specials=this.getSpecials(); var specials = this.getSpecials();
if (core.isset(specials)) { if (core.isset(specials)) {
for (var i=0;i<specials.length;i++) { for (var i = 0; i < specials.length; i++) {
if (this.hasSpecial(special, specials[i][0])) if (this.hasSpecial(special, specials[i][0]))
text.push(this._calSpecialContent(enemy, specials[i][1])); text.push(this._calSpecialContent(enemy, specials[i][1]));
} }
@ -66,22 +68,22 @@ enemys.prototype.getSpecialText = function (enemy) {
////// 获得每个特殊属性的说明 ////// ////// 获得每个特殊属性的说明 //////
enemys.prototype.getSpecialHint = function (enemy, special) { enemys.prototype.getSpecialHint = function (enemy, special) {
var specials=this.getSpecials(); var specials = this.getSpecials();
if (!core.isset(special)) { if (!core.isset(special)) {
if (!core.isset(specials)) return []; if (!core.isset(specials)) return [];
var hints = []; var hints = [];
for (var i=0;i<specials.length;i++) { for (var i = 0; i < specials.length; i++) {
if (this.hasSpecial(enemy, specials[i][0])) if (this.hasSpecial(enemy, specials[i][0]))
hints.push(this._calSpecialContent(enemy, specials[i][1])+""+this._calSpecialContent(enemy, specials[i][2])); hints.push(this._calSpecialContent(enemy, specials[i][1]) + "" + this._calSpecialContent(enemy, specials[i][2]));
} }
return hints; return hints;
} }
if (!core.isset(specials)) return ""; if (!core.isset(specials)) return "";
for (var i=0;i<specials.length;i++) { for (var i = 0; i < specials.length; i++) {
if (special == specials[i][0]) if (special == specials[i][0])
return this._calSpecialContent(enemy, specials[i][1])+""+this._calSpecialContent(enemy, specials[i][2]); return this._calSpecialContent(enemy, specials[i][1]) + "" + this._calSpecialContent(enemy, specials[i][2]);
} }
return ""; return "";
} }
@ -118,7 +120,7 @@ enemys.prototype.getExtraDamage = function (enemy) {
extra_damage += core.getFlag('hatred', 0); extra_damage += core.getFlag('hatred', 0);
} }
if (this.hasSpecial(enemy.special, 22)) { // 固伤 if (this.hasSpecial(enemy.special, 22)) { // 固伤
extra_damage += enemy.damage||0; extra_damage += enemy.damage || 0;
} }
return extra_damage; return extra_damage;
} }
@ -158,21 +160,21 @@ enemys.prototype.getDamageString = function (enemy, x, y, floorId) {
////// 接下来N个临界值和临界减伤计算 ////// ////// 接下来N个临界值和临界减伤计算 //////
enemys.prototype.nextCriticals = function (enemy, number, x, y, floorId) { enemys.prototype.nextCriticals = function (enemy, number, x, y, floorId) {
if (typeof enemy == 'string') enemy = core.material.enemys[enemy]; if (typeof enemy == 'string') enemy = core.material.enemys[enemy];
number = number||1; number = number || 1;
if (this.hasSpecial(enemy.special, 10)) return []; // 模仿怪物临界 if (this.hasSpecial(enemy.special, 10)) return []; // 模仿怪物临界
var info = this.getDamageInfo(enemy, null, x, y, floorId); var info = this.getDamageInfo(enemy, null, x, y, floorId);
if (info == null || this.hasSpecial(enemy.special, 3)) { // 未破防,或是坚固怪 if (info == null || this.hasSpecial(enemy.special, 3)) { // 未破防,或是坚固怪
info = this.getEnemyInfo(enemy, null, x, y, floorId); info = this.getEnemyInfo(enemy, null, x, y, floorId);
if (core.status.hero.atk<=info.def) { if (core.status.hero.atk <= info.def) {
return [[info.def+1-core.status.hero.atk,'?']]; return [[info.def + 1 - core.status.hero.atk, '?']];
} }
return []; return [];
} }
// getDamageInfo直接返回数字0伤且无负伤 // getDamageInfo直接返回数字0伤且无负伤
if (typeof info == 'number' || (info.damage<=0 && !core.flags.enableNegativeDamage)) { if (typeof info == 'number' || (info.damage <= 0 && !core.flags.enableNegativeDamage)) {
return [[0,0]]; return [[0, 0]];
} }
if (core.flags.useLoop) { if (core.flags.useLoop) {
@ -192,17 +194,17 @@ enemys.prototype.nextCriticals = function (enemy, number, x, y, floorId) {
enemys.prototype._nextCriticals_useLoop = function (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 mon_hp = info.mon_hp, hero_atk = core.status.hero.atk, mon_def = info.mon_def, pre = info.damage;
var list = []; var list = [];
for (var atk=hero_atk+1;atk<=mon_hp+mon_def;atk++) { for (var atk = hero_atk + 1; atk <= mon_hp + mon_def; atk++) {
var nextInfo = this.getDamageInfo(enemy, {"atk": atk}, x, y, floorId); var nextInfo = this.getDamageInfo(enemy, {"atk": atk}, x, y, floorId);
if (nextInfo==null || (typeof nextInfo == 'number')) break; if (nextInfo == null || (typeof nextInfo == 'number')) break;
if (pre>nextInfo.damage) { if (pre > nextInfo.damage) {
pre = nextInfo.damage; pre = nextInfo.damage;
list.push([atk-hero_atk, info.damage-nextInfo.damage]); list.push([atk - hero_atk, info.damage - nextInfo.damage]);
if (nextInfo.damage<=0 && !core.flags.enableNegativeDamage) break; if (nextInfo.damage <= 0 && !core.flags.enableNegativeDamage) break;
if (list.length>=number) break; if (list.length >= number) break;
} }
} }
if (list.length==0) list.push([0,0]); if (list.length == 0) list.push([0, 0]);
return list; return list;
} }
@ -211,51 +213,51 @@ enemys.prototype._nextCriticals_useBinarySearch = function (enemy, info, number,
var list = []; var list = [];
var calNext = function (currAtk, maxAtk) { var calNext = function (currAtk, maxAtk) {
var start = Math.floor(currAtk), end = Math.floor(maxAtk); var start = Math.floor(currAtk), end = Math.floor(maxAtk);
if (start>end) return null; if (start > end) return null;
while (start<end) { while (start < end) {
var mid = Math.floor((start+end)/2); var mid = Math.floor((start + end) / 2);
var nextInfo = core.enemys.getDamageInfo(enemy, {"atk": mid}, x, y, floorId); var nextInfo = core.enemys.getDamageInfo(enemy, {"atk": mid}, x, y, floorId);
if (nextInfo == null || (typeof nextInfo == 'number')) return null; if (nextInfo == null || (typeof nextInfo == 'number')) return null;
if (pre>nextInfo.damage) end = mid; if (pre > nextInfo.damage) end = mid;
else start = mid+1; else start = mid + 1;
} }
var nextInfo = core.enemys.getDamageInfo(enemy, {"atk": start}, x, y, floorId); var nextInfo = core.enemys.getDamageInfo(enemy, {"atk": start}, x, y, floorId);
return nextInfo==null||(typeof nextInfo == 'number')||nextInfo.damage>=pre?null:[start,nextInfo.damage]; return nextInfo == null || (typeof nextInfo == 'number') || nextInfo.damage >= pre ? null : [start, nextInfo.damage];
} }
var currAtk = hero_atk; var currAtk = hero_atk;
while (true) { while (true) {
var next = calNext(currAtk+1, mon_hp+mon_def, pre); var next = calNext(currAtk + 1, mon_hp + mon_def, pre);
if (next == null) break; if (next == null) break;
currAtk = next[0]; currAtk = next[0];
pre = next[1]; pre = next[1];
list.push([currAtk-hero_atk, info.damage-pre]); list.push([currAtk - hero_atk, info.damage - pre]);
if (pre<=0 && !core.flags.enableNegativeDamage) break; if (pre <= 0 && !core.flags.enableNegativeDamage) break;
if (list.length>=number) break; if (list.length >= number) break;
} }
if (list.length==0) list.push([0,0]); if (list.length == 0) list.push([0, 0]);
return list; return list;
} }
enemys.prototype._nextCriticals_useTurn = function (enemy, info, number, x, y, floorId) { enemys.prototype._nextCriticals_useTurn = function (enemy, info, number, x, y, floorId) {
var mon_hp = info.mon_hp, hero_atk = core.status.hero.atk, mon_def = info.mon_def, turn = info.turn; var mon_hp = info.mon_hp, hero_atk = core.status.hero.atk, mon_def = info.mon_def, turn = info.turn;
var list = [], pre = null; var list = [], pre = null;
for (var t = turn-1;t>=1;t--) { for (var t = turn - 1; t >= 1; t--) {
var nextAtk = Math.ceil(mon_hp/t) + mon_def; var nextAtk = Math.ceil(mon_hp / t) + mon_def;
// 装备提升比例的计算临界 // 装备提升比例的计算临界
nextAtk = Math.ceil(nextAtk / core.getFlag('__atk_buff__', 1)); nextAtk = Math.ceil(nextAtk / core.getFlag('__atk_buff__', 1));
if (nextAtk<=hero_atk) break; if (nextAtk <= hero_atk) break;
if (nextAtk!=pre) { if (nextAtk != pre) {
var nextInfo = this.getDamageInfo(enemy, {"atk": nextAtk}, x, y, floorId); var nextInfo = this.getDamageInfo(enemy, {"atk": nextAtk}, x, y, floorId);
if (nextInfo==null || (typeof nextInfo == 'number')) break; if (nextInfo == null || (typeof nextInfo == 'number')) break;
list.push([nextAtk-hero_atk,Math.floor(info.damage-nextInfo.damage)]); list.push([nextAtk - hero_atk, Math.floor(info.damage - nextInfo.damage)]);
if (nextInfo.damage<=0 && !core.flags.enableNegativeDamage) break; if (nextInfo.damage <= 0 && !core.flags.enableNegativeDamage) break;
pre = nextAtk; pre = nextAtk;
} }
if (list.length>=number) if (list.length >= number)
break; break;
} }
if (list.length==0) list.push([0,0]); if (list.length == 0) list.push([0, 0]);
return list; return list;
} }
@ -265,7 +267,7 @@ enemys.prototype.getDefDamage = function (enemy, k, x, y, floorId) {
k = k || 1; k = k || 1;
var nowDamage = this.calDamage(enemy, null, x, y, floorId); var nowDamage = this.calDamage(enemy, null, x, y, floorId);
var nextDamage = this.calDamage(enemy, {"def": core.status.hero.def + k}, x, y, floorId); var nextDamage = this.calDamage(enemy, {"def": core.status.hero.def + k}, x, y, floorId);
if (nowDamage == null || nextDamage ==null) return "???"; if (nowDamage == null || nextDamage == null) return "???";
return nowDamage - nextDamage; return nowDamage - nextDamage;
} }
@ -275,7 +277,7 @@ enemys.prototype.getEnemyInfo = function (enemy, hero, x, y, floorId) {
} }
////// 获得战斗伤害信息(实际伤害计算函数) ////// ////// 获得战斗伤害信息(实际伤害计算函数) //////
enemys.prototype.getDamageInfo = function(enemy, hero, x, y, floorId) { enemys.prototype.getDamageInfo = function (enemy, hero, x, y, floorId) {
// 移动到了脚本编辑 - getDamageInfo中 // 移动到了脚本编辑 - getDamageInfo中
if (typeof enemy == 'string') enemy = core.material.enemys[enemy]; if (typeof enemy == 'string') enemy = core.material.enemys[enemy];
return this.enemydata.getDamageInfo(enemy, hero, x, y, floorId); return this.enemydata.getDamageInfo(enemy, hero, x, y, floorId);
@ -298,12 +300,12 @@ enemys.prototype.updateEnemys = function () {
////// 获得当前楼层的怪物列表 ////// ////// 获得当前楼层的怪物列表 //////
enemys.prototype.getCurrentEnemys = function (floorId) { enemys.prototype.getCurrentEnemys = function (floorId) {
floorId=floorId||core.status.floorId; floorId = floorId || core.status.floorId;
var enemys = [], used = {}; var enemys = [], used = {};
var mapBlocks = core.status.maps[floorId].blocks; var mapBlocks = core.status.maps[floorId].blocks;
for (var b = 0; b < mapBlocks.length; b++) { for (var b = 0; b < mapBlocks.length; b++) {
if (core.isset(mapBlocks[b].event) && !mapBlocks[b].disable if (core.isset(mapBlocks[b].event) && !mapBlocks[b].disable
&& mapBlocks[b].event.cls.indexOf('enemy')==0) { && mapBlocks[b].event.cls.indexOf('enemy') == 0) {
this._getCurrentEnemys_addEnemy(mapBlocks[b].event.id, enemys, used, floorId); this._getCurrentEnemys_addEnemy(mapBlocks[b].event.id, enemys, used, floorId);
} }
} }
@ -324,15 +326,15 @@ enemys.prototype._getCurrentEnemys_getEnemy = function (enemyId) {
enemys.prototype._getCurrentEnemys_addEnemy = function (enemyId, enemys, used, floorId) { enemys.prototype._getCurrentEnemys_addEnemy = function (enemyId, enemys, used, floorId) {
var enemy = this._getCurrentEnemys_getEnemy(enemyId); var enemy = this._getCurrentEnemys_getEnemy(enemyId);
if (enemy==null || used[enemy.id]) return; if (enemy == null || used[enemy.id]) return;
var enemyInfo = this.getEnemyInfo(enemy, null, null, null, floorId); var enemyInfo = this.getEnemyInfo(enemy, null, null, null, floorId);
var specialText = core.enemys.getSpecialText(enemy); var specialText = core.enemys.getSpecialText(enemy);
if (specialText.length>=3) specialText = "多属性..."; if (specialText.length >= 3) specialText = "多属性...";
else specialText = specialText.join(" "); else specialText = specialText.join(" ");
var critical = this.nextCriticals(enemy, 1, null, null, floorId); var critical = this.nextCriticals(enemy, 1, null, null, floorId);
if (critical.length>0) critical=critical[0]; if (critical.length > 0) critical = critical[0];
var e = core.clone(enemy); var e = core.clone(enemy);
for (var x in enemyInfo) { for (var x in enemyInfo) {
@ -342,7 +344,7 @@ enemys.prototype._getCurrentEnemys_addEnemy = function (enemyId, enemys, used, f
e.damage = this.getDamage(enemy, null, null, floorId); e.damage = this.getDamage(enemy, null, null, floorId);
e.critical = critical[0]; e.critical = critical[0];
e.criticalDamage = critical[1]; e.criticalDamage = critical[1];
e.defDamage = this.getDefDamage(enemy,1,null,null,floorId); e.defDamage = this.getDefDamage(enemy, 1, null, null, floorId);
enemys.push(e); enemys.push(e);
used[enemy.id] = true; used[enemy.id] = true;
} }

View File

@ -21,10 +21,10 @@ events.prototype.initGame = function () {
////// 游戏开始事件 ////// ////// 游戏开始事件 //////
events.prototype.startGame = function (hard, seed, route, callback) { events.prototype.startGame = function (hard, seed, route, callback) {
main.dom.levelChooseButtons.style.display='none'; main.dom.levelChooseButtons.style.display = 'none';
main.dom.startButtonGroup.style.display='none'; main.dom.startButtonGroup.style.display = 'none';
if (main.mode!='play') return; if (main.mode != 'play') return;
// 无动画的开始游戏 // 无动画的开始游戏
if (core.flags.startUsingCanvas || core.isset(route)) { if (core.flags.startUsingCanvas || core.isset(route)) {
@ -84,7 +84,7 @@ events.prototype._startGame_upload = function () {
formData.append('type', 'people'); formData.append('type', 'people');
formData.append('name', core.firstData.name); formData.append('name', core.firstData.name);
formData.append('version', core.firstData.version); formData.append('version', core.firstData.version);
formData.append('platform', core.platform.isPC?"PC":core.platform.isAndroid?"Android":core.platform.isIOS?"iOS":""); formData.append('platform', core.platform.isPC ? "PC" : core.platform.isAndroid ? "Android" : core.platform.isIOS ? "iOS" : "");
formData.append('hard', core.encodeBase64(core.status.hard)); formData.append('hard', core.encodeBase64(core.status.hard));
formData.append('hardCode', core.getFlag('hard', 0)); formData.append('hardCode', core.getFlag('hard', 0));
formData.append('base64', 1); formData.append('base64', 1);
@ -141,7 +141,7 @@ events.prototype._gameOver_confirmUpload = function (ending, norank) {
return; return;
} }
core.ui.drawConfirmBox("你想记录你的ID和成绩吗", function () { core.ui.drawConfirmBox("你想记录你的ID和成绩吗", function () {
var username = main.isCompetition?"":prompt("请输入你的ID", core.getCookie('id')||""); var username = main.isCompetition ? "" : prompt("请输入你的ID", core.getCookie('id') || "");
core.events._gameOver_doUpload(username, ending, norank); core.events._gameOver_doUpload(username, ending, norank);
}, function () { }, function () {
if (main.isCompetition) if (main.isCompetition)
@ -160,9 +160,9 @@ events.prototype._gameOver_doUpload = function (username, ending, norank) {
formData.append('type', 'score'); formData.append('type', 'score');
formData.append('name', core.firstData.name); formData.append('name', core.firstData.name);
formData.append('version', core.firstData.version); formData.append('version', core.firstData.version);
formData.append('platform', core.platform.isPC?"PC":core.platform.isAndroid?"Android":core.platform.isIOS?"iOS":""); formData.append('platform', core.platform.isPC ? "PC" : core.platform.isAndroid ? "Android" : core.platform.isIOS ? "iOS" : "");
formData.append('hard', core.encodeBase64(core.status.hard)); formData.append('hard', core.encodeBase64(core.status.hard));
formData.append('username', core.encodeBase64(username||"")); formData.append('username', core.encodeBase64(username || ""));
formData.append('ending', core.encodeBase64(ending)); formData.append('ending', core.encodeBase64(ending));
formData.append('lv', core.status.hero.lv); formData.append('lv', core.status.hero.lv);
formData.append('hp', Math.min(hp, Math.pow(2, 63))); formData.append('hp', Math.min(hp, Math.pow(2, 63)));
@ -172,9 +172,9 @@ events.prototype._gameOver_doUpload = function (username, ending, norank) {
formData.append('money', core.status.hero.money); formData.append('money', core.status.hero.money);
formData.append('experience', core.status.hero.experience); formData.append('experience', core.status.hero.experience);
formData.append('steps', core.status.hero.steps); formData.append('steps', core.status.hero.steps);
formData.append('norank', norank||0); formData.append('norank', norank || 0);
formData.append('seed', core.getFlag('__seed__')); formData.append('seed', core.getFlag('__seed__'));
formData.append('totalTime', Math.floor(core.status.hero.statistics.totalTime/1000)); formData.append('totalTime', Math.floor(core.status.hero.statistics.totalTime / 1000));
formData.append('route', core.encodeRoute(core.status.route)); formData.append('route', core.encodeRoute(core.status.route));
formData.append('base64', 1); formData.append('base64', 1);
@ -183,7 +183,7 @@ events.prototype._gameOver_doUpload = function (username, ending, norank) {
else else
core.http("POST", "/games/upload.php", formData); core.http("POST", "/games/upload.php", formData);
setTimeout(function() { setTimeout(function () {
core.events._gameOver_confirmDownload(ending); core.events._gameOver_confirmDownload(ending);
}, 200); }, 200);
} }
@ -198,7 +198,7 @@ events.prototype._gameOver_confirmDownload = function (ending) {
'seed': core.getFlag('__seed__'), 'seed': core.getFlag('__seed__'),
'route': core.encodeRoute(core.status.route) 'route': core.encodeRoute(core.status.route)
} }
core.download(core.firstData.name+"_"+core.formatDate2(new Date())+".h5route", JSON.stringify(obj)); core.download(core.firstData.name + "_" + core.formatDate2(new Date()) + ".h5route", JSON.stringify(obj));
core.events._gameOver_askRate(ending); core.events._gameOver_askRate(ending);
}, function () { }, function () {
core.events._gameOver_askRate(ending); core.events._gameOver_askRate(ending);
@ -214,11 +214,11 @@ events.prototype._gameOver_askRate = function (ending) {
core.ui.closePanel(); core.ui.closePanel();
core.ui.drawConfirmBox("恭喜通关本塔,你想进行评分吗?", function () { core.ui.drawConfirmBox("恭喜通关本塔,你想进行评分吗?", function () {
if (core.platform.isPC) { if (core.platform.isPC) {
window.open("/score.php?name="+core.firstData.name+"&num=10", "_blank"); window.open("/score.php?name=" + core.firstData.name + "&num=10", "_blank");
core.restart(); core.restart();
} }
else { else {
window.location.href = "/score.php?name="+core.firstData.name+"&num=10"; window.location.href = "/score.php?name=" + core.firstData.name + "&num=10";
} }
}, function () { }, function () {
core.restart(); core.restart();
@ -241,9 +241,9 @@ events.prototype.unregisterSystemEvent = function (type) {
////// 执行一个系统事件 ////// ////// 执行一个系统事件 //////
events.prototype.doSystemEvent = function (type, data, callback) { events.prototype.doSystemEvent = function (type, data, callback) {
if (this.systemEvents[type]) this.systemEvents[type](data, callback); if (this.systemEvents[type]) this.systemEvents[type](data, callback);
else if (this["_sys_"+type]) this["_sys_"+type](data, callback); else if (this["_sys_" + type]) this["_sys_" + type](data, callback);
else { else {
main.log("未知的系统事件: "+type+""); main.log("未知的系统事件: " + type + "");
if (callback) callback(); if (callback) callback();
} }
} }
@ -263,7 +263,7 @@ events.prototype._trigger = function (x, y) {
if (trigger == 'ski') core.status.isSkiing = true; if (trigger == 'ski') core.status.isSkiing = true;
// 转换楼层能否穿透 // 转换楼层能否穿透
if (trigger=='changeFloor' && !noPass && this._trigger_ignoreChangeFloor(block)) if (trigger == 'changeFloor' && !noPass && this._trigger_ignoreChangeFloor(block))
return; return;
core.status.automaticRoute.moveDirectly = false; core.status.automaticRoute.moveDirectly = false;
this.doSystemEvent(trigger, block, function () { this.doSystemEvent(trigger, block, function () {
@ -276,17 +276,17 @@ events.prototype._trigger = function (x, y) {
events.prototype._trigger_ignoreChangeFloor = function (block) { events.prototype._trigger_ignoreChangeFloor = function (block) {
var able = core.flags.ignoreChangeFloor; var able = core.flags.ignoreChangeFloor;
if (core.isset(block.event.data) && core.isset(block.event.data.ignoreChangeFloor)) if (core.isset(block.event.data) && core.isset(block.event.data.ignoreChangeFloor))
able=block.event.data.ignoreChangeFloor; able = block.event.data.ignoreChangeFloor;
if (able) { if (able) {
if (core.isReplaying()) { if (core.isReplaying()) {
if (core.status.replay.toReplay[0]=='no') { if (core.status.replay.toReplay[0] == 'no') {
core.status.replay.toReplay.shift(); core.status.replay.toReplay.shift();
core.status.route.push("no"); core.status.route.push("no");
return true; return true;
} }
} }
else if (core.status.automaticRoute.autoHeroMove else if (core.status.automaticRoute.autoHeroMove
|| core.status.automaticRoute.autoStep<core.status.automaticRoute.autoStepRoutes.length) { || core.status.automaticRoute.autoStep < core.status.automaticRoute.autoStepRoutes.length) {
core.status.route.push("no"); core.status.route.push("no");
return true; return true;
} }
@ -323,7 +323,7 @@ events.prototype.beforeBattle = function (enemyId, x, y) {
} }
////// 战斗结束后触发的事件 ////// ////// 战斗结束后触发的事件 //////
events.prototype.afterBattle = function (enemyId, x , y,callback) { events.prototype.afterBattle = function (enemyId, x, y, callback) {
return this.eventdata.afterBattle(enemyId, x, y, callback); return this.eventdata.afterBattle(enemyId, x, y, callback);
} }
@ -353,7 +353,7 @@ events.prototype._openDoor_check = function (id, x, y, needKey) {
var key = id.replace("Door", "Key"); var key = id.replace("Door", "Key");
if (!core.hasItem(key)) { if (!core.hasItem(key)) {
if (key != "specialKey") if (key != "specialKey")
core.drawTip("你没有" + ((core.material.items[key]||{}).name||"钥匙")); core.drawTip("你没有" + ((core.material.items[key] || {}).name || "钥匙"));
else core.drawTip("无法开启此门"); else core.drawTip("无法开启此门");
core.clearContinueAutomaticRoute(); core.clearContinueAutomaticRoute();
return false; return false;
@ -388,7 +388,7 @@ events.prototype._openDoor_animate = function (id, x, y, callback) {
////// 开一个门后触发的事件 ////// ////// 开一个门后触发的事件 //////
events.prototype.afterOpenDoor = function (doorId, x, y, callback) { events.prototype.afterOpenDoor = function (doorId, x, y, callback) {
return this.eventdata.afterOpenDoor(doorId,x,y,callback); return this.eventdata.afterOpenDoor(doorId, x, y, callback);
} }
events.prototype._sys_getItem = function (data, callback) { events.prototype._sys_getItem = function (data, callback) {
@ -411,13 +411,13 @@ events.prototype.getItem = function (itemId, itemNum, itemX, itemY, callback) {
} }
////// 获得面前的物品(轻按) ////// ////// 获得面前的物品(轻按) //////
events.prototype.getNextItem = function() { events.prototype.getNextItem = function () {
if (core.isMoving() || !core.canMoveHero() || !core.flags.enableGentleClick) return false; if (core.isMoving() || !core.canMoveHero() || !core.flags.enableGentleClick) return false;
var nextX = core.nextX(), nextY = core.nextY(); var nextX = core.nextX(), nextY = core.nextY();
var block = core.getBlock(nextX, nextY); var block = core.getBlock(nextX, nextY);
if (block==null) return false; if (block == null) return false;
if (block.block.event.trigger=='getItem') { if (block.block.event.trigger == 'getItem') {
core.status.route.push("getNext"); core.status.route.push("getNext");
this.getItem(block.block.event.id, 1, nextX, nextY); this.getItem(block.block.event.id, 1, nextX, nextY);
return true; return true;
@ -432,7 +432,7 @@ events.prototype._sys_changeFloor = function (data, callback) {
heroLoc = {'x': data.loc[0], 'y': data.loc[1]}; heroLoc = {'x': data.loc[0], 'y': data.loc[1]};
if (core.isset(data.direction)) if (core.isset(data.direction))
heroLoc.direction = data.direction; heroLoc.direction = data.direction;
if (core.status.event.id!='action') core.status.event.id=null; if (core.status.event.id != 'action') core.status.event.id = null;
core.changeFloor(data.floorId, data.stair, heroLoc, data.time, callback); core.changeFloor(data.floorId, data.stair, heroLoc, data.time, callback);
} }
@ -450,7 +450,7 @@ events.prototype.changeFloor = function (floorId, stair, heroLoc, time, callback
core.lockControl(); core.lockControl();
core.stopAutomaticRoute(); core.stopAutomaticRoute();
core.clearContinueAutomaticRoute(); core.clearContinueAutomaticRoute();
core.status.replay.animate=true; core.status.replay.animate = true;
this._changeFloor_beforeChange(info, callback); this._changeFloor_beforeChange(info, callback);
} }
@ -458,24 +458,24 @@ events.prototype.changeFloor = function (floorId, stair, heroLoc, time, callback
events.prototype._changeFloor_getInfo = function (floorId, stair, heroLoc, time) { events.prototype._changeFloor_getInfo = function (floorId, stair, heroLoc, time) {
floorId = floorId || core.status.floorId; floorId = floorId || core.status.floorId;
if (floorId == ':before') { if (floorId == ':before') {
var index=core.floorIds.indexOf(core.status.floorId); var index = core.floorIds.indexOf(core.status.floorId);
if (index>0) floorId = core.floorIds[index-1]; if (index > 0) floorId = core.floorIds[index - 1];
else floorId=core.status.floorId; else floorId = core.status.floorId;
} }
else if (floorId == ':next') { else if (floorId == ':next') {
var index=core.floorIds.indexOf(core.status.floorId); var index = core.floorIds.indexOf(core.status.floorId);
if (index<core.floorIds.length-1) floorId = core.floorIds[index+1]; if (index < core.floorIds.length - 1) floorId = core.floorIds[index + 1];
else floorId=core.status.floorId; else floorId = core.status.floorId;
} }
if (!core.status.maps[floorId]) { if (!core.status.maps[floorId]) {
main.log("不存在的楼层:"+floorId); main.log("不存在的楼层:" + floorId);
return null; return null;
} }
if (main.mode != 'play' || core.isReplaying()) time = 0; if (main.mode != 'play' || core.isReplaying()) time = 0;
if (!core.isset(time)) time = core.values.floorChangeTime; if (!core.isset(time)) time = core.values.floorChangeTime;
if (!core.isset(time)) time = 800; if (!core.isset(time)) time = 800;
if (time<100) time = 0; if (time < 100) time = 0;
time /= 20; time /= 20;
return { return {
@ -538,7 +538,7 @@ events.prototype._changeFloor_changing = function (info, callback) {
events.prototype._changeFloor_afterChange = function (info, callback) { events.prototype._changeFloor_afterChange = function (info, callback) {
core.unLockControl(); core.unLockControl();
core.status.replay.animate=false; core.status.replay.animate = false;
core.events.afterChangeFloor(info.floorId, info.fromLoad); core.events.afterChangeFloor(info.floorId, info.fromLoad);
if (callback) callback(); if (callback) callback();
@ -550,7 +550,7 @@ events.prototype.changingFloor = function (floorId, heroLoc, fromLoad) {
////// 转换楼层结束的事件 ////// ////// 转换楼层结束的事件 //////
events.prototype.afterChangeFloor = function (floorId, fromLoad) { events.prototype.afterChangeFloor = function (floorId, fromLoad) {
if (main.mode!='play') return; if (main.mode != 'play') return;
return this.eventdata.afterChangeFloor(floorId, fromLoad); return this.eventdata.afterChangeFloor(floorId, fromLoad);
} }
@ -573,15 +573,15 @@ events.prototype._sys_passNet = function (data, callback) {
events.prototype.passNet = function (data) { events.prototype.passNet = function (data) {
if (core.hasItem('shoes')) return; if (core.hasItem('shoes')) return;
// 血网 lavaNet 移动到 checkBlock 中处理 // 血网 lavaNet 移动到 checkBlock 中处理
if (data.event.id=='poisonNet') { // 毒网 if (data.event.id == 'poisonNet') { // 毒网
core.setFlag('debuff', 'poison'); core.setFlag('debuff', 'poison');
core.insertAction('毒衰咒处理'); core.insertAction('毒衰咒处理');
} }
else if (data.event.id=='weakNet') { // 衰网 else if (data.event.id == 'weakNet') { // 衰网
core.setFlag('debuff', 'weak'); core.setFlag('debuff', 'weak');
core.insertAction('毒衰咒处理'); core.insertAction('毒衰咒处理');
} }
else if (data.event.id=='curseNet') { // 咒网 else if (data.event.id == 'curseNet') { // 咒网
core.setFlag('debuff', 'curse'); core.setFlag('debuff', 'curse');
core.insertAction('毒衰咒处理'); core.insertAction('毒衰咒处理');
} }
@ -595,7 +595,7 @@ events.prototype._sys_pushBox = function (data, callback) {
////// 推箱子 ////// ////// 推箱子 //////
events.prototype.pushBox = function (data) { events.prototype.pushBox = function (data) {
if (data.event.id!='box' && data.event.id!='boxed') return; if (data.event.id != 'box' && data.event.id != 'boxed') return;
// 判断还能否前进,看看是否存在事件 // 判断还能否前进,看看是否存在事件
var direction = core.getHeroLoc('direction'), var direction = core.getHeroLoc('direction'),
@ -606,9 +606,9 @@ events.prototype.pushBox = function (data) {
var nextId = core.getBlockId(nx, ny); var nextId = core.getBlockId(nx, ny);
if (nextId != null && nextId != 'flower') return; if (nextId != null && nextId != 'flower') return;
core.setBlock(nextId==null?169:170, nx, ny); core.setBlock(nextId == null ? 169 : 170, nx, ny);
if (data.event.id=='box') if (data.event.id == 'box')
core.removeBlock(data.x, data.y); core.removeBlock(data.x, data.y);
else else
core.setBlock(168, data.x, data.y); core.setBlock(168, data.x, data.y);
@ -621,7 +621,7 @@ events.prototype._pushBox_moveHero = function (direction) {
core.status.replay.animate = true; core.status.replay.animate = true;
core.lockControl(); core.lockControl();
setTimeout(function () { setTimeout(function () {
core.moveHero(direction, function() { core.moveHero(direction, function () {
core.status.replay.animate = false; core.status.replay.animate = false;
core.status.route.pop(); core.status.route.pop();
core.events.afterPushBox(); core.events.afterPushBox();
@ -645,15 +645,15 @@ events.prototype._sys_changeLight = function (data, callback) {
} }
////// 改变亮灯(感叹号)的事件 ////// ////// 改变亮灯(感叹号)的事件 //////
events.prototype.changeLight = function(id, x, y) { events.prototype.changeLight = function (id, x, y) {
if (id != null && id != 'light') return; if (id != null && id != 'light') return;
core.setBlock(core.getNumberById('darkLight'), x, y); core.setBlock(core.getNumberById('darkLight'), x, y);
this.afterChangeLight(x,y); this.afterChangeLight(x, y);
} }
////// 改变亮灯之后,可以触发的事件 ////// ////// 改变亮灯之后,可以触发的事件 //////
events.prototype.afterChangeLight = function (x,y) { events.prototype.afterChangeLight = function (x, y) {
return this.eventdata.afterChangeLight(x,y); return this.eventdata.afterChangeLight(x, y);
} }
events.prototype._sys_ski = function (data, callback) { events.prototype._sys_ski = function (data, callback) {
@ -665,16 +665,16 @@ events.prototype._sys_ski = function (data, callback) {
events.prototype.ski = function (direction) { events.prototype.ski = function (direction) {
if (!core.isset(direction)) if (!core.isset(direction))
direction = core.status.automaticRoute.lastDirection || core.getHeroLoc('direction'); direction = core.status.automaticRoute.lastDirection || core.getHeroLoc('direction');
if (core.status.event.id!='ski') { if (core.status.event.id != 'ski') {
core.waitHeroToStop(function () { core.waitHeroToStop(function () {
core.status.event.id='ski'; core.status.event.id = 'ski';
core.events.ski(direction); core.events.ski(direction);
}); });
} }
else { else {
core.moveHero(direction, function () { core.moveHero(direction, function () {
if (core.status.event.id=='ski' && !core.status.isSkiing) { if (core.status.event.id == 'ski' && !core.status.isSkiing) {
core.status.event.id=null; core.status.event.id = null;
core.unLockControl(); core.unLockControl();
core.replay(); core.replay();
} }
@ -686,11 +686,11 @@ events.prototype._sys_action = function (data, callback) {
var ev = core.clone(data.event.data), ex = data.x, ey = data.y; var ev = core.clone(data.event.data), ex = data.x, ey = data.y;
// 检查是否需要改变朝向 // 检查是否需要改变朝向
if (ex == core.nextX() && ey == core.nextY()) { if (ex == core.nextX() && ey == core.nextY()) {
var dir = {"up":"down","down":"up","left":"right","right":"left"}[core.getHeroLoc('direction')]; var dir = {"up": "down", "down": "up", "left": "right", "right": "left"}[core.getHeroLoc('direction')];
var id = data.event.id, toId = (data.event.faceIds||{})[dir]; var id = data.event.id, toId = (data.event.faceIds || {})[dir];
if (core.isset(toId) && id!=toId) { if (core.isset(toId) && id != toId) {
var number = core.icons.getNumberById(toId); var number = core.icons.getNumberById(toId);
if (number>0) if (number > 0)
core.setBlock(number, ex, ey); core.setBlock(number, ex, ey);
} }
} }
@ -715,9 +715,9 @@ events.prototype.unregisterEvent = function (type) {
events.prototype.doEvent = function (data, x, y, prefix) { events.prototype.doEvent = function (data, x, y, prefix) {
var type = data.type; var type = data.type;
if (this.actions[type]) this.actions[type](data, x, y, prefix); if (this.actions[type]) this.actions[type](data, x, y, prefix);
else if (this["_action_"+type]) this["_action_"+type](data, x, y, prefix); else if (this["_action_" + type]) this["_action_" + type](data, x, y, prefix);
else { else {
core.insertAction("未知的自定义事件: "+type+""); core.insertAction("未知的自定义事件: " + type + "");
core.doAction(); core.doAction();
} }
} }
@ -730,7 +730,7 @@ events.prototype.doEvents = function (list, x, y, callback) {
} }
this.setEvents(list, x, y, callback); this.setEvents(list, x, y, callback);
// 停止勇士 // 停止勇士
core.waitHeroToStop(function() { core.waitHeroToStop(function () {
core.lockControl(); core.lockControl();
core.doAction(); core.doAction();
}); });
@ -747,7 +747,7 @@ events.prototype.setEvents = function (list, x, y, callback) {
} }
////// 执行当前自定义事件列表中的下一个事件 ////// ////// 执行当前自定义事件列表中的下一个事件 //////
events.prototype.doAction = function() { events.prototype.doAction = function () {
// 清空boxAnimate和UI层 // 清空boxAnimate和UI层
core.status.boxAnimateObjs = []; core.status.boxAnimateObjs = [];
clearInterval(core.status.event.interval); clearInterval(core.status.event.interval);
@ -757,7 +757,7 @@ events.prototype.doAction = function() {
if (this._doAction_finishEvents()) return; if (this._doAction_finishEvents()) return;
// 当前点坐标和前缀 // 当前点坐标和前缀
var x = core.status.event.data.x, y = core.status.event.data.y; var x = core.status.event.data.x, y = core.status.event.data.y;
var prefix = [core.status.floorId||"f", core.isset(x)?x:"x", core.isset(y)?y:"y"].join("@"); var prefix = [core.status.floorId || "f", core.isset(x) ? x : "x", core.isset(y) ? y : "y"].join("@");
var current = core.status.event.data.list[0]; var current = core.status.event.data.list[0];
if (this._popEvents(current, prefix)) return; if (this._popEvents(current, prefix)) return;
// 当前要执行的事件 // 当前要执行的事件
@ -772,7 +772,7 @@ events.prototype.doAction = function() {
events.prototype._doAction_finishEvents = function () { events.prototype._doAction_finishEvents = function () {
// 事件处理完毕 // 事件处理完毕
if (core.status.event.data.list.length==0) { if (core.status.event.data.list.length == 0) {
var callback = core.status.event.data.callback; var callback = core.status.event.data.callback;
core.ui.closePanel(); core.ui.closePanel();
if (core.isset(callback)) if (core.isset(callback))
@ -851,7 +851,7 @@ events.prototype.__action_getLoc = function (loc, x, y, prefix) {
x = core.calValue(loc[0], prefix); x = core.calValue(loc[0], prefix);
y = core.calValue(loc[1], prefix); y = core.calValue(loc[1], prefix);
} }
return [x,y]; return [x, y];
} }
events.prototype.__action_getHeroLoc = function (loc, prefix) { events.prototype.__action_getHeroLoc = function (loc, prefix) {
@ -897,17 +897,17 @@ events.prototype._action_comment = function (data, x, y, prefix) {
events.prototype._action_setText = function (data, x, y, prefix) { events.prototype._action_setText = function (data, x, y, prefix) {
["position", "offset", "bold", "titlefont", "textfont", "time"].forEach(function (t) { ["position", "offset", "bold", "titlefont", "textfont", "time"].forEach(function (t) {
if (core.isset(data[t])) core.status.textAttribute[t]=data[t]; if (core.isset(data[t])) core.status.textAttribute[t] = data[t];
}); });
["background", "title", "text"].forEach(function (t) { ["background", "title", "text"].forEach(function (t) {
if (core.isset(data[t]) && (data[t] instanceof Array) && data[t].length>=3) { if (core.isset(data[t]) && (data[t] instanceof Array) && data[t].length >= 3) {
if (data[t].length==3) data[t].push(1); if (data[t].length == 3) data[t].push(1);
core.status.textAttribute[t]=data[t]; core.status.textAttribute[t] = data[t];
} }
if (t=='background' && core.isset(data[t])) { if (t == 'background' && core.isset(data[t])) {
var img = core.material.images.images[data[t]]; var img = core.material.images.images[data[t]];
if (core.isset(img) && img.width==192 && img.height==128) { if (core.isset(img) && img.width == 192 && img.height == 128) {
core.status.textAttribute[t]=data[t]; core.status.textAttribute[t] = data[t];
} }
} }
}); });
@ -922,7 +922,7 @@ events.prototype._action_tip = function (data, x, y, prefix) {
events.prototype._action_show = function (data, x, y, prefix) { events.prototype._action_show = function (data, x, y, prefix) {
data.loc = this.__action_getLoc2D(data.loc, x, y, prefix); data.loc = this.__action_getLoc2D(data.loc, x, y, prefix);
if (data.time>0 && !(data.floorId && data.floorId != core.status.floorId)) { if (data.time > 0 && !(data.floorId && data.floorId != core.status.floorId)) {
this.__action_doAsyncFunc(data.async, core.animateBlock, data.loc, 'show', data.time); this.__action_doAsyncFunc(data.async, core.animateBlock, data.loc, 'show', data.time);
} }
else { else {
@ -935,7 +935,7 @@ events.prototype._action_show = function (data, x, y, prefix) {
events.prototype._action_hide = function (data, x, y, prefix) { events.prototype._action_hide = function (data, x, y, prefix) {
data.loc = this.__action_getLoc2D(data.loc, x, y, prefix); data.loc = this.__action_getLoc2D(data.loc, x, y, prefix);
if (data.time>0 && !(data.floorId && data.floorId != core.status.floorId)) { if (data.time > 0 && !(data.floorId && data.floorId != core.status.floorId)) {
data.loc.forEach(function (t) { data.loc.forEach(function (t) {
core.hideBlock(t[0], t[1], data.floorId); core.hideBlock(t[0], t[1], data.floorId);
}); });
@ -943,7 +943,7 @@ events.prototype._action_hide = function (data, x, y, prefix) {
} }
else { else {
data.loc.forEach(function (t) { data.loc.forEach(function (t) {
core.removeBlock(t[0],t[1],data.floorId) core.removeBlock(t[0], t[1], data.floorId)
}); });
core.doAction(); core.doAction();
} }
@ -1016,7 +1016,7 @@ events.prototype._action_jumpHero = function (data, x, y, prefix) {
events.prototype._action_changeFloor = function (data, x, y, prefix) { events.prototype._action_changeFloor = function (data, x, y, prefix) {
var loc = this.__action_getHeroLoc(data.loc, prefix); var loc = this.__action_getHeroLoc(data.loc, prefix);
var heroLoc = {x: loc[0], y: loc[1], direction: data.direction}; var heroLoc = {x: loc[0], y: loc[1], direction: data.direction};
core.changeFloor(data.floorId || core.status.floorId, null, heroLoc, data.time, function() { core.changeFloor(data.floorId || core.status.floorId, null, heroLoc, data.time, function () {
core.lockControl(); core.lockControl();
core.doAction(); core.doAction();
}); });
@ -1071,7 +1071,7 @@ events.prototype._action_setFg = function (data, x, y, prefix) {
core.doAction(); core.doAction();
} }
else { else {
core.setFg(data.color, data.time, function() { core.setFg(data.color, data.time, function () {
core.setFlag('__color__', data.color || null); core.setFlag('__color__', data.color || null);
core.doAction(); core.doAction();
}); });
@ -1113,7 +1113,7 @@ events.prototype._action_useItem = function (data, x, y, prefix) {
core.useItem(data.id, true, core.doAction); core.useItem(data.id, true, core.doAction);
} }
else { else {
core.drawTip("当前无法使用"+((core.material.items[data.id]||{}).name||"未知道具")); core.drawTip("当前无法使用" + ((core.material.items[data.id] || {}).name || "未知道具"));
core.doAction(); core.doAction();
} }
} }
@ -1163,7 +1163,7 @@ events.prototype._action_insert = function (data, x, y, prefix) {
else { else {
var loc = this.__action_getLoc(data.loc, x, y, prefix); var loc = this.__action_getLoc(data.loc, x, y, prefix);
var floorId = data.floorId || core.status.floorId; var floorId = data.floorId || core.status.floorId;
var event = core.floors[floorId].events[loc[0]+","+loc[1]]; var event = core.floors[floorId].events[loc[0] + "," + loc[1]];
if (core.isset(event)) { if (core.isset(event)) {
if (core.isset(event.data)) event = event.data; if (core.isset(event.data)) event = event.data;
this.insertAction(event); this.insertAction(event);
@ -1208,7 +1208,7 @@ events.prototype._action_stopSound = function (data, x, y, prefix) {
} }
events.prototype._action_setVolume = function (data, x, y, prefix) { events.prototype._action_setVolume = function (data, x, y, prefix) {
data.value = core.clamp(parseInt(data.value)/100, 0, 1); data.value = core.clamp(parseInt(data.value) / 100, 0, 1);
core.setFlag("__volume__", data.value); core.setFlag("__volume__", data.value);
this.__action_doAsyncFunc(data.async, this.setVolume, data.value, data.time || 0); this.__action_doAsyncFunc(data.async, this.setVolume, data.value, data.time || 0);
} }
@ -1251,7 +1251,7 @@ events.prototype._action_setHeroIcon = function (data, x, y, prefix) {
events.prototype._action_input = function (data, x, y, prefix) { events.prototype._action_input = function (data, x, y, prefix) {
var value = this.__action_getInput(data.text, false); var value = this.__action_getInput(data.text, false);
if (value == null) return; if (value == null) return;
value = Math.abs(parseInt(value)||0); value = Math.abs(parseInt(value) || 0);
core.status.route.push("input:" + value); core.status.route.push("input:" + value);
core.setFlag("input", value); core.setFlag("input", value);
core.doAction(); core.doAction();
@ -1266,19 +1266,19 @@ events.prototype._action_input2 = function (data, x, y, prefix) {
} }
events.prototype.__action_getInput = function (hint, isText) { events.prototype.__action_getInput = function (hint, isText) {
var value, prefix = isText?"input2:":"input:"; var value, prefix = isText ? "input2:" : "input:";
if (core.isReplaying()) { if (core.isReplaying()) {
var action = core.status.replay.toReplay.shift(); var action = core.status.replay.toReplay.shift();
try { try {
if (action.indexOf(prefix)!=0) if (action.indexOf(prefix) != 0)
throw new Error("录像文件出错!当前需要一个 "+prefix+" 项,实际为 "+action); throw new Error("录像文件出错!当前需要一个 " + prefix + " 项,实际为 " + action);
if (isText) value = core.decodeBase64(action.substring(7)); if (isText) value = core.decodeBase64(action.substring(7));
else value = parseInt(action.substring(6)); else value = parseInt(action.substring(6));
} }
catch (e) { catch (e) {
main.log(e); main.log(e);
core.stopReplay(); core.stopReplay();
core.insertAction(["录像文件出错,请在控制台查看报错信息。", {"type":"exit"}]); core.insertAction(["录像文件出错,请在控制台查看报错信息。", {"type": "exit"}]);
core.doAction(); core.doAction();
return null; return null;
} }
@ -1286,7 +1286,7 @@ events.prototype.__action_getInput = function (hint, isText) {
else { else {
core.interval.onDownInterval = 'tmp'; core.interval.onDownInterval = 'tmp';
value = prompt(core.replaceText(hint)); value = prompt(core.replaceText(hint));
if (!core.isset(value)) value=""; if (!core.isset(value)) value = "";
} }
return value; return value;
} }
@ -1316,18 +1316,18 @@ events.prototype._action_choices = function (data, x, y, prefix) {
var action = core.status.replay.toReplay.shift(), index; var action = core.status.replay.toReplay.shift(), index;
// --- 忽略可能的turn事件 // --- 忽略可能的turn事件
if (action == 'turn') action = core.status.replay.toReplay.shift(); if (action == 'turn') action = core.status.replay.toReplay.shift();
if (action.indexOf("choices:")==0 && ((index=parseInt(action.substring(8)))>=0) && index<data.choices.length) { if (action.indexOf("choices:") == 0 && ((index = parseInt(action.substring(8))) >= 0) && index < data.choices.length) {
core.status.event.selection=index; core.status.event.selection = index;
setTimeout(function () { setTimeout(function () {
core.status.route.push("choices:"+index); core.status.route.push("choices:" + index);
core.insertAction(data.choices[index].action); core.insertAction(data.choices[index].action);
core.doAction(); core.doAction();
}, 750 / Math.max(1, core.status.replay.speed)) }, 750 / Math.max(1, core.status.replay.speed))
} }
else { else {
main.log("录像文件出错!当前需要一个 choices: 项,实际为 "+action); main.log("录像文件出错!当前需要一个 choices: 项,实际为 " + action);
core.stopReplay(); core.stopReplay();
core.insertAction(["录像文件出错,请在控制台查看报错信息。", {"type":"exit"}]); core.insertAction(["录像文件出错,请在控制台查看报错信息。", {"type": "exit"}]);
core.doAction(); core.doAction();
return; return;
} }
@ -1370,8 +1370,8 @@ events.prototype._action_lose = function (data, x, y, prefix) {
events.prototype._action_function = function (data, x, y, prefix) { events.prototype._action_function = function (data, x, y, prefix) {
var func = data["function"]; var func = data["function"];
try { try {
if (typeof func == "string" && func.indexOf("function")==0) { if (typeof func == "string" && func.indexOf("function") == 0) {
eval('('+func+')()'); eval('(' + func + ')()');
} }
} catch (e) { } catch (e) {
main.log(e); main.log(e);
@ -1406,24 +1406,24 @@ events.prototype._action_vibrate = function (data, x, y, prefix) {
} }
events.prototype._action_sleep = function (data, x, y, prefix) { events.prototype._action_sleep = function (data, x, y, prefix) {
core.timeout.sleepTimeout = setTimeout(function() { core.timeout.sleepTimeout = setTimeout(function () {
core.timeout.sleepTimeout = null; core.timeout.sleepTimeout = null;
core.doAction(); core.doAction();
}, core.isReplaying()?Math.min(data.time, 20):data.time); }, core.isReplaying() ? Math.min(data.time, 20) : data.time);
} }
events.prototype._action_wait = function (data, x, y, prefix) { events.prototype._action_wait = function (data, x, y, prefix) {
if (core.isReplaying()) { if (core.isReplaying()) {
var code = core.status.replay.toReplay.shift(); var code = core.status.replay.toReplay.shift();
if (code.indexOf("input:")==0) { if (code.indexOf("input:") == 0) {
var value = parseInt(code.substring(6)); var value = parseInt(code.substring(6));
core.status.route.push("input:"+value); core.status.route.push("input:" + value);
this.__action_wait_getValue(value); this.__action_wait_getValue(value);
} }
else { else {
main.log("录像文件出错!当前需要一个 input: 项,实际为 "+code); main.log("录像文件出错!当前需要一个 input: 项,实际为 " + code);
core.stopReplay(); core.stopReplay();
core.insertAction(["录像文件出错,请在控制台查看报错信息。", {"type":"exit"}]); core.insertAction(["录像文件出错,请在控制台查看报错信息。", {"type": "exit"}]);
} }
core.doAction(); core.doAction();
return; return;
@ -1515,7 +1515,7 @@ events.prototype._action_exit = function (data, x, y, prefix) {
events.prototype.follow = function (name) { events.prototype.follow = function (name) {
core.status.hero.followers = core.status.hero.followers || []; core.status.hero.followers = core.status.hero.followers || [];
if (core.isset(core.material.images.images[name]) if (core.isset(core.material.images.images[name])
&& core.material.images.images[name].width==128) { && core.material.images.images[name].width == 128) {
core.status.hero.followers.push({"img": name}); core.status.hero.followers.push({"img": name});
core.control.gatherFollowers(); core.control.gatherFollowers();
core.clearMap('hero'); core.clearMap('hero');
@ -1594,8 +1594,8 @@ events.prototype._setValue_setFlag = function (name, value) {
} }
events.prototype._setValue_setSwitch = function (name, value, prefix) { events.prototype._setValue_setSwitch = function (name, value, prefix) {
if (name.indexOf("switch:") !==0 ) return; if (name.indexOf("switch:") !== 0) return;
core.setFlag((prefix||"f@x@y")+"@"+data.name.substring(7), value); core.setFlag((prefix || "f@x@y") + "@" + data.name.substring(7), value);
} }
////// 数值增减 ////// ////// 数值增减 //////
@ -1613,11 +1613,11 @@ events.prototype.setFloorInfo = function (name, value, floorId, prefix) {
////// 设置全塔属性 ////// ////// 设置全塔属性 //////
events.prototype.setGlobalAttribute = function (name, value) { events.prototype.setGlobalAttribute = function (name, value) {
if (typeof value == 'string') { if (typeof value == 'string') {
if ((value.charAt(0)=='"' && value.charAt(value.length-1)=='"') if ((value.charAt(0) == '"' && value.charAt(value.length - 1) == '"')
|| (value.charAt(0)=="'" && value.charAt(value.length-1)=="'")) || (value.charAt(0) == "'" && value.charAt(value.length - 1) == "'"))
value = value.substring(1, value.length-1); value = value.substring(1, value.length - 1);
// --- 检查 [] // --- 检查 []
if (value.charAt(0) == '[' && value.charAt(value.length-1)==']') if (value.charAt(0) == '[' && value.charAt(value.length - 1) == ']')
value = eval(value); value = eval(value);
} }
core.status.globalAttribute[name] = value; core.status.globalAttribute[name] = value;
@ -1647,7 +1647,7 @@ events.prototype.showImage = function (code, image, x, y, dw, dh, opacityVal, ti
} }
var zIndex = code + 100; var zIndex = code + 100;
time = time || 0; time = time || 0;
var name = "image"+ zIndex; var name = "image" + zIndex;
var ctx = core.createCanvas(name, x, y, image.width * dw, image.height * dh, zIndex); var ctx = core.createCanvas(name, x, y, image.width * dw, image.height * dh, zIndex);
ctx.drawImage(image, 0, 0, image.width * dw, image.height * dh); ctx.drawImage(image, 0, 0, image.width * dw, image.height * dh);
if (time == 0) { if (time == 0) {
@ -1678,7 +1678,7 @@ events.prototype.hideImage = function (code, time, callback) {
events.prototype.moveImage = function (code, to, opacityVal, time, callback) { events.prototype.moveImage = function (code, to, opacityVal, time, callback) {
time = time || 1000; time = time || 1000;
to = to || []; to = to || [];
var name = "image"+ (code+100); var name = "image" + (code + 100);
if (!core.dymCanvas[name]) { if (!core.dymCanvas[name]) {
if (callback) callback(); if (callback) callback();
return; return;
@ -1699,16 +1699,16 @@ events.prototype.moveImage = function (code, to, opacityVal, time, callback) {
}, callback) }, callback)
} }
events.prototype._moveImage_moving = function(name, moveInfo, callback) { events.prototype._moveImage_moving = function (name, moveInfo, callback) {
var per_time = 10, step = 0, steps = parseInt(moveInfo.time / 10); var per_time = 10, step = 0, steps = parseInt(moveInfo.time / 10);
var fromX = moveInfo.fromX, fromY = moveInfo.fromY, toX = moveInfo.toX, toY = moveInfo.toY, var fromX = moveInfo.fromX, fromY = moveInfo.fromY, toX = moveInfo.toX, toY = moveInfo.toY,
opacity = moveInfo.opacity, toOpacity = moveInfo.toOpacity; opacity = moveInfo.opacity, toOpacity = moveInfo.toOpacity;
var currX = fromX, currY = fromY, currOpacity = opacity; var currX = fromX, currY = fromY, currOpacity = opacity;
var animate = setInterval(function () { var animate = setInterval(function () {
step++; step++;
currOpacity = opacity + (toOpacity-opacity)*step/steps; currOpacity = opacity + (toOpacity - opacity) * step / steps;
currX = parseInt(fromX + (toX-fromX)*step/steps); currX = parseInt(fromX + (toX - fromX) * step / steps);
currY = parseInt(fromY + (toY-fromY)*step/steps); currY = parseInt(fromY + (toY - fromY) * step / steps);
core.setOpacity(name, currOpacity); core.setOpacity(name, currOpacity);
core.relocateCanvas(name, currX, currY); core.relocateCanvas(name, currX, currY);
if (step == steps) { if (step == steps) {
@ -1728,7 +1728,7 @@ events.prototype.setVolume = function (value, time, callback) {
if (core.musicStatus.playingBgm) if (core.musicStatus.playingBgm)
core.material.bgms[core.musicStatus.playingBgm].volume = value; core.material.bgms[core.musicStatus.playingBgm].volume = value;
} }
if (!core.isset(time) || time<100) { if (!core.isset(time) || time < 100) {
set(value); set(value);
if (callback) callback(); if (callback) callback();
return; return;
@ -1737,8 +1737,8 @@ events.prototype.setVolume = function (value, time, callback) {
var per_time = 10, step = 0, steps = parseInt(time / per_time); var per_time = 10, step = 0, steps = parseInt(time / per_time);
var fade = setInterval(function () { var fade = setInterval(function () {
step++; step++;
set(currVolume+(value-currVolume)*step/steps); set(currVolume + (value - currVolume) * step / steps);
if (step>=steps) { if (step >= steps) {
delete core.animateFrame.asyncId[fade]; delete core.animateFrame.asyncId[fade];
clearInterval(fade); clearInterval(fade);
if (callback) callback(); if (callback) callback();
@ -1748,19 +1748,19 @@ events.prototype.setVolume = function (value, time, callback) {
} }
////// 画面震动 ////// ////// 画面震动 //////
events.prototype.vibrate = function(time, callback) { events.prototype.vibrate = function (time, callback) {
if (core.isReplaying()) { if (core.isReplaying()) {
if (callback) callback(); if (callback) callback();
return; return;
} }
if (!core.isset(time) || time<1000) time=1000; if (!core.isset(time) || time < 1000) time = 1000;
// --- 将time调整为500的倍数上整不然会出错 // --- 将time调整为500的倍数上整不然会出错
time = Math.ceil(time / 500) * 500; time = Math.ceil(time / 500) * 500;
var shakeInfo = { duration: time * 3 / 50, speed: 5, power: 5, direction: 1, shake: 0 }; var shakeInfo = {duration: time * 3 / 50, speed: 5, power: 5, direction: 1, shake: 0};
var animate=setInterval(function(){ var animate = setInterval(function () {
core.events._vibrate_update(shakeInfo); core.events._vibrate_update(shakeInfo);
core.control.addGameCanvasTranslate(shakeInfo.shake, 0); core.control.addGameCanvasTranslate(shakeInfo.shake, 0);
if(shakeInfo.duration===0) { if (shakeInfo.duration === 0) {
delete core.animateFrame.asyncId[animate]; delete core.animateFrame.asyncId[animate];
clearInterval(animate); clearInterval(animate);
if (callback) callback(); if (callback) callback();
@ -1771,33 +1771,33 @@ events.prototype.vibrate = function(time, callback) {
} }
events.prototype._vibrate_update = function (shakeInfo) { events.prototype._vibrate_update = function (shakeInfo) {
if(shakeInfo.duration >= 1 || shakeInfo.shake != 0){ if (shakeInfo.duration >= 1 || shakeInfo.shake != 0) {
var delta = (shakeInfo.power * shakeInfo.speed * shakeInfo.direction) / 10.0; var delta = (shakeInfo.power * shakeInfo.speed * shakeInfo.direction) / 10.0;
if(shakeInfo.duration <= 1 && shakeInfo.shake * (shakeInfo.shake + delta) < 0){ if (shakeInfo.duration <= 1 && shakeInfo.shake * (shakeInfo.shake + delta) < 0) {
shakeInfo.shake = 0; shakeInfo.shake = 0;
}else{ } else {
shakeInfo.shake += delta; shakeInfo.shake += delta;
} }
if(shakeInfo.shake > shakeInfo.power * 2){ if (shakeInfo.shake > shakeInfo.power * 2) {
shakeInfo.direction = -1; shakeInfo.direction = -1;
} }
if(shakeInfo.shake < - shakeInfo.power * 2){ if (shakeInfo.shake < -shakeInfo.power * 2) {
shakeInfo.direction = 1; shakeInfo.direction = 1;
} }
if(shakeInfo.duration >= 1){ if (shakeInfo.duration >= 1) {
shakeInfo.duration -= 1 shakeInfo.duration -= 1
} }
} }
} }
////// 打开一个全局商店 ////// ////// 打开一个全局商店 //////
events.prototype.openShop = function(shopId, needVisited) { events.prototype.openShop = function (shopId, needVisited) {
var shop = core.status.shops[shopId]; var shop = core.status.shops[shopId];
shop.times = shop.times || 0; shop.times = shop.times || 0;
if (shop.commonTimes) shop.times = core.getFlag('commonTimes', 0); if (shop.commonTimes) shop.times = core.getFlag('commonTimes', 0);
if (needVisited && !shop.visited) { if (needVisited && !shop.visited) {
if (!core.flags.enableDisabledShop) { if (!core.flags.enableDisabledShop) {
if (shop.times==0) core.drawTip("该商店尚未开启"); if (shop.times == 0) core.drawTip("该商店尚未开启");
else core.drawTip("该商店已失效"); else core.drawTip("该商店已失效");
return; return;
} }
@ -1817,9 +1817,9 @@ events.prototype._useShop = function (shop, index) {
return false; return false;
} }
var use = shop.use, choice = shop.choices[index]; var use = shop.use, choice = shop.choices[index];
var times = shop.times, need = core.calValue(choice.need||shop.need, null, null, times); var times = shop.times, need = core.calValue(choice.need || shop.need, null, null, times);
if (need > core.getStatus(use)) { if (need > core.getStatus(use)) {
core.drawTip("你的"+(use=='money'?"金币":"经验")+"不足"); core.drawTip("你的" + (use == 'money' ? "金币" : "经验") + "不足");
return false; return false;
} }
core.status.event.selection = index; core.status.event.selection = index;
@ -1834,8 +1834,8 @@ events.prototype._useShop = function (shop, index) {
} }
events.prototype._exitShop = function () { events.prototype._exitShop = function () {
if (core.status.event.data.actions.length>0) { if (core.status.event.data.actions.length > 0) {
core.status.route.push("shop:"+core.status.event.data.id+":"+core.status.event.data.actions.join("")); core.status.route.push("shop:" + core.status.event.data.id + ":" + core.status.event.data.actions.join(""));
} }
core.status.event.data.actions = []; core.status.event.data.actions = [];
core.status.boxAnimateObjs = []; core.status.boxAnimateObjs = [];
@ -1851,7 +1851,7 @@ events.prototype.disableQuickShop = function (shopId) {
} }
////// 能否使用快捷商店 ////// ////// 能否使用快捷商店 //////
events.prototype.canUseQuickShop = function(shopId) { events.prototype.canUseQuickShop = function (shopId) {
return this.eventdata.canUseQuickShop(shopId); return this.eventdata.canUseQuickShop(shopId);
} }
@ -1861,7 +1861,7 @@ events.prototype.setHeroIcon = function (name, noDraw) {
if (!img || img.width != 128) return; if (!img || img.width != 128) return;
core.setFlag("heroIcon", name); core.setFlag("heroIcon", name);
core.material.images.hero.onload = function () { core.material.images.hero.onload = function () {
core.material.icons.hero.height = img.height/4; core.material.icons.hero.height = img.height / 4;
core.control.updateHeroIcon(name); core.control.updateHeroIcon(name);
if (!noDraw) core.drawHero(); if (!noDraw) core.drawHero();
} }
@ -1876,35 +1876,35 @@ events.prototype.checkLvUp = function () {
if (next == null) break; if (next == null) break;
actions = actions.concat(next); actions = actions.concat(next);
} }
if (actions.length>0) core.insertAction(actions); if (actions.length > 0) core.insertAction(actions);
} }
events.prototype._checkLvUp_check = function () { events.prototype._checkLvUp_check = function () {
if (!core.flags.enableLevelUp || !core.isset(core.firstData.levelUp) if (!core.flags.enableLevelUp || !core.isset(core.firstData.levelUp)
|| core.status.hero.lv>=core.firstData.levelUp.length) return null; || core.status.hero.lv >= core.firstData.levelUp.length) return null;
// 计算下一个所需要的数值 // 计算下一个所需要的数值
var next = (core.firstData.levelUp[core.status.hero.lv]||{}); var next = (core.firstData.levelUp[core.status.hero.lv] || {});
var need = core.calValue(next.need); var need = core.calValue(next.need);
if (!core.isset(need)) return null; if (!core.isset(need)) return null;
if (core.status.hero.experience>=need) { if (core.status.hero.experience >= need) {
// 升级 // 升级
core.status.hero.lv++; core.status.hero.lv++;
if (next.clear) core.status.hero.experience -= need; if (next.clear) core.status.hero.experience -= need;
return next.action||[]; return next.action || [];
} }
return null; return null;
} }
////// 尝试使用道具 ////// ////// 尝试使用道具 //////
events.prototype.tryUseItem = function(itemId) { events.prototype.tryUseItem = function (itemId) {
core.ui.closePanel(); core.ui.closePanel();
if (itemId=='book') return core.openBook(false); if (itemId == 'book') return core.openBook(false);
if (itemId=='fly') return core.useFly(false); if (itemId == 'fly') return core.useFly(false);
if (itemId=='centerFly') return core.ui.drawCenterFly(); if (itemId == 'centerFly') return core.ui.drawCenterFly();
if (core.canUseItem(itemId))core.useItem(itemId); if (core.canUseItem(itemId)) core.useItem(itemId);
else core.drawTip("当前无法使用"+core.material.items[itemId].name); else core.drawTip("当前无法使用" + core.material.items[itemId].name);
} }
////// 使用炸弹/圣锤后的事件 ////// ////// 使用炸弹/圣锤后的事件 //////
@ -1929,9 +1929,9 @@ events.prototype.uploadCurrent = function (username) {
formData.append('type', 'score'); formData.append('type', 'score');
formData.append('name', core.firstData.name); formData.append('name', core.firstData.name);
formData.append('version', core.firstData.version); formData.append('version', core.firstData.version);
formData.append('platform', core.platform.isPC?"PC":core.platform.isAndroid?"Android":core.platform.isIOS?"iOS":""); formData.append('platform', core.platform.isPC ? "PC" : core.platform.isAndroid ? "Android" : core.platform.isIOS ? "iOS" : "");
formData.append('hard', core.encodeBase64(core.status.hard)); formData.append('hard', core.encodeBase64(core.status.hard));
formData.append('username', core.encodeBase64(username||"current")); formData.append('username', core.encodeBase64(username || "current"));
formData.append('lv', core.status.hero.lv); formData.append('lv', core.status.hero.lv);
formData.append('hp', Math.min(core.status.hero.hp, Math.pow(2, 63))); formData.append('hp', Math.min(core.status.hero.hp, Math.pow(2, 63)));
formData.append('atk', core.status.hero.atk); formData.append('atk', core.status.hero.atk);
@ -1941,7 +1941,7 @@ events.prototype.uploadCurrent = function (username) {
formData.append('experience', core.status.hero.experience); formData.append('experience', core.status.hero.experience);
formData.append('steps', core.status.hero.steps); formData.append('steps', core.status.hero.steps);
formData.append('seed', core.getFlag('__seed__')); formData.append('seed', core.getFlag('__seed__'));
formData.append('totalTime', Math.floor(core.status.hero.statistics.totalTime/1000)); formData.append('totalTime', Math.floor(core.status.hero.statistics.totalTime / 1000));
formData.append('route', core.encodeRoute(core.status.route)); formData.append('route', core.encodeRoute(core.status.route));
formData.append('deler', 'current'); formData.append('deler', 'current');
formData.append('base64', 1); formData.append('base64', 1);

View File

@ -26,14 +26,14 @@ icons.prototype.getClsFromId = function (id) {
} }
icons.prototype._getAnimateFrames = function (cls, useOriginValue) { icons.prototype._getAnimateFrames = function (cls, useOriginValue) {
if (cls=='enemys' || cls=='npcs') { if (cls == 'enemys' || cls == 'npcs') {
return 2; return 2;
} }
if (cls == 'animates' || cls == 'enemy48') { if (cls == 'animates' || cls == 'enemy48') {
return 4; return 4;
} }
if (cls == 'npc48') { if (cls == 'npc48') {
return useOriginValue? 4 : 1; return useOriginValue ? 4 : 1;
} }
return 1; return 1;
} }
@ -55,9 +55,9 @@ icons.prototype.getTilesetOffset = function (id) {
for (var i in core.tilesets) { for (var i in core.tilesets) {
var imgName = core.tilesets[i]; var imgName = core.tilesets[i];
var img = core.material.images.tilesets[imgName]; var img = core.material.images.tilesets[imgName];
var width = Math.floor(img.width/32), height = Math.floor(img.height/32); var width = Math.floor(img.width / 32), height = Math.floor(img.height / 32);
if (id>=startOffset && id<startOffset+width*height) { if (id >= startOffset && id < startOffset + width * height) {
var x = (id-startOffset)%width, y = parseInt((id-startOffset)/width); var x = (id - startOffset) % width, y = parseInt((id - startOffset) / width);
return {"image": imgName, "x": x, "y": y}; return {"image": imgName, "x": x, "y": y};
} }
startOffset += this.tilesetStartOffset; startOffset += this.tilesetStartOffset;

View File

@ -22,7 +22,7 @@ items.prototype.getItems = function () {
} }
////// “即捡即用类”道具的使用效果 ////// ////// “即捡即用类”道具的使用效果 //////
items.prototype.getItemEffect = function(itemId, itemNum) { items.prototype.getItemEffect = function (itemId, itemNum) {
var itemCls = core.material.items[itemId].cls; var itemCls = core.material.items[itemId].cls;
// 消耗品 // 消耗品
if (itemCls === 'items') { if (itemCls === 'items') {
@ -44,14 +44,14 @@ items.prototype.getItemEffect = function(itemId, itemNum) {
} }
////// “即捡即用类”道具的文字提示 ////// ////// “即捡即用类”道具的文字提示 //////
items.prototype.getItemEffectTip = function(itemId) { items.prototype.getItemEffectTip = function (itemId) {
var itemCls = core.material.items[itemId].cls; var itemCls = core.material.items[itemId].cls;
// 消耗品 // 消耗品
if (itemCls === 'items') { if (itemCls === 'items') {
var ratio = parseInt(core.status.thisMap.item_ratio) || 1; var ratio = parseInt(core.status.thisMap.item_ratio) || 1;
if (itemId in this.itemEffectTip) { if (itemId in this.itemEffectTip) {
try { try {
return eval(this.itemEffectTip[itemId])||""; return eval(this.itemEffectTip[itemId]) || "";
} catch (e) { } catch (e) {
main.log(e); main.log(e);
return ""; return "";
@ -72,7 +72,7 @@ items.prototype.useItem = function (itemId, noRoute, callback) {
// 执行完毕 // 执行完毕
this._afterUseItem(itemId); this._afterUseItem(itemId);
// 记录路线 // 记录路线
if (!noRoute) core.status.route.push("item:"+itemId); if (!noRoute) core.status.route.push("item:" + itemId);
if (core.isset(callback)) callback(); if (core.isset(callback)) callback();
} }
@ -91,9 +91,9 @@ items.prototype._useItemEffect = function (itemId) {
items.prototype._afterUseItem = function (itemId) { items.prototype._afterUseItem = function (itemId) {
// 道具使用完毕:删除 // 道具使用完毕:删除
var itemCls = core.material.items[itemId].cls; var itemCls = core.material.items[itemId].cls;
if (itemCls=='tools') if (itemCls == 'tools')
core.status.hero.items[itemCls][itemId]--; core.status.hero.items[itemCls][itemId]--;
if (core.status.hero.items[itemCls][itemId]<=0) if (core.status.hero.items[itemCls][itemId] <= 0)
delete core.status.hero.items[itemCls][itemId]; delete core.status.hero.items[itemCls][itemId];
if (!core.status.event.id) { if (!core.status.event.id) {
@ -130,8 +130,8 @@ items.prototype.itemCount = function (itemId) {
if (!core.isset(core.status.hero)) return 0; if (!core.isset(core.status.hero)) return 0;
if (!core.isset(itemId) || !core.isset(core.material.items[itemId])) return 0; if (!core.isset(itemId) || !core.isset(core.material.items[itemId])) return 0;
var itemCls = core.material.items[itemId].cls; var itemCls = core.material.items[itemId].cls;
if (itemCls=="items") return 0; if (itemCls == "items") return 0;
return core.status.hero.items[itemCls][itemId]||0; return core.status.hero.items[itemCls][itemId] || 0;
} }
////// 是否存在某个物品 ////// ////// 是否存在某个物品 //////
@ -144,9 +144,9 @@ items.prototype.hasEquip = function (itemId) {
if (!core.isset(core.status.hero)) return null; if (!core.isset(core.status.hero)) return null;
if (!core.isset(itemId)) return null; if (!core.isset(itemId)) return null;
if (!core.isset((core.material.items[itemId]||{}).equip)) return null; if (!core.isset((core.material.items[itemId] || {}).equip)) return null;
for (var i in core.status.hero.equipment||[]) for (var i in core.status.hero.equipment || [])
if (core.status.hero.equipment[i] == itemId) if (core.status.hero.equipment[i] == itemId)
return true; return true;
return false return false
@ -155,7 +155,7 @@ items.prototype.hasEquip = function (itemId) {
////// 获得某个装备类型的当前装备 ////// ////// 获得某个装备类型的当前装备 //////
items.prototype.getEquip = function (equipType) { items.prototype.getEquip = function (equipType) {
if (!core.isset(core.status.hero)) return null; if (!core.isset(core.status.hero)) return null;
return (core.status.hero.equipment||[])[equipType]||null; return (core.status.hero.equipment || [])[equipType] || null;
} }
////// 设置某个物品的个数 ////// ////// 设置某个物品的个数 //////
@ -169,7 +169,7 @@ items.prototype.setItem = function (itemId, itemNum) {
} }
core.status.hero.items[itemCls][itemId] = itemNum; core.status.hero.items[itemCls][itemId] = itemNum;
if (core.status.hero.items[itemCls][itemId] <= 0) { if (core.status.hero.items[itemCls][itemId] <= 0) {
if (itemCls!='keys') delete core.status.hero.items[itemCls][itemId]; if (itemCls != 'keys') delete core.status.hero.items[itemCls][itemId];
else core.status.hero.items[itemCls][itemId] = 0; else core.status.hero.items[itemCls][itemId] = 0;
} }
core.updateStatusBar(); core.updateStatusBar();
@ -181,9 +181,9 @@ items.prototype.removeItem = function (itemId, itemNum) {
if (!core.isset(itemNum)) itemNum = 1; if (!core.isset(itemNum)) itemNum = 1;
if (!core.hasItem(itemId)) return false; if (!core.hasItem(itemId)) return false;
var itemCls = core.material.items[itemId].cls; var itemCls = core.material.items[itemId].cls;
core.status.hero.items[itemCls][itemId]-=itemNum; core.status.hero.items[itemCls][itemId] -= itemNum;
if (core.status.hero.items[itemCls][itemId] <= 0) { if (core.status.hero.items[itemCls][itemId] <= 0) {
if (itemCls!='keys') delete core.status.hero.items[itemCls][itemId]; if (itemCls != 'keys') delete core.status.hero.items[itemCls][itemId];
else core.status.hero.items[itemCls][itemId] = 0; else core.status.hero.items[itemCls][itemId] = 0;
} }
core.updateStatusBar(); core.updateStatusBar();
@ -206,11 +206,11 @@ items.prototype.addItem = function (itemId, itemNum) {
} }
core.status.hero.items[itemCls][itemId] += itemNum; core.status.hero.items[itemCls][itemId] += itemNum;
if (core.status.hero.items[itemCls][itemId] <= 0) { if (core.status.hero.items[itemCls][itemId] <= 0) {
if (itemCls!='keys') delete core.status.hero.items[itemCls][itemId]; if (itemCls != 'keys') delete core.status.hero.items[itemCls][itemId];
else core.status.hero.items[itemCls][itemId] = 0; else core.status.hero.items[itemCls][itemId] = 0;
} }
// 永久道具只能有一个 // 永久道具只能有一个
if (itemCls == 'constants' && core.status.hero.items[itemCls][itemId]>1) if (itemCls == 'constants' && core.status.hero.items[itemCls][itemId] > 1)
core.status.hero.items[itemCls][itemId] = 1; core.status.hero.items[itemCls][itemId] = 1;
core.updateStatusBar(); core.updateStatusBar();
} }
@ -227,7 +227,7 @@ items.prototype.getEquipTypeById = function (equipId) {
items.prototype.getEquipTypeByName = function (name) { items.prototype.getEquipTypeByName = function (name) {
var names = core.status.globalAttribute.equipName; var names = core.status.globalAttribute.equipName;
for (var i = 0; i < names.length; ++i) { for (var i = 0; i < names.length; ++i) {
if (names[i] === name && !core.isset((core.status.hero.equipment||[])[i])) { if (names[i] === name && !core.isset((core.status.hero.equipment || [])[i])) {
return i; return i;
} }
} }
@ -237,7 +237,7 @@ items.prototype.getEquipTypeByName = function (name) {
// 当前能否撞上某装备 // 当前能否撞上某装备
items.prototype.canEquip = function (equipId, hint) { items.prototype.canEquip = function (equipId, hint) {
// 装备是否合法 // 装备是否合法
var equip = core.material.items[equipId]||{}; var equip = core.material.items[equipId] || {};
if (!core.isset(equip.equip)) { if (!core.isset(equip.equip)) {
if (hint) core.drawTip("不合法的装备!"); if (hint) core.drawTip("不合法的装备!");
return false; return false;
@ -245,16 +245,16 @@ items.prototype.canEquip = function (equipId, hint) {
// 是否拥有该装备 // 是否拥有该装备
if (!core.hasItem(equipId) && !core.hasEquip(equipId)) { if (!core.hasItem(equipId) && !core.hasEquip(equipId)) {
if (hint) core.drawTip("你当前没有"+equip.name+",无法换装"); if (hint) core.drawTip("你当前没有" + equip.name + ",无法换装");
return false; return false;
} }
// 可装备条件 // 可装备条件
var condition = this.equipCondition[equipId]; var condition = this.equipCondition[equipId];
if (core.isset(condition) && condition.length>0) { if (core.isset(condition) && condition.length > 0) {
try { try {
if (!eval(condition)) { if (!eval(condition)) {
if (hint) core.drawTip("当前不可换上"+equip.name); if (hint) core.drawTip("当前不可换上" + equip.name);
return false; return false;
} }
} }
@ -278,7 +278,7 @@ items.prototype.loadEquip = function (equipId, callback) {
var loadEquip = core.material.items[equipId] || {}; var loadEquip = core.material.items[equipId] || {};
var type = this.getEquipTypeById(equipId); var type = this.getEquipTypeById(equipId);
if (type < 0) { if (type < 0) {
core.drawTip("当前没有"+loadEquip.equip.type+"的空位!"); core.drawTip("当前没有" + loadEquip.equip.type + "的空位!");
if (core.isset(callback)) callback(); if (core.isset(callback)) callback();
return; return;
} }
@ -304,17 +304,17 @@ items.prototype.compareEquipment = function (compareEquipId, beComparedEquipId)
var compareAtk = 0, compareDef = 0, compareMdef = 0; var compareAtk = 0, compareDef = 0, compareMdef = 0;
if (core.isset(compareEquipId)) { if (core.isset(compareEquipId)) {
var compareEquip = core.material.items[compareEquipId]; var compareEquip = core.material.items[compareEquipId];
compareAtk += (compareEquip.equip||{}).atk || 0; compareAtk += (compareEquip.equip || {}).atk || 0;
compareDef += (compareEquip.equip||{}).def || 0; compareDef += (compareEquip.equip || {}).def || 0;
compareMdef += (compareEquip.equip||{}).mdef || 0; compareMdef += (compareEquip.equip || {}).mdef || 0;
} }
if (core.isset(beComparedEquipId)) { if (core.isset(beComparedEquipId)) {
var beComparedEquip = core.material.items[beComparedEquipId]; var beComparedEquip = core.material.items[beComparedEquipId];
compareAtk -= (beComparedEquip.equip||{}).atk || 0; compareAtk -= (beComparedEquip.equip || {}).atk || 0;
compareDef -= (beComparedEquip.equip||{}).def || 0; compareDef -= (beComparedEquip.equip || {}).def || 0;
compareMdef -= (beComparedEquip.equip||{}).mdef || 0; compareMdef -= (beComparedEquip.equip || {}).mdef || 0;
} }
return {"atk":compareAtk,"def":compareDef,"mdef":compareMdef}; return {"atk": compareAtk, "def": compareDef, "mdef": compareMdef};
} }
////// 实际换装的效果 ////// ////// 实际换装的效果 //////
@ -324,7 +324,7 @@ items.prototype._loadEquipEffect = function (equipId, unloadEquipId, isPercentag
if (isPercentage) { if (isPercentage) {
for (var v in result) for (var v in result)
core.addFlag('__'+v+'_buff__', result[v]/100); core.addFlag('__' + v + '_buff__', result[v] / 100);
} }
else { else {
for (var v in result) for (var v in result)
@ -350,16 +350,16 @@ items.prototype._realLoadEquip = function (type, loadId, unloadId, callback) {
core.playSound('equip.mp3'); core.playSound('equip.mp3');
// --- 实际换装 // --- 实际换装
this._loadEquipEffect(loadId, unloadId, loadPercentage==null?unloadPercentage:loadPercentage); this._loadEquipEffect(loadId, unloadId, loadPercentage == null ? unloadPercentage : loadPercentage);
// --- 加减 // --- 加减
if (loadId) core.removeItem(loadId); if (loadId) core.removeItem(loadId);
if (unloadId) core.addItem(unloadId); if (unloadId) core.addItem(unloadId);
core.status.hero.equipment[type] = loadId||null; core.status.hero.equipment[type] = loadId || null;
// --- 提示 // --- 提示
if (loadId) core.drawTip("已装备上"+loadEquip.name, core.material.icons.items[loadId]); if (loadId) core.drawTip("已装备上" + loadEquip.name, core.material.icons.items[loadId]);
else if (unloadId) core.drawTip("已卸下"+unloadEquip.name, core.material.icons.items[unloadId]); else if (unloadId) core.drawTip("已卸下" + unloadEquip.name, core.material.icons.items[unloadId]);
if (core.isset(callback)) callback(); if (core.isset(callback)) callback();
} }
@ -370,38 +370,38 @@ items.prototype.quickSaveEquip = function (index) {
var saveEquips = core.getFlag("saveEquips", []); var saveEquips = core.getFlag("saveEquips", []);
saveEquips[index] = core.clone(core.status.hero.equipment); saveEquips[index] = core.clone(core.status.hero.equipment);
core.setFlag("saveEquips", saveEquips); core.setFlag("saveEquips", saveEquips);
core.drawTip("已保存"+index+"号套装"); core.drawTip("已保存" + index + "号套装");
} }
////// 读取装备 ////// ////// 读取装备 //////
items.prototype.quickLoadEquip = function (index) { items.prototype.quickLoadEquip = function (index) {
var current = core.getFlag("saveEquips", [])[index]; var current = core.getFlag("saveEquips", [])[index];
if (!core.isset(current)) { if (!core.isset(current)) {
core.drawTip(index+"号套装不存在"); core.drawTip(index + "号套装不存在");
return; return;
} }
// 检查所有的装备 // 检查所有的装备
var equipSize = core.status.globalAttribute.equipName.length; var equipSize = core.status.globalAttribute.equipName.length;
for (var i=0;i<equipSize;i++) { for (var i = 0; i < equipSize; i++) {
var v = current[i]; var v = current[i];
if (core.isset(v) && !this.canEquip(v, true)) if (core.isset(v) && !this.canEquip(v, true))
return; return;
} }
// 快速换装 // 快速换装
if (!core.isset(core.status.hero.equipment)) core.status.hero.equipment = []; if (!core.isset(core.status.hero.equipment)) core.status.hero.equipment = [];
for (var i=0;i<equipSize;i++) { for (var i = 0; i < equipSize; i++) {
var now = core.status.hero.equipment[i] || null; var now = core.status.hero.equipment[i] || null;
if (now != null) { if (now != null) {
this.unloadEquip(i); this.unloadEquip(i);
core.status.route.push("unEquip:" + i); core.status.route.push("unEquip:" + i);
} }
} }
for (var i=0;i<equipSize;i++) { for (var i = 0; i < equipSize; i++) {
var to = current[i]||null; var to = current[i] || null;
if (to!=null) { if (to != null) {
this.loadEquip(to); this.loadEquip(to);
core.status.route.push("equip:"+to); core.status.route.push("equip:" + to);
} }
} }
core.drawTip("成功换上"+index+"号套装"); core.drawTip("成功换上" + index + "号套装");
} }

View File

@ -57,7 +57,7 @@ loader.prototype._loadExtraImages = function (callback) {
core.material.images.images = {}; core.material.images.images = {};
var images = core.clone(core.images); var images = core.clone(core.images);
if (images.indexOf("hero.png")<0) if (images.indexOf("hero.png") < 0)
images.push("hero.png"); images.push("hero.png");
this.loadImages(images, core.material.images.images, callback); this.loadImages(images, core.material.images.images, callback);
@ -87,11 +87,11 @@ loader.prototype._loadTilesets = function (callback) {
// 检查宽高是32倍数如果出错在控制台报错 // 检查宽高是32倍数如果出错在控制台报错
for (var imgName in core.material.images.tilesets) { for (var imgName in core.material.images.tilesets) {
var img = core.material.images.tilesets[imgName]; var img = core.material.images.tilesets[imgName];
if (img.width%32!=0 || img.height%32!=0) { if (img.width % 32 != 0 || img.height % 32 != 0) {
console.warn("警告!"+imgName+"的宽或高不是32的倍数"); console.warn("警告!" + imgName + "的宽或高不是32的倍数");
} }
if (img.width * img.height > 32*32*3000) { if (img.width * img.height > 32 * 32 * 3000) {
console.warn("警告!"+imgName+"上的图块素材个数大于3000"); console.warn("警告!" + imgName + "上的图块素材个数大于3000");
} }
} }
callback(); callback();
@ -99,12 +99,12 @@ loader.prototype._loadTilesets = function (callback) {
} }
loader.prototype.loadImages = function (names, toSave, callback) { loader.prototype.loadImages = function (names, toSave, callback) {
if (!core.isset(names) || names.length==0) { if (!core.isset(names) || names.length == 0) {
if (core.isset(callback)) callback(); if (core.isset(callback)) callback();
return; return;
} }
var items = 0; var items = 0;
for (var i=0;i<names.length;i++) { for (var i = 0; i < names.length; i++) {
this.loadImage(names[i], function (id, image) { this.loadImage(names[i], function (id, image) {
core.loader._setStartLoadTipText('正在加载图片 ' + id + "..."); core.loader._setStartLoadTipText('正在加载图片 ' + id + "...");
toSave[id] = image; toSave[id] = image;
@ -119,9 +119,9 @@ loader.prototype.loadImages = function (names, toSave, callback) {
loader.prototype.loadImage = function (imgName, callback) { loader.prototype.loadImage = function (imgName, callback) {
try { try {
var name=imgName; var name = imgName;
if (name.indexOf(".")<0) if (name.indexOf(".") < 0)
name=name+".png"; name = name + ".png";
var image = new Image(); var image = new Image();
image.onload = function () { image.onload = function () {
callback(imgName, image); callback(imgName, image);
@ -204,15 +204,15 @@ loader.prototype._loadMusic = function () {
loader.prototype.loadOneMusic = function (name) { loader.prototype.loadOneMusic = function (name) {
var music = new Audio(); var music = new Audio();
music.preload = 'none'; music.preload = 'none';
if (main.bgmRemote) music.src = main.bgmRemoteRoot+core.firstData.name+'/'+name; if (main.bgmRemote) music.src = main.bgmRemoteRoot + core.firstData.name + '/' + name;
else music.src = 'project/sounds/'+name; else music.src = 'project/sounds/' + name;
music.loop = 'loop'; music.loop = 'loop';
core.material.bgms[name] = music; core.material.bgms[name] = music;
} }
loader.prototype.loadOneSound = function (name) { loader.prototype.loadOneSound = function (name) {
if (core.musicStatus.audioContext != null) { if (core.musicStatus.audioContext != null) {
core.http('GET', 'project/sounds/'+name, null, function (data) { core.http('GET', 'project/sounds/' + name, null, function (data) {
try { try {
core.musicStatus.audioContext.decodeAudioData(data, function (buffer) { core.musicStatus.audioContext.decodeAudioData(data, function (buffer) {
core.material.sounds[name] = buffer; core.material.sounds[name] = buffer;
@ -232,7 +232,7 @@ loader.prototype.loadOneSound = function (name) {
} }
else { else {
var music = new Audio(); var music = new Audio();
music.src = 'project/sounds/'+name; music.src = 'project/sounds/' + name;
core.material.sounds[name] = music; core.material.sounds[name] = music;
} }
} }
@ -243,7 +243,7 @@ loader.prototype.loadBgm = function (name) {
if (!core.musicStatus.bgmStatus) return; if (!core.musicStatus.bgmStatus) return;
// 是否已经预加载过 // 是否已经预加载过
var index = core.musicStatus.cachedBgms.indexOf(name); var index = core.musicStatus.cachedBgms.indexOf(name);
if (index>=0) { if (index >= 0) {
core.musicStatus.cachedBgms.splice(index, 1); core.musicStatus.cachedBgms.splice(index, 1);
} }
else { else {
@ -267,7 +267,9 @@ loader.prototype._preloadBgm = function (bgm) {
loader.prototype.freeBgm = function (name) { loader.prototype.freeBgm = function (name) {
if (!core.isset(core.material.bgms[name])) return; if (!core.isset(core.material.bgms[name])) return;
// 从cachedBgms中删除 // 从cachedBgms中删除
core.musicStatus.cachedBgms = core.musicStatus.cachedBgms.filter(function (t) {return t!=name; }); core.musicStatus.cachedBgms = core.musicStatus.cachedBgms.filter(function (t) {
return t != name;
});
// 清掉缓存 // 清掉缓存
core.material.bgms[name].removeAttribute("src"); core.material.bgms[name].removeAttribute("src");
core.material.bgms[name].load(); core.material.bgms[name].load();

View File

@ -18,7 +18,7 @@ function utils() {
utils.prototype._init = function () { utils.prototype._init = function () {
// 定义Object.assign // 定义Object.assign
if (typeof Object.assign != "function") { if (typeof Object.assign != "function") {
Object.assign = function(target, varArgs) { // .length of function is 2 Object.assign = function (target, varArgs) { // .length of function is 2
if (target == null) { // TypeError if undefined or null if (target == null) { // TypeError if undefined or null
throw new TypeError('Cannot convert undefined or null to object'); throw new TypeError('Cannot convert undefined or null to object');
} }
@ -41,7 +41,7 @@ utils.prototype._init = function () {
}; };
} }
if (typeof String.prototype.endsWith != "function") { if (typeof String.prototype.endsWith != "function") {
String.prototype.endsWith = function(search, this_len) { String.prototype.endsWith = function (search, this_len) {
if (this_len === undefined || this_len > this.length) { if (this_len === undefined || this_len > this.length) {
this_len = this.length; this_len = this.length;
} }
@ -63,10 +63,10 @@ utils.prototype.replaceText = function (text, need, times) {
utils.prototype.calValue = function (value, prefix, need, times) { utils.prototype.calValue = function (value, prefix, need, times) {
if (!core.isset(value)) return value; if (!core.isset(value)) return value;
if (typeof value === 'string') { if (typeof value === 'string') {
value=value.replace(/status:([\w\d_]+)/g, "core.getStatus('$1')"); value = value.replace(/status:([\w\d_]+)/g, "core.getStatus('$1')");
value=value.replace(/item:([\w\d_]+)/g, "core.itemCount('$1')"); value = value.replace(/item:([\w\d_]+)/g, "core.itemCount('$1')");
value=value.replace(/flag:([\w\d_]+)/g, "core.getFlag('$1', 0)"); value = value.replace(/flag:([\w\d_]+)/g, "core.getFlag('$1', 0)");
value=value.replace(/switch:([\w\d_]+)/g, "core.getFlag('"+(prefix||"global")+"@$1', 0)"); value = value.replace(/switch:([\w\d_]+)/g, "core.getFlag('" + (prefix || "global") + "@$1', 0)");
return eval(value); return eval(value);
} }
if (value instanceof Function) { if (value instanceof Function) {
@ -76,27 +76,27 @@ utils.prototype.calValue = function (value, prefix, need, times) {
} }
////// 字符串自动换行的分割 ////// ////// 字符串自动换行的分割 //////
utils.prototype.splitLines = function(canvas, text, maxLength, font) { utils.prototype.splitLines = function (canvas, text, maxLength, font) {
if (core.isset(font)) core.setFont(canvas, font); if (core.isset(font)) core.setFont(canvas, font);
var contents = []; var contents = [];
var last = 0; var last = 0;
for (var i=0;i<text.length;i++) { for (var i = 0; i < text.length; i++) {
if (text.charAt(i)=='\n') { if (text.charAt(i) == '\n') {
contents.push(text.substring(last, i)); contents.push(text.substring(last, i));
last=i+1; last = i + 1;
} }
else if (text.charAt(i)=='\\' && text.charAt(i+1)=='n') { else if (text.charAt(i) == '\\' && text.charAt(i + 1) == 'n') {
contents.push(text.substring(last, i)); contents.push(text.substring(last, i));
last=i+2; last = i + 2;
} }
else { else {
var toAdd = text.substring(last, i+1); var toAdd = text.substring(last, i + 1);
var width = core.calWidth(canvas, toAdd); var width = core.calWidth(canvas, toAdd);
if (core.isset(maxLength) && width>maxLength) { if (core.isset(maxLength) && width > maxLength) {
contents.push(text.substring(last, i)); contents.push(text.substring(last, i));
last=i; last = i;
} }
} }
} }
@ -105,7 +105,7 @@ utils.prototype.splitLines = function(canvas, text, maxLength, font) {
} }
////// 向某个数组前插入另一个数组或元素 ////// ////// 向某个数组前插入另一个数组或元素 //////
utils.prototype.unshift = function (a,b) { utils.prototype.unshift = function (a, b) {
if (!(a instanceof Array) || !core.isset(b)) return; if (!(a instanceof Array) || !core.isset(b)) return;
if (b instanceof Array) { if (b instanceof Array) {
core.clone(b).reverse().forEach(function (e) { core.clone(b).reverse().forEach(function (e) {
@ -117,7 +117,7 @@ utils.prototype.unshift = function (a,b) {
} }
////// 向某个数组后插入另一个数组或元素 ////// ////// 向某个数组后插入另一个数组或元素 //////
utils.prototype.push = function (a,b) { utils.prototype.push = function (a, b) {
if (!(a instanceof Array) || !core.isset(b)) return; if (!(a instanceof Array) || !core.isset(b)) return;
if (b instanceof Array) { if (b instanceof Array) {
core.clone(b).forEach(function (e) { core.clone(b).forEach(function (e) {
@ -129,21 +129,21 @@ utils.prototype.push = function (a,b) {
} }
////// 设置本地存储 ////// ////// 设置本地存储 //////
utils.prototype.setLocalStorage = function(key, value) { utils.prototype.setLocalStorage = function (key, value) {
try { try {
if (!core.isset(value)) { if (!core.isset(value)) {
this.removeLocalStorage(key); this.removeLocalStorage(key);
return; return;
} }
var str = JSON.stringify(value).replace(/[\u007F-\uFFFF]/g, function(chr) { var str = JSON.stringify(value).replace(/[\u007F-\uFFFF]/g, function (chr) {
return "\\u" + ("0000" + chr.charCodeAt(0).toString(16)).substr(-4) return "\\u" + ("0000" + chr.charCodeAt(0).toString(16)).substr(-4)
}); });
var compressed = lzw_encode(str); var compressed = lzw_encode(str);
// test if we can save to localStorage // test if we can save to localStorage
localStorage.setItem("__tmp__", compressed); localStorage.setItem("__tmp__", compressed);
if (lzw_decode(localStorage.getItem("__tmp__"))==str) { if (lzw_decode(localStorage.getItem("__tmp__")) == str) {
localStorage.setItem(core.firstData.name + "_" + key, compressed); localStorage.setItem(core.firstData.name + "_" + key, compressed);
} }
else { else {
@ -169,29 +169,33 @@ utils.prototype.decompress = function (value) {
if (core.isset(output) && output.length > 0) if (core.isset(output) && output.length > 0)
return JSON.parse(output); return JSON.parse(output);
} }
catch (e) {} catch (e) {
}
try { try {
var output = LZString.decompress(value); var output = LZString.decompress(value);
if (core.isset(output) && output.length > 0) if (core.isset(output) && output.length > 0)
return JSON.parse(output); return JSON.parse(output);
} }
catch (e) {} catch (e) {
}
try { try {
return JSON.parse(value); return JSON.parse(value);
} }
catch (e) {main.log(e);} catch (e) {
main.log(e);
}
return null; return null;
} }
////// 获得本地存储 ////// ////// 获得本地存储 //////
utils.prototype.getLocalStorage = function(key, defaultValue) { utils.prototype.getLocalStorage = function (key, defaultValue) {
var res = this.decompress(localStorage.getItem(core.firstData.name+"_"+key)); var res = this.decompress(localStorage.getItem(core.firstData.name + "_" + key));
return res==null?defaultValue:res; return res == null ? defaultValue : res;
} }
////// 移除本地存储 ////// ////// 移除本地存储 //////
utils.prototype.removeLocalStorage = function (key) { utils.prototype.removeLocalStorage = function (key) {
localStorage.removeItem(core.firstData.name+"_"+key); localStorage.removeItem(core.firstData.name + "_" + key);
if (key == 'autoSave') delete core.saves.ids[0]; if (key == 'autoSave') delete core.saves.ids[0];
else if (/^save\d+$/.test(key)) delete core.saves.ids[parseInt(key.substring(4))]; else if (/^save\d+$/.test(key)) delete core.saves.ids[parseInt(key.substring(4))];
} }
@ -214,10 +218,10 @@ utils.prototype.setLocalForage = function (key, value, successCallback, errorCal
} }
// Save to localforage // Save to localforage
var compressed = lzw_encode(JSON.stringify(value).replace(/[\u007F-\uFFFF]/g, function(chr) { var compressed = lzw_encode(JSON.stringify(value).replace(/[\u007F-\uFFFF]/g, function (chr) {
return "\\u" + ("0000" + chr.charCodeAt(0).toString(16)).substr(-4) return "\\u" + ("0000" + chr.charCodeAt(0).toString(16)).substr(-4)
})); }));
localforage.setItem(core.firstData.name+"_"+key, compressed, function (err) { localforage.setItem(core.firstData.name + "_" + key, compressed, function (err) {
if (core.isset(err)) { if (core.isset(err)) {
if (core.isset(errorCallback)) errorCallback(err); if (core.isset(errorCallback)) errorCallback(err);
} }
@ -232,14 +236,14 @@ utils.prototype.setLocalForage = function (key, value, successCallback, errorCal
utils.prototype.getLocalForage = function (key, defaultValue, successCallback, errorCallback) { utils.prototype.getLocalForage = function (key, defaultValue, successCallback, errorCallback) {
if (!core.platform.useLocalForage) { if (!core.platform.useLocalForage) {
var value=this.getLocalStorage(key, defaultValue); var value = this.getLocalStorage(key, defaultValue);
if (core.isset(successCallback)) { if (core.isset(successCallback)) {
successCallback(value); successCallback(value);
} }
return; return;
} }
localforage.getItem(core.firstData.name+"_"+key, function (err, value) { localforage.getItem(core.firstData.name + "_" + key, function (err, value) {
if (core.isset(err)) { if (core.isset(err)) {
if (core.isset(errorCallback)) errorCallback(err); if (core.isset(errorCallback)) errorCallback(err);
} }
@ -247,7 +251,7 @@ utils.prototype.getLocalForage = function (key, defaultValue, successCallback, e
if (!core.isset(successCallback)) return; if (!core.isset(successCallback)) return;
if (core.isset(value)) { if (core.isset(value)) {
var res = core.utils.decompress(value); var res = core.utils.decompress(value);
successCallback(res==null?defaultValue:res); successCallback(res == null ? defaultValue : res);
return; return;
} }
successCallback(defaultValue); successCallback(defaultValue);
@ -263,7 +267,7 @@ utils.prototype.removeLocalForage = function (key, successCallback, errorCallbac
return; return;
} }
localforage.removeItem(core.firstData.name+"_"+key, function (err) { localforage.removeItem(core.firstData.name + "_" + key, function (err) {
if (core.isset(err)) { if (core.isset(err)) {
if (core.isset(errorCallback)) errorCallback(err); if (core.isset(errorCallback)) errorCallback(err);
} }
@ -280,13 +284,13 @@ utils.prototype.clone = function (data) {
if (!core.isset(data)) return data; if (!core.isset(data)) return data;
// date // date
if (data instanceof Date) { if (data instanceof Date) {
var copy=new Date(); var copy = new Date();
copy.setTime(data.getTime()); copy.setTime(data.getTime());
return copy; return copy;
} }
// array // array
if (data instanceof Array) { if (data instanceof Array) {
var copy=[]; var copy = [];
// for (var i=0;i<data.length;i++) { // for (var i=0;i<data.length;i++) {
for (var i in data) { for (var i in data) {
// copy.push(core.clone(data[i])); // copy.push(core.clone(data[i]));
@ -300,10 +304,10 @@ utils.prototype.clone = function (data) {
} }
// object // object
if (data instanceof Object) { if (data instanceof Object) {
var copy={}; var copy = {};
for (var i in data) { for (var i in data) {
if (data.hasOwnProperty(i)) if (data.hasOwnProperty(i))
copy[i]=core.clone(data[i]); copy[i] = core.clone(data[i]);
} }
return copy; return copy;
} }
@ -312,49 +316,49 @@ utils.prototype.clone = function (data) {
////// 裁剪图片 ////// ////// 裁剪图片 //////
utils.prototype.cropImage = function (image, size) { utils.prototype.cropImage = function (image, size) {
size = size||32; size = size || 32;
var canvas = document.createElement("canvas"); var canvas = document.createElement("canvas");
var context = canvas.getContext("2d"); var context = canvas.getContext("2d");
canvas.width = size; canvas.width = size;
canvas.height = size; canvas.height = size;
var ans = []; var ans = [];
for (var i=0;i<image.height;i+=size) { for (var i = 0; i < image.height; i += size) {
context.drawImage(image, 0, i, size, size, 0, 0, size, size); context.drawImage(image, 0, i, size, size, 0, 0, size, size);
var img = new Image(); var img = new Image();
img.src = canvas.toDataURL("image/png"); img.src = canvas.toDataURL("image/png");
ans.push(img); ans.push(img);
context.clearRect(0,0,size,size); context.clearRect(0, 0, size, size);
} }
return ans; return ans;
} }
////// 格式化时间为字符串 ////// ////// 格式化时间为字符串 //////
utils.prototype.formatDate = function(date) { utils.prototype.formatDate = function (date) {
if (!core.isset(date)) return ""; if (!core.isset(date)) return "";
return ""+date.getFullYear()+"-"+core.setTwoDigits(date.getMonth()+1)+"-"+core.setTwoDigits(date.getDate())+" " return "" + date.getFullYear() + "-" + core.setTwoDigits(date.getMonth() + 1) + "-" + core.setTwoDigits(date.getDate()) + " "
+core.setTwoDigits(date.getHours())+":"+core.setTwoDigits(date.getMinutes())+":"+core.setTwoDigits(date.getSeconds()); + core.setTwoDigits(date.getHours()) + ":" + core.setTwoDigits(date.getMinutes()) + ":" + core.setTwoDigits(date.getSeconds());
} }
////// 格式化时间为最简字符串 ////// ////// 格式化时间为最简字符串 //////
utils.prototype.formatDate2 = function (date) { utils.prototype.formatDate2 = function (date) {
if (!core.isset(date)) return ""; if (!core.isset(date)) return "";
return ""+date.getFullYear()+core.setTwoDigits(date.getMonth()+1)+core.setTwoDigits(date.getDate()) return "" + date.getFullYear() + core.setTwoDigits(date.getMonth() + 1) + core.setTwoDigits(date.getDate())
+core.setTwoDigits(date.getHours())+core.setTwoDigits(date.getMinutes())+core.setTwoDigits(date.getSeconds()); + core.setTwoDigits(date.getHours()) + core.setTwoDigits(date.getMinutes()) + core.setTwoDigits(date.getSeconds());
} }
////// 两位数显示 ////// ////// 两位数显示 //////
utils.prototype.setTwoDigits = function (x) { utils.prototype.setTwoDigits = function (x) {
return parseInt(x)<10?"0"+x:x; return parseInt(x) < 10 ? "0" + x : x;
} }
utils.prototype.formatBigNumber = function (x, onMap) { utils.prototype.formatBigNumber = function (x, onMap) {
x = Math.floor(parseFloat(x)); x = Math.floor(parseFloat(x));
if (!core.isset(x)) return '???'; if (!core.isset(x)) return '???';
var c = x<0?"-":""; var c = x < 0 ? "-" : "";
x = Math.abs(x); x = Math.abs(x);
if (x<=99999 || (!onMap && x<=999999)) return c + x; if (x <= 99999 || (!onMap && x <= 999999)) return c + x;
var all = [ var all = [
{"val": 1e20, "c": "g"}, {"val": 1e20, "c": "g"},
@ -364,105 +368,105 @@ utils.prototype.formatBigNumber = function (x, onMap) {
{"val": 1e4, "c": "w"}, {"val": 1e4, "c": "w"},
] ]
for (var i=0;i<all.length;i++) { for (var i = 0; i < all.length; i++) {
var one = all[i]; var one = all[i];
if (onMap) { if (onMap) {
if (x>=one.val) { if (x >= one.val) {
var v = x/one.val; var v = x / one.val;
return c + v.toFixed(Math.max(0, Math.floor(3-Math.log10(v+1)))) + one.c; return c + v.toFixed(Math.max(0, Math.floor(3 - Math.log10(v + 1)))) + one.c;
} }
} }
else { else {
if (x>=10*one.val) { if (x >= 10 * one.val) {
var v = x/one.val; var v = x / one.val;
return c + v.toFixed(Math.max(0, Math.floor(4-Math.log10(v+1)))) + one.c; return c + v.toFixed(Math.max(0, Math.floor(4 - Math.log10(v + 1)))) + one.c;
} }
} }
} }
return c+x; return c + x;
} }
////// 数组转RGB ////// ////// 数组转RGB //////
utils.prototype.arrayToRGB = function (color) { utils.prototype.arrayToRGB = function (color) {
var nowR = this.clamp(parseInt(color[0]),0,255), nowG = this.clamp(parseInt(color[1]),0,255), var nowR = this.clamp(parseInt(color[0]), 0, 255), nowG = this.clamp(parseInt(color[1]), 0, 255),
nowB = this.clamp(parseInt(color[2]),0,255); nowB = this.clamp(parseInt(color[2]), 0, 255);
return "#"+((1<<24)+(nowR<<16)+(nowG<<8)+nowB).toString(16).slice(1); return "#" + ((1 << 24) + (nowR << 16) + (nowG << 8) + nowB).toString(16).slice(1);
} }
utils.prototype.arrayToRGBA = function (color) { utils.prototype.arrayToRGBA = function (color) {
if (!this.isset(color[3])) color[3]=1; if (!this.isset(color[3])) color[3] = 1;
var nowR = this.clamp(parseInt(color[0]),0,255), nowG = this.clamp(parseInt(color[1]),0,255), var nowR = this.clamp(parseInt(color[0]), 0, 255), nowG = this.clamp(parseInt(color[1]), 0, 255),
nowB = this.clamp(parseInt(color[2]),0,255), nowA = this.clamp(parseFloat(color[3]),0,1); nowB = this.clamp(parseInt(color[2]), 0, 255), nowA = this.clamp(parseFloat(color[3]), 0, 1);
return "rgba("+nowR+","+nowG+","+nowB+","+nowA+")"; return "rgba(" + nowR + "," + nowG + "," + nowB + "," + nowA + ")";
} }
////// 加密路线 ////// ////// 加密路线 //////
utils.prototype.encodeRoute = function (route) { utils.prototype.encodeRoute = function (route) {
var ans="", lastMove = "", cnt=0; var ans = "", lastMove = "", cnt = 0;
route.forEach(function (t) { route.forEach(function (t) {
if (t=='up' || t=='down' || t=='left' || t=='right') { if (t == 'up' || t == 'down' || t == 'left' || t == 'right') {
if (t!=lastMove && cnt>0) { if (t != lastMove && cnt > 0) {
ans+=lastMove.substring(0,1).toUpperCase(); ans += lastMove.substring(0, 1).toUpperCase();
if (cnt>1) ans+=cnt; if (cnt > 1) ans += cnt;
cnt=0; cnt = 0;
} }
lastMove=t; lastMove = t;
cnt++; cnt++;
} }
else { else {
if (cnt>0) { if (cnt > 0) {
ans+=lastMove.substring(0,1).toUpperCase(); ans += lastMove.substring(0, 1).toUpperCase();
if (cnt>1) ans+=cnt; if (cnt > 1) ans += cnt;
cnt=0; cnt = 0;
} }
ans += core.utils._encodeRoute_encodeOne(t); ans += core.utils._encodeRoute_encodeOne(t);
} }
}); });
if (cnt>0) { if (cnt > 0) {
ans+=lastMove.substring(0,1).toUpperCase(); ans += lastMove.substring(0, 1).toUpperCase();
if (cnt>1) ans+=cnt; if (cnt > 1) ans += cnt;
} }
return LZString.compressToBase64(ans); return LZString.compressToBase64(ans);
} }
utils.prototype._encodeRoute_id2number = function (id) { utils.prototype._encodeRoute_id2number = function (id) {
var number = core.maps.getNumberById(id); var number = core.maps.getNumberById(id);
return number==0?id:number; return number == 0 ? id : number;
} }
utils.prototype._encodeRoute_encodeOne = function (t) { utils.prototype._encodeRoute_encodeOne = function (t) {
if (t.indexOf('item:')==0) if (t.indexOf('item:') == 0)
return "I"+this._encodeRoute_id2number(t.substring(5))+":"; return "I" + this._encodeRoute_id2number(t.substring(5)) + ":";
else if (t.indexOf('unEquip:')==0) else if (t.indexOf('unEquip:') == 0)
return "u"+t.substring(8); return "u" + t.substring(8);
else if (t.indexOf('equip:')==0) else if (t.indexOf('equip:') == 0)
return "e"+this._encodeRoute_id2number(t.substring(6))+":"; return "e" + this._encodeRoute_id2number(t.substring(6)) + ":";
else if (t.indexOf('fly:')==0) else if (t.indexOf('fly:') == 0)
return "F"+t.substring(4)+":"; return "F" + t.substring(4) + ":";
else if (t.indexOf('choices:')==0) else if (t.indexOf('choices:') == 0)
return "C"+t.substring(8); return "C" + t.substring(8);
else if (t.indexOf('shop:')==0) else if (t.indexOf('shop:') == 0)
return "S"+t.substring(5); return "S" + t.substring(5);
else if (t=='turn') else if (t == 'turn')
return 'T'; return 'T';
else if (t.indexOf('turn:')==0) else if (t.indexOf('turn:') == 0)
return "t"+t.substring(5).substring(0,1).toUpperCase()+":"; return "t" + t.substring(5).substring(0, 1).toUpperCase() + ":";
else if (t=='getNext') else if (t == 'getNext')
return 'G'; return 'G';
else if (t.indexOf('input:')==0) else if (t.indexOf('input:') == 0)
return "P"+t.substring(6); return "P" + t.substring(6);
else if (t.indexOf('input2:')==0) else if (t.indexOf('input2:') == 0)
return "Q"+t.substring(7)+":"; return "Q" + t.substring(7) + ":";
else if (t=='no') else if (t == 'no')
return 'N'; return 'N';
else if (t.indexOf('move:')==0) else if (t.indexOf('move:') == 0)
return "M"+t.substring(5); return "M" + t.substring(5);
else if (t.indexOf('key:')==0) else if (t.indexOf('key:') == 0)
return 'K'+t.substring(4); return 'K' + t.substring(4);
else if (t.indexOf('random:')==0) else if (t.indexOf('random:') == 0)
return 'X'+t.substring(7); return 'X' + t.substring(7);
return ''; return '';
} }
@ -476,7 +480,8 @@ utils.prototype.decodeRoute = function (route) {
if (core.isset(v) && /^[a-zA-Z0-9+\/=:]*$/.test(v)) { if (core.isset(v) && /^[a-zA-Z0-9+\/=:]*$/.test(v)) {
route = v; route = v;
} }
} catch (e) {} } catch (e) {
}
var decodeObj = {route: route, index: 0, ans: []}; var decodeObj = {route: route, index: 0, ans: []};
while (decodeObj.index < decodeObj.route.length) { while (decodeObj.index < decodeObj.route.length) {
@ -486,18 +491,18 @@ utils.prototype.decodeRoute = function (route) {
} }
utils.prototype._decodeRoute_getNumber = function (decodeObj, noparse) { utils.prototype._decodeRoute_getNumber = function (decodeObj, noparse) {
var num=""; var num = "";
while (decodeObj.index<decodeObj.route.length && !isNaN(decodeObj.route.charAt(decodeObj.index))) { while (decodeObj.index < decodeObj.route.length && !isNaN(decodeObj.route.charAt(decodeObj.index))) {
num+=decodeObj.route.charAt(decodeObj.index++); num += decodeObj.route.charAt(decodeObj.index++);
} }
if (num.length==0) num="1"; if (num.length == 0) num = "1";
return core.isset(noparse)?num:parseInt(num); return core.isset(noparse) ? num : parseInt(num);
} }
utils.prototype._decodeRoute_getString = function (decodeObj) { utils.prototype._decodeRoute_getString = function (decodeObj) {
var str=""; var str = "";
while (decodeObj.index<decodeObj.route.length && decodeObj.route.charAt(decodeObj.index)!=':') { while (decodeObj.index < decodeObj.route.length && decodeObj.route.charAt(decodeObj.index) != ':') {
str+=decodeObj.route.charAt(decodeObj.index++); str += decodeObj.route.charAt(decodeObj.index++);
} }
decodeObj.index++; decodeObj.index++;
return str; return str;
@ -512,34 +517,70 @@ utils.prototype._decodeRoute_number2id = function (number) {
} }
utils.prototype._decodeRoute_decodeOne = function (decodeObj, c) { utils.prototype._decodeRoute_decodeOne = function (decodeObj, c) {
var nxt=(c=='I'|| c=='e' ||c=='F'||c=='S'||c=='Q'||c=='t')? var nxt = (c == 'I' || c == 'e' || c == 'F' || c == 'S' || c == 'Q' || c == 't') ?
this._decodeRoute_getString(decodeObj):this._decodeRoute_getNumber(decodeObj); this._decodeRoute_getString(decodeObj) : this._decodeRoute_getNumber(decodeObj);
var mp = {"U": "up", "D": "down", "L": "left", "R": "right"}; var mp = {"U": "up", "D": "down", "L": "left", "R": "right"};
switch (c) { switch (c) {
case "U": case "D": case "L": case "R": for (var i=0;i<nxt;i++) decodeObj.ans.push(mp[c]); break; case "U":
case "I": decodeObj.ans.push("item:"+this._decodeRoute_number2id(nxt)); break; case "D":
case "u": decodeObj.ans.push("unEquip:"+nxt); break; case "L":
case "e": decodeObj.ans.push("equip:"+this._decodeRoute_number2id(nxt)); break; case "R":
case "F": decodeObj.ans.push("fly:"+nxt); break; for (var i = 0; i < nxt; i++) decodeObj.ans.push(mp[c]);
case "C": decodeObj.ans.push("choices:"+nxt); break; break;
case "S": decodeObj.ans.push("shop:"+nxt+":"+this._decodeRoute_getNumber(decodeObj, true)); break; case "I":
case "T": decodeObj.ans.push("turn"); break; decodeObj.ans.push("item:" + this._decodeRoute_number2id(nxt));
case "t": decodeObj.ans.push("turn:"+mp[nxt]); break; break;
case "G": decodeObj.ans.push("getNext"); break; case "u":
case "P": decodeObj.ans.push("input:"+nxt); break; decodeObj.ans.push("unEquip:" + nxt);
case "Q": decodeObj.ans.push("input2:"+nxt); break; break;
case "N": decodeObj.ans.push("no"); break; case "e":
case "M": ++decodeObj.index; decodeObj.ans.push("move:"+nxt+":"+this._decodeRoute_getNumber(decodeObj)); break; decodeObj.ans.push("equip:" + this._decodeRoute_number2id(nxt));
case "K": decodeObj.ans.push("key:"+nxt); break; break;
case "X": decodeObj.ans.push("random:"+nxt); break; case "F":
decodeObj.ans.push("fly:" + nxt);
break;
case "C":
decodeObj.ans.push("choices:" + nxt);
break;
case "S":
decodeObj.ans.push("shop:" + nxt + ":" + this._decodeRoute_getNumber(decodeObj, true));
break;
case "T":
decodeObj.ans.push("turn");
break;
case "t":
decodeObj.ans.push("turn:" + mp[nxt]);
break;
case "G":
decodeObj.ans.push("getNext");
break;
case "P":
decodeObj.ans.push("input:" + nxt);
break;
case "Q":
decodeObj.ans.push("input2:" + nxt);
break;
case "N":
decodeObj.ans.push("no");
break;
case "M":
++decodeObj.index;
decodeObj.ans.push("move:" + nxt + ":" + this._decodeRoute_getNumber(decodeObj));
break;
case "K":
decodeObj.ans.push("key:" + nxt);
break;
case "X":
decodeObj.ans.push("random:" + nxt);
break;
} }
} }
////// 判断某对象是否不为undefined也不会null ////// ////// 判断某对象是否不为undefined也不会null //////
utils.prototype.isset = function (val) { utils.prototype.isset = function (val) {
if (val == undefined || val == null || (typeof val=='number' && isNaN(val))) { if (val == undefined || val == null || (typeof val == 'number' && isNaN(val))) {
return false; return false;
} }
return true return true
@ -547,33 +588,33 @@ utils.prototype.isset = function (val) {
////// 获得子数组 ////// ////// 获得子数组 //////
utils.prototype.subarray = function (a, b) { utils.prototype.subarray = function (a, b) {
if (!core.isset(a) || !core.isset(b) || !(a instanceof Array) || !(b instanceof Array) || a.length<b.length) if (!core.isset(a) || !core.isset(b) || !(a instanceof Array) || !(b instanceof Array) || a.length < b.length)
return null; return null;
var na = core.clone(a), nb=core.clone(b); var na = core.clone(a), nb = core.clone(b);
while (nb.length>0) { while (nb.length > 0) {
if (na.shift() != nb.shift()) return null; if (na.shift() != nb.shift()) return null;
} }
return na; return na;
} }
utils.prototype.inArray = function (array, element) { utils.prototype.inArray = function (array, element) {
return this.isset(array) && (array instanceof Array) && array.indexOf(element)>=0; return this.isset(array) && (array instanceof Array) && array.indexOf(element) >= 0;
} }
utils.prototype.clamp = function (x, a, b) { utils.prototype.clamp = function (x, a, b) {
var min=Math.min(a, b), max=Math.max(a, b); var min = Math.min(a, b), max = Math.max(a, b);
return Math.min(Math.max(x||0, min), max); return Math.min(Math.max(x || 0, min), max);
} }
utils.prototype.getCookie = function (name) { utils.prototype.getCookie = function (name) {
var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)')); var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
return match?match[2]:null; return match ? match[2] : null;
} }
utils.prototype.expandMoveSteps = function (steps) { utils.prototype.expandMoveSteps = function (steps) {
var moveSteps=[]; var moveSteps = [];
steps.forEach(function (e) { steps.forEach(function (e) {
if (typeof e=="string") { if (typeof e == "string") {
moveSteps.push(e); moveSteps.push(e);
} }
else { else {
@ -581,7 +622,7 @@ utils.prototype.expandMoveSteps = function (steps) {
moveSteps.push(e.direction) moveSteps.push(e.direction)
} }
else { else {
for (var i=0;i<e.value;i++) { for (var i = 0; i < e.value; i++) {
moveSteps.push(e.direction); moveSteps.push(e.direction);
} }
} }
@ -595,10 +636,10 @@ utils.prototype.setStatusBarInnerHTML = function (name, value, css) {
if (typeof value == 'number') value = this.formatBigNumber(value); if (typeof value == 'number') value = this.formatBigNumber(value);
// 判定是否斜体 // 判定是否斜体
var italic = /^[-a-zA-Z0-9`~!@#$%^&*()_=+\[{\]}\\|;:'",<.>\/?]*$/.test(value); var italic = /^[-a-zA-Z0-9`~!@#$%^&*()_=+\[{\]}\\|;:'",<.>\/?]*$/.test(value);
var style = 'font-style: ' + (italic?'italic':'normal') + '; '; var style = 'font-style: ' + (italic ? 'italic' : 'normal') + '; ';
// 判定是否需要缩放 // 判定是否需要缩放
var length = this.strlen(value) || 1; var length = this.strlen(value) || 1;
style += 'font-size: ' + Math.min(1, 7/length) + 'em; '; style += 'font-size: ' + Math.min(1, 7 / length) + 'em; ';
if (core.isset(css)) style += css; if (core.isset(css)) style += css;
core.statusBar[name].innerHTML = "<span class='_status' style='" + style + "'>" + value + "</span>"; core.statusBar[name].innerHTML = "<span class='_status' style='" + style + "'>" + value + "</span>";
} }
@ -620,7 +661,7 @@ utils.prototype.encodeBase64 = function (str) {
////// Base64解密 ////// ////// Base64解密 //////
utils.prototype.decodeBase64 = function (str) { utils.prototype.decodeBase64 = function (str) {
return decodeURIComponent(atob(str).split('').map(function(c) { return decodeURIComponent(atob(str).split('').map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join('')); }).join(''));
} }
@ -628,19 +669,19 @@ utils.prototype.decodeBase64 = function (str) {
////// 任意进制转换 ////// ////// 任意进制转换 //////
utils.prototype.convertBase = function (str, fromBase, toBase) { utils.prototype.convertBase = function (str, fromBase, toBase) {
var map = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~`!@#$%^&*()_-+={}[]\\|:;<>,.?/"; var map = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~`!@#$%^&*()_-+={}[]\\|:;<>,.?/";
if (fromBase==toBase) return str; if (fromBase == toBase) return str;
var len = str.length, ans=""; var len = str.length, ans = "";
var t = []; var t = [];
for (var i=0;i<len;i++) t[i]=map.indexOf(str.charAt(i)); for (var i = 0; i < len; i++) t[i] = map.indexOf(str.charAt(i));
t[len]=0; t[len] = 0;
while (len>0) { while (len > 0) {
for (var i=len; i>=1; i--) { for (var i = len; i >= 1; i--) {
t[i-1]+=t[i]%toBase*fromBase; t[i - 1] += t[i] % toBase * fromBase;
t[i]=parseInt(t[i]/toBase); t[i] = parseInt(t[i] / toBase);
} }
ans+=map.charAt(t[0]%toBase); ans += map.charAt(t[0] % toBase);
t[0]=parseInt(t[0]/toBase); t[0] = parseInt(t[0] / toBase);
while (len>0 && t[len-1]==0) len--; while (len > 0 && t[len - 1] == 0) len--;
} }
return ans; return ans;
} }
@ -649,21 +690,21 @@ utils.prototype.rand = function (num) {
var rand = core.getFlag('__rand__'); var rand = core.getFlag('__rand__');
rand = this.__next_rand(rand); rand = this.__next_rand(rand);
core.setFlag('__rand__', rand); core.setFlag('__rand__', rand);
var ans = rand/2147483647; var ans = rand / 2147483647;
if (core.isset(num) && num>0) if (core.isset(num) && num > 0)
return Math.floor(ans*num); return Math.floor(ans * num);
return ans; return ans;
} }
////// 生成随机数(录像方法) ////// ////// 生成随机数(录像方法) //////
utils.prototype.rand2 = function (num) { utils.prototype.rand2 = function (num) {
num = num||2147483648; num = num || 2147483648;
var value; var value;
if (core.isReplaying()) { if (core.isReplaying()) {
var action = core.status.replay.toReplay.shift(); var action = core.status.replay.toReplay.shift();
if (action.indexOf("random:")==0 ) { if (action.indexOf("random:") == 0) {
value=parseInt(action.substring(7)); value = parseInt(action.substring(7));
} }
else { else {
core.stopReplay(); core.stopReplay();
@ -672,14 +713,14 @@ utils.prototype.rand2 = function (num) {
} }
} }
else { else {
value = Math.floor(Math.random()*num); value = Math.floor(Math.random() * num);
} }
core.status.route.push("random:"+value); core.status.route.push("random:" + value);
return value; return value;
} }
utils.prototype.__init_seed = function () { utils.prototype.__init_seed = function () {
var rand = new Date().getTime()%34834795 + 3534; var rand = new Date().getTime() % 34834795 + 3534;
rand = this.__next_rand(rand); rand = this.__next_rand(rand);
rand = this.__next_rand(rand); rand = this.__next_rand(rand);
rand = this.__next_rand(rand); rand = this.__next_rand(rand);
@ -688,8 +729,8 @@ utils.prototype.__init_seed = function () {
} }
utils.prototype.__next_rand = function (_rand) { utils.prototype.__next_rand = function (_rand) {
_rand=(_rand%127773)*16807-~~(_rand/127773)*2836; _rand = (_rand % 127773) * 16807 - ~~(_rand / 127773) * 2836;
_rand+=_rand<0?2147483647:0; _rand += _rand < 0 ? 2147483647 : 0;
return _rand; return _rand;
} }
@ -712,24 +753,24 @@ utils.prototype.readFile = function (success, error, readType) {
} }
// Step 1: 如果不支持FileReader直接不支持 // Step 1: 如果不支持FileReader直接不支持
if (core.platform.fileReader==null) { if (core.platform.fileReader == null) {
alert("当前浏览器不支持FileReader"); alert("当前浏览器不支持FileReader");
if (core.isset(error)) error(); if (core.isset(error)) error();
return; return;
} }
if (core.platform.fileInput==null) { if (core.platform.fileInput == null) {
core.platform.fileInput = document.createElement("input"); core.platform.fileInput = document.createElement("input");
core.platform.fileInput.style.opacity = 0; core.platform.fileInput.style.opacity = 0;
core.platform.fileInput.type = 'file'; core.platform.fileInput.type = 'file';
core.platform.fileInput.onchange = function () { core.platform.fileInput.onchange = function () {
var files = core.platform.fileInput.files; var files = core.platform.fileInput.files;
if (files.length==0) { if (files.length == 0) {
if (core.isset(core.platform.errorCallback)) if (core.isset(core.platform.errorCallback))
core.platform.errorCallback(); core.platform.errorCallback();
return; return;
} }
if(!readType)core.platform.fileReader.readAsText(core.platform.fileInput.files[0]); if (!readType) core.platform.fileReader.readAsText(core.platform.fileInput.files[0]);
else core.platform.fileReader.readAsDataURL(core.platform.fileInput.files[0]); else core.platform.fileReader.readAsDataURL(core.platform.fileInput.files[0]);
core.platform.fileInput.value = ''; core.platform.fileInput.value = '';
} }
@ -740,14 +781,14 @@ utils.prototype.readFile = function (success, error, readType) {
////// 读取文件完毕 ////// ////// 读取文件完毕 //////
utils.prototype.readFileContent = function (content) { utils.prototype.readFileContent = function (content) {
var obj=null; var obj = null;
if(content.slice(0,4)==='data'){ if (content.slice(0, 4) === 'data') {
if (core.isset(core.platform.successCallback)) if (core.isset(core.platform.successCallback))
core.platform.successCallback(content); core.platform.successCallback(content);
return; return;
} }
try { try {
obj=JSON.parse(content); obj = JSON.parse(content);
if (core.isset(obj)) { if (core.isset(obj)) {
if (core.isset(core.platform.successCallback)) if (core.isset(core.platform.successCallback))
core.platform.successCallback(obj); core.platform.successCallback(obj);
@ -807,14 +848,14 @@ utils.prototype.download = function (filename, content) {
alert("你当前使用的是Safari浏览器不支持直接下载文件。\n即将打开一个新窗口为应下载内容请自行全选复制然后创建空白文件并粘贴。"); alert("你当前使用的是Safari浏览器不支持直接下载文件。\n即将打开一个新窗口为应下载内容请自行全选复制然后创建空白文件并粘贴。");
var blob = new Blob([content], {type: 'text/plain;charset=utf-8'}); var blob = new Blob([content], {type: 'text/plain;charset=utf-8'});
var href = window.URL.createObjectURL(blob); var href = window.URL.createObjectURL(blob);
var opened=window.open(href, "_blank"); var opened = window.open(href, "_blank");
window.URL.revokeObjectURL(href); window.URL.revokeObjectURL(href);
return; return;
} }
// Step 4: 下载 // Step 4: 下载
var blob = new Blob([content], {type: 'text/plain;charset=utf-8'}); var blob = new Blob([content], {type: 'text/plain;charset=utf-8'});
if(window.navigator.msSaveOrOpenBlob) { if (window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveBlob(blob, filename); window.navigator.msSaveBlob(blob, filename);
} }
else { else {
@ -868,7 +909,7 @@ utils.prototype.copy = function (data) {
////// 动画显示某对象 ////// ////// 动画显示某对象 //////
utils.prototype.show = function (obj, speed, callback) { utils.prototype.show = function (obj, speed, callback) {
obj.style.display = 'block'; obj.style.display = 'block';
if (!core.isset(speed) && main.mode!='play') { if (!core.isset(speed) && main.mode != 'play') {
obj.style.opacity = 1; obj.style.opacity = 1;
if (core.isset(callback)) callback(); if (core.isset(callback)) callback();
return; return;
@ -889,7 +930,7 @@ utils.prototype.show = function (obj, speed, callback) {
////// 动画使某对象消失 ////// ////// 动画使某对象消失 //////
utils.prototype.hide = function (obj, speed, callback) { utils.prototype.hide = function (obj, speed, callback) {
if (!core.isset(speed) || main.mode!='play'){ if (!core.isset(speed) || main.mode != 'play') {
obj.style.display = 'none'; obj.style.display = 'none';
if (core.isset(callback)) callback(); if (core.isset(callback)) callback();
return; return;
@ -918,16 +959,16 @@ utils.prototype.encodeCanvas = function (ctx) {
ctx.imageSmoothingEnabled = false; ctx.imageSmoothingEnabled = false;
var imgData = ctx.getImageData(0, 0, width, height); var imgData = ctx.getImageData(0, 0, width, height);
for (var i=0;i<imgData.data.length;i+=4) { for (var i = 0; i < imgData.data.length; i += 4) {
list.push(Math.sign(imgData.data[i+3])); list.push(Math.sign(imgData.data[i + 3]));
} }
// compress 01 to array // compress 01 to array
var prev = 0, cnt = 0, arr = []; var prev = 0, cnt = 0, arr = [];
for (var i=0;i<list.length;i++) { for (var i = 0; i < list.length; i++) {
if (list[i]!=prev) { if (list[i] != prev) {
arr.push(cnt); arr.push(cnt);
prev=list[i]; prev = list[i];
cnt=0; cnt = 0;
} }
cnt++; cnt++;
} }
@ -939,24 +980,24 @@ utils.prototype.encodeCanvas = function (ctx) {
utils.prototype.decodeCanvas = function (arr, width, height) { utils.prototype.decodeCanvas = function (arr, width, height) {
// 清空tempCanvas // 清空tempCanvas
var tempCanvas = core.bigmap.tempCanvas; var tempCanvas = core.bigmap.tempCanvas;
tempCanvas.canvas.width=width; tempCanvas.canvas.width = width;
tempCanvas.canvas.height=height; tempCanvas.canvas.height = height;
tempCanvas.clearRect(0, 0, width, height); tempCanvas.clearRect(0, 0, width, height);
if (!core.isset(arr)) return null; if (!core.isset(arr)) return null;
// to byte array // to byte array
var curr = 0, list = []; var curr = 0, list = [];
arr.forEach(function (x) { arr.forEach(function (x) {
for (var i=0;i<x;i++) list.push(curr); for (var i = 0; i < x; i++) list.push(curr);
curr = 1-curr; curr = 1 - curr;
}) })
var imgData = tempCanvas.getImageData(0, 0, width, height); var imgData = tempCanvas.getImageData(0, 0, width, height);
for (var i=0;i<imgData.data.length;i+=4) { for (var i = 0; i < imgData.data.length; i += 4) {
var index = i/4; var index = i / 4;
if (list[index]) { if (list[index]) {
imgData.data[i]=255; imgData.data[i] = 255;
imgData.data[i+3]=255; imgData.data[i + 3] = 255;
} }
} }
tempCanvas.putImageData(imgData, 0, 0); tempCanvas.putImageData(imgData, 0, 0);
@ -967,9 +1008,9 @@ utils.prototype.consoleOpened = function () {
if (window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized) if (window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized)
return true; return true;
var threshold = 160; var threshold = 160;
var zoom = Math.min(window.outerWidth/window.innerWidth, window.outerHeight/window.innerHeight); var zoom = Math.min(window.outerWidth / window.innerWidth, window.outerHeight / window.innerHeight);
return window.outerWidth - zoom*window.innerWidth > threshold return window.outerWidth - zoom * window.innerWidth > threshold
|| window.outerHeight - zoom*window.innerHeight > threshold; || window.outerHeight - zoom * window.innerHeight > threshold;
} }
utils.prototype.hashCode = function (obj) { utils.prototype.hashCode = function (obj) {
@ -977,8 +1018,8 @@ utils.prototype.hashCode = function (obj) {
var hash = 0, i, chr; var hash = 0, i, chr;
if (obj.length === 0) return hash; if (obj.length === 0) return hash;
for (i = 0; i < obj.length; i++) { for (i = 0; i < obj.length; i++) {
chr = obj.charCodeAt(i); chr = obj.charCodeAt(i);
hash = ((hash << 5) - hash) + chr; hash = ((hash << 5) - hash) + chr;
hash |= 0; hash |= 0;
} }
return hash; return hash;
@ -1011,20 +1052,20 @@ utils.prototype.same = function (a, b) {
utils.prototype._export = function (floorIds) { utils.prototype._export = function (floorIds) {
if (!core.isset(floorIds)) floorIds = [core.status.floorId]; if (!core.isset(floorIds)) floorIds = [core.status.floorId];
else if (floorIds=='all') floorIds = core.clone(core.floorIds); else if (floorIds == 'all') floorIds = core.clone(core.floorIds);
else if (typeof floorIds == 'string') floorIds = [floorIds]; else if (typeof floorIds == 'string') floorIds = [floorIds];
var monsterMap = {}; var monsterMap = {};
// map // map
var content = floorIds.length+"\n13 13\n\n"; var content = floorIds.length + "\n13 13\n\n";
floorIds.forEach(function (floorId) { floorIds.forEach(function (floorId) {
var arr = core.maps.getMapArray(core.status.maps[floorId].blocks, 13, 13); var arr = core.maps.getMapArray(core.status.maps[floorId].blocks, 13, 13);
content += arr.map(function (x) { content += arr.map(function (x) {
// check monster // check monster
x.forEach(function (t) { x.forEach(function (t) {
var block = core.maps.initBlock(null, null, t); var block = core.maps.initBlock(null, null, t);
if (block.event.cls.indexOf("enemy")==0) { if (block.event.cls.indexOf("enemy") == 0) {
monsterMap[t] = block.event.id; monsterMap[t] = block.event.id;
} }
}) })
@ -1034,7 +1075,9 @@ utils.prototype._export = function (floorIds) {
// values // values
content += ["redJewel", "blueJewel", "greenJewel", "redPotion", "bluePotion", content += ["redJewel", "blueJewel", "greenJewel", "redPotion", "bluePotion",
"yellowPotion", "greenPotion", "sword1", "shield1"].map(function (x) {return core.values[x]}).join(" ") + "\n\n"; "yellowPotion", "greenPotion", "sword1", "shield1"].map(function (x) {
return core.values[x]
}).join(" ") + "\n\n";
// monster // monster
content += Object.keys(monsterMap).length + "\n"; content += Object.keys(monsterMap).length + "\n";
@ -1059,26 +1102,26 @@ utils.prototype.http = function (type, url, formData, success, error, mimeType,
xhr.overrideMimeType(mimeType); xhr.overrideMimeType(mimeType);
if (core.isset(responseType)) if (core.isset(responseType))
xhr.responseType = responseType; xhr.responseType = responseType;
xhr.onload = function(e) { xhr.onload = function (e) {
if (xhr.status==200) { if (xhr.status == 200) {
if (core.isset(success)) { if (core.isset(success)) {
success(xhr.response); success(xhr.response);
} }
} }
else { else {
if (core.isset(error)) if (core.isset(error))
error("HTTP "+xhr.status); error("HTTP " + xhr.status);
} }
}; };
xhr.onabort = function () { xhr.onabort = function () {
if (core.isset(error)) if (core.isset(error))
error("Abort"); error("Abort");
} }
xhr.ontimeout = function() { xhr.ontimeout = function () {
if (core.isset(error)) if (core.isset(error))
error("Timeout"); error("Timeout");
} }
xhr.onerror = function() { xhr.onerror = function () {
if (core.isset(error)) if (core.isset(error))
error("Error on Connection"); error("Error on Connection");
} }
@ -1096,8 +1139,8 @@ function lzw_encode(s) {
var currChar; var currChar;
var phrase = data[0]; var phrase = data[0];
var code = 256; var code = 256;
for (var i=1; i<data.length; i++) { for (var i = 1; i < data.length; i++) {
currChar=data[i]; currChar = data[i];
if (dict[phrase + currChar] != null) { if (dict[phrase + currChar] != null) {
phrase += currChar; phrase += currChar;
} }
@ -1105,11 +1148,11 @@ function lzw_encode(s) {
out.push(phrase.length > 1 ? dict[phrase] : phrase.charCodeAt(0)); out.push(phrase.length > 1 ? dict[phrase] : phrase.charCodeAt(0));
dict[phrase + currChar] = code; dict[phrase + currChar] = code;
code++; code++;
phrase=currChar; phrase = currChar;
} }
} }
out.push(phrase.length > 1 ? dict[phrase] : phrase.charCodeAt(0)); out.push(phrase.length > 1 ? dict[phrase] : phrase.charCodeAt(0));
for (var i=0; i<out.length; i++) { for (var i = 0; i < out.length; i++) {
out[i] = String.fromCharCode(out[i]); out[i] = String.fromCharCode(out[i]);
} }
return out.join(""); return out.join("");
@ -1124,7 +1167,7 @@ function lzw_decode(s) {
var out = [currChar]; var out = [currChar];
var code = 256; var code = 256;
var phrase; var phrase;
for (var i=1; i<data.length; i++) { for (var i = 1; i < data.length; i++) {
var currCode = data[i].charCodeAt(0); var currCode = data[i].charCodeAt(0);
if (currCode < 256) { if (currCode < 256) {
phrase = data[i]; phrase = data[i];

View File

@ -864,7 +864,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
break; break;
case 51: // 快捷键3: 飞 case 51: // 快捷键3: 飞
if (core.hasItem('centerFly')) { if (core.hasItem('centerFly')) {
core.events.tryUseItem('centerFly'); core.ui.drawCenterFly();
} }
break; break;
case 52: // 快捷键4破冰/冰冻/地震/上下楼器/... 其他道具依次判断 case 52: // 快捷键4破冰/冰冻/地震/上下楼器/... 其他道具依次判断