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')
|
||||
|
||||
@@ -2662,3 +2662,273 @@
|
||||
background: #ef4444;
|
||||
color: white;
|
||||
}
|
||||
|
||||
/* ===== QUEST OFFER CARD ===== */
|
||||
/* Inline card that appears in NPC chat when quest is offered */
|
||||
|
||||
.quest-offer-card {
|
||||
background: linear-gradient(135deg, rgba(139, 92, 246, 0.15), rgba(59, 130, 246, 0.1));
|
||||
border: 2px solid var(--action-premium);
|
||||
border-radius: 8px;
|
||||
margin-top: 1rem;
|
||||
padding: 1rem;
|
||||
animation: questCardAppear 0.4s ease;
|
||||
}
|
||||
|
||||
@keyframes questCardAppear {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.quest-offer-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
margin-bottom: 0.75rem;
|
||||
padding-bottom: 0.5rem;
|
||||
border-bottom: 1px solid rgba(139, 92, 246, 0.3);
|
||||
}
|
||||
|
||||
.quest-offer-icon {
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
|
||||
.quest-offer-label {
|
||||
font-size: var(--text-xs);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
color: var(--action-premium);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.quest-offer-content {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.quest-offer-title {
|
||||
font-family: var(--font-heading);
|
||||
font-size: var(--text-lg);
|
||||
color: var(--accent-gold);
|
||||
margin: 0 0 0.5rem 0;
|
||||
}
|
||||
|
||||
.quest-offer-description {
|
||||
font-size: var(--text-sm);
|
||||
color: var(--text-secondary);
|
||||
margin: 0 0 0.75rem 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.quest-offer-rewards {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.rewards-label {
|
||||
font-size: var(--text-xs);
|
||||
color: var(--text-muted);
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.reward-item {
|
||||
font-size: var(--text-sm);
|
||||
padding: 0.25rem 0.5rem;
|
||||
border-radius: 4px;
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.reward-gold {
|
||||
color: var(--accent-gold);
|
||||
}
|
||||
|
||||
.reward-xp {
|
||||
color: #10b981;
|
||||
}
|
||||
|
||||
.quest-offer-actions {
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.quest-btn {
|
||||
flex: 1;
|
||||
padding: 0.625rem 1rem;
|
||||
font-size: var(--text-sm);
|
||||
font-weight: 600;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.quest-btn--accept {
|
||||
background: #10b981;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.quest-btn--accept:hover {
|
||||
background: #059669;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.quest-btn--decline {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
color: var(--text-secondary);
|
||||
border: 1px solid var(--play-border);
|
||||
}
|
||||
|
||||
.quest-btn--decline:hover {
|
||||
background: rgba(255, 255, 255, 0.15);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
/* Quest action result (replaces card after action) */
|
||||
.quest-action-result {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 0.75rem 1rem;
|
||||
border-radius: 6px;
|
||||
margin-top: 1rem;
|
||||
animation: questCardAppear 0.3s ease;
|
||||
}
|
||||
|
||||
.quest-action-result--accept {
|
||||
background: rgba(16, 185, 129, 0.15);
|
||||
border: 1px solid #10b981;
|
||||
}
|
||||
|
||||
.quest-action-result--decline {
|
||||
background: rgba(107, 114, 128, 0.15);
|
||||
border: 1px solid var(--play-border);
|
||||
}
|
||||
|
||||
.quest-action-result--error {
|
||||
background: rgba(239, 68, 68, 0.15);
|
||||
border: 1px solid #ef4444;
|
||||
}
|
||||
|
||||
.quest-action-icon {
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.quest-action-message {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.quest-action-message strong {
|
||||
display: block;
|
||||
color: var(--text-primary);
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.quest-action-message p {
|
||||
margin: 0;
|
||||
font-size: var(--text-sm);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
|
||||
/* ===== TOAST NOTIFICATIONS ===== */
|
||||
/* Fixed position notifications for quick feedback */
|
||||
|
||||
.toast-container {
|
||||
position: fixed;
|
||||
top: 1rem;
|
||||
right: 1rem;
|
||||
z-index: 9999;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
max-width: 350px;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.toast {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0.75rem 1rem;
|
||||
border-radius: 6px;
|
||||
font-size: var(--text-sm);
|
||||
box-shadow: var(--shadow-lg);
|
||||
opacity: 0;
|
||||
transform: translateX(100%);
|
||||
transition: all 0.3s ease;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.toast--visible {
|
||||
opacity: 1;
|
||||
transform: translateX(0);
|
||||
}
|
||||
|
||||
.toast--dismissing {
|
||||
opacity: 0;
|
||||
transform: translateX(100%);
|
||||
}
|
||||
|
||||
.toast--success {
|
||||
background: rgba(16, 185, 129, 0.95);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.toast--error {
|
||||
background: rgba(239, 68, 68, 0.95);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.toast--info {
|
||||
background: rgba(59, 130, 246, 0.95);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.toast-message {
|
||||
flex: 1;
|
||||
margin-right: 0.5rem;
|
||||
}
|
||||
|
||||
.toast-close {
|
||||
background: none;
|
||||
border: none;
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
font-size: 1.25rem;
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
line-height: 1;
|
||||
transition: color 0.2s ease;
|
||||
}
|
||||
|
||||
.toast-close:hover {
|
||||
color: white;
|
||||
}
|
||||
|
||||
/* Mobile responsiveness for quest card */
|
||||
@media (max-width: 768px) {
|
||||
.quest-offer-card {
|
||||
margin-top: 0.75rem;
|
||||
padding: 0.75rem;
|
||||
}
|
||||
|
||||
.quest-offer-actions {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.quest-btn {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.toast-container {
|
||||
left: 1rem;
|
||||
right: 1rem;
|
||||
max-width: none;
|
||||
}
|
||||
}
|
||||
|
||||
82
public_web/static/js/toast.js
Normal file
82
public_web/static/js/toast.js
Normal file
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* Toast Notification System
|
||||
* Provides temporary notifications for game events (quest acceptance, errors, etc.)
|
||||
*
|
||||
* Usage:
|
||||
* showToast('Quest accepted!', 'success');
|
||||
* showToast('Failed to save', 'error');
|
||||
* showToast('Item added to inventory', 'info');
|
||||
*/
|
||||
|
||||
/**
|
||||
* Show a toast notification
|
||||
* @param {string} message - The message to display
|
||||
* @param {string} type - Type of toast: 'success', 'error', or 'info'
|
||||
* @param {number} duration - Duration in ms before auto-dismiss (default: 4000)
|
||||
*/
|
||||
function showToast(message, type = 'info', duration = 4000) {
|
||||
// Create toast container if it doesn't exist
|
||||
let container = document.getElementById('toast-container');
|
||||
if (!container) {
|
||||
container = document.createElement('div');
|
||||
container.id = 'toast-container';
|
||||
container.className = 'toast-container';
|
||||
document.body.appendChild(container);
|
||||
}
|
||||
|
||||
// Create toast element
|
||||
const toast = document.createElement('div');
|
||||
toast.className = `toast toast--${type}`;
|
||||
toast.innerHTML = `
|
||||
<span class="toast-message">${escapeHtml(message)}</span>
|
||||
<button class="toast-close" onclick="dismissToast(this.parentElement)" aria-label="Close">×</button>
|
||||
`;
|
||||
|
||||
// Add to container
|
||||
container.appendChild(toast);
|
||||
|
||||
// Trigger animation (small delay for DOM to register element)
|
||||
requestAnimationFrame(() => {
|
||||
toast.classList.add('toast--visible');
|
||||
});
|
||||
|
||||
// Auto-remove after duration
|
||||
setTimeout(() => {
|
||||
dismissToast(toast);
|
||||
}, duration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dismiss a toast notification with animation
|
||||
* @param {HTMLElement} toast - The toast element to dismiss
|
||||
*/
|
||||
function dismissToast(toast) {
|
||||
if (!toast || toast.classList.contains('toast--dismissing')) {
|
||||
return;
|
||||
}
|
||||
|
||||
toast.classList.add('toast--dismissing');
|
||||
toast.classList.remove('toast--visible');
|
||||
|
||||
// Remove from DOM after animation completes
|
||||
setTimeout(() => {
|
||||
if (toast.parentElement) {
|
||||
toast.remove();
|
||||
}
|
||||
}, 300);
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape HTML to prevent XSS
|
||||
* @param {string} text - Text to escape
|
||||
* @returns {string} Escaped text
|
||||
*/
|
||||
function escapeHtml(text) {
|
||||
const div = document.createElement('div');
|
||||
div.textContent = text;
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
// Make functions globally available
|
||||
window.showToast = showToast;
|
||||
window.dismissToast = dismissToast;
|
||||
@@ -9,6 +9,8 @@ Expected context:
|
||||
- player_line: What the player just said
|
||||
- dialogue: NPC's current response
|
||||
- session_id: For any follow-up actions
|
||||
- quest_offer: Optional quest offer data {quest_id, quest_name, quest_description, rewards, npc_id}
|
||||
- npc_id: NPC identifier for quest accept/decline
|
||||
#}
|
||||
|
||||
{# Only show CURRENT exchange (removed conversation_history loop) #}
|
||||
@@ -23,6 +25,50 @@ Expected context:
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# Quest Offer Card - appears inline after NPC dialogue when quest is offered #}
|
||||
{% if quest_offer %}
|
||||
<div class="quest-offer-card" id="quest-offer-{{ quest_offer.quest_id }}">
|
||||
<div class="quest-offer-header">
|
||||
<span class="quest-offer-icon">📜</span>
|
||||
<span class="quest-offer-label">Quest Offered</span>
|
||||
</div>
|
||||
|
||||
<div class="quest-offer-content">
|
||||
<h4 class="quest-offer-title">{{ quest_offer.quest_name }}</h4>
|
||||
<p class="quest-offer-description">{{ quest_offer.quest_description }}</p>
|
||||
|
||||
{% if quest_offer.rewards %}
|
||||
<div class="quest-offer-rewards">
|
||||
<span class="rewards-label">Rewards:</span>
|
||||
{% if quest_offer.rewards.gold %}
|
||||
<span class="reward-item reward-gold">{{ quest_offer.rewards.gold }} gold</span>
|
||||
{% endif %}
|
||||
{% if quest_offer.rewards.experience %}
|
||||
<span class="reward-item reward-xp">{{ quest_offer.rewards.experience }} XP</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="quest-offer-actions">
|
||||
<button class="quest-btn quest-btn--accept"
|
||||
hx-post="{{ url_for('game.accept_quest', session_id=session_id) }}"
|
||||
hx-vals='{"quest_id": "{{ quest_offer.quest_id }}", "npc_id": "{{ quest_offer.npc_id }}", "npc_name": "{{ npc_name }}"}'
|
||||
hx-target="#quest-offer-{{ quest_offer.quest_id }}"
|
||||
hx-swap="outerHTML">
|
||||
Accept Quest
|
||||
</button>
|
||||
<button class="quest-btn quest-btn--decline"
|
||||
hx-post="{{ url_for('game.decline_quest', session_id=session_id) }}"
|
||||
hx-vals='{"quest_id": "{{ quest_offer.quest_id }}", "npc_id": "{{ quest_offer.npc_id }}", "npc_name": "{{ npc_name }}"}'
|
||||
hx-target="#quest-offer-{{ quest_offer.quest_id }}"
|
||||
hx-swap="outerHTML">
|
||||
Decline
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{# Trigger history refresh after new message #}
|
||||
<div hx-trigger="load"
|
||||
_="on load trigger newMessage on body"
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
{#
|
||||
Quest Action Response - Replaces quest offer card after accept/decline.
|
||||
Shows confirmation message and triggers toast notification + sidebar refresh.
|
||||
|
||||
Expected context:
|
||||
- action: 'accept', 'decline', or 'error'
|
||||
- quest_name: Name of the quest (for accept message)
|
||||
- npc_name: Name of the NPC offering the quest
|
||||
- error_message: Error details (for error action)
|
||||
- session_id: For sidebar refresh
|
||||
#}
|
||||
|
||||
{% if action == 'error' %}
|
||||
{# Error state - display error message #}
|
||||
<div class="quest-action-result quest-action-result--error">
|
||||
<div class="quest-action-icon">⚠</div>
|
||||
<div class="quest-action-message">
|
||||
<strong>Error</strong>
|
||||
<p>{{ error_message | default('Something went wrong') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% elif action == 'accept' %}
|
||||
{# Quest accepted - show success message #}
|
||||
<div class="quest-action-result quest-action-result--accept">
|
||||
<div class="quest-action-icon">✔</div>
|
||||
<div class="quest-action-message">
|
||||
<strong>Quest Accepted!</strong>
|
||||
<p>{{ npc_name }} nods approvingly. Check your quest log for details.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# Trigger toast notification #}
|
||||
<script>
|
||||
if (typeof showToast === 'function') {
|
||||
showToast('Quest "{{ quest_name }}" accepted!', 'success');
|
||||
}
|
||||
</script>
|
||||
|
||||
{# Refresh quests accordion to show newly accepted quest #}
|
||||
<div hx-get="{{ url_for('game.quests_accordion', session_id=session_id) }}"
|
||||
hx-trigger="load"
|
||||
hx-target="#accordion-quests"
|
||||
hx-swap="innerHTML"
|
||||
style="display: none;"></div>
|
||||
|
||||
{% elif action == 'decline' %}
|
||||
{# Quest declined - show confirmation message #}
|
||||
<div class="quest-action-result quest-action-result--decline">
|
||||
<div class="quest-action-icon">✖</div>
|
||||
<div class="quest-action-message">
|
||||
<strong>Quest Declined</strong>
|
||||
<p>{{ npc_name }} understands. Perhaps another time.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# Trigger toast notification #}
|
||||
<script>
|
||||
if (typeof showToast === 'function') {
|
||||
showToast('Quest declined', 'info');
|
||||
}
|
||||
</script>
|
||||
|
||||
{% endif %}
|
||||
@@ -154,4 +154,7 @@ document.addEventListener('keydown', function(e) {
|
||||
|
||||
<!-- Responsive Modal Navigation -->
|
||||
<script src="{{ url_for('static', filename='js/responsive-modals.js') }}"></script>
|
||||
|
||||
<!-- Toast Notifications -->
|
||||
<script src="{{ url_for('static', filename='js/toast.js') }}"></script>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user