Split custom world generation into staged lightweight batches
Some checks failed
CI / verify (push) Has been cancelled
Some checks failed
CI / verify (push) Has been cancelled
This commit is contained in:
@@ -5,21 +5,21 @@ import type {
|
||||
EquipmentLoadout,
|
||||
GameState,
|
||||
InventoryItem,
|
||||
RoleAttributeProfile,
|
||||
SceneMonster,
|
||||
TimedBuildBuff,
|
||||
WorldAttributeSchema,
|
||||
} from '../types';
|
||||
import { WorldType } from '../types';
|
||||
import {
|
||||
WorldType,
|
||||
} from '../types';
|
||||
resolveCriticalStrike,
|
||||
resolveRoleCombatStats,
|
||||
} from './attributeCombat';
|
||||
import {
|
||||
getNormalizedAttributeWeights,
|
||||
resolveAttributeSchema,
|
||||
resolveCharacterAttributeProfile,
|
||||
} from './attributeResolver';
|
||||
import { normalizeAttributeVector } from './attributeValidation';
|
||||
import {getBuildTagAttributeSimilarityProfile} from './buildTagAttributeAffinity';
|
||||
import { getBuildTagAttributeSimilarityProfile } from './buildTagAttributeAffinity';
|
||||
import {
|
||||
buildSetBuildTagLabel,
|
||||
getBuildTagDefinition,
|
||||
@@ -35,6 +35,16 @@ import { getEquipmentBonuses } from './equipmentEffects';
|
||||
const MAX_ACTIVE_BUILD_TAGS = 8;
|
||||
export const BASE_TAG_BONUS = 0.12;
|
||||
export const MAX_BUILD_BONUS = 0.6;
|
||||
export type BuildContributionQuality =
|
||||
| 'common'
|
||||
| 'fine'
|
||||
| 'rare'
|
||||
| 'epic'
|
||||
| 'legendary';
|
||||
export type BuildContributionResourceLabels = {
|
||||
maxHp?: string | null;
|
||||
maxMp?: string | null;
|
||||
};
|
||||
|
||||
export type BuildTagSource =
|
||||
| 'buff'
|
||||
@@ -83,6 +93,37 @@ export type BuildContributionAttributeRow = {
|
||||
percent: number;
|
||||
};
|
||||
|
||||
export type OutgoingDamageResult = {
|
||||
damage: number;
|
||||
isCritical: boolean;
|
||||
critChance: number;
|
||||
critDamageMultiplier: number;
|
||||
attackPowerMultiplier: number;
|
||||
};
|
||||
|
||||
type BuildContributionTarget = {
|
||||
slotId: string;
|
||||
label: string;
|
||||
definition: string;
|
||||
};
|
||||
|
||||
type ResolvedTagAffinity = {
|
||||
rawSimilarity: AttributeVector;
|
||||
};
|
||||
|
||||
const BUILD_CONTRIBUTION_QUALITY_LEVELS: Array<{
|
||||
tier: BuildContributionQuality;
|
||||
label: string;
|
||||
minimumBonus: number;
|
||||
colorRatio: number;
|
||||
}> = [
|
||||
{ tier: 'legendary', label: '传说', minimumBonus: 0.06, colorRatio: 1 },
|
||||
{ tier: 'epic', label: '史诗', minimumBonus: 0.045, colorRatio: 0.78 },
|
||||
{ tier: 'rare', label: '稀有', minimumBonus: 0.03, colorRatio: 0.56 },
|
||||
{ tier: 'fine', label: '优秀', minimumBonus: 0.018, colorRatio: 0.32 },
|
||||
{ tier: 'common', label: '普通', minimumBonus: 0, colorRatio: 0.08 },
|
||||
];
|
||||
|
||||
function clamp(value: number, min: number, max: number) {
|
||||
return Math.min(max, Math.max(min, value));
|
||||
}
|
||||
@@ -126,7 +167,8 @@ function pushTag(
|
||||
label: normalizedLabel,
|
||||
source,
|
||||
priority,
|
||||
relatedTags: relatedTags && relatedTags.length > 0 ? [...relatedTags] : undefined,
|
||||
relatedTags:
|
||||
relatedTags && relatedTags.length > 0 ? [...relatedTags] : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -142,16 +184,21 @@ function getLoadoutBuildTags(loadout: EquipmentLoadout | null | undefined) {
|
||||
if (!loadout) return [];
|
||||
|
||||
const tags: ResolvedBuildTag[] = [];
|
||||
const setPieces = new Map<string, { count: number; tags: string[]; setName: string }>();
|
||||
const setPieces = new Map<
|
||||
string,
|
||||
{ count: number; tags: string[]; setName: string }
|
||||
>();
|
||||
|
||||
([
|
||||
['weapon', loadout.weapon],
|
||||
['armor', loadout.armor],
|
||||
['relic', loadout.relic],
|
||||
] as const).forEach(([slotId, item]) => {
|
||||
(
|
||||
[
|
||||
['weapon', loadout.weapon],
|
||||
['armor', loadout.armor],
|
||||
['relic', loadout.relic],
|
||||
] as const
|
||||
).forEach(([slotId, item]) => {
|
||||
if (!item) return;
|
||||
const itemTags = getItemBuildTags(item);
|
||||
itemTags.forEach(tag => pushTag(tags, tag, slotId, 60));
|
||||
itemTags.forEach((tag) => pushTag(tags, tag, slotId, 60));
|
||||
|
||||
const setId = item.buildProfile?.setId?.trim();
|
||||
const setName = item.buildProfile?.setName?.trim();
|
||||
@@ -167,7 +214,7 @@ function getLoadoutBuildTags(loadout: EquipmentLoadout | null | undefined) {
|
||||
setPieces.set(setId, entry);
|
||||
});
|
||||
|
||||
setPieces.forEach(entry => {
|
||||
setPieces.forEach((entry) => {
|
||||
if (entry.count < 2) return;
|
||||
pushTag(
|
||||
tags,
|
||||
@@ -184,7 +231,7 @@ function getLoadoutBuildTags(loadout: EquipmentLoadout | null | undefined) {
|
||||
function dedupeAndLimitTags(tags: ResolvedBuildTag[]) {
|
||||
const bestByLabel = new Map<string, ResolvedBuildTag>();
|
||||
|
||||
tags.forEach(tag => {
|
||||
tags.forEach((tag) => {
|
||||
const existing = bestByLabel.get(tag.label);
|
||||
if (!existing || tag.priority > existing.priority) {
|
||||
bestByLabel.set(tag.label, tag);
|
||||
@@ -192,70 +239,147 @@ function dedupeAndLimitTags(tags: ResolvedBuildTag[]) {
|
||||
});
|
||||
|
||||
return [...bestByLabel.values()]
|
||||
.sort((left, right) => right.priority - left.priority || left.label.localeCompare(right.label, 'zh-CN'))
|
||||
.sort(
|
||||
(left, right) =>
|
||||
right.priority - left.priority ||
|
||||
left.label.localeCompare(right.label, 'zh-CN'),
|
||||
)
|
||||
.slice(0, MAX_ACTIVE_BUILD_TAGS);
|
||||
}
|
||||
|
||||
function averageAttributeVectors(vectors: AttributeVector[], slotIds: readonly string[]) {
|
||||
function averageAttributeVectors(
|
||||
vectors: AttributeVector[],
|
||||
slotIds: readonly string[],
|
||||
) {
|
||||
if (vectors.length === 0) {
|
||||
const evenShare = 1 / Math.max(slotIds.length, 1);
|
||||
return Object.fromEntries(slotIds.map(slotId => [slotId, evenShare]));
|
||||
return Object.fromEntries(slotIds.map((slotId) => [slotId, evenShare]));
|
||||
}
|
||||
|
||||
return Object.fromEntries(
|
||||
slotIds.map(slotId => [
|
||||
slotIds.map((slotId) => [
|
||||
slotId,
|
||||
roundNumber(vectors.reduce((sum, vector) => sum + (vector[slotId] ?? 0), 0) / vectors.length, 4),
|
||||
roundNumber(
|
||||
vectors.reduce((sum, vector) => sum + (vector[slotId] ?? 0), 0) /
|
||||
vectors.length,
|
||||
4,
|
||||
),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
function resolveTagAffinity(tag: ResolvedBuildTag, schema: WorldAttributeSchema) {
|
||||
function resolveTagAffinity(
|
||||
tag: ResolvedBuildTag,
|
||||
schema: WorldAttributeSchema,
|
||||
) {
|
||||
const definition = getBuildTagDefinition(tag.label);
|
||||
if (definition) {
|
||||
return getBuildTagAttributeSimilarityProfile(definition.id, schema);
|
||||
return {
|
||||
rawSimilarity: getBuildTagAttributeSimilarityProfile(
|
||||
definition.id,
|
||||
schema,
|
||||
).rawSimilarity,
|
||||
} satisfies ResolvedTagAffinity;
|
||||
}
|
||||
|
||||
const relatedAffinities = (tag.relatedTags ?? []).flatMap(relatedTag => {
|
||||
const relatedDefinition = getBuildTagDefinition(relatedTag);
|
||||
if (!relatedDefinition) {
|
||||
return [];
|
||||
}
|
||||
const relatedSchemaAffinities = (tag.relatedTags ?? []).flatMap(
|
||||
(relatedTag) => {
|
||||
const relatedDefinition = getBuildTagDefinition(relatedTag);
|
||||
if (!relatedDefinition) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [getBuildTagAttributeSimilarityProfile(relatedDefinition.id, schema).rawSimilarity];
|
||||
});
|
||||
|
||||
const rawSimilarity = averageAttributeVectors(relatedAffinities, schema.slots.map(slot => slot.slotId));
|
||||
return [
|
||||
getBuildTagAttributeSimilarityProfile(relatedDefinition.id, schema)
|
||||
.rawSimilarity,
|
||||
];
|
||||
},
|
||||
);
|
||||
const rawSimilarity = averageAttributeVectors(
|
||||
relatedSchemaAffinities,
|
||||
schema.slots.map((slot) => slot.slotId),
|
||||
);
|
||||
|
||||
return {
|
||||
rawSimilarity,
|
||||
normalizedSimilarity: normalizeAttributeVector(rawSimilarity, schema.slots.map(slot => slot.slotId)),
|
||||
};
|
||||
} satisfies ResolvedTagAffinity;
|
||||
}
|
||||
|
||||
function resolveContributionTargets(
|
||||
schema: WorldAttributeSchema,
|
||||
_resourceLabels?: BuildContributionResourceLabels | null,
|
||||
) {
|
||||
return schema.slots.map((slot) => ({
|
||||
slotId: slot.slotId,
|
||||
label: slot.name,
|
||||
definition: slot.definition,
|
||||
})) satisfies BuildContributionTarget[];
|
||||
}
|
||||
|
||||
function buildAttributeContributions(
|
||||
profile: RoleAttributeProfile | null | undefined,
|
||||
tagAffinity: AttributeVector,
|
||||
tagAffinity: ResolvedTagAffinity,
|
||||
schema: WorldAttributeSchema,
|
||||
sourceCoefficient: number,
|
||||
resourceLabels?: BuildContributionResourceLabels | null,
|
||||
) {
|
||||
const slotIds = schema.slots.map(slot => slot.slotId);
|
||||
const attributeWeights = getNormalizedAttributeWeights(profile, schema);
|
||||
const normalizedAffinity = normalizeAttributeVector(tagAffinity ?? {}, slotIds);
|
||||
const targets = resolveContributionTargets(schema, resourceLabels);
|
||||
const slotIds = targets.map((target) => target.slotId);
|
||||
const rawSimilarity = Object.fromEntries(
|
||||
targets.map((target) => {
|
||||
return [
|
||||
target.slotId,
|
||||
roundNumber(tagAffinity.rawSimilarity[target.slotId] ?? 0, 4),
|
||||
];
|
||||
}),
|
||||
);
|
||||
const normalizedAffinity = normalizeAttributeVector(rawSimilarity, slotIds);
|
||||
const effectiveSlotIds = new Set(
|
||||
[...slotIds]
|
||||
.sort((left, right) => {
|
||||
const difference =
|
||||
(normalizedAffinity[right] ?? 0) - (normalizedAffinity[left] ?? 0);
|
||||
if (Math.abs(difference) > 0.0001) {
|
||||
return difference;
|
||||
}
|
||||
|
||||
return left.localeCompare(right, 'zh-CN');
|
||||
})
|
||||
.slice(0, 2),
|
||||
);
|
||||
const attributeContributions = Object.fromEntries(
|
||||
slotIds.map(slotId => [
|
||||
slotIds.map((slotId) => [
|
||||
slotId,
|
||||
roundNumber((attributeWeights[slotId] ?? 0) * (normalizedAffinity[slotId] ?? 0), 4),
|
||||
roundNumber(
|
||||
effectiveSlotIds.has(slotId) ? (normalizedAffinity[slotId] ?? 0) : 0,
|
||||
4,
|
||||
),
|
||||
]),
|
||||
);
|
||||
const attributeWeights = Object.fromEntries(
|
||||
slotIds.map((slotId) => [
|
||||
slotId,
|
||||
roundNumber(
|
||||
effectiveSlotIds.has(slotId) ? (normalizedAffinity[slotId] ?? 0) : 0,
|
||||
4,
|
||||
),
|
||||
]),
|
||||
);
|
||||
const attributeModifierDeltas = Object.fromEntries(
|
||||
slotIds.map(slotId => [
|
||||
slotIds.map((slotId) => [
|
||||
slotId,
|
||||
roundNumber(BASE_TAG_BONUS * sourceCoefficient * (attributeContributions[slotId] ?? 0), 4),
|
||||
roundNumber(
|
||||
BASE_TAG_BONUS *
|
||||
sourceCoefficient *
|
||||
(attributeContributions[slotId] ?? 0),
|
||||
4,
|
||||
),
|
||||
]),
|
||||
);
|
||||
const fitScore = roundNumber(
|
||||
slotIds.reduce((sum, slotId) => sum + (attributeContributions[slotId] ?? 0), 0),
|
||||
slotIds.reduce(
|
||||
(sum, slotId) => sum + (attributeContributions[slotId] ?? 0),
|
||||
0,
|
||||
),
|
||||
4,
|
||||
);
|
||||
|
||||
@@ -270,8 +394,8 @@ function buildAttributeContributions(
|
||||
|
||||
function buildBreakdownFromTags(
|
||||
tags: ResolvedBuildTag[],
|
||||
profile: RoleAttributeProfile | null | undefined,
|
||||
schema: WorldAttributeSchema,
|
||||
resourceLabels?: BuildContributionResourceLabels | null,
|
||||
): BuildDamageBreakdown {
|
||||
if (tags.length === 0) {
|
||||
return {
|
||||
@@ -283,7 +407,7 @@ function buildBreakdownFromTags(
|
||||
};
|
||||
}
|
||||
|
||||
const rows = tags.map(currentTag => {
|
||||
const rows = tags.map((currentTag) => {
|
||||
const tagAffinity = resolveTagAffinity(currentTag, schema);
|
||||
const sourceCoefficient = getSourceCoefficient(currentTag.source);
|
||||
const {
|
||||
@@ -292,9 +416,17 @@ function buildBreakdownFromTags(
|
||||
normalizedAffinity,
|
||||
attributeContributions,
|
||||
attributeModifierDeltas,
|
||||
} = buildAttributeContributions(profile, tagAffinity.normalizedSimilarity, schema, sourceCoefficient);
|
||||
} = buildAttributeContributions(
|
||||
tagAffinity,
|
||||
schema,
|
||||
sourceCoefficient,
|
||||
resourceLabels,
|
||||
);
|
||||
const bonusDelta = roundNumber(
|
||||
Object.values(attributeModifierDeltas).reduce((sum, value) => sum + value, 0),
|
||||
Object.values(attributeModifierDeltas).reduce(
|
||||
(sum, value) => sum + value,
|
||||
0,
|
||||
),
|
||||
4,
|
||||
);
|
||||
|
||||
@@ -312,13 +444,17 @@ function buildBreakdownFromTags(
|
||||
});
|
||||
|
||||
const buildDamageBonus = roundNumber(
|
||||
clamp(rows.reduce((sum, row) => sum + row.bonusDelta, 0), 0, MAX_BUILD_BONUS),
|
||||
clamp(
|
||||
rows.reduce((sum, row) => sum + row.bonusDelta, 0),
|
||||
0,
|
||||
MAX_BUILD_BONUS,
|
||||
),
|
||||
4,
|
||||
);
|
||||
const buildDamageMultiplier = roundNumber(1 + buildDamageBonus, 4);
|
||||
|
||||
return {
|
||||
tags: tags.map(tag => tag.label),
|
||||
tags: tags.map((tag) => tag.label),
|
||||
baseTagCount: tags.length,
|
||||
buildDamageBonus,
|
||||
buildDamageMultiplier,
|
||||
@@ -347,68 +483,139 @@ export function getBuildSourceLabel(source: BuildTagSource) {
|
||||
}
|
||||
}
|
||||
|
||||
export function getBuildContributionQuality(
|
||||
bonusDelta: number,
|
||||
): (typeof BUILD_CONTRIBUTION_QUALITY_LEVELS)[number] {
|
||||
const fallbackLevel =
|
||||
BUILD_CONTRIBUTION_QUALITY_LEVELS[
|
||||
BUILD_CONTRIBUTION_QUALITY_LEVELS.length - 1
|
||||
] ?? BUILD_CONTRIBUTION_QUALITY_LEVELS[0]!;
|
||||
|
||||
return (
|
||||
BUILD_CONTRIBUTION_QUALITY_LEVELS.find(
|
||||
(level) => bonusDelta >= level.minimumBonus,
|
||||
) ?? fallbackLevel
|
||||
);
|
||||
}
|
||||
|
||||
export function getBuildContributionQualityLabel(bonusDelta: number) {
|
||||
return getBuildContributionQuality(bonusDelta).label;
|
||||
}
|
||||
|
||||
export function getBuildContributionQualityRatio(bonusDelta: number) {
|
||||
return getBuildContributionQuality(bonusDelta).colorRatio;
|
||||
}
|
||||
|
||||
export function formatBuildContributionPercent(value: number, digits = 1) {
|
||||
const percentValue = roundNumber(value * 100, digits);
|
||||
const normalizedDigits = Math.max(0, digits);
|
||||
return `${percentValue >= 0 ? '+' : ''}${percentValue.toFixed(normalizedDigits)}%`;
|
||||
}
|
||||
|
||||
export function getBuildContributionAttributeRows(
|
||||
row: Pick<
|
||||
BuildContributionRow,
|
||||
'attributeContributions' | 'attributeModifierDeltas' | 'attributeSimilarities' | 'attributeWeights'
|
||||
| 'attributeContributions'
|
||||
| 'attributeModifierDeltas'
|
||||
| 'attributeSimilarities'
|
||||
| 'attributeWeights'
|
||||
>,
|
||||
schema: WorldAttributeSchema,
|
||||
minimumValue = 0.0001,
|
||||
options: {
|
||||
minimumValue?: number;
|
||||
resourceLabels?: BuildContributionResourceLabels | null;
|
||||
} = {},
|
||||
) {
|
||||
const totalModifierDelta = Object.values(row.attributeModifierDeltas ?? {}).reduce((sum, value) => sum + value, 0);
|
||||
const minimumValue = options.minimumValue ?? 0.0001;
|
||||
const totalModifierDelta = Object.values(
|
||||
row.attributeModifierDeltas ?? {},
|
||||
).reduce((sum, value) => sum + value, 0);
|
||||
const targets = resolveContributionTargets(schema, options.resourceLabels);
|
||||
|
||||
return schema.slots
|
||||
.map(slot => {
|
||||
const value = roundNumber(row.attributeContributions[slot.slotId] ?? 0, 4);
|
||||
const modifierDelta = roundNumber(row.attributeModifierDeltas?.[slot.slotId] ?? 0, 4);
|
||||
const percent = totalModifierDelta > 0 ? roundNumber(modifierDelta / totalModifierDelta, 4) : 0;
|
||||
return targets
|
||||
.map((target) => {
|
||||
const value = roundNumber(
|
||||
row.attributeContributions[target.slotId] ?? 0,
|
||||
4,
|
||||
);
|
||||
const modifierDelta = roundNumber(
|
||||
row.attributeModifierDeltas?.[target.slotId] ?? 0,
|
||||
4,
|
||||
);
|
||||
const percent =
|
||||
totalModifierDelta > 0
|
||||
? roundNumber(modifierDelta / totalModifierDelta, 4)
|
||||
: 0;
|
||||
|
||||
return {
|
||||
slotId: slot.slotId,
|
||||
label: slot.name,
|
||||
definition: slot.definition,
|
||||
similarity: roundNumber(row.attributeSimilarities?.[slot.slotId] ?? 0, 4),
|
||||
weight: roundNumber(row.attributeWeights?.[slot.slotId] ?? 0, 4),
|
||||
slotId: target.slotId,
|
||||
label: target.label,
|
||||
definition: target.definition,
|
||||
similarity: roundNumber(
|
||||
row.attributeSimilarities?.[target.slotId] ?? 0,
|
||||
4,
|
||||
),
|
||||
weight: roundNumber(row.attributeWeights?.[target.slotId] ?? 0, 4),
|
||||
value,
|
||||
modifierDelta,
|
||||
percent,
|
||||
} satisfies BuildContributionAttributeRow;
|
||||
})
|
||||
.filter(entry => entry.value > minimumValue || entry.modifierDelta > minimumValue)
|
||||
.sort((left, right) => right.value - left.value || left.label.localeCompare(right.label, 'zh-CN'));
|
||||
.filter(
|
||||
(entry) =>
|
||||
entry.value > minimumValue || entry.modifierDelta > minimumValue,
|
||||
)
|
||||
.sort(
|
||||
(left, right) =>
|
||||
right.modifierDelta - left.modifierDelta ||
|
||||
left.label.localeCompare(right.label, 'zh-CN'),
|
||||
);
|
||||
}
|
||||
|
||||
export function describeBuildContribution(
|
||||
row: Pick<
|
||||
BuildContributionRow,
|
||||
'attributeContributions' | 'attributeModifierDeltas' | 'attributeSimilarities' | 'attributeWeights'
|
||||
| 'attributeContributions'
|
||||
| 'attributeModifierDeltas'
|
||||
| 'attributeSimilarities'
|
||||
| 'attributeWeights'
|
||||
>,
|
||||
schema: WorldAttributeSchema,
|
||||
limit = 2,
|
||||
options: {
|
||||
limit?: number;
|
||||
resourceLabels?: BuildContributionResourceLabels | null;
|
||||
} = {},
|
||||
) {
|
||||
const topRows = getBuildContributionAttributeRows(row, schema).slice(0, limit);
|
||||
const limit = options.limit ?? 2;
|
||||
const topRows = getBuildContributionAttributeRows(row, schema, options).slice(
|
||||
0,
|
||||
limit,
|
||||
);
|
||||
if (topRows.length === 0) {
|
||||
return '\u5f53\u524d\u5c5e\u6027\u9002\u914d\u8f83\u5f31';
|
||||
return '\u6682\u65e0\u53ef\u89c1\u5c5e\u6027\u52a0\u6210';
|
||||
}
|
||||
|
||||
if (topRows.length === 1) {
|
||||
return `${topRows[0]?.label ?? '\u4e3b\u5c5e\u6027'}\u4e3b\u5bfc`;
|
||||
}
|
||||
|
||||
return `${topRows[0]?.label ?? '\u4e3b\u5c5e\u6027'}\u4e3b\u5bfc\uff0c${topRows[1]?.label ?? '\u8f85\u52a9\u5c5e\u6027'}\u8f85\u52a9`;
|
||||
return topRows
|
||||
.map(
|
||||
(entry) =>
|
||||
`${entry.label} ${formatBuildContributionPercent(entry.modifierDelta)}`,
|
||||
)
|
||||
.join(',');
|
||||
}
|
||||
|
||||
function getPlayerBuffs(gameState: GameState) {
|
||||
return (gameState.activeBuildBuffs ?? []).filter(buff => (buff.durationTurns ?? 0) > 0);
|
||||
return (gameState.activeBuildBuffs ?? []).filter(
|
||||
(buff) => (buff.durationTurns ?? 0) > 0,
|
||||
);
|
||||
}
|
||||
|
||||
export function tickBuildBuffs(buffs: TimedBuildBuff[] | null | undefined) {
|
||||
return (buffs ?? [])
|
||||
.map(buff => ({
|
||||
.map((buff) => ({
|
||||
...buff,
|
||||
durationTurns: Math.max(0, (buff.durationTurns ?? 0) - 1),
|
||||
}))
|
||||
.filter(buff => buff.durationTurns > 0);
|
||||
.filter((buff) => buff.durationTurns > 0);
|
||||
}
|
||||
|
||||
export function appendBuildBuffs(
|
||||
@@ -417,9 +624,12 @@ export function appendBuildBuffs(
|
||||
) {
|
||||
const merged = new Map<string, TimedBuildBuff>();
|
||||
|
||||
[...(baseBuffs ?? []), ...(additions ?? [])].forEach(buff => {
|
||||
[...(baseBuffs ?? []), ...(additions ?? [])].forEach((buff) => {
|
||||
const existing = merged.get(buff.id);
|
||||
if (!existing || (buff.durationTurns ?? 0) >= (existing.durationTurns ?? 0)) {
|
||||
if (
|
||||
!existing ||
|
||||
(buff.durationTurns ?? 0) >= (existing.durationTurns ?? 0)
|
||||
) {
|
||||
merged.set(buff.id, {
|
||||
...buff,
|
||||
tags: normalizeBuildTags(buff.tags),
|
||||
@@ -427,18 +637,28 @@ export function appendBuildBuffs(
|
||||
}
|
||||
});
|
||||
|
||||
return [...merged.values()].filter(buff => buff.tags.length > 0 && buff.durationTurns > 0);
|
||||
return [...merged.values()].filter(
|
||||
(buff) => buff.tags.length > 0 && buff.durationTurns > 0,
|
||||
);
|
||||
}
|
||||
|
||||
export function getPlayerBuildDamageBreakdown(gameState: GameState, character: Character) {
|
||||
export function getPlayerBuildDamageBreakdown(
|
||||
gameState: GameState,
|
||||
character: Character,
|
||||
) {
|
||||
const tags: ResolvedBuildTag[] = [];
|
||||
getTimedBuildBuffTags(getPlayerBuffs(gameState)).forEach(tag => pushTag(tags, tag, 'buff', 100));
|
||||
getCharacterCombatTags(character).forEach(tag => pushTag(tags, tag, 'character', 90));
|
||||
getLoadoutBuildTags(gameState.playerEquipment).forEach(tag => tags.push(tag));
|
||||
getTimedBuildBuffTags(getPlayerBuffs(gameState)).forEach((tag) =>
|
||||
pushTag(tags, tag, 'buff', 100),
|
||||
);
|
||||
getCharacterCombatTags(character).forEach((tag) =>
|
||||
pushTag(tags, tag, 'character', 90),
|
||||
);
|
||||
getLoadoutBuildTags(gameState.playerEquipment).forEach((tag) =>
|
||||
tags.push(tag),
|
||||
);
|
||||
|
||||
return buildBreakdownFromTags(
|
||||
dedupeAndLimitTags(tags),
|
||||
resolveCharacterAttributeProfile(character, gameState.worldType, gameState.customWorldProfile),
|
||||
resolveAttributeSchema(gameState.worldType, gameState.customWorldProfile),
|
||||
);
|
||||
}
|
||||
@@ -449,12 +669,14 @@ export function getCompanionBuildDamageBreakdown(
|
||||
customWorldProfile: CustomWorldProfile | null = getRuntimeCustomWorldProfile(),
|
||||
) {
|
||||
const tags: ResolvedBuildTag[] = [];
|
||||
getCharacterCombatTags(character).forEach(tag => pushTag(tags, tag, 'character', 90));
|
||||
const resolvedWorldType = worldType ?? (customWorldProfile ? WorldType.CUSTOM : WorldType.WUXIA);
|
||||
getCharacterCombatTags(character).forEach((tag) =>
|
||||
pushTag(tags, tag, 'character', 90),
|
||||
);
|
||||
const resolvedWorldType =
|
||||
worldType ?? (customWorldProfile ? WorldType.CUSTOM : WorldType.WUXIA);
|
||||
|
||||
return buildBreakdownFromTags(
|
||||
dedupeAndLimitTags(tags),
|
||||
resolveCharacterAttributeProfile(character, resolvedWorldType, customWorldProfile),
|
||||
resolveAttributeSchema(resolvedWorldType, customWorldProfile),
|
||||
);
|
||||
}
|
||||
@@ -465,13 +687,19 @@ export function getMonsterBuildDamageBreakdown(
|
||||
customWorldProfile: CustomWorldProfile | null = getRuntimeCustomWorldProfile(),
|
||||
) {
|
||||
const tags: ResolvedBuildTag[] = [];
|
||||
getSceneMonsterCombatTags(monster).forEach(tag => pushTag(tags, tag, 'monster', 90));
|
||||
const resolvedWorldType = worldType
|
||||
?? (monster.attributeProfile?.schemaId?.includes('xianxia') ? WorldType.XIANXIA : customWorldProfile ? WorldType.CUSTOM : WorldType.WUXIA);
|
||||
getSceneMonsterCombatTags(monster).forEach((tag) =>
|
||||
pushTag(tags, tag, 'monster', 90),
|
||||
);
|
||||
const resolvedWorldType =
|
||||
worldType ??
|
||||
(monster.attributeProfile?.schemaId?.includes('xianxia')
|
||||
? WorldType.XIANXIA
|
||||
: customWorldProfile
|
||||
? WorldType.CUSTOM
|
||||
: WorldType.WUXIA);
|
||||
|
||||
return buildBreakdownFromTags(
|
||||
dedupeAndLimitTags(tags),
|
||||
monster.attributeProfile ?? null,
|
||||
resolveAttributeSchema(resolvedWorldType, customWorldProfile),
|
||||
);
|
||||
}
|
||||
@@ -482,25 +710,61 @@ export function calculateOutgoingDamage(
|
||||
functionMultiplier?: number;
|
||||
equipmentMultiplier?: number;
|
||||
buildMultiplier?: number;
|
||||
attackPowerMultiplier?: number;
|
||||
} = {},
|
||||
) {
|
||||
return Math.max(
|
||||
1,
|
||||
Math.round(
|
||||
baseDamage
|
||||
* (options.functionMultiplier ?? 1)
|
||||
* (options.equipmentMultiplier ?? 1)
|
||||
* (options.buildMultiplier ?? 1),
|
||||
baseDamage *
|
||||
(options.functionMultiplier ?? 1) *
|
||||
(options.equipmentMultiplier ?? 1) *
|
||||
(options.buildMultiplier ?? 1) *
|
||||
(options.attackPowerMultiplier ?? 1),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function calculateOutgoingDamageResult(
|
||||
baseDamage: number,
|
||||
options: {
|
||||
functionMultiplier?: number;
|
||||
equipmentMultiplier?: number;
|
||||
buildMultiplier?: number;
|
||||
attackPowerMultiplier?: number;
|
||||
criticalHit?: boolean;
|
||||
critDamageMultiplier?: number;
|
||||
critChance?: number;
|
||||
} = {},
|
||||
): OutgoingDamageResult {
|
||||
const baseResolvedDamage = calculateOutgoingDamage(baseDamage, options);
|
||||
const isCritical = options.criticalHit ?? false;
|
||||
const critDamageMultiplier = options.critDamageMultiplier ?? 1;
|
||||
|
||||
return {
|
||||
damage: Math.max(
|
||||
1,
|
||||
Math.round(baseResolvedDamage * (isCritical ? critDamageMultiplier : 1)),
|
||||
),
|
||||
isCritical,
|
||||
critChance: options.critChance ?? 0,
|
||||
critDamageMultiplier,
|
||||
attackPowerMultiplier: options.attackPowerMultiplier ?? 1,
|
||||
};
|
||||
}
|
||||
|
||||
export function resolvePlayerOutgoingDamage(
|
||||
gameState: GameState,
|
||||
character: Character,
|
||||
baseDamage: number,
|
||||
functionMultiplier = 1,
|
||||
) {
|
||||
const attributeProfile = resolveCharacterAttributeProfile(
|
||||
character,
|
||||
gameState.worldType,
|
||||
gameState.customWorldProfile,
|
||||
);
|
||||
const combatStats = resolveRoleCombatStats(attributeProfile);
|
||||
const buildBreakdown = getPlayerBuildDamageBreakdown(gameState, character);
|
||||
const equipmentBonuses = getEquipmentBonuses(gameState.playerEquipment);
|
||||
|
||||
@@ -508,6 +772,37 @@ export function resolvePlayerOutgoingDamage(
|
||||
functionMultiplier,
|
||||
equipmentMultiplier: equipmentBonuses.outgoingDamageMultiplier,
|
||||
buildMultiplier: buildBreakdown.buildDamageMultiplier,
|
||||
attackPowerMultiplier: combatStats.attackPowerMultiplier,
|
||||
});
|
||||
}
|
||||
|
||||
export function resolvePlayerOutgoingDamageResult(
|
||||
gameState: GameState,
|
||||
character: Character,
|
||||
baseDamage: number,
|
||||
functionMultiplier = 1,
|
||||
critRollSeed?: string,
|
||||
) {
|
||||
const attributeProfile = resolveCharacterAttributeProfile(
|
||||
character,
|
||||
gameState.worldType,
|
||||
gameState.customWorldProfile,
|
||||
);
|
||||
const combatStats = resolveRoleCombatStats(attributeProfile);
|
||||
const criticalStrike = critRollSeed
|
||||
? resolveCriticalStrike(attributeProfile, critRollSeed)
|
||||
: null;
|
||||
const buildBreakdown = getPlayerBuildDamageBreakdown(gameState, character);
|
||||
const equipmentBonuses = getEquipmentBonuses(gameState.playerEquipment);
|
||||
|
||||
return calculateOutgoingDamageResult(baseDamage, {
|
||||
functionMultiplier,
|
||||
equipmentMultiplier: equipmentBonuses.outgoingDamageMultiplier,
|
||||
buildMultiplier: buildBreakdown.buildDamageMultiplier,
|
||||
attackPowerMultiplier: combatStats.attackPowerMultiplier,
|
||||
criticalHit: criticalStrike?.isCritical ?? false,
|
||||
critChance: combatStats.critChance,
|
||||
critDamageMultiplier: combatStats.critDamageMultiplier,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -518,11 +813,55 @@ export function resolveCompanionOutgoingDamage(
|
||||
worldType: WorldType | null = null,
|
||||
customWorldProfile: CustomWorldProfile | null = getRuntimeCustomWorldProfile(),
|
||||
) {
|
||||
const buildBreakdown = getCompanionBuildDamageBreakdown(character, worldType, customWorldProfile);
|
||||
const attributeProfile = resolveCharacterAttributeProfile(
|
||||
character,
|
||||
worldType,
|
||||
customWorldProfile,
|
||||
);
|
||||
const combatStats = resolveRoleCombatStats(attributeProfile);
|
||||
const buildBreakdown = getCompanionBuildDamageBreakdown(
|
||||
character,
|
||||
worldType,
|
||||
customWorldProfile,
|
||||
);
|
||||
|
||||
return calculateOutgoingDamage(baseDamage, {
|
||||
functionMultiplier,
|
||||
buildMultiplier: buildBreakdown.buildDamageMultiplier,
|
||||
attackPowerMultiplier: combatStats.attackPowerMultiplier,
|
||||
});
|
||||
}
|
||||
|
||||
export function resolveCompanionOutgoingDamageResult(
|
||||
character: Character,
|
||||
baseDamage: number,
|
||||
functionMultiplier = 1,
|
||||
worldType: WorldType | null = null,
|
||||
customWorldProfile: CustomWorldProfile | null = getRuntimeCustomWorldProfile(),
|
||||
critRollSeed?: string,
|
||||
) {
|
||||
const attributeProfile = resolveCharacterAttributeProfile(
|
||||
character,
|
||||
worldType,
|
||||
customWorldProfile,
|
||||
);
|
||||
const combatStats = resolveRoleCombatStats(attributeProfile);
|
||||
const criticalStrike = critRollSeed
|
||||
? resolveCriticalStrike(attributeProfile, critRollSeed)
|
||||
: null;
|
||||
const buildBreakdown = getCompanionBuildDamageBreakdown(
|
||||
character,
|
||||
worldType,
|
||||
customWorldProfile,
|
||||
);
|
||||
|
||||
return calculateOutgoingDamageResult(baseDamage, {
|
||||
functionMultiplier,
|
||||
buildMultiplier: buildBreakdown.buildDamageMultiplier,
|
||||
attackPowerMultiplier: combatStats.attackPowerMultiplier,
|
||||
criticalHit: criticalStrike?.isCritical ?? false,
|
||||
critChance: combatStats.critChance,
|
||||
critDamageMultiplier: combatStats.critDamageMultiplier,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -533,10 +872,44 @@ export function resolveMonsterOutgoingDamage(
|
||||
worldType: WorldType | null = null,
|
||||
customWorldProfile: CustomWorldProfile | null = getRuntimeCustomWorldProfile(),
|
||||
) {
|
||||
const buildBreakdown = getMonsterBuildDamageBreakdown(monster, worldType, customWorldProfile);
|
||||
const combatStats = resolveRoleCombatStats(monster.attributeProfile);
|
||||
const buildBreakdown = getMonsterBuildDamageBreakdown(
|
||||
monster,
|
||||
worldType,
|
||||
customWorldProfile,
|
||||
);
|
||||
|
||||
return calculateOutgoingDamage(baseDamage, {
|
||||
functionMultiplier,
|
||||
buildMultiplier: buildBreakdown.buildDamageMultiplier,
|
||||
attackPowerMultiplier: combatStats.attackPowerMultiplier,
|
||||
});
|
||||
}
|
||||
|
||||
export function resolveMonsterOutgoingDamageResult(
|
||||
monster: SceneMonster,
|
||||
baseDamage: number,
|
||||
functionMultiplier = 1,
|
||||
worldType: WorldType | null = null,
|
||||
customWorldProfile: CustomWorldProfile | null = getRuntimeCustomWorldProfile(),
|
||||
critRollSeed?: string,
|
||||
) {
|
||||
const combatStats = resolveRoleCombatStats(monster.attributeProfile);
|
||||
const criticalStrike = critRollSeed
|
||||
? resolveCriticalStrike(monster.attributeProfile, critRollSeed)
|
||||
: null;
|
||||
const buildBreakdown = getMonsterBuildDamageBreakdown(
|
||||
monster,
|
||||
worldType,
|
||||
customWorldProfile,
|
||||
);
|
||||
|
||||
return calculateOutgoingDamageResult(baseDamage, {
|
||||
functionMultiplier,
|
||||
buildMultiplier: buildBreakdown.buildDamageMultiplier,
|
||||
attackPowerMultiplier: combatStats.attackPowerMultiplier,
|
||||
criticalHit: criticalStrike?.isCritical ?? false,
|
||||
critChance: combatStats.critChance,
|
||||
critDamageMultiplier: combatStats.critDamageMultiplier,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user