Randoloot/scripts/planets/distant_expeditions.gd
2026-10-25 12:34:56 +01:00

42 lines
1.9 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 visit_offer(progress: Resource, profile: Dictionary, source_level: int) -> Dictionary:
var visit := maxi(1, int(progress.visits.get(str(profile.id), 1)))
var visit_profile := profile.duplicate(true)
visit_profile.id = str(profile.id) + ":visit:%d" % visit
visit_profile.seed = int(profile.get("seed", 0)) ^ (visit * 7919)
return offer(visit_profile, source_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 := visit_offer(progress, profile, source_level)
if progress.hermit_purchases.has(str(map.id)) or captain.credits < map_cost(map): return false
captain.credits -= map_cost(map)
progress.hermit_purchases[str(map.id)] = true
progress.distant_maps[str(map.id)] = map.duplicate(true)
captain.emit_changed()
progress.emit_changed()
return true