refactor: 技能系统

This commit is contained in:
AncTe committed 2024-11-07 23:43:08 +08:00
1 parent eca62f5dd0
commit d137068f4f
17 files changed
+235 -86

No files matched your search

+2 -7
View File
@@ -1,7 +1,7 @@
import { DamageEnemy, ensureFloorDamage, getSingleEnemy } from './damage';
import { findDir, has } from '../../plugin/game/utils';
import { hook, loading } from '../game';
import { NightSpecial } from '../mechanism/misc';
import { HeroSkill, NightSpecial } from '../mechanism/misc';
export interface CurrentEnemy {
enemy: DamageEnemy;
@@ -225,12 +225,7 @@ function init() {
'打败 ' + enemy.enemy.name + ',金币+' + money + ',经验+' + exp;
core.drawTip(hint, enemy.id);
if (core.getFlag('bladeOn') && core.getFlag('blade')) {
core.setFlag('blade', false);
}
if (core.getFlag('shieldOn') && core.getFlag('shield')) {
core.setFlag('shield', false);
}
HeroSkill.disableSkill();
// 事件的处理
const todo: MotaEvent = [];
+14 -15
View File
@@ -3,7 +3,7 @@ import { Range } from '../util/range';
import { ensureArray, has, manhattan } from '@/plugin/game/utils';
import EventEmitter from 'eventemitter3';
import { hook } from '../game';
import { NightSpecial } from '../mechanism/misc';
import { HeroSkill, NightSpecial } from '../mechanism/misc';
// todo: 光环划分优先级,从而可以实现光环的多级运算
@@ -772,27 +772,26 @@ export class DamageEnemy<T extends EnemyIds = EnemyIds> {
private calEnemyDamageOf(hero: Partial<HeroStatus>, enemy: EnemyInfo) {
const status = getHeroStatusOf(hero, realStatus, this.floorId);
let damage = calDamageWith(enemy, status) ?? Infinity;
let skill = -1;
let bestSkill = -1;
// 自动切换技能
if (flags.autoSkill) {
for (let i = 0; i < skills.length; i++) {
const [unlock, condition] = skills[i];
if (!flags[unlock]) continue;
flags[condition] = true;
if (HeroSkill.getAutoSkill()) {
for (const skill of skills) {
if (!HeroSkill.learnedSkill(skill)) continue;
HeroSkill.enableSkill(skill);
const status = getHeroStatusOf(hero, realStatus);
const d = calDamageWith(enemy, status) ?? Infinity;
if (d < damage) {
damage = d;
skill = i;
bestSkill = skill;
}
flags[condition] = false;
HeroSkill.disableSkill();
}
}
return { damage, skill };
return { damage, skill: bestSkill };
}
/**
@@ -838,8 +837,11 @@ export class DamageEnemy<T extends EnemyIds = EnemyIds> {
let end = seckill;
let ori = origin.damage;
const status = { atk: curr, def };
const calDam = () => {
return this.calEnemyDamageOf({ atk: curr, def }, enemy).damage;
status.atk = curr;
return this.calEnemyDamageOf(status, enemy).damage;
};
let i = 0;
@@ -981,10 +983,7 @@ const realStatus: (keyof HeroStatus)[] = [
/**
* 主动技能列表
*/
const skills: [unlock: string, condition: string][] = [
['bladeOn', 'blade'],
['shieldOn', 'shield']
];
const skills: HeroSkill.Skill[] = [HeroSkill.Blade, HeroSkill.Shield];
/**
* 计算怪物伤害
+2 -1
View File
@@ -35,7 +35,8 @@ Mota.register('var', 'loading', loading);
Mota.register('module', 'Mechanism', {
BluePalace: miscMechanism.BluePalace,
NightSpecial: miscMechanism.NightSpecial,
MiscData: miscMechanism.MiscData
MiscData: miscMechanism.MiscData,
HeroSkill: miscMechanism.HeroSkill
});
Mota.register('module', 'State', {
ItemState,
+92 -3
View File
@@ -14,7 +14,7 @@ export namespace MiscData {
* 永夜/极昼
*/
export namespace NightSpecial {
let nightMap = new Map<FloorIds, number>();
const nightMap = new Map<FloorIds, number>();
export function getNight(floor: FloorIds) {
return nightMap.get(floor) ?? 0;
@@ -25,12 +25,21 @@ export namespace NightSpecial {
nightMap.set(floor, num + value);
}
export function clearNight(floors: Iterable<FloorIds>) {
for (const floor of floors) {
nightMap.delete(floor);
}
}
export function saveNight() {
return nightMap.entries();
}
export function loadNight(night: IterableIterator<[FloorIds, number]>) {
nightMap = new Map(night);
export function loadNight(night: Iterable<[FloorIds, number]>) {
nightMap.clear();
for (const [floor, num] of night) {
nightMap.set(floor, num);
}
}
export function getAll() {
@@ -38,6 +47,86 @@ export namespace NightSpecial {
}
}
export namespace HeroSkill {
export const enum Skill {
None,
/** 断灭之刃 */
Blade,
/** 铸剑为盾 */
Shield,
/** 跳跃 */
Jump
}
export const Blade = Skill.Blade;
export const Shield = Skill.Shield;
export const Jump = Skill.Jump;
interface SkillSave {
autoSkill: boolean;
learned: Skill[];
}
const learned = new Set<Skill>();
let autoSkill = true;
let enabled: Skill = Skill.None;
export function setAutoSkill(auto: boolean) {
autoSkill = auto;
}
export function getAutoSkill() {
return autoSkill;
}
export function learnedSkill(skill: Skill) {
return learned.has(skill);
}
export function learnSkill(skill: Skill) {
learned.add(skill);
}
export function forgetSkill(skill: Skill) {
learned.delete(skill);
}
export function saveSkill(): SkillSave {
return { autoSkill, learned: [...learned] };
}
export function loadSkill(skills: SkillSave) {
learned.clear();
for (const skill of skills.learned) {
learned.add(skill);
}
autoSkill = skills.autoSkill;
}
export function getAll() {
return learned;
}
export function toggleSkill(skill: Skill) {
if (!learned.has(skill)) return;
if (enabled !== skill) enabled = skill;
else enabled = Skill.None;
}
export function enableSkill(skill: Skill) {
if (!learned.has(skill)) return;
enabled = skill;
}
export function disableSkill() {
enabled = Skill.None;
}
export function getEnabled() {
return enabled;
}
}
export namespace BluePalace {
type DoorConvertInfo = [id: AllIds, x: number, y: number];
+4 -4
View File
@@ -2,7 +2,7 @@ import { logger } from '@/core/common/logger';
import { EventEmitter } from 'eventemitter3';
import { cloneDeep, isNil } from 'lodash-es';
import { ItemState } from './item';
import { NightSpecial } from '../mechanism/misc';
import { HeroSkill, NightSpecial } from '../mechanism/misc';
/**
* 获取勇士在某一点的属性
@@ -100,16 +100,16 @@ function getRealStatus(
s += NightSpecial.getNight(floorId);
}
const enabled = HeroSkill.getEnabled();
// 技能
if (flags.bladeOn && flags.blade) {
if (enabled === HeroSkill.Blade) {
const level = getSkillLevel(2);
if (name === 'atk') {
s *= 1 + 0.1 * level;
} else if (name === 'def') {
s *= 1 - 0.1 * level;
}
}
if (flags.shield && flags.shieldOn) {
} else if (enabled === HeroSkill.Shield) {
const level = getSkillLevel(10);
if (name === 'atk') {
s *= 1 - 0.1 * level;
+1
View File
@@ -107,6 +107,7 @@ interface ModuleInterface {
BluePalace: typeof misc.BluePalace;
NightSpecial: typeof misc.NightSpecial;
MiscData: typeof misc.MiscData;
HeroSkill: typeof misc.HeroSkill;
};
Effect: {
Portal: typeof portal;