mirror of
https://github.com/motajs/template.git
synced 2026-11-03 07:24:30 +08:00
feat: 完善内置特殊属性
This commit is contained in:
1 parent
a0e402728e
commit
3f74d5f25e
10 files changed
+221
-16
No files matched your search
@@ -148,6 +148,11 @@ export class MainDamageCalculator implements IDamageCalculator<
|
||||
damage += handler.state.flags.getFieldValueDefaults('hatred', 0);
|
||||
}
|
||||
|
||||
// 自爆
|
||||
if (enemy.hasSpecial(17)) {
|
||||
damage = Math.max(damage, hp - 1);
|
||||
}
|
||||
|
||||
return {
|
||||
damage: Math.floor(damage),
|
||||
turn
|
||||
|
||||
+100
-1
@@ -7,6 +7,7 @@ import {
|
||||
PercentageModifier
|
||||
} from '@user/data-base';
|
||||
import {
|
||||
FaceGroup,
|
||||
IEnemyAttr,
|
||||
IHeroAttr,
|
||||
IObjectMover,
|
||||
@@ -22,8 +23,17 @@ import {
|
||||
IPathfindingSystem,
|
||||
IPathfindingSystemHooks
|
||||
} from '@user/data-system';
|
||||
import { ICombatWeakHandler } from './types';
|
||||
import { ICombatWeakHandler, MapDamageType } from './types';
|
||||
import { isNil } from 'lodash-es';
|
||||
import { ISpecial19Value } from './special';
|
||||
|
||||
const mapDamageTypeString: Record<number, string> = {
|
||||
[MapDamageType.Between]: '夹击',
|
||||
[MapDamageType.Layer]: '激光',
|
||||
[MapDamageType.Repulse]: '阻击',
|
||||
[MapDamageType.Zone]: '领域',
|
||||
[MapDamageType.Unknown]: '地图'
|
||||
};
|
||||
|
||||
export class EnemyMoveHooks implements IObjectMoverHooks<IHeroLocation> {
|
||||
constructor(readonly state: ICoreState) {}
|
||||
@@ -57,6 +67,71 @@ export class EnemyMoveHooks implements IObjectMoverHooks<IHeroLocation> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理地图伤害
|
||||
* @param location 勇士位置对象
|
||||
*/
|
||||
private async handleMapDamage(location: IHeroLocation) {
|
||||
if (isNil(location.floorId)) return;
|
||||
|
||||
const context = this.state.enemyContext;
|
||||
const mapDamage = context.getMapDamage();
|
||||
if (!mapDamage) return;
|
||||
const damage = mapDamage.getReducedDamage(location);
|
||||
if (!damage) return;
|
||||
const hero = this.state.hero.getModifiableAttribute();
|
||||
// 首先掉血
|
||||
hero.add('hp', -damage.damage);
|
||||
this.state.emitTip(
|
||||
`玩家受到${mapDamageTypeString[damage.type]}伤害${damage.damage}点`
|
||||
);
|
||||
|
||||
// 获取朝向处理工具,用于处理位移技能
|
||||
const handler = this.state.faceManager.get(FaceGroup.Dir8);
|
||||
if (!handler) return;
|
||||
// 获取当前地图事件层
|
||||
const map = this.state.maps.getMap(location.floorId);
|
||||
if (!map) return;
|
||||
const event = map.eventLayer;
|
||||
if (!event) return;
|
||||
|
||||
const movings: Promise<unknown>[] = [];
|
||||
|
||||
// 阻击效果
|
||||
for (const repulse of damage.extra.repulse) {
|
||||
const dx = location.x - repulse.x;
|
||||
const dy = location.y - repulse.y;
|
||||
const dir = handler.dirOf(-dx, -dy);
|
||||
const next = event.getTile(
|
||||
location.x + dx * 2,
|
||||
location.y + dy * 2
|
||||
);
|
||||
// 身后有东西就无法后退无法后退
|
||||
if (next) continue;
|
||||
movings.push(
|
||||
event.moveBlock(repulse.x, repulse.y, dir, 1, 200, true)
|
||||
);
|
||||
}
|
||||
|
||||
// 捕捉效果
|
||||
for (const cat of damage.extra.catch) {
|
||||
const view = context.getEnemyByLocator(cat);
|
||||
if (!view) continue;
|
||||
const computed = view.getComputedEnemy();
|
||||
const dx = location.x - cat.x;
|
||||
const dy = location.y - cat.y;
|
||||
const dir = handler.dirOf(dx, dy);
|
||||
const moving = event
|
||||
.moveBlock(cat.x, cat.y, dir, 1, 200, true)
|
||||
.then(() => {
|
||||
return this.state.combat.battleComputed(computed);
|
||||
});
|
||||
movings.push(moving);
|
||||
}
|
||||
|
||||
await Promise.all(movings);
|
||||
}
|
||||
|
||||
async onStepEnd(
|
||||
_code: number,
|
||||
step: Readonly<ObjectMoveStep>,
|
||||
@@ -70,6 +145,8 @@ export class EnemyMoveHooks implements IObjectMoverHooks<IHeroLocation> {
|
||||
|
||||
// 处理中毒
|
||||
this.handlePoison(step, mover as IHeroMover<IHeroLocation>);
|
||||
|
||||
await this.handleMapDamage(tile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,6 +239,28 @@ export class EnemyCombatHooks
|
||||
this.setWeakValue(max);
|
||||
}
|
||||
|
||||
// 处理诅咒属性
|
||||
if (info.handler.enemy.hasSpecial(12)) {
|
||||
this.state.flags.setFieldValue('curse', true);
|
||||
}
|
||||
|
||||
// 处理仇恨属性
|
||||
const currHatred = this.state.flags.getOrInsert('currHatred', 0);
|
||||
if (info.handler.enemy.hasSpecial(15)) {
|
||||
currHatred.set(Math.floor(currHatred.get() / 2));
|
||||
} else {
|
||||
const hatred = this.state.flags.getFieldValueDefaults('hatred', 1);
|
||||
currHatred.add(hatred);
|
||||
}
|
||||
|
||||
// 处理退化属性
|
||||
const degrade = info.handler.enemy.getSpecial<ISpecial19Value>(19);
|
||||
if (degrade) {
|
||||
const hero = this.state.hero.getModifiableAttribute();
|
||||
hero.add('atk', -degrade.value.atkValue);
|
||||
hero.add('def', -degrade.value.defValue);
|
||||
}
|
||||
|
||||
// 处理重生属性
|
||||
if (info.handler.enemy.hasSpecial(21)) {
|
||||
const field = this.state.flags.getFieldValueDefaults<
|
||||
|
||||
@@ -47,9 +47,11 @@ export class MainCombatScript implements ICombatScript<IEnemyAttr, IHeroAttr> {
|
||||
const totalExp = baseExp + guardExp;
|
||||
const totalMoney = baseMoney + guardMoney;
|
||||
|
||||
// 给勇士添加经验和金币
|
||||
hero.add('exp', totalExp);
|
||||
hero.add('money', totalMoney);
|
||||
// 给勇士添加经验和金币,诅咒不加
|
||||
if (!handler.state.flags.getFieldValueDefaults('curse', false)) {
|
||||
hero.add('exp', totalExp);
|
||||
hero.add('money', totalMoney);
|
||||
}
|
||||
|
||||
// 进行全局提示
|
||||
handler.state.emitTip(
|
||||
|
||||
@@ -32,7 +32,7 @@ export interface ISpecial13Value {
|
||||
}
|
||||
|
||||
/** 21 - 退化 */
|
||||
export interface ISpecial21Value {
|
||||
export interface ISpecial19Value {
|
||||
/** 攻击下降值 */
|
||||
atkValue: number;
|
||||
/** 防御下降值 */
|
||||
@@ -320,7 +320,7 @@ export function createSpecials(
|
||||
// 19 - 退化
|
||||
map.set(
|
||||
19,
|
||||
defineCommonSerializableSpecial<ISpecial21Value>(
|
||||
defineCommonSerializableSpecial<ISpecial19Value>(
|
||||
19,
|
||||
{ atkValue: 0, defValue: 0 },
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user