Chevifier / QuestManager

A Quest Manager plugin for making and managing quests in Godot 4
MIT License
145 stars 10 forks source link

_init function in QuestObjects not working #17

Closed Ohtoh04 closed 5 months ago

Ohtoh04 commented 6 months ago

In add_quest function quest dictionary is passed instead of id

func add_quest(quest_name:String,resource:QuestResource=current_resource) -> void:
    var node_data = resource.get_quest_by_name(quest_name)
    player_quests[node_data.quest_id] = node_data.duplicate(true)
    new_quest_added.emit(quest_name)
    active_quest = quest_name
    check_callable_step(node_data.quest_id)
    step_updated.emit(get_current_step(quest_name))
    print(node_data.quest_id)
    var quest_object = QuestObject.new(player_quests[node_data.quest_id]) # we are passing quest dictionary
    active_quest_objects.append(quest_object)

Then in _init function you are trying to iterate through QuestManager.player_quests[quest_id].quest_steps using this dictionary as a key, which leads to this error

Invalid get index '{ "completed": false, "failed": false, "first_step": "1118a2488c", "group": "", "id": "1e3cd6e59f", "meta_data": { "Is Somthing True": false, "funcparams": [] }, "next_id": "1118a2488c", "position": (380, -440), "quest_details": "", "quest_id": "1e3cd6e59f", "quest_name": "ShootEmUp", "quest_rewards": { "money": 1000 }, "quest_steps": { "1118a2488c": { "collected": 0, "complete": false, "details": "Destroy 10 ships", "id": "1118a2488c", "item_name": "Ships", "meta_data": { "funcparams": [] }, "next_id": "e95c4966d1", "position": (619.791, -396.681), "quest_id": "1e3cd6e59f", "required": 10, "size": (240, 231), "step_type": "incremental_step", "type": 2 }, "a5e44c9e14": { "details": "Complete", "id": "a5e44c9e14", "next_id": "", "position": (1260, -420), "size": (115, 85), "step_type": "end", "type": 6 }, "e95c4966d1": { "complete": false, "details": "Survive 5 seconds", "fail_on_timeout": false, "id": "e95c4966d1", "is_count_down": true, "meta_data": { "funcparams": [] }, "next_id": "a5e44c9e14", "position": (960, -500), "quest_id": "1e3cd6e59f", "size": (231, 281), "step_type": "timer_step", "time": 5, "time_minutes": 0, "time_seconds": 5, "total_time": 5, "type": 7 } }, "size": (200, 250), "type": 0 }' (on base: 'Dictionary').

func _init(_quest_id) -> void:
    quest_id = _quest_id
    for step in QuestManager.player_quests[quest_id].quest_steps:
        match step.step_type:
            "action_step":
                var action_step = ActionStep.new(step.id)
                step_objects[step.id] = action_step
                pass
            "incremental_step":
                var inc_step = IncrementalStep.new(step.id)
                step_objects[step.id] = inc_step
            "items_step":
                var item_step = ItemsStep.new(step.id)
                step_objects[step.id] = item_step
            "timer_step":
                var timer_step = ItemsStep.new(step.id)
                step_objects[step.id] = timer_step
            "branch_step":
                var branch_step = ItemsStep.new(step.id)
                step_objects[step.id] = branch_step
            "callable_step":
                var callabe_step = ItemsStep.new(step.id)
                step_objects[step.id] = callabe_step
            "end":
                var end_step = ItemsStep.new(step.id)
                step_objects[step.id] =end_step

Then, if we do quest_id = _quest_id.id instead, iterator assigns only id value of the step inquest_steps instead of a step dictionary

I've changed _init function to this:

func _init(_quest_id) -> void:
    quest_id = _quest_id.id
    print(QuestManager.player_quests[quest_id])
    for step in QuestManager.player_quests[quest_id].quest_steps:
        match QuestManager.player_quests[quest_id].quest_steps[step].step_type:
            "action_step":
                var action_step = ActionStep.new(QuestManager.player_quests[quest_id].quest_steps[step].id)
                step_objects[QuestManager.player_quests[quest_id].quest_steps[step].id] = action_step
                pass
            "incremental_step":
                var inc_step = IncrementalStep.new(QuestManager.player_quests[quest_id].quest_steps[step].id)
                step_objects[QuestManager.player_quests[quest_id].quest_steps[step].id] = inc_step
            "items_step":
                var item_step = ItemsStep.new(QuestManager.player_quests[quest_id].quest_steps[step].id)
                step_objects[QuestManager.player_quests[quest_id].quest_steps[step].id] = item_step
            "timer_step":
                var timer_step = ItemsStep.new(QuestManager.player_quests[quest_id].quest_steps[step].id)
                step_objects[QuestManager.player_quests[quest_id].quest_steps[step].id] = timer_step
            "branch_step":
                var branch_step = ItemsStep.new(QuestManager.player_quests[quest_id].quest_steps[step].id)
                step_objects[QuestManager.player_quests[quest_id].quest_steps[step].id] = branch_step
            "callable_step":
                var callabe_step = ItemsStep.new(QuestManager.player_quests[quest_id].quest_steps[step].id)
                step_objects[QuestManager.player_quests[quest_id].quest_steps[step].id] = callabe_step
            "end":
                var end_step = ItemsStep.new(QuestManager.player_quests[quest_id].quest_steps[step].id)
                step_objects[QuestManager.player_quests[quest_id].quest_steps[step].id] =end_step

It is quite clunky, but it seems to work as intended now

Chevifier commented 5 months ago

Sorry for the late update Ive fixed this issue I had code I was testing that I didn't remove from the main release. Its now fixed with update 0.8.3. The last 3 lines of add quest were for testing quests as class objects instead of dictionaries. Didn't get around to fully implementing it yet. But it will allow tracking quests to be easier using signals directly in each "Quest object step". As noted in #14