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': {
'position': "center",
"offset": 0,
"title": [255,215,0,1],
"background": [0,0,0,0.85],
"text": [255,255,255,1],
"title": [255, 215, 0, 1],
"background": [0, 0, 0, 0.85],
"text": [255, 255, 255, 1],
"titlefont": 22,
"textfont": 16,
"bold": false,
@ -242,7 +242,7 @@ core.prototype.init = function (coreData, callback) {
core.material.enemys = core.enemys.getEnemys();
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) {
window.AudioContext = window.AudioContext || window.webkitAudioContext || window.mozAudioContext || window.msAudioContext;
try {
@ -256,10 +256,10 @@ core.prototype.init = function (coreData, callback) {
}
["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"].forEach(function (t) {
if (navigator.userAgent.indexOf(t)>=0) {
if (t=='iPhone' || t=='iPad' || t=='iPod') core.platform.isIOS = true;
if (t=='Android') core.platform.isAndroid=true;
core.platform.isPC=false;
if (navigator.userAgent.indexOf(t) >= 0) {
if (t == 'iPhone' || t == 'iPad' || t == 'iPod') core.platform.isIOS = true;
if (t == 'Android') core.platform.isAndroid = true;
core.platform.isPC = false;
}
});
@ -270,8 +270,8 @@ core.prototype.init = function (coreData, callback) {
core.platform.supportCopy = false;
}
var chrome=/Chrome\/(\d+)\./i.exec(navigator.userAgent);
if (core.isset(chrome) && parseInt(chrome[1])>=50)
var chrome = /Chrome\/(\d+)\./i.exec(navigator.userAgent);
if (core.isset(chrome) && parseInt(chrome[1]) >= 50)
core.platform.isChrome = true;
core.platform.isSafari = /Safari/i.test(navigator.userAgent) && !/Chrome/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);
if (core.platform.useLocalForage) {
try {
core.setLocalForage("__test__", lzw_encode("__test__"), function() {
core.setLocalForage("__test__", lzw_encode("__test__"), function () {
try {
core.getLocalForage("__test__", null, function(data) {
core.getLocalForage("__test__", null, function (data) {
try {
if (lzw_decode(data)!="__test__") {
if (lzw_decode(data) != "__test__") {
console.log("localForage unsupported!");
core.platform.useLocalForage=false;
core.platform.useLocalForage = false;
}
else {
console.log("localForage supported!")
core.removeLocalForage("__test__");
}
}
catch (e) {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;
}
}, function (e) {
main.log(e);
core.platform.useLocalForage = false;
})
}
catch (e) {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;
}
}, 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);
@ -316,7 +331,7 @@ core.prototype.init = function (coreData, callback) {
// 先从存储中读取BGM状态
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.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.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.src = "project/images/keyboard.png";
@ -351,14 +366,14 @@ core.prototype.init = function (coreData, callback) {
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.initStatus.maps = core.maps.initMaps(core.floorIds);
core.setRequestAnimationFrame();
if (main.mode=='play')
if (main.mode == 'play')
core.events.initGame();
if (core.isset(functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a.plugins)) {
@ -396,13 +411,13 @@ core.prototype._forwardFunc = function (name, funcname) {
}
if (core[funcname]) {
console.error("ERROR: Cannot forward function "+funcname+" from "+name+"!");
console.error("ERROR: Cannot forward function " + funcname + " from " + name + "!");
return;
}
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+");");
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();
}
data.prototype._init = function() {
data.prototype._init = function () {
this.firstData = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.firstData;
this.values = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.values;
this.flags = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.flags;
//delete(data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d);
}
data.prototype.getFirstData = function() {
data.prototype.getFirstData = function () {
return core.clone(this.firstData);
}

View File

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

View File

@ -21,10 +21,10 @@ events.prototype.initGame = function () {
////// 游戏开始事件 //////
events.prototype.startGame = function (hard, seed, route, callback) {
main.dom.levelChooseButtons.style.display='none';
main.dom.startButtonGroup.style.display='none';
main.dom.levelChooseButtons.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)) {
@ -84,7 +84,7 @@ events.prototype._startGame_upload = function () {
formData.append('type', 'people');
formData.append('name', core.firstData.name);
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('hardCode', core.getFlag('hard', 0));
formData.append('base64', 1);
@ -141,7 +141,7 @@ events.prototype._gameOver_confirmUpload = function (ending, norank) {
return;
}
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);
}, function () {
if (main.isCompetition)
@ -160,9 +160,9 @@ events.prototype._gameOver_doUpload = function (username, ending, norank) {
formData.append('type', 'score');
formData.append('name', core.firstData.name);
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('username', core.encodeBase64(username||""));
formData.append('username', core.encodeBase64(username || ""));
formData.append('ending', core.encodeBase64(ending));
formData.append('lv', core.status.hero.lv);
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('experience', core.status.hero.experience);
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('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('base64', 1);
@ -183,7 +183,7 @@ events.prototype._gameOver_doUpload = function (username, ending, norank) {
else
core.http("POST", "/games/upload.php", formData);
setTimeout(function() {
setTimeout(function () {
core.events._gameOver_confirmDownload(ending);
}, 200);
}
@ -198,7 +198,7 @@ events.prototype._gameOver_confirmDownload = function (ending) {
'seed': core.getFlag('__seed__'),
'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);
}, function () {
core.events._gameOver_askRate(ending);
@ -214,11 +214,11 @@ events.prototype._gameOver_askRate = function (ending) {
core.ui.closePanel();
core.ui.drawConfirmBox("恭喜通关本塔,你想进行评分吗?", function () {
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();
}
else {
window.location.href = "/score.php?name="+core.firstData.name+"&num=10";
window.location.href = "/score.php?name=" + core.firstData.name + "&num=10";
}
}, function () {
core.restart();
@ -241,9 +241,9 @@ events.prototype.unregisterSystemEvent = function (type) {
////// 执行一个系统事件 //////
events.prototype.doSystemEvent = function (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 {
main.log("未知的系统事件: "+type+"");
main.log("未知的系统事件: " + type + "");
if (callback) callback();
}
}
@ -263,7 +263,7 @@ events.prototype._trigger = function (x, y) {
if (trigger == 'ski') core.status.isSkiing = true;
// 转换楼层能否穿透
if (trigger=='changeFloor' && !noPass && this._trigger_ignoreChangeFloor(block))
if (trigger == 'changeFloor' && !noPass && this._trigger_ignoreChangeFloor(block))
return;
core.status.automaticRoute.moveDirectly = false;
this.doSystemEvent(trigger, block, function () {
@ -276,17 +276,17 @@ events.prototype._trigger = function (x, y) {
events.prototype._trigger_ignoreChangeFloor = function (block) {
var able = core.flags.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 (core.isReplaying()) {
if (core.status.replay.toReplay[0]=='no') {
if (core.status.replay.toReplay[0] == 'no') {
core.status.replay.toReplay.shift();
core.status.route.push("no");
return true;
}
}
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");
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);
}
@ -353,7 +353,7 @@ events.prototype._openDoor_check = function (id, x, y, needKey) {
var key = id.replace("Door", "Key");
if (!core.hasItem(key)) {
if (key != "specialKey")
core.drawTip("你没有" + ((core.material.items[key]||{}).name||"钥匙"));
core.drawTip("你没有" + ((core.material.items[key] || {}).name || "钥匙"));
else core.drawTip("无法开启此门");
core.clearContinueAutomaticRoute();
return false;
@ -388,7 +388,7 @@ events.prototype._openDoor_animate = function (id, 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) {
@ -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;
var nextX = core.nextX(), nextY = core.nextY();
var block = core.getBlock(nextX, nextY);
if (block==null) return false;
if (block.block.event.trigger=='getItem') {
if (block == null) return false;
if (block.block.event.trigger == 'getItem') {
core.status.route.push("getNext");
this.getItem(block.block.event.id, 1, nextX, nextY);
return true;
@ -432,7 +432,7 @@ events.prototype._sys_changeFloor = function (data, callback) {
heroLoc = {'x': data.loc[0], 'y': data.loc[1]};
if (core.isset(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);
}
@ -450,7 +450,7 @@ events.prototype.changeFloor = function (floorId, stair, heroLoc, time, callback
core.lockControl();
core.stopAutomaticRoute();
core.clearContinueAutomaticRoute();
core.status.replay.animate=true;
core.status.replay.animate = true;
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) {
floorId = floorId || core.status.floorId;
if (floorId == ':before') {
var index=core.floorIds.indexOf(core.status.floorId);
if (index>0) floorId = core.floorIds[index-1];
else floorId=core.status.floorId;
var index = core.floorIds.indexOf(core.status.floorId);
if (index > 0) floorId = core.floorIds[index - 1];
else floorId = core.status.floorId;
}
else if (floorId == ':next') {
var index=core.floorIds.indexOf(core.status.floorId);
if (index<core.floorIds.length-1) floorId = core.floorIds[index+1];
else floorId=core.status.floorId;
var index = core.floorIds.indexOf(core.status.floorId);
if (index < core.floorIds.length - 1) floorId = core.floorIds[index + 1];
else floorId = core.status.floorId;
}
if (!core.status.maps[floorId]) {
main.log("不存在的楼层:"+floorId);
main.log("不存在的楼层:" + floorId);
return null;
}
if (main.mode != 'play' || core.isReplaying()) time = 0;
if (!core.isset(time)) time = core.values.floorChangeTime;
if (!core.isset(time)) time = 800;
if (time<100) time = 0;
if (time < 100) time = 0;
time /= 20;
return {
@ -538,7 +538,7 @@ events.prototype._changeFloor_changing = function (info, callback) {
events.prototype._changeFloor_afterChange = function (info, callback) {
core.unLockControl();
core.status.replay.animate=false;
core.status.replay.animate = false;
core.events.afterChangeFloor(info.floorId, info.fromLoad);
if (callback) callback();
@ -550,7 +550,7 @@ events.prototype.changingFloor = function (floorId, heroLoc, fromLoad) {
////// 转换楼层结束的事件 //////
events.prototype.afterChangeFloor = function (floorId, fromLoad) {
if (main.mode!='play') return;
if (main.mode != 'play') return;
return this.eventdata.afterChangeFloor(floorId, fromLoad);
}
@ -573,15 +573,15 @@ events.prototype._sys_passNet = function (data, callback) {
events.prototype.passNet = function (data) {
if (core.hasItem('shoes')) return;
// 血网 lavaNet 移动到 checkBlock 中处理
if (data.event.id=='poisonNet') { // 毒网
if (data.event.id == 'poisonNet') { // 毒网
core.setFlag('debuff', 'poison');
core.insertAction('毒衰咒处理');
}
else if (data.event.id=='weakNet') { // 衰网
else if (data.event.id == 'weakNet') { // 衰网
core.setFlag('debuff', 'weak');
core.insertAction('毒衰咒处理');
}
else if (data.event.id=='curseNet') { // 咒网
else if (data.event.id == 'curseNet') { // 咒网
core.setFlag('debuff', 'curse');
core.insertAction('毒衰咒处理');
}
@ -595,7 +595,7 @@ events.prototype._sys_pushBox = function (data, callback) {
////// 推箱子 //////
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'),
@ -606,9 +606,9 @@ events.prototype.pushBox = function (data) {
var nextId = core.getBlockId(nx, ny);
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);
else
core.setBlock(168, data.x, data.y);
@ -621,7 +621,7 @@ events.prototype._pushBox_moveHero = function (direction) {
core.status.replay.animate = true;
core.lockControl();
setTimeout(function () {
core.moveHero(direction, function() {
core.moveHero(direction, function () {
core.status.replay.animate = false;
core.status.route.pop();
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;
core.setBlock(core.getNumberById('darkLight'), x, y);
this.afterChangeLight(x,y);
this.afterChangeLight(x, y);
}
////// 改变亮灯之后,可以触发的事件 //////
events.prototype.afterChangeLight = function (x,y) {
return this.eventdata.afterChangeLight(x,y);
events.prototype.afterChangeLight = function (x, y) {
return this.eventdata.afterChangeLight(x, y);
}
events.prototype._sys_ski = function (data, callback) {
@ -665,16 +665,16 @@ events.prototype._sys_ski = function (data, callback) {
events.prototype.ski = function (direction) {
if (!core.isset(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.status.event.id='ski';
core.status.event.id = 'ski';
core.events.ski(direction);
});
}
else {
core.moveHero(direction, function () {
if (core.status.event.id=='ski' && !core.status.isSkiing) {
core.status.event.id=null;
if (core.status.event.id == 'ski' && !core.status.isSkiing) {
core.status.event.id = null;
core.unLockControl();
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;
// 检查是否需要改变朝向
if (ex == core.nextX() && ey == core.nextY()) {
var dir = {"up":"down","down":"up","left":"right","right":"left"}[core.getHeroLoc('direction')];
var id = data.event.id, toId = (data.event.faceIds||{})[dir];
if (core.isset(toId) && id!=toId) {
var dir = {"up": "down", "down": "up", "left": "right", "right": "left"}[core.getHeroLoc('direction')];
var id = data.event.id, toId = (data.event.faceIds || {})[dir];
if (core.isset(toId) && id != toId) {
var number = core.icons.getNumberById(toId);
if (number>0)
if (number > 0)
core.setBlock(number, ex, ey);
}
}
@ -715,9 +715,9 @@ events.prototype.unregisterEvent = function (type) {
events.prototype.doEvent = function (data, x, y, prefix) {
var type = data.type;
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 {
core.insertAction("未知的自定义事件: "+type+"");
core.insertAction("未知的自定义事件: " + type + "");
core.doAction();
}
}
@ -730,7 +730,7 @@ events.prototype.doEvents = function (list, x, y, callback) {
}
this.setEvents(list, x, y, callback);
// 停止勇士
core.waitHeroToStop(function() {
core.waitHeroToStop(function () {
core.lockControl();
core.doAction();
});
@ -747,7 +747,7 @@ events.prototype.setEvents = function (list, x, y, callback) {
}
////// 执行当前自定义事件列表中的下一个事件 //////
events.prototype.doAction = function() {
events.prototype.doAction = function () {
// 清空boxAnimate和UI层
core.status.boxAnimateObjs = [];
clearInterval(core.status.event.interval);
@ -757,7 +757,7 @@ events.prototype.doAction = function() {
if (this._doAction_finishEvents()) return;
// 当前点坐标和前缀
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];
if (this._popEvents(current, prefix)) return;
// 当前要执行的事件
@ -772,7 +772,7 @@ events.prototype.doAction = 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;
core.ui.closePanel();
if (core.isset(callback))
@ -851,7 +851,7 @@ events.prototype.__action_getLoc = function (loc, x, y, prefix) {
x = core.calValue(loc[0], prefix);
y = core.calValue(loc[1], prefix);
}
return [x,y];
return [x, y];
}
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) {
["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) {
if (core.isset(data[t]) && (data[t] instanceof Array) && data[t].length>=3) {
if (data[t].length==3) data[t].push(1);
core.status.textAttribute[t]=data[t];
if (core.isset(data[t]) && (data[t] instanceof Array) && data[t].length >= 3) {
if (data[t].length == 3) data[t].push(1);
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]];
if (core.isset(img) && img.width==192 && img.height==128) {
core.status.textAttribute[t]=data[t];
if (core.isset(img) && img.width == 192 && img.height == 128) {
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) {
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);
}
else {
@ -935,7 +935,7 @@ events.prototype._action_show = function (data, x, y, prefix) {
events.prototype._action_hide = function (data, 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) {
core.hideBlock(t[0], t[1], data.floorId);
});
@ -943,7 +943,7 @@ events.prototype._action_hide = function (data, x, y, prefix) {
}
else {
data.loc.forEach(function (t) {
core.removeBlock(t[0],t[1],data.floorId)
core.removeBlock(t[0], t[1], data.floorId)
});
core.doAction();
}
@ -1016,7 +1016,7 @@ events.prototype._action_jumpHero = function (data, x, y, prefix) {
events.prototype._action_changeFloor = function (data, x, y, prefix) {
var loc = this.__action_getHeroLoc(data.loc, prefix);
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.doAction();
});
@ -1071,7 +1071,7 @@ events.prototype._action_setFg = function (data, x, y, prefix) {
core.doAction();
}
else {
core.setFg(data.color, data.time, function() {
core.setFg(data.color, data.time, function () {
core.setFlag('__color__', data.color || null);
core.doAction();
});
@ -1113,7 +1113,7 @@ events.prototype._action_useItem = function (data, x, y, prefix) {
core.useItem(data.id, true, core.doAction);
}
else {
core.drawTip("当前无法使用"+((core.material.items[data.id]||{}).name||"未知道具"));
core.drawTip("当前无法使用" + ((core.material.items[data.id] || {}).name || "未知道具"));
core.doAction();
}
}
@ -1163,7 +1163,7 @@ events.prototype._action_insert = function (data, x, y, prefix) {
else {
var loc = this.__action_getLoc(data.loc, x, y, prefix);
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.data)) event = event.data;
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) {
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);
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) {
var value = this.__action_getInput(data.text, false);
if (value == null) return;
value = Math.abs(parseInt(value)||0);
value = Math.abs(parseInt(value) || 0);
core.status.route.push("input:" + value);
core.setFlag("input", value);
core.doAction();
@ -1266,19 +1266,19 @@ events.prototype._action_input2 = function (data, x, y, prefix) {
}
events.prototype.__action_getInput = function (hint, isText) {
var value, prefix = isText?"input2:":"input:";
var value, prefix = isText ? "input2:" : "input:";
if (core.isReplaying()) {
var action = core.status.replay.toReplay.shift();
try {
if (action.indexOf(prefix)!=0)
throw new Error("录像文件出错!当前需要一个 "+prefix+" 项,实际为 "+action);
if (action.indexOf(prefix) != 0)
throw new Error("录像文件出错!当前需要一个 " + prefix + " 项,实际为 " + action);
if (isText) value = core.decodeBase64(action.substring(7));
else value = parseInt(action.substring(6));
}
catch (e) {
main.log(e);
core.stopReplay();
core.insertAction(["录像文件出错,请在控制台查看报错信息。", {"type":"exit"}]);
core.insertAction(["录像文件出错,请在控制台查看报错信息。", {"type": "exit"}]);
core.doAction();
return null;
}
@ -1286,7 +1286,7 @@ events.prototype.__action_getInput = function (hint, isText) {
else {
core.interval.onDownInterval = 'tmp';
value = prompt(core.replaceText(hint));
if (!core.isset(value)) value="";
if (!core.isset(value)) value = "";
}
return value;
}
@ -1316,18 +1316,18 @@ events.prototype._action_choices = function (data, x, y, prefix) {
var action = core.status.replay.toReplay.shift(), index;
// --- 忽略可能的turn事件
if (action == 'turn') action = core.status.replay.toReplay.shift();
if (action.indexOf("choices:")==0 && ((index=parseInt(action.substring(8)))>=0) && index<data.choices.length) {
core.status.event.selection=index;
if (action.indexOf("choices:") == 0 && ((index = parseInt(action.substring(8))) >= 0) && index < data.choices.length) {
core.status.event.selection = index;
setTimeout(function () {
core.status.route.push("choices:"+index);
core.status.route.push("choices:" + index);
core.insertAction(data.choices[index].action);
core.doAction();
}, 750 / Math.max(1, core.status.replay.speed))
}
else {
main.log("录像文件出错!当前需要一个 choices: 项,实际为 "+action);
main.log("录像文件出错!当前需要一个 choices: 项,实际为 " + action);
core.stopReplay();
core.insertAction(["录像文件出错,请在控制台查看报错信息。", {"type":"exit"}]);
core.insertAction(["录像文件出错,请在控制台查看报错信息。", {"type": "exit"}]);
core.doAction();
return;
}
@ -1370,8 +1370,8 @@ events.prototype._action_lose = function (data, x, y, prefix) {
events.prototype._action_function = function (data, x, y, prefix) {
var func = data["function"];
try {
if (typeof func == "string" && func.indexOf("function")==0) {
eval('('+func+')()');
if (typeof func == "string" && func.indexOf("function") == 0) {
eval('(' + func + ')()');
}
} catch (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) {
core.timeout.sleepTimeout = setTimeout(function() {
core.timeout.sleepTimeout = setTimeout(function () {
core.timeout.sleepTimeout = null;
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) {
if (core.isReplaying()) {
var code = core.status.replay.toReplay.shift();
if (code.indexOf("input:")==0) {
if (code.indexOf("input:") == 0) {
var value = parseInt(code.substring(6));
core.status.route.push("input:"+value);
core.status.route.push("input:" + value);
this.__action_wait_getValue(value);
}
else {
main.log("录像文件出错!当前需要一个 input: 项,实际为 "+code);
main.log("录像文件出错!当前需要一个 input: 项,实际为 " + code);
core.stopReplay();
core.insertAction(["录像文件出错,请在控制台查看报错信息。", {"type":"exit"}]);
core.insertAction(["录像文件出错,请在控制台查看报错信息。", {"type": "exit"}]);
}
core.doAction();
return;
@ -1515,7 +1515,7 @@ events.prototype._action_exit = function (data, x, y, prefix) {
events.prototype.follow = function (name) {
core.status.hero.followers = core.status.hero.followers || [];
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.control.gatherFollowers();
core.clearMap('hero');
@ -1594,8 +1594,8 @@ events.prototype._setValue_setFlag = function (name, value) {
}
events.prototype._setValue_setSwitch = function (name, value, prefix) {
if (name.indexOf("switch:") !==0 ) return;
core.setFlag((prefix||"f@x@y")+"@"+data.name.substring(7), value);
if (name.indexOf("switch:") !== 0) return;
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) {
if (typeof value == 'string') {
if ((value.charAt(0)=='"' && value.charAt(value.length-1)=='"')
|| (value.charAt(0)=="'" && value.charAt(value.length-1)=="'"))
value = value.substring(1, value.length-1);
if ((value.charAt(0) == '"' && value.charAt(value.length - 1) == '"')
|| (value.charAt(0) == "'" && value.charAt(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);
}
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;
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);
ctx.drawImage(image, 0, 0, image.width * dw, image.height * dh);
if (time == 0) {
@ -1678,7 +1678,7 @@ events.prototype.hideImage = function (code, time, callback) {
events.prototype.moveImage = function (code, to, opacityVal, time, callback) {
time = time || 1000;
to = to || [];
var name = "image"+ (code+100);
var name = "image" + (code + 100);
if (!core.dymCanvas[name]) {
if (callback) callback();
return;
@ -1699,16 +1699,16 @@ events.prototype.moveImage = function (code, to, opacityVal, time, 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 fromX = moveInfo.fromX, fromY = moveInfo.fromY, toX = moveInfo.toX, toY = moveInfo.toY,
opacity = moveInfo.opacity, toOpacity = moveInfo.toOpacity;
var currX = fromX, currY = fromY, currOpacity = opacity;
var animate = setInterval(function () {
step++;
currOpacity = opacity + (toOpacity-opacity)*step/steps;
currX = parseInt(fromX + (toX-fromX)*step/steps);
currY = parseInt(fromY + (toY-fromY)*step/steps);
currOpacity = opacity + (toOpacity - opacity) * step / steps;
currX = parseInt(fromX + (toX - fromX) * step / steps);
currY = parseInt(fromY + (toY - fromY) * step / steps);
core.setOpacity(name, currOpacity);
core.relocateCanvas(name, currX, currY);
if (step == steps) {
@ -1728,7 +1728,7 @@ events.prototype.setVolume = function (value, time, callback) {
if (core.musicStatus.playingBgm)
core.material.bgms[core.musicStatus.playingBgm].volume = value;
}
if (!core.isset(time) || time<100) {
if (!core.isset(time) || time < 100) {
set(value);
if (callback) callback();
return;
@ -1737,8 +1737,8 @@ events.prototype.setVolume = function (value, time, callback) {
var per_time = 10, step = 0, steps = parseInt(time / per_time);
var fade = setInterval(function () {
step++;
set(currVolume+(value-currVolume)*step/steps);
if (step>=steps) {
set(currVolume + (value - currVolume) * step / steps);
if (step >= steps) {
delete core.animateFrame.asyncId[fade];
clearInterval(fade);
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 (callback) callback();
return;
}
if (!core.isset(time) || time<1000) time=1000;
if (!core.isset(time) || time < 1000) time = 1000;
// --- 将time调整为500的倍数上整不然会出错
time = Math.ceil(time / 500) * 500;
var shakeInfo = { duration: time * 3 / 50, speed: 5, power: 5, direction: 1, shake: 0 };
var animate=setInterval(function(){
var shakeInfo = {duration: time * 3 / 50, speed: 5, power: 5, direction: 1, shake: 0};
var animate = setInterval(function () {
core.events._vibrate_update(shakeInfo);
core.control.addGameCanvasTranslate(shakeInfo.shake, 0);
if(shakeInfo.duration===0) {
if (shakeInfo.duration === 0) {
delete core.animateFrame.asyncId[animate];
clearInterval(animate);
if (callback) callback();
@ -1771,33 +1771,33 @@ events.prototype.vibrate = function(time, callback) {
}
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;
if(shakeInfo.duration <= 1 && shakeInfo.shake * (shakeInfo.shake + delta) < 0){
if (shakeInfo.duration <= 1 && shakeInfo.shake * (shakeInfo.shake + delta) < 0) {
shakeInfo.shake = 0;
}else{
} else {
shakeInfo.shake += delta;
}
if(shakeInfo.shake > shakeInfo.power * 2){
if (shakeInfo.shake > shakeInfo.power * 2) {
shakeInfo.direction = -1;
}
if(shakeInfo.shake < - shakeInfo.power * 2){
if (shakeInfo.shake < -shakeInfo.power * 2) {
shakeInfo.direction = 1;
}
if(shakeInfo.duration >= 1){
if (shakeInfo.duration >= 1) {
shakeInfo.duration -= 1
}
}
}
////// 打开一个全局商店 //////
events.prototype.openShop = function(shopId, needVisited) {
events.prototype.openShop = function (shopId, needVisited) {
var shop = core.status.shops[shopId];
shop.times = shop.times || 0;
if (shop.commonTimes) shop.times = core.getFlag('commonTimes', 0);
if (needVisited && !shop.visited) {
if (!core.flags.enableDisabledShop) {
if (shop.times==0) core.drawTip("该商店尚未开启");
if (shop.times == 0) core.drawTip("该商店尚未开启");
else core.drawTip("该商店已失效");
return;
}
@ -1817,9 +1817,9 @@ events.prototype._useShop = function (shop, index) {
return false;
}
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)) {
core.drawTip("你的"+(use=='money'?"金币":"经验")+"不足");
core.drawTip("你的" + (use == 'money' ? "金币" : "经验") + "不足");
return false;
}
core.status.event.selection = index;
@ -1834,8 +1834,8 @@ events.prototype._useShop = function (shop, index) {
}
events.prototype._exitShop = function () {
if (core.status.event.data.actions.length>0) {
core.status.route.push("shop:"+core.status.event.data.id+":"+core.status.event.data.actions.join(""));
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.event.data.actions = [];
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);
}
@ -1861,7 +1861,7 @@ events.prototype.setHeroIcon = function (name, noDraw) {
if (!img || img.width != 128) return;
core.setFlag("heroIcon", name);
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);
if (!noDraw) core.drawHero();
}
@ -1876,35 +1876,35 @@ events.prototype.checkLvUp = function () {
if (next == null) break;
actions = actions.concat(next);
}
if (actions.length>0) core.insertAction(actions);
if (actions.length > 0) core.insertAction(actions);
}
events.prototype._checkLvUp_check = function () {
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);
if (!core.isset(need)) return null;
if (core.status.hero.experience>=need) {
if (core.status.hero.experience >= need) {
// 升级
core.status.hero.lv++;
if (next.clear) core.status.hero.experience -= need;
return next.action||[];
return next.action || [];
}
return null;
}
////// 尝试使用道具 //////
events.prototype.tryUseItem = function(itemId) {
events.prototype.tryUseItem = function (itemId) {
core.ui.closePanel();
if (itemId=='book') return core.openBook(false);
if (itemId=='fly') return core.useFly(false);
if (itemId=='centerFly') return core.ui.drawCenterFly();
if (itemId == 'book') return core.openBook(false);
if (itemId == 'fly') return core.useFly(false);
if (itemId == 'centerFly') return core.ui.drawCenterFly();
if (core.canUseItem(itemId))core.useItem(itemId);
else core.drawTip("当前无法使用"+core.material.items[itemId].name);
if (core.canUseItem(itemId)) core.useItem(itemId);
else core.drawTip("当前无法使用" + core.material.items[itemId].name);
}
////// 使用炸弹/圣锤后的事件 //////
@ -1929,9 +1929,9 @@ events.prototype.uploadCurrent = function (username) {
formData.append('type', 'score');
formData.append('name', core.firstData.name);
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('username', core.encodeBase64(username||"current"));
formData.append('username', core.encodeBase64(username || "current"));
formData.append('lv', core.status.hero.lv);
formData.append('hp', Math.min(core.status.hero.hp, Math.pow(2, 63)));
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('steps', core.status.hero.steps);
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('deler', 'current');
formData.append('base64', 1);

View File

@ -26,14 +26,14 @@ icons.prototype.getClsFromId = function (id) {
}
icons.prototype._getAnimateFrames = function (cls, useOriginValue) {
if (cls=='enemys' || cls=='npcs') {
if (cls == 'enemys' || cls == 'npcs') {
return 2;
}
if (cls == 'animates' || cls == 'enemy48') {
return 4;
}
if (cls == 'npc48') {
return useOriginValue? 4 : 1;
return useOriginValue ? 4 : 1;
}
return 1;
}
@ -55,9 +55,9 @@ icons.prototype.getTilesetOffset = function (id) {
for (var i in core.tilesets) {
var imgName = core.tilesets[i];
var img = core.material.images.tilesets[imgName];
var width = Math.floor(img.width/32), height = Math.floor(img.height/32);
if (id>=startOffset && id<startOffset+width*height) {
var x = (id-startOffset)%width, y = parseInt((id-startOffset)/width);
var width = Math.floor(img.width / 32), height = Math.floor(img.height / 32);
if (id >= startOffset && id < startOffset + width * height) {
var x = (id - startOffset) % width, y = parseInt((id - startOffset) / width);
return {"image": imgName, "x": x, "y": y};
}
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;
// 消耗品
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;
// 消耗品
if (itemCls === 'items') {
var ratio = parseInt(core.status.thisMap.item_ratio) || 1;
if (itemId in this.itemEffectTip) {
try {
return eval(this.itemEffectTip[itemId])||"";
return eval(this.itemEffectTip[itemId]) || "";
} catch (e) {
main.log(e);
return "";
@ -72,7 +72,7 @@ items.prototype.useItem = function (itemId, noRoute, callback) {
// 执行完毕
this._afterUseItem(itemId);
// 记录路线
if (!noRoute) core.status.route.push("item:"+itemId);
if (!noRoute) core.status.route.push("item:" + itemId);
if (core.isset(callback)) callback();
}
@ -91,9 +91,9 @@ items.prototype._useItemEffect = function (itemId) {
items.prototype._afterUseItem = function (itemId) {
// 道具使用完毕:删除
var itemCls = core.material.items[itemId].cls;
if (itemCls=='tools')
if (itemCls == 'tools')
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];
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(itemId) || !core.isset(core.material.items[itemId])) return 0;
var itemCls = core.material.items[itemId].cls;
if (itemCls=="items") return 0;
return core.status.hero.items[itemCls][itemId]||0;
if (itemCls == "items") return 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(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)
return true;
return false
@ -155,7 +155,7 @@ items.prototype.hasEquip = function (itemId) {
////// 获得某个装备类型的当前装备 //////
items.prototype.getEquip = function (equipType) {
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;
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;
}
core.updateStatusBar();
@ -181,9 +181,9 @@ items.prototype.removeItem = function (itemId, itemNum) {
if (!core.isset(itemNum)) itemNum = 1;
if (!core.hasItem(itemId)) return false;
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 (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;
}
core.updateStatusBar();
@ -206,11 +206,11 @@ items.prototype.addItem = function (itemId, itemNum) {
}
core.status.hero.items[itemCls][itemId] += itemNum;
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;
}
// 永久道具只能有一个
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.updateStatusBar();
}
@ -227,7 +227,7 @@ items.prototype.getEquipTypeById = function (equipId) {
items.prototype.getEquipTypeByName = function (name) {
var names = core.status.globalAttribute.equipName;
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;
}
}
@ -237,7 +237,7 @@ items.prototype.getEquipTypeByName = function (name) {
// 当前能否撞上某装备
items.prototype.canEquip = function (equipId, hint) {
// 装备是否合法
var equip = core.material.items[equipId]||{};
var equip = core.material.items[equipId] || {};
if (!core.isset(equip.equip)) {
if (hint) core.drawTip("不合法的装备!");
return false;
@ -245,16 +245,16 @@ items.prototype.canEquip = function (equipId, hint) {
// 是否拥有该装备
if (!core.hasItem(equipId) && !core.hasEquip(equipId)) {
if (hint) core.drawTip("你当前没有"+equip.name+",无法换装");
if (hint) core.drawTip("你当前没有" + equip.name + ",无法换装");
return false;
}
// 可装备条件
var condition = this.equipCondition[equipId];
if (core.isset(condition) && condition.length>0) {
if (core.isset(condition) && condition.length > 0) {
try {
if (!eval(condition)) {
if (hint) core.drawTip("当前不可换上"+equip.name);
if (hint) core.drawTip("当前不可换上" + equip.name);
return false;
}
}
@ -278,7 +278,7 @@ items.prototype.loadEquip = function (equipId, callback) {
var loadEquip = core.material.items[equipId] || {};
var type = this.getEquipTypeById(equipId);
if (type < 0) {
core.drawTip("当前没有"+loadEquip.equip.type+"的空位!");
core.drawTip("当前没有" + loadEquip.equip.type + "的空位!");
if (core.isset(callback)) callback();
return;
}
@ -304,17 +304,17 @@ items.prototype.compareEquipment = function (compareEquipId, beComparedEquipId)
var compareAtk = 0, compareDef = 0, compareMdef = 0;
if (core.isset(compareEquipId)) {
var compareEquip = core.material.items[compareEquipId];
compareAtk += (compareEquip.equip||{}).atk || 0;
compareDef += (compareEquip.equip||{}).def || 0;
compareMdef += (compareEquip.equip||{}).mdef || 0;
compareAtk += (compareEquip.equip || {}).atk || 0;
compareDef += (compareEquip.equip || {}).def || 0;
compareMdef += (compareEquip.equip || {}).mdef || 0;
}
if (core.isset(beComparedEquipId)) {
var beComparedEquip = core.material.items[beComparedEquipId];
compareAtk -= (beComparedEquip.equip||{}).atk || 0;
compareDef -= (beComparedEquip.equip||{}).def || 0;
compareMdef -= (beComparedEquip.equip||{}).mdef || 0;
compareAtk -= (beComparedEquip.equip || {}).atk || 0;
compareDef -= (beComparedEquip.equip || {}).def || 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) {
for (var v in result)
core.addFlag('__'+v+'_buff__', result[v]/100);
core.addFlag('__' + v + '_buff__', result[v] / 100);
}
else {
for (var v in result)
@ -350,16 +350,16 @@ items.prototype._realLoadEquip = function (type, loadId, unloadId, callback) {
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 (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]);
else if (unloadId) core.drawTip("已卸下"+unloadEquip.name, core.material.icons.items[unloadId]);
if (loadId) core.drawTip("已装备上" + loadEquip.name, core.material.icons.items[loadId]);
else if (unloadId) core.drawTip("已卸下" + unloadEquip.name, core.material.icons.items[unloadId]);
if (core.isset(callback)) callback();
}
@ -370,38 +370,38 @@ items.prototype.quickSaveEquip = function (index) {
var saveEquips = core.getFlag("saveEquips", []);
saveEquips[index] = core.clone(core.status.hero.equipment);
core.setFlag("saveEquips", saveEquips);
core.drawTip("已保存"+index+"号套装");
core.drawTip("已保存" + index + "号套装");
}
////// 读取装备 //////
items.prototype.quickLoadEquip = function (index) {
var current = core.getFlag("saveEquips", [])[index];
if (!core.isset(current)) {
core.drawTip(index+"号套装不存在");
core.drawTip(index + "号套装不存在");
return;
}
// 检查所有的装备
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];
if (core.isset(v) && !this.canEquip(v, true))
return;
}
// 快速换装
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;
if (now != null) {
this.unloadEquip(i);
core.status.route.push("unEquip:" + i);
}
}
for (var i=0;i<equipSize;i++) {
var to = current[i]||null;
if (to!=null) {
for (var i = 0; i < equipSize; i++) {
var to = current[i] || null;
if (to != null) {
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 = {};
var images = core.clone(core.images);
if (images.indexOf("hero.png")<0)
if (images.indexOf("hero.png") < 0)
images.push("hero.png");
this.loadImages(images, core.material.images.images, callback);
@ -87,11 +87,11 @@ loader.prototype._loadTilesets = function (callback) {
// 检查宽高是32倍数如果出错在控制台报错
for (var imgName in core.material.images.tilesets) {
var img = core.material.images.tilesets[imgName];
if (img.width%32!=0 || img.height%32!=0) {
console.warn("警告!"+imgName+"的宽或高不是32的倍数");
if (img.width % 32 != 0 || img.height % 32 != 0) {
console.warn("警告!" + imgName + "的宽或高不是32的倍数");
}
if (img.width * img.height > 32*32*3000) {
console.warn("警告!"+imgName+"上的图块素材个数大于3000");
if (img.width * img.height > 32 * 32 * 3000) {
console.warn("警告!" + imgName + "上的图块素材个数大于3000");
}
}
callback();
@ -99,12 +99,12 @@ loader.prototype._loadTilesets = function (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();
return;
}
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) {
core.loader._setStartLoadTipText('正在加载图片 ' + id + "...");
toSave[id] = image;
@ -119,9 +119,9 @@ loader.prototype.loadImages = function (names, toSave, callback) {
loader.prototype.loadImage = function (imgName, callback) {
try {
var name=imgName;
if (name.indexOf(".")<0)
name=name+".png";
var name = imgName;
if (name.indexOf(".") < 0)
name = name + ".png";
var image = new Image();
image.onload = function () {
callback(imgName, image);
@ -204,15 +204,15 @@ loader.prototype._loadMusic = function () {
loader.prototype.loadOneMusic = function (name) {
var music = new Audio();
music.preload = 'none';
if (main.bgmRemote) music.src = main.bgmRemoteRoot+core.firstData.name+'/'+name;
else music.src = 'project/sounds/'+name;
if (main.bgmRemote) music.src = main.bgmRemoteRoot + core.firstData.name + '/' + name;
else music.src = 'project/sounds/' + name;
music.loop = 'loop';
core.material.bgms[name] = music;
}
loader.prototype.loadOneSound = function (name) {
if (core.musicStatus.audioContext != null) {
core.http('GET', 'project/sounds/'+name, null, function (data) {
core.http('GET', 'project/sounds/' + name, null, function (data) {
try {
core.musicStatus.audioContext.decodeAudioData(data, function (buffer) {
core.material.sounds[name] = buffer;
@ -232,7 +232,7 @@ loader.prototype.loadOneSound = function (name) {
}
else {
var music = new Audio();
music.src = 'project/sounds/'+name;
music.src = 'project/sounds/' + name;
core.material.sounds[name] = music;
}
}
@ -243,7 +243,7 @@ loader.prototype.loadBgm = function (name) {
if (!core.musicStatus.bgmStatus) return;
// 是否已经预加载过
var index = core.musicStatus.cachedBgms.indexOf(name);
if (index>=0) {
if (index >= 0) {
core.musicStatus.cachedBgms.splice(index, 1);
}
else {
@ -267,7 +267,9 @@ loader.prototype._preloadBgm = function (bgm) {
loader.prototype.freeBgm = function (name) {
if (!core.isset(core.material.bgms[name])) return;
// 从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].load();

View File

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

View File

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