Randoloot/scripts/planets/distant_expeditions.gd
2026-10-20 20:32:50 +02:00

34 lines
1.5 KiB
GDScript

extends RefCounted
const HERMIT_CHANCE := 0.70
const CREDITS_PER_LEVEL := 1000
const DEUTER_PER_LEVEL := 1000
static func roll(profile: Dictionary, salt: int) -> RandomNumberGenerator:
var rng := RandomNumberGenerator.new()
rng.seed = int(profile.get("seed", 0)) ^ str(profile.get("id", "")).hash() ^ salt
return rng
static func has_hermit(profile: Dictionary) -> bool:
return roll(profile, 0x4845524d).randf() < HERMIT_CHANCE
static func offer(profile: Dictionary, source_level: int) -> Dictionary:
# No upper cap: expedition planets can continue the chain beyond level 120.
var level := maxi(1, source_level) + roll(profile, 0x4d415053).randi_range(1, 5)
return {"id":str(profile.id)+":distant_map", "level":level, "seed":roll(profile, 0x44495354).randi(), "source_level":maxi(1,source_level), "source_planet":str(profile.get("name","Nieznana planeta")), "name":"Odległy sektor %03d" % level}
static func map_cost(map: Dictionary) -> int:
return maxi(1, int(map.level)) * CREDITS_PER_LEVEL
static func fuel_cost(map: Dictionary) -> int:
return maxi(1, int(map.level)) * DEUTER_PER_LEVEL
static func buy(progress: Resource, captain: Resource, profile: Dictionary, source_level: int) -> bool:
if not has_hermit(profile): return false
var map := offer(profile, source_level)
if progress.distant_maps.has(str(map.id)) or captain.credits < map_cost(map): return false
captain.credits -= map_cost(map)
progress.distant_maps[str(map.id)] = map.duplicate(true)
captain.emit_changed()
progress.emit_changed()
return true