重构怪物属性定义

This commit is contained in:
AncTe committed 2023-08-07 17:57:51 +08:00
1 parent 93fad2f637
commit 9bab089a14
18 files changed
+250 -610

No files matched your search

+1 -5
View File
@@ -103,11 +103,7 @@ editor_multi = function () {
"!doc": core.material.items[name].name || "道具"
}
});
functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a.enemys.getSpecials().forEach(function (one) {
var name = one[1];
if (name instanceof Function) name = name({});
coredef.core.enemys.hasSpecial["!doc"] += name + "(" + one[0] + "); ";
});
Object.keys(core.canvas).forEach(function (name) {
coredef.core.canvas[name] = {
"!type": "CanvasRenderingContext2D",
+2 -11
View File
@@ -191,18 +191,9 @@ var comment_c456ea59_6018_45ef_8bcc_211a24c627dc = {
"_leaf": true,
"_type": "popCheckboxSet",
"_checkboxSet": function () {
var array = functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a.enemys.getSpecials()
var b = [],
c = [];
for (var index = 0; index < array.length; index++) {
b.push(array[index][0])
var name = array[index][1];
if (name instanceof Function) name = name({});
c.push(name + "(" + array[index][0] + ")")
}
return {
"prefix": c,
"key": b
"prefix": [],
"key": []
}
},
"_data": "特殊属性"
+9 -143
View File
@@ -9,15 +9,9 @@ function enemys() {
////// 初始化 //////
enemys.prototype._init = function () {
this.enemys = enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80;
this.enemydata = functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a.enemys;
for (var enemyId in this.enemys) {
this.enemys[enemyId].id = enemyId;
}
if (main.mode == 'play') {
this.enemydata.hasSpecial = function (a, b) {
return core.enemys.hasSpecial(a, b);
};
}
};
enemys.prototype.getEnemys = function () {
@@ -62,143 +56,40 @@ enemys.prototype.getEnemys = function () {
////// 判断是否含有某特殊属性 //////
enemys.prototype.hasSpecial = function (special, test) {
if (special == null) return false;
if (special instanceof Array) {
return special.indexOf(test) >= 0;
}
if (typeof special == 'number') {
return special === test;
}
if (typeof special == 'string') {
return this.hasSpecial(core.material.enemys[special], test);
}
if (special.special != null) {
return this.hasSpecial(special.special, test);
}
return false;
// Deprecated. Use `Array.includes` instead.
};
enemys.prototype.getSpecials = function () {
return this.enemydata.getSpecials();
// Deprecated. See src/plugin/game/enemy/special.ts
};
////// 获得所有特殊属性的名称 //////
enemys.prototype.getSpecialText = function (enemy) {
if (typeof enemy == 'string') enemy = core.material.enemys[enemy];
if (!enemy) return [];
var special = enemy.special;
var text = [];
var specials = this.getSpecials();
if (specials) {
for (var i = 0; i < specials.length; i++) {
if (this.hasSpecial(special, specials[i][0]))
text.push(this._calSpecialContent(enemy, specials[i][1]));
}
}
return text;
// Deprecated.
};
////// 获得所有特殊属性的颜色 //////
enemys.prototype.getSpecialColor = function (enemy) {
if (typeof enemy == 'string') enemy = core.material.enemys[enemy];
if (!enemy) return [];
var special = enemy.special;
var colors = [];
var specials = this.getSpecials();
if (specials) {
for (var i = 0; i < specials.length; i++) {
if (this.hasSpecial(special, specials[i][0]))
colors.push(specials[i][3] || null);
}
}
return colors;
// Deprecated.
};
////// 获得所有特殊属性的额外标记 //////
enemys.prototype.getSpecialFlag = function (enemy) {
if (typeof enemy == 'string') enemy = core.material.enemys[enemy];
if (!enemy) return [];
var special = enemy.special;
var flag = 0;
var specials = this.getSpecials();
if (specials) {
for (var i = 0; i < specials.length; i++) {
if (this.hasSpecial(special, specials[i][0]))
flag |= specials[i][4] || 0;
}
}
return flag;
// Deprecated.
};
////// 获得每个特殊属性的说明 //////
enemys.prototype.getSpecialHint = function (enemy, special) {
var specials = this.getSpecials();
if (special == null) {
if (specials == null) return [];
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])
);
}
return hints;
}
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 '';
// Deprecated.
};
enemys.prototype._calSpecialContent = function (enemy, content) {
if (typeof content == 'string') return content;
if (typeof enemy == 'string') enemy = core.material.enemys[enemy];
if (content instanceof Function) {
return content(enemy);
}
return '';
// Deprecated.
};
////// 获得某个点上某个怪物的某项属性 //////
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 (enemy == null) {
var block = core.getBlock(x, y, floorId);
if (block == null) return null;
enemy = core.material.enemys[block.event.id];
}
if (typeof enemy == 'string') enemy = core.material.enemys[enemy];
if (enemy == null) return null;
return enemy[name];
// Deprecated.
};
////// 能否获胜 //////
@@ -273,30 +164,5 @@ enemys.prototype._getCurrentEnemys_sort = function (enemys) {
};
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;
});
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;
}
}
}
return false;
// Deprecated.
};
+3 -42
View File
@@ -2203,19 +2203,7 @@ events.prototype._action_setEnemy = function (data, x, y, prefix) {
};
events.prototype._action_setEnemyOnPoint = function (data, x, y, prefix) {
var loc = this.__action_getLoc2D(data.loc, x, y, prefix);
loc.forEach(function (one) {
core.setEnemyOnPoint(
one[0],
one[1],
data.floorId,
data.name,
data.value,
data.operator,
prefix,
data.norefresh
);
});
// Deprecated.
core.doAction();
};
@@ -3545,35 +3533,8 @@ events.prototype.setEnemy = function (
};
////// 设置某个点上的怪物属性 //////
events.prototype.setEnemyOnPoint = function (
x,
y,
floorId,
name,
value,
operator,
prefix,
norefresh
) {
floorId = floorId || core.status.floorId;
var block = core.getBlock(x, y, floorId);
if (block == null) return;
if (block.event.cls.indexOf('enemy') != 0) return;
var enemy = core.material.enemys[block.event.id];
if (enemy == null) return;
if (typeof value === 'string' && name == 'name')
value = value.replaceAll(/\r/g, '\\r');
value = this._updateValueByOperator(
core.calValue(value, prefix),
core.getEnemyValue(enemy, name, x, y, floorId),
operator
);
flags.enemyOnPoint = flags.enemyOnPoint || {};
flags.enemyOnPoint[floorId] = flags.enemyOnPoint[floorId] || {};
flags.enemyOnPoint[floorId][x + ',' + y] =
flags.enemyOnPoint[floorId][x + ',' + y] || {};
flags.enemyOnPoint[floorId][x + ',' + y][name] = value;
if (!norefresh) core.updateStatusBar();
events.prototype.setEnemyOnPoint = function (x, y) {
// Deprecated.
};
////// 重置某个点上的怪物属性 //////
-225
View File
@@ -327,231 +327,6 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = {
if (todo.length > 0) core.insertAction(todo, x, y);
}
},
enemys: {
getSpecials: function () {
// todo: 重写
// 获得怪物的特殊属性,每一行定义一个特殊属性。
// 分为五项,第一项为该特殊属性的数字,第二项为特殊属性的名字,第三项为特殊属性的描述
// 第四项为该特殊属性的颜色,可以写十六进制 #RRGGBB 或者 [r,g,b,a] 四元数组
// 第五项为该特殊属性的标记;目前 1 代表是地图类技能(需要进行遍历全图)
// 名字和描述可以直接写字符串,也可以写个function将怪物传进去
return [
[
1,
'致命一击',
function (enemy) {
return (
'怪物每5回合触发一次强力攻击,造成' +
(enemy.crit || 100) +
'%的伤害'
);
},
'#fc3'
],
[2, '恶毒', '怪物攻击无视勇士的防御', '#bbb0ff'],
[3, '坚固', '怪物防御不小于勇士攻击-1', '#c0b088'],
[4, '2连击', '怪物每回合攻击2次', '#ffee77'],
[5, '3连击', '怪物每回合攻击3次', '#ffee77'],
[
6,
function (enemy) {
return (enemy.n || '') + '连击';
},
function (enemy) {
return '怪物每回合攻击' + (enemy.n || 4) + '次';
},
'#ffee77'
],
[
7,
'饥渴',
function (enemy) {
return (
'战斗前,怪物偷取勇士' +
(enemy.hungry || 0) +
'%的攻击加在自己身上(勇士攻击也会降低)'
);
},
'#b67'
],
[
8,
'抱团',
function (enemy) {
return (
'怪物周围5×5范围内每有一个拥有该属性的怪物,该怪物攻防就增加' +
(enemy.together || 0) +
'%(线性叠加)'
);
},
'#ffaa44',
1
],
[
9,
'绝对防御',
function () {
return '怪物的奇特护甲可以让勇士的额外攻击变为正常攻击(相当于勇士的攻击变为基础攻击+额外攻击)';
},
'#80eed6'
],
[
10,
'勇气之刃',
function (enemy) {
return (
'第一回合造成' +
(enemy.courage || 100) +
'%的伤害,之后正常'
);
},
'#b0c0dd'
],
[
11,
'勇气冲锋',
function (enemy) {
return (
'怪物首先发动冲锋,造成' +
(enemy.charge || 100) +
'%的伤害,并眩晕勇士5回合'
);
},
'#ff00d2'
],
[
12,
'追猎',
'当勇士移动到该怪物的水平或竖直方向上时,怪物向勇士移动一格',
'#99ee88',
2
],
[13, '魔攻', '怪物攻击无视勇士防御', '#bbb0ff'],
[
14,
'智慧之源',
'困难难度下(简单难度没有效果),战斗后,怪物会吸取勇士30%的智慧(勇士智慧向下取整至整十)加在本层的拥有该属性的怪物攻击上',
'#bbeef0'
],
[
15,
'突刺',
function (enemy) {
return (
'经过怪物周围' +
(enemy.zoneSquare ? '九宫格' : '十字') +
'范围内' +
(enemy.range || 1) +
'格时怪物会攻击勇士,造成' +
core.formatBigNumber(
Math.max(
(enemy.value || 0) -
core.plugin.hero.getHeroStatusOn('def')
)
) +
'点伤害'
);
},
'#c677dd'
],
[
16,
'夹击',
'经过两只相同的怪物中间,勇士生命值变成一半',
'#bb99ee'
],
[17, '先攻', '战斗时怪物首先攻击', '#b0b666'],
[
18,
'阻击',
function (enemy) {
return (
'经过怪物的十字领域时自动减生命' +
(enemy.value || 0) +
'点,同时怪物后退一格'
);
},
'#8888e6'
],
[
19,
'电摇嘲讽',
'当勇士移动到怪物同行或同列时,勇士会直接冲向怪物,撞碎路上的所有地形和门,拾取路上的道具,与路上的怪物战斗' +
',最后与该怪物战斗',
'#ff6666'
],
[
20,
'霜冻',
enemy =>
`怪物寒冷的攻击使勇士动作变慢,勇士每回合对怪物造成的伤害减少${enemy.ice}%。装备杰克的衣服后可以免疫。`,
'cyan'
],
[
21,
'冰封光环',
enemy =>
`寒气逼人,使勇士对该怪物周围7*7范围内的怪物伤害减少${enemy.iceHalo}%(线性叠加)`,
'cyan',
1
],
[
22,
'永夜',
enemy =>
`战斗后,减少勇士${enemy.night}点攻防,增加本层所有怪物${enemy.night}点攻防,仅在本层有效`,
'#d8a'
],
[
23,
'极昼',
enemy =>
`战斗后,减少本层所有怪物${enemy.day}点攻防,增加勇士${enemy.day}点攻防,仅在本层有效`,
'#ffd'
],
[
24,
'射击',
function () {
return '经过怪物同行或同列的可视范围内时受到一次普通攻击的伤害';
},
'#dda0dd'
],
[
25,
'融化',
enemy =>
`战斗后该怪物会融化,在怪物位置产生一个3*3的范围光环,光环内怪物的攻防增加${enemy.melt}%`,
'#e6e099',
1
],
[
26,
'冰封之核',
enemy =>
`怪物拥有逼人的寒气,使周围5*5范围内的怪物防御增加${enemy.iceCore}%`,
'#70ffd1',
1
],
[
27,
'火焰之核',
enemy =>
`怪物拥有灼热的火焰,使周围5*5范围内的怪物攻击增加${enemy.fireCore}%`,
'#ff6f0a',
1
],
[
28,
'苍蓝刻',
enemy =>
`怪物使用苍蓝之灵的力量,使自身受到的伤害减少${enemy.paleShield}%`,
'#ff6f0a',
1
]
];
}
},
actions: {
onKeyUp: function (keyCode, altKey) {
// 键盘按键处理,可以在这里自定义快捷键列表