feat: generate animal-care quests and render them in the journal
This commit is contained in:
@@ -3,12 +3,77 @@ extends RefCounted
|
||||
|
||||
const PANTRY_STANDING_REWARD := 8.0
|
||||
const WOOD_STANDING_REWARD := 8.0
|
||||
const ANIMAL_CARE_STANDING_REWARD := 6.0
|
||||
|
||||
var quests: Array[PlayerQuestRecord] = []
|
||||
var next_quest_id := 0
|
||||
var standing := PlayerStandingRecord.create()
|
||||
|
||||
|
||||
func consider_animal_care(
|
||||
animal_state: AnimalStateRecord,
|
||||
requester_npc_id: int,
|
||||
current_tick: int,
|
||||
pantry: StorageStateRecord
|
||||
) -> PlayerQuestRecord:
|
||||
if (
|
||||
animal_state == null
|
||||
or requester_npc_id < 0
|
||||
or current_tick < 0
|
||||
or pantry == null
|
||||
or not animal_state.needs_feed()
|
||||
or not animal_state.can_player_feed_animal()
|
||||
):
|
||||
return null
|
||||
var definition := SimulationDefinitions.get_action(SimulationIds.ACTION_FEED_ANIMAL)
|
||||
if (
|
||||
definition == null
|
||||
or not definition.has_completion_cost()
|
||||
or (
|
||||
pantry.get_amount(definition.completion_cost_resource_id)
|
||||
< definition.completion_cost_amount
|
||||
)
|
||||
):
|
||||
return null
|
||||
if _find_open_quest_for_animal(animal_state.get_animal_id()) != null:
|
||||
return null
|
||||
var quest := PlayerQuestRecord.create(
|
||||
next_quest_id,
|
||||
PlayerQuestRecord.NO_OPPORTUNITY,
|
||||
requester_npc_id,
|
||||
SimulationIds.OPPORTUNITY_FEED_HUNGRY_ANIMAL,
|
||||
definition.completion_cost_resource_id,
|
||||
animal_state.get_animal_id(),
|
||||
definition.completion_cost_amount,
|
||||
current_tick,
|
||||
ANIMAL_CARE_STANDING_REWARD,
|
||||
animal_state.get_animal_id()
|
||||
)
|
||||
next_quest_id += 1
|
||||
quests.append(quest)
|
||||
return quest
|
||||
|
||||
|
||||
func on_animal_fed(
|
||||
animal_state: AnimalStateRecord, resolution_event: EconomicEventRecord, current_tick: int
|
||||
) -> Dictionary:
|
||||
if animal_state == null or resolution_event == null:
|
||||
return {}
|
||||
var quest := _find_open_quest_for_animal(animal_state.get_animal_id())
|
||||
if quest == null:
|
||||
return {}
|
||||
var event_id := int(resolution_event.data["event_id"])
|
||||
var actor_id := int(resolution_event.data["actor_id"])
|
||||
if actor_id < 0:
|
||||
if not quest.complete(event_id, current_tick):
|
||||
return {}
|
||||
standing.grant_standing(quest.get_standing_reward(), quest.get_requester_npc_id())
|
||||
return {"quest": quest, "completed": true}
|
||||
if quest.expire(current_tick):
|
||||
return {"quest": quest, "completed": false}
|
||||
return {}
|
||||
|
||||
|
||||
func consider_opportunity_opened(
|
||||
opportunity: OpportunityStateRecord,
|
||||
player_response: OpportunityPlayerResponseResult,
|
||||
@@ -108,6 +173,13 @@ func _find_open_quest_for_opportunity(opportunity_id: int) -> PlayerQuestRecord:
|
||||
return null
|
||||
|
||||
|
||||
func _find_open_quest_for_animal(animal_id: StringName) -> PlayerQuestRecord:
|
||||
for quest in quests:
|
||||
if quest.is_open() and quest.has_animal_target() and quest.get_animal_id() == animal_id:
|
||||
return quest
|
||||
return null
|
||||
|
||||
|
||||
func _standing_reward_for(opportunity: OpportunityStateRecord) -> float:
|
||||
match opportunity.get_opportunity_type():
|
||||
SimulationIds.OPPORTUNITY_RESTOCK_EMPTY_PANTRY:
|
||||
|
||||
Reference in New Issue
Block a user