2022-12-29 23:08:44 +08:00
|
|
|
|
///<reference path="../../src/types/core.d.ts" />
|
2022-11-13 18:02:05 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 初始化 start
|
|
|
|
|
*/
|
|
|
|
|
|
2022-12-29 23:08:44 +08:00
|
|
|
|
'use strict';
|
2022-11-13 18:02:05 +08:00
|
|
|
|
|
2022-12-29 23:08:44 +08:00
|
|
|
|
function core() {
|
2022-11-13 18:02:05 +08:00
|
|
|
|
this._WIDTH_ = 15;
|
|
|
|
|
this._HEIGHT_ = 15;
|
|
|
|
|
this._PX_ = this._WIDTH_ * 32;
|
|
|
|
|
this._PY_ = this._HEIGHT_ * 32;
|
|
|
|
|
this._HALF_WIDTH_ = Math.floor(this._WIDTH_ / 2);
|
|
|
|
|
this._HALF_HEIGHT_ = Math.floor(this._HEIGHT_ / 2);
|
|
|
|
|
|
|
|
|
|
this.__SIZE__ = main.mode == 'editor' ? 15 : this._HEIGHT_;
|
|
|
|
|
this.__PIXELS__ = this.__SIZE__ * 32;
|
|
|
|
|
this.__HALF_SIZE__ = Math.floor(this.__SIZE__ / 2);
|
|
|
|
|
this.material = {
|
2022-12-29 23:08:44 +08:00
|
|
|
|
animates: {},
|
|
|
|
|
images: {},
|
|
|
|
|
bgms: {},
|
|
|
|
|
sounds: {},
|
|
|
|
|
items: {},
|
|
|
|
|
enemys: {},
|
|
|
|
|
icons: {},
|
|
|
|
|
ground: null,
|
|
|
|
|
grundCanvas: null,
|
|
|
|
|
groundPattern: null,
|
|
|
|
|
autotileEdges: {}
|
|
|
|
|
};
|
2022-11-13 18:02:05 +08:00
|
|
|
|
this.timeout = {
|
2022-12-29 23:08:44 +08:00
|
|
|
|
turnHeroTimeout: null,
|
|
|
|
|
onDownTimeout: null,
|
|
|
|
|
sleepTimeout: null
|
|
|
|
|
};
|
2022-11-13 18:02:05 +08:00
|
|
|
|
this.interval = {
|
2022-12-29 23:08:44 +08:00
|
|
|
|
heroMoveInterval: null,
|
|
|
|
|
onDownInterval: null
|
|
|
|
|
};
|
2022-11-13 18:02:05 +08:00
|
|
|
|
this.animateFrame = {
|
2022-12-29 23:08:44 +08:00
|
|
|
|
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
|
2022-11-13 18:02:05 +08:00
|
|
|
|
},
|
2022-12-29 23:08:44 +08:00
|
|
|
|
tip: null,
|
|
|
|
|
asyncId: {},
|
|
|
|
|
lastAsyncId: null
|
|
|
|
|
};
|
2022-11-13 18:02:05 +08:00
|
|
|
|
this.musicStatus = {
|
2022-12-29 23:08:44 +08:00
|
|
|
|
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数量
|
|
|
|
|
};
|
2022-11-13 18:02:05 +08:00
|
|
|
|
this.platform = {
|
2022-12-29 23:08:44 +08:00
|
|
|
|
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 // 读取失败
|
|
|
|
|
};
|
2022-11-13 18:02:05 +08:00
|
|
|
|
// 样式
|
|
|
|
|
this.domStyle = {
|
|
|
|
|
scale: 1.0,
|
|
|
|
|
ratio: 1.0,
|
|
|
|
|
availableScale: [],
|
|
|
|
|
isVertical: false,
|
|
|
|
|
showStatusBar: true,
|
2023-01-11 09:45:18 +08:00
|
|
|
|
toolbarBtn: false,
|
|
|
|
|
hdCanvas: ['damage', 'ui', 'data']
|
2022-12-29 23:08:44 +08:00
|
|
|
|
};
|
2022-11-13 18:02:05 +08:00
|
|
|
|
this.bigmap = {
|
2022-12-29 23:08:44 +08:00
|
|
|
|
canvas: ['bg', 'event', 'event2', 'fg', 'damage'],
|
2022-11-13 18:02:05 +08:00
|
|
|
|
offsetX: 0, // in pixel
|
|
|
|
|
offsetY: 0,
|
2022-12-29 23:08:44 +08:00
|
|
|
|
posX: 0, //
|
2022-11-13 18:02:05 +08:00
|
|
|
|
posY: 0,
|
|
|
|
|
width: main.mode == 'editor' ? this.__SIZE__ : this._WIDTH_, // map width and height
|
|
|
|
|
height: main.mode == 'editor' ? this.__SIZE__ : this._HEIGHT_,
|
|
|
|
|
v2: false,
|
2023-04-22 17:11:40 +08:00
|
|
|
|
threshold: 512,
|
2022-11-13 18:02:05 +08:00
|
|
|
|
extend: 10,
|
|
|
|
|
scale: 1.0,
|
|
|
|
|
tempCanvas: null, // A temp canvas for drawing
|
2022-12-29 23:08:44 +08:00
|
|
|
|
cacheCanvas: null // A cache canvas
|
|
|
|
|
};
|
2022-11-13 18:02:05 +08:00
|
|
|
|
this.saves = {
|
2022-12-29 23:08:44 +08:00
|
|
|
|
saveIndex: null,
|
|
|
|
|
ids: {},
|
|
|
|
|
autosave: {
|
|
|
|
|
data: null,
|
|
|
|
|
time: 0,
|
|
|
|
|
updated: false,
|
|
|
|
|
storage: true, // 是否把自动存档写入文件a
|
|
|
|
|
max: 20, // 自动存档最大回退数
|
|
|
|
|
now: 0
|
2022-11-13 18:02:05 +08:00
|
|
|
|
},
|
2022-12-29 23:08:44 +08:00
|
|
|
|
favorite: [],
|
|
|
|
|
favoriteName: {},
|
|
|
|
|
cache: {}
|
|
|
|
|
};
|
2022-11-13 18:02:05 +08:00
|
|
|
|
this.initStatus = {
|
2022-12-29 23:08:44 +08:00
|
|
|
|
played: false,
|
|
|
|
|
gameOver: false,
|
2022-11-13 18:02:05 +08:00
|
|
|
|
|
|
|
|
|
// 勇士属性
|
2022-12-29 23:08:44 +08:00
|
|
|
|
hero: {},
|
|
|
|
|
heroCenter: { px: null, py: null },
|
2022-11-13 18:02:05 +08:00
|
|
|
|
|
|
|
|
|
// 当前地图
|
2022-12-29 23:08:44 +08:00
|
|
|
|
floorId: null,
|
|
|
|
|
thisMap: null,
|
|
|
|
|
maps: null,
|
|
|
|
|
bgmaps: {},
|
|
|
|
|
fgmaps: {},
|
|
|
|
|
mapBlockObjs: {},
|
|
|
|
|
checkBlock: {}, // 每个点的阻激夹域信息
|
|
|
|
|
damage: {
|
|
|
|
|
// 每个点的显伤绘制
|
|
|
|
|
posX: 0,
|
|
|
|
|
posY: 0,
|
|
|
|
|
data: [],
|
|
|
|
|
extraData: []
|
2022-11-13 18:02:05 +08:00
|
|
|
|
},
|
|
|
|
|
|
2022-12-29 23:08:44 +08:00
|
|
|
|
lockControl: false,
|
2022-11-13 18:02:05 +08:00
|
|
|
|
|
|
|
|
|
// 勇士移动状态
|
2022-12-29 23:08:44 +08:00
|
|
|
|
heroMoving: 0,
|
|
|
|
|
heroStop: true,
|
2022-11-13 18:02:05 +08:00
|
|
|
|
|
|
|
|
|
// 自动寻路相关
|
2022-12-29 23:08:44 +08:00
|
|
|
|
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
|
2022-11-13 18:02:05 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 按下键的时间:为了判定双击
|
2022-12-29 23:08:44 +08:00
|
|
|
|
downTime: null,
|
|
|
|
|
ctrlDown: false,
|
|
|
|
|
preview: {
|
|
|
|
|
enabled: false,
|
|
|
|
|
prepareDragging: false,
|
|
|
|
|
dragging: false,
|
|
|
|
|
px: 0,
|
|
|
|
|
py: 0
|
2022-11-13 18:02:05 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 路线&回放
|
2022-12-29 23:08:44 +08:00
|
|
|
|
route: [],
|
|
|
|
|
replay: {
|
|
|
|
|
replaying: false,
|
|
|
|
|
pausing: false,
|
|
|
|
|
animate: false, // 正在某段动画中
|
|
|
|
|
failed: false,
|
|
|
|
|
toReplay: [],
|
|
|
|
|
totalList: [],
|
|
|
|
|
speed: 1.0,
|
|
|
|
|
steps: 0,
|
|
|
|
|
save: []
|
2022-11-13 18:02:05 +08:00
|
|
|
|
},
|
|
|
|
|
// 录像折叠
|
2022-12-29 23:08:44 +08:00
|
|
|
|
routeFolding: {},
|
2022-11-13 18:02:05 +08:00
|
|
|
|
|
|
|
|
|
// event事件
|
2022-12-29 23:08:44 +08:00
|
|
|
|
shops: {},
|
|
|
|
|
event: {
|
|
|
|
|
id: null,
|
|
|
|
|
data: null,
|
|
|
|
|
selection: null,
|
|
|
|
|
ui: null,
|
|
|
|
|
interval: null
|
2022-11-13 18:02:05 +08:00
|
|
|
|
},
|
2022-12-29 23:08:44 +08:00
|
|
|
|
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
|
2022-11-13 18:02:05 +08:00
|
|
|
|
},
|
2022-12-29 23:08:44 +08:00
|
|
|
|
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'
|
2022-11-13 18:02:05 +08:00
|
|
|
|
},
|
2022-12-29 23:08:44 +08:00
|
|
|
|
curtainColor: null,
|
2022-11-13 18:02:05 +08:00
|
|
|
|
|
|
|
|
|
// 动画
|
2022-12-29 23:08:44 +08:00
|
|
|
|
globalAnimateObjs: [],
|
|
|
|
|
floorAnimateObjs: [],
|
|
|
|
|
boxAnimateObjs: [],
|
|
|
|
|
autotileAnimateObjs: [],
|
|
|
|
|
globalAnimateStatus: 0,
|
|
|
|
|
animateObjs: []
|
2022-11-13 18:02:05 +08:00
|
|
|
|
};
|
|
|
|
|
// 标记的楼层列表,用于数据统计
|
|
|
|
|
this.markedFloorIds = {};
|
|
|
|
|
this.status = {};
|
|
|
|
|
this.dymCanvas = {};
|
|
|
|
|
|
|
|
|
|
if (main.mode == 'editor') {
|
|
|
|
|
document.documentElement.style.setProperty('--size', this.__SIZE__);
|
2022-12-29 23:08:44 +08:00
|
|
|
|
document.documentElement.style.setProperty(
|
|
|
|
|
'--pixel',
|
|
|
|
|
this.__PIXELS__ + 'px'
|
|
|
|
|
);
|
2022-11-13 18:02:05 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/////////// 系统事件相关 ///////////
|
|
|
|
|
|
|
|
|
|
////// 初始化 //////
|
2023-03-04 20:21:12 +08:00
|
|
|
|
core.prototype.init = async function (coreData, callback) {
|
2022-11-13 18:02:05 +08:00
|
|
|
|
this._forwardFuncs();
|
2022-12-29 23:08:44 +08:00
|
|
|
|
for (var key in coreData) core[key] = coreData[key];
|
2022-11-13 18:02:05 +08:00
|
|
|
|
this._init_flags();
|
|
|
|
|
this._init_platform();
|
|
|
|
|
this._init_others();
|
2023-03-04 20:21:12 +08:00
|
|
|
|
await this._loadPlugin();
|
|
|
|
|
|
2022-11-13 18:02:05 +08:00
|
|
|
|
var b = main.mode == 'editor';
|
|
|
|
|
// 初始化画布
|
|
|
|
|
for (var name in core.canvas) {
|
2023-01-11 09:45:18 +08:00
|
|
|
|
if (core.domStyle.hdCanvas.includes(name))
|
|
|
|
|
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_;
|
|
|
|
|
}
|
2022-11-13 18:02:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
core.loader._load(function () {
|
|
|
|
|
core.extensions._load(function () {
|
|
|
|
|
core._afterLoadResources(callback);
|
|
|
|
|
});
|
|
|
|
|
});
|
2022-12-29 23:08:44 +08:00
|
|
|
|
};
|
2022-11-13 18:02:05 +08:00
|
|
|
|
|
2023-04-25 20:50:23 +08:00
|
|
|
|
core.prototype.initSync = function (coreData, callback) {
|
|
|
|
|
this._forwardFuncs();
|
|
|
|
|
for (var key in coreData) core[key] = coreData[key];
|
|
|
|
|
this._init_flags();
|
|
|
|
|
this._init_platform();
|
|
|
|
|
this._init_others();
|
|
|
|
|
this._loadPluginSync();
|
|
|
|
|
|
|
|
|
|
core.loader._load(function () {
|
|
|
|
|
core.extensions._load(function () {
|
|
|
|
|
core._afterLoadResources(callback);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
core.prototype._loadPluginSync = function () {
|
|
|
|
|
core.plugin = {};
|
|
|
|
|
if (main.useCompress) main.loadMod('project', 'plugin', () => 0);
|
|
|
|
|
else main.loadMod('project', 'plugin.min', () => 0);
|
|
|
|
|
};
|
|
|
|
|
|
2023-03-04 20:21:12 +08:00
|
|
|
|
core.prototype._loadPlugin = async function () {
|
|
|
|
|
const mainData = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.main;
|
|
|
|
|
core.plugin = {};
|
|
|
|
|
// 加载插件
|
2023-04-25 20:50:23 +08:00
|
|
|
|
if (main.mode === 'play') {
|
2023-03-04 20:21:12 +08:00
|
|
|
|
main.forward();
|
|
|
|
|
core.resetSettings();
|
|
|
|
|
core.plugin.showMarkedEnemy.value = true;
|
|
|
|
|
}
|
|
|
|
|
if (main.pluginUseCompress) {
|
2023-04-25 20:50:23 +08:00
|
|
|
|
await main.loadScript(`project/plugin.min.js?v=${main.version}`);
|
2023-03-04 20:21:12 +08:00
|
|
|
|
} else {
|
2023-05-13 21:47:37 +08:00
|
|
|
|
if (main.mode === 'play') {
|
|
|
|
|
await main.loadScript(`src/plugin/game/index.js`, true);
|
|
|
|
|
} else {
|
|
|
|
|
await main.loadScript(`src/plugin/game/index.esm.js`, true);
|
|
|
|
|
}
|
2023-03-04 20:21:12 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-11-13 18:02:05 +08:00
|
|
|
|
core.prototype._init_flags = function () {
|
|
|
|
|
core.flags = core.clone(core.data.flags);
|
|
|
|
|
core.values = core.clone(core.data.values);
|
|
|
|
|
core.firstData = core.clone(core.data.firstData);
|
|
|
|
|
this._init_sys_flags();
|
|
|
|
|
|
|
|
|
|
core.dom.versionLabel.innerText = core.firstData.version;
|
|
|
|
|
core.dom.logoLabel.innerText = core.firstData.title;
|
2022-12-29 23:08:44 +08:00
|
|
|
|
document.title = core.firstData.title + ' - HTML5魔塔';
|
|
|
|
|
(core.firstData.shops || []).forEach(function (t) {
|
|
|
|
|
core.initStatus.shops[t.id] = t;
|
|
|
|
|
});
|
2022-11-13 18:02:05 +08:00
|
|
|
|
|
|
|
|
|
core.maps._initFloors();
|
|
|
|
|
// 初始化怪物、道具等
|
|
|
|
|
core.material.enemys = core.enemys.getEnemys();
|
|
|
|
|
core.material.items = core.items.getItems();
|
|
|
|
|
core.material.icons = core.icons.getIcons();
|
|
|
|
|
|
|
|
|
|
// 初始化自动事件
|
|
|
|
|
for (var floorId in core.floors) {
|
|
|
|
|
var autoEvents = core.floors[floorId].autoEvent || {};
|
|
|
|
|
for (var loc in autoEvents) {
|
2022-12-29 23:08:44 +08:00
|
|
|
|
var locs = loc.split(','),
|
|
|
|
|
x = parseInt(locs[0]),
|
|
|
|
|
y = parseInt(locs[1]);
|
2022-11-13 18:02:05 +08:00
|
|
|
|
for (var index in autoEvents[loc]) {
|
|
|
|
|
var autoEvent = core.clone(autoEvents[loc][index]);
|
|
|
|
|
if (autoEvent && autoEvent.condition && autoEvent.data) {
|
|
|
|
|
autoEvent.floorId = floorId;
|
|
|
|
|
autoEvent.x = x;
|
|
|
|
|
autoEvent.y = y;
|
|
|
|
|
autoEvent.index = index;
|
2022-12-29 23:08:44 +08:00
|
|
|
|
autoEvent.symbol =
|
|
|
|
|
floorId + '@' + x + '@' + y + '@' + index;
|
|
|
|
|
autoEvent.condition = core.replaceValue(
|
|
|
|
|
autoEvent.condition
|
|
|
|
|
);
|
2022-11-13 18:02:05 +08:00
|
|
|
|
autoEvent.data = core.precompile(autoEvent.data);
|
|
|
|
|
core.initStatus.autoEvents.push(autoEvent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 道具的穿上/脱下,视为自动事件
|
|
|
|
|
for (var equipId in core.material.items) {
|
|
|
|
|
var equip = core.material.items[equipId];
|
|
|
|
|
if (equip.cls != 'equips' || !equip.equip) continue;
|
|
|
|
|
if (!equip.equip.equipEvent && !equip.equip.unequipEvent) continue;
|
|
|
|
|
var equipFlag = '_equipEvent_' + equipId;
|
|
|
|
|
var autoEvent1 = {
|
2022-12-29 23:08:44 +08:00
|
|
|
|
symbol: '_equipEvent_' + equipId,
|
2022-11-13 18:02:05 +08:00
|
|
|
|
currentFloor: false,
|
|
|
|
|
multiExecute: true,
|
2022-12-29 23:08:44 +08:00
|
|
|
|
condition:
|
|
|
|
|
"core.hasEquip('" +
|
|
|
|
|
equipId +
|
|
|
|
|
"') && !core.hasFlag('" +
|
|
|
|
|
equipFlag +
|
|
|
|
|
"')",
|
|
|
|
|
data: core.precompile(
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
type: 'setValue',
|
|
|
|
|
name: 'flag:' + equipFlag,
|
|
|
|
|
value: 'true'
|
|
|
|
|
}
|
|
|
|
|
].concat(equip.equip.equipEvent || [])
|
|
|
|
|
)
|
2022-11-13 18:02:05 +08:00
|
|
|
|
};
|
|
|
|
|
var autoEvent2 = {
|
2022-12-29 23:08:44 +08:00
|
|
|
|
symbol: '_unequipEvent_' + equipId,
|
2022-11-13 18:02:05 +08:00
|
|
|
|
currentFloor: false,
|
|
|
|
|
multiExecute: true,
|
2022-12-29 23:08:44 +08:00
|
|
|
|
condition:
|
|
|
|
|
"!core.hasEquip('" +
|
|
|
|
|
equipId +
|
|
|
|
|
"') && core.hasFlag('" +
|
|
|
|
|
equipFlag +
|
|
|
|
|
"')",
|
|
|
|
|
data: core.precompile(
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
type: 'setValue',
|
|
|
|
|
name: 'flag:' + equipFlag,
|
|
|
|
|
value: 'null'
|
|
|
|
|
}
|
|
|
|
|
].concat(equip.equip.unequipEvent || [])
|
|
|
|
|
)
|
2022-11-13 18:02:05 +08:00
|
|
|
|
};
|
|
|
|
|
core.initStatus.autoEvents.push(autoEvent1);
|
|
|
|
|
core.initStatus.autoEvents.push(autoEvent2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
core.initStatus.autoEvents.sort(function (e1, e2) {
|
|
|
|
|
if (e1.floorId == null) return 1;
|
|
|
|
|
if (e2.floorId == null) return -1;
|
|
|
|
|
if (e1.priority != e2.priority) return e2.priority - e1.priority;
|
2022-12-29 23:08:44 +08:00
|
|
|
|
if (e1.floorId != e2.floorId)
|
|
|
|
|
return (
|
|
|
|
|
core.floorIds.indexOf(e1.floorId) -
|
|
|
|
|
core.floorIds.indexOf(e2.floorId)
|
|
|
|
|
);
|
2022-11-13 18:02:05 +08:00
|
|
|
|
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;
|
2022-12-29 23:08:44 +08:00
|
|
|
|
});
|
|
|
|
|
};
|
2022-11-13 18:02:05 +08:00
|
|
|
|
|
|
|
|
|
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);
|
2022-12-29 23:08:44 +08:00
|
|
|
|
core.flags.enableEnemyPoint = core.getLocalStorage(
|
|
|
|
|
'enableEnemyPoint',
|
|
|
|
|
core.flags.enableEnemyPoint
|
|
|
|
|
);
|
2022-11-13 18:02:05 +08:00
|
|
|
|
core.flags.leftHandPrefer = core.getLocalStorage('leftHandPrefer', false);
|
|
|
|
|
core.flags.extraDamageType = core.getLocalStorage('extraDamageType', 2);
|
|
|
|
|
// 行走速度
|
2022-12-29 23:08:44 +08:00
|
|
|
|
core.values.moveSpeed = core.getLocalStorage(
|
|
|
|
|
'moveSpeed',
|
|
|
|
|
core.values.moveSpeed || 100
|
|
|
|
|
);
|
|
|
|
|
core.values.floorChangeTime = core.getLocalStorage(
|
|
|
|
|
'floorChangeTime',
|
|
|
|
|
core.values.floorChangeTime
|
|
|
|
|
);
|
2022-11-13 18:02:05 +08:00
|
|
|
|
if (core.values.floorChangeTime == null) core.values.floorChangeTime = 500;
|
2022-12-29 23:08:44 +08:00
|
|
|
|
core.flags.enableHDCanvas = core.getLocalStorage(
|
|
|
|
|
'enableHDCanvas',
|
|
|
|
|
!core.platform.isIOS
|
|
|
|
|
);
|
|
|
|
|
};
|
2022-11-13 18:02:05 +08:00
|
|
|
|
|
|
|
|
|
core.prototype._init_platform = function () {
|
2022-12-29 23:08:44 +08:00
|
|
|
|
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;
|
2022-11-13 18:02:05 +08:00
|
|
|
|
core.musicStatus.bgmStatus = core.getLocalStorage('bgmStatus', true);
|
|
|
|
|
core.musicStatus.soundStatus = core.getLocalStorage('soundStatus', true);
|
|
|
|
|
//新增 userVolume 默认值0.7
|
|
|
|
|
core.musicStatus.userVolume = core.getLocalStorage('userVolume', 0.7);
|
|
|
|
|
try {
|
|
|
|
|
core.musicStatus.audioContext = new window.AudioContext();
|
|
|
|
|
core.musicStatus.gainNode = core.musicStatus.audioContext.createGain();
|
|
|
|
|
core.musicStatus.gainNode.gain.value = core.musicStatus.userVolume;
|
2022-12-29 23:08:44 +08:00
|
|
|
|
core.musicStatus.gainNode.connect(
|
|
|
|
|
core.musicStatus.audioContext.destination
|
|
|
|
|
);
|
2022-11-13 18:02:05 +08:00
|
|
|
|
} catch (e) {
|
2022-12-29 23:08:44 +08:00
|
|
|
|
console.log('该浏览器不支持AudioContext');
|
2022-11-13 18:02:05 +08:00
|
|
|
|
core.musicStatus.audioContext = null;
|
|
|
|
|
}
|
2022-12-29 23:08:44 +08:00
|
|
|
|
['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;
|
|
|
|
|
}
|
2022-11-13 18:02:05 +08:00
|
|
|
|
}
|
2022-12-29 23:08:44 +08:00
|
|
|
|
);
|
|
|
|
|
core.platform.string = core.platform.isPC
|
|
|
|
|
? 'PC'
|
|
|
|
|
: core.platform.isAndroid
|
|
|
|
|
? 'Android'
|
|
|
|
|
: core.platform.isIOS
|
|
|
|
|
? 'iOS'
|
|
|
|
|
: '';
|
|
|
|
|
core.platform.supportCopy =
|
|
|
|
|
document.queryCommandSupported &&
|
|
|
|
|
document.queryCommandSupported('copy');
|
2022-11-13 18:02:05 +08:00
|
|
|
|
var chrome = /Chrome\/(\d+)\./i.exec(navigator.userAgent);
|
|
|
|
|
if (chrome && parseInt(chrome[1]) >= 50) core.platform.isChrome = true;
|
2022-12-29 23:08:44 +08:00
|
|
|
|
core.platform.isSafari =
|
|
|
|
|
/Safari/i.test(navigator.userAgent) &&
|
|
|
|
|
!/Chrome/i.test(navigator.userAgent);
|
2022-11-13 18:02:05 +08:00
|
|
|
|
core.platform.isQQ = /QQ/i.test(navigator.userAgent);
|
|
|
|
|
core.platform.isWeChat = /MicroMessenger/i.test(navigator.userAgent);
|
|
|
|
|
if (window.FileReader) {
|
|
|
|
|
core.platform.fileReader = new FileReader();
|
|
|
|
|
core.platform.fileReader.onload = function () {
|
|
|
|
|
core.readFileContent(core.platform.fileReader.result);
|
|
|
|
|
};
|
|
|
|
|
core.platform.fileReader.onerror = function () {
|
2022-12-29 23:08:44 +08:00
|
|
|
|
if (core.platform.errorCallback) core.platform.errorCallback();
|
|
|
|
|
};
|
2022-11-13 18:02:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-29 23:08:44 +08:00
|
|
|
|
core.flags.enableHDCanvas = core.getLocalStorage(
|
|
|
|
|
'enableHDCanvas',
|
|
|
|
|
!core.platform.isIOS
|
|
|
|
|
);
|
2022-11-13 18:02:05 +08:00
|
|
|
|
if (main.mode != 'editor') {
|
|
|
|
|
core.domStyle.scale = core.getLocalStorage('scale', 1);
|
2022-12-29 23:08:44 +08:00
|
|
|
|
if (core.flags.enableHDCanvas)
|
|
|
|
|
core.domStyle.ratio = Math.max(
|
|
|
|
|
window.devicePixelRatio || 1,
|
|
|
|
|
core.domStyle.scale
|
|
|
|
|
);
|
2022-11-13 18:02:05 +08:00
|
|
|
|
}
|
2022-12-29 23:08:44 +08:00
|
|
|
|
};
|
2022-11-13 18:02:05 +08:00
|
|
|
|
|
|
|
|
|
core.prototype._init_others = function () {
|
|
|
|
|
// 一些额外的东西
|
2022-12-29 23:08:44 +08:00
|
|
|
|
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'
|
|
|
|
|
);
|
2022-11-13 18:02:05 +08:00
|
|
|
|
core.bigmap.tempCanvas = document.createElement('canvas').getContext('2d');
|
|
|
|
|
core.bigmap.cacheCanvas = document.createElement('canvas').getContext('2d');
|
2022-12-29 23:08:44 +08:00
|
|
|
|
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;
|
|
|
|
|
});
|
2022-11-13 18:02:05 +08:00
|
|
|
|
// 记录存档编号
|
|
|
|
|
core.saves.saveIndex = core.getLocalStorage('saveIndex', 1);
|
2022-12-29 23:08:44 +08:00
|
|
|
|
core.control.getSaveIndexes(function (indexes) {
|
|
|
|
|
core.saves.ids = indexes;
|
|
|
|
|
});
|
|
|
|
|
};
|
2022-11-13 18:02:05 +08:00
|
|
|
|
|
|
|
|
|
core.prototype._afterLoadResources = function (callback) {
|
|
|
|
|
// 初始化地图
|
|
|
|
|
core.initStatus.maps = core.maps._initMaps();
|
|
|
|
|
core.control._setRequestAnimationFrame();
|
|
|
|
|
// 图片裁剪
|
|
|
|
|
(main.splitImages || []).forEach(function (one) {
|
|
|
|
|
var name = core.getMappedName(one.name);
|
|
|
|
|
if (!core.material.images.images[name]) {
|
|
|
|
|
console.warn('找不到图片:' + name + ',无法裁剪');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!name.endsWith('.png')) {
|
|
|
|
|
console.warn('无法裁剪非png格式图片:' + name);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-12-29 23:08:44 +08:00
|
|
|
|
var arr = core.splitImage(
|
|
|
|
|
core.material.images.images[name],
|
|
|
|
|
one.width,
|
|
|
|
|
one.height
|
|
|
|
|
);
|
2022-11-13 18:02:05 +08:00
|
|
|
|
for (var i = 0; i < arr.length; ++i) {
|
2022-12-29 23:08:44 +08:00
|
|
|
|
core.material.images.images[(one.prefix || '') + i + '.png'] =
|
|
|
|
|
arr[i];
|
2022-11-13 18:02:05 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2022-12-29 23:08:44 +08:00
|
|
|
|
if (core.plugin._afterLoadResources) core.plugin._afterLoadResources();
|
2022-11-13 18:02:05 +08:00
|
|
|
|
core.showStartAnimate();
|
|
|
|
|
if (callback) callback();
|
2022-12-29 23:08:44 +08:00
|
|
|
|
};
|
2022-11-13 18:02:05 +08:00
|
|
|
|
|
|
|
|
|
core.prototype._forwardFuncs = function () {
|
|
|
|
|
for (var i = 0; i < main.loadList.length; ++i) {
|
|
|
|
|
var name = main.loadList[i];
|
|
|
|
|
if (name == 'core') continue;
|
|
|
|
|
this._forwardFunc(name);
|
|
|
|
|
}
|
2022-12-29 23:08:44 +08:00
|
|
|
|
};
|
2022-11-13 18:02:05 +08:00
|
|
|
|
|
|
|
|
|
core.prototype._forwardFunc = function (name, funcname) {
|
|
|
|
|
if (funcname == null) {
|
|
|
|
|
for (funcname in core[name]) {
|
2022-12-29 23:08:44 +08:00
|
|
|
|
if (
|
|
|
|
|
funcname.charAt(0) != '_' &&
|
|
|
|
|
core[name][funcname] instanceof Function
|
|
|
|
|
) {
|
2022-11-13 18:02:05 +08:00
|
|
|
|
this._forwardFunc(name, funcname);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (core[funcname]) {
|
2022-12-29 23:08:44 +08:00
|
|
|
|
console.error(
|
|
|
|
|
'ERROR: 无法转发 ' +
|
|
|
|
|
name +
|
|
|
|
|
' 中的函数 ' +
|
|
|
|
|
funcname +
|
|
|
|
|
' 到 core 中!同名函数已存在。'
|
|
|
|
|
);
|
2022-11-13 18:02:05 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2022-12-29 23:08:44 +08:00
|
|
|
|
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, ', ');
|
2022-11-13 18:02:05 +08:00
|
|
|
|
// core[funcname] = new Function(parameters, "return core."+name+"."+funcname+"("+parameters+");");
|
2022-12-29 23:08:44 +08:00
|
|
|
|
eval(
|
|
|
|
|
'core.' +
|
|
|
|
|
funcname +
|
|
|
|
|
' = function (' +
|
|
|
|
|
parameters +
|
|
|
|
|
') {\n\treturn core.' +
|
|
|
|
|
name +
|
|
|
|
|
'.' +
|
|
|
|
|
funcname +
|
|
|
|
|
'.apply(core.' +
|
|
|
|
|
name +
|
|
|
|
|
', arguments);\n}'
|
|
|
|
|
);
|
|
|
|
|
};
|
2022-11-13 18:02:05 +08:00
|
|
|
|
|
|
|
|
|
core.prototype.doFunc = function (func, _this) {
|
|
|
|
|
if (typeof func == 'string') {
|
|
|
|
|
func = core.plugin[func];
|
|
|
|
|
_this = core.plugin;
|
|
|
|
|
}
|
|
|
|
|
return func.apply(_this, Array.prototype.slice.call(arguments, 2));
|
2022-12-29 23:08:44 +08:00
|
|
|
|
};
|
2022-11-13 18:02:05 +08:00
|
|
|
|
|
|
|
|
|
var core = new core();
|