47 lines
2.2 KiB
GDScript
47 lines
2.2 KiB
GDScript
extends RefCounted
|
|
const CHANCE := 0.70
|
|
const CRYSTALS_PER_LEVEL := 10
|
|
const AFFIXES := preload("res://resources/items/affix_database.tres")
|
|
|
|
static func has_engineer(profile: Dictionary) -> bool:
|
|
var rng := RandomNumberGenerator.new()
|
|
rng.seed = int(profile.get("seed",0)) ^ str(profile.get("id","")).hash() ^ 0x54494d45
|
|
return rng.randf() < CHANCE
|
|
|
|
static func cost(item: ItemInstance) -> int:
|
|
return maxi(1,item.item_level)*CRYSTALS_PER_LEVEL if item != null else 0
|
|
|
|
static func affix_for(item: ItemInstance, addon: int) -> ItemAffixDefinition:
|
|
if item == null or item.definition == null or addon < 0 or addon >= item.additional_modifiers.size(): return null
|
|
var modifier: ItemStatModifier = item.additional_modifiers[addon]
|
|
if modifier == null: return null
|
|
if modifier.affix != null: return modifier.affix
|
|
for candidate in AFFIXES.affixes:
|
|
if candidate != null and candidate.stat_key == modifier.stat_key and candidate.can_roll(item.definition,item.item_level): return candidate
|
|
return null
|
|
|
|
static func maximum(item: ItemInstance, addon: int) -> float:
|
|
var affix := affix_for(item,addon)
|
|
return affix.get_value_range(item.item_level).y if affix != null else 0.0
|
|
|
|
static func can_maximize(item: ItemInstance, addon: int) -> bool:
|
|
var affix := affix_for(item,addon)
|
|
if affix == null: return false
|
|
return item.additional_modifiers[addon].value < maximum(item,addon) - 0.000001
|
|
|
|
static func maximize(progress: Resource, inventory: Node, item: ItemInstance, addon: int) -> bool:
|
|
if not progress.active or inventory == null or not bool(inventory.get_parent().get("is_docked")): return false
|
|
if not can_maximize(item,addon) or progress.time_crystals < cost(item): return false
|
|
var owned: Array = inventory.cargo + inventory.weapon_slots + inventory.module_slots + inventory.extension_slots
|
|
if not owned.has(item): return false
|
|
var modifier := item.additional_modifiers[addon].duplicate() as ItemStatModifier
|
|
modifier.affix = affix_for(item,addon)
|
|
modifier.value = maximum(item,addon)
|
|
item.additional_modifiers[addon] = modifier
|
|
progress.time_crystals -= cost(item)
|
|
item.emit_changed()
|
|
inventory.call("_recalculate_ship_stats")
|
|
inventory.inventory_changed.emit()
|
|
progress.emit_changed()
|
|
return true
|