a
    iI                     @   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d0ddZd1ddZd2ddZd3ddZd4ddZd5ddZd6dd Zd7d!d"Zd8d#d$Zd9d%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   )player
game_hourshours_played r   0/var/www/lichun.app/lichun/ws/tutorial_events.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friendtutorial_messagezWelcome to BaoLife, zV! Your journey begins now. Make choices, build relationships, and live your best life!systemT)typemessage	charactercharacter_image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
    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>Ntutorial_interactionzYour classmate z# smiles at you. They seem friendly!T      z<Making friends increases happiness and opens new activities!)	r   event_idnpc_idnpc_namer   guaranteed_successaffinity_bonusreward_diamondstutorial_hintfirst_activityStudyzIncreases intelligence)nameenergybenefitPlayzIncreases happinessExercisezIncreases healthtutorial_activity_selectionz8Activities cost energy but help you grow. Choose wisely!)r   r*   simplified_choiceschoicesr0   first_purchase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   r0   first_class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*   guaranteed_good_gradegrader   r/   r0   )rrandomchoiceidr   )r   
event_typefriendly_peoplenpcbasic_activitiesr   r   r   generate_tutorial_event=   sV    




rK   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
    
difficulty      money_rewardg      ?diamonds_reward
energyCostg      ?Ttutorial_moder   generalr0   )r   maxintget_contextual_hintget)r   
event_datar   r   r   apply_tutorial_modifiers   s    rY   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!)rW   )rG   hintsr   r   r   rV      s    
rV   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dictrY   r	   rb   itemssetattr)r   event
event_dictmodified_dictkeyvaluer   r   r   modify_event_for_tutorial   s    



rl   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!   rQ   zStart a conversationzWave and smilerM   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   lenrC   rD   rE   r   r   r   messageQueueappendr
   	happinessr	   rq   )	r   r   r   responsefnamecheckrH   rI   answerOptionsr   r   r   rm      s$     



rm   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)   rn   z3You have some free time! What would you like to do?zStudy (Gain Intelligence)rp   zPlay (Gain Happiness)zExercise (Gain Health)option r2   intelligence2   r=   z:You studied hard and feel smarter! Intelligence increased.r6   rv   z)You had fun playing! Happiness increased.r7   r]   z3You exercised and feel healthier! Health increased.rq   ro   z9You earned 3 diamonds for completing your first activity!N)rr   r   r
   ageYearsr   r   rW   r   r~   rt   ru   rv   r]   r	   rq   )r   r   r   rw   rx   ry   rz   rE   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!rq   z4 You earned 25 diamonds for completing the tutorial!N)rr   r
   r   r	   rq   r   r   r   rx   ry   r   r   r   r   r   4  s    "r   c                 C   s,   d}|| j vo| jjdk }d}t||| |S )z_
    Tutorial event: Explaining energy system when low
    Trigger: First time energy < 20
    tutorialEnergyExplainedr(   ztYour energy is running low! When you're tired, activities cost more effort and you'll feel worse. Make sure to rest!)rr   r
   r4   r   r   r   r   r   r   I  s    r   c                 C   s    d}|| j v}d}t||| |S )z
    Tutorial event: Explaining money system on first expense
    Trigger: First question with moneyCost
    Note: This is triggered externally when a choice with moneyCost appears
    tutorialMoneyExplainedzmThis choice costs money! You earn money through jobs and can spend it on activities and items. Choose wisely!)rr   r   r   r   r   r   r   U  s    
r   c                 C   sB   d}|| j vo.t| jdko.tdd | jD }d}t||| |S )z]
    Tutorial event: Explaining relationship affinity
    Trigger: First NPC interaction
    tutorialRelationshipExplainedr   c                 s   s   | ]}t |d V  qdS )r   N)r	   r"   r   r   r   	<genexpr>h  r&   z0tutorialRelationshipExplained.<locals>.<genexpr>z{Each person has an affinity toward you that changes based on your interactions. Higher affinity means better relationships!)rr   rs   rC   anyr   r   r   r   r   r   b  s    ,r   c                 C   s,   d}|| j vo| jjdk}d}t||| |S )z
    Tutorial event: Explaining stat tracking
    Trigger: First stat change notification
    Note: This should trigger after any significant stat change
    tutorialStatsExplainedrN   zbYour choices affect your stats! Keep an eye on happiness, health, intelligence, and social skills.rr   r
   r   r   r   r   r   r   r   n  s    r   c                 C   s8   d}|| j vo$t| jdo$| jjdk}d}t||| |S )z
    Tutorial event: Explaining premium currency
    Trigger: First time earning diamonds
    Note: This should trigger right after diamonds are awarded
    tutorialDiamondsEarnedrq   r   z`You earned diamonds! These are special currency for premium choices that unlock better outcomes.)rr   r	   r
   rq   r   r   r   r   r   r   {  s    


r   c                 C   s,   d}|| j vo| jjdk}d}t||| |S )z_
    Tutorial event: Explaining game speed controls
    Trigger: After 1 hour of game time
    tutorialGameSpeedExplainedrM   zYou can control how fast time passes! Use the speed controls to slow down during important moments or speed up during routine times.r   r   r   r   r   r     s    r   c                 C   s<   d}|| j vo(t| jdo(t| jjdk}d}t||| |S )zt
    Tutorial event: Explaining schedule system
    Trigger: First schedule added (bike lessons, swimming, etc)
    tutorialSchedulesIntro	schedulesr   zYou've started a recurring activity! This will happen automatically on scheduled days. Check your schedules to see what's coming up.)rr   r	   r
   rs   r   r   r   r   r   r   r     s    

r   c                 C   s.   d}|| j vot| j dk}d}t||| |S )zN
    Tutorial event: Explaining event system
    Trigger: After 3rd event
    tutorialEventsIntroro   zvEvents are how life unfolds! Some happen automatically, others require your choices. Every decision shapes your story.)rr   rs   r   r   r   r   r   r     s    r   c                 C   s8   d}|| j vo$t| do$t| jdk}d}t||| |S )z]
    Tutorial event: Explaining delayed events
    Trigger: First oneTimeEvent scheduled
    tutorialOneTimeEventsoneTimeEventsr   z\Some events are scheduled for the future! Keep an eye on your calendar for upcoming moments.)rr   r	   rs   r   r   r   r   r   r   r     s    
r   c                    sn   d}g d}t  fdd|D }| jvo.|}|rjd}t jdr\ j jd7  _|d7 }t|| |S d	S )
z
    Tutorial event: Celebrating first major milestone
    Trigger: First major event (learned to walk, first day school, etc)
    Awards 5 diamonds
    tutorialFirstMilestone)learnedWalklearnedBikelearnedSwimZfirstDayOfSchoollostFirstTooth
likeSchool
firstCrush	firstKissc                 3   s   | ]}| j v V  qd S )N)rr   )r#   Z	milestoner   r   r   r     r&   z)tutorialFirstMilestone.<locals>.<genexpr>zrCongratulations on your first major milestone! These special moments mark important progress in your life journey.rq   r)   z You earned 5 diamonds!N)r   rr   r	   r
   rq   r   )r   r   rx   Zmajor_milestonesZhas_milestonery   r   r   r   r   r     s    r   c                 C   s  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
 d| jvr| jj	dkr|t d	| jvr| jj	d
kr|t d| jvrt| jdkr|t d| jvr| jjdk r|t d| jvrt| jdkr|t d| jvrLt| jdrL| jjdkrL|t d| jvrt| jdrt| jjdkr|t d| jvrt| drt| jdkr|t |t |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
    rm   r   r{   r)   r   r   r   rM   r   rN   r   ro   r   r(   r   r   rq   r   r   r   r   )r   rr   rs   rC   ru   rm   r
   r   r{   r   r   r   r   r   r4   r   r   r	   rq   r   r   r   r   r   r   r   )r   events_to_checkr   r   r   check_tutorial_triggers  s8    








(
,
(


r   )N)r   FF)r   FF)r   )r   )r   )r   )r   )r   )r   )r   )r   )r   )r   )__doc__r   r   loggingrD   rr   r   r   r   r   r   rK   rY   rV   rl   rm   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s0   
N'!
#
'










