Skip to content

Commit

Permalink
fix(core): rename ambagious commonSkill to characterSkill (genius-inv…
Browse files Browse the repository at this point in the history
  • Loading branch information
guyutongxue authored Feb 3, 2025
1 parent 7cd8ec7 commit 21ae84b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 42 deletions.
14 changes: 7 additions & 7 deletions packages/core/src/base/skill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ import {
diceCostSize,
getEntityArea,
getEntityById,
isCharacterInitiativeSkill,
mixins,
normalizeCost,
} from "../utils";
import { commonInitiativeSkillCheck } from "../builder/skill";

export interface SkillDefinitionBase<Arg> {
readonly type: "skill";
Expand All @@ -69,7 +69,7 @@ export interface SkillDefinitionBase<Arg> {
export type SkillResult = {
readonly emittedEvents: readonly EventAndRequest[];
readonly mainDamage: DamageInfo | null;
}
};

export const EMPTY_SKILL_RESULT: SkillResult = {
emittedEvents: [],
Expand Down Expand Up @@ -392,8 +392,8 @@ export class ActionEventArg<
return this.action.type === "declareEnd";
}
/** 是角色主动技能(而非特技) */
isUseCommonSkill(): this is ActionEventArg<UseSkillInfo> {
return this.isUseSkill() && commonInitiativeSkillCheck(this.action.skill);
isUseCharacterSkill(): this is ActionEventArg<UseSkillInfo> {
return this.isUseSkill() && isCharacterInitiativeSkill(this.action.skill);
}
isUseTechnique(): this is ActionEventArg<UseSkillInfo> {
return this.isSkillType("technique");
Expand All @@ -402,7 +402,7 @@ export class ActionEventArg<
character: CharacterState,
skillType?: CommonSkillType,
): boolean {
if (this.isUseCommonSkill()) {
if (this.isUseCharacterSkill()) {
const skillDef = this.action.skill.definition;
return (
character.definition.skills.some((sk) => sk.id === skillDef.id) &&
Expand Down Expand Up @@ -1051,8 +1051,8 @@ export class ReactionEventArg extends CharacterEventArg {
}

/** 是否为“角色引发的” */
viaCommonInitiativeSkill() {
return commonInitiativeSkillCheck(this.reactionInfo.via);
viaCharacterSkill() {
return isCharacterInitiativeSkill(this.reactionInfo.via);
}

relatedTo(target: DamageType): boolean {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/builder/context/skill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import {
getActiveCharacterIndex,
getEntityArea,
getEntityById,
isCharacterInitiativeSkill,
sortDice,
} from "../../utils";
import { executeQuery } from "../../query";
Expand Down Expand Up @@ -756,6 +757,7 @@ export class SkillContext<Meta extends ContextMetaBase> {
const targetState = t.state;
let isSkillMainDamage = false;
if (
isCharacterInitiativeSkill(this.skillInfo) &&
!this.fromReaction &&
!this.mainDamage &&
type !== DamageType.Piercing
Expand Down
36 changes: 11 additions & 25 deletions packages/core/src/builder/skill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,6 @@ function defineDescriptor<E extends EventNames>(
*
* @param allowTechnique 是否允许特技
*/
export function commonInitiativeSkillCheck(
skillInfo: SkillInfo,
allowTechnique = false,
): boolean {
return (
isCharacterInitiativeSkill(skillInfo.definition, allowTechnique) &&
!skillInfo.definition.initiativeSkillConfig.prepared
);
}

function isDebuff(state: GameState, damageInfo: DamageInfo): boolean {
return (
Expand Down Expand Up @@ -297,20 +288,20 @@ const detailedEventDictionary = {
}),
deductVoidDiceSkill: defineDescriptor("modifyAction0", (c, e, r) => {
return (
e.isUseCommonSkill() &&
e.isUseCharacterSkill() &&
checkRelative(e.onTimeState, e.action.skill.caller.id, r) &&
e.canDeductVoidCost()
);
}),
deductElementDiceSkill: defineDescriptor("modifyAction1", (c, e, r) => {
return (
e.isUseCommonSkill() &&
e.isUseCharacterSkill() &&
checkRelative(e.onTimeState, e.action.skill.caller.id, r)
);
}),
deductOmniDiceSkill: defineDescriptor("modifyAction2", (c, e, r) => {
return (
e.isUseCommonSkill() &&
e.isUseCharacterSkill() &&
checkRelative(e.onTimeState, e.action.skill.caller.id, r) &&
e.canDeductCost()
);
Expand Down Expand Up @@ -339,7 +330,7 @@ const detailedEventDictionary = {
return (
e.type !== DamageType.Piercing &&
checkRelative(e.onTimeState, e.source.id, r) &&
isCharacterInitiativeSkill(e.via.definition) &&
isCharacterInitiativeSkill(e.via) &&
e.damageInfo.fromReaction === null
);
}),
Expand All @@ -354,7 +345,7 @@ const detailedEventDictionary = {
return (
e.type !== DamageType.Piercing &&
checkRelative(e.onTimeState, e.source.id, r) &&
isCharacterInitiativeSkill(e.via.definition) &&
isCharacterInitiativeSkill(e.via) &&
e.damageInfo.fromReaction === null
);
}),
Expand All @@ -370,7 +361,7 @@ const detailedEventDictionary = {
return (
e.type !== DamageType.Piercing &&
checkRelative(e.onTimeState, e.source.id, r) &&
isCharacterInitiativeSkill(e.via.definition) &&
isCharacterInitiativeSkill(e.via) &&
!isDebuff(e.onTimeState, e.damageInfo)
);
}),
Expand Down Expand Up @@ -423,16 +414,11 @@ const detailedEventDictionary = {
checkRelative(e.onTimeState, { who: e.who }, r)
);
}),
// modifySkill: defineDescriptor("modifyUseSkill", (c, e, r) => {
// return (
// checkRelative(e.onTimeState, e.callerArea, r) &&
// commonInitiativeSkillCheck(e.skill)
// );
// }),
useSkill: defineDescriptor("onUseSkill", (c, e, r) => {
return (
checkRelative(e.onTimeState, e.callerArea, r) &&
commonInitiativeSkillCheck(e.skill)
isCharacterInitiativeSkill(e.skill) &&
!e.skill.definition.initiativeSkillConfig.prepared
);
}),
useTechinque: defineDescriptor("onUseSkill", (c, e, r) => {
Expand All @@ -444,7 +430,8 @@ const detailedEventDictionary = {
useSkillOrTechnique: defineDescriptor("onUseSkill", (c, e, r) => {
return (
checkRelative(e.onTimeState, e.callerArea, r) &&
commonInitiativeSkillCheck(e.skill, true)
isCharacterInitiativeSkill(e.skill, true) &&
!e.skill.definition.initiativeSkillConfig.prepared
);
}),
declareEnd: defineDescriptor("onAction", (c, e, r) => {
Expand Down Expand Up @@ -499,8 +486,7 @@ const detailedEventDictionary = {
}),
skillReaction: defineDescriptor("onReaction", (c, e, r) => {
return (
checkRelative(e.onTimeState, e.caller.id, r) &&
e.viaCommonInitiativeSkill()
checkRelative(e.onTimeState, e.caller.id, r) && e.viaCharacterSkill()
);
}),
enter: defineDescriptor("onEnter", (c, e, r) => {
Expand Down
10 changes: 4 additions & 6 deletions packages/core/src/skill_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,12 +527,10 @@ export class SkillExecutor {
plunging,
});
await this.finalizeSkill(skillInfo, { targets: [] });
if (!skillDef.initiativeSkillConfig.prepared) {
await this.handleEvent([
"onUseSkill",
new UseSkillEventArg(this.state, callerArea, skillInfo),
]);
}
await this.handleEvent([
"onUseSkill",
new UseSkillEventArg(this.state, callerArea, skillInfo),
]);
} else if (name === "requestTriggerEndPhaseSkill") {
using l = this.mutator.subLog(
DetailLogType.Event,
Expand Down
10 changes: 6 additions & 4 deletions packages/core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
EventNames,
InitiativeSkillDefinition,
InitiativeSkillEventArg,
InitiativeSkillInfo,
SkillDefinition,
SkillInfo,
SkillType,
Expand Down Expand Up @@ -303,17 +304,18 @@ export function removeEntity(state: Draft<GameState>, id: number) {
throw new GiTcgCoreInternalEntityNotFoundError(state, id);
}

/** 检查 `skill` 是否是角色主动技能 */
export function isCharacterInitiativeSkill(
skillDef: SkillDefinition,
skill: SkillInfo,
allowTechnique = false,
): skillDef is InitiativeSkillDefinition {
): skill is InitiativeSkillInfo {
const allowSkillType: SkillType[] = ["normal", "elemental", "burst"];
if (allowTechnique) {
allowSkillType.push("technique");
}
return (
skillDef.triggerOn === "initiative" &&
allowSkillType.includes(skillDef.initiativeSkillConfig.skillType)
skill.definition.triggerOn === "initiative" &&
allowSkillType.includes(skill.definition.initiativeSkillConfig.skillType)
);
}

Expand Down

0 comments on commit 21ae84b

Please sign in to comment.