给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用户交互的事件的处理
键盘鼠标触摸屏事件相关

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff