Compare commits
No commits in common. "63e55a828ee4963911a7bbf16e4063def7262ee9" and "f4c96a4a7292190ce24a086fef6873f3cc8a71e1" have entirely different histories.
63e55a828e
...
f4c96a4a72
|
|
@ -1,5 +1,5 @@
|
|||
# type CardEffectTrigger = 'onPlay' | 'onDraw' | 'onDiscard'
|
||||
# type CardEffectTarget = 'source' | 'eachTarget' | 'eachEnemy' | 'randomEnemy' | 'player'
|
||||
# type CardEffectTarget = 'user' | 'eachTarget' | 'eachEnemy' | 'randomEnemy' | 'player'
|
||||
# type CardEffectList = [effect: @effect; stacks: number][]
|
||||
|
||||
id,card,trigger,target,effects
|
||||
|
|
@ -9,28 +9,28 @@ greataxe,greataxe,onPlay,eachTarget,[attack;5]
|
|||
spear,spear,onPlay,eachTarget,[attack;2];[attack;2];[attack;2]
|
||||
dagger,dagger,onPlay,eachTarget,[attack;3];[attack;3]
|
||||
dart,dart,onPlay,eachTarget,[attack;1]
|
||||
dart-draw,dart,onPlay,source,[draw;1]
|
||||
dart-draw,dart,onPlay,user,[draw;1]
|
||||
crossbow,crossbow,onPlay,eachTarget,[attack;6]
|
||||
crossbow-combo,crossbow,onPlay,source,[crossbow;0]
|
||||
shield,shield,onPlay,source,[defend;3]
|
||||
hat,hat,onPlay,source,[defend;8]
|
||||
cape,cape,onPlay,source,[defend;2];[defendNext;2]
|
||||
bracer,bracer,onPlay,source,[defend;1];[draw;1]
|
||||
greatshield,greatshield,onPlay,source,[defend;5]
|
||||
chainmail,chainmail,onPlay,source,[damageReduce;3]
|
||||
bandage,bandage,onPlay,source,[removeWound;1]
|
||||
poisonPotion,poisonPotion,onPlay,source,[attackBuff;2]
|
||||
fortifyPotion,fortifyPotion,onPlay,source,[defendBuff;2]
|
||||
vitalityPotion,vitalityPotion,onPlay,source,[gainEnergy;1]
|
||||
focusPotion,focusPotion,onPlay,source,[draw;2]
|
||||
healingPotion,healingPotion,onPlay,source,[removeWound;3]
|
||||
waterBag,waterBag,onPlay,source,[energyNext;1];[drawNext;2]
|
||||
rope,rope,onPlay,source,[defendBuffUntilPlay;2]
|
||||
belt,belt,onPlay,source,[drawChoice;1]
|
||||
torch,torch,onPlay,source,[burnForEnergy;1]
|
||||
whetstone,whetstone,onPlay,source,[attackBuffUntilPlay;3]
|
||||
blacksmithHammer,blacksmithHammer,onPlay,source,[transformRandom;1]
|
||||
venom,venom,onDiscard,source,[attack;3]
|
||||
curse,curse,onDraw,source,[curse;1]
|
||||
static,static,onDraw,source,[static;1]
|
||||
vultureEye,vultureEye,onDraw,source,[expose;3]
|
||||
crossbow-combo,crossbow,onPlay,user,[crossbow;0]
|
||||
shield,shield,onPlay,user,[defend;3]
|
||||
hat,hat,onPlay,user,[defend;8]
|
||||
cape,cape,onPlay,user,[defend;2];[defendNext;2]
|
||||
bracer,bracer,onPlay,user,[defend;1];[draw;1]
|
||||
greatshield,greatshield,onPlay,user,[defend;5]
|
||||
chainmail,chainmail,onPlay,user,[damageReduce;3]
|
||||
bandage,bandage,onPlay,user,[removeWound;1]
|
||||
poisonPotion,poisonPotion,onPlay,user,[attackBuff;2]
|
||||
fortifyPotion,fortifyPotion,onPlay,user,[defendBuff;2]
|
||||
vitalityPotion,vitalityPotion,onPlay,user,[gainEnergy;1]
|
||||
focusPotion,focusPotion,onPlay,user,[draw;2]
|
||||
healingPotion,healingPotion,onPlay,user,[removeWound;3]
|
||||
waterBag,waterBag,onPlay,user,[energyNext;1];[drawNext;2]
|
||||
rope,rope,onPlay,user,[defendBuffUntilPlay;2]
|
||||
belt,belt,onPlay,user,[drawChoice;1]
|
||||
torch,torch,onPlay,user,[burnForEnergy;1]
|
||||
whetstone,whetstone,onPlay,user,[attackBuffUntilPlay;3]
|
||||
blacksmithHammer,blacksmithHammer,onPlay,user,[transformRandom;1]
|
||||
venom,venom,onDiscard,user,[attack;3]
|
||||
curse,curse,onDraw,user,[curse;1]
|
||||
static,static,onDraw,user,[static;1]
|
||||
vultureEye,vultureEye,onDraw,user,[expose;3]
|
||||
|
|
|
|||
|
|
|
@ -2,7 +2,7 @@ import type { Card } from './card.csv';
|
|||
import type { Effect } from './effect.csv';
|
||||
|
||||
export type CardEffectTrigger = 'onPlay' | 'onDraw' | 'onDiscard';
|
||||
export type CardEffectTarget = 'source' | 'eachTarget' | 'eachEnemy' | 'randomEnemy' | 'player';
|
||||
export type CardEffectTarget = 'user' | 'eachTarget' | 'eachEnemy' | 'randomEnemy' | 'player';
|
||||
export type CardEffectList = [effect: Effect, stacks: number][];
|
||||
|
||||
type CardEffectTable = readonly {
|
||||
|
|
|
|||
|
|
@ -6,50 +6,50 @@
|
|||
# initBuffs: initial buffs for this intent (applied when intent becomes active)
|
||||
# effects: effects executed when this intent is active
|
||||
|
||||
# type IntentEffectTarget = 'source' | 'eachEnemy' | 'randomEnemy' | 'player'
|
||||
# type IntentEffectTarget = 'user' | 'eachEnemy' | 'randomEnemy' | 'player'
|
||||
# type IntentEffect = [IntentEffectTarget;@effect;number]
|
||||
# type IntentEffectList = IntentEffect[]
|
||||
|
||||
id,enemy,initialIntent,nextIntents,brokenIntent,effects
|
||||
string,@enemy,boolean,@intent[],@intent[],IntentEffectList
|
||||
仙人掌怪-boost,仙人掌怪,true,仙人掌怪-boost;仙人掌怪-defend,,[source;spike;1];[source;defend;4]
|
||||
仙人掌怪-defend,仙人掌怪,false,仙人掌怪-attack,,[source;defend;8]
|
||||
仙人掌怪-boost,仙人掌怪,true,仙人掌怪-boost;仙人掌怪-defend,,[user;spike;1];[user;defend;4]
|
||||
仙人掌怪-defend,仙人掌怪,false,仙人掌怪-attack,,[user;defend;8]
|
||||
仙人掌怪-attack,仙人掌怪,false,仙人掌怪-boost,,[player;attack;5]
|
||||
蛇-poison,蛇,true,蛇-attack;蛇-attack,,[player;venom;1];[player;attack;4]
|
||||
蛇-attack,蛇,false,蛇-poison;蛇-boost,,[player;attack;6]
|
||||
蛇-boost,蛇,false,蛇-poison;蛇-attack,,[source;defend;3];[player;venom;1]
|
||||
蛇-boost,蛇,false,蛇-poison;蛇-attack,,[user;defend;3];[player;venom;1]
|
||||
木乃伊-attack,木乃伊,true,木乃伊-defend;木乃伊-curse,,[player;attack;6]
|
||||
木乃伊-defend,木乃伊,false,木乃伊-attack,,[source;defend;6]
|
||||
木乃伊-defend,木乃伊,false,木乃伊-attack,,[user;defend;6]
|
||||
木乃伊-curse,木乃伊,false,木乃伊-defend;木乃伊-attack,木乃伊-attack,[player;curse;1]
|
||||
枪手-aim,枪手,true,枪手-attack,,[source;aim;2]
|
||||
枪手-aim,枪手,true,枪手-attack,,[user;aim;2]
|
||||
枪手-attack,枪手,false,枪手-aim;枪手-defend,枪手-aim,[player;attack;8]
|
||||
枪手-defend,枪手,false,枪手-aim,枪手-aim,[source;defend;5]
|
||||
风卷草-boost,风卷草,true,风卷草-defend;风卷草-defend;风卷草-boost,,[source;roll;5];[source;defend;4]
|
||||
风卷草-defend,风卷草,false,风卷草-boost;风卷草-attack,,[source;defend;8]
|
||||
枪手-defend,枪手,false,枪手-aim,枪手-aim,[user;defend;5]
|
||||
风卷草-boost,风卷草,true,风卷草-defend;风卷草-defend;风卷草-boost,,[user;roll;5];[user;defend;4]
|
||||
风卷草-defend,风卷草,false,风卷草-boost;风卷草-attack,,[user;defend;8]
|
||||
风卷草-attack,风卷草,false,风卷草-boost,,[player;rollDamage;0]
|
||||
秃鹫-attack,秃鹫,true,秃鹫-defend;秃鹫-defend,,[player;attack;6];[player;vultureEye;1]
|
||||
秃鹫-defend,秃鹫,false,秃鹫-attack;秃鹫-attack,,[source;defend;5]
|
||||
沙蝎-boost,沙蝎,true,沙蝎-attack;沙蝎-attack,,[source;tailSting;2]
|
||||
秃鹫-defend,秃鹫,false,秃鹫-attack;秃鹫-attack,,[user;defend;5]
|
||||
沙蝎-boost,沙蝎,true,沙蝎-attack;沙蝎-attack,,[user;tailSting;2]
|
||||
沙蝎-attack,沙蝎,false,沙蝎-boost;沙蝎-attack,,[player;attack;6]
|
||||
幼沙虫-defend,幼沙虫,true,幼沙虫-defend;幼沙虫-boost,,[source;defend;6]
|
||||
幼沙虫-boost,幼沙虫,false,幼沙虫-attack;幼沙虫-defend,,[source;energyDrain;1];[source;defend;4]
|
||||
幼沙虫-defend,幼沙虫,true,幼沙虫-defend;幼沙虫-boost,,[user;defend;6]
|
||||
幼沙虫-boost,幼沙虫,false,幼沙虫-attack;幼沙虫-defend,,[user;energyDrain;1];[user;defend;4]
|
||||
幼沙虫-attack,幼沙虫,false,幼沙虫-defend;幼沙虫-defend,,[player;attack;5]
|
||||
蜥蜴-attack,蜥蜴,true,蜥蜴-defend;蜥蜴-molt,,[player;attack;5]
|
||||
蜥蜴-defend,蜥蜴,false,蜥蜴-attack;蜥蜴-attack,,[source;defend;6]
|
||||
蜥蜴-molt,蜥蜴,false,蜥蜴-defend;蜥蜴-attack,,[source;molt;3]
|
||||
蜥蜴-defend,蜥蜴,false,蜥蜴-attack;蜥蜴-attack,,[user;defend;6]
|
||||
蜥蜴-molt,蜥蜴,false,蜥蜴-defend;蜥蜴-attack,,[user;molt;3]
|
||||
沙匪-attack,沙匪,true,沙匪-attack;沙匪-heavyAttack,,[player;attack;6]
|
||||
沙匪-heavyAttack,沙匪,false,沙匪-attack;沙匪-attack;沙匪-debuff,,[player;attack;10]
|
||||
沙匪-debuff,沙匪,false,沙匪-attack;沙匪-attack,,[player;discard;1]
|
||||
风暴之灵-storm,风暴之灵,true,风暴之灵-attack;风暴之灵-storm,,[source;storm;2];[source;defend;3]
|
||||
风暴之灵-storm,风暴之灵,true,风暴之灵-attack;风暴之灵-storm,,[user;storm;2];[user;defend;3]
|
||||
风暴之灵-attack,风暴之灵,false,风暴之灵-storm;风暴之灵-defend,,[player;attack;8];[player;static;1]
|
||||
风暴之灵-defend,风暴之灵,false,风暴之灵-storm;风暴之灵-attack,,[source;defend;8]
|
||||
骑马枪手-charge,骑马枪手,true,骑马枪手-attack,,[source;charge;2]
|
||||
风暴之灵-defend,风暴之灵,false,风暴之灵-storm;风暴之灵-attack,,[user;defend;8]
|
||||
骑马枪手-charge,骑马枪手,true,骑马枪手-attack,,[user;charge;2]
|
||||
骑马枪手-attack,骑马枪手,false,骑马枪手-charge;骑马枪手-defend,骑马枪手-charge,[player;attack;6]
|
||||
骑马枪手-defend,骑马枪手,false,骑马枪手-charge;骑马枪手-attack,骑马枪手-charge,[source;defend;5]
|
||||
沙虫王-summon,沙虫王,true,沙虫王-attack;沙虫王-defend,,[source;summonSandwormLarva;18]
|
||||
骑马枪手-defend,骑马枪手,false,骑马枪手-charge;骑马枪手-attack,骑马枪手-charge,[user;defend;5]
|
||||
沙虫王-summon,沙虫王,true,沙虫王-attack;沙虫王-defend,,[user;summonSandwormLarva;18]
|
||||
沙虫王-attack,沙虫王,false,沙虫王-summon;沙虫王-defend,,[player;attack;9]
|
||||
沙虫王-defend,沙虫王,false,沙虫王-attack;沙虫王-summon,,[source;defend;6]
|
||||
沙漠守卫-summon,沙漠守卫,true,沙漠守卫-attack;沙漠守卫-defend,,[source;summonMummy;14]
|
||||
沙虫王-defend,沙虫王,false,沙虫王-attack;沙虫王-summon,,[user;defend;6]
|
||||
沙漠守卫-summon,沙漠守卫,true,沙漠守卫-attack;沙漠守卫-defend,,[user;summonMummy;14]
|
||||
沙漠守卫-attack,沙漠守卫,false,沙漠守卫-defend;沙漠守卫-summon,,[player;attack;8]
|
||||
沙漠守卫-defend,沙漠守卫,false,沙漠守卫-attack;沙漠守卫-revive,,[source;defend;8]
|
||||
沙漠守卫-revive,沙漠守卫,false,沙漠守卫-attack;沙漠守卫-summon,,[source;reviveMummy;1]
|
||||
沙漠守卫-defend,沙漠守卫,false,沙漠守卫-attack;沙漠守卫-revive,,[user;defend;8]
|
||||
沙漠守卫-revive,沙漠守卫,false,沙漠守卫-attack;沙漠守卫-summon,,[user;reviveMummy;1]
|
||||
|
|
|
|||
|
Can't render this file because it has a wrong number of fields in line 13.
|
|
|
@ -1,7 +1,7 @@
|
|||
import type { Enemy } from './enemy.csv';
|
||||
import type { Effect } from './effect.csv';
|
||||
|
||||
export type IntentEffectTarget = 'source' | 'eachEnemy' | 'randomEnemy' | 'player';
|
||||
export type IntentEffectTarget = 'user' | 'eachEnemy' | 'randomEnemy' | 'player';
|
||||
export type IntentEffect = [IntentEffectTarget, Effect, number];
|
||||
export type IntentEffectList = IntentEffect[];
|
||||
|
||||
|
|
|
|||
|
|
@ -30,9 +30,9 @@ export function addCardEventTriggers(triggers: Triggers, run: IRunContext) {
|
|||
for (let i = 0; i < storm; i++) {
|
||||
await triggers.onEffectApplied.execute(ctx.game, {
|
||||
effect: findEffect("static"),
|
||||
entityId: "player",
|
||||
entityKey: "player",
|
||||
stacks: 1,
|
||||
sourceEntityId: ctx.enemyId,
|
||||
sourceEntityKey: ctx.enemyId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -52,7 +52,7 @@ export function addCardEventTriggers(triggers: Triggers, run: IRunContext) {
|
|||
await triggers.onCardPlayed.execute(ctx.game, {
|
||||
cardId: id,
|
||||
targetId: ctx.targetId,
|
||||
sourceEntityId: "player",
|
||||
sourceEntityKey: "player",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -113,17 +113,17 @@ export function addCardEventTriggers(triggers: Triggers, run: IRunContext) {
|
|||
await next();
|
||||
|
||||
const dealt = ctx.amount - (ctx.prevented ?? 0);
|
||||
if (dealt <= 0 || !ctx.sourceEntityId) return;
|
||||
if (dealt <= 0 || !ctx.sourceEntityKey) return;
|
||||
|
||||
const attacker = getCombatEntity(ctx.game.value, ctx.sourceEntityId);
|
||||
const attacker = getCombatEntity(ctx.game.value, ctx.sourceEntityKey);
|
||||
if (!attacker || !("enemy" in attacker) || attacker.enemy.id !== "秃鹫")
|
||||
return;
|
||||
|
||||
await triggers.onEffectApplied.execute(ctx.game, {
|
||||
effect: findEffect("vultureEye"),
|
||||
entityId: "player",
|
||||
entityKey: "player",
|
||||
stacks: 1,
|
||||
sourceEntityId: ctx.sourceEntityId,
|
||||
sourceEntityKey: ctx.sourceEntityKey,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ export function addDamageTriggers(triggers: Triggers) {
|
|||
|
||||
// block / damage prevention
|
||||
triggers.onDamage.use(async (ctx, next) => {
|
||||
const entity = getCombatEntity(ctx.game.value, ctx.entityId);
|
||||
const entity = getCombatEntity(ctx.game.value, ctx.entityKey);
|
||||
if (!entity) return;
|
||||
|
||||
let preventable = ctx.amount - (ctx.prevented ?? 0);
|
||||
|
|
@ -42,7 +42,7 @@ export function addDamageTriggers(triggers: Triggers) {
|
|||
ctx.prevented = (ctx.prevented ?? 0) + blocked;
|
||||
preventable -= blocked;
|
||||
await ctx.game.produceAsync((draft) => {
|
||||
const e = getCombatEntity(draft, ctx.entityId);
|
||||
const e = getCombatEntity(draft, ctx.entityKey);
|
||||
if (e) addEntityEffect(e, findEffect("defend"), -blocked);
|
||||
});
|
||||
}
|
||||
|
|
@ -61,26 +61,26 @@ export function addDamageTriggers(triggers: Triggers) {
|
|||
|
||||
if (ctx.amount - (ctx.prevented ?? 0) <= 0) return;
|
||||
|
||||
const entity = getCombatEntity(ctx.game.value, ctx.entityId);
|
||||
const entity = getCombatEntity(ctx.game.value, ctx.entityKey);
|
||||
if (!entity || !entity.isAlive) return;
|
||||
|
||||
const spike = entity.effects.spike?.stacks ?? 0;
|
||||
if (spike > 0 && ctx.sourceEntityId) {
|
||||
if (spike > 0 && ctx.sourceEntityKey) {
|
||||
await triggers.onDamage.execute(ctx.game, {
|
||||
entityId: ctx.sourceEntityId,
|
||||
entityKey: ctx.sourceEntityKey,
|
||||
amount: spike,
|
||||
sourceEntityId: ctx.entityId,
|
||||
sourceEntityKey: ctx.entityKey,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// energyDrain: player loses energy when enemy takes damage
|
||||
triggers.onDamage.use(async (ctx, next) => {
|
||||
const entity = getCombatEntity(ctx.game.value, ctx.entityId);
|
||||
const entity = getCombatEntity(ctx.game.value, ctx.entityKey);
|
||||
if (!entity) return;
|
||||
|
||||
const energyDrain = entity.effects.energyDrain?.stacks ?? 0;
|
||||
if (energyDrain > 0 && ctx.entityId !== "player") {
|
||||
if (energyDrain > 0 && ctx.entityKey !== "player") {
|
||||
const dealt = Math.min(
|
||||
Math.max(0, entity.hp),
|
||||
ctx.amount - (ctx.prevented ?? 0),
|
||||
|
|
@ -97,7 +97,7 @@ export function addDamageTriggers(triggers: Triggers) {
|
|||
|
||||
// molt: enemy flees if molt >= maxHp
|
||||
triggers.onDamage.use(async (ctx, next) => {
|
||||
const entity = getCombatEntity(ctx.game.value, ctx.entityId);
|
||||
const entity = getCombatEntity(ctx.game.value, ctx.entityKey);
|
||||
if (!entity || !entity.isAlive) {
|
||||
await next();
|
||||
return;
|
||||
|
|
@ -106,7 +106,7 @@ export function addDamageTriggers(triggers: Triggers) {
|
|||
const molt = entity.effects.molt?.stacks ?? 0;
|
||||
if (molt >= entity.maxHp) {
|
||||
await ctx.game.produceAsync((draft) => {
|
||||
const e = draft.enemies.find((en) => en.id === ctx.entityId);
|
||||
const e = draft.enemies.find((en) => en.id === ctx.entityKey);
|
||||
if (e) {
|
||||
e.isAlive = false;
|
||||
e.hp = 0;
|
||||
|
|
@ -124,7 +124,7 @@ export function addDamageTriggers(triggers: Triggers) {
|
|||
|
||||
// aim: double damage, lose aim on damage
|
||||
triggers.onDamage.use(async (ctx, next) => {
|
||||
if (ctx.sourceEntityId === "player") {
|
||||
if (ctx.sourceEntityKey === "player") {
|
||||
const player = ctx.game.value.player;
|
||||
const aim = player.effects.aim?.stacks ?? 0;
|
||||
if (aim > 0) {
|
||||
|
|
@ -136,7 +136,7 @@ export function addDamageTriggers(triggers: Triggers) {
|
|||
|
||||
// roll: consume 10 roll per 10 damage
|
||||
triggers.onDamage.use(async (ctx, next) => {
|
||||
if (ctx.sourceEntityId === "player") {
|
||||
if (ctx.sourceEntityKey === "player") {
|
||||
const player = ctx.game.value.player;
|
||||
const roll = player.effects.roll?.stacks ?? 0;
|
||||
if (roll >= 10) {
|
||||
|
|
@ -152,8 +152,8 @@ export function addDamageTriggers(triggers: Triggers) {
|
|||
|
||||
// tailSting: bonus damage on attack
|
||||
triggers.onDamage.use(async (ctx, next) => {
|
||||
if (ctx.sourceEntityId && ctx.sourceEntityId !== "player") {
|
||||
const attacker = getCombatEntity(ctx.game.value, ctx.sourceEntityId);
|
||||
if (ctx.sourceEntityKey && ctx.sourceEntityKey !== "player") {
|
||||
const attacker = getCombatEntity(ctx.game.value, ctx.sourceEntityKey);
|
||||
if (attacker) {
|
||||
const tailSting = attacker.effects.tailSting?.stacks ?? 0;
|
||||
if (tailSting > 0) {
|
||||
|
|
@ -166,7 +166,7 @@ export function addDamageTriggers(triggers: Triggers) {
|
|||
|
||||
// charge: double damage dealt/received, consume equal charge
|
||||
triggers.onDamage.use(async (ctx, next) => {
|
||||
const entity = getCombatEntity(ctx.game.value, ctx.entityId);
|
||||
const entity = getCombatEntity(ctx.game.value, ctx.entityKey);
|
||||
if (entity) {
|
||||
const charge = entity.effects.charge?.stacks ?? 0;
|
||||
if (charge > 0) {
|
||||
|
|
@ -178,20 +178,20 @@ export function addDamageTriggers(triggers: Triggers) {
|
|||
ctx.amount += dealt;
|
||||
if (consumed > 0) {
|
||||
await ctx.game.produceAsync((draft) => {
|
||||
const e = getCombatEntity(draft, ctx.entityId);
|
||||
const e = getCombatEntity(draft, ctx.entityKey);
|
||||
if (e) addEntityEffect(e, findEffect("charge"), -consumed);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ctx.sourceEntityId) {
|
||||
const attacker = getCombatEntity(ctx.game.value, ctx.sourceEntityId);
|
||||
if (ctx.sourceEntityKey) {
|
||||
const attacker = getCombatEntity(ctx.game.value, ctx.sourceEntityKey);
|
||||
if (attacker) {
|
||||
const charge = attacker.effects.charge?.stacks ?? 0;
|
||||
if (charge > 0) {
|
||||
const baseAmount = ctx.amount;
|
||||
const targetEntity = getCombatEntity(ctx.game.value, ctx.entityId);
|
||||
const targetEntity = getCombatEntity(ctx.game.value, ctx.entityKey);
|
||||
const dealt = Math.min(
|
||||
Math.max(0, targetEntity?.hp ?? 0),
|
||||
baseAmount - (ctx.prevented ?? 0),
|
||||
|
|
@ -200,7 +200,7 @@ export function addDamageTriggers(triggers: Triggers) {
|
|||
ctx.amount += dealt;
|
||||
if (consumed > 0) {
|
||||
await ctx.game.produceAsync((draft) => {
|
||||
const a = getCombatEntity(draft, ctx.sourceEntityId!);
|
||||
const a = getCombatEntity(draft, ctx.sourceEntityKey!);
|
||||
if (a) addEntityEffect(a, findEffect("charge"), -consumed);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,10 +93,10 @@ export function addInstantEffectTriggers(triggers: Triggers) {
|
|||
triggers.onEffectApplied.use(async (ctx, next) => {
|
||||
if (ctx.effect.id === "attack") {
|
||||
await triggers.onDamage.execute(ctx.game, {
|
||||
entityId: ctx.entityId,
|
||||
entityKey: ctx.entityKey,
|
||||
amount: ctx.stacks,
|
||||
sourceEntityId:
|
||||
(ctx.sourceEntityId ?? ctx.entityId === "player")
|
||||
sourceEntityKey:
|
||||
(ctx.sourceEntityKey ?? ctx.entityKey === "player")
|
||||
? undefined
|
||||
: "player",
|
||||
});
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ export function addTurnStartTriggers(triggers: Triggers) {
|
|||
|
||||
// discard: random discard at turn start
|
||||
triggers.onTurnStart.use(async (ctx, next) => {
|
||||
if (ctx.entityId !== "player") {
|
||||
if (ctx.entityKey !== "player") {
|
||||
await next();
|
||||
return;
|
||||
}
|
||||
|
|
@ -56,7 +56,7 @@ export function addTurnStartTriggers(triggers: Triggers) {
|
|||
|
||||
// energyNext: gain energy next turn
|
||||
triggers.onTurnStart.use(async (ctx, next) => {
|
||||
if (ctx.entityId !== "player") {
|
||||
if (ctx.entityKey !== "player") {
|
||||
await next();
|
||||
return;
|
||||
}
|
||||
|
|
@ -74,7 +74,7 @@ export function addTurnStartTriggers(triggers: Triggers) {
|
|||
|
||||
// drawNext: draw extra cards next turn
|
||||
triggers.onTurnStart.use(async (ctx, next) => {
|
||||
if (ctx.entityId !== "player") {
|
||||
if (ctx.entityKey !== "player") {
|
||||
await next();
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ export function* getEffectTargets(
|
|||
for (const enemy of getAliveEnemies(game.value)) {
|
||||
yield enemy;
|
||||
}
|
||||
} else if (target === "source") {
|
||||
} else if (target === "user") {
|
||||
const entity = getCombatEntity(game.value, sourceEntityKey);
|
||||
if (entity) yield entity;
|
||||
} else if (target === "player") {
|
||||
|
|
|
|||
|
|
@ -19,33 +19,33 @@ import { EffectData } from "@/samples/slay-the-spire-like/system/types";
|
|||
|
||||
type TriggerTypes = {
|
||||
onCombatStart: {};
|
||||
onTurnStart: { entityId: "player" | string };
|
||||
onTurnEnd: { entityId: "player" | string };
|
||||
onTurnStart: { entityKey: "player" | string };
|
||||
onTurnEnd: { entityKey: "player" | string };
|
||||
onShuffle: {};
|
||||
onCardPlayed: {
|
||||
cardId: string;
|
||||
targetId?: string;
|
||||
sourceEntityId?: "player" | string;
|
||||
sourceEntityKey?: "player" | string;
|
||||
};
|
||||
onCardDiscarded: { cardId: string; sourceEntityId?: "player" | string };
|
||||
onCardDrawn: { cardId: string; sourceEntityId?: "player" | string };
|
||||
onCardDiscarded: { cardId: string; sourceEntityKey?: "player" | string };
|
||||
onCardDrawn: { cardId: string; sourceEntityKey?: "player" | string };
|
||||
onDraw: { count: number };
|
||||
onEffectApplied: {
|
||||
effect: EffectData;
|
||||
entityId: "player" | string;
|
||||
entityKey: "player" | string;
|
||||
stacks: number;
|
||||
cardId?: string;
|
||||
sourceEntityId?: "player" | string;
|
||||
sourceEntityKey?: "player" | string;
|
||||
targetId?: string;
|
||||
};
|
||||
onHpChange: { entityId: "player" | string; amount: number };
|
||||
onHpChange: { entityKey: "player" | string; amount: number };
|
||||
onDamage: {
|
||||
entityId: "player" | string;
|
||||
entityKey: "player" | string;
|
||||
amount: number;
|
||||
prevented?: number;
|
||||
sourceEntityId?: "player" | string;
|
||||
sourceEntityKey?: "player" | string;
|
||||
};
|
||||
onEnemyIntent: { enemyId: string; sourceEntityId?: "player" | string };
|
||||
onEnemyIntent: { enemyId: string; sourceEntityKey?: "player" | string };
|
||||
onIntentUpdate: { enemyId: string };
|
||||
};
|
||||
|
||||
|
|
@ -57,13 +57,13 @@ export function createTriggers(run: IRunContext) {
|
|||
}),
|
||||
onTurnStart: createTrigger("onTurnStart", async (ctx) => {
|
||||
await ctx.game.produceAsync((draft) => {
|
||||
const entity = getCombatEntity(draft, ctx.entityId);
|
||||
const entity = getCombatEntity(draft, ctx.entityKey);
|
||||
if (entity) onEntityEffectUpkeep(entity);
|
||||
if (entity === draft.player) onPlayerItemEffectUpkeep(draft.player);
|
||||
});
|
||||
}),
|
||||
onTurnEnd: createTrigger("onTurnEnd", async (ctx) => {
|
||||
if (ctx.entityId !== "player") return;
|
||||
if (ctx.entityKey !== "player") return;
|
||||
const { regions } = ctx.game.value.player.deck;
|
||||
for (const cardId of Object.values(regions.hand.childIds)) {
|
||||
await triggers.onCardDiscarded.execute(ctx.game, { cardId });
|
||||
|
|
@ -97,7 +97,7 @@ export function createTriggers(run: IRunContext) {
|
|||
});
|
||||
const { cards, regions } = ctx.game.value.player.deck;
|
||||
const card = cards[ctx.cardId];
|
||||
const source = ctx.sourceEntityId ?? "player";
|
||||
const source = ctx.sourceEntityKey ?? "player";
|
||||
for (const { trigger, target, effects } of card.cardData.effects) {
|
||||
if (trigger !== "onPlay") continue;
|
||||
for (const [effect, stacks] of effects)
|
||||
|
|
@ -109,10 +109,10 @@ export function createTriggers(run: IRunContext) {
|
|||
))
|
||||
await triggers.onEffectApplied.execute(ctx.game, {
|
||||
effect,
|
||||
entityId: entity.id,
|
||||
entityKey: entity.id,
|
||||
stacks,
|
||||
cardId: ctx.cardId,
|
||||
sourceEntityId: source,
|
||||
sourceEntityKey: source,
|
||||
targetId: ctx.targetId,
|
||||
});
|
||||
}
|
||||
|
|
@ -125,7 +125,7 @@ export function createTriggers(run: IRunContext) {
|
|||
});
|
||||
const { cards, regions } = ctx.game.value.player.deck;
|
||||
const card = cards[ctx.cardId];
|
||||
const source = ctx.sourceEntityId ?? "player";
|
||||
const source = ctx.sourceEntityKey ?? "player";
|
||||
for (const { trigger, target, effects } of card.cardData.effects) {
|
||||
if (trigger !== "onDiscard") continue;
|
||||
for (const [effect, stacks] of effects)
|
||||
|
|
@ -137,10 +137,10 @@ export function createTriggers(run: IRunContext) {
|
|||
))
|
||||
await triggers.onEffectApplied.execute(ctx.game, {
|
||||
effect,
|
||||
entityId: entity.id,
|
||||
entityKey: entity.id,
|
||||
stacks,
|
||||
cardId: ctx.cardId,
|
||||
sourceEntityId: source,
|
||||
sourceEntityKey: source,
|
||||
});
|
||||
}
|
||||
}),
|
||||
|
|
@ -151,7 +151,7 @@ export function createTriggers(run: IRunContext) {
|
|||
});
|
||||
const { cards, regions } = ctx.game.value.player.deck;
|
||||
const card = cards[ctx.cardId];
|
||||
const source = ctx.sourceEntityId ?? "player";
|
||||
const source = ctx.sourceEntityKey ?? "player";
|
||||
for (const { trigger, target, effects } of card.cardData.effects) {
|
||||
if (trigger !== "onDraw") continue;
|
||||
for (const [effect, stacks] of effects)
|
||||
|
|
@ -163,10 +163,10 @@ export function createTriggers(run: IRunContext) {
|
|||
))
|
||||
await triggers.onEffectApplied.execute(ctx.game, {
|
||||
effect,
|
||||
entityId: entity.id,
|
||||
entityKey: entity.id,
|
||||
stacks,
|
||||
cardId: ctx.cardId,
|
||||
sourceEntityId: source,
|
||||
sourceEntityKey: source,
|
||||
});
|
||||
}
|
||||
}),
|
||||
|
|
@ -204,18 +204,18 @@ export function createTriggers(run: IRunContext) {
|
|||
|
||||
await ctx.game.produceAsync((draft) => {
|
||||
const entity =
|
||||
ctx.entityId === "player"
|
||||
ctx.entityKey === "player"
|
||||
? draft.player
|
||||
: draft.enemies.find((e) => e.id === ctx.entityId);
|
||||
: draft.enemies.find((e) => e.id === ctx.entityKey);
|
||||
if (entity) addEntityEffect(entity, ctx.effect, ctx.stacks);
|
||||
});
|
||||
}),
|
||||
onHpChange: createTrigger("onHpChange", async (ctx) => {
|
||||
await ctx.game.produceAsync((draft) => {
|
||||
const entity =
|
||||
ctx.entityId === "player"
|
||||
ctx.entityKey === "player"
|
||||
? draft.player
|
||||
: draft.enemies.find((e) => e.id === ctx.entityId);
|
||||
: draft.enemies.find((e) => e.id === ctx.entityKey);
|
||||
if (!entity) return;
|
||||
entity.hp += ctx.amount;
|
||||
entity.isAlive = entity.hp > 0;
|
||||
|
|
@ -229,9 +229,9 @@ export function createTriggers(run: IRunContext) {
|
|||
}),
|
||||
onDamage: createTrigger("onDamage", async (ctx) => {
|
||||
const entity =
|
||||
ctx.entityId === "player"
|
||||
ctx.entityKey === "player"
|
||||
? ctx.game.value.player
|
||||
: ctx.game.value.enemies.find((e) => e.id === ctx.entityId);
|
||||
: ctx.game.value.enemies.find((e) => e.id === ctx.entityKey);
|
||||
if (!entity || !entity.isAlive) return;
|
||||
const dealt = Math.min(
|
||||
Math.max(0, entity.hp),
|
||||
|
|
@ -241,7 +241,7 @@ export function createTriggers(run: IRunContext) {
|
|||
onEntityPostureDamage(entity, dealt);
|
||||
});
|
||||
await triggers.onHpChange.execute(ctx.game, {
|
||||
entityId: ctx.entityId,
|
||||
entityKey: ctx.entityKey,
|
||||
amount: -dealt,
|
||||
});
|
||||
}),
|
||||
|
|
@ -252,7 +252,7 @@ export function createTriggers(run: IRunContext) {
|
|||
const intent = enemy.currentIntent;
|
||||
if (!intent) return;
|
||||
|
||||
const source = ctx.sourceEntityId ?? enemy.id;
|
||||
const source = ctx.sourceEntityKey ?? enemy.id;
|
||||
for (const [target, effect, stacks] of intent.effects) {
|
||||
for (const entity of getEffectTargets(
|
||||
target,
|
||||
|
|
@ -262,9 +262,9 @@ export function createTriggers(run: IRunContext) {
|
|||
))
|
||||
await triggers.onEffectApplied.execute(ctx.game, {
|
||||
effect,
|
||||
entityId: entity.id,
|
||||
entityKey: entity.id,
|
||||
stacks,
|
||||
sourceEntityId: source,
|
||||
sourceEntityKey: source,
|
||||
});
|
||||
}
|
||||
}),
|
||||
|
|
@ -298,7 +298,7 @@ export function createStartWith(
|
|||
|
||||
try {
|
||||
while (true) {
|
||||
await triggers.onTurnStart.execute(game, { entityId: "player" });
|
||||
await triggers.onTurnStart.execute(game, { entityKey: "player" });
|
||||
while (true) {
|
||||
const action = await promptMainAction(game, run);
|
||||
if (action.action === "end-turn") break;
|
||||
|
|
@ -306,17 +306,17 @@ export function createStartWith(
|
|||
await triggers.onCardPlayed.execute(game, action);
|
||||
}
|
||||
}
|
||||
await triggers.onTurnEnd.execute(game, { entityId: "player" });
|
||||
await triggers.onTurnEnd.execute(game, { entityKey: "player" });
|
||||
|
||||
for (const enemy of getAliveEnemies(game.value)) {
|
||||
await triggers.onTurnStart.execute(game, { entityId: enemy.id });
|
||||
await triggers.onTurnStart.execute(game, { entityKey: enemy.id });
|
||||
}
|
||||
for (const enemy of getAliveEnemies(game.value)) {
|
||||
await triggers.onEnemyIntent.execute(game, { enemyId: enemy.id });
|
||||
await triggers.onIntentUpdate.execute(game, { enemyId: enemy.id });
|
||||
}
|
||||
for (const enemy of getAliveEnemies(game.value)) {
|
||||
await triggers.onTurnEnd.execute(game, { entityId: enemy.id });
|
||||
await triggers.onTurnEnd.execute(game, { entityKey: enemy.id });
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
|
|
|
|||
|
|
@ -205,9 +205,9 @@ describe("desert triggers", () => {
|
|||
|
||||
await triggers.onEffectApplied.execute(ctx, {
|
||||
effect: attackEffect,
|
||||
entityId: "player",
|
||||
entityKey: "player",
|
||||
stacks: 5,
|
||||
sourceEntityId: "enemy-0",
|
||||
sourceEntityKey: "enemy-0",
|
||||
});
|
||||
|
||||
expect(ctx.value.player.hp).toBe(25);
|
||||
|
|
@ -223,7 +223,7 @@ describe("desert triggers", () => {
|
|||
|
||||
await triggers.onEffectApplied.execute(ctx, {
|
||||
effect: drawEffect,
|
||||
entityId: "player",
|
||||
entityKey: "player",
|
||||
stacks: 2,
|
||||
});
|
||||
|
||||
|
|
@ -239,7 +239,7 @@ describe("desert triggers", () => {
|
|||
const initialEnergy = ctx.value.player.energy;
|
||||
await triggers.onEffectApplied.execute(ctx, {
|
||||
effect: gainEnergyEffect,
|
||||
entityId: "player",
|
||||
entityKey: "player",
|
||||
stacks: 2,
|
||||
});
|
||||
|
||||
|
|
@ -261,7 +261,7 @@ describe("desert triggers", () => {
|
|||
|
||||
await triggers.onEffectApplied.execute(ctx, {
|
||||
effect: removeWoundEffect,
|
||||
entityId: "player",
|
||||
entityKey: "player",
|
||||
stacks: 2,
|
||||
});
|
||||
|
||||
|
|
@ -286,9 +286,9 @@ describe("desert triggers", () => {
|
|||
});
|
||||
|
||||
await triggers.onDamage.execute(ctx, {
|
||||
entityId: "player",
|
||||
entityKey: "player",
|
||||
amount: 8,
|
||||
sourceEntityId: "enemy-0",
|
||||
sourceEntityKey: "enemy-0",
|
||||
});
|
||||
|
||||
expect(ctx.value.player.hp).toBe(27);
|
||||
|
|
@ -312,9 +312,9 @@ describe("desert triggers", () => {
|
|||
});
|
||||
|
||||
await triggers.onDamage.execute(ctx, {
|
||||
entityId: "player",
|
||||
entityKey: "player",
|
||||
amount: 8,
|
||||
sourceEntityId: "enemy-0",
|
||||
sourceEntityKey: "enemy-0",
|
||||
});
|
||||
|
||||
expect(ctx.value.player.hp).toBe(25);
|
||||
|
|
@ -334,9 +334,9 @@ describe("desert triggers", () => {
|
|||
});
|
||||
|
||||
await triggers.onDamage.execute(ctx, {
|
||||
entityId: "player",
|
||||
entityKey: "player",
|
||||
amount: 5,
|
||||
sourceEntityId: "enemy-0",
|
||||
sourceEntityKey: "enemy-0",
|
||||
});
|
||||
|
||||
expect(ctx.value.player.hp).toBe(23);
|
||||
|
|
@ -359,9 +359,9 @@ describe("desert triggers", () => {
|
|||
});
|
||||
|
||||
await triggers.onDamage.execute(ctx, {
|
||||
entityId: "仙人掌怪-0",
|
||||
entityKey: "仙人掌怪-0",
|
||||
amount: 5,
|
||||
sourceEntityId: "player",
|
||||
sourceEntityKey: "player",
|
||||
});
|
||||
|
||||
expect(ctx.value.player.hp).toBe(27);
|
||||
|
|
@ -402,9 +402,9 @@ describe("desert triggers", () => {
|
|||
});
|
||||
|
||||
await triggers.onDamage.execute(ctx, {
|
||||
entityId: "幼沙虫-0",
|
||||
entityKey: "幼沙虫-0",
|
||||
amount: 5,
|
||||
sourceEntityId: "player",
|
||||
sourceEntityKey: "player",
|
||||
});
|
||||
|
||||
expect(ctx.value.player.energy).toBe(2);
|
||||
|
|
@ -429,9 +429,9 @@ describe("desert triggers", () => {
|
|||
let threw = false;
|
||||
try {
|
||||
await triggers.onDamage.execute(ctx, {
|
||||
entityId: "蜥蜴-0",
|
||||
entityKey: "蜥蜴-0",
|
||||
amount: 1,
|
||||
sourceEntityId: "player",
|
||||
sourceEntityKey: "player",
|
||||
});
|
||||
} catch (e) {
|
||||
threw = true;
|
||||
|
|
@ -457,7 +457,7 @@ describe("desert triggers", () => {
|
|||
draft.player.effects.discard = { data: discardEffect, stacks: 1 };
|
||||
});
|
||||
|
||||
await triggers.onTurnStart.execute(ctx, { entityId: "player" });
|
||||
await triggers.onTurnStart.execute(ctx, { entityKey: "player" });
|
||||
|
||||
expect(ctx.value.player.deck.regions.hand.childIds.length).toBe(2);
|
||||
expect(ctx.value.player.deck.regions.discardPile.childIds.length).toBe(1);
|
||||
|
|
@ -474,7 +474,7 @@ describe("desert triggers", () => {
|
|||
draft.player.effects.defendNext = { data: defendNextEffect, stacks: 5 };
|
||||
});
|
||||
|
||||
await triggers.onTurnStart.execute(ctx, { entityId: "player" });
|
||||
await triggers.onTurnStart.execute(ctx, { entityKey: "player" });
|
||||
|
||||
expect(ctx.value.player.effects.defend?.stacks).toBe(5);
|
||||
expect(ctx.value.player.effects.defendNext).toBeUndefined();
|
||||
|
|
@ -489,7 +489,7 @@ describe("desert triggers", () => {
|
|||
draft.player.effects.energyNext = { data: energyNextEffect, stacks: 2 };
|
||||
});
|
||||
|
||||
await triggers.onTurnStart.execute(ctx, { entityId: "player" });
|
||||
await triggers.onTurnStart.execute(ctx, { entityKey: "player" });
|
||||
|
||||
expect(ctx.value.player.energy).toBe(5);
|
||||
expect(ctx.value.player.effects.energyNext).toBeUndefined();
|
||||
|
|
@ -508,7 +508,7 @@ describe("desert triggers", () => {
|
|||
draft.player.effects.drawNext = { data: drawNextEffect, stacks: 2 };
|
||||
});
|
||||
|
||||
await triggers.onTurnStart.execute(ctx, { entityId: "player" });
|
||||
await triggers.onTurnStart.execute(ctx, { entityKey: "player" });
|
||||
|
||||
expect(ctx.value.player.deck.regions.hand.childIds.length).toBe(2);
|
||||
expect(ctx.value.player.effects.drawNext).toBeUndefined();
|
||||
|
|
@ -530,9 +530,9 @@ describe("desert triggers", () => {
|
|||
});
|
||||
|
||||
await triggers.onDamage.execute(ctx, {
|
||||
entityId: "仙人掌怪-0",
|
||||
entityKey: "仙人掌怪-0",
|
||||
amount: 5,
|
||||
sourceEntityId: "player",
|
||||
sourceEntityKey: "player",
|
||||
});
|
||||
|
||||
expect(ctx.value.enemies[0].hp).toBe(2);
|
||||
|
|
@ -552,9 +552,9 @@ describe("desert triggers", () => {
|
|||
});
|
||||
|
||||
await triggers.onDamage.execute(ctx, {
|
||||
entityId: "仙人掌怪-0",
|
||||
entityKey: "仙人掌怪-0",
|
||||
amount: 5,
|
||||
sourceEntityId: "player",
|
||||
sourceEntityKey: "player",
|
||||
});
|
||||
|
||||
expect(ctx.value.enemies[0].hp).toBe(74);
|
||||
|
|
@ -576,9 +576,9 @@ describe("desert triggers", () => {
|
|||
});
|
||||
|
||||
await triggers.onDamage.execute(ctx, {
|
||||
entityId: "player",
|
||||
entityKey: "player",
|
||||
amount: 5,
|
||||
sourceEntityId: "沙蝎-0",
|
||||
sourceEntityKey: "沙蝎-0",
|
||||
});
|
||||
|
||||
expect(ctx.value.player.hp).toBe(23);
|
||||
|
|
@ -599,9 +599,9 @@ describe("desert triggers", () => {
|
|||
});
|
||||
|
||||
await triggers.onDamage.execute(ctx, {
|
||||
entityId: "player",
|
||||
entityKey: "player",
|
||||
amount: 5,
|
||||
sourceEntityId: "骑马枪手-0",
|
||||
sourceEntityKey: "骑马枪手-0",
|
||||
});
|
||||
|
||||
expect(ctx.value.player.hp).toBe(20);
|
||||
|
|
@ -623,10 +623,10 @@ describe("desert triggers", () => {
|
|||
|
||||
await triggers.onEffectApplied.execute(ctx, {
|
||||
effect: crossbowEffect,
|
||||
entityId: "player",
|
||||
entityKey: "player",
|
||||
stacks: 0,
|
||||
cardId: "crossbow-1",
|
||||
sourceEntityId: "player",
|
||||
sourceEntityKey: "player",
|
||||
targetId: "仙人掌怪-0",
|
||||
});
|
||||
|
||||
|
|
@ -647,7 +647,7 @@ describe("desert triggers", () => {
|
|||
|
||||
await triggers.onCardDiscarded.execute(ctx, {
|
||||
cardId: "fatigue-1",
|
||||
sourceEntityId: "player",
|
||||
sourceEntityKey: "player",
|
||||
});
|
||||
|
||||
expect(ctx.value.enemies[0].hp).toBe(40);
|
||||
|
|
@ -664,9 +664,9 @@ describe("desert triggers", () => {
|
|||
const triggers = getTriggers();
|
||||
|
||||
await triggers.onDamage.execute(ctx, {
|
||||
entityId: "player",
|
||||
entityKey: "player",
|
||||
amount: 5,
|
||||
sourceEntityId: "秃鹫-0",
|
||||
sourceEntityKey: "秃鹫-0",
|
||||
});
|
||||
|
||||
const vultureEyeCards = Object.values(ctx.value.player.deck.cards).filter(
|
||||
|
|
|
|||
|
|
@ -1,176 +1,174 @@
|
|||
import { describe, it, expect } from "vitest";
|
||||
import { parseCommand, type Command } from "@/utils/command";
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { parseCommand, type Command } from '@/utils/command';
|
||||
|
||||
describe("parseCommand", () => {
|
||||
it("should parse empty string", () => {
|
||||
const result = parseCommand("");
|
||||
expect(result).toEqual({
|
||||
name: "",
|
||||
flags: {},
|
||||
options: {},
|
||||
params: [],
|
||||
describe('parseCommand', () => {
|
||||
it('should parse empty string', () => {
|
||||
const result = parseCommand('');
|
||||
expect(result).toEqual({
|
||||
name: '',
|
||||
flags: {},
|
||||
options: {},
|
||||
params: []
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should parse command name only", () => {
|
||||
const result = parseCommand("move");
|
||||
expect(result).toEqual({
|
||||
name: "move",
|
||||
flags: {},
|
||||
options: {},
|
||||
params: [],
|
||||
it('should parse command name only', () => {
|
||||
const result = parseCommand('move');
|
||||
expect(result).toEqual({
|
||||
name: 'move',
|
||||
flags: {},
|
||||
options: {},
|
||||
params: []
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should parse command with params", () => {
|
||||
const result = parseCommand("move meeple1 region1");
|
||||
expect(result).toEqual({
|
||||
name: "move",
|
||||
flags: {},
|
||||
options: {},
|
||||
params: ["meeple1", "region1"],
|
||||
it('should parse command with params', () => {
|
||||
const result = parseCommand('move meeple1 region1');
|
||||
expect(result).toEqual({
|
||||
name: 'move',
|
||||
flags: {},
|
||||
options: {},
|
||||
params: ['meeple1', 'region1']
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should parse command with long flags", () => {
|
||||
const result = parseCommand("move meeple1 --force --quiet");
|
||||
expect(result).toEqual({
|
||||
name: "move",
|
||||
flags: { force: true, quiet: true },
|
||||
options: {},
|
||||
params: ["meeple1"],
|
||||
it('should parse command with long flags', () => {
|
||||
const result = parseCommand('move meeple1 --force --quiet');
|
||||
expect(result).toEqual({
|
||||
name: 'move',
|
||||
flags: { force: true, quiet: true },
|
||||
options: {},
|
||||
params: ['meeple1']
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should parse command with short flags", () => {
|
||||
const result = parseCommand("move meeple1 -f -q");
|
||||
expect(result).toEqual({
|
||||
name: "move",
|
||||
flags: { f: true, q: true },
|
||||
options: {},
|
||||
params: ["meeple1"],
|
||||
it('should parse command with short flags', () => {
|
||||
const result = parseCommand('move meeple1 -f -q');
|
||||
expect(result).toEqual({
|
||||
name: 'move',
|
||||
flags: { f: true, q: true },
|
||||
options: {},
|
||||
params: ['meeple1']
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should parse command with long options", () => {
|
||||
const result = parseCommand("move meeple1 --x 10 --y 20");
|
||||
expect(result).toEqual({
|
||||
name: "move",
|
||||
flags: {},
|
||||
options: { x: "10", y: "20" },
|
||||
params: ["meeple1"],
|
||||
it('should parse command with long options', () => {
|
||||
const result = parseCommand('move meeple1 --x 10 --y 20');
|
||||
expect(result).toEqual({
|
||||
name: 'move',
|
||||
flags: {},
|
||||
options: { x: '10', y: '20' },
|
||||
params: ['meeple1']
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should parse command with short options", () => {
|
||||
const result = parseCommand("move meeple1 -x 10 -y 20");
|
||||
expect(result).toEqual({
|
||||
name: "move",
|
||||
flags: {},
|
||||
options: { x: "10", y: "20" },
|
||||
params: ["meeple1"],
|
||||
it('should parse command with short options', () => {
|
||||
const result = parseCommand('move meeple1 -x 10 -y 20');
|
||||
expect(result).toEqual({
|
||||
name: 'move',
|
||||
flags: {},
|
||||
options: { x: '10', y: '20' },
|
||||
params: ['meeple1']
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should parse command with mixed flags和选项", () => {
|
||||
const result = parseCommand("move meeple1 region1 --force -x 10 -q");
|
||||
expect(result).toEqual({
|
||||
name: "move",
|
||||
flags: { force: true, q: true },
|
||||
options: { x: "10" },
|
||||
params: ["meeple1", "region1"],
|
||||
it('should parse command with mixed flags和选项', () => {
|
||||
const result = parseCommand('move meeple1 region1 --force -x 10 -q');
|
||||
expect(result).toEqual({
|
||||
name: 'move',
|
||||
flags: { force: true, q: true },
|
||||
options: { x: '10' },
|
||||
params: ['meeple1', 'region1']
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should handle extra whitespace", () => {
|
||||
const result = parseCommand(" move meeple1 --force ");
|
||||
expect(result).toEqual({
|
||||
name: "move",
|
||||
flags: { force: true },
|
||||
options: {},
|
||||
params: ["meeple1"],
|
||||
it('should handle extra whitespace', () => {
|
||||
const result = parseCommand(' move meeple1 --force ');
|
||||
expect(result).toEqual({
|
||||
name: 'move',
|
||||
flags: { force: true },
|
||||
options: {},
|
||||
params: ['meeple1']
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should parse complex command", () => {
|
||||
const result = parseCommand(
|
||||
"place meeple1 board --x 5 --y 3 --rotate 90 --force",
|
||||
);
|
||||
expect(result).toEqual({
|
||||
name: "place",
|
||||
flags: { force: true },
|
||||
options: { x: "5", y: "3", rotate: "90" },
|
||||
params: ["meeple1", "board"],
|
||||
it('should parse complex command', () => {
|
||||
const result = parseCommand('place meeple1 board --x 5 --y 3 --rotate 90 --force');
|
||||
expect(result).toEqual({
|
||||
name: 'place',
|
||||
flags: { force: true },
|
||||
options: { x: '5', y: '3', rotate: '90' },
|
||||
params: ['meeple1', 'board']
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should treat negative number as option value", () => {
|
||||
const result = parseCommand("set --value -10");
|
||||
expect(result).toEqual({
|
||||
name: "set",
|
||||
flags: {},
|
||||
options: { value: "-10" },
|
||||
params: [],
|
||||
it('should treat negative number as option value', () => {
|
||||
const result = parseCommand('set --value -10');
|
||||
expect(result).toEqual({
|
||||
name: 'set',
|
||||
flags: {},
|
||||
options: { value: '-10' },
|
||||
params: []
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should parse quoted string with double quotes", () => {
|
||||
const result = parseCommand('place tile "large castle" --x 5');
|
||||
expect(result).toEqual({
|
||||
name: "place",
|
||||
flags: {},
|
||||
options: { x: "5" },
|
||||
params: ["tile", "large castle"],
|
||||
it('should parse quoted string with double quotes', () => {
|
||||
const result = parseCommand('place tile "large castle" --x 5');
|
||||
expect(result).toEqual({
|
||||
name: 'place',
|
||||
flags: {},
|
||||
options: { x: '5' },
|
||||
params: ['tile', 'large castle']
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should parse quoted string with single quotes", () => {
|
||||
const result = parseCommand("place tile 'large castle' --x 5");
|
||||
expect(result).toEqual({
|
||||
name: "place",
|
||||
flags: {},
|
||||
options: { x: "5" },
|
||||
params: ["tile", "large castle"],
|
||||
it('should parse quoted string with single quotes', () => {
|
||||
const result = parseCommand("place tile 'large castle' --x 5");
|
||||
expect(result).toEqual({
|
||||
name: 'place',
|
||||
flags: {},
|
||||
options: { x: '5' },
|
||||
params: ['tile', 'large castle']
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should handle escaped quotes", () => {
|
||||
const result = parseCommand('say "hello \\"world\\""');
|
||||
expect(result).toEqual({
|
||||
name: "say",
|
||||
flags: {},
|
||||
options: {},
|
||||
params: ['hello "world"'],
|
||||
it('should handle escaped quotes', () => {
|
||||
const result = parseCommand('say "hello \\"world\\""');
|
||||
expect(result).toEqual({
|
||||
name: 'say',
|
||||
flags: {},
|
||||
options: {},
|
||||
params: ['hello "world"']
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should handle escaped backslash", () => {
|
||||
const result = parseCommand('set path "C:\\\\Users"');
|
||||
expect(result).toEqual({
|
||||
name: "set",
|
||||
flags: {},
|
||||
options: {},
|
||||
params: ["path", "C:\\Users"],
|
||||
it('should handle escaped backslash', () => {
|
||||
const result = parseCommand('set path "C:\\\\Users"');
|
||||
expect(result).toEqual({
|
||||
name: 'set',
|
||||
flags: {},
|
||||
options: {},
|
||||
params: ['path', 'C:\\Users']
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should handle mixed quotes", () => {
|
||||
const result = parseCommand("cmd \"hello world\" 'foo bar' --flag");
|
||||
expect(result).toEqual({
|
||||
name: "cmd",
|
||||
flags: { flag: true },
|
||||
options: {},
|
||||
params: ["hello world", "foo bar"],
|
||||
it('should handle mixed quotes', () => {
|
||||
const result = parseCommand('cmd "hello world" \'foo bar\' --flag');
|
||||
expect(result).toEqual({
|
||||
name: 'cmd',
|
||||
flags: { flag: true },
|
||||
options: {},
|
||||
params: ['hello world', 'foo bar']
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should handle quote in middle of argument", () => {
|
||||
const result = parseCommand('cmd "hello\'s world"');
|
||||
expect(result).toEqual({
|
||||
name: "cmd",
|
||||
flags: {},
|
||||
options: {},
|
||||
params: ["hello's world"],
|
||||
it('should handle quote in middle of argument', () => {
|
||||
const result = parseCommand('cmd "hello\'s world"');
|
||||
expect(result).toEqual({
|
||||
name: 'cmd',
|
||||
flags: {},
|
||||
options: {},
|
||||
params: ["hello's world"]
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue