80 lines
2.1 KiB
GDScript
80 lines
2.1 KiB
GDScript
class_name VillagerOpportunityNote
|
|
extends RefCounted
|
|
|
|
const HELP_PLAYER_ROUTE := &"player_route"
|
|
const HELP_HELPER := &"helper"
|
|
const HELP_UNAVAILABLE := &"unavailable"
|
|
|
|
var has_need := false
|
|
var need_text := ""
|
|
var help_kind: StringName = &""
|
|
var help_text := ""
|
|
|
|
|
|
func _init(
|
|
note_has_need := false,
|
|
note_need_text := "",
|
|
note_help_kind: StringName = &"",
|
|
note_help_text := ""
|
|
) -> void:
|
|
has_need = note_has_need
|
|
need_text = note_need_text
|
|
help_kind = note_help_kind
|
|
help_text = note_help_text
|
|
|
|
|
|
func cache_key() -> String:
|
|
return "%s|%s|%s|%s" % [has_need, need_text, String(help_kind), help_text]
|
|
|
|
|
|
static func derive(
|
|
opportunity: OpportunityStateRecord,
|
|
player_response: OpportunityPlayerResponseResult,
|
|
helper: OpportunityHelperResult,
|
|
helper_npc_name: String,
|
|
storage: StorageStateRecord,
|
|
target_display_name: String,
|
|
resource_display_name: String
|
|
) -> VillagerOpportunityNote:
|
|
if opportunity == null:
|
|
return VillagerOpportunityNote.new()
|
|
var need_text := "The %s needs %s" % [target_display_name, resource_display_name]
|
|
if player_response != null:
|
|
return (
|
|
VillagerOpportunityNote
|
|
. new(
|
|
true,
|
|
need_text,
|
|
HELP_PLAYER_ROUTE,
|
|
"You can help · forage %s to the %s" % [resource_display_name, target_display_name],
|
|
)
|
|
)
|
|
if helper != null:
|
|
return VillagerOpportunityNote.new(
|
|
true,
|
|
need_text,
|
|
HELP_HELPER,
|
|
"%s is bringing %s" % [helper_npc_name, resource_display_name]
|
|
)
|
|
if storage == null:
|
|
return VillagerOpportunityNote.new(
|
|
true, need_text, HELP_UNAVAILABLE, "No storage is within reach right now."
|
|
)
|
|
var remaining := maxf(
|
|
opportunity.get_target_amount() - storage.get_amount(opportunity.get_resource_id()), 0.0
|
|
)
|
|
if remaining <= 0.0:
|
|
return VillagerOpportunityNote.new(
|
|
true,
|
|
need_text,
|
|
HELP_UNAVAILABLE,
|
|
"The %s already has enough %s." % [target_display_name, resource_display_name]
|
|
)
|
|
if storage.get_available_capacity() < remaining:
|
|
return VillagerOpportunityNote.new(
|
|
true, need_text, HELP_UNAVAILABLE, "The %s has no room right now." % target_display_name
|
|
)
|
|
return VillagerOpportunityNote.new(
|
|
true, need_text, HELP_UNAVAILABLE, "No stocked source is in reach right now."
|
|
)
|