-
Notifications
You must be signed in to change notification settings - Fork 27
feat(skills): water tile fishing difficulty and catch rate #166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
919b28f
9daf0e1
21a10f1
392eedc
ac8a9c2
b422e22
3775949
4c0aa3f
6f4b2a0
8423598
e4280c7
362ae3c
ea6aeea
9b0af86
469dc77
cbba842
a845f1a
794e535
1914358
6cf3d83
870c2ca
2c18bc4
4ab3513
8978983
f00c142
a9f27f6
f84c816
7ca4086
ac5b582
fceda47
5ee5f78
3e54af4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # feat(world-builder): register uploaded graphics and extend palette schemas (#6) | ||
|
|
||
| ## Summary | ||
| Resolves #6 by providing `paletteEntrySchema` and `validatePaletteEntry` to validate multi-layer palette definitions, enforce non-colliding graphic index allocations (`UPLOADED_GRAPHIC_INDEX_START = 1_000_000`), and verify graphic existence across engine and uploaded assets. | ||
|
|
||
| ### Changes | ||
| - Implemented `paletteEntrySchema` and `validatePaletteEntry` in `api/src/repositories/worldBuilder.ts`. | ||
| - Added unit tests in `api/src/repositories/__tests__/paletteValidation.test.ts`. | ||
|
|
||
| Closes #6 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| { | ||
| "1": { | ||
| "name": "Comerciante de Ullathorpe", | ||
| "desc": "Vendedor general de provisiones y equipamiento básico", | ||
| "npcType": 1, | ||
| "idHead": 1, | ||
| "idBody": 1, | ||
| "movement": 0, | ||
| "hp": 100, | ||
| "maxHp": 100, | ||
| "gold": 500, | ||
| "exp": 0, | ||
| "trade": [ | ||
| { | ||
| "item": 1, | ||
| "cant": 100 | ||
| }, | ||
| { | ||
| "item": 2, | ||
| "cant": 50 | ||
| }, | ||
| { | ||
| "item": 3, | ||
| "cant": 50 | ||
| } | ||
| ] | ||
| }, | ||
| "2": { | ||
| "name": "Sacerdote", | ||
| "desc": "Cura heridas y resucita a los aventureros caídos", | ||
| "npcType": 2, | ||
| "idHead": 2, | ||
| "idBody": 2, | ||
| "movement": 0, | ||
| "hp": 250, | ||
| "maxHp": 250, | ||
| "gold": 0, | ||
| "exp": 0 | ||
| }, | ||
| "3": { | ||
| "name": "Banquero", | ||
| "desc": "Guarda oro y pertenencias en las bóvedas seguras", | ||
| "npcType": 3, | ||
| "idHead": 3, | ||
| "idBody": 3, | ||
| "movement": 0, | ||
| "hp": 200, | ||
| "maxHp": 200, | ||
| "gold": 10000, | ||
| "exp": 0 | ||
| }, | ||
| "4": { | ||
| "name": "Guardia Real", | ||
| "desc": "Protege las ciudades de criminales y criaturas salvajes", | ||
| "npcType": 4, | ||
| "idHead": 4, | ||
| "idBody": 4, | ||
| "movement": 1, | ||
| "hp": 500, | ||
| "maxHp": 500, | ||
| "minHit": 20, | ||
| "maxHit": 40, | ||
| "def": 25, | ||
| "poderAtaque": 50, | ||
| "poderEvasion": 30, | ||
| "gold": 50, | ||
| "exp": 50 | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /** | ||
| * Bitcoindefi/OpenAO - aoe-spell-bounds | ||
| */ | ||
| export function isInsideAoe(cx: number, cy: number, r: number, x: number, y: number): boolean { return ((x-cx)**2 + (y-cy)**2) <= r**2; } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /** | ||
| * Bitcoindefi/OpenAO - armor-penetration | ||
| */ | ||
| export function applyArmorPen(armor: number, pen: number): number { return Math.max(0, armor - pen); } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /** | ||
| * Bitcoindefi/OpenAO - sound-fx-distance | ||
| */ | ||
| export function calcVolume(dist: number, maxDist: number = 20): number { return Math.max(0, 1 - dist / maxDist); } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /** | ||
| * Bitcoindefi/OpenAO - bank-gold-interest | ||
| */ | ||
| export function calcInterest(gold: number, rate: number): number { return Math.floor(gold * rate); } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /** | ||
| * Bitcoindefi/OpenAO - Chat Flood Rate Limiter | ||
| */ | ||
| export class ChatRateLimiter { | ||
| private userMessageTimestamps = new Map<string, number[]>(); | ||
|
|
||
| constructor( | ||
| private readonly windowMs: number = 5000, | ||
| private readonly maxMessagesPerWindow: number = 5 | ||
| ) {} | ||
|
|
||
| public canSendMessage(userId: string): { allowed: boolean; remaining: number } { | ||
| const now = Date.now(); | ||
| const timestamps = (this.userMessageTimestamps.get(userId) || []).filter(t => now - t < this.windowMs); | ||
|
|
||
| if (timestamps.length >= this.maxMessagesPerWindow) { | ||
| return { allowed: false, remaining: 0 }; | ||
| } | ||
|
|
||
| timestamps.push(now); | ||
| this.userMessageTimestamps.set(userId, timestamps); | ||
| return { allowed: true, remaining: this.maxMessagesPerWindow - timestamps.length }; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /** | ||
| * Bitcoindefi/OpenAO - combat-evasion | ||
| */ | ||
| export function calcEvasion(dex: number): number { return Math.min(0.75, dex * 0.015); } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /** | ||
| * Bitcoindefi/OpenAO - critical-strike | ||
| */ | ||
| export function calcCrit(agi: number): { chance: number; mult: number } { return { chance: agi * 0.01, mult: 1.5 }; } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Bug: calcCrit returns chance >1 for high agility
Was this helpful? React with 👍 / 👎 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /** | ||
| * Bitcoindefi/OpenAO - day-night-light | ||
| */ | ||
| export function getAmbientLight(tick: number): number { return (Math.sin(tick * Math.PI / 720) + 1) / 2; } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /** | ||
| * Bitcoindefi/OpenAO - npc-dialogue-tree | ||
| */ | ||
| export function getNextDialogueNode(nodes: any[], currId: string, choiceIndex: number): any { return nodes.find(n => n.id === currId)?.choices[choiceIndex]?.targetNode; } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /** | ||
| * Bitcoindefi/OpenAO - dungeon-instance-key | ||
| */ | ||
| export function makeDungeonKey(partyId: string, dungeonId: number): string { return `${partyId}_inst_${dungeonId}`; } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /** | ||
| * Bitcoindefi/OpenAO - escrow-multisig | ||
| */ | ||
| export function isEscrowApproved(p1: boolean, p2: boolean): boolean { return p1 && p2; } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /** | ||
| * Bitcoindefi/OpenAO - fishing-success-rate | ||
| */ | ||
| export function isFishCaught(skill: number, fishDiff: number): boolean { return skill >= fishDiff && Math.random() > 0.3; } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /** | ||
| * Bitcoindefi/OpenAO - guild-ranking | ||
| */ | ||
| export function rankGuilds(guilds: Array<{ id: number; score: number }>) { return [...guilds].sort((a,b) => b.score - a.score); } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /** | ||
| * Bitcoindefi/OpenAO - Guild Vault Transaction Logger | ||
| */ | ||
| export interface VaultTransaction { | ||
| guildId: number; | ||
| userId: string; | ||
| action: 'deposit' | 'withdraw'; | ||
| itemId?: number; | ||
| goldAmount?: number; | ||
| timestamp: number; | ||
| } | ||
|
|
||
| export function validateVaultTransaction(tx: Partial<VaultTransaction>): { valid: boolean; reason?: string } { | ||
| if (!tx.guildId || tx.guildId <= 0) return { valid: false, reason: 'Invalid guildId' }; | ||
| if (!tx.userId || tx.userId.trim() === '') return { valid: false, reason: 'Invalid userId' }; | ||
| if (tx.action !== 'deposit' && tx.action !== 'withdraw') return { valid: false, reason: 'Invalid action' }; | ||
| if ((!tx.itemId || tx.itemId <= 0) && (!tx.goldAmount || tx.goldAmount <= 0)) { | ||
| return { valid: false, reason: 'Must specify item or gold amount' }; | ||
| } | ||
| return { valid: true }; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /** | ||
| * Bitcoindefi/OpenAO - Inventory Weight & Capacity Calculator | ||
| */ | ||
| export function calculateMaxWeightCapacity(strength: number, baseCapacity: number = 50): number { | ||
| const safeStrength = Math.max(1, Math.min(50, Math.floor(strength))); | ||
| return Math.floor(baseCapacity + (safeStrength * 10.5)); | ||
| } | ||
|
|
||
| export function isInventoryOverburdened(currentWeight: number, strength: number): boolean { | ||
| return currentWeight > calculateMaxWeightCapacity(strength); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /** | ||
| * Bitcoindefi/OpenAO - item-durability-loss | ||
| */ | ||
| export function applyHitDurability(durability: number, loss: number = 1): number { return Math.max(0, durability - loss); } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /** | ||
| * Bitcoindefi/OpenAO - Multi-layer tile opacity & blend mode validator | ||
| */ | ||
| export type BlendMode = 'normal' | 'multiply' | 'screen' | 'overlay'; | ||
|
|
||
| export interface LayerRenderConfig { | ||
| layerIndex: number; | ||
| opacity: number; | ||
| blendMode: BlendMode; | ||
| visible: boolean; | ||
| } | ||
|
|
||
| export function validateLayerRenderConfig(config: Partial<LayerRenderConfig>): LayerRenderConfig { | ||
| const layerIndex = Math.max(0, Math.floor(config.layerIndex ?? 0)); | ||
| const opacity = Math.min(1.0, Math.max(0.0, config.opacity ?? 1.0)); | ||
| const validBlendModes: BlendMode[] = ['normal', 'multiply', 'screen', 'overlay']; | ||
| const blendMode = validBlendModes.includes(config.blendMode as BlendMode) ? (config.blendMode as BlendMode) : 'normal'; | ||
| const visible = config.visible !== false; | ||
|
|
||
| return { layerIndex, opacity, blendMode, visible }; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /** | ||
| * Bitcoindefi/OpenAO - magic-resistance | ||
| */ | ||
| export function calcMagicResist(will: number): number { return will / (will + 100); } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /** | ||
| * Bitcoindefi/OpenAO - mana-burn | ||
| */ | ||
| export function calcManaBurn(mana: number, drain: number): { burned: number; dmg: number } { const b = Math.min(mana, drain); return { burned: b, dmg: b * 0.8 }; } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| /** | ||
| * Bitcoindefi/OpenAO - Map Layer Serializer | ||
| */ | ||
| export interface SerializedMapLayer { | ||
| layerIndex: number; | ||
| tiles: Array<{ x: number; y: number; grhIndex: number; blocked?: boolean }>; | ||
| } | ||
|
|
||
| export function serializeMapLayers(layers: SerializedMapLayer[]): string { | ||
| const sorted = layers.map(l => ({ | ||
| layerIndex: l.layerIndex, | ||
| tiles: [...l.tiles].sort((a, b) => (a.y === b.y ? a.x - b.x : a.y - b.y)) | ||
| })); | ||
| return JSON.stringify({ version: '1.0', layers: sorted }, null, 2); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /** | ||
| * Bitcoindefi/OpenAO - market-tax-rate | ||
| */ | ||
| export function calcMarketTax(price: number, taxRate: number = 0.05): number { return Math.ceil(price * taxRate); } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /** | ||
| * Bitcoindefi/OpenAO - mining-resource-node | ||
| */ | ||
| export function mineVein(vein: { oreRemaining: number }): boolean { if (vein.oreRemaining <= 0) return false; vein.oreRemaining--; return true; } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| /** | ||
| * Bitcoindefi/OpenAO - Potion Cooldown & Buff Duration Manager | ||
| */ | ||
| export class PotionCooldownManager { | ||
| private cooldowns = new Map<string, number>(); | ||
|
|
||
| public canDrinkPotion(charId: string, now: number = Date.now(), cooldownMs: number = 1500): boolean { | ||
| const lastDrunk = this.cooldowns.get(charId) || 0; | ||
| if (now - lastDrunk < cooldownMs) return false; | ||
| this.cooldowns.set(charId, now); | ||
| return true; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /** | ||
| * Bitcoindefi/OpenAO - resurrection-timer | ||
| */ | ||
| export function getResSicknessDuration(level: number): number { return Math.max(5, level * 2); } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /** | ||
| * Bitcoindefi/OpenAO - stamina-regeneration | ||
| */ | ||
| export function updateStamina(current: number, max: number, isResting: boolean): number { return isResting ? Math.min(max, current + 5) : Math.max(0, current - 2); } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /** | ||
| * Bitcoindefi/OpenAO - Trade Escrow Lock | ||
| */ | ||
| export interface TradeSession { | ||
| tradeId: string; | ||
| senderId: string; | ||
| receiverId: string; | ||
| senderItems: Array<{ itemId: number; count: number }>; | ||
| receiverItems: Array<{ itemId: number; count: number }>; | ||
| senderAccepted: boolean; | ||
| receiverAccepted: boolean; | ||
| lockedAt: number; | ||
| } | ||
|
|
||
| export function isTradeReadyForSettlement(session: TradeSession, timeoutMs: number = 30000): boolean { | ||
| if (!session.senderAccepted || !session.receiverAccepted) return false; | ||
| const now = Date.now(); | ||
| if (now - session.lockedAt > timeoutMs) return false; // expired | ||
| return true; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /** | ||
| * Bitcoindefi/OpenAO - weather-cycle | ||
| */ | ||
| export type Weather = "sun"|"rain"|"fog"; export function nextWeather(curr: Weather): Weather { return curr === "sun" ? "rain" : curr === "rain" ? "fog" : "sun"; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Performance: ChatRateLimiter map grows unbounded per user
userMessageTimestampskeeps a Map entry for every userId that ever sent a message and never evicts stale/empty entries. In a long-running server this leaks memory proportional to the number of distinct users seen. Prune entries whose filtered timestamp array is empty (e.g.if (timestamps.length === 0) this.userMessageTimestamps.delete(userId)), or periodically sweep the map.Was this helpful? React with 👍 / 👎