fix: building effects take their sign from the value: a copy's training speed shows −50%, not +-50% (header table, wall tag); the mock sends training speed for military buildings
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
bcb1e4d4e4
commit
a63f0a2fd8
|
|
@ -41,11 +41,12 @@ function value(e: BuildingEffect) {
|
||||||
case 'production':
|
case 'production':
|
||||||
return t('village.resources.per_hour', { rate: formatRate(e.value) })
|
return t('village.resources.per_hour', { rate: formatRate(e.value) })
|
||||||
case 'wall_defense':
|
case 'wall_defense':
|
||||||
return `+${e.value}`
|
return formatSigned(e.value)
|
||||||
|
// A copy's training speed can fall below a single building's: the sign comes from the value.
|
||||||
case 'wall_bonus':
|
case 'wall_bonus':
|
||||||
case 'build_speed':
|
case 'build_speed':
|
||||||
case 'recruit_speed':
|
case 'recruit_speed':
|
||||||
return `+${e.value}%`
|
return `${formatSigned(e.value)}%`
|
||||||
case 'detection':
|
case 'detection':
|
||||||
return t('village.effects.fields', { n: e.value })
|
return t('village.effects.fields', { n: e.value })
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -535,6 +535,12 @@ function missingRequirements(v: MockVillage, unit: UnitType) {
|
||||||
.map(([type, level]) => ({ type: type as BuildingType, level: level ?? 0 }))
|
.map(([type, level]) => ({ type: type as BuildingType, level: level ?? 0 }))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const trains = (b: MockBuilding) => UNIT_TYPES.some((u) => UNITS[u].building === b.type)
|
||||||
|
|
||||||
|
/** Training speed against a single level-1 building, in percent; a copy's can be negative. */
|
||||||
|
const recruitSpeed = (v: MockVillage, b: MockBuilding, level: number) =>
|
||||||
|
({ key: 'recruit_speed', value: Math.round(((1 + 0.05 * Math.max(0, level - 1)) * instanceShare(v, b) - 1) * 100) }) as const
|
||||||
|
|
||||||
const secondsPerUnit = (v: MockVillage, b: MockBuilding, unit: UnitType) =>
|
const secondsPerUnit = (v: MockVillage, b: MockBuilding, unit: UnitType) =>
|
||||||
Math.max(1, Math.ceil(UNITS[unit].seconds / (1 + 0.05 * Math.max(0, b.level - 1)) / instanceShare(v, b)))
|
Math.max(1, Math.ceil(UNITS[unit].seconds / (1 + 0.05 * Math.max(0, b.level - 1)) / instanceShare(v, b)))
|
||||||
|
|
||||||
|
|
@ -682,9 +688,9 @@ function view(state: MockState, v: MockVillage, now: number): VillageState {
|
||||||
production: p ? { resource: p.resource, per_hour: round(p.per_hour) } : null,
|
production: p ? { resource: p.resource, per_hour: round(p.per_hour) } : null,
|
||||||
upgrade: upgradeOffer(v, b),
|
upgrade: upgradeOffer(v, b),
|
||||||
demolish: demolishOffer(v, b),
|
demolish: demolishOffer(v, b),
|
||||||
// Placeholder: production only; the backend lists every effect.
|
// Placeholder: production and training speed only; the backend lists every effect.
|
||||||
effects: p ? [{ key: 'production', value: round(p.per_hour), resource: p.resource }] : [],
|
effects: p ? [{ key: 'production', value: round(p.per_hour), resource: p.resource }] : trains(b) ? [recruitSpeed(v, b, b.level)] : [],
|
||||||
next_effects: null,
|
next_effects: !p && trains(b) && b.level < MAX_LEVEL ? [recruitSpeed(v, b, b.level + 1)] : null,
|
||||||
instance_share: instanceShare(v, b),
|
instance_share: instanceShare(v, b),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ export function buildingTag(
|
||||||
case 'wall':
|
case 'wall':
|
||||||
return {
|
return {
|
||||||
icon: { kind: 'ui', name: 'support' },
|
icon: { kind: 'ui', name: 'support' },
|
||||||
text: t('village.tags.percent', { value: effect('wall_bonus') }),
|
text: t('village.tags.percent', { value: formatSigned(effect('wall_bonus')) }),
|
||||||
tone: 'plain',
|
tone: 'plain',
|
||||||
title: t('village.tags.wall', { bonus: effect('wall_bonus'), defense: effect('wall_defense') }),
|
title: t('village.tags.wall', { bonus: effect('wall_bonus'), defense: effect('wall_defense') }),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,4 +20,7 @@ export const formatAmount = (n: number) => String(Math.floor(n))
|
||||||
/** 12.5 → "+12.5", -3 → "-3" */
|
/** 12.5 → "+12.5", -3 → "-3" */
|
||||||
export const formatRate = (n: number) => `${n >= 0 ? '+' : ''}${Math.round(n * 10) / 10}`
|
export const formatRate = (n: number) => `${n >= 0 ? '+' : ''}${Math.round(n * 10) / 10}`
|
||||||
|
|
||||||
|
/** A bonus with its sign from the value: 20 → "+20", -50 → "−50", 0 → "0". */
|
||||||
|
export const formatSigned = (n: number) => `${n > 0 ? '+' : n < 0 ? '−' : ''}${Math.abs(n)}`
|
||||||
|
|
||||||
export const formatCost = (cost: Cost) => `${cost.wood} / ${cost.clay} / ${cost.iron}`
|
export const formatCost = (cost: Cost) => `${cost.wood} / ${cost.clay} / ${cost.iron}`
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ export default {
|
||||||
troops: '{troops}',
|
troops: '{troops}',
|
||||||
troops_attacked: '{troops} · {attacks} incoming',
|
troops_attacked: '{troops} · {attacks} incoming',
|
||||||
troops_title: '{own} own troops and {support} support in the village',
|
troops_title: '{own} own troops and {support} support in the village',
|
||||||
percent: '+{value}%',
|
percent: '{value}%',
|
||||||
wall: 'Defenders fight {bonus}% harder, plus {defense} defence',
|
wall: 'Defenders fight {bonus}% harder, plus {defense} defence',
|
||||||
hides: 'Hides {amount} of each resource from raiders',
|
hides: 'Hides {amount} of each resource from raiders',
|
||||||
fields: '{fields} fields',
|
fields: '{fields} fields',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue