Skip to content

Commit

Permalink
Merge pull request #497 from ckcz123/v2.x
Browse files Browse the repository at this point in the history
V2.x
  • Loading branch information
ckcz123 authored Jun 28, 2020
2 parents 0676bdd + 9387479 commit d0b0fec
Show file tree
Hide file tree
Showing 14 changed files with 249 additions and 53 deletions.
6 changes: 5 additions & 1 deletion _server/CodeMirror/defs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2607,7 +2607,7 @@ var terndefs_f6783a0a_522d_417e_8407_94c67b692e50 = [
"addItem": {
"!doc": "静默增减某种道具的持有量 不会更新游戏画面或是显示提示<br/>例如:core.addItem('yellowKey', -2) // 没收两把黄钥匙<br/>itemId: 道具id<br/>itemNum: 增加量,负数表示没收",
"!type": "fn(itemId: string, itemNum?: number)"
},
},
"unloadEquip": {
"!doc": "脱下某个类型的装备<br/>例如:core.unloadEquip(1) // 卸下盾牌,无回调<br/>equipType: 装备类型编号,自然数<br/>callback: 卸下装备后的回调函数",
"!type": "fn(equipType: number, callback?: fn())"
Expand Down Expand Up @@ -3546,6 +3546,10 @@ var terndefs_f6783a0a_522d_417e_8407_94c67b692e50 = [
"!doc": "绘制怪物属性的详细信息",
"!type": "fn(index?: ?)"
},
"getToolboxItems": {
"!doc": "获得所有应该在道具栏显示的某个类型道具",
"!type": "fn(cls: string) -> [string]"
},
"drawToolbox": {
"!doc": "绘制道具栏",
"!type": "fn(index?: ?)"
Expand Down
4 changes: 2 additions & 2 deletions _server/editor_listen.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ editor_listen_wrapper = function (editor) {
editor.showdataarea(true)
}
mobileview.children[1].onclick = function () {
mid.style = '';
mid.style = 'z-index:110';
right.style = 'z-index:-1;opacity: 0;';
// mobileeditdata.style = 'z-index:-1;opacity: 0;';
editor.lastClickId = '';
}
mobileview.children[3].onclick = function () {
mid.style = 'z-index:-1;opacity: 0;';
right.style = '';
right.style = 'z-index:110';
// mobileeditdata.style = 'z-index:-1;opacity: 0;';
editor.lastClickId = '';
}
Expand Down
6 changes: 6 additions & 0 deletions _server/table/functions.comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ var functions_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = {
"ui": {
"_type": "object",
"_data": {
"getToolboxItems": {
"_leaf": true,
"_type": "textarea",
"_lint": true,
"_data": "道具栏显示项"
},
"drawStatusBar": {
"_leaf": true,
"_type": "textarea",
Expand Down
6 changes: 6 additions & 0 deletions _server/table/plugins.comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ var plugins_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = {
"_range": "typeof(thiseval)=='string' || thiseval==null",
"_data": "楼传可以跳过楼层"
},
"itemCategory": {
"_leaf": true,
"_type": "textarea",
"_range": "typeof(thiseval)=='string' || thiseval==null",
"_data": "物品分类插件"
},
"smoothCamera": {
"_leaf": true,
"_type": "textarea",
Expand Down
24 changes: 9 additions & 15 deletions libs/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1346,10 +1346,8 @@ actions.prototype._keyUpQuickShop = function (keycode) {

////// 工具栏界面时的点击操作 //////
actions.prototype._clickToolbox = function (x, y) {
var tools = Object.keys(core.status.hero.items.tools)
.filter(function (id) { return !core.material.items[id].hideInToolbox; }).sort();
var constants = Object.keys(core.status.hero.items.constants)
.filter(function (id) { return !core.material.items[id].hideInToolbox; }).sort();
var tools = core.getToolboxItems('tools'),
constants = core.getToolboxItems('constants');

// 装备栏
if (x >= this.LAST - 2 && y == 0) {
Expand Down Expand Up @@ -1402,10 +1400,8 @@ actions.prototype._clickToolbox = function (x, y) {

////// 选择工具栏界面中某个Index后的操作 //////
actions.prototype._clickToolboxIndex = function (index) {
var tools = Object.keys(core.status.hero.items.tools)
.filter(function (id) { return !core.material.items[id].hideInToolbox; }).sort();
var constants = Object.keys(core.status.hero.items.constants)
.filter(function (id) { return !core.material.items[id].hideInToolbox; }).sort();
var tools = core.getToolboxItems('tools'),
constants = core.getToolboxItems('constants');

var items = null;
var select;
Expand Down Expand Up @@ -1435,10 +1431,8 @@ actions.prototype._keyDownToolbox = function (keycode) {

var last_index = this.LAST - 1;

var tools = Object.keys(core.status.hero.items.tools)
.filter(function (id) { return !core.material.items[id].hideInToolbox; }).sort();
var constants = Object.keys(core.status.hero.items.constants)
.filter(function (id) { return !core.material.items[id].hideInToolbox; }).sort();
var tools = core.getToolboxItems('tools'),
constants = core.getToolboxItems('constants');
var index = core.status.event.selection;
var toolsPage = core.status.event.data.toolsPage;
var constantsPage = core.status.event.data.constantsPage;
Expand Down Expand Up @@ -1571,7 +1565,7 @@ actions.prototype._clickEquipbox = function (x, y) {
}
// 下一页
if ((x == this.HSIZE+2 || x == this.HSIZE+3) && y == this.LAST) {
var lastPage = Math.ceil(Object.keys(core.status.hero.items.equips).length / this.LAST);
var lastPage = Math.ceil(core.getToolboxItems('equips').length / this.LAST);
if (core.status.event.data.page < lastPage) {
core.status.event.data.page++;
core.ui.drawEquipbox(core.status.event.selection);
Expand Down Expand Up @@ -1607,7 +1601,7 @@ actions.prototype._clickEquipboxIndex = function (index) {
}
}
else {
var equips = Object.keys(core.status.hero.items.equips || {}).sort();
var equips = core.getToolboxItems('equips');
if (index == core.status.event.selection) {
if (core.isReplaying()) return;
var equipId = equips[index - this.LAST + (core.status.event.data.page - 1) * this.LAST];
Expand All @@ -1625,7 +1619,7 @@ actions.prototype._keyDownEquipbox = function (keycode) {
var last_index = this.LAST - 1;
var per_line = this.HSIZE - 3;
var equipCapacity = core.status.globalAttribute.equipName.length;
var ownEquipment = Object.keys(core.status.hero.items.equips).sort();
var ownEquipment = core.getToolboxItems('equips');
var index = core.status.event.selection;
var page = core.status.event.data.page;
var totalPage = Math.ceil(ownEquipment.length / this.LAST);
Expand Down
12 changes: 5 additions & 7 deletions libs/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -1142,11 +1142,11 @@ control.prototype._updateDamage_extraDamage = function (floorId, ctx, refresh) {
var damage = core.status.checkBlock.damage[x+","+y]||0;
if (damage>0) { // 该点伤害
damage = core.formatBigNumber(damage, true);
core.fillBoldText(ctx, damage, 32*x+16, 32*(y+1)-14, '#FF7F00');
core.fillBoldText(ctx, damage, 32*x+16, 32*(y+1)-14, '#ffaa33');
}
else { // 检查捕捉
if (core.status.checkBlock.ambush[x+","+y]) {
core.fillBoldText(ctx, '!', 32*x+16, 32*(y+1)-14, '#FF7F00');
core.fillBoldText(ctx, '!', 32*x+16, 32*(y+1)-14, '#ffaa33');
}
}
}
Expand Down Expand Up @@ -1486,10 +1486,8 @@ control.prototype._replayAction_item = function (action) {
core.useItem(itemId, false, core.replay);
return true;
}
var tools = Object.keys(core.status.hero.items.tools)
.filter(function (id) { return !core.material.items[id].hideInToolbox; }).sort();
var constants = Object.keys(core.status.hero.items.constants)
.filter(function (id) { return !core.material.items[id].hideInToolbox; }).sort();
var tools = core.getToolboxItems('tools'),
constants = core.getToolboxItems('constants');
var index, per = core.__SIZE__-1;
if ((index=tools.indexOf(itemId))>=0) {
core.status.event.data = {"toolsPage": Math.floor(index/per)+1, "constantsPage":1};
Expand All @@ -1511,7 +1509,7 @@ control.prototype._replayAction_item = function (action) {
control.prototype._replayAction_equip = function (action) {
if (action.indexOf("equip:")!=0) return false;
var equipId = action.substring(6);
var ownEquipment = Object.keys(core.status.hero.items.equips).sort();
var ownEquipment = core.getToolboxItems('equips');
var index = ownEquipment.indexOf(equipId), per = core.__SIZE__-1;
if (index<0) return false;
core.status.route.push(action);
Expand Down
4 changes: 2 additions & 2 deletions libs/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ core.prototype.init = function (coreData, callback) {
this._init_flags();
this._init_platform();
this._init_others();
this._initPlugins();
this._init_plugins();

// 初始化画布
for (var name in core.canvas) {
Expand Down Expand Up @@ -410,7 +410,7 @@ core.prototype._afterLoadResources = function (callback) {
if (callback) callback();
}

core.prototype._initPlugins = function () {
core.prototype._init_plugins = function () {
core.plugin = new function () {};

for (var name in plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1) {
Expand Down
8 changes: 4 additions & 4 deletions libs/enemys.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ enemys.prototype.getDamageString = function (enemy, x, y, floorId) {

if (damage == null) {
damage = "???";
color = '#FF0000';
color = '#FF2222';
}
else {
if (damage <= 0) color = '#00FF00';
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) color = '#FF7F00';
else color = '#FF0000';
else if (damage < core.status.hero.hp) color = '#FF9933';
else color = '#FF2222';

damage = core.formatBigNumber(damage, true);
if (core.enemys.hasSpecial(enemy, 19))
Expand Down
2 changes: 1 addition & 1 deletion libs/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -2226,7 +2226,7 @@ events.prototype._action_waitAsync = function (data, x, y, prefix) {
clearInterval(test);
core.doAction();
}
}, 50);
}, 50 / core.status.replay.speed);
}

events.prototype._action_callBook = function (data, x, y, prefix) {
Expand Down
11 changes: 6 additions & 5 deletions libs/maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ maps.prototype._automaticRoute_bfs = function (startX, startY, destX, destY) {
var queue = new PriorityQueue({comparator: function (a,b) { return a.depth - b.depth; }});
route[startX + "," + startY] = '';
queue.queue({depth: 0, x: startX, y: startY});
var blocks = core.getMapBlocksObj();
while (queue.length!=0) {
var curr = queue.dequeue(), deep = curr.depth, nowX = curr.x, nowY = curr.y;
for (var direction in core.utils.scan) {
Expand All @@ -719,19 +720,19 @@ maps.prototype._automaticRoute_bfs = function (startX, startY, destX, destY) {
// 不可通行
if (core.noPass(nx, ny)) continue;
route[nx+","+ny] = direction;
queue.queue({depth: deep + this._automaticRoute_deepAdd(nx, ny), x: nx, y: ny});
queue.queue({depth: deep + this._automaticRoute_deepAdd(nx, ny, blocks), x: nx, y: ny});
}
if (route[destX+","+destY] != null) break;
}
return route;
}

maps.prototype._automaticRoute_deepAdd = function (x, y) {
maps.prototype._automaticRoute_deepAdd = function (x, y, blocks) {
// 判定每个可通行点的损耗值,越高越应该绕路
var deepAdd = 1;
var block = core.getBlock(x,y);
var block = blocks[x+","+y];
if (block != null){
var id = block.block.event.id;
var id = block.event.id;
// 绕过亮灯
if (id == "light") deepAdd += 100;
// 绕过路障
Expand Down Expand Up @@ -1301,7 +1302,7 @@ maps.prototype._drawThumbnail_drawToTarget = function (floorId, toDraw) {
if (centerY == null) centerY = Math.floor(height / 2);
var tempCanvas = core.bigmap.tempCanvas, tempWidth = 32 * width, tempHeight = 32 * height;

core.clearMap(ctx, x, y, size, size);
// core.clearMap(ctx, x, y, size, size);
if (toDraw.all) {
// 绘制全景图
if (tempWidth <= tempHeight) {
Expand Down
69 changes: 53 additions & 16 deletions libs/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -1919,20 +1919,45 @@ ui.prototype._drawBook_drawOne = function (floorId, index, enemy, pageinfo, sele
core.strokeRoundRect('ui', 10, top + 1, this.PIXEL - 10 * 2, pageinfo.per_height, 10, core.status.globalAttribute.selectColor);
}

ui.prototype._drawBook_is32x32 = function (blockInfo) {
// 判定48的怪物上半部分是否是全透明
var height = blockInfo.height - 32;
var canvas = document.createElement('canvas');
canvas.width = 32; canvas.height = height;
var ctx = canvas.getContext("2d");
core.drawImage(ctx, blockInfo.image, 0, blockInfo.posY * blockInfo.height, 32, height, 0, 0, 32, height);
var url = canvas.toDataURL();
core.clearMap(ctx);
return url == canvas.toDataURL();
}

ui.prototype._drawBook_drawBox = function (index, enemy, top, pageinfo) {
// 横向:22+42;纵向:10 + 42 + 10(正好居中);内部图像 32x32
var border_top = top + (pageinfo.per_height - 42) / 2, border_left = 22;
var img_top = border_top + 5, img_left = border_left + 5;
core.strokeRect('ui', 22, border_top, 42, 42, '#DDDDDD', 2);
var blockInfo = core.getBlockInfo(enemy.id);
if (blockInfo.height >= 42) {
var drawWidth = 42 * 32 / blockInfo.height;
core.status.boxAnimateObjs.push({
'bgx': border_left, 'bgy': border_top, 'bgWidth': 42, 'bgHeight': 42,
'x': img_left - 5 + (42 - drawWidth) / 2, 'y': img_top - 5, 'dw': drawWidth, 'dh': 42,
'height': blockInfo.height, 'animate': blockInfo.animate,
'image': blockInfo.image, 'pos': blockInfo.posY * blockInfo.height
});
var originEnemy = core.material.enemys[enemy.id] || {};
// 检查上半部分是不是纯透明的;取用原始值避免重复计算
if (originEnemy.is32x32 == null) {
originEnemy.is32x32 = this._drawBook_is32x32(blockInfo);
}
if (originEnemy.is32x32) {
core.status.boxAnimateObjs.push({
'bgx': border_left, 'bgy': border_top, 'bgWidth': 42, 'bgHeight': 42,
'x': img_left, 'y': img_top, 'height': 32, 'animate': blockInfo.animate,
'image': blockInfo.image, 'pos': blockInfo.posY * blockInfo.height + blockInfo.height - 32
});
} else {
var drawWidth = 42 * 32 / blockInfo.height;
core.status.boxAnimateObjs.push({
'bgx': border_left, 'bgy': border_top, 'bgWidth': 42, 'bgHeight': 42,
'x': img_left - 5 + (42 - drawWidth) / 2, 'y': img_top - 5, 'dw': drawWidth, 'dh': 42,
'height': blockInfo.height, 'animate': blockInfo.animate,
'image': blockInfo.image, 'pos': blockInfo.posY * blockInfo.height
});
}
} else {
core.status.boxAnimateObjs.push({
'bgx': border_left, 'bgy': border_top, 'bgWidth': 42, 'bgHeight': 42,
Expand Down Expand Up @@ -2048,11 +2073,12 @@ ui.prototype._drawBook_drawDamage = function (index, enemy, offset, position) {
var damage = enemy.damage, color = '#FFFF00';
if (damage == null) {
damage = '无法战斗';
color = '#FF0000';
color = '#FF2222';
}
else {
if (damage >= core.status.hero.hp) color = '#FF0000';
if (damage <= 0) color = '#00FF00';
if (damage >= core.status.hero.hp) color = '#FF2222';
else if (damage >= core.status.hero.hp * 2 / 3) color = '#FF9933';
else if (damage <= 0) color = '#11FF11';
damage = core.formatBigNumber(damage);
if (core.enemys.hasSpecial(enemy, 19)) damage += "+";
if (core.enemys.hasSpecial(enemy, 21)) damage += "-";
Expand Down Expand Up @@ -2255,6 +2281,8 @@ ui.prototype.drawCenterFly = function () {
var fillstyle = 'rgba(255,0,0,0.5)';
if (core.canUseItem('centerFly')) fillstyle = 'rgba(0,255,0,0.5)';
var toX = core.bigmap.width - 1 - core.getHeroLoc('x'), toY = core.bigmap.height - 1 - core.getHeroLoc('y');
this.clearUI();
core.fillRect('ui', 0, 0, this.PIXEL, this.PIXEL, '#000000');
core.drawThumbnail(null, null, {heroLoc: core.status.hero.loc, heroIcon: core.status.hero.image},
{ctx: 'ui', centerX: toX, centerY: toY});
var offsetX = core.clamp(toX - core.__HALF_SIZE__, 0, core.bigmap.width - core.__SIZE__),
Expand All @@ -2274,6 +2302,7 @@ ui.prototype.drawMaps = function (index, x, y) {
core.clearTip();
core.status.checkBlock.cache = {};
var data = this._drawMaps_buildData(index, x, y);
core.fillRect('ui', 0, 0, this.PIXEL, this.PIXEL, '#000000');
core.drawThumbnail(data.floorId, null, {damage: data.damage},
{ctx: 'ui', centerX: data.x, centerY: data.y, all: data.all});
core.clearMap('data');
Expand Down Expand Up @@ -2376,15 +2405,23 @@ ui.prototype.drawToolbox = function(index) {
core.fillText('ui', '返回游戏', this.PIXEL - 46, this.PIXEL - 13);
}

////// 获得所有应该在道具栏显示的某个类型道具 //////
ui.prototype.getToolboxItems = function (cls) {
if (this.uidata.getToolboxItems) {
return this.uidata.getToolboxItems(cls);
}
return Object.keys(core.status.hero.items[cls] || {})
.filter(function (id) { return !core.material.items[id].hideInToolbox; })
.sort();
}

ui.prototype._drawToolbox_getInfo = function (index) {
// 设定eventdata
if (!core.status.event.data || core.status.event.data.toolsPage == null)
core.status.event.data = {"toolsPage":1, "constantsPage":1, "selectId":null}
// 获取物品列表
var tools = Object.keys(core.status.hero.items.tools)
.filter(function (id) { return !core.material.items[id].hideInToolbox; }).sort();
var constants = Object.keys(core.status.hero.items.constants)
.filter(function (id) { return !core.material.items[id].hideInToolbox; }).sort();
var tools = core.getToolboxItems('tools'),
constants = core.getToolboxItems('constants');
// 处理页数
var toolsPage = core.status.event.data.toolsPage;
var constantsPage = core.status.event.data.constantsPage;
Expand Down Expand Up @@ -2511,7 +2548,7 @@ ui.prototype._drawEquipbox_getInfo = function (index) {
var equipLength = allEquips.length;
if (!core.status.hero.equipment) core.status.hero.equipment = [];
var equipEquipment = core.status.hero.equipment;
var ownEquipment = Object.keys(core.status.hero.items.equips).sort();
var ownEquipment = core.getToolboxItems('equips');
var page = core.status.event.data.page;
var totalPage = Math.ceil(ownEquipment.length / this.LAST);
// 处理index
Expand Down Expand Up @@ -2839,7 +2876,7 @@ ui.prototype.drawKeyBoard = function () {
if (isWindowSkin)
this.drawWindowSelector(core.status.textAttribute.background, this.HPIXEL + 92, offset - 22, 72, 27);
else
core.strokeRoundRect('ui', this.HPIXEL + 92, offset - 22, 72, 27, 6, "#FFD700", 2);
core.strokeRoundRect('ui', this.HPIXEL + 92, offset - 22, 72, 27, 6, core.status.globalAttribute.selectColor, 2);
}

////// 绘制状态栏 /////
Expand Down
9 changes: 9 additions & 0 deletions project/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,15 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
}
},
"ui": {
"getToolboxItems": function (cls) {
// 获得道具栏中当前某类型道具的显示项和显示顺序
// cls为道具类型,只可能是 tools, constants 和 equips
// 返回一个数组,代表当前某类型道具的显示内容和顺序

return Object.keys(core.status.hero.items[cls] || {})
.filter(function (id) { return !core.material.items[id].hideInToolbox; })
.sort();
},
"drawStatusBar": function () {
// 自定义绘制状态栏,需要开启状态栏canvas化

Expand Down
Loading

0 comments on commit d0b0fec

Please sign in to comment.