a
    i-                     @   s   d Z ddlmZmZ ddlZddlZddlmZmZmZ dddZ	dd Z
d	d
 Zdd Zdd Zdd ZdddZdddZdddZdd ZdS )z}
Tutorial Events System for BaoLife
Provides gentle guided events for first-time players during their first 24 in-game hours
    )datetime	timedeltaN)messageFunctionquestionFunctionanswerOptionc                 C   s0   |dur|dk S t | jds dS | jj}|dk S )z
    Check if player is still in tutorial mode (first 24 in-game hours)

    Args:
        player: Player object
        game_hours: Optional override for testing

    Returns:
        bool: True if player is in tutorial mode
    N   ageHoursT)hasattrcr   )playerZ
game_hoursZhours_played r   ;/var/www/lichun.app/lichun/ws/events/tutorial/onboarding.pyis_tutorial_mode   s    r   c                 C   s.   t | jdd}|sd}dd| ddddd	S )
z
    Generate welcome message for new player

    Args:
        player: Player object

    Returns:
        dict: Tutorial message event
    	firstnameNfriendZtutorial_messagezWelcome to BaoLife, zV! Your journey begins now. Make choices, build relationships, and live your best life!systemT)typemessage	characterZcharacter_imageZdismissible)getattrr
   )r   r   r   r   r   get_welcome_message&   s    

r   c              
   C   s   |dkrPdd | j D }|s dS t|}dd|j|jd|j ddd	d
dd	S |dkrdd
dddd
dddd
ddg}ddd|ddS |dkrddddddS |dkrdddd d!d
d"d#S dS )$a  
    Generate special gentle events for tutorial mode

    Event types:
    - first_friend: Guaranteed positive interaction with NPC
    - first_activity: Simplified activity choices
    - first_purchase: Small diamond reward for first store visit
    - first_class: Guaranteed good grade

    Args:
        player: Player object
        event_type: String indicating which tutorial event to generate

    Returns:
        dict: Tutorial event data or None
    Zfirst_friendc                 S   s*   g | ]"}t |d ddkr|jdkr|qS affinityr   aliver   status.0pr   r   r   
<listcomp>Q       z+generate_tutorial_event.<locals>.<listcomp>NZtutorial_interactionzYour classmate z# smiles at you. They seem friendly!T      z<Making friends increases happiness and opens new activities!)	r   event_idZnpc_idZnpc_namer   Zguaranteed_successZaffinity_bonusreward_diamondstutorial_hintZfirst_activityStudyzIncreases intelligence)nameenergyZbenefitPlayzIncreases happinessExercisezIncreases healthZtutorial_activity_selectionz8Activities cost energy but help you grow. Choose wisely!)r   r#   Zsimplified_choiceschoicesr%   Zfirst_purchaseZtutorial_store_visit
   z<Welcome to the store! Here's 10 diamonds to get you started.z7Buy items to increase your prestige and impress others!)r   r#   r$   r   r%   Zfirst_classZtutorial_class_resultAz-Great job in class! You're a natural learner.z<Good grades lead to better college and career opportunities!)r   r#   Zguaranteed_good_gradeZgrader   r$   r%   )rrandomchoiceidr   )r   
event_typefriendly_peoplenpcZbasic_activitiesr   r   r   generate_tutorial_event=   sV    




r5   c                 C   s   t | s|S d|v r*td|d d |d< d|v rFt|d d |d< d|v rbt|d d |d< d|v rtdt|d d |d< d	|d
< t|dd|d< |S )a  
    Apply tutorial mode modifiers to regular events
    - Reduce difficulty
    - Increase rewards
    - Add helpful hints

    Args:
        player: Player object
        event_data: Dictionary of event data

    Returns:
        dict: Modified event data
    Z
difficulty      Zmoney_rewardg      ?Zdiamonds_reward
energyCostg      ?TZtutorial_moder   Zgeneralr%   )r   maxintget_contextual_hintget)r   Z
event_datar   r   r   apply_tutorial_modifiers   s    r=   c                 C   s    dddddddd}| | d	S )
z
    Get helpful hint based on event type

    Args:
        event_type: String indicating event type

    Returns:
        str: Helpful hint text
    z/Working earns money. Save up for big purchases!z,Education opens better career opportunities.z2Building relationships makes life more fulfilling.z%Keep your health high to live longer.z-Money buys items that increase your prestige.z9Take your time making decisions - they shape your future!z4Pay attention to life events - they tell your story!)workschoolsocialhealthmoneyquestionEventmessageEventz(Make choices that align with your goals!)r<   )r2   hintsr   r   r   r;      s    
r;   c                 C   s\   t | s|S t|tr t| |S t|drX|j}t| |}| D ]\}}t||| qB|S )a  
    Modify any generated event if player is in tutorial mode
    Called by main event generator

    Args:
        player: Player object
        event: Event object (messageEvent, questionEvent, etc.)

    Returns:
        Event object (potentially modified)
    __dict__)r   
isinstancedictr=   r	   rF   itemssetattr)r   eventZ
event_dictZmodified_dictkeyvaluer   r   r   modify_event_for_tutorial   s    



rN   r   Fc           	      C   s   d}|| j vo"t| o"t| jdk}|dkr|rdd | jD }|rt|}|j d}tddd	td
dd	tddd	g}t||| ||S nL|dkr| j	
d | j jd7  _t| jdr| j jd7  _| j	
d dS )zx
    Tutorial event: First conversation with an NPC
    Guaranteed positive outcome to encourage social interaction
    firstConversationr   answerc                 S   s*   g | ]"}t |d ddkr|jdkr|qS r   r   r   r   r   r   r      r    z%firstConversation.<locals>.<listcomp>zX approaches you with a warm smile. This seems like a great opportunity to make a friend!z
Say hello!   r8   zStart a conversationzWave and smiler6   zpGreat! You've taken your first steps in building relationships. Keep talking to people to grow your friendships!r"   diamondsz7You earned 5 diamonds for making your first connection!N)eventsr   lenr.   r/   r0   r   r   r   messageQueueappendr
   	happinessr	   rS   )	r   r   r   responsefnamecheckr3   r4   answerOptionsr   r   r   rO      s$     



rO   c                 C   s*  d}|| j vo t| o | jjdk}|dkrd|rdd}tdddtdddtdddg}t||| ||S |dkr&|d	d
}d|v rt| jddd | j_| j	
d nVd|v rt| jddd | j_| j	
d n*d|v rt| jddd | j_| j	
d t| jdr&| j jd7  _| j	
d dS )z]
    Tutorial event: First activity selection
    Simplified choices with clear benefits
    firstActivityChoicer"   rP   z3You have some free time! What would you like to do?zStudy (Gain Intelligence)rR   zPlay (Gain Happiness)zExercise (Gain Health)option r&   intelligence2   r,   z:You studied hard and feel smarter! Intelligence increased.r)   rX   z)You had fun playing! Happiness increased.r*   rA   z3You exercised and feel healthier! Health increased.rS   rQ   z9You earned 3 diamonds for completing your first activity!N)rT   r   r
   ageYearsr   r   r<   r   r`   rV   rW   rX   rA   r	   rS   )r   r   r   rY   rZ   r[   r\   r0   r   r   r   r]     s.    



r]   c                 C   sd   d}|| j vo$| jjdko$| jjdk }|r`d}t| jdrR| j jd7  _|d7 }t||| |S dS )z_
    Event triggered when player completes tutorial (24 hours)
    Awards completion bonus
    tutorialCompleter      zMYou've completed your first day! You're getting the hang of life. Keep going!rS   z4 You earned 25 diamonds for completing the tutorial!N)rT   r
   r   r	   rS   r   )r   r   rZ   r[   r   r   r   r   rc   4  s    "rc   c                 C   sv   t | sg S g }d| jvr2t| jdkr2|t d| jvrR| jjdkrR|t d| jvrr| jj	dkrr|t
 |S )z
    Check which tutorial events should be triggered based on player state

    Args:
        player: Player object

    Returns:
        list: List of event functions to call
    rO   r   r]   r"   rc   r   )r   rT   rU   r.   rW   rO   r
   rb   r]   r   rc   )r   Zevents_to_checkr   r   r   check_tutorial_triggersH  s    



re   )N)r   FF)r   FF)r   )__doc__r   r   loggingr/   Zevents.baser   r   r   r   r   r5   r=   r;   rN   rO   r]   rc   re   r   r   r   r   <module>   s   
N'!
#
'
