a
    Ži–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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rŠdd
ddœdd
ddœdd
ddœg}ddd|ddœS |dkr¢ddddddœS |dkr¾d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 r„t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Ž|rŽdd„ | jD ƒ}|rÚt |¡}|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 r¦t| jddƒd | j_| j	 
d¡ nVd|v rÒt| jddƒd | j_| j	 
d¡ n*d|v rüt| 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   Úintelligenceé2   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   z„You 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   z„You'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rÔt| 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�r‚t| jdƒ�r‚t| jjƒdk�r‚| t¡ d| jv�r´t| dƒ�r´t| 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'!
#
'










