fixes to make quest tracking work better, also quest rejection in via the converation with the NPC
This commit is contained in:
@@ -601,6 +601,7 @@ def poll_job(session_id: str, job_id: str):
|
||||
nested_result = result.get('result', {})
|
||||
if nested_result.get('context_type') == 'npc_dialogue':
|
||||
# NPC dialogue response - return dialogue partial
|
||||
# Include quest_offer data for inline quest offer card
|
||||
return render_template(
|
||||
'game/partials/npc_dialogue_response.html',
|
||||
npc_name=nested_result.get('npc_name', 'NPC'),
|
||||
@@ -608,6 +609,8 @@ def poll_job(session_id: str, job_id: str):
|
||||
conversation_history=nested_result.get('conversation_history', []),
|
||||
player_line=nested_result.get('player_line', ''),
|
||||
dialogue=nested_result.get('dialogue', 'No response'),
|
||||
quest_offer=nested_result.get('quest_offer'), # Quest offer data for UI card
|
||||
npc_id=nested_result.get('npc_id'), # NPC ID for accept/decline
|
||||
session_id=session_id
|
||||
)
|
||||
else:
|
||||
@@ -1429,6 +1432,158 @@ def talk_to_npc(session_id: str, npc_id: str):
|
||||
return f'<div class="error">Failed to talk to NPC: {e}</div>', 500
|
||||
|
||||
|
||||
# ===== Quest Accept/Decline Routes =====
|
||||
|
||||
@game_bp.route('/session/<session_id>/quest/accept', methods=['POST'])
|
||||
@require_auth
|
||||
def accept_quest(session_id: str):
|
||||
"""
|
||||
Accept a quest offer from NPC chat.
|
||||
|
||||
Called when player clicks 'Accept Quest' button on inline quest offer card.
|
||||
Returns updated card with confirmation message and triggers toast notification.
|
||||
"""
|
||||
client = get_api_client()
|
||||
quest_id = request.form.get('quest_id')
|
||||
npc_id = request.form.get('npc_id')
|
||||
npc_name = request.form.get('npc_name', 'NPC')
|
||||
|
||||
if not quest_id:
|
||||
return render_template(
|
||||
'game/partials/quest_action_response.html',
|
||||
action='error',
|
||||
error_message='No quest specified',
|
||||
session_id=session_id
|
||||
)
|
||||
|
||||
try:
|
||||
# Get character_id from session
|
||||
session_response = client.get(f'/api/v1/sessions/{session_id}')
|
||||
session_data = session_response.get('result', {})
|
||||
character_id = session_data.get('character_id')
|
||||
|
||||
if not character_id:
|
||||
return render_template(
|
||||
'game/partials/quest_action_response.html',
|
||||
action='error',
|
||||
error_message='Session error - no character found',
|
||||
session_id=session_id
|
||||
)
|
||||
|
||||
# Call API to accept quest
|
||||
response = client.post('/api/v1/quests/accept', {
|
||||
'character_id': character_id,
|
||||
'quest_id': quest_id,
|
||||
'npc_id': npc_id
|
||||
})
|
||||
|
||||
result = response.get('result', {})
|
||||
quest_name = result.get('quest_name', 'Quest')
|
||||
|
||||
logger.info(
|
||||
"quest_accepted",
|
||||
quest_id=quest_id,
|
||||
quest_name=quest_name,
|
||||
character_id=character_id,
|
||||
session_id=session_id
|
||||
)
|
||||
|
||||
return render_template(
|
||||
'game/partials/quest_action_response.html',
|
||||
action='accept',
|
||||
quest_name=quest_name,
|
||||
npc_name=npc_name,
|
||||
session_id=session_id
|
||||
)
|
||||
|
||||
except APIError as e:
|
||||
logger.error(
|
||||
"failed_to_accept_quest",
|
||||
quest_id=quest_id,
|
||||
session_id=session_id,
|
||||
error=str(e)
|
||||
)
|
||||
return render_template(
|
||||
'game/partials/quest_action_response.html',
|
||||
action='error',
|
||||
error_message=str(e),
|
||||
session_id=session_id
|
||||
)
|
||||
|
||||
|
||||
@game_bp.route('/session/<session_id>/quest/decline', methods=['POST'])
|
||||
@require_auth
|
||||
def decline_quest(session_id: str):
|
||||
"""
|
||||
Decline a quest offer from NPC chat.
|
||||
|
||||
Called when player clicks 'Decline' button on inline quest offer card.
|
||||
Returns updated card with decline confirmation.
|
||||
"""
|
||||
client = get_api_client()
|
||||
quest_id = request.form.get('quest_id')
|
||||
npc_id = request.form.get('npc_id')
|
||||
npc_name = request.form.get('npc_name', 'NPC')
|
||||
|
||||
if not quest_id:
|
||||
return render_template(
|
||||
'game/partials/quest_action_response.html',
|
||||
action='error',
|
||||
error_message='No quest specified',
|
||||
session_id=session_id
|
||||
)
|
||||
|
||||
try:
|
||||
# Get character_id from session
|
||||
session_response = client.get(f'/api/v1/sessions/{session_id}')
|
||||
session_data = session_response.get('result', {})
|
||||
character_id = session_data.get('character_id')
|
||||
|
||||
if not character_id:
|
||||
return render_template(
|
||||
'game/partials/quest_action_response.html',
|
||||
action='error',
|
||||
error_message='Session error - no character found',
|
||||
session_id=session_id
|
||||
)
|
||||
|
||||
# Call API to decline quest
|
||||
client.post('/api/v1/quests/decline', {
|
||||
'character_id': character_id,
|
||||
'quest_id': quest_id,
|
||||
'npc_id': npc_id
|
||||
})
|
||||
|
||||
logger.info(
|
||||
"quest_declined",
|
||||
quest_id=quest_id,
|
||||
character_id=character_id,
|
||||
session_id=session_id
|
||||
)
|
||||
|
||||
return render_template(
|
||||
'game/partials/quest_action_response.html',
|
||||
action='decline',
|
||||
quest_name='', # Not needed for decline message
|
||||
npc_name=npc_name,
|
||||
session_id=session_id
|
||||
)
|
||||
|
||||
except APIError as e:
|
||||
logger.error(
|
||||
"failed_to_decline_quest",
|
||||
quest_id=quest_id,
|
||||
session_id=session_id,
|
||||
error=str(e)
|
||||
)
|
||||
return render_template(
|
||||
'game/partials/quest_action_response.html',
|
||||
action='error',
|
||||
error_message=str(e),
|
||||
session_id=session_id
|
||||
)
|
||||
|
||||
|
||||
# ===== Shop Routes =====
|
||||
|
||||
@game_bp.route('/session/<session_id>/shop-modal')
|
||||
|
||||
Reference in New Issue
Block a user