extends RefCounted const DURATION := 60.0 const IDS := ["incendiary_missile", "radiation_laser", "artillery_cannon"] const COSTS := { "incendiary_missile":{"iron":45,"sulfur":60,"uranium":30,"copper":12,"mercury":6}, "radiation_laser":{"uranium":60,"aluminium":45,"silicon":18,"copper":12}, "artillery_cannon":{"iron":75,"titanium":45,"nickel":15,"tungsten":10}, } static func definition(id: String) -> ItemDefinition: return load("res://resources/items/%s.tres" % id) as ItemDefinition if id in IDS else null static func ensure_offers(progress: Resource) -> void: if not progress.laboratory_offers.is_empty() or not progress.laboratory_project.is_empty(): return var pool := IDS.duplicate() for id in progress.laboratory_unlocks: pool.erase(id) pool.shuffle() for id in pool.slice(0,3): progress.laboratory_offers.append(id) static func can_start(captain: Resource, id: String) -> bool: var progress: Resource = captain.expedition if progress.freighter_rooms.get("expansion_1","") != "laboratory" or not progress.laboratory_project.is_empty(): return false if id not in progress.laboratory_offers or id not in IDS or progress.laboratory_unlocks.get(id,false): return false for key in COSTS[id]: if int(captain.minerals.get(key,0)) < int(COSTS[id][key]): return false return true static func start(captain: Resource, id: String) -> bool: if not can_start(captain,id): return false for key in COSTS[id]: captain.minerals[key] = int(captain.minerals.get(key,0))-int(COSTS[id][key]) captain.expedition.laboratory_project = id captain.expedition.laboratory_remaining = DURATION captain.emit_changed() captain.expedition.emit_changed() return true static func advance(progress: Resource, delta: float) -> bool: if progress.laboratory_project.is_empty() or delta <= 0.0: return false progress.laboratory_remaining = maxf(0.0,progress.laboratory_remaining-delta) if progress.laboratory_remaining <= 0.00001: progress.laboratory_remaining = 0.0 progress.laboratory_unlocks[progress.laboratory_project] = true progress.laboratory_project = "" progress.laboratory_offers.clear() ensure_offers(progress) progress.emit_changed() return true