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   UnderweightF   ZNormalZ   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rd|_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rd| _| 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*><   gh㈵>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   	"














-