a
    w^i«6  ã                   @   s’   d Z ddlZddlZddlmZ ddlmZ ddlmZ G dd„ dƒZ	dd	„ Z
d
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )aÂ  
Relationship Manager Module

This module contains all relationship management functions for the BaoLife game.
It handles romantic relationships, dating activities, affinity updates, and
relationship data management.

Functions:
    - updateAffinity: Updates affinity score for a person
    - handleRelationships: Manages relationship events and score updates
    - getRelData: Fetches relationship data by person ID
    - romance: Initiates a romantic relationship with a target
    - getActiveRelationship: Returns the active dating/married relationship
    - breakUp: Ends a relationship with a partner
    - partnerGift: Gives a gift to partner to increase affinity
    - dateNight: Executes a date night activity with partner

Classes:
    - DateIdea: Represents a date activity with costs and rewards

Imports:
    - relationshipClass: Imported from core.models
    - get_person: Imported from character.character_manager

Author: BaoLife Development Team
é    N)ÚmessageFunction)ÚrelationshipClass)Ú
get_personc                   @   s   e Zd ZdZddd„ZdS )ÚDateIdeaad  
    Represents a date activity option with associated costs and benefits.

    Attributes:
        name: Name of the date activity
        energy_cost: Energy points required for this activity
        money_cost: Money cost for this activity
        message: Description message shown to player
        image: URL to image representing this date type
    Nc                 C   s"   || _ || _|| _|| _|| _d S )N)ÚnameÚenergy_costÚ
money_costÚmessageÚimage)Úselfr   r   r   r	   r
   © r   úC/var/www/lichun.app/lichun/ws/relationships/relationship_manager.pyÚ__init__8   s
    zDateIdea.__init__)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   -   s   
r   c                 C   s6   | j D ]*}|j|ks(|j|ks(|j|kr|  S qdS )zý
    Fetch relationship data based on person1 or person2 id.

    Args:
        player: The player object
        person_id: The ID of the person you are searching for in the relationships

    Returns:
        Relationship data if found, else None
    N)ÚrelDataÚperson1Úperson2Úid)ÚplayerZ	person_idÚrelr   r   r   Ú
getRelDataD   s    

r   c                 C   s,   | j D ] }|jdks|jdkr|  S qdS )zË
    Get the player's current active romantic relationship.

    Args:
        player: The player object

    Returns:
        Active relationship (Dating or Married status) if found, None otherwise
    ÚDatingÚMarriedN)r   ÚrelationshipStatus)r   r   r   r   r   ÚgetActiveRelationshipU   s    


r   c                 C   s:   t | jƒD ]*\}}|j|kr
| j| j| | j| _q
| S )a9  
    Update the affinity score for a specific person in the player's relationships.

    Args:
        player: The player object
        id: The ID of the person whose affinity to update
        value: The amount to change affinity by (can be positive or negative)

    Returns:
        Updated player object
    )Ú	enumerateÚrr   Úaffinity)r   r   ÚvalueÚindexÚitemr   r   r   ÚupdateAffinityi   s    
r$   c                 C   sÄ   t  dd¡}t| |jƒ}|s dS |dkr€t  g d¢¡}|j |¡ |dkrZ| jd7  _n&|dkrr| jd8  _n| jd	7  _| jd7  _|jd
k r¨| jd7  _n|jdkrÀ| jd8  _dS )aÊ  
    Handle relationship events and score updates for a person.

    This function:
    - Has a 5% chance of triggering random relationship events
    - Updates relationship score weekly
    - Applies correction mechanism to keep scores balanced

    Args:
        player: The player object
        person: The person object to handle relationship with

    Returns:
        False if no relationship data exists, otherwise modifies relationship in place
    é   éd   Fé_   )úWent on a romantic tripúHad a disagreementzMet with friendsr(   é
   r)   é   é(   é   é<   N)ÚrandomÚrandintr   r   ÚchoiceÚ	eventsLogÚappendÚrelationshipScore)r   ÚpersonZevent_chancer   Úeventr   r   r   ÚhandleRelationships{   s"    

r7   c                 C   sŒ   t | |ƒ}|rˆ|jdkrˆt| jj|j| jddƒ}| j |¡ |j| j_|j|_| j	 d|j
 d |j d ¡ ddlm} ||d	ƒ d
S dS )a\  
    Attempt to start a romantic relationship with a target person.

    Checks if the target has sufficient affinity (>= 50) and creates a new
    relationship if successful.

    Args:
        player: The player object
        partner: The ID of the person to romance

    Returns:
        True if romance attempt successful, False otherwise
    é2   ZProspectzYou are now dating.z You have attempted a romance of Ú Ú.r   ©Úapply_event_modifiersZstart_datingTF)r   r    r   Úcr   Údater   r3   ÚrelationshipÚmessageQueueÚ	firstnameÚlastnameÚmessaging_styler<   )r   ÚpartnerZromanticTargetr?   r<   r   r   r   Úromance¨   s    


 
rE   c                 C   sP   | j D ]D}|j|krd|_d| j_| j d¡ ddlm} ||dƒ  dS qdS )	zÜ
    End a romantic relationship with a partner.

    Args:
        player: The player object
        partner: The ID of the partner to break up with

    Returns:
        True if breakup successful, False otherwise
    zBroke UpNzYou dumped your partner.r   r;   ZbreakupTF)	r   r   r   r=   r?   r@   r3   rC   r<   )r   rD   r   r<   r   r   r   ÚbreakUpÊ   s    


rF   c                 C   s    | j D ]”}|j|kr| jjdkr”| j jd8  _dt dd¡ }t| |ƒ}| j|7  _dt|ƒ d }d}| j	 
|¡ td|| d	d
|d|d�  S  dS qdS )a2  
    Give a gift to your partner to increase affinity.

    Costs $100 and increases affinity by 6-15 points.

    Args:
        player: The player object
        partner: The ID of the partner to give gift to

    Returns:
        messageEvent if successful, False if player doesn't have enough money
    r&   r+   r%   r*   z,You bought a gift for your partner, gaining z
 affinity.z1https://lichun.app/assets/images/partnerGift.jpegÚpartnerGiftTZGift)Útitler
   Ú	moneyCostÚaffinityChangeFN)r   r   r=   Úmoneyr/   r0   r   r    Ústrr@   r3   r   )r   rD   r   Zgainedr	   Z	imageLinkr   r   r   rG   å   s    


rG   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,ƒg
} | S )-zˆ
    Get all available date activity options.

    Returns:
        List of DateIdea objects representing different date activities
    úPicnic in the Parkr-   é   ú*You enjoyed a relaxing picnic in the park.z/https://lichun.app/assets/images/picnicDate.pngúMovie Night at Homer%   r   ú#You had a cozy movie night at home.z.https://lichun.app/assets/images/dateNight.pngúHiking Adventureé   r*   ú1You embarked on an exhilarating hiking adventure.z/https://lichun.app/assets/images/hikingDate.pngúFine Dining Experiencer&   ú*You had a romantic fine dining experience.z3https://lichun.app/assets/images/fineDiningDate.pngúVisit a Museum or Art Galleryr8   ú$You visited a museum or art gallery.z/https://lichun.app/assets/images/museumDate.pngúCooking Class TogetheréF   ú"You took a cooking class together.z0https://lichun.app/assets/images/cookingDate.pngúAmusement Park Dayé   éx   ú(You had a fun day at the amusement park.z6https://lichun.app/assets/images/amusementParkDate.pngú	Beach Dayé   úYou spent the day at the beach.z.https://lichun.app/assets/images/beachDate.pngúAttend a Concert or Showé–   úYou attended a concert or show.z0https://lichun.app/assets/images/concertDate.pngúSpa Day for RelaxationéÈ   úYou enjoyed a relaxing spa day.z,https://lichun.app/assets/images/spaDate.png)r   )Z
date_ideasr   r   r   ÚgetDateIdeas	  s    öri   c                 C   sª  t ƒ D �]œ}|j|kr| jj|jk�rž| jj|jk�ržt| ƒ}t 	dd¡}| j
|7  _
|j d|j› d�¡ | j j|j8  _| j j|j8  _| j jd7  _d|j› d�}|dkr¾d}n†|dkrÌd	}nx|d
krÚd}nj|dkrèd}n\|dkröd}nN|dk�rd}n>|dk�rd}n.|dk�r&d}n|dk�r6d}n|dk�rDd}|d|j› d|j› d�7 }|d|› d�7 }| j |¡ td|| d d!|j|jd"|jd"ƒ
  S  d#S qd$S )%a«  
    Execute a date night activity with the player's partner.

    Checks if player has sufficient energy and money, then:
    - Increases relationship score
    - Deducts energy and money costs
    - Adds prestige
    - Creates a message event

    Args:
        player: The player object
        idea: The name of the date idea to execute

    Returns:
        messageEvent if successful, False if player lacks resources
    r%   r*   zYou went on a 'z' date.r+   rM   rO   rP   rQ   rR   rT   rU   rV   rW   rX   rY   r[   r\   r_   r`   rb   rc   re   rf   rh   z You spent z energy and z money.z& Your relationship score increased by z points.Ú	dateNightTz
Date Nightr   FN)ri   r   r=   Úenergyr   rK   r   r   r/   r0   r4   r2   r3   Úprestiger@   r   r
   )r   ZideaZdateIdear?   Zscore_changer	   r   r   r   rj     sH    
 




$rj   )r   r/   ÚuuidÚeventsr   Úcore.modelsr   Úcharacter.character_managerr   r   r   r   r$   r7   rE   rF   rG   ri   rj   r   r   r   r   Ú<module>   s   -"$