BlueGit

timfa questward

Add combat shove and block/hit flash colors in world view.

Hits knock the target back, misses dodge sideways, and blocks flash white instead of damage red.

timfa Tim Falken · pushed by timfa

Authored 2026-08-30 · 2 months ago

Hash
b997b836430b6027c44e91eabba50db35f96cbec
Parent
324ceeca
1 file changed +93 −14
client/src/render/worldView.js +93 −14
@@ -48,6 +48,8 @@ const STACK_SPREAD_LERP_MS = 280;
48 48 /** Hold gather-tool equip overlay slightly past swing interval so it stays visible between swings. */
49 49 const GATHER_TOOL_HOLD_MS = 1100;
50 50 const DAMAGE_FLASH_MS = 180;
51 const FLASH_COLOR_DAMAGE = Object.freeze([1.0, 0.12, 0.12]);
52 const FLASH_COLOR_BLOCK = Object.freeze([1.0, 1.0, 1.0]);
51 53 const DAMAGE_FLOAT_MS = 900;
52 54 const SKILL_LEVEL_FLOAT_MS = 2800;
53 55 /** Projectiles spawn this many sprite-pixels below the caster sprite top. */
@@ -59,6 +61,7 @@ const SPRITE_LIGHTING_FRAG = [
59 61 "uniform sampler2D u_texture;",
60 62 "uniform float u_darkness;",
61 63 "uniform float u_strength;",
64 "uniform vec3 u_flashColor;",
62 65 "uniform float u_wade;",
63 66 "uniform float u_spriteHeight;",
64 67 "void main() {",
@@ -71,7 +74,7 @@ const SPRITE_LIGHTING_FRAG = [
71 74 " rgb = mix(rgb, vec3(0.55, 0.82, 0.98), 0.55);",
72 75 " }",
73 76 " rgb = mix(rgb, vec3(0.0), u_darkness);",
74 " rgb = mix(rgb, vec3(1.0, 0.12, 0.12), u_strength);",
77 " rgb = mix(rgb, u_flashColor, u_strength);",
75 78 " gl_FragColor = vec4(rgb, color.a);",
76 79 "}"
77 80 ].join("\n");
@@ -125,6 +128,7 @@ const TINT_LIT_SPRITE_FRAG = [
125 128 "uniform sampler2D u_texture;",
126 129 "uniform float u_darkness;",
127 130 "uniform float u_strength;",
131 "uniform vec3 u_flashColor;",
128 132 "uniform float u_wade;",
129 133 "uniform float u_spriteHeight;",
130 134 "uniform float u_useTint;",
@@ -147,7 +151,7 @@ const TINT_LIT_SPRITE_FRAG = [
147 151 " rgb = mix(rgb, vec3(0.55, 0.82, 0.98), 0.55);",
148 152 " }",
149 153 " rgb = mix(rgb, vec3(0.0), u_darkness);",
150 " rgb = mix(rgb, vec3(1.0, 0.12, 0.12), u_strength);",
154 " rgb = mix(rgb, u_flashColor, u_strength);",
151 155 " gl_FragColor = vec4(rgb, color.a);",
152 156 "}"
153 157 ].join("\n");
@@ -160,6 +164,7 @@ const DUAL_TINT_LIT_SPRITE_FRAG = [
160 164 "uniform sampler2D u_texture;",
161 165 "uniform float u_darkness;",
162 166 "uniform float u_strength;",
167 "uniform vec3 u_flashColor;",
163 168 "uniform float u_wade;",
164 169 "uniform float u_spriteHeight;",
165 170 "uniform vec3 u_shaftTint;",
@@ -200,7 +205,7 @@ const DUAL_TINT_LIT_SPRITE_FRAG = [
200 205 " rgb = mix(rgb, vec3(0.55, 0.82, 0.98), 0.55);",
201 206 " }",
202 207 " rgb = mix(rgb, vec3(0.0), u_darkness);",
203 " rgb = mix(rgb, vec3(1.0, 0.12, 0.12), u_strength);",
208 " rgb = mix(rgb, u_flashColor, u_strength);",
204 209 " gl_FragColor = vec4(rgb, color.a);",
205 210 "}"
206 211 ].join("\n");
@@ -246,6 +251,7 @@ const TIGHT_FIT_TINT_LIT_SPRITE_FRAG = [
246 251 "uniform sampler2D u_secondary;",
247 252 "uniform float u_darkness;",
248 253 "uniform float u_strength;",
254 "uniform vec3 u_flashColor;",
249 255 "uniform float u_wade;",
250 256 "uniform float u_spriteHeight;",
251 257 "uniform float u_useTint;",
@@ -269,7 +275,7 @@ const TIGHT_FIT_TINT_LIT_SPRITE_FRAG = [
269 275 " rgb = mix(rgb, vec3(0.55, 0.82, 0.98), 0.55);",
270 276 " }",
271 277 " rgb = mix(rgb, vec3(0.0), u_darkness);",
272 " rgb = mix(rgb, vec3(1.0, 0.12, 0.12), u_strength);",
278 " rgb = mix(rgb, u_flashColor, u_strength);",
273 279 " float alpha = min(tightFitBodyAlpha(), color.a);",
274 280 " if (alpha <= 0.0) { discard; }",
275 281 " gl_FragColor = vec4(rgb, alpha);",
@@ -284,6 +290,7 @@ const TIGHT_FIT_LIT_SPRITE_FRAG = [
284 290 "uniform sampler2D u_secondary;",
285 291 "uniform float u_darkness;",
286 292 "uniform float u_strength;",
293 "uniform vec3 u_flashColor;",
287 294 "uniform float u_wade;",
288 295 "uniform float u_spriteHeight;",
289 296 TIGHT_FIT_BODY_MASK_GLSL,
@@ -297,7 +304,7 @@ const TIGHT_FIT_LIT_SPRITE_FRAG = [
297 304 " rgb = mix(rgb, vec3(0.55, 0.82, 0.98), 0.55);",
298 305 " }",
299 306 " rgb = mix(rgb, vec3(0.0), u_darkness);",
300 " rgb = mix(rgb, vec3(1.0, 0.12, 0.12), u_strength);",
307 " rgb = mix(rgb, u_flashColor, u_strength);",
301 308 " float alpha = min(tightFitBodyAlpha(), color.a);",
302 309 " if (alpha <= 0.0) { discard; }",
303 310 " gl_FragColor = vec4(rgb, alpha);",
@@ -759,11 +766,53 @@ export class WorldView
759 766 }
760 767
761 768 flashDamage (entityId)
769 {
770 this.#flashEntity(entityId, FLASH_COLOR_DAMAGE);
771 }
772
773 flashBlock (entityId)
774 {
775 this.#flashEntity(entityId, FLASH_COLOR_BLOCK);
776 }
777
778 #flashEntity (entityId, color)
762 779 {
763 780 const entity = this.entities.get(entityId);
764 781 if (!entity)
765 782 { return; }
766 783 entity.damageFlashUntil = performance.now() + DAMAGE_FLASH_MS;
784 entity.damageFlashColor = color ?? FLASH_COLOR_DAMAGE;
785 }
786
787 /** Target knocks back away from attacker (hit). */
788 spawnCombatKnockback (payload)
789 {
790 const attacker = this.entities.get(payload?.attackerId);
791 const target = this.entities.get(payload?.targetId);
792 if (!attacker || !target)
793 { return; }
794 const ax = attacker.visualX + (attacker.stackOffsetX ?? 0);
795 const ay = attacker.visualY + (attacker.stackOffsetY ?? 0);
796 const tx = target.visualX + (target.stackOffsetX ?? 0);
797 const ty = target.visualY + (target.stackOffsetY ?? 0);
798 this.#applyShoveInDirection(target, tx - ax, ty - ay);
799 }
800
801 /** Target sidesteps perpendicular to the attack (dodge / miss). */
802 spawnCombatDodge (payload)
803 {
804 const attacker = this.entities.get(payload?.attackerId);
805 const target = this.entities.get(payload?.targetId);
806 if (!attacker || !target)
807 { return; }
808 const ax = attacker.visualX + (attacker.stackOffsetX ?? 0);
809 const ay = attacker.visualY + (attacker.stackOffsetY ?? 0);
810 const tx = target.visualX + (target.stackOffsetX ?? 0);
811 const ty = target.visualY + (target.stackOffsetY ?? 0);
812 const dx = tx - ax;
813 const dy = ty - ay;
814 const side = Math.random() < 0.5 ? 1 : -1;
815 this.#applyShoveInDirection(target, -dy * side, dx * side);
767 816 }
768 817
769 818 spawnDamageNumber (entityId, damage)
@@ -999,6 +1048,7 @@ export class WorldView
999 1048 uniforms = {
1000 1049 u_darkness: 0,
1001 1050 u_strength: 0,
1051 u_flashColor: FLASH_COLOR_DAMAGE,
1002 1052 u_wade: 0,
1003 1053 u_spriteHeight: height,
1004 1054 u_shaftTint: [shaft.r, shaft.g, shaft.b],
@@ -1016,6 +1066,7 @@ export class WorldView
1016 1066 uniforms = {
1017 1067 u_darkness: 0,
1018 1068 u_strength: 0,
1069 u_flashColor: FLASH_COLOR_DAMAGE,
1019 1070 u_wade: 0,
1020 1071 u_spriteHeight: height,
1021 1072 u_useTint: 1,
@@ -1029,6 +1080,7 @@ export class WorldView
1029 1080 uniforms = {
1030 1081 u_darkness: 0,
1031 1082 u_strength: 0,
1083 u_flashColor: FLASH_COLOR_DAMAGE,
1032 1084 u_wade: 0,
1033 1085 u_spriteHeight: height,
1034 1086 ...maskUniforms
@@ -1041,6 +1093,7 @@ export class WorldView
1041 1093 uniforms = {
1042 1094 u_darkness: 0,
1043 1095 u_strength: 0,
1096 u_flashColor: FLASH_COLOR_DAMAGE,
1044 1097 u_wade: 0,
1045 1098 u_spriteHeight: height,
1046 1099 u_useTint: 1,
@@ -1053,6 +1106,7 @@ export class WorldView
1053 1106 uniforms = {
1054 1107 u_darkness: 0,
1055 1108 u_strength: 0,
1109 u_flashColor: FLASH_COLOR_DAMAGE,
1056 1110 u_wade: 0,
1057 1111 u_spriteHeight: height
1058 1112 };
@@ -1467,6 +1521,21 @@ export class WorldView
1467 1521 };
1468 1522 }
1469 1523
1524 #applyShoveInDirection (entity, dirX, dirY)
1525 {
1526 const len = Math.hypot(dirX, dirY);
1527 if (len < 1e-4)
1528 { return; }
1529 const tileSize = this.tileSize();
1530 const ux = dirX / len;
1531 const uy = dirY / len;
1532 this.#applyShove(
1533 entity,
1534 entity.visualX + ux * tileSize,
1535 entity.visualY + uy * tileSize
1536 );
1537 }
1538
1470 1539 /** Physical combat FX (melee swipes, ranged projectiles). Magic spells stay unshaded. */
1471 1540 spawnPhysicalProjectileFx (payload)
1472 1541 {
@@ -2174,11 +2243,12 @@ export class WorldView
2174 2243 const flashStrength = (entity.damageFlashUntil ?? 0) > now
2175 2244 ? (entity.damageFlashUntil - now) / DAMAGE_FLASH_MS
2176 2245 : 0;
2246 const flashColor = entity.damageFlashColor ?? FLASH_COLOR_DAMAGE;
2177 2247 const tileShade = this.#entityShadeAlpha(entity, now);
2178 2248 const wade = isWadeGroundInSeason(this.#groundTypeAt(entity.tileX, entity.tileY), this.worldSeason);
2179 2249
2180 2250 entity.object.transform.rotation = walkTilt;
2181 this.#syncLitSprite(entity.object, tileShade, flashStrength, wade, entity.bodyTint ?? null);
2251 this.#syncLitSprite(entity.object, tileShade, flashStrength, wade, entity.bodyTint ?? null, flashColor);
2182 2252 this.#placePivoted(entity.object, pivotX, pivotY, pivotY, SORT_ENTITY, entity.visualScale ?? 1);
2183 2253 for (let index = 0; index < (entity.overlays ?? []).length; index++)
2184 2254 {
@@ -2188,7 +2258,7 @@ export class WorldView
2188 2258 const dualTint = entity.overlayDualTints?.[index] ?? null;
2189 2259 if (dualTint)
2190 2260 {
2191 this.#syncDualTintLitSprite(overlay, tileShade, dualTint, flashStrength, wade);
2261 this.#syncDualTintLitSprite(overlay, tileShade, dualTint, flashStrength, wade, flashColor);
2192 2262 }
2193 2263 else if (entity.overlayTightFit?.[index])
2194 2264 {
@@ -2198,12 +2268,13 @@ export class WorldView
2198 2268 tileShade,
2199 2269 flashStrength,
2200 2270 wade,
2201 entity.overlayTints?.[index] ?? null
2271 entity.overlayTints?.[index] ?? null,
2272 flashColor
2202 2273 );
2203 2274 }
2204 2275 else
2205 2276 {
2206 this.#syncLitSprite(overlay, tileShade, flashStrength, wade, entity.overlayTints?.[index] ?? null);
2277 this.#syncLitSprite(overlay, tileShade, flashStrength, wade, entity.overlayTints?.[index] ?? null, flashColor);
2207 2278 }
2208 2279 this.#placePivoted(overlay, pivotX, pivotY, overlaySortY, SORT_ENTITY, entity.visualScale ?? 1);
2209 2280 }
@@ -2224,7 +2295,7 @@ export class WorldView
2224 2295 if (bloomTint)
2225 2296 { this.#syncUnlitTintSprite(overlay, bloomTint); }
2226 2297 else
2227 { this.#syncLitSprite(overlay, tileShade, flashStrength, wade); }
2298 { this.#syncLitSprite(overlay, tileShade, flashStrength, wade, null, flashColor); }
2228 2299 this.#placePivoted(overlay, pivotX, pivotY, pivotY + 0.002, SORT_ENTITY, entity.visualScale ?? 1);
2229 2300 }
2230 2301 this.#placeHpBar(entity, pivotX, pivotY);
@@ -2252,6 +2323,7 @@ export class WorldView
2252 2323 object.renderer.shaderUniforms = {
2253 2324 u_darkness: 0,
2254 2325 u_strength: 0,
2326 u_flashColor: FLASH_COLOR_DAMAGE,
2255 2327 u_wade: 0,
2256 2328 u_spriteHeight: height,
2257 2329 u_useTint: 1,
@@ -2260,7 +2332,7 @@ export class WorldView
2260 2332 object.renderer.secondaryMap = null;
2261 2333 }
2262 2334
2263 #syncLitSprite (object, darkness, flashStrength = 0, wade = false, tintColor = null)
2335 #syncLitSprite (object, darkness, flashStrength = 0, wade = false, tintColor = null, flashColor = null)
2264 2336 {
2265 2337 if (!object?.renderer || object._lit === false)
2266 2338 { return; }
@@ -2268,6 +2340,7 @@ export class WorldView
2268 2340 const dark = Math.min(1, Math.max(0, darkness ?? 0));
2269 2341 const flash = Math.min(1, Math.max(0, flashStrength ?? 0));
2270 2342 const height = object.renderer.sprite?.height ?? SPRITE_SIZE_PX;
2343 const flashRgb = flashColor ?? FLASH_COLOR_DAMAGE;
2271 2344 const tint = tintColor ? normalizeRgb(tintColor) : null;
2272 2345 if (tint)
2273 2346 {
@@ -2275,6 +2348,7 @@ export class WorldView
2275 2348 object.renderer.shaderUniforms = {
2276 2349 u_darkness: dark,
2277 2350 u_strength: flash,
2351 u_flashColor: flashRgb,
2278 2352 u_wade: wade ? 1 : 0,
2279 2353 u_spriteHeight: height,
2280 2354 u_useTint: 1,
@@ -2287,6 +2361,7 @@ export class WorldView
2287 2361 object.renderer.shaderUniforms = {
2288 2362 u_darkness: dark,
2289 2363 u_strength: flash,
2364 u_flashColor: flashRgb,
2290 2365 u_wade: wade ? 1 : 0,
2291 2366 u_spriteHeight: height
2292 2367 };
@@ -2320,15 +2395,16 @@ export class WorldView
2320 2395 };
2321 2396 }
2322 2397
2323 #syncTightFitLitSprite (overlay, entity, darkness, flashStrength = 0, wade = false, tintColor = null)
2398 #syncTightFitLitSprite (overlay, entity, darkness, flashStrength = 0, wade = false, tintColor = null, flashColor = null)
2324 2399 {
2325 2400 if (!overlay?.renderer || entity?.object?.renderer == null)
2326 2401 { return; }
2327 2402 const bodyMap = this.#bodySecondaryMap(entity);
2328 2403 const maskUniforms = this.#tightFitMaskUniforms(overlay, entity);
2404 const flashRgb = flashColor ?? FLASH_COLOR_DAMAGE;
2329 2405 if (!bodyMap || !maskUniforms)
2330 2406 {
2331 this.#syncLitSprite(overlay, darkness, flashStrength, wade, tintColor);
2407 this.#syncLitSprite(overlay, darkness, flashStrength, wade, tintColor, flashRgb);
2332 2408 return;
2333 2409 }
2334 2410 overlay._lit = true;
@@ -2343,6 +2419,7 @@ export class WorldView
2343 2419 overlay.renderer.shaderUniforms = {
2344 2420 u_darkness: dark,
2345 2421 u_strength: flash,
2422 u_flashColor: flashRgb,
2346 2423 u_wade: wade ? 1 : 0,
2347 2424 u_spriteHeight: height,
2348 2425 u_useTint: 1,
@@ -2356,6 +2433,7 @@ export class WorldView
2356 2433 overlay.renderer.shaderUniforms = {
2357 2434 u_darkness: dark,
2358 2435 u_strength: flash,
2436 u_flashColor: flashRgb,
2359 2437 u_wade: wade ? 1 : 0,
2360 2438 u_spriteHeight: height,
2361 2439 ...maskUniforms
@@ -2363,7 +2441,7 @@ export class WorldView
2363 2441 }
2364 2442 }
2365 2443
2366 #syncDualTintLitSprite (object, darkness, dualTint, flashStrength = 0, wade = false)
2444 #syncDualTintLitSprite (object, darkness, dualTint, flashStrength = 0, wade = false, flashColor = null)
2367 2445 {
2368 2446 if (!object?.renderer || object._lit === false || !dualTint)
2369 2447 { return; }
@@ -2378,6 +2456,7 @@ export class WorldView
2378 2456 object.renderer.shaderUniforms = {
2379 2457 u_darkness: dark,
2380 2458 u_strength: flash,
2459 u_flashColor: flashColor ?? FLASH_COLOR_DAMAGE,
2381 2460 u_wade: wade ? 1 : 0,
2382 2461 u_spriteHeight: height,
2383 2462 u_shaftTint: [shaft.r, shaft.g, shaft.b],
@@ -48,6 +48,8 @@ const STACK_SPREAD_LERP_MS = 280;
48/** Hold gather-tool equip overlay slightly past swing interval so it stays visible between swings. */
48/** Hold gather-tool equip overlay slightly past swing interval so it stays visible between swings. */
49const GATHER_TOOL_HOLD_MS = 1100;
49const GATHER_TOOL_HOLD_MS = 1100;
50const DAMAGE_FLASH_MS = 180;
50const DAMAGE_FLASH_MS = 180;
51const FLASH_COLOR_DAMAGE = Object.freeze([1.0, 0.12, 0.12]);
52const FLASH_COLOR_BLOCK = Object.freeze([1.0, 1.0, 1.0]);
51const DAMAGE_FLOAT_MS = 900;
53const DAMAGE_FLOAT_MS = 900;
52const SKILL_LEVEL_FLOAT_MS = 2800;
54const SKILL_LEVEL_FLOAT_MS = 2800;
53/** Projectiles spawn this many sprite-pixels below the caster sprite top. */
55/** Projectiles spawn this many sprite-pixels below the caster sprite top. */
@@ -59,6 +61,7 @@ const SPRITE_LIGHTING_FRAG = [
59 "uniform sampler2D u_texture;",
61 "uniform sampler2D u_texture;",
60 "uniform float u_darkness;",
62 "uniform float u_darkness;",
61 "uniform float u_strength;",
63 "uniform float u_strength;",
64 "uniform vec3 u_flashColor;",
62 "uniform float u_wade;",
65 "uniform float u_wade;",
63 "uniform float u_spriteHeight;",
66 "uniform float u_spriteHeight;",
64 "void main() {",
67 "void main() {",
@@ -71,7 +74,7 @@ const SPRITE_LIGHTING_FRAG = [
71 " rgb = mix(rgb, vec3(0.55, 0.82, 0.98), 0.55);",
74 " rgb = mix(rgb, vec3(0.55, 0.82, 0.98), 0.55);",
72 " }",
75 " }",
73 " rgb = mix(rgb, vec3(0.0), u_darkness);",
76 " rgb = mix(rgb, vec3(0.0), u_darkness);",
74 " rgb = mix(rgb, vec3(1.0, 0.12, 0.12), u_strength);",
77 " rgb = mix(rgb, u_flashColor, u_strength);",
75 " gl_FragColor = vec4(rgb, color.a);",
78 " gl_FragColor = vec4(rgb, color.a);",
76 "}"
79 "}"
77].join("\n");
80].join("\n");
@@ -125,6 +128,7 @@ const TINT_LIT_SPRITE_FRAG = [
125 "uniform sampler2D u_texture;",
128 "uniform sampler2D u_texture;",
126 "uniform float u_darkness;",
129 "uniform float u_darkness;",
127 "uniform float u_strength;",
130 "uniform float u_strength;",
131 "uniform vec3 u_flashColor;",
128 "uniform float u_wade;",
132 "uniform float u_wade;",
129 "uniform float u_spriteHeight;",
133 "uniform float u_spriteHeight;",
130 "uniform float u_useTint;",
134 "uniform float u_useTint;",
@@ -147,7 +151,7 @@ const TINT_LIT_SPRITE_FRAG = [
147 " rgb = mix(rgb, vec3(0.55, 0.82, 0.98), 0.55);",
151 " rgb = mix(rgb, vec3(0.55, 0.82, 0.98), 0.55);",
148 " }",
152 " }",
149 " rgb = mix(rgb, vec3(0.0), u_darkness);",
153 " rgb = mix(rgb, vec3(0.0), u_darkness);",
150 " rgb = mix(rgb, vec3(1.0, 0.12, 0.12), u_strength);",
154 " rgb = mix(rgb, u_flashColor, u_strength);",
151 " gl_FragColor = vec4(rgb, color.a);",
155 " gl_FragColor = vec4(rgb, color.a);",
152 "}"
156 "}"
153].join("\n");
157].join("\n");
@@ -160,6 +164,7 @@ const DUAL_TINT_LIT_SPRITE_FRAG = [
160 "uniform sampler2D u_texture;",
164 "uniform sampler2D u_texture;",
161 "uniform float u_darkness;",
165 "uniform float u_darkness;",
162 "uniform float u_strength;",
166 "uniform float u_strength;",
167 "uniform vec3 u_flashColor;",
163 "uniform float u_wade;",
168 "uniform float u_wade;",
164 "uniform float u_spriteHeight;",
169 "uniform float u_spriteHeight;",
165 "uniform vec3 u_shaftTint;",
170 "uniform vec3 u_shaftTint;",
@@ -200,7 +205,7 @@ const DUAL_TINT_LIT_SPRITE_FRAG = [
200 " rgb = mix(rgb, vec3(0.55, 0.82, 0.98), 0.55);",
205 " rgb = mix(rgb, vec3(0.55, 0.82, 0.98), 0.55);",
201 " }",
206 " }",
202 " rgb = mix(rgb, vec3(0.0), u_darkness);",
207 " rgb = mix(rgb, vec3(0.0), u_darkness);",
203 " rgb = mix(rgb, vec3(1.0, 0.12, 0.12), u_strength);",
208 " rgb = mix(rgb, u_flashColor, u_strength);",
204 " gl_FragColor = vec4(rgb, color.a);",
209 " gl_FragColor = vec4(rgb, color.a);",
205 "}"
210 "}"
206].join("\n");
211].join("\n");
@@ -246,6 +251,7 @@ const TIGHT_FIT_TINT_LIT_SPRITE_FRAG = [
246 "uniform sampler2D u_secondary;",
251 "uniform sampler2D u_secondary;",
247 "uniform float u_darkness;",
252 "uniform float u_darkness;",
248 "uniform float u_strength;",
253 "uniform float u_strength;",
254 "uniform vec3 u_flashColor;",
249 "uniform float u_wade;",
255 "uniform float u_wade;",
250 "uniform float u_spriteHeight;",
256 "uniform float u_spriteHeight;",
251 "uniform float u_useTint;",
257 "uniform float u_useTint;",
@@ -269,7 +275,7 @@ const TIGHT_FIT_TINT_LIT_SPRITE_FRAG = [
269 " rgb = mix(rgb, vec3(0.55, 0.82, 0.98), 0.55);",
275 " rgb = mix(rgb, vec3(0.55, 0.82, 0.98), 0.55);",
270 " }",
276 " }",
271 " rgb = mix(rgb, vec3(0.0), u_darkness);",
277 " rgb = mix(rgb, vec3(0.0), u_darkness);",
272 " rgb = mix(rgb, vec3(1.0, 0.12, 0.12), u_strength);",
278 " rgb = mix(rgb, u_flashColor, u_strength);",
273 " float alpha = min(tightFitBodyAlpha(), color.a);",
279 " float alpha = min(tightFitBodyAlpha(), color.a);",
274 " if (alpha <= 0.0) { discard; }",
280 " if (alpha <= 0.0) { discard; }",
275 " gl_FragColor = vec4(rgb, alpha);",
281 " gl_FragColor = vec4(rgb, alpha);",
@@ -284,6 +290,7 @@ const TIGHT_FIT_LIT_SPRITE_FRAG = [
284 "uniform sampler2D u_secondary;",
290 "uniform sampler2D u_secondary;",
285 "uniform float u_darkness;",
291 "uniform float u_darkness;",
286 "uniform float u_strength;",
292 "uniform float u_strength;",
293 "uniform vec3 u_flashColor;",
287 "uniform float u_wade;",
294 "uniform float u_wade;",
288 "uniform float u_spriteHeight;",
295 "uniform float u_spriteHeight;",
289 TIGHT_FIT_BODY_MASK_GLSL,
296 TIGHT_FIT_BODY_MASK_GLSL,
@@ -297,7 +304,7 @@ const TIGHT_FIT_LIT_SPRITE_FRAG = [
297 " rgb = mix(rgb, vec3(0.55, 0.82, 0.98), 0.55);",
304 " rgb = mix(rgb, vec3(0.55, 0.82, 0.98), 0.55);",
298 " }",
305 " }",
299 " rgb = mix(rgb, vec3(0.0), u_darkness);",
306 " rgb = mix(rgb, vec3(0.0), u_darkness);",
300 " rgb = mix(rgb, vec3(1.0, 0.12, 0.12), u_strength);",
307 " rgb = mix(rgb, u_flashColor, u_strength);",
301 " float alpha = min(tightFitBodyAlpha(), color.a);",
308 " float alpha = min(tightFitBodyAlpha(), color.a);",
302 " if (alpha <= 0.0) { discard; }",
309 " if (alpha <= 0.0) { discard; }",
303 " gl_FragColor = vec4(rgb, alpha);",
310 " gl_FragColor = vec4(rgb, alpha);",
@@ -759,11 +766,53 @@ export class WorldView
759 }
766 }
760
767
761 flashDamage (entityId)
768 flashDamage (entityId)
769 {
770 this.#flashEntity(entityId, FLASH_COLOR_DAMAGE);
771 }
772
773 flashBlock (entityId)
774 {
775 this.#flashEntity(entityId, FLASH_COLOR_BLOCK);
776 }
777
778 #flashEntity (entityId, color)
762 {
779 {
763 const entity = this.entities.get(entityId);
780 const entity = this.entities.get(entityId);
764 if (!entity)
781 if (!entity)
765 { return; }
782 { return; }
766 entity.damageFlashUntil = performance.now() + DAMAGE_FLASH_MS;
783 entity.damageFlashUntil = performance.now() + DAMAGE_FLASH_MS;
784 entity.damageFlashColor = color ?? FLASH_COLOR_DAMAGE;
785 }
786
787 /** Target knocks back away from attacker (hit). */
788 spawnCombatKnockback (payload)
789 {
790 const attacker = this.entities.get(payload?.attackerId);
791 const target = this.entities.get(payload?.targetId);
792 if (!attacker || !target)
793 { return; }
794 const ax = attacker.visualX + (attacker.stackOffsetX ?? 0);
795 const ay = attacker.visualY + (attacker.stackOffsetY ?? 0);
796 const tx = target.visualX + (target.stackOffsetX ?? 0);
797 const ty = target.visualY + (target.stackOffsetY ?? 0);
798 this.#applyShoveInDirection(target, tx - ax, ty - ay);
799 }
800
801 /** Target sidesteps perpendicular to the attack (dodge / miss). */
802 spawnCombatDodge (payload)
803 {
804 const attacker = this.entities.get(payload?.attackerId);
805 const target = this.entities.get(payload?.targetId);
806 if (!attacker || !target)
807 { return; }
808 const ax = attacker.visualX + (attacker.stackOffsetX ?? 0);
809 const ay = attacker.visualY + (attacker.stackOffsetY ?? 0);
810 const tx = target.visualX + (target.stackOffsetX ?? 0);
811 const ty = target.visualY + (target.stackOffsetY ?? 0);
812 const dx = tx - ax;
813 const dy = ty - ay;
814 const side = Math.random() < 0.5 ? 1 : -1;
815 this.#applyShoveInDirection(target, -dy * side, dx * side);
767 }
816 }
768
817
769 spawnDamageNumber (entityId, damage)
818 spawnDamageNumber (entityId, damage)
@@ -999,6 +1048,7 @@ export class WorldView
999 uniforms = {
1048 uniforms = {
1000 u_darkness: 0,
1049 u_darkness: 0,
1001 u_strength: 0,
1050 u_strength: 0,
1051 u_flashColor: FLASH_COLOR_DAMAGE,
1002 u_wade: 0,
1052 u_wade: 0,
1003 u_spriteHeight: height,
1053 u_spriteHeight: height,
1004 u_shaftTint: [shaft.r, shaft.g, shaft.b],
1054 u_shaftTint: [shaft.r, shaft.g, shaft.b],
@@ -1016,6 +1066,7 @@ export class WorldView
1016 uniforms = {
1066 uniforms = {
1017 u_darkness: 0,
1067 u_darkness: 0,
1018 u_strength: 0,
1068 u_strength: 0,
1069 u_flashColor: FLASH_COLOR_DAMAGE,
1019 u_wade: 0,
1070 u_wade: 0,
1020 u_spriteHeight: height,
1071 u_spriteHeight: height,
1021 u_useTint: 1,
1072 u_useTint: 1,
@@ -1029,6 +1080,7 @@ export class WorldView
1029 uniforms = {
1080 uniforms = {
1030 u_darkness: 0,
1081 u_darkness: 0,
1031 u_strength: 0,
1082 u_strength: 0,
1083 u_flashColor: FLASH_COLOR_DAMAGE,
1032 u_wade: 0,
1084 u_wade: 0,
1033 u_spriteHeight: height,
1085 u_spriteHeight: height,
1034 ...maskUniforms
1086 ...maskUniforms
@@ -1041,6 +1093,7 @@ export class WorldView
1041 uniforms = {
1093 uniforms = {
1042 u_darkness: 0,
1094 u_darkness: 0,
1043 u_strength: 0,
1095 u_strength: 0,
1096 u_flashColor: FLASH_COLOR_DAMAGE,
1044 u_wade: 0,
1097 u_wade: 0,
1045 u_spriteHeight: height,
1098 u_spriteHeight: height,
1046 u_useTint: 1,
1099 u_useTint: 1,
@@ -1053,6 +1106,7 @@ export class WorldView
1053 uniforms = {
1106 uniforms = {
1054 u_darkness: 0,
1107 u_darkness: 0,
1055 u_strength: 0,
1108 u_strength: 0,
1109 u_flashColor: FLASH_COLOR_DAMAGE,
1056 u_wade: 0,
1110 u_wade: 0,
1057 u_spriteHeight: height
1111 u_spriteHeight: height
1058 };
1112 };
@@ -1467,6 +1521,21 @@ export class WorldView
1467 };
1521 };
1468 }
1522 }
1469
1523
1524 #applyShoveInDirection (entity, dirX, dirY)
1525 {
1526 const len = Math.hypot(dirX, dirY);
1527 if (len < 1e-4)
1528 { return; }
1529 const tileSize = this.tileSize();
1530 const ux = dirX / len;
1531 const uy = dirY / len;
1532 this.#applyShove(
1533 entity,
1534 entity.visualX + ux * tileSize,
1535 entity.visualY + uy * tileSize
1536 );
1537 }
1538
1470 /** Physical combat FX (melee swipes, ranged projectiles). Magic spells stay unshaded. */
1539 /** Physical combat FX (melee swipes, ranged projectiles). Magic spells stay unshaded. */
1471 spawnPhysicalProjectileFx (payload)
1540 spawnPhysicalProjectileFx (payload)
1472 {
1541 {
@@ -2174,11 +2243,12 @@ export class WorldView
2174 const flashStrength = (entity.damageFlashUntil ?? 0) > now
2243 const flashStrength = (entity.damageFlashUntil ?? 0) > now
2175 ? (entity.damageFlashUntil - now) / DAMAGE_FLASH_MS
2244 ? (entity.damageFlashUntil - now) / DAMAGE_FLASH_MS
2176 : 0;
2245 : 0;
2246 const flashColor = entity.damageFlashColor ?? FLASH_COLOR_DAMAGE;
2177 const tileShade = this.#entityShadeAlpha(entity, now);
2247 const tileShade = this.#entityShadeAlpha(entity, now);
2178 const wade = isWadeGroundInSeason(this.#groundTypeAt(entity.tileX, entity.tileY), this.worldSeason);
2248 const wade = isWadeGroundInSeason(this.#groundTypeAt(entity.tileX, entity.tileY), this.worldSeason);
2179
2249
2180 entity.object.transform.rotation = walkTilt;
2250 entity.object.transform.rotation = walkTilt;
2181 this.#syncLitSprite(entity.object, tileShade, flashStrength, wade, entity.bodyTint ?? null);
2251 this.#syncLitSprite(entity.object, tileShade, flashStrength, wade, entity.bodyTint ?? null, flashColor);
2182 this.#placePivoted(entity.object, pivotX, pivotY, pivotY, SORT_ENTITY, entity.visualScale ?? 1);
2252 this.#placePivoted(entity.object, pivotX, pivotY, pivotY, SORT_ENTITY, entity.visualScale ?? 1);
2183 for (let index = 0; index < (entity.overlays ?? []).length; index++)
2253 for (let index = 0; index < (entity.overlays ?? []).length; index++)
2184 {
2254 {
@@ -2188,7 +2258,7 @@ export class WorldView
2188 const dualTint = entity.overlayDualTints?.[index] ?? null;
2258 const dualTint = entity.overlayDualTints?.[index] ?? null;
2189 if (dualTint)
2259 if (dualTint)
2190 {
2260 {
2191 this.#syncDualTintLitSprite(overlay, tileShade, dualTint, flashStrength, wade);
2261 this.#syncDualTintLitSprite(overlay, tileShade, dualTint, flashStrength, wade, flashColor);
2192 }
2262 }
2193 else if (entity.overlayTightFit?.[index])
2263 else if (entity.overlayTightFit?.[index])
2194 {
2264 {
@@ -2198,12 +2268,13 @@ export class WorldView
2198 tileShade,
2268 tileShade,
2199 flashStrength,
2269 flashStrength,
2200 wade,
2270 wade,
2201 entity.overlayTints?.[index] ?? null
2271 entity.overlayTints?.[index] ?? null,
2272 flashColor
2202 );
2273 );
2203 }
2274 }
2204 else
2275 else
2205 {
2276 {
2206 this.#syncLitSprite(overlay, tileShade, flashStrength, wade, entity.overlayTints?.[index] ?? null);
2277 this.#syncLitSprite(overlay, tileShade, flashStrength, wade, entity.overlayTints?.[index] ?? null, flashColor);
2207 }
2278 }
2208 this.#placePivoted(overlay, pivotX, pivotY, overlaySortY, SORT_ENTITY, entity.visualScale ?? 1);
2279 this.#placePivoted(overlay, pivotX, pivotY, overlaySortY, SORT_ENTITY, entity.visualScale ?? 1);
2209 }
2280 }
@@ -2224,7 +2295,7 @@ export class WorldView
2224 if (bloomTint)
2295 if (bloomTint)
2225 { this.#syncUnlitTintSprite(overlay, bloomTint); }
2296 { this.#syncUnlitTintSprite(overlay, bloomTint); }
2226 else
2297 else
2227 { this.#syncLitSprite(overlay, tileShade, flashStrength, wade); }
2298 { this.#syncLitSprite(overlay, tileShade, flashStrength, wade, null, flashColor); }
2228 this.#placePivoted(overlay, pivotX, pivotY, pivotY + 0.002, SORT_ENTITY, entity.visualScale ?? 1);
2299 this.#placePivoted(overlay, pivotX, pivotY, pivotY + 0.002, SORT_ENTITY, entity.visualScale ?? 1);
2229 }
2300 }
2230 this.#placeHpBar(entity, pivotX, pivotY);
2301 this.#placeHpBar(entity, pivotX, pivotY);
@@ -2252,6 +2323,7 @@ export class WorldView
2252 object.renderer.shaderUniforms = {
2323 object.renderer.shaderUniforms = {
2253 u_darkness: 0,
2324 u_darkness: 0,
2254 u_strength: 0,
2325 u_strength: 0,
2326 u_flashColor: FLASH_COLOR_DAMAGE,
2255 u_wade: 0,
2327 u_wade: 0,
2256 u_spriteHeight: height,
2328 u_spriteHeight: height,
2257 u_useTint: 1,
2329 u_useTint: 1,
@@ -2260,7 +2332,7 @@ export class WorldView
2260 object.renderer.secondaryMap = null;
2332 object.renderer.secondaryMap = null;
2261 }
2333 }
2262
2334
2263 #syncLitSprite (object, darkness, flashStrength = 0, wade = false, tintColor = null)
2335 #syncLitSprite (object, darkness, flashStrength = 0, wade = false, tintColor = null, flashColor = null)
2264 {
2336 {
2265 if (!object?.renderer || object._lit === false)
2337 if (!object?.renderer || object._lit === false)
2266 { return; }
2338 { return; }
@@ -2268,6 +2340,7 @@ export class WorldView
2268 const dark = Math.min(1, Math.max(0, darkness ?? 0));
2340 const dark = Math.min(1, Math.max(0, darkness ?? 0));
2269 const flash = Math.min(1, Math.max(0, flashStrength ?? 0));
2341 const flash = Math.min(1, Math.max(0, flashStrength ?? 0));
2270 const height = object.renderer.sprite?.height ?? SPRITE_SIZE_PX;
2342 const height = object.renderer.sprite?.height ?? SPRITE_SIZE_PX;
2343 const flashRgb = flashColor ?? FLASH_COLOR_DAMAGE;
2271 const tint = tintColor ? normalizeRgb(tintColor) : null;
2344 const tint = tintColor ? normalizeRgb(tintColor) : null;
2272 if (tint)
2345 if (tint)
2273 {
2346 {
@@ -2275,6 +2348,7 @@ export class WorldView
2275 object.renderer.shaderUniforms = {
2348 object.renderer.shaderUniforms = {
2276 u_darkness: dark,
2349 u_darkness: dark,
2277 u_strength: flash,
2350 u_strength: flash,
2351 u_flashColor: flashRgb,
2278 u_wade: wade ? 1 : 0,
2352 u_wade: wade ? 1 : 0,
2279 u_spriteHeight: height,
2353 u_spriteHeight: height,
2280 u_useTint: 1,
2354 u_useTint: 1,
@@ -2287,6 +2361,7 @@ export class WorldView
2287 object.renderer.shaderUniforms = {
2361 object.renderer.shaderUniforms = {
2288 u_darkness: dark,
2362 u_darkness: dark,
2289 u_strength: flash,
2363 u_strength: flash,
2364 u_flashColor: flashRgb,
2290 u_wade: wade ? 1 : 0,
2365 u_wade: wade ? 1 : 0,
2291 u_spriteHeight: height
2366 u_spriteHeight: height
2292 };
2367 };
@@ -2320,15 +2395,16 @@ export class WorldView
2320 };
2395 };
2321 }
2396 }
2322
2397
2323 #syncTightFitLitSprite (overlay, entity, darkness, flashStrength = 0, wade = false, tintColor = null)
2398 #syncTightFitLitSprite (overlay, entity, darkness, flashStrength = 0, wade = false, tintColor = null, flashColor = null)
2324 {
2399 {
2325 if (!overlay?.renderer || entity?.object?.renderer == null)
2400 if (!overlay?.renderer || entity?.object?.renderer == null)
2326 { return; }
2401 { return; }
2327 const bodyMap = this.#bodySecondaryMap(entity);
2402 const bodyMap = this.#bodySecondaryMap(entity);
2328 const maskUniforms = this.#tightFitMaskUniforms(overlay, entity);
2403 const maskUniforms = this.#tightFitMaskUniforms(overlay, entity);
2404 const flashRgb = flashColor ?? FLASH_COLOR_DAMAGE;
2329 if (!bodyMap || !maskUniforms)
2405 if (!bodyMap || !maskUniforms)
2330 {
2406 {
2331 this.#syncLitSprite(overlay, darkness, flashStrength, wade, tintColor);
2407 this.#syncLitSprite(overlay, darkness, flashStrength, wade, tintColor, flashRgb);
2332 return;
2408 return;
2333 }
2409 }
2334 overlay._lit = true;
2410 overlay._lit = true;
@@ -2343,6 +2419,7 @@ export class WorldView
2343 overlay.renderer.shaderUniforms = {
2419 overlay.renderer.shaderUniforms = {
2344 u_darkness: dark,
2420 u_darkness: dark,
2345 u_strength: flash,
2421 u_strength: flash,
2422 u_flashColor: flashRgb,
2346 u_wade: wade ? 1 : 0,
2423 u_wade: wade ? 1 : 0,
2347 u_spriteHeight: height,
2424 u_spriteHeight: height,
2348 u_useTint: 1,
2425 u_useTint: 1,
@@ -2356,6 +2433,7 @@ export class WorldView
2356 overlay.renderer.shaderUniforms = {
2433 overlay.renderer.shaderUniforms = {
2357 u_darkness: dark,
2434 u_darkness: dark,
2358 u_strength: flash,
2435 u_strength: flash,
2436 u_flashColor: flashRgb,
2359 u_wade: wade ? 1 : 0,
2437 u_wade: wade ? 1 : 0,
2360 u_spriteHeight: height,
2438 u_spriteHeight: height,
2361 ...maskUniforms
2439 ...maskUniforms
@@ -2363,7 +2441,7 @@ export class WorldView
2363 }
2441 }
2364 }
2442 }
2365
2443
2366 #syncDualTintLitSprite (object, darkness, dualTint, flashStrength = 0, wade = false)
2444 #syncDualTintLitSprite (object, darkness, dualTint, flashStrength = 0, wade = false, flashColor = null)
2367 {
2445 {
2368 if (!object?.renderer || object._lit === false || !dualTint)
2446 if (!object?.renderer || object._lit === false || !dualTint)
2369 { return; }
2447 { return; }
@@ -2378,6 +2456,7 @@ export class WorldView
2378 object.renderer.shaderUniforms = {
2456 object.renderer.shaderUniforms = {
2379 u_darkness: dark,
2457 u_darkness: dark,
2380 u_strength: flash,
2458 u_strength: flash,
2459 u_flashColor: flashColor ?? FLASH_COLOR_DAMAGE,
2381 u_wade: wade ? 1 : 0,
2460 u_wade: wade ? 1 : 0,
2382 u_spriteHeight: height,
2461 u_spriteHeight: height,
2383 u_shaftTint: [shaft.r, shaft.g, shaft.b],
2462 u_shaftTint: [shaft.r, shaft.g, shaft.b],