给libs加上类型标注

This commit is contained in:
unanmed 2022-12-29 23:08:44 +08:00
parent a1a6539583
commit 3ca3a7c3f9
14 changed files with 748 additions and 2973 deletions

View File

@ -1,3 +1,5 @@
///<reference path="../../src/types/core.d.ts" />
/* /*
actions.js用户交互的事件的处理 actions.js用户交互的事件的处理
键盘鼠标触摸屏事件相关 键盘鼠标触摸屏事件相关

View File

@ -1,3 +1,5 @@
///<reference path="../../src/types/core.d.ts" />
/* /*
control.js游戏主要逻辑控制 control.js游戏主要逻辑控制
主要负责status相关内容以及各种变量获取/存储 主要负责status相关内容以及各种变量获取/存储

View File

@ -1,16 +1,17 @@
///<reference path="../../src/types/core.d.ts" />
/** /**
* 初始化 start * 初始化 start
*/ */
"use strict"; 'use strict';
// /** // /**
// * @type {CoreMixin} // * @type {CoreMixin}
// */ // */
// const core = (() => { // const core = (() => {
function core () { function core() {
this._WIDTH_ = 15; this._WIDTH_ = 15;
this._HEIGHT_ = 15; this._HEIGHT_ = 15;
this._PX_ = this._WIDTH_ * 32; this._PX_ = this._WIDTH_ * 32;
@ -22,96 +23,96 @@ function core () {
this.__PIXELS__ = this.__SIZE__ * 32; this.__PIXELS__ = this.__SIZE__ * 32;
this.__HALF_SIZE__ = Math.floor(this.__SIZE__ / 2); this.__HALF_SIZE__ = Math.floor(this.__SIZE__ / 2);
this.material = { this.material = {
'animates': {}, animates: {},
'images': {}, images: {},
'bgms': {}, bgms: {},
'sounds': {}, sounds: {},
'items': {}, items: {},
'enemys': {}, enemys: {},
'icons': {}, icons: {},
'ground': null, ground: null,
'grundCanvas': null, grundCanvas: null,
'groundPattern': null, groundPattern: null,
'autotileEdges': {}, autotileEdges: {}
} };
this.timeout = { this.timeout = {
'turnHeroTimeout': null, turnHeroTimeout: null,
'onDownTimeout': null, onDownTimeout: null,
'sleepTimeout': null, sleepTimeout: null
} };
this.interval = { this.interval = {
'heroMoveInterval': null, heroMoveInterval: null,
'onDownInterval': null, onDownInterval: null
} };
this.animateFrame = { this.animateFrame = {
'totalTime': 0, totalTime: 0,
'totalTimeStart': 0, totalTimeStart: 0,
'globalAnimate': false, globalAnimate: false,
'globalTime': 0, globalTime: 0,
'selectorTime': 0, selectorTime: 0,
'selectorUp': true, selectorUp: true,
'animateTime': 0, animateTime: 0,
'moveTime': 0, moveTime: 0,
'lastLegTime': 0, lastLegTime: 0,
'leftLeg': true, leftLeg: true,
'weather': { weather: {
'time': 0, time: 0,
'type': null, type: null,
'level': 1, level: 1,
'nodes': [], nodes: [],
'data': null, data: null,
'fog': null, fog: null,
'cloud': null, cloud: null,
'sun': null sun: null
}, },
"tip": null, tip: null,
"asyncId": {}, asyncId: {},
"lastAsyncId": null lastAsyncId: null
} };
this.musicStatus = { this.musicStatus = {
'audioContext': null, // WebAudioContext audioContext: null, // WebAudioContext
'bgmStatus': false, // 是否播放BGM bgmStatus: false, // 是否播放BGM
'soundStatus': true, // 是否播放SE soundStatus: true, // 是否播放SE
'playingBgm': null, // 正在播放的BGM playingBgm: null, // 正在播放的BGM
'pauseTime': 0, // 上次暂停的时间 pauseTime: 0, // 上次暂停的时间
'lastBgm': null, // 上次播放的bgm lastBgm: null, // 上次播放的bgm
'gainNode': null, gainNode: null,
'playingSounds': {}, // 正在播放的SE playingSounds: {}, // 正在播放的SE
'userVolume': 1.0, // 用户音量 userVolume: 1.0, // 用户音量
'designVolume': 1.0, //设计音量 designVolume: 1.0, //设计音量
'bgmSpeed': 100, // 背景音乐速度 bgmSpeed: 100, // 背景音乐速度
'bgmUsePitch': null, // 是否同时修改音调 bgmUsePitch: null, // 是否同时修改音调
'cachedBgms': [], // 缓存BGM内容 cachedBgms: [], // 缓存BGM内容
'cachedBgmCount': 8, // 缓存的bgm数量 cachedBgmCount: 8 // 缓存的bgm数量
} };
this.platform = { this.platform = {
'isOnline': true, // 是否http isOnline: true, // 是否http
'isPC': true, // 是否是PC isPC: true, // 是否是PC
'isAndroid': false, // 是否是Android isAndroid: false, // 是否是Android
'isIOS': false, // 是否是iOS isIOS: false, // 是否是iOS
'string': 'PC', string: 'PC',
'isWeChat': false, // 是否是微信 isWeChat: false, // 是否是微信
'isQQ': false, // 是否是QQ isQQ: false, // 是否是QQ
'isChrome': false, // 是否是Chrome isChrome: false, // 是否是Chrome
'supportCopy': false, // 是否支持复制到剪切板 supportCopy: false, // 是否支持复制到剪切板
'fileInput': null, // FileInput fileInput: null, // FileInput
'fileReader': null, // 是否支持FileReader fileReader: null, // 是否支持FileReader
'successCallback': null, // 读取成功 successCallback: null, // 读取成功
'errorCallback': null, // 读取失败 errorCallback: null // 读取失败
} };
// 样式 // 样式
this.domStyle = { this.domStyle = {
scale: 1.0, scale: 1.0,
ratio: 1.0, ratio: 1.0,
hdCanvas: ["damage", "ui", "data"], hdCanvas: ['damage', 'ui', 'data'],
availableScale: [], availableScale: [],
isVertical: false, isVertical: false,
showStatusBar: true, showStatusBar: true,
toolbarBtn: false, toolbarBtn: false
} };
this.bigmap = { this.bigmap = {
canvas: ["bg", "event", "event2", "fg", "damage"], canvas: ['bg', 'event', 'event2', 'fg', 'damage'],
offsetX: 0, // in pixel offsetX: 0, // in pixel
offsetY: 0, offsetY: 0,
posX: 0, // posX: 0, //
@ -123,140 +124,149 @@ function core () {
extend: 10, extend: 10,
scale: 1.0, scale: 1.0,
tempCanvas: null, // A temp canvas for drawing tempCanvas: null, // A temp canvas for drawing
cacheCanvas: null, // A cache canvas cacheCanvas: null // A cache canvas
} };
this.saves = { this.saves = {
"saveIndex": null, saveIndex: null,
"ids": {}, ids: {},
"autosave": { autosave: {
"data": null, data: null,
"time": 0, time: 0,
"updated": false, updated: false,
"storage": true, // 是否把自动存档写入文件a storage: true, // 是否把自动存档写入文件a
"max": 20, // 自动存档最大回退数 max: 20, // 自动存档最大回退数
"now": 0, now: 0
}, },
"favorite": [], favorite: [],
"favoriteName": {}, favoriteName: {},
"cache": {} cache: {}
} };
this.initStatus = { this.initStatus = {
'played': false, played: false,
'gameOver': false, gameOver: false,
// 勇士属性 // 勇士属性
'hero': {}, hero: {},
'heroCenter': { 'px': null, 'py': null }, heroCenter: { px: null, py: null },
// 当前地图 // 当前地图
'floorId': null, floorId: null,
'thisMap': null, thisMap: null,
'maps': null, maps: null,
'bgmaps': {}, bgmaps: {},
'fgmaps': {}, fgmaps: {},
'mapBlockObjs': {}, mapBlockObjs: {},
'checkBlock': {}, // 每个点的阻激夹域信息 checkBlock: {}, // 每个点的阻激夹域信息
'damage': { // 每个点的显伤绘制 damage: {
'posX': 0, // 每个点的显伤绘制
'posY': 0, posX: 0,
'data': [], posY: 0,
'extraData': [], data: [],
extraData: []
}, },
'lockControl': false, lockControl: false,
// 勇士移动状态 // 勇士移动状态
'heroMoving': 0, heroMoving: 0,
'heroStop': true, heroStop: true,
// 自动寻路相关 // 自动寻路相关
'automaticRoute': { automaticRoute: {
'autoHeroMove': false, autoHeroMove: false,
'autoStep': 0, autoStep: 0,
'movedStep': 0, movedStep: 0,
'destStep': 0, destStep: 0,
'destX': null, destX: null,
'destY': null, destY: null,
'offsetX': null, offsetX: null,
'offsetY': null, offsetY: null,
'autoStepRoutes': [], autoStepRoutes: [],
'moveStepBeforeStop': [], moveStepBeforeStop: [],
'lastDirection': null, lastDirection: null,
'cursorX': 0, cursorX: 0,
'cursorY': 0, cursorY: 0,
"moveDirectly": false, moveDirectly: false
}, },
// 按下键的时间:为了判定双击 // 按下键的时间:为了判定双击
'downTime': null, downTime: null,
'ctrlDown': false, ctrlDown: false,
'preview': { preview: {
'enabled': false, enabled: false,
'prepareDragging': false, prepareDragging: false,
'dragging': false, dragging: false,
'px': 0, px: 0,
'py': 0, py: 0
}, },
// 路线&回放 // 路线&回放
'route': [], route: [],
'replay': { replay: {
'replaying': false, replaying: false,
'pausing': false, pausing: false,
'animate': false, // 正在某段动画中 animate: false, // 正在某段动画中
'failed': false, failed: false,
'toReplay': [], toReplay: [],
'totalList': [], totalList: [],
'speed': 1.0, speed: 1.0,
'steps': 0, steps: 0,
'save': [], save: []
}, },
// 录像折叠 // 录像折叠
'routeFolding': {}, routeFolding: {},
// event事件 // event事件
'shops': {}, shops: {},
'event': { event: {
'id': null, id: null,
'data': null, data: null,
'selection': null, selection: null,
'ui': null, ui: null,
'interval': null, interval: null
}, },
'autoEvents': [], autoEvents: [],
'textAttribute': { textAttribute: {
'position': "center", position: 'center',
"offset": 0, offset: 0,
"title": [255, 215, 0, 1], title: [255, 215, 0, 1],
"background": [0, 0, 0, 0.85], background: [0, 0, 0, 0.85],
"text": [255, 255, 255, 1], text: [255, 255, 255, 1],
"titlefont": 22, titlefont: 22,
"textfont": 16, textfont: 16,
"bold": false, bold: false,
"time": 0, time: 0,
"letterSpacing": 0, letterSpacing: 0,
"animateTime": 0, animateTime: 0
}, },
"globalAttribute": { globalAttribute: {
'equipName': main.equipName || [], equipName: main.equipName || [],
"statusLeftBackground": main.styles.statusLeftBackground || "url(project/materials/ground.png) repeat", statusLeftBackground:
"statusTopBackground": main.styles.statusTopBackground || "url(project/materials/ground.png) repeat", main.styles.statusLeftBackground ||
"toolsBackground": main.styles.toolsBackground || "url(project/materials/ground.png) repeat", 'url(project/materials/ground.png) repeat',
"borderColor": main.styles.borderColor || [204, 204, 204, 1], statusTopBackground:
"statusBarColor": main.styles.statusBarColor || [255, 255, 255, 1], main.styles.statusTopBackground ||
"floorChangingStyle": main.styles.floorChangingStyle || "background-color: black; color: white", 'url(project/materials/ground.png) repeat',
"selectColor": main.styles.selectColor || [255, 215, 0, 1], toolsBackground:
"font": main.styles.font || "Verdana" main.styles.toolsBackground ||
'url(project/materials/ground.png) repeat',
borderColor: main.styles.borderColor || [204, 204, 204, 1],
statusBarColor: main.styles.statusBarColor || [255, 255, 255, 1],
floorChangingStyle:
main.styles.floorChangingStyle ||
'background-color: black; color: white',
selectColor: main.styles.selectColor || [255, 215, 0, 1],
font: main.styles.font || 'Verdana'
}, },
'curtainColor': null, curtainColor: null,
// 动画 // 动画
'globalAnimateObjs': [], globalAnimateObjs: [],
'floorAnimateObjs': [], floorAnimateObjs: [],
'boxAnimateObjs': [], boxAnimateObjs: [],
'autotileAnimateObjs': [], autotileAnimateObjs: [],
"globalAnimateStatus": 0, globalAnimateStatus: 0,
'animateObjs': [], animateObjs: []
}; };
// 标记的楼层列表,用于数据统计 // 标记的楼层列表,用于数据统计
this.markedFloorIds = {}; this.markedFloorIds = {};
@ -265,7 +275,10 @@ function core () {
if (main.mode == 'editor') { if (main.mode == 'editor') {
document.documentElement.style.setProperty('--size', this.__SIZE__); document.documentElement.style.setProperty('--size', this.__SIZE__);
document.documentElement.style.setProperty('--pixel', this.__PIXELS__ + 'px'); document.documentElement.style.setProperty(
'--pixel',
this.__PIXELS__ + 'px'
);
} }
} }
@ -274,8 +287,7 @@ function core () {
////// 初始化 ////// ////// 初始化 //////
core.prototype.init = function (coreData, callback) { core.prototype.init = function (coreData, callback) {
this._forwardFuncs(); this._forwardFuncs();
for (var key in coreData) for (var key in coreData) core[key] = coreData[key];
core[key] = coreData[key];
this._init_flags(); this._init_flags();
this._init_platform(); this._init_platform();
this._init_others(); this._init_others();
@ -284,10 +296,14 @@ core.prototype.init = function (coreData, callback) {
// 初始化画布 // 初始化画布
for (var name in core.canvas) { for (var name in core.canvas) {
if (core.domStyle.hdCanvas.indexOf(name) >= 0) if (core.domStyle.hdCanvas.indexOf(name) >= 0)
core.maps._setHDCanvasSize(core.canvas[name], b ? core.__PIXELS__ : core._PX_, b ? core.__PIXELS__ : core._PY_); core.maps._setHDCanvasSize(
core.canvas[name],
b ? core.__PIXELS__ : core._PX_,
b ? core.__PIXELS__ : core._PY_
);
else { else {
core.canvas[name].canvas.width = (b ? core.__PIXELS__ : core._PX_); core.canvas[name].canvas.width = b ? core.__PIXELS__ : core._PX_;
core.canvas[name].canvas.height = (b ? core.__PIXELS__ : core._PY_); core.canvas[name].canvas.height = b ? core.__PIXELS__ : core._PY_;
} }
} }
@ -298,7 +314,7 @@ core.prototype.init = function (coreData, callback) {
}); });
core.dom.musicBtn.style.display = 'block'; core.dom.musicBtn.style.display = 'block';
core.setMusicBtn(); core.setMusicBtn();
} };
core.prototype._init_flags = function () { core.prototype._init_flags = function () {
core.flags = core.clone(core.data.flags); core.flags = core.clone(core.data.flags);
@ -314,9 +330,11 @@ core.prototype._init_flags = function () {
core.dom.versionLabel.innerText = core.firstData.version; core.dom.versionLabel.innerText = core.firstData.version;
core.dom.logoLabel.innerText = core.firstData.title; core.dom.logoLabel.innerText = core.firstData.title;
document.title = core.firstData.title + " - HTML5魔塔"; document.title = core.firstData.title + ' - HTML5魔塔';
document.getElementById("startLogo").innerText = core.firstData.title; document.getElementById('startLogo').innerText = core.firstData.title;
(core.firstData.shops || []).forEach(function (t) { core.initStatus.shops[t.id] = t; }); (core.firstData.shops || []).forEach(function (t) {
core.initStatus.shops[t.id] = t;
});
core.maps._initFloors(); core.maps._initFloors();
// 初始化怪物、道具等 // 初始化怪物、道具等
@ -328,7 +346,9 @@ core.prototype._init_flags = function () {
for (var floorId in core.floors) { for (var floorId in core.floors) {
var autoEvents = core.floors[floorId].autoEvent || {}; var autoEvents = core.floors[floorId].autoEvent || {};
for (var loc in autoEvents) { for (var loc in autoEvents) {
var locs = loc.split(","), x = parseInt(locs[0]), y = parseInt(locs[1]); var locs = loc.split(','),
x = parseInt(locs[0]),
y = parseInt(locs[1]);
for (var index in autoEvents[loc]) { for (var index in autoEvents[loc]) {
var autoEvent = core.clone(autoEvents[loc][index]); var autoEvent = core.clone(autoEvents[loc][index]);
if (autoEvent && autoEvent.condition && autoEvent.data) { if (autoEvent && autoEvent.condition && autoEvent.data) {
@ -336,8 +356,11 @@ core.prototype._init_flags = function () {
autoEvent.x = x; autoEvent.x = x;
autoEvent.y = y; autoEvent.y = y;
autoEvent.index = index; autoEvent.index = index;
autoEvent.symbol = floorId + "@" + x + "@" + y + "@" + index; autoEvent.symbol =
autoEvent.condition = core.replaceValue(autoEvent.condition); floorId + '@' + x + '@' + y + '@' + index;
autoEvent.condition = core.replaceValue(
autoEvent.condition
);
autoEvent.data = core.precompile(autoEvent.data); autoEvent.data = core.precompile(autoEvent.data);
core.initStatus.autoEvents.push(autoEvent); core.initStatus.autoEvents.push(autoEvent);
} }
@ -351,18 +374,44 @@ core.prototype._init_flags = function () {
if (!equip.equip.equipEvent && !equip.equip.unequipEvent) continue; if (!equip.equip.equipEvent && !equip.equip.unequipEvent) continue;
var equipFlag = '_equipEvent_' + equipId; var equipFlag = '_equipEvent_' + equipId;
var autoEvent1 = { var autoEvent1 = {
symbol: "_equipEvent_" + equipId, symbol: '_equipEvent_' + equipId,
currentFloor: false, currentFloor: false,
multiExecute: true, multiExecute: true,
condition: "core.hasEquip('" + equipId + "') && !core.hasFlag('" + equipFlag + "')", condition:
data: core.precompile([{ "type": "setValue", "name": "flag:" + equipFlag, "value": "true" }].concat(equip.equip.equipEvent || [])), "core.hasEquip('" +
equipId +
"') && !core.hasFlag('" +
equipFlag +
"')",
data: core.precompile(
[
{
type: 'setValue',
name: 'flag:' + equipFlag,
value: 'true'
}
].concat(equip.equip.equipEvent || [])
)
}; };
var autoEvent2 = { var autoEvent2 = {
symbol: "_unequipEvent_" + equipId, symbol: '_unequipEvent_' + equipId,
currentFloor: false, currentFloor: false,
multiExecute: true, multiExecute: true,
condition: "!core.hasEquip('" + equipId + "') && core.hasFlag('" + equipFlag + "')", condition:
data: core.precompile([{ "type": "setValue", "name": "flag:" + equipFlag, "value": "null" }].concat(equip.equip.unequipEvent || [])), "!core.hasEquip('" +
equipId +
"') && core.hasFlag('" +
equipFlag +
"')",
data: core.precompile(
[
{
type: 'setValue',
name: 'flag:' + equipFlag,
value: 'null'
}
].concat(equip.equip.unequipEvent || [])
)
}; };
core.initStatus.autoEvents.push(autoEvent1); core.initStatus.autoEvents.push(autoEvent1);
core.initStatus.autoEvents.push(autoEvent2); core.initStatus.autoEvents.push(autoEvent2);
@ -372,33 +421,53 @@ core.prototype._init_flags = function () {
if (e1.floorId == null) return 1; if (e1.floorId == null) return 1;
if (e2.floorId == null) return -1; if (e2.floorId == null) return -1;
if (e1.priority != e2.priority) return e2.priority - e1.priority; if (e1.priority != e2.priority) return e2.priority - e1.priority;
if (e1.floorId != e2.floorId) return core.floorIds.indexOf(e1.floorId) - core.floorIds.indexOf(e2.floorId); if (e1.floorId != e2.floorId)
return (
core.floorIds.indexOf(e1.floorId) -
core.floorIds.indexOf(e2.floorId)
);
if (e1.x != e2.x) return e1.x - e2.x; if (e1.x != e2.x) return e1.x - e2.x;
if (e1.y != e2.y) return e1.y - e2.y; if (e1.y != e2.y) return e1.y - e2.y;
return e1.index - e2.index; return e1.index - e2.index;
}) });
};
}
core.prototype._init_sys_flags = function () { core.prototype._init_sys_flags = function () {
if (core.flags.equipboxButton) core.flags.equipment = true; if (core.flags.equipboxButton) core.flags.equipment = true;
core.flags.displayEnemyDamage = core.getLocalStorage('enemyDamage', true); core.flags.displayEnemyDamage = core.getLocalStorage('enemyDamage', true);
core.flags.displayCritical = core.getLocalStorage('critical', true); core.flags.displayCritical = core.getLocalStorage('critical', true);
core.flags.displayExtraDamage = core.getLocalStorage('extraDamage', true); core.flags.displayExtraDamage = core.getLocalStorage('extraDamage', true);
core.flags.enableEnemyPoint = core.getLocalStorage('enableEnemyPoint', core.flags.enableEnemyPoint); core.flags.enableEnemyPoint = core.getLocalStorage(
'enableEnemyPoint',
core.flags.enableEnemyPoint
);
core.flags.leftHandPrefer = core.getLocalStorage('leftHandPrefer', false); core.flags.leftHandPrefer = core.getLocalStorage('leftHandPrefer', false);
core.flags.extraDamageType = core.getLocalStorage('extraDamageType', 2); core.flags.extraDamageType = core.getLocalStorage('extraDamageType', 2);
// 行走速度 // 行走速度
core.values.moveSpeed = core.getLocalStorage('moveSpeed', core.values.moveSpeed || 100); core.values.moveSpeed = core.getLocalStorage(
core.values.floorChangeTime = core.getLocalStorage('floorChangeTime', core.values.floorChangeTime); 'moveSpeed',
core.values.moveSpeed || 100
);
core.values.floorChangeTime = core.getLocalStorage(
'floorChangeTime',
core.values.floorChangeTime
);
if (core.values.floorChangeTime == null) core.values.floorChangeTime = 500; if (core.values.floorChangeTime == null) core.values.floorChangeTime = 500;
core.flags.enableHDCanvas = core.getLocalStorage('enableHDCanvas', !core.platform.isIOS); core.flags.enableHDCanvas = core.getLocalStorage(
} 'enableHDCanvas',
!core.platform.isIOS
);
};
core.prototype._init_platform = function () { core.prototype._init_platform = function () {
core.platform.isOnline = location.protocol.indexOf("http") == 0; core.platform.isOnline = location.protocol.indexOf('http') == 0;
if (!core.platform.isOnline) alert("请勿直接打开html文件使用启动服务或者APP进行离线游戏。"); if (!core.platform.isOnline)
window.AudioContext = window.AudioContext || window.webkitAudioContext || window.mozAudioContext || window.msAudioContext; alert('请勿直接打开html文件使用启动服务或者APP进行离线游戏。');
window.AudioContext =
window.AudioContext ||
window.webkitAudioContext ||
window.mozAudioContext ||
window.msAudioContext;
core.musicStatus.bgmStatus = core.getLocalStorage('bgmStatus', true); core.musicStatus.bgmStatus = core.getLocalStorage('bgmStatus', true);
core.musicStatus.soundStatus = core.getLocalStorage('soundStatus', true); core.musicStatus.soundStatus = core.getLocalStorage('soundStatus', true);
//新增 userVolume 默认值0.7 //新增 userVolume 默认值0.7
@ -407,23 +476,38 @@ core.prototype._init_platform = function () {
core.musicStatus.audioContext = new window.AudioContext(); core.musicStatus.audioContext = new window.AudioContext();
core.musicStatus.gainNode = core.musicStatus.audioContext.createGain(); core.musicStatus.gainNode = core.musicStatus.audioContext.createGain();
core.musicStatus.gainNode.gain.value = core.musicStatus.userVolume; core.musicStatus.gainNode.gain.value = core.musicStatus.userVolume;
core.musicStatus.gainNode.connect(core.musicStatus.audioContext.destination); core.musicStatus.gainNode.connect(
core.musicStatus.audioContext.destination
);
} catch (e) { } catch (e) {
console.log("该浏览器不支持AudioContext"); console.log('该浏览器不支持AudioContext');
core.musicStatus.audioContext = null; core.musicStatus.audioContext = null;
} }
["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"].forEach(function (t) { ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod'].forEach(
if (navigator.userAgent.indexOf(t) >= 0) { function (t) {
if (t == 'iPhone' || t == 'iPad' || t == 'iPod') core.platform.isIOS = true; if (navigator.userAgent.indexOf(t) >= 0) {
if (t == 'Android') core.platform.isAndroid = true; if (t == 'iPhone' || t == 'iPad' || t == 'iPod')
core.platform.isPC = false; core.platform.isIOS = true;
if (t == 'Android') core.platform.isAndroid = true;
core.platform.isPC = false;
}
} }
}); );
core.platform.string = core.platform.isPC ? "PC" : core.platform.isAndroid ? "Android" : core.platform.isIOS ? "iOS" : ""; core.platform.string = core.platform.isPC
core.platform.supportCopy = document.queryCommandSupported && document.queryCommandSupported("copy"); ? 'PC'
: core.platform.isAndroid
? 'Android'
: core.platform.isIOS
? 'iOS'
: '';
core.platform.supportCopy =
document.queryCommandSupported &&
document.queryCommandSupported('copy');
var chrome = /Chrome\/(\d+)\./i.exec(navigator.userAgent); var chrome = /Chrome\/(\d+)\./i.exec(navigator.userAgent);
if (chrome && parseInt(chrome[1]) >= 50) core.platform.isChrome = true; if (chrome && parseInt(chrome[1]) >= 50) core.platform.isChrome = true;
core.platform.isSafari = /Safari/i.test(navigator.userAgent) && !/Chrome/i.test(navigator.userAgent); core.platform.isSafari =
/Safari/i.test(navigator.userAgent) &&
!/Chrome/i.test(navigator.userAgent);
core.platform.isQQ = /QQ/i.test(navigator.userAgent); core.platform.isQQ = /QQ/i.test(navigator.userAgent);
core.platform.isWeChat = /MicroMessenger/i.test(navigator.userAgent); core.platform.isWeChat = /MicroMessenger/i.test(navigator.userAgent);
if (window.FileReader) { if (window.FileReader) {
@ -432,33 +516,55 @@ core.prototype._init_platform = function () {
core.readFileContent(core.platform.fileReader.result); core.readFileContent(core.platform.fileReader.result);
}; };
core.platform.fileReader.onerror = function () { core.platform.fileReader.onerror = function () {
if (core.platform.errorCallback) if (core.platform.errorCallback) core.platform.errorCallback();
core.platform.errorCallback(); };
}
} }
core.flags.enableHDCanvas = core.getLocalStorage('enableHDCanvas', !core.platform.isIOS); core.flags.enableHDCanvas = core.getLocalStorage(
'enableHDCanvas',
!core.platform.isIOS
);
if (main.mode != 'editor') { if (main.mode != 'editor') {
core.domStyle.scale = core.getLocalStorage('scale', 1); core.domStyle.scale = core.getLocalStorage('scale', 1);
if (core.flags.enableHDCanvas) core.domStyle.ratio = Math.max(window.devicePixelRatio || 1, core.domStyle.scale); if (core.flags.enableHDCanvas)
core.domStyle.ratio = Math.max(
window.devicePixelRatio || 1,
core.domStyle.scale
);
} }
} };
core.prototype._init_others = function () { core.prototype._init_others = function () {
// 一些额外的东西 // 一些额外的东西
core.material.groundCanvas = document.createElement('canvas').getContext('2d'); core.material.groundCanvas = document
core.material.groundCanvas.canvas.width = core.material.groundCanvas.canvas.height = 32; .createElement('canvas')
core.material.groundPattern = core.material.groundCanvas.createPattern(core.material.groundCanvas.canvas, 'repeat'); .getContext('2d');
core.material.groundCanvas.canvas.width =
core.material.groundCanvas.canvas.height = 32;
core.material.groundPattern = core.material.groundCanvas.createPattern(
core.material.groundCanvas.canvas,
'repeat'
);
core.bigmap.tempCanvas = document.createElement('canvas').getContext('2d'); core.bigmap.tempCanvas = document.createElement('canvas').getContext('2d');
core.bigmap.cacheCanvas = document.createElement('canvas').getContext('2d'); core.bigmap.cacheCanvas = document.createElement('canvas').getContext('2d');
core.loadImage("materials", 'fog', function (name, img) { core.animateFrame.weather.fog = img; }); core.loadImage('materials', 'fog', function (name, img) {
core.loadImage("materials", "cloud", function (name, img) { core.animateFrame.weather.cloud = img; }) core.animateFrame.weather.fog = img;
core.loadImage("materials", "sun", function (name, img) { core.animateFrame.weather.sun = img; }) });
core.loadImage("materials", 'keyboard', function (name, img) { core.material.images.keyboard = img; }); core.loadImage('materials', 'cloud', function (name, img) {
core.animateFrame.weather.cloud = img;
});
core.loadImage('materials', 'sun', function (name, img) {
core.animateFrame.weather.sun = img;
});
core.loadImage('materials', 'keyboard', function (name, img) {
core.material.images.keyboard = img;
});
// 记录存档编号 // 记录存档编号
core.saves.saveIndex = core.getLocalStorage('saveIndex', 1); core.saves.saveIndex = core.getLocalStorage('saveIndex', 1);
core.control.getSaveIndexes(function (indexes) { core.saves.ids = indexes; }); core.control.getSaveIndexes(function (indexes) {
} core.saves.ids = indexes;
});
};
core.prototype._afterLoadResources = function (callback) { core.prototype._afterLoadResources = function (callback) {
// 初始化地图 // 初始化地图
@ -475,35 +581,43 @@ core.prototype._afterLoadResources = function (callback) {
console.warn('无法裁剪非png格式图片' + name); console.warn('无法裁剪非png格式图片' + name);
return; return;
} }
var arr = core.splitImage(core.material.images.images[name], one.width, one.height); var arr = core.splitImage(
core.material.images.images[name],
one.width,
one.height
);
for (var i = 0; i < arr.length; ++i) { for (var i = 0; i < arr.length; ++i) {
core.material.images.images[(one.prefix || "") + i + '.png'] = arr[i]; core.material.images.images[(one.prefix || '') + i + '.png'] =
arr[i];
} }
}); });
if (core.plugin._afterLoadResources) if (core.plugin._afterLoadResources) core.plugin._afterLoadResources();
core.plugin._afterLoadResources();
core.showStartAnimate(); core.showStartAnimate();
if (callback) callback(); if (callback) callback();
} };
core.prototype._init_plugins = function () { core.prototype._init_plugins = function () {
core.plugin = new function () { }; core.plugin = new (function () {})();
for (var name in plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1) { for (var name in plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1) {
if (plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1[name] instanceof Function) { if (
plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1[name] instanceof
Function
) {
try { try {
plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1[name].apply(core.plugin); plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1[name].apply(
} core.plugin
catch (e) { );
} catch (e) {
console.error(e); console.error(e);
console.error("无法初始化插件" + name); console.error('无法初始化插件' + name);
} }
} }
} }
core._forwardFunc("plugin"); core._forwardFunc('plugin');
} };
core.prototype._forwardFuncs = function () { core.prototype._forwardFuncs = function () {
for (var i = 0; i < main.loadList.length; ++i) { for (var i = 0; i < main.loadList.length; ++i) {
@ -511,12 +625,15 @@ core.prototype._forwardFuncs = function () {
if (name == 'core') continue; if (name == 'core') continue;
this._forwardFunc(name); this._forwardFunc(name);
} }
} };
core.prototype._forwardFunc = function (name, funcname) { core.prototype._forwardFunc = function (name, funcname) {
if (funcname == null) { if (funcname == null) {
for (funcname in core[name]) { for (funcname in core[name]) {
if (funcname.charAt(0) != "_" && core[name][funcname] instanceof Function) { if (
funcname.charAt(0) != '_' &&
core[name][funcname] instanceof Function
) {
this._forwardFunc(name, funcname); this._forwardFunc(name, funcname);
} }
} }
@ -524,14 +641,36 @@ core.prototype._forwardFunc = function (name, funcname) {
} }
if (core[funcname]) { if (core[funcname]) {
console.error("ERROR: 无法转发 " + name + " 中的函数 " + funcname + " 到 core 中!同名函数已存在。"); console.error(
'ERROR: 无法转发 ' +
name +
' 中的函数 ' +
funcname +
' 到 core 中!同名函数已存在。'
);
return; return;
} }
var parameterInfo = /^\s*function\s*[\w_$]*\(([\w_,$\s]*)\)\s*\{/.exec(core[name][funcname].toString()); var parameterInfo = /^\s*function\s*[\w_$]*\(([\w_,$\s]*)\)\s*\{/.exec(
var parameters = (parameterInfo == null ? "" : parameterInfo[1]).replace(/\s*/g, '').replace(/,/g, ', '); core[name][funcname].toString()
);
var parameters = (parameterInfo == null ? '' : parameterInfo[1])
.replace(/\s*/g, '')
.replace(/,/g, ', ');
// core[funcname] = new Function(parameters, "return core."+name+"."+funcname+"("+parameters+");"); // core[funcname] = new Function(parameters, "return core."+name+"."+funcname+"("+parameters+");");
eval("core." + funcname + " = function (" + parameters + ") {\n\treturn core." + name + "." + funcname + ".apply(core." + name + ", arguments);\n}"); eval(
} 'core.' +
funcname +
' = function (' +
parameters +
') {\n\treturn core.' +
name +
'.' +
funcname +
'.apply(core.' +
name +
', arguments);\n}'
);
};
core.prototype.doFunc = function (func, _this) { core.prototype.doFunc = function (func, _this) {
if (typeof func == 'string') { if (typeof func == 'string') {
@ -539,7 +678,7 @@ core.prototype.doFunc = function (func, _this) {
_this = core.plugin; _this = core.plugin;
} }
return func.apply(_this, Array.prototype.slice.call(arguments, 2)); return func.apply(_this, Array.prototype.slice.call(arguments, 2));
} };
// return new Core(); // return new Core();

View File

@ -1,7 +1,8 @@
///<reference path="../../src/types/core.d.ts" />
"use strict"; 'use strict';
function data () { function data() {
this._init(); this._init();
} }
@ -10,4 +11,4 @@ data.prototype._init = function () {
this.values = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.values; this.values = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.values;
this.flags = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.flags; this.flags = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.flags;
//delete(data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d); //delete(data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d);
} };

View File

@ -1,7 +1,8 @@
///<reference path="../../src/types/core.d.ts" />
"use strict"; 'use strict';
function enemys () { function enemys() {
this._init(); this._init();
} }
@ -14,10 +15,10 @@ enemys.prototype._init = function () {
} }
if (main.mode == 'play') { if (main.mode == 'play') {
this.enemydata.hasSpecial = function (a, b) { this.enemydata.hasSpecial = function (a, b) {
return core.enemys.hasSpecial(a, b) return core.enemys.hasSpecial(a, b);
}; };
} }
} };
enemys.prototype.getEnemys = function () { enemys.prototype.getEnemys = function () {
var enemys = core.clone(this.enemys); var enemys = core.clone(this.enemys);
@ -36,13 +37,20 @@ enemys.prototype.getEnemys = function () {
if (downId != null && downId != id && enemys[downId]) { if (downId != null && downId != id && enemys[downId]) {
enemys[id] = { id: id }; enemys[id] = { id: id };
for (var property in enemys[downId]) { for (var property in enemys[downId]) {
if (property != 'id' && enemys[downId].hasOwnProperty(property)) { if (
property != 'id' &&
enemys[downId].hasOwnProperty(property)
) {
(function (id, downId, property) { (function (id, downId, property) {
Object.defineProperty(enemys[id], property, { Object.defineProperty(enemys[id], property, {
get: function () { return enemys[downId][property] }, get: function () {
set: function (v) { enemys[downId][property] = v }, return enemys[downId][property];
},
set: function (v) {
enemys[downId][property] = v;
},
enumerable: true enumerable: true
}) });
})(id, downId, property); })(id, downId, property);
} }
} }
@ -50,7 +58,7 @@ enemys.prototype.getEnemys = function () {
} }
} }
return enemys; return enemys;
} };
////// 判断是否含有某特殊属性 ////// ////// 判断是否含有某特殊属性 //////
enemys.prototype.hasSpecial = function (special, test) { enemys.prototype.hasSpecial = function (special, test) {
@ -73,11 +81,11 @@ enemys.prototype.hasSpecial = function (special, test) {
} }
return false; return false;
} };
enemys.prototype.getSpecials = function () { enemys.prototype.getSpecials = function () {
return this.enemydata.getSpecials(); return this.enemydata.getSpecials();
} };
////// 获得所有特殊属性的名称 ////// ////// 获得所有特殊属性的名称 //////
enemys.prototype.getSpecialText = function (enemy) { enemys.prototype.getSpecialText = function (enemy) {
@ -94,7 +102,7 @@ enemys.prototype.getSpecialText = function (enemy) {
} }
} }
return text; return text;
} };
////// 获得所有特殊属性的颜色 ////// ////// 获得所有特殊属性的颜色 //////
enemys.prototype.getSpecialColor = function (enemy) { enemys.prototype.getSpecialColor = function (enemy) {
@ -111,8 +119,7 @@ enemys.prototype.getSpecialColor = function (enemy) {
} }
} }
return colors; return colors;
};
}
////// 获得所有特殊属性的额外标记 ////// ////// 获得所有特殊属性的额外标记 //////
enemys.prototype.getSpecialFlag = function (enemy) { enemys.prototype.getSpecialFlag = function (enemy) {
@ -125,11 +132,11 @@ enemys.prototype.getSpecialFlag = function (enemy) {
if (specials) { if (specials) {
for (var i = 0; i < specials.length; i++) { for (var i = 0; i < specials.length; i++) {
if (this.hasSpecial(special, specials[i][0])) if (this.hasSpecial(special, specials[i][0]))
flag |= (specials[i][4] || 0); flag |= specials[i][4] || 0;
} }
} }
return flag; return flag;
} };
////// 获得每个特殊属性的说明 ////// ////// 获得每个特殊属性的说明 //////
enemys.prototype.getSpecialHint = function (enemy, special) { enemys.prototype.getSpecialHint = function (enemy, special) {
@ -140,19 +147,30 @@ enemys.prototype.getSpecialHint = function (enemy, special) {
var hints = []; var hints = [];
for (var i = 0; i < specials.length; i++) { for (var i = 0; i < specials.length; i++) {
if (this.hasSpecial(enemy, specials[i][0])) if (this.hasSpecial(enemy, specials[i][0]))
hints.push("\r[" + core.arrayToRGBA(specials[i][3] || "#FF6A6A") + "]\\d" + this._calSpecialContent(enemy, specials[i][1]) + hints.push(
"\\d\r[]" + this._calSpecialContent(enemy, specials[i][2])); '\r[' +
core.arrayToRGBA(specials[i][3] || '#FF6A6A') +
']\\d' +
this._calSpecialContent(enemy, specials[i][1]) +
'\\d\r[]' +
this._calSpecialContent(enemy, specials[i][2])
);
} }
return hints; return hints;
} }
if (specials == null) return ""; if (specials == null) return '';
for (var i = 0; i < specials.length; i++) { for (var i = 0; i < specials.length; i++) {
if (special == specials[i][0]) if (special == specials[i][0])
return "\r[#FF6A6A]\\d" + this._calSpecialContent(enemy, specials[i][1]) + "\\d\r[]" + this._calSpecialContent(enemy, specials[i][2]); return (
'\r[#FF6A6A]\\d' +
this._calSpecialContent(enemy, specials[i][1]) +
'\\d\r[]' +
this._calSpecialContent(enemy, specials[i][2])
);
} }
return ""; return '';
} };
enemys.prototype._calSpecialContent = function (enemy, content) { enemys.prototype._calSpecialContent = function (enemy, content) {
if (typeof content == 'string') return content; if (typeof content == 'string') return content;
@ -160,14 +178,18 @@ enemys.prototype._calSpecialContent = function (enemy, content) {
if (content instanceof Function) { if (content instanceof Function) {
return content(enemy); return content(enemy);
} }
return ""; return '';
} };
////// 获得某个点上某个怪物的某项属性 ////// ////// 获得某个点上某个怪物的某项属性 //////
enemys.prototype.getEnemyValue = function (enemy, name, x, y, floorId) { enemys.prototype.getEnemyValue = function (enemy, name, x, y, floorId) {
floorId = floorId || core.status.floorId; floorId = floorId || core.status.floorId;
if ((((flags.enemyOnPoint || {})[floorId] || {})[x + "," + y] || {})[name] != null) { if (
return flags.enemyOnPoint[floorId][x + "," + y][name]; (((flags.enemyOnPoint || {})[floorId] || {})[x + ',' + y] || {})[
name
] != null
) {
return flags.enemyOnPoint[floorId][x + ',' + y][name];
} }
if (enemy == null) { if (enemy == null) {
var block = core.getBlock(x, y, floorId); var block = core.getBlock(x, y, floorId);
@ -177,14 +199,14 @@ enemys.prototype.getEnemyValue = function (enemy, name, x, y, floorId) {
if (typeof enemy == 'string') enemy = core.material.enemys[enemy]; if (typeof enemy == 'string') enemy = core.material.enemys[enemy];
if (enemy == null) return null; if (enemy == null) return null;
return enemy[name]; return enemy[name];
} };
////// 能否获胜 ////// ////// 能否获胜 //////
enemys.prototype.canBattle = function (enemy, x, y, floorId) { enemys.prototype.canBattle = function (enemy, x, y, floorId) {
if (typeof enemy == 'string') enemy = core.material.enemys[enemy]; if (typeof enemy == 'string') enemy = core.material.enemys[enemy];
var damage = this.getDamage(enemy, x, y, floorId); var damage = this.getDamage(enemy, x, y, floorId);
return damage != null && damage < core.status.hero.hp; return damage != null && damage < core.status.hero.hp;
} };
enemys.prototype.getDamageString = function (enemy, x, y, floorId) { enemys.prototype.getDamageString = function (enemy, x, y, floorId) {
if (typeof enemy == 'string') enemy = core.material.enemys[enemy]; if (typeof enemy == 'string') enemy = core.material.enemys[enemy];
@ -193,40 +215,43 @@ enemys.prototype.getDamageString = function (enemy, x, y, floorId) {
var color = '#000000'; var color = '#000000';
if (damage == null) { if (damage == null) {
damage = "???"; damage = '???';
color = '#FF2222'; color = '#FF2222';
} } else {
else {
if (damage <= 0) color = '#11FF11'; if (damage <= 0) color = '#11FF11';
else if (damage < core.status.hero.hp / 3) color = '#FFFFFF'; else if (damage < core.status.hero.hp / 3) color = '#FFFFFF';
else if (damage < core.status.hero.hp * 2 / 3) color = '#FFFF00'; else if (damage < (core.status.hero.hp * 2) / 3) color = '#FFFF00';
else if (damage < core.status.hero.hp) color = '#FF9933'; else if (damage < core.status.hero.hp) color = '#FF9933';
else color = '#FF2222'; else color = '#FF2222';
damage = core.formatBigNumber(damage, true); damage = core.formatBigNumber(damage, true);
if (core.enemys.hasSpecial(enemy, 19)) if (core.enemys.hasSpecial(enemy, 19)) damage += '+';
damage += "+"; if (core.enemys.hasSpecial(enemy, 21)) damage += '-';
if (core.enemys.hasSpecial(enemy, 21)) if (core.enemys.hasSpecial(enemy, 11)) damage += '^';
damage += "-";
if (core.enemys.hasSpecial(enemy, 11))
damage += "^";
} }
return { return {
"damage": damage, damage: damage,
"color": color color: color
}; };
} };
////// 接下来N个临界值和临界减伤计算 ////// ////// 接下来N个临界值和临界减伤计算 //////
enemys.prototype.nextCriticals = function (enemy, number, x, y, floorId) { enemys.prototype.nextCriticals = function (enemy, number, x, y, floorId) {
if (typeof enemy == 'string') enemy = core.material.enemys[enemy]; if (typeof enemy == 'string') enemy = core.material.enemys[enemy];
number = number || 1; number = number || 1;
var specialCriticals = this._nextCriticals_special(enemy, number, x, y, floorId); var specialCriticals = this._nextCriticals_special(
enemy,
number,
x,
y,
floorId
);
if (specialCriticals != null) return specialCriticals; if (specialCriticals != null) return specialCriticals;
var info = this.getDamageInfo(enemy, null, x, y, floorId); var info = this.getDamageInfo(enemy, null, x, y, floorId);
if (info == null) { // 如果未破防... if (info == null) {
// 如果未破防...
var overAtk = this._nextCriticals_overAtk(enemy, x, y, floorId); var overAtk = this._nextCriticals_overAtk(enemy, x, y, floorId);
if (overAtk == null) return []; if (overAtk == null) return [];
if (typeof overAtk[1] == 'number') return [[overAtk[0], -overAtk[1]]]; if (typeof overAtk[1] == 'number') return [[overAtk[0], -overAtk[1]]];
@ -242,45 +267,91 @@ enemys.prototype.nextCriticals = function (enemy, number, x, y, floorId) {
if (core.flags.useLoop) { if (core.flags.useLoop) {
if (core.status.hero.atk <= (main.criticalUseLoop || 1)) { if (core.status.hero.atk <= (main.criticalUseLoop || 1)) {
return this._nextCriticals_useLoop(enemy, info, number, x, y, floorId); return this._nextCriticals_useLoop(
enemy,
info,
number,
x,
y,
floorId
);
} else {
return this._nextCriticals_useBinarySearch(
enemy,
info,
number,
x,
y,
floorId
);
} }
else { } else {
return this._nextCriticals_useBinarySearch(enemy, info, number, x, y, floorId);
}
}
else {
return this._nextCriticals_useTurn(enemy, info, number, x, y, floorId); return this._nextCriticals_useTurn(enemy, info, number, x, y, floorId);
} }
} };
/// 未破防临界采用二分计算 /// 未破防临界采用二分计算
enemys.prototype._nextCriticals_overAtk = function (enemy, x, y, floorId) { enemys.prototype._nextCriticals_overAtk = function (enemy, x, y, floorId) {
var calNext = function (currAtk, maxAtk) { var calNext = function (currAtk, maxAtk) {
var start = currAtk, end = maxAtk; var start = currAtk,
end = maxAtk;
if (start > end) return null; if (start > end) return null;
while (start < end) { while (start < end) {
var mid = Math.floor((start + end) / 2); var mid = Math.floor((start + end) / 2);
if (mid - start > end - mid) mid--; if (mid - start > end - mid) mid--;
var nextInfo = core.enemys.getDamageInfo(enemy, { "atk": mid }, x, y, floorId); var nextInfo = core.enemys.getDamageInfo(
enemy,
{ atk: mid },
x,
y,
floorId
);
if (nextInfo != null) end = mid; if (nextInfo != null) end = mid;
else start = mid + 1; else start = mid + 1;
} }
var nextInfo = core.enemys.getDamageInfo(enemy, { "atk": start }, x, y, floorId); var nextInfo = core.enemys.getDamageInfo(
return nextInfo == null ? null : [start - core.status.hero.atk, nextInfo]; enemy,
} { atk: start },
return calNext(core.status.hero.atk + 1, x,
core.getEnemyValue(enemy, 'hp', x, y, floorId) + core.getEnemyValue(enemy, 'def', x, y, floorId)); y,
} floorId
);
return nextInfo == null
? null
: [start - core.status.hero.atk, nextInfo];
};
return calNext(
core.status.hero.atk + 1,
core.getEnemyValue(enemy, 'hp', x, y, floorId) +
core.getEnemyValue(enemy, 'def', x, y, floorId)
);
};
enemys.prototype._nextCriticals_special = function (enemy, number, x, y, floorId) { enemys.prototype._nextCriticals_special = function (
enemy,
number,
x,
y,
floorId
) {
if (this.hasSpecial(enemy.special, 10) || this.hasSpecial(enemy.special, 3)) if (this.hasSpecial(enemy.special, 10) || this.hasSpecial(enemy.special, 3))
return []; // 模仿or坚固临界 return []; // 模仿or坚固临界
return null; return null;
} };
enemys.prototype._nextCriticals_useLoop = function (enemy, info, number, x, y, floorId) { enemys.prototype._nextCriticals_useLoop = function (
var mon_hp = info.mon_hp, hero_atk = core.status.hero.atk, mon_def = info.mon_def, pre = info.damage; 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 = []; var list = [];
var start_atk = hero_atk; var start_atk = hero_atk;
if (info.__over__) { if (info.__over__) {
@ -288,8 +359,8 @@ enemys.prototype._nextCriticals_useLoop = function (enemy, info, number, x, y, f
list.push([info.__overAtk__, -info.damage]); list.push([info.__overAtk__, -info.damage]);
} }
for (var atk = start_atk + 1; atk <= mon_hp + mon_def; atk++) { for (var atk = start_atk + 1; atk <= mon_hp + mon_def; atk++) {
var nextInfo = this.getDamageInfo(enemy, { "atk": atk }, x, y, floorId); var nextInfo = this.getDamageInfo(enemy, { atk: atk }, x, y, floorId);
if (nextInfo == null || (typeof nextInfo == 'number')) break; if (nextInfo == null || typeof nextInfo == 'number') break;
if (pre > nextInfo.damage) { if (pre > nextInfo.damage) {
pre = nextInfo.damage; pre = nextInfo.damage;
list.push([atk - hero_atk, info.damage - nextInfo.damage]); list.push([atk - hero_atk, info.damage - nextInfo.damage]);
@ -299,10 +370,20 @@ enemys.prototype._nextCriticals_useLoop = function (enemy, info, number, x, y, f
} }
if (list.length == 0) list.push([0, 0]); if (list.length == 0) list.push([0, 0]);
return list; return list;
} };
enemys.prototype._nextCriticals_useBinarySearch = function (enemy, info, number, x, y, floorId) { enemys.prototype._nextCriticals_useBinarySearch = function (
var mon_hp = info.mon_hp, hero_atk = core.status.hero.atk, mon_def = info.mon_def, pre = info.damage; 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 = []; var list = [];
var start_atk = hero_atk; var start_atk = hero_atk;
if (info.__over__) { if (info.__over__) {
@ -310,20 +391,37 @@ enemys.prototype._nextCriticals_useBinarySearch = function (enemy, info, number,
list.push([info.__overAtk__, -info.damage]); list.push([info.__overAtk__, -info.damage]);
} }
var calNext = function (currAtk, maxAtk) { var calNext = function (currAtk, maxAtk) {
var start = Math.floor(currAtk), end = Math.floor(maxAtk); var start = Math.floor(currAtk),
end = Math.floor(maxAtk);
if (start > end) return null; if (start > end) return null;
while (start < end) { while (start < end) {
var mid = Math.floor((start + end) / 2); var mid = Math.floor((start + end) / 2);
if (mid - start > end - mid) mid--; if (mid - start > end - mid) mid--;
var nextInfo = core.enemys.getDamageInfo(enemy, { "atk": mid }, x, y, floorId); var nextInfo = core.enemys.getDamageInfo(
if (nextInfo == null || (typeof nextInfo == 'number')) return null; enemy,
{ atk: mid },
x,
y,
floorId
);
if (nextInfo == null || typeof nextInfo == 'number') return null;
if (pre > nextInfo.damage) end = mid; if (pre > nextInfo.damage) end = mid;
else start = mid + 1; else start = mid + 1;
} }
var nextInfo = core.enemys.getDamageInfo(enemy, { "atk": start }, x, y, floorId); var nextInfo = core.enemys.getDamageInfo(
return nextInfo == null || (typeof nextInfo == 'number') || nextInfo.damage >= pre ? null : [start, nextInfo.damage]; enemy,
} { atk: start },
x,
y,
floorId
);
return nextInfo == null ||
typeof nextInfo == 'number' ||
nextInfo.damage >= pre
? null
: [start, nextInfo.damage];
};
var currAtk = start_atk; var currAtk = start_atk;
while (true) { while (true) {
var next = calNext(currAtk + 1, mon_hp + mon_def, pre); var next = calNext(currAtk + 1, mon_hp + mon_def, pre);
@ -336,16 +434,35 @@ enemys.prototype._nextCriticals_useBinarySearch = function (enemy, info, number,
} }
if (list.length == 0) list.push([0, 0]); if (list.length == 0) list.push([0, 0]);
return list; return list;
} };
enemys.prototype._nextCriticals_useTurn = function (enemy, info, number, x, y, floorId) { enemys.prototype._nextCriticals_useTurn = function (
var mon_hp = info.mon_hp, hero_atk = core.status.hero.atk, mon_def = info.mon_def, turn = info.turn; 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;
// ------ 超大回合数强制使用二分算临界 // ------ 超大回合数强制使用二分算临界
// 以避免1攻10e回合2攻5e回合导致下述循环卡死问题 // 以避免1攻10e回合2攻5e回合导致下述循环卡死问题
if (turn >= 1e6) { // 100w回合以上强制二分计算临界 if (turn >= 1e6) {
return this._nextCriticals_useBinarySearch(enemy, info, number, x, y, floorId); // 100w回合以上强制二分计算临界
return this._nextCriticals_useBinarySearch(
enemy,
info,
number,
x,
y,
floorId
);
} }
var list = [], pre = null; var list = [],
pre = null;
var start_atk = hero_atk; var start_atk = hero_atk;
if (info.__over__) { if (info.__over__) {
start_atk += info.__overAtk__; start_atk += info.__overAtk__;
@ -357,34 +474,48 @@ enemys.prototype._nextCriticals_useTurn = function (enemy, info, number, x, y, f
nextAtk = Math.ceil(nextAtk / core.getBuff('atk')); nextAtk = Math.ceil(nextAtk / core.getBuff('atk'));
if (nextAtk <= start_atk) break; if (nextAtk <= start_atk) break;
if (nextAtk != pre) { if (nextAtk != pre) {
var nextInfo = this.getDamageInfo(enemy, { "atk": nextAtk }, x, y, floorId); var nextInfo = this.getDamageInfo(
if (nextInfo == null || (typeof nextInfo == 'number')) break; enemy,
list.push([nextAtk - hero_atk, Math.floor(info.damage - nextInfo.damage)]); { 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.damage <= 0 && !core.flags.enableNegativeDamage) break;
pre = nextAtk; pre = nextAtk;
} }
if (list.length >= number) if (list.length >= number) break;
break;
} }
if (list.length == 0) list.push([0, 0]); if (list.length == 0) list.push([0, 0]);
return list; return list;
} };
////// N防减伤计算 ////// ////// N防减伤计算 //////
enemys.prototype.getDefDamage = function (enemy, k, x, y, floorId) { enemys.prototype.getDefDamage = function (enemy, k, x, y, floorId) {
if (typeof enemy == 'string') enemy = core.material.enemys[enemy]; if (typeof enemy == 'string') enemy = core.material.enemys[enemy];
k = k || 1; k = k || 1;
var nowDamage = this._getDamage(enemy, null, x, y, floorId); var nowDamage = this._getDamage(enemy, null, x, y, floorId);
var nextDamage = this._getDamage(enemy, { "def": core.status.hero.def + k }, x, y, floorId); var nextDamage = this._getDamage(
if (nowDamage == null || nextDamage == null) return "???"; enemy,
{ def: core.status.hero.def + k },
x,
y,
floorId
);
if (nowDamage == null || nextDamage == null) return '???';
return nowDamage - nextDamage; return nowDamage - nextDamage;
} };
enemys.prototype.getEnemyInfo = function (enemy, hero, x, y, floorId) { enemys.prototype.getEnemyInfo = function (enemy, hero, x, y, floorId) {
if (enemy == null) return null; if (enemy == null) return null;
if (typeof enemy == 'string') enemy = core.material.enemys[enemy]; if (typeof enemy == 'string') enemy = core.material.enemys[enemy];
return this.enemydata.getEnemyInfo(enemy, hero, x, y, floorId) return this.enemydata.getEnemyInfo(enemy, hero, x, y, floorId);
} };
////// 获得战斗伤害信息(实际伤害计算函数) ////// ////// 获得战斗伤害信息(实际伤害计算函数) //////
enemys.prototype.getDamageInfo = function (enemy, hero, x, y, floorId) { enemys.prototype.getDamageInfo = function (enemy, hero, x, y, floorId) {
@ -392,12 +523,12 @@ enemys.prototype.getDamageInfo = function (enemy, hero, x, y, floorId) {
// 移动到了脚本编辑 - getDamageInfo中 // 移动到了脚本编辑 - getDamageInfo中
if (typeof enemy == 'string') enemy = core.material.enemys[enemy]; if (typeof enemy == 'string') enemy = core.material.enemys[enemy];
return this.enemydata.getDamageInfo(enemy, hero, x, y, floorId); return this.enemydata.getDamageInfo(enemy, hero, x, y, floorId);
} };
////// 获得在某个勇士属性下怪物伤害 ////// ////// 获得在某个勇士属性下怪物伤害 //////
enemys.prototype.getDamage = function (enemy, x, y, floorId) { enemys.prototype.getDamage = function (enemy, x, y, floorId) {
return this._getDamage(enemy, null, x, y, floorId); return this._getDamage(enemy, null, x, y, floorId);
} };
enemys.prototype._getDamage = function (enemy, hero, x, y, floorId) { enemys.prototype._getDamage = function (enemy, hero, x, y, floorId) {
if (enemy == null) enemy = core.getBlockId(x, y, floorId); if (enemy == null) enemy = core.getBlockId(x, y, floorId);
@ -408,30 +539,49 @@ enemys.prototype._getDamage = function (enemy, hero, x, y, floorId) {
if (info == null) return null; if (info == null) return null;
if (typeof info == 'number') return info; if (typeof info == 'number') return info;
return info.damage; return info.damage;
} };
////// 获得当前楼层的怪物列表 ////// ////// 获得当前楼层的怪物列表 //////
enemys.prototype.getCurrentEnemys = function (floorId) { enemys.prototype.getCurrentEnemys = function (floorId) {
floorId = floorId || core.status.floorId; floorId = floorId || core.status.floorId;
var enemys = [], used = {}; var enemys = [],
used = {};
core.extractBlocks(floorId); core.extractBlocks(floorId);
core.status.maps[floorId].blocks.forEach(function (block) { core.status.maps[floorId].blocks.forEach(function (block) {
if (!block.disable && block.event.cls.indexOf('enemy') == 0) { if (!block.disable && block.event.cls.indexOf('enemy') == 0) {
this._getCurrentEnemys_addEnemy(block.event.id, enemys, used, block.x, block.y, floorId); this._getCurrentEnemys_addEnemy(
block.event.id,
enemys,
used,
block.x,
block.y,
floorId
);
} }
}, this); }, this);
return this._getCurrentEnemys_sort(enemys); return this._getCurrentEnemys_sort(enemys);
} };
enemys.prototype._getCurrentEnemys_getEnemy = function (enemyId) { enemys.prototype._getCurrentEnemys_getEnemy = function (enemyId) {
var enemy = core.material.enemys[enemyId]; var enemy = core.material.enemys[enemyId];
if (!enemy) return null; if (!enemy) return null;
// 检查朝向displayIdInBook // 检查朝向displayIdInBook
return core.material.enemys[enemy.displayIdInBook] || core.material.enemys[(enemy.faceIds || {}).down] || enemy; return (
} core.material.enemys[enemy.displayIdInBook] ||
core.material.enemys[(enemy.faceIds || {}).down] ||
enemy
);
};
enemys.prototype._getCurrentEnemys_addEnemy = function (enemyId, enemys, used, x, y, floorId) { enemys.prototype._getCurrentEnemys_addEnemy = function (
enemyId,
enemys,
used,
x,
y,
floorId
) {
var enemy = this._getCurrentEnemys_getEnemy(enemyId); var enemy = this._getCurrentEnemys_getEnemy(enemyId);
if (enemy == null) return; if (enemy == null) return;
@ -440,23 +590,32 @@ enemys.prototype._getCurrentEnemys_addEnemy = function (enemyId, enemys, used, x
var enemyInfo = this.getEnemyInfo(enemy, null, null, null, floorId); var enemyInfo = this.getEnemyInfo(enemy, null, null, null, floorId);
var locEnemyInfo = this.getEnemyInfo(enemy, null, x, y, floorId); var locEnemyInfo = this.getEnemyInfo(enemy, null, x, y, floorId);
if (!core.flags.enableEnemyPoint || if (
(locEnemyInfo.atk == enemyInfo.atk && locEnemyInfo.def == enemyInfo.def && locEnemyInfo.hp == enemyInfo.hp)) { !core.flags.enableEnemyPoint ||
(locEnemyInfo.atk == enemyInfo.atk &&
locEnemyInfo.def == enemyInfo.def &&
locEnemyInfo.hp == enemyInfo.hp)
) {
x = null; x = null;
y = null; y = null;
} else { } else {
// 检查enemys里面是否使用了存在的内容 // 检查enemys里面是否使用了存在的内容
for (var i = 0; i < enemys.length; ++i) { for (var i = 0; i < enemys.length; ++i) {
var one = enemys[i]; var one = enemys[i];
if (id == one.id && one.locs != null && if (
locEnemyInfo.atk == one.atk && locEnemyInfo.def == one.def && locEnemyInfo.hp == one.hp) { id == one.id &&
one.locs != null &&
locEnemyInfo.atk == one.atk &&
locEnemyInfo.def == one.def &&
locEnemyInfo.hp == one.hp
) {
one.locs.push([x, y]); one.locs.push([x, y]);
return; return;
} }
} }
enemyInfo = locEnemyInfo; enemyInfo = locEnemyInfo;
} }
var id = enemy.id + ":" + x + ":" + y; var id = enemy.id + ':' + x + ':' + y;
if (used[id]) return; if (used[id]) return;
used[id] = true; used[id] = true;
@ -479,14 +638,24 @@ enemys.prototype._getCurrentEnemys_addEnemy = function (enemyId, enemys, used, x
e.damage = this.getDamage(enemy, x, y, floorId); e.damage = this.getDamage(enemy, x, y, floorId);
e.critical = critical[0]; e.critical = critical[0];
e.criticalDamage = critical[1]; e.criticalDamage = critical[1];
e.defDamage = this._getCurrentEnemys_addEnemy_defDamage(enemy, x, y, floorId); e.defDamage = this._getCurrentEnemys_addEnemy_defDamage(
enemy,
x,
y,
floorId
);
enemys.push(e); enemys.push(e);
} };
enemys.prototype._getCurrentEnemys_addEnemy_defDamage = function (enemy, x, y, floorId) { enemys.prototype._getCurrentEnemys_addEnemy_defDamage = function (
enemy,
x,
y,
floorId
) {
var ratio = core.status.maps[floorId || core.status.floorId].ratio || 1; var ratio = core.status.maps[floorId || core.status.floorId].ratio || 1;
return this.getDefDamage(enemy, ratio, x, y, floorId); return this.getDefDamage(enemy, ratio, x, y, floorId);
} };
enemys.prototype._getCurrentEnemys_sort = function (enemys) { enemys.prototype._getCurrentEnemys_sort = function (enemys) {
return enemys.sort(function (a, b) { return enemys.sort(function (a, b) {
@ -501,23 +670,33 @@ enemys.prototype._getCurrentEnemys_sort = function (enemys) {
} }
return a.damage - b.damage; return a.damage - b.damage;
}); });
} };
enemys.prototype.hasEnemyLeft = function (enemyId, floorId) { enemys.prototype.hasEnemyLeft = function (enemyId, floorId) {
if (floorId == null) floorId = core.status.floorId; if (floorId == null) floorId = core.status.floorId;
if (!(floorId instanceof Array)) floorId = [floorId]; if (!(floorId instanceof Array)) floorId = [floorId];
var enemyMap = {}; var enemyMap = {};
if (enemyId instanceof Array) enemyId.forEach(function (v) { enemyMap[v] = true; }); if (enemyId instanceof Array)
enemyId.forEach(function (v) {
enemyMap[v] = true;
});
else if (enemyId) enemyMap[enemyId] = true; else if (enemyId) enemyMap[enemyId] = true;
else enemyMap = null; else enemyMap = null;
for (var i = 0; i < floorId.length; i++) { for (var i = 0; i < floorId.length; i++) {
core.extractBlocks(floorId[i]); core.extractBlocks(floorId[i]);
var mapBlocks = core.status.maps[floorId[i]].blocks; var mapBlocks = core.status.maps[floorId[i]].blocks;
for (var b = 0; b < mapBlocks.length; b++) { for (var b = 0; b < mapBlocks.length; b++) {
if (!mapBlocks[b].disable && mapBlocks[b].event.cls.indexOf('enemy') === 0) { if (
if (enemyMap === null || enemyMap[core.getFaceDownId(mapBlocks[b])]) return true; !mapBlocks[b].disable &&
mapBlocks[b].event.cls.indexOf('enemy') === 0
) {
if (
enemyMap === null ||
enemyMap[core.getFaceDownId(mapBlocks[b])]
)
return true;
} }
} }
} }
return false; return false;
} };

View File

@ -1,3 +1,5 @@
///<reference path="../../src/types/core.d.ts" />
'use strict'; 'use strict';
function events() { function events() {

View File

@ -1,22 +1,25 @@
///<reference path="../../src/types/core.d.ts" />
/* /*
extensions.js负责拓展插件 extensions.js负责拓展插件
*/ */
"use strict"; 'use strict';
function extensions () { function extensions() {}
}
extensions.prototype._load = function (callback) { extensions.prototype._load = function (callback) {
if (main.replayChecking) return callback(); if (main.replayChecking) return callback();
if (!window.fs) { if (!window.fs) {
this._loadJs('_server/fs.js', function () { this._loadJs(
core.extensions._listExtensions(callback); '_server/fs.js',
}, callback); function () {
core.extensions._listExtensions(callback);
},
callback
);
} else this._listExtensions(callback); } else this._listExtensions(callback);
} };
extensions.prototype._loadJs = function (file, callback, onerror) { extensions.prototype._loadJs = function (file, callback, onerror) {
var script = document.createElement('script'); var script = document.createElement('script');
@ -24,7 +27,7 @@ extensions.prototype._loadJs = function (file, callback, onerror) {
script.onload = callback; script.onload = callback;
script.onerror = onerror; script.onerror = onerror;
main.dom.body.appendChild(script); main.dom.body.appendChild(script);
} };
extensions.prototype._listExtensions = function (callback) { extensions.prototype._listExtensions = function (callback) {
if (!window.fs) return callback(); if (!window.fs) return callback();
@ -39,13 +42,13 @@ extensions.prototype._listExtensions = function (callback) {
list.sort(); list.sort();
core.extensions._loadExtensions(list, callback); core.extensions._loadExtensions(list, callback);
}); });
} };
extensions.prototype._loadExtensions = function (list, callback) { extensions.prototype._loadExtensions = function (list, callback) {
var i = 0; var i = 0;
var load = function () { var load = function () {
if (i == list.length) return callback(); if (i == list.length) return callback();
core.extensions._loadJs('extensions/' + list[i++], load, load); core.extensions._loadJs('extensions/' + list[i++], load, load);
} };
load(); load();
} };

View File

@ -1,3 +1,5 @@
///<reference path="../../src/types/core.d.ts" />
'use strict'; 'use strict';
function icons() { function icons() {

View File

@ -1,3 +1,5 @@
///<reference path="../../src/types/core.d.ts" />
'use strict'; 'use strict';
function items() { function items() {

View File

@ -1,3 +1,5 @@
///<reference path="../../src/types/core.d.ts" />
/* /*
loader.js负责对资源的加载 loader.js负责对资源的加载

View File

@ -1,3 +1,5 @@
///<reference path="../../src/types/core.d.ts" />
'use strict'; 'use strict';
function maps() { function maps() {

View File

@ -1,3 +1,5 @@
///<reference path="../../src/types/core.d.ts" />
/** /**
* ui.js负责所有和UI界面相关的绘制 * ui.js负责所有和UI界面相关的绘制
* 包括 * 包括

View File

@ -1,3 +1,5 @@
///<reference path="../../src/types/core.d.ts" />
/* /*
utils.js 工具类 utils.js 工具类

File diff suppressed because it is too large Load Diff