a
    w^i6                     @   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rt 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rt| 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 TogetherF   "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rt| }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rd}n|dkrd	}nx|d
krd}nj|dkrd}n\|dkrd}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   -"$