Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #349: Poison #350

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions app/src/libs/combat/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,46 @@ export const lifesteal = (
}
return getInfo(target, effect, `will steal ${qualifier} damage as health`);
};

/** Apply poison damage based on Chakra and Stamina usage */
export const poison = (
effect: UserEffect,
usersEffects: UserEffect[],
consequences: Map<string, Consequence>,
target: BattleUserState,
) => {
const { power, qualifier } = getPower(effect);

if (!effect.isNew && !effect.castThisRound) {
// Get all consequences for the target
consequences.forEach((consequence, effectId) => {
if (consequence.targetId === effect.targetId) {
const actionEffect = usersEffects.find((e) => e.id === effectId);
if (actionEffect && "data" in actionEffect && actionEffect.data && typeof actionEffect.data === "object" && actionEffect.data !== null && "chakraCost" in actionEffect.data) {
// Get the action data which contains the cost information
const actionData = actionEffect.data as { chakraCost: number; staminaCost: number };
// Calculate poison damage based on chakra and stamina costs
const chakraCost = actionData.chakraCost;
const staminaCost = actionData.staminaCost;
const totalCost = chakraCost + staminaCost;

if (totalCost > 0) {
// Calculate poison damage as a percentage of the total cost
const poisonDamage = Math.ceil(totalCost * (power / 100));

// Add poison damage to existing damage
consequence.damage = (consequence.damage || 0) + poisonDamage;
}
}
}
});
}

return getInfo(
target,
effect,
`will take ${qualifier}% damage based on Chakra and Stamina usage`,
);

/** Create a temporary HP shield that absorbs damage */
export const shield = (effect: UserEffect, target: BattleUserState) => {
Expand Down
12 changes: 12 additions & 0 deletions app/src/libs/combat/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,17 @@ export const WeaknessTag = z.object({
});
export type WeaknessTagType = z.infer<typeof WeaknessTag>;

export const PoisonTag = z.object({
...BaseAttributes,
...PowerAttributes,
type: z.literal("poison").default("poison"),
description: msg("Deals percentage damage based on Chakra and Stamina usage"),
calculation: z.enum(["percentage"]).default("percentage"),
rounds: z.coerce.number().int().min(1).max(10).default(3),
direction: type("offence"),
});
export type PoisonTagType = z.infer<typeof PoisonTag>;

export const UnknownTag = z.object({
...BaseAttributes,
type: z.literal("unknown").default("unknown"),
Expand Down Expand Up @@ -710,6 +721,7 @@ export const AllTags = z.union([
CloneTag.default({}),
DamageTag.default({}),
DebuffPreventTag.default({}),
PoisonTag.default({}),
DecreaseDamageGivenTag.default({}),
DecreaseDamageTakenTag.default({}),
DecreaseHealGivenTag.default({}),
Expand Down
Loading