| 1 | import { Component } from "../ecs/components.js"; |
| 2 | import { |
| 3 | BlockType, |
| 4 | GroundType, |
| 5 | isLiquidWaterGround, |
| 6 | normalizeGround |
| 7 | } from "../../../shared/definitions/tiles.js"; |
| 8 | import { |
| 9 | FISH_SPECIES, |
| 10 | fishTierRankFromItemId, |
| 11 | fishingDifficulty, |
| 12 | fishingExhaustDurationMs, |
| 13 | baitItemIdForCloth, |
| 14 | BaitItemId, |
| 15 | normalizeFishingSpotConfig, |
| 16 | fishingPoleItemIdForWood, |
| 17 | woodTierFromFishingRodItemId |
| 18 | } from "../../../shared/definitions/fishItems.js"; |
| 19 | import { resolveFishingTool } from "../../../shared/definitions/gathering.js"; |
| 20 | import { EquipmentKind } from "../../../shared/definitions/equipmentKinds.js"; |
| 21 | import { |
| 22 | ClothTier, |
| 23 | tierRank, |
| 24 | clothTierForWood |
| 25 | } from "../../../shared/definitions/materialTiers.js"; |
| 26 | import { yarnItemId } from "../../../shared/definitions/clothItems.js"; |
| 27 | import { itemDefinition } from "../../../shared/definitions/items.js"; |
| 28 | import { SkillId, skillLevel } from "../../../shared/definitions/skills.js"; |
| 29 | import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js"; |
| 30 | import |
| 31 | { |
| 32 | gatherDurationMultiplier, |
| 33 | harvestYieldMultiplier |
| 34 | } from "../../../shared/equipment/jewelryEffects.js"; |
| 35 | import { rollSkill } from "../../../shared/combat/rolls.js"; |
| 36 | import { |
| 37 | insertStack, |
| 38 | stackQuantity, |
| 39 | takeMatchingFromSlots, |
| 40 | takeFromSlot |
| 41 | } from "../../../shared/items/inventory.js"; |
| 42 | import { attachOrigins, gatherOrigin, GatherOriginVerb } from "../../../shared/items/origin.js"; |
| 43 | import { addGroundItem, publicGroundItem, bagView } from "../items/bags.js"; |
| 44 | import { isAdjacentTile } from "../../../shared/navigation/adjacency.js"; |
| 45 | import { tileToChunk, tileToLocal } from "../world/coordinates.js"; |
| 46 | import { CHUNK_SIZE } from "../../../shared/protocol/constants.js"; |
| 47 | import { tileShoveEvent } from "../simulation/tileInteract.js"; |
| 48 | import { seasonIdAt } from "../../../shared/world/season.js"; |
| 49 | |
| 50 | const FISH_ATTEMPT_MS = 3000; |
| 51 | const FISH_SHOVE_MS = 1000; |
| 52 | const MAX_FISH_ATTEMPTS = 3; |
| 53 | /** Chance the fishing line snaps after a fully failed rod session. */ |
| 54 | const LINE_BREAK_CHANCE = 0.05; |
| 55 | |
| 56 | function userError (message) |
| 57 | { |
| 58 | const error = new Error(message); |
| 59 | error.userFacing = true; |
| 60 | return error; |
| 61 | } |
| 62 | |
| 63 | function tileKey (tileX, tileY) |
| 64 | { |
| 65 | return `${tileX},${tileY}`; |
| 66 | } |
| 67 | |
| 68 | function characterDisplayName (world, handle) |
| 69 | { |
| 70 | const appearance = world.ecs.get(handle, Component.appearance); |
| 71 | const name = [appearance?.firstName, appearance?.lastName].filter(Boolean).join(" ").trim(); |
| 72 | return name || "someone"; |
| 73 | } |
| 74 | |
| 75 | function ensureFishSessions (world) |
| 76 | { |
| 77 | if (!world.fishSessions) |
| 78 | { world.fishSessions = new Map(); } |
| 79 | return world.fishSessions; |
| 80 | } |
| 81 | |
| 82 | function ensureFishSpotRespawns (world) |
| 83 | { |
| 84 | if (!world.fishingSpotRespawns) |
| 85 | { world.fishingSpotRespawns = new Map(); } |
| 86 | return world.fishingSpotRespawns; |
| 87 | } |
| 88 | |
| 89 | function clearFishSession (world, characterId) |
| 90 | { |
| 91 | ensureFishSessions(world).delete(characterId); |
| 92 | } |
| 93 | |
| 94 | function blockAt (world, tileX, tileY) |
| 95 | { |
| 96 | const data = world.chunkData(tileToChunk(tileX), tileToChunk(tileY)); |
| 97 | const index = tileToLocal(tileY) * CHUNK_SIZE + tileToLocal(tileX); |
| 98 | return data.blocks[index] ?? null; |
| 99 | } |
| 100 | |
| 101 | function groundAt (world, tileX, tileY) |
| 102 | { |
| 103 | const data = world.chunkData(tileToChunk(tileX), tileToChunk(tileY)); |
| 104 | const index = tileToLocal(tileY) * CHUNK_SIZE + tileToLocal(tileX); |
| 105 | return normalizeGround(data.grounds[index]).typeId; |
| 106 | } |
| 107 | |
| 108 | function setBlockState (world, tileX, tileY, state) |
| 109 | { |
| 110 | const chunkX = tileToChunk(tileX); |
| 111 | const chunkY = tileToChunk(tileY); |
| 112 | const localX = tileToLocal(tileX); |
| 113 | const localY = tileToLocal(tileY); |
| 114 | const data = world.chunkData(chunkX, chunkY); |
| 115 | const index = localY * CHUNK_SIZE + localX; |
| 116 | const existing = data.blocks[index]; |
| 117 | if (!existing) |
| 118 | { return null; } |
| 119 | const block = { ...existing, state }; |
| 120 | data.blocks[index] = block; |
| 121 | return { |
| 122 | type: "chunk-delta", |
| 123 | chunkX, |
| 124 | chunkY, |
| 125 | tileX, |
| 126 | tileY, |
| 127 | localX, |
| 128 | localY, |
| 129 | block |
| 130 | }; |
| 131 | } |
| 132 | |
| 133 | function spotFishItemIds (block) |
| 134 | { |
| 135 | return normalizeFishingSpotConfig(block?.config).fishes; |
| 136 | } |
| 137 | |
| 138 | function maxFishTierInList (fishItemIds) |
| 139 | { |
| 140 | let max = 0; |
| 141 | for (const itemId of fishItemIds) |
| 142 | { max = Math.max(max, fishTierRankFromItemId(itemId)); } |
| 143 | return max; |
| 144 | } |
| 145 | |
| 146 | function eligibleFishItemIds (fishItemIds, baitTierRank) |
| 147 | { |
| 148 | return fishItemIds.filter((itemId) => fishTierRankFromItemId(itemId) <= baitTierRank); |
| 149 | } |
| 150 | |
| 151 | function findBestBaitSlot (slots, maxRank) |
| 152 | { |
| 153 | let best = null; |
| 154 | for (let i = 0; i < (slots?.length ?? 0); i++) |
| 155 | { |
| 156 | const slot = slots[i]; |
| 157 | if (!slot || stackQuantity(slot.quantity) <= 0) |
| 158 | { continue; } |
| 159 | const def = itemDefinition(slot.itemId); |
| 160 | if (!def?.bait || !def.tier) |
| 161 | { continue; } |
| 162 | const rank = tierRank(def.tier); |
| 163 | if (rank < 1 || rank > maxRank) |
| 164 | { continue; } |
| 165 | if (!best || rank > best.rank) |
| 166 | { best = { slotIndex: i, itemId: slot.itemId, rank, tier: def.tier }; } |
| 167 | } |
| 168 | return best; |
| 169 | } |
| 170 | |
| 171 | function toolTierRank (tool) |
| 172 | { |
| 173 | const tier = tool?.def?.equipment?.tier ?? tool?.tier; |
| 174 | return tierRank(tier); |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Start fishing at a fishing-spot block tile. |
| 179 | */ |
| 180 | export function startFish (world, sessionId, characterId, tileX, tileY, now = Date.now()) |
| 181 | { |
| 182 | const entityId = world.characterEntities.get(characterId); |
| 183 | if (entityId == null) |
| 184 | { throw userError("Character is not in the world."); } |
| 185 | const handle = world.ecs.handleOf(entityId); |
| 186 | const identity = world.ecs.get(handle, Component.networkIdentity); |
| 187 | if (!identity || identity.sessionId !== sessionId) |
| 188 | { throw userError("Character is not in the world."); } |
| 189 | if (world.ecs.has(handle, Component.dead)) |
| 190 | { throw userError("You are dead."); } |
| 191 | |
| 192 | const position = world.ecs.get(handle, Component.position); |
| 193 | if (!isAdjacentTile(position.tileX, position.tileY, tileX, tileY)) |
| 194 | { throw userError("You need to stand next to the fishing spot."); } |
| 195 | |
| 196 | const block = blockAt(world, tileX, tileY); |
| 197 | if (!block || block.typeId !== BlockType.fishingSpot) |
| 198 | { throw userError("There is no fishing spot there."); } |
| 199 | if (block.state === "exhausted" || ensureFishSpotRespawns(world).has(tileKey(tileX, tileY))) |
| 200 | { throw userError("The fish have scattered. Wait for them to return."); } |
| 201 | |
| 202 | const ground = groundAt(world, tileX, tileY); |
| 203 | const season = seasonIdAt(now); |
| 204 | if (ground !== GroundType.water && ground !== GroundType.deepWater) |
| 205 | { throw userError("Fishing spots must be on water."); } |
| 206 | if (!isLiquidWaterGround(ground, season)) |
| 207 | { throw userError("The water is frozen solid."); } |
| 208 | |
| 209 | const fishList = spotFishItemIds(block); |
| 210 | if (!fishList.length) |
| 211 | { throw userError("No fish swim here."); } |
| 212 | |
| 213 | const inventory = world.ecs.get(handle, Component.inventory); |
| 214 | const equipment = world.ecs.get(handle, Component.equipment); |
| 215 | const skills = world.ecs.get(handle, Component.skills); |
| 216 | const resolved = resolveFishingTool({ |
| 217 | inventorySlots: inventory?.slots, |
| 218 | equipmentSlots: equipment?.slots, |
| 219 | skills |
| 220 | }); |
| 221 | if (!resolved.ok) |
| 222 | { throw userError(resolved.reason); } |
| 223 | |
| 224 | const isNet = resolved.kind === EquipmentKind.fishingNet; |
| 225 | const rodRank = isNet ? 1 : toolTierRank(resolved.tool); |
| 226 | const maxInSpot = maxFishTierInList(fishList); |
| 227 | const usefulMax = Math.min(rodRank, maxInSpot); |
| 228 | |
| 229 | let baitRank = 1; |
| 230 | let baitItemId = null; |
| 231 | let baitConsumedRank = 0; |
| 232 | |
| 233 | if (isNet) |
| 234 | { |
| 235 | baitRank = 1; |
| 236 | baitConsumedRank = 0; |
| 237 | } |
| 238 | else |
| 239 | { |
| 240 | const bait = findBestBaitSlot(inventory?.slots, usefulMax); |
| 241 | if (!bait) |
| 242 | { throw userError("You need suitable bait for this spot."); } |
| 243 | baitRank = bait.rank; |
| 244 | baitItemId = bait.itemId; |
| 245 | baitConsumedRank = bait.rank; |
| 246 | } |
| 247 | |
| 248 | const eligible = eligibleFishItemIds(fishList, baitRank); |
| 249 | if (!eligible.length) |
| 250 | { throw userError("No fish here match your bait."); } |
| 251 | |
| 252 | if (!isNet) |
| 253 | { |
| 254 | const taken = takeMatchingFromSlots(inventory.slots, { |
| 255 | itemId: baitItemId, |
| 256 | quantity: 1, |
| 257 | compact: false |
| 258 | }); |
| 259 | if (!taken.ok) |
| 260 | { throw userError("You need suitable bait for this spot."); } |
| 261 | inventory.slots = taken.slots; |
| 262 | } |
| 263 | |
| 264 | clearFishSession(world, characterId); |
| 265 | if (world.ecs.has(handle, Component.gather)) |
| 266 | { world.ecs.remove(handle, Component.gather); } |
| 267 | const path = world.ecs.get(handle, Component.path); |
| 268 | if (path) |
| 269 | { path.tiles = []; } |
| 270 | |
| 271 | ensureFishSessions(world).set(characterId, { |
| 272 | sessionId, |
| 273 | tileX, |
| 274 | tileY, |
| 275 | toolItemId: resolved.tool.def.itemId, |
| 276 | isNet, |
| 277 | baitRank, |
| 278 | baitConsumedRank, |
| 279 | baitItemId, |
| 280 | eligible, |
| 281 | difficulty: fishingDifficulty(baitRank), |
| 282 | attemptsLeft: MAX_FISH_ATTEMPTS, |
| 283 | attemptStartedAt: now, |
| 284 | nextShoveAt: now, |
| 285 | attemptEndsAt: now + Math.max( |
| 286 | 1, |
| 287 | Math.floor(FISH_ATTEMPT_MS * gatherDurationMultiplier(equipment)) |
| 288 | ) |
| 289 | }); |
| 290 | |
| 291 | return { |
| 292 | events: [], |
| 293 | private: isNet ? null : bagView(world.ecs, handle) |
| 294 | }; |
| 295 | } |
| 296 | |
| 297 | export function handleFishingCommand (world, sessionId, command, now = Date.now()) |
| 298 | { |
| 299 | if (command.type === "start-fish") |
| 300 | { |
| 301 | return startFish( |
| 302 | world, |
| 303 | sessionId, |
| 304 | command.characterId, |
| 305 | command.tileX | 0, |
| 306 | command.tileY | 0, |
| 307 | now |
| 308 | ); |
| 309 | } |
| 310 | if (command.type === "cancel-fish") |
| 311 | { |
| 312 | clearFishSession(world, command.characterId); |
| 313 | return { events: [] }; |
| 314 | } |
| 315 | return null; |
| 316 | } |
| 317 | |
| 318 | function completeCatch (world, handle, entityId, characterId, session, events, privates, now) |
| 319 | { |
| 320 | const eligible = session.eligible ?? []; |
| 321 | if (!eligible.length) |
| 322 | { |
| 323 | events.push({ |
| 324 | type: "command-error", |
| 325 | sessionId: session.sessionId, |
| 326 | message: "The fish got away." |
| 327 | }); |
| 328 | clearFishSession(world, characterId); |
| 329 | return; |
| 330 | } |
| 331 | const rng = world.rng ?? Math.random; |
| 332 | const pick = eligible[Math.floor(rng() * eligible.length) % eligible.length]; |
| 333 | const fishRank = fishTierRankFromItemId(pick); |
| 334 | const inventory = world.ecs.get(handle, Component.inventory); |
| 335 | const def = itemDefinition(pick); |
| 336 | const origin = gatherOrigin(GatherOriginVerb.caught, characterDisplayName(world, handle)); |
| 337 | const quantity = Math.max(1, Math.floor(1 * harvestYieldMultiplier(world.ecs.get(handle, Component.equipment)))); |
| 338 | const stack = attachOrigins({ |
| 339 | itemId: pick, |
| 340 | quantity, |
| 341 | origins: [{ origin, quantity }] |
| 342 | }); |
| 343 | const inserted = insertStack(inventory.slots, stack, def); |
| 344 | if (!inserted.ok || inserted.remainder > 0) |
| 345 | { |
| 346 | events.push({ |
| 347 | type: "command-error", |
| 348 | sessionId: session.sessionId, |
| 349 | message: "Your inventory is full." |
| 350 | }); |
| 351 | clearFishSession(world, characterId); |
| 352 | return; |
| 353 | } |
| 354 | inventory.slots = inserted.slots; |
| 355 | |
| 356 | const xpAmount = (session.baitConsumedRank | 0) + fishRank; |
| 357 | const skills = world.ecs.get(handle, Component.skills); |
| 358 | let skillsChanged = false; |
| 359 | const levelUps = []; |
| 360 | if (skills?.xp && xpAmount > 0) |
| 361 | { |
| 362 | const result = applySkillXp( |
| 363 | skills, |
| 364 | SkillId.fishing, |
| 365 | xpAmount, |
| 366 | world.ecs.get(handle, Component.equipment) |
| 367 | ); |
| 368 | if (result.changed) |
| 369 | { skillsChanged = true; } |
| 370 | if (result.levelUp) |
| 371 | { levelUps.push(result.levelUp); } |
| 372 | } |
| 373 | if (skillsChanged) |
| 374 | { |
| 375 | events.push({ |
| 376 | type: "skills-updated", |
| 377 | entityId, |
| 378 | characterId, |
| 379 | ...publicSkillsPayload(skills), |
| 380 | stored: storedSkillXp(skills), |
| 381 | levelUps |
| 382 | }); |
| 383 | } |
| 384 | |
| 385 | const exhausted = setBlockState(world, session.tileX, session.tileY, "exhausted"); |
| 386 | if (exhausted) |
| 387 | { events.push(exhausted); } |
| 388 | ensureFishSpotRespawns(world).set(tileKey(session.tileX, session.tileY), { |
| 389 | tileX: session.tileX, |
| 390 | tileY: session.tileY, |
| 391 | respawnsAt: now + fishingExhaustDurationMs(fishRank) |
| 392 | }); |
| 393 | |
| 394 | privates.push({ characterId, bag: bagView(world.ecs, handle) }); |
| 395 | events.push({ |
| 396 | type: "item-bubble", |
| 397 | entityId, |
| 398 | itemId: pick, |
| 399 | quantity: 1 |
| 400 | }); |
| 401 | clearFishSession(world, characterId); |
| 402 | } |
| 403 | |
| 404 | export function stepFishing (world, now) |
| 405 | { |
| 406 | const events = []; |
| 407 | const privates = []; |
| 408 | events.push(...stepFishingSpotRespawns(world, now).events); |
| 409 | |
| 410 | const sessions = ensureFishSessions(world); |
| 411 | for (const [characterId, session] of [...sessions.entries()]) |
| 412 | { |
| 413 | const entityId = world.characterEntities.get(characterId); |
| 414 | if (entityId == null) |
| 415 | { |
| 416 | clearFishSession(world, characterId); |
| 417 | continue; |
| 418 | } |
| 419 | const handle = world.ecs.handleOf(entityId); |
| 420 | if (world.ecs.has(handle, Component.dead)) |
| 421 | { |
| 422 | clearFishSession(world, characterId); |
| 423 | continue; |
| 424 | } |
| 425 | const position = world.ecs.get(handle, Component.position); |
| 426 | if (!isAdjacentTile(position.tileX, position.tileY, session.tileX, session.tileY)) |
| 427 | { |
| 428 | clearFishSession(world, characterId); |
| 429 | continue; |
| 430 | } |
| 431 | |
| 432 | if (now >= session.nextShoveAt && now < session.attemptEndsAt) |
| 433 | { |
| 434 | session.nextShoveAt = now + FISH_SHOVE_MS; |
| 435 | events.push(tileShoveEvent( |
| 436 | entityId, |
| 437 | position.tileX, |
| 438 | position.tileY, |
| 439 | session.tileX, |
| 440 | session.tileY |
| 441 | )); |
| 442 | // Also emit gather-swing so tool overlay shows. |
| 443 | events.push({ |
| 444 | type: "gather-swing", |
| 445 | attackerId: entityId, |
| 446 | tileX: session.tileX, |
| 447 | tileY: session.tileY, |
| 448 | fromTileX: position.tileX, |
| 449 | fromTileY: position.tileY, |
| 450 | toolItemId: session.toolItemId, |
| 451 | swipe: false |
| 452 | }); |
| 453 | } |
| 454 | |
| 455 | if (now < session.attemptEndsAt) |
| 456 | { continue; } |
| 457 | |
| 458 | const skills = world.ecs.get(handle, Component.skills); |
| 459 | const level = skillLevel(skills, SkillId.fishing); |
| 460 | const roll = rollSkill(level, world.rng ?? Math.random); |
| 461 | session.attemptsLeft -= 1; |
| 462 | |
| 463 | if (roll >= session.difficulty) |
| 464 | { |
| 465 | completeCatch(world, handle, entityId, characterId, session, events, privates, now); |
| 466 | continue; |
| 467 | } |
| 468 | |
| 469 | if (session.attemptsLeft <= 0) |
| 470 | { |
| 471 | events.push({ |
| 472 | type: "command-error", |
| 473 | sessionId: session.sessionId, |
| 474 | message: "The fish got away." |
| 475 | }); |
| 476 | maybeBreakFishingLine(world, handle, entityId, characterId, session, events, privates, now); |
| 477 | clearFishSession(world, characterId); |
| 478 | continue; |
| 479 | } |
| 480 | |
| 481 | session.attemptStartedAt = now; |
| 482 | session.nextShoveAt = now; |
| 483 | session.attemptEndsAt = now + Math.max( |
| 484 | 1, |
| 485 | Math.floor(FISH_ATTEMPT_MS * gatherDurationMultiplier(world.ecs.get(handle, Component.equipment))) |
| 486 | ); |
| 487 | } |
| 488 | |
| 489 | return { events, privates }; |
| 490 | } |
| 491 | |
| 492 | function spawnGroundStack (world, tileX, tileY, itemId, now, events, source = "fishing-line-break") |
| 493 | { |
| 494 | const groundItemId = (world.nextGroundItemId = (world.nextGroundItemId ?? 1) + 1); |
| 495 | const stack = attachOrigins({ |
| 496 | itemId, |
| 497 | quantity: 1, |
| 498 | origins: [] |
| 499 | }); |
| 500 | const item = { |
| 501 | groundItemId, |
| 502 | tileX, |
| 503 | tileY, |
| 504 | stack, |
| 505 | droppedAt: now, |
| 506 | expiresAt: now + (world.settings?.groundItemDespawnDurationMs ?? 600_000), |
| 507 | source |
| 508 | }; |
| 509 | addGroundItem(world, item); |
| 510 | events.push({ |
| 511 | type: "ground-item-appear", |
| 512 | ...publicGroundItem(item), |
| 513 | stack: item.stack, |
| 514 | droppedAt: item.droppedAt, |
| 515 | source: item.source, |
| 516 | expiresAt: item.expiresAt |
| 517 | }); |
| 518 | } |
| 519 | |
| 520 | /** |
| 521 | * After a fully failed rod session: 5% chance the line snaps → rod becomes pole + 1 yarn. |
| 522 | */ |
| 523 | function maybeBreakFishingLine (world, handle, entityId, characterId, session, events, privates, now) |
| 524 | { |
| 525 | if (session.isNet) |
| 526 | { return; } |
| 527 | const rng = world.rng ?? Math.random; |
| 528 | if (rng() >= LINE_BREAK_CHANCE) |
| 529 | { return; } |
| 530 | |
| 531 | const rodItemId = session.toolItemId | 0; |
| 532 | const rodDef = itemDefinition(rodItemId); |
| 533 | const woodTier = woodTierFromFishingRodItemId(rodItemId) ?? rodDef?.tier; |
| 534 | const poleItemId = rodDef?.poleItemId ?? fishingPoleItemIdForWood(woodTier); |
| 535 | const clothTier = rodDef?.clothTier ?? clothTierForWood(woodTier); |
| 536 | const yarnId = yarnItemId(clothTier); |
| 537 | if (!poleItemId || !yarnId) |
| 538 | { return; } |
| 539 | |
| 540 | const inventory = world.ecs.get(handle, Component.inventory); |
| 541 | const equipment = world.ecs.get(handle, Component.equipment); |
| 542 | let removed = false; |
| 543 | let appearanceChanged = false; |
| 544 | |
| 545 | if (inventory?.slots) |
| 546 | { |
| 547 | const idx = inventory.slots.findIndex((s) => s?.itemId === rodItemId); |
| 548 | if (idx >= 0) |
| 549 | { |
| 550 | const taken = takeFromSlot(inventory.slots, idx, 1); |
| 551 | if (taken.ok) |
| 552 | { |
| 553 | inventory.slots = taken.slots; |
| 554 | removed = true; |
| 555 | } |
| 556 | } |
| 557 | } |
| 558 | if (!removed && equipment?.slots?.weapon?.itemId === rodItemId) |
| 559 | { |
| 560 | equipment.slots.weapon = null; |
| 561 | removed = true; |
| 562 | appearanceChanged = true; |
| 563 | } |
| 564 | if (!removed) |
| 565 | { return; } |
| 566 | |
| 567 | const position = world.ecs.get(handle, Component.position); |
| 568 | const poleDef = itemDefinition(poleItemId); |
| 569 | const yarnDef = itemDefinition(yarnId); |
| 570 | let slots = inventory.slots; |
| 571 | |
| 572 | const poleIns = insertStack(slots, attachOrigins({ itemId: poleItemId, quantity: 1, origins: [] }), poleDef); |
| 573 | if (poleIns.ok && poleIns.remainder === 0) |
| 574 | { slots = poleIns.slots; } |
| 575 | else |
| 576 | { spawnGroundStack(world, position.tileX, position.tileY, poleItemId, now, events); } |
| 577 | |
| 578 | const yarnIns = insertStack(slots, attachOrigins({ itemId: yarnId, quantity: 1, origins: [] }), yarnDef); |
| 579 | if (yarnIns.ok && yarnIns.remainder === 0) |
| 580 | { slots = yarnIns.slots; } |
| 581 | else |
| 582 | { spawnGroundStack(world, position.tileX, position.tileY, yarnId, now, events); } |
| 583 | |
| 584 | inventory.slots = slots; |
| 585 | |
| 586 | events.push({ |
| 587 | type: "command-error", |
| 588 | sessionId: session.sessionId, |
| 589 | message: "Your fishing line broke!" |
| 590 | }); |
| 591 | privates.push({ |
| 592 | characterId, |
| 593 | bag: bagView(world.ecs, handle), |
| 594 | ...(appearanceChanged ? { appearanceChanged: true } : {}) |
| 595 | }); |
| 596 | } |
| 597 | |
| 598 | export function stepFishingSpotRespawns (world, now) |
| 599 | { |
| 600 | const respawns = world.fishingSpotRespawns; |
| 601 | if (!respawns?.size) |
| 602 | { return { events: [] }; } |
| 603 | const events = []; |
| 604 | for (const [key, entry] of [...respawns.entries()]) |
| 605 | { |
| 606 | if (now < entry.respawnsAt) |
| 607 | { continue; } |
| 608 | respawns.delete(key); |
| 609 | const block = blockAt(world, entry.tileX, entry.tileY); |
| 610 | if (!block || block.typeId !== BlockType.fishingSpot) |
| 611 | { continue; } |
| 612 | const delta = setBlockState(world, entry.tileX, entry.tileY, "fishing-spot"); |
| 613 | if (delta) |
| 614 | { events.push(delta); } |
| 615 | } |
| 616 | return { events }; |
| 617 | } |
| 618 | |
| 619 | export { ClothTier, BaitItemId, baitItemIdForCloth, FISH_SPECIES }; |