@aresrpg/aresrpg-sdk
Advanced tools
Comparing version 5.0.22 to 5.0.23
{ | ||
"name": "@aresrpg/aresrpg-sdk", | ||
"version": "5.0.22", | ||
"version": "5.0.23", | ||
"description": "General SDK to interract with AresRPG", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -5,2 +5,4 @@ import alea from 'alea' | ||
const seeded_random = alea('aresrpg') | ||
const get_board_center = board_bounds => { | ||
@@ -102,25 +104,30 @@ const { min: origin, max: end } = board_bounds | ||
export const random_select_items = (items, count) => { | ||
const selected = [] | ||
if (items.length > count) { | ||
const prng = alea('fight_boards') | ||
while (selected.length < count) { | ||
const rand = prng() | ||
const item_index = Math.round(rand * (items.length - 1)) | ||
const item = items[item_index] | ||
if (item) { | ||
selected.push(item) | ||
} else { | ||
console.warn( | ||
`unexpected, selected index: ${item_index}, items: `, | ||
items, | ||
) | ||
} | ||
export function get_fight_start_positions({ | ||
team_1_blocks = [], | ||
team_2_blocks = [], | ||
max_team_size = 0, | ||
}) { | ||
const select_random_blocks = blocks => { | ||
if (blocks.length <= max_team_size) { | ||
console.warn( | ||
`bad input: max_team_size ${max_team_size} must be lower than provided blocks length ${blocks.length}`, | ||
) | ||
return [] | ||
} | ||
} else { | ||
console.warn( | ||
`bad input: argument count ${count} must be higher than provided items length ${items.length} `, | ||
) | ||
return Array.from({ length: max_team_size }, () => { | ||
const index = Math.floor(seeded_random() * blocks.length) | ||
const block = blocks[index] | ||
if (!block) | ||
console.warn(`unexpected, selected index: ${index}, blocks:`, blocks) | ||
return block | ||
}).filter(Boolean) | ||
} | ||
return selected | ||
return { | ||
team_1: select_random_blocks(team_1_blocks), | ||
team_2: select_random_blocks(team_2_blocks), | ||
} | ||
} | ||
@@ -127,0 +134,0 @@ |
@@ -7,7 +7,11 @@ export function iter_board_data(board: any): Generator<{ | ||
}; | ||
data: any; | ||
type: any; | ||
}, void, unknown>; | ||
export function format_board_data(board_element: any): { | ||
materialId: any; | ||
type: any; | ||
export function get_fight_start_positions({ team_1_blocks, team_2_blocks, max_team_size, }: { | ||
team_1_blocks?: any[]; | ||
team_2_blocks?: any[]; | ||
max_team_size?: number; | ||
}): { | ||
team_1: any[]; | ||
team_2: any[]; | ||
}; | ||
@@ -20,3 +24,3 @@ export function extract_border_blocks(board: any): { | ||
}; | ||
data: any; | ||
type: any; | ||
}[]; | ||
@@ -31,4 +35,3 @@ export function find_split_axis(board: any): { | ||
}; | ||
export function random_select_items(items: any, count: any): any[]; | ||
export { LineOfSight } from "./board/line_of_sight.js"; | ||
export { PathFinder } from "./board/path_finder.js"; |
107224
3385