drawLight & shop icons

This commit is contained in:
oc 2019-01-21 22:19:24 +08:00
parent d1e164b66a
commit e317259f42
7 changed files with 69 additions and 51 deletions

View File

@ -1886,6 +1886,7 @@ actions.prototype.clickSwitchs = function (x,y) {
case 8:
core.platform.extendKeyboard = !core.platform.extendKeyboard;
core.setLocalStorage('extendKeyboard', core.platform.extendKeyboard);
core.updateStatusBar();
core.ui.drawSwitchs();
break;
case 9:

View File

@ -2053,9 +2053,17 @@ control.prototype.openQuickShop = function (need) {
control.prototype.openKeyBoard = function (need) {
if (core.isReplaying()) return;
if (!core.checkStatus('keyBoard', need))
return;
core.ui.drawKeyBoard();
if (core.platform.extendKeyboard) {
if (!core.checkStatus('keyBoard', need))
return;
core.ui.drawKeyBoard();
}
else {
if (!core.checkStatus('selectShop', need))
return;
core.ui.drawQuickShop();
}
}
////// 点击保存按钮时的打开操作 //////
@ -2736,7 +2744,8 @@ control.prototype.updateStatusBar = function () {
core.statusBar.image.toolbox.src = core.statusBar.icons.toolbox.src;
core.statusBar.image.keyboard.src = core.statusBar.icons.keyboard.src;
core.statusBar.image.keyboard.src =
core.platform.extendKeyboard ? core.statusBar.icons.keyboard.src : core.statusBar.icons.shop.src;
core.statusBar.image.save.src = core.statusBar.icons.save.src;

View File

@ -8,7 +8,12 @@ function enemys() {
enemys.prototype.init = function () {
this.enemys = enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80;
this.enemydata = functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a.enemys;
if (main.mode=='play') this.enemydata.hasSpecial = function (a, b) {return core.enemys.hasSpecial(a, b)};
if (main.mode=='play') {
this.enemydata.hasSpecial = function (a, b) {return core.enemys.hasSpecial(a, b)};
for (var enemyId in this.enemys) {
this.enemys[enemyId].id = enemyId;
}
}
}
////// 获得一个或所有怪物数据 //////
@ -185,6 +190,11 @@ enemys.prototype.nextCriticals = function (enemy, number, x, y, floorId) {
return [];
}
// getDamageInfo直接返回数字
if (typeof info == 'number') {
return [[0,0]];
}
if (info.damage<=0 && !core.flags.enableNegativeDamage) {
return [[0,0]];
}
@ -200,7 +210,7 @@ enemys.prototype.nextCriticals = function (enemy, number, x, y, floorId) {
if (nextAtk<=hero_atk) break;
if (nextAtk!=pre) {
var nextInfo = this.getDamageInfo(enemy, core.status.hero.hp, nextAtk, core.status.hero.def, core.status.hero.mdef, x, y, floorId);
if (nextInfo==null) break;
if (nextInfo==null || (typeof nextInfo == 'number')) break;
list.push([nextAtk-hero_atk,Math.floor(info.damage-nextInfo.damage)]);
if (nextInfo.damage<=0 && !core.flags.enableNegativeDamage) break;
pre = nextAtk;
@ -217,7 +227,7 @@ enemys.prototype.nextCriticals = function (enemy, number, x, y, floorId) {
if (hero_atk <= LOOP_MAX_VALUE) { // 循环法
for (var atk=hero_atk+1;atk<=mon_hp+mon_def;atk++) {
var nextInfo = this.getDamageInfo(enemy, core.status.hero.hp, atk, core.status.hero.def, core.status.hero.mdef, x, y, floorId);
if (nextInfo==null) break;
if (nextInfo==null || (typeof nextInfo == 'number')) break;
if (pre>nextInfo.damage) {
pre = nextInfo.damage;
list.push([atk-hero_atk, info.damage-nextInfo.damage]);
@ -234,12 +244,12 @@ enemys.prototype.nextCriticals = function (enemy, number, x, y, floorId) {
while (start<end) {
var mid = Math.floor((start+end)/2);
var nextInfo = core.enemys.getDamageInfo(enemy, core.status.hero.hp, mid, core.status.hero.def, core.status.hero.mdef, x, y, floorId);
if (nextInfo == null) return null;
if (nextInfo == null || (typeof nextInfo == 'number')) return null;
if (pre>nextInfo.damage) end = mid;
else start = mid+1;
}
var nextInfo = core.enemys.getDamageInfo(enemy, core.status.hero.hp, start, core.status.hero.def, core.status.hero.mdef, x, y, floorId);
return nextInfo==null||nextInfo.damage>=pre?null:[start,nextInfo.damage];
return nextInfo==null||(typeof nextInfo == 'number')||nextInfo.damage>=pre?null:[start,nextInfo.damage];
}
var currAtk = hero_atk;
while (true) {
@ -285,6 +295,7 @@ enemys.prototype.calDamage = function (enemy, hero_hp, hero_atk, hero_def, hero_
var info = this.getDamageInfo(enemy, hero_hp, hero_atk, hero_def, hero_mdef, x, y, floorId);
if (info == null) return null;
if (typeof info == 'number') return info;
return info.damage;
}

View File

@ -88,6 +88,8 @@ loader.prototype.loadIcons = function () {
core.statusBar.image[key].src = core.statusBar.icons[key].src;
}
}
core.statusBar.image.keyboard.src =
core.platform.extendKeyboard ? core.statusBar.icons.keyboard.src : core.statusBar.icons.shop.src;
});
}

View File

@ -149,7 +149,8 @@ function main() {
'btn4': 33,
'btn5': 34,
'btn6': 35,
'btn7': 36
'btn7': 36,
'shop': 37
},
'floor': document.getElementById('floor'),
'name': document.getElementById('name'),

View File

@ -293,8 +293,8 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
// 事件的处理
var todo = [];
// 如果不为阻击,且该点存在,且有事件
if (!core.enemys.hasSpecial(special, 18) && core.isset(x) && core.isset(y)) {
// 如果该点存在,且有事件 -- V2.5.4 以后阻击怪也可以有战后事件了
if (core.isset(x) && core.isset(y)) {
var event = core.floors[core.status.floorId].afterBattle[x+","+y];
if (core.isset(event)) {
// 插入事件
@ -1263,63 +1263,57 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
// 绘制灯光/漆黑层效果。调用方式 core.plugin.drawLight(...)
// 【参数说明】
// color可选灯光以外部分的颜色可以是一个四元数组或者简单的一个0到1之间的数。忽略则默认为0.9。
// 如果是四元数组则代表RGBA值如 [255,255,0,0.2] 就代表 #FFFF00 且不透明度0.2
// 如果是一个数则只是不透明度的值RGB均为0如 0.9 就代表 [0,0,0,0.9]
// name必填要绘制到的画布名可以是一个系统画布或者是个自定义画布如果不存在则创建
// color可选只能是一个0~1之间的数为不透明度的值。不填则默认为0.9。
// lights可选一个数组定义了每个独立的灯光。
// 其中每一项是三元组 [x,y,r] 或者四元组 [x,y,r,o]
// x和y分别为该灯光的横纵坐标r为该灯光的半径o为该灯光中心的不透明度可忽略默认为0。
// 其中每一项是三元组 [x,y,r] x和y分别为该灯光的横纵坐标r为该灯光的半径。
// lightDec可选0到1之间光从多少百分比才开始衰减在此范围内保持全亮不设置默认为0。
// 比如lightDec为0.5代表每个灯光部分内圈50%的范围全亮50%以后才开始快速衰减。
// 【调用样例】
// core.plugin.drawLight(); // 绘制一个0.9的全图不透明度,等价于更改画面色调为[0,0,0,0.9]。
// core.plugin.drawLight(0.95, [[25,11,46]]); // 全图不透明度0.95,其中在(25,11)点存在一个半径为46的灯光效果。
// core.plugin.drawLight([255,255,0,0.2], [[25,11,46,0.1]]); // 全图为不透明度0.2的黄色,其中在(25,11)点存在一个半径为46的灯光效果灯光中心不透明度0.1。
// core.plugin.drawLight(0.9, [[25,11,46],[105,121,88],[301,221,106]]); // 存在三个灯光效果,分别是中心(25,11)半径46中心(105,121)半径88中心(301,221)半径106。
// core.plugin.drawLight([0,0,255,0.3], [[25,11,46],[105,121,88,0.2]], 0.4); // 存在两个灯光效果它们在内圈40%范围内保持全亮且40%后才开始衰减。
this.drawLight = function (color, lights, lightDec) {
// core.plugin.drawLight('curtain'); // 在curtain层绘制全图不透明度0.9,等价于更改画面色调为[0,0,0,0.9]。
// core.plugin.drawLight('ui', 0.95, [[25,11,46]]); // 在ui层绘制全图不透明度0.95,其中在(25,11)点存在一个半径为46的灯光效果。
// core.plugin.drawLight('test', 0.2, [[25,11,46,0.1]]); // 创建一个test图层不透明度0.2,其中在(25,11)点存在一个半径为46的灯光效果灯光中心不透明度0.1。
// core.plugin.drawLight('test2', 0.9, [[25,11,46],[105,121,88],[301,221,106]]); // 创建test2图层存在三个灯光效果,分别是中心(25,11)半径46中心(105,121)半径88中心(301,221)半径106。
// core.plugin.drawLight('xxx', 0.3, [[25,11,46],[105,121,88,0.2]], 0.4); // 存在两个灯光效果它们在内圈40%范围内保持全亮且40%后才开始衰减。
this.drawLight = function (name, color, lights, lightDec) {
// 清空色调层也可以修改成其它层比如animate/weather层或者用自己创建的canvas
var canvasName = 'curtain';
var ctx = core.getContextByName(canvasName);
if (ctx == null) return;
var ctx = core.getContextByName(name);
if (ctx == null) {
if (typeof name == 'string')
ctx = core.createCanvas(name, 0, 0, 416, 416, 98);
else return;
}
ctx.mozImageSmoothingEnabled = false;
ctx.webkitImageSmoothingEnabled = false;
ctx.msImageSmoothingEnabled = false;
ctx.imageSmoothingEnabled = false;
ctx.clearRect(0, 0, 416, 416);
core.clearMap(name);
// 绘制色调层,默认不透明度
if (!core.isset(color)) color = 0.9;
if (typeof color == "number") color = [0,0,0,color];
ctx.fillStyle = core.arrayToRGBA(color);
ctx.fillRect(0, 0, 416, 416);
ctx.fillStyle = "rgba(0,0,0,"+color+")";
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
lightDec = core.clamp(lightDec, 0, 1);
// 绘制每个灯光效果
if (!core.isset(lights) || lights.length==0) return;
lightDec = core.clamp(lightDec, 0, 1);
ctx.globalCompositeOperation = 'destination-out';
lights.forEach(function (light) {
// 坐标,半径,中心不透明度
var x = light[0], y = light[1], r = light[2], o = 255 * (1 - core.clamp(light[3], 0, 1));
var x = light[0], y = light[1], r = light[2];
// 计算衰减距离
var decDistance = parseInt(r * lightDec), leftDistance = r - decDistance;
var decDistance = parseInt(r * lightDec);
// 正方形区域的直径和左上角坐标
var d = r * 2, sx = x - r, sy = y - r;
// 获得正方形区域的颜色信息
var imageData = ctx.getImageData(sx, sy, d, d);
// 对每个像素点进行遍历
for (var i = 0; i < imageData.data.length; i+=4) {
// 当前点的坐标
var index = i / 4, cx = parseInt(index/d), cy = index%d;
// 当前点距离中心点的距离
var dx = r - cx, dy = r - cy, distance = Math.sqrt(dx*dx+dy*dy);
if (distance >= r) continue;
// 计算当前点的alpha值
var alpha = imageData.data[i+3] - (distance<decDistance?1:(r-distance)/leftDistance)*o;
imageData.data[i+3] = core.clamp(alpha, 0, 255);
}
ctx.putImageData(imageData, sx, sy);
var grd=ctx.createRadialGradient(x,y,decDistance,x,y,r);
grd.addColorStop(0, "rgba(0,0,0,1)");
grd.addColorStop(1, "rgba(0,0,0,0)");
ctx.beginPath();
ctx.fillStyle=grd;
ctx.arc(x,y,r,0,2*Math.PI);
ctx.fill();
});
ctx.globalCompositeOperation = 'source-over';
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 26 KiB