a
    
Üir>  ã                   @   s¾  d Z ddlZddlmZmZ dd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dd„ Z
G dd„ dƒZdd„ ZG dd„ dƒZeddƒeddƒeddƒeddƒed d!ƒed"d#ƒed$d%ƒed&d'ƒed(d)ƒed*d+ƒed,d-ƒed.d/ƒed0d1ƒed2d3ƒed4d5ƒed6d7ƒd8œZed9d:d;ƒed<d=d;ƒed>d?d;ƒed@dAd;ƒedBdCd;ƒedDdEd;ƒedFdGd;ƒedHdId;ƒedJdKd;ƒedLdMd;ƒedNdOd;ƒedPdQd;ƒedRdSd;ƒedTdUd;ƒedVdWd;ƒdXœZdYdZ„ Zd[d\„ Zd]d^„ Zd_d`„ ZdS )aa!  
Health and Habits Management System

This module contains all health and habits-related functionality for the BaoLife game,
including health conditions, weight management, death mechanics, and habit tracking.

Extracted from functions.py for better code organization and maintainability.
é    N©Ú	timedeltaÚdatetimec                 C   s,   | dk rdS | dk rdS | dk r$dS dS dS )	zÆ
    Determine weight category based on weight value.

    Args:
        weight: Numeric weight value

    Returns:
        str: Weight category ('Underweight', 'Normal', 'Overweight', 'Obese')
    é2   ÚUnderweightéF   ZNormaléZ   Z
OverweightÚObeseN© ©Úweightr
   r
   ú6/var/www/lichun.app/lichun/ws/health/health_manager.pyÚgetWeightType   s    
r   c                 C   s$   | j dk rd| _ | j dkr d| _ dS )zk
    Enforce weight boundaries (0-100).

    Args:
        person: Person object with weight attribute
    r   éd   Nr   ©Úpersonr
   r
   r   ÚhandleWeight'   s    

r   c                 C   sÀ   ddl m}m } |jdks$|jdkr0|jd |_|jr–|jD ]X}| |jd¡}|||jd� }| | jd¡}||kr|d|_q<|j|j	d	  |_d
|_q<|jdkr¬|j
d |_
|jdkr¼d|_dS )zó
    Update person's health based on weight type and health conditions.
    Handles health condition duration and healing.

    Args:
        player: Player object with date information
        person: Person object with health attributes
    r   r   r   r	   ç�íµ ÷Æ°>z%m-%d)ÚweeksTi † Fé   é   N)r   r   Ú
weightTypeÚhealthÚhealthConditionsÚstrptimeÚdateÚaverageDurationZisCuredÚhealthModifierÚdeathChance)Úplayerr   r   r   Ú	conditionZcondition_dateZhealing_dateZplayer_dater
   r
   r   ÚhandleHealth8   s     	


r!   c                 C   s   | j  d¡ d| _dS )zM
    Handle player death event.

    Args:
        player: Player object
    zYou have died!ÚinactiveN)ÚmessageQueueÚappendÚ
controller©r   r
   r
   r   ÚhandleDeathW   s    r'   c                 C   s¢   | j dkrd| _n|| j dkr$d| _nj| j dkr6d| _nX| j dkrHd| _nF| j d	krZd
| _n4| j dkrld| _n"| j dkr~d| _n| j dkrŽd| _| j| j | _| jS )z¹
    Calculate death chance based on age and health.

    Args:
        person: Person object with age and health attributes

    Returns:
        float: Updated death chance value
    r   ga2U0*©S?éR   g-Cëâ6*?r   gTäqs*Ù>é<   gñhãˆµøÔ>r   g�íµ ÷ÆÐ>é(   gTäqs*É>é   g�íµ ÷ÆÀ>é   r   )ÚageYearsr   r   r   r
   r
   r   ÚupdateDeathChanceb   s$    








r.   c                 C   s$   | j dk rd| _ | jdk r d| _| S )zº
    Enforce hunger and thirst boundaries (minimum 0).

    Args:
        person: Person object with hunger and thirst attributes

    Returns:
        person: Updated person object
    r   )ÚhungerÚthirstr   r
   r
   r   ÚhandleHunger„   s
    


r1   c                 C   s4   | j jt dd¡ | j _| j jt dd¡ | j _| S )z³
    Process meal event, reducing hunger and thirst.

    Args:
        player: Player object with character (c) attribute

    Returns:
        player: Updated player object
    r   r)   )Úcr/   ÚrandomÚrandintr0   r&   r
   r
   r   Ú	mealEvent•   s    r5   c                   @   s   e Zd ZdZddd„ZdS )ÚHealthConditiona½  
    Represents a health condition or disease that can affect a character.

    Attributes:
        id: Unique identifier for the condition
        title: Display name of the condition
        healthModifier: Amount of health impact (higher = worse)
        averageDuration: Expected duration in weeks
        date: Date when condition was acquired
        description: Descriptive text about the condition
        image: Optional image URL
    Nc                 C   s.   || _ || _|| _|| _d | _|| _|| _d S )N)ÚidÚtitler   r   r   ÚdescriptionÚimage)Úselfr7   r8   r   r   r9   r:   r
   r
   r   Ú__init__¶   s    zHealthCondition.__init__)N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r<   r
   r
   r
   r   r6   ©   s   r6   c                  C   s¾   t dddddƒt dddd	d
ƒt dddddƒt dddddƒt dddddƒt dddd	dƒt dddddƒt ddddd ƒt d!d"dd	d#ƒt d$d%d&dd'ƒt d(d)d*dd+ƒt d,d-ddd.ƒt d/d0ddd1ƒg} | S )2zr
    Get list of all available health conditions.

    Returns:
        list: List of HealthCondition objects
    Z
condition1zCOVID-19é
   é   z>You have contracted COVID-19. You must quarantine for 14 days.Z
condition2zCommon Coldé   é   z1You have a common cold. You must rest for 3 days.Z
condition3ZFlué   z+You have the flu. You must rest for 7 days.Z
condition4zBroken Boneé   r+   z2You have a broken bone. You must rest for 30 days.Z
condition5zSprained Anklez4You have a sprained ankle. You must rest for 7 days.Z
condition6zFood Poisoningz2You have food poisoning. You must rest for 3 days.Z
condition7ZDiabetesiŸ† z]You have been diagnosed with Diabetes. Regular medication and lifestyle changes are required.Z
condition8zHigh Blood Pressurez\You have high blood pressure. You need to monitor it regularly and possibly take medication.Z
condition9ZMigrainez`You are suffering from a migraine. You need rest and possibly medication to manage the symptoms.Zcondition10ZAsthmar   z_You have been diagnosed with Asthma. Regular use of inhalers and avoiding triggers is required.Zcondition11zHeart Diseaser,   zfYou have been diagnosed with heart disease. Lifestyle changes, medication, or surgery may be required.Zcondition15Z	ArthritiszVYou have been diagnosed with Arthritis. Pain management and physical therapy can help.Zcondition16ZGastroenteritiszSYou have gastroenteritis. Rest, fluid intake, and possibly medication are required.)r6   )Ú
conditionsr
   r
   r   ÚgetHealthConditionsÀ   s    	órI   c                   @   s   e Zd ZdZddd„ZdS )Ú
HabitClassa`  
    Represents a habit (positive or negative) that a character can have.

    Attributes:
        name: Habit identifier
        description: Descriptive text about the habit
        type: Always "habit"
        habitType: "positive" or "negative"
        status: "active" or "quitting"
        quitProgress: Days of progress when quitting (0-30)
    Únegativec                 C   s(   || _ || _d| _|| _d| _d| _d S )NÚhabitÚactiver   )Únamer9   ÚtypeÚ	habitTypeÚstatusÚquitProgress)r;   rN   r9   rP   r
   r
   r   r<   ê   s    zHabitClass.__init__N)rK   r=   r
   r
   r
   r   rJ   Þ   s   rJ   Ú	tardinessz0Your lack of punctuality is becoming noticeable.Únail_bitingz;You catch yourself biting your nails. It's a nervous habit.Úoverthinkingz/You can't help but overanalyze every situation.Úprocrastinationz1You tend to put things off until the last minute.Únegative_thinkingz3You're struggling to keep negative thoughts at bay.Ú
overeatingzpYour tiredness is making you reach for comfort foods. You're overeating and it's not making you feel any better.Úunder_exercisingz.You haven't been getting much exercise lately.Úexcessive_screen_timez2You're spending too much time in front of screens.Úimpulsivenessz;You have a tendency to act without thinking things through.Úindecisivenessz1You struggle with making decisions, big or small.Úneglecting_self_carez?You haven't been taking care of yourself as much as you should.Úpoor_time_managementz&You're always running behind schedule.Úovereating_when_stressedz,Stress pushes you to eat more than you need.Úexcessive_caffeine_intakez(You've been consuming too much caffeine.Úsmokingz5The habit of smoking is taking a toll on your health.Úexcessive_alcohol_consumptionzTExhaustion sets in and you find yourself reaching for a drink more often than usual.)rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   Úpunctualityz4Your punctuality is appreciated by those around you.ÚpositiveÚregular_exercisez2Your commitment to regular exercise is paying off.Úhealthy_eatingz"You feel better when you eat well.Úpositive_thinkingz4Your positive mindset helps you overcome challenges.Úplanning_aheadz#Planning ahead makes life smoother.Úprioritizing_self_carez+Taking care of yourself improves your mood.Úeffective_time_managementz6Your time management skills keep things under control.Úpracticing_gratitudez,Practicing gratitude makes you feel happier.Úmindfulness_meditationz&Meditation helps keep your mind clear.Úregular_sleeping_schedulez9Maintaining a regular sleep schedule keeps you refreshed.Úactive_listeningz3You understand others better by actively listening.Úshowing_empathyz,Showing empathy builds strong relationships.Útidyz-Keeping things tidy helps your peace of mind.Úhygienicz%Your hygiene habits keep you healthy.Úwork_life_balancez5Balancing work and personal time keeps you satisfied.)rc   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   c                    s¬   ddddddddddddd	ddd
œ‰ d}| j dk r@t| j d ƒ}t tt ¡ ƒt d|¡¡‰|tˆƒ }‡ ‡fdd„t	 ¡ D ƒ}t |t
t d|¡t|ƒƒ¡}ˆ| | _| S )a  
    Initialize habits for a person based on age.
    Assigns random negative and non-conflicting positive habits.

    Args:
        person: Person object with ageYears and habits attributes

    Returns:
        person: Updated person object with habits assigned
    rc   rg   rh   rf   re   rr   ri   rj   rm   )rS   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   é   é   rD   r   c                    s&   g | ]}|‡ fd d„ˆD ƒvr|‘qS )c                    s   g | ]}t  ˆ  |¡¡‘qS r
   )Únegative_habitsÚget)Ú.0Znegative_habit)Úhabit_pairsr
   r   Ú
<listcomp>=  ó    z(setHabits.<locals>.<listcomp>.<listcomp>r
   )rw   rL   ©rx   Zperson_negative_habitsr
   r   ry   =  rz   zsetHabits.<locals>.<listcomp>)r-   Úroundr3   ÚsampleÚlistru   Úvaluesr4   ÚlenÚpositive_habitsÚminÚhabits)r   ZhabitCntZnon_conflicting_positive_habitsZperson_positive_habitsr
   r{   r   Ú	setHabits  s2    ñ

r„   c                 C   sh   t | jjƒD ]V\}}|j|krd| jj| _| j d| dd¡ ¡  d ¡ ddl	m
} || jƒ qdS )	z¦
    Start the process of quitting a habit.

    Args:
        player: Player object with character (c) and messageQueue
        habit: Name of the habit to quit
    Úquittingz"You have decided to try quitting "Ú_Ú ú". r   ©ÚgetPeakEnergyN)Ú	enumerater2   rƒ   rN   rQ   r#   r$   Úreplacer8   Ústats.stats_managerrŠ   ©r   rL   ÚindexÚitemrŠ   r
   r
   r   Ú	quitHabitG  s    	
 r‘   c                 C   sv   t | jjƒD ]d\}}|j|krd| jj| _d| jj| _| j d| dd¡ 	¡  d ¡ ddl
m} || jƒ qdS )	z¸
    Stop trying to quit a habit and reset progress.

    Args:
        player: Player object with character (c) and messageQueue
        habit: Name of the habit to stop quitting
    rM   r   z)You have decided to stop trying to quit "r†   r‡   rˆ   r‰   N)r‹   r2   rƒ   rN   rQ   rR   r#   r$   rŒ   r8   r�   rŠ   rŽ   r
   r
   r   ÚstopQuitHabitY  s    	
 r’   c                 C   sp   |j D ]d}|jdkr| jd7  _tdt|jƒ ƒ |jdkr|j  |¡ | j d¡ ddlm	} ||ƒ qdS )	zº
    Process habit quitting progress. After 30 days, habit is successfully quit.

    Args:
        player: Player object for message queue
        person: Person object with habits
    r…   r   zHabit: r+   z&You have successfully quit your habit!r   r‰   N)
rƒ   rQ   rR   ÚprintÚstrÚremover#   r$   r�   rŠ   )r   r   rL   rŠ   r
   r
   r   ÚhandleHabitChangesl  s    


r–   )rA   r3   r   r   r   r   r!   r'   r.   r1   r5   r6   rI   rJ   ru   r�   r„   r‘   r’   r–   r
   r
   r
   r   Ú<module>   sb   	"ð














ñ-