
    Ii=/                    2   S r SSKJr  SSKJr  SSKJrJrJrJ	r	J
r
  SSKJr  \(       a  SSKJrJr  SS jr      SS	 jrSS
 jr          SS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jr        SS jr        SS jrSS jrg)zEvent processing system for Age of Heroes.

Handles mandatory events like Population Growth, Earthquake, Eruption,
Hunger, and Barbarians.
    )annotations)TYPE_CHECKING   )CardCardTypeResourceType	EventTypeget_card_name)	GamePhase)AgeOfHeroesGameAgeOfHeroesPlayerc                   UR                   (       d  gU R                  S:  =(       d    U R                  [        R                  :H  n[        X5      n[        U5       H<  u  pEnUR                  R                  U5      nU R                  R                  U5        M>     U H  u  pen[        XXX5        M     U R                  U5        g)a  Process mandatory events for a player.

Pascal behavior:
- Round 1: Only Population Growth has effect, other disasters just discard
- Round 2+: Population Growth effect, Hunger/Barbarians effects apply,
  Earthquake/Eruption are targetable (just discard here, play later)
Nr   )tribe_statecurrent_dayphaser   PLAY_collect_player_eventsreversedhandpopdiscard_pileappend_apply_player_event_effect_check_elimination)	gameplayereffects_activeevents_to_processicard_removedeffect_types	            >c:\Users\dbart\PlayPalace11\server\games\ageofheroes\events.pyprocess_player_eventsr%      s      %%)ITZZ9>>-IN /vF 01
++//!$  ) 2
 !2"4C !2 	F#    c                    / n[        U R                  5       HC  u  p4UR                  5       (       d  M  [        XA5      nU(       d  M0  UR	                  X4U45        ME     U$ )z2Collect mandatory events that should be processed.)	enumerater   is_mandatory_event_get_event_effect_typer   )r   r   r   r   r    r#   s         r$   r   r   5   s[     68V[[)&&((,TB;$$a{%;< * r&   c                   U R                   [        R                  :X  a  gU R                   [        R                  :X  a  U(       d  S$ S$ U R                   [        R                  :X  a  U(       d  S$ S$ U R                   [        R
                  :X  a  U(       a  S$ S$ U R                   [        R                  :X  a  U(       a  S$ S$ g)	zDDetermine which effect should be applied for a mandatory event card.population_growth
earthquakeNeruptionhunger_effecthunger_discardbarbarians_effectbarbarians_discard)subtyper	   POPULATION_GROWTH
EARTHQUAKEERUPTIONHUNGER
BARBARIANS)r    r   s     r$   r*   r*   C   s    ||y222"||y+++#1|;t;||y)))!/z9T9||y'''"0F6FF||y+++&4"N:NNr&   c                    US:X  a  [        X5        gUS;   a  [        XU5        gUS:X  a  [        X5        gUS:X  a  [        X5        gg)z1Apply the per-card event effect after discarding.r,   N>   r.   r-   r0   r2   r/   r1   )_apply_population_growth_announce_event_discardapply_hunger_effectapply_barbarians_effect)r   r   r    r#   s       r$   r   r   R   sZ     )) .XXd3o%D)))- *r&   c                    U R                   S::  d  UR                  (       d  gUR                  =R                  S-  sl        U =R                   S-  sl         U R                  USS5        U R	                  S5        g)z"Apply the population growth bonus.r   Nr   z!ageofheroes-population-growth-youzageofheroes-population-growthzgame_ageofheroes/build.ogg)city_supplyr   citiesbroadcast_personal_l
play_sound)r   r   s     r$   r:   r:   g   si    1F$6$6
"+'
 	OO01r&   c                    U R                  U5      nU(       a%  [        X#R                  5      nUR                  SUS9  [	        XU5        g)z"Announce discarding an event card.zageofheroes-discard-card-your    N)get_userr
   localespeak_l_broadcast_discard)r   r   r    user	card_names        r$   r;   r;   u   s<    == D!$4	3)DtT*r&   c                    UR                    H5  nUR                  [        R                  :X  d  M#  UR                  U:X  d  M5    g   g)z*Check if player has a specific event card.TF)r   	card_typer   EVENTr3   )r   r   
event_typer    s       r$   player_has_cardrO   ~   s3    >>X^^+
0J  r&   c                T   [        UR                  5       GH  u  p4UR                  [        R                  :X  d  M&  UR
                  U:X  d  M8  UR                  R                  U5      nU R                  R                  U5        U R                  U5      nU(       a%  [        XVR                  5      nUR                  SUS9  U R                   HT  nX:w  d  M
  U R                  U5      n	U	(       d  M$  [        XYR                  5      nU	R                  SUR                  US9  MV       g   g)zHDiscard a specific event card from player's hand. Returns True if found.zageofheroes-block-with-card-yourD   zageofheroes-block-with-cardr   r    TF)r(   r   rL   r   rM   r3   r   r   r   rE   r
   rF   rG   playersname)
r   r   rN   r   r    r"   rI   rJ   p
other_users
             r$   discard_player_cardrV      s    V[[)>>X^^+
0Jkkooa(G$$W- ==(D)';;?	>YO\\;!%q!1J!z$1';L;L$M	"**9#);;!* +  " + *, r&   c                   U R                  S5        U R                  S5        U R                  5        GH=  nSSKJn  [        X#5      (       d  M  UR                  (       d  M/  [        X[        R                  5      (       a  [        X[        R                  5        Mj  [        UR                  5       H  u  pEUR                  [        R                  :X  d  M%  UR                   ["        R$                  :X  d  ME  UR                  R'                  U5      nU R(                  R+                  U5        U R-                  U5      nU(       a%  [/        XgR0                  5      nUR3                  SUS9    GM;     GM@     g)zUApply Hunger effect: ALL players lose 1 Grain card.

Can be blocked by Fortune card.
zageofheroes-hunger-strikesgame_ageofheroes/disaster.oggr   )r   zageofheroes-lose-card-hungerrD   N)broadcast_lrB   get_active_playersr   r   
isinstancer   rO   r	   FORTUNErV   r(   r   rL   r   RESOURCEr3   r   GRAINr   r   r   rE   r
   rF   rG   )	r   source_playerr   r   r   r    r"   rI   rJ   s	            r$   r<   r<      s   
 	12OO34))++&44!! 4):):;;i.?.?@ !-GA~~!2!22t|||GYGY7Y ++//!,!!((1}}V, -g{{ CILL!?iLP . ,r&   c                >   UR                   (       d  gU R                  USS5        U R                  S5        [        X[        R
                  5      (       a  [        X[        R
                  5        g[        X[        R                  5      (       a  [        X[        R                  5        gSnUS:  a  Sn[        UR                  5       H  u  pEUR                  [        R                  :X  d  M%  UR                  [        R                  :w  d  ME  UR                  R!                  U5      nU R"                  R%                  U5        US-  nU R'                  U5      nU(       a%  [)        XgR*                  5      nUR-                  S	US
9  Sn  O   U(       d  gUS:  a  M  gg)zrApply Barbarians effect: player loses 2 conventional resource cards.

Can be blocked by Fortune or Olympics card.
Nz!ageofheroes-barbarians-attack-youzageofheroes-barbarians-attackrX   r      Fr   z ageofheroes-lose-card-barbariansrD   T)r   rA   rB   rO   r	   r\   rV   OLYMPICSr(   r   rL   r   r]   r3   r   GOLDr   r   r   rE   r
   rF   rG   )	r   r   
lost_countfoundr   r    r"   rI   rJ   s	            r$   r=   r=      sI   
 35T 	OO34 tY%6%677D)*;*;< tY%7%788D)*<*<= J
q. -GA~~!2!22t|||GXGX7X ++//!,!!((1a
}}V, -g{{ CILL!C)LT .  q.r&   c                `   UR                   [        R                  :w  a  gU R                  [        R
                  :w  a  U R                  S::  a  gUR                  [        R                  :X  aR  [        X5        X!R                  ;   a7  UR                  R                  U5        U R                  R                  U5        ggUR                  [        R                  :X  aR  [!        X5        X!R                  ;   a7  UR                  R                  U5        U R                  R                  U5        ggg)zCheck if a drawn card triggers an immediate event.

Pascal behavior: Hunger and Barbarians trigger immediately when drawn
during Play phase or after round 1.
Nr   )rL   r   rM   r   r   r   r   r3   r	   r7   r<   r   remover   r   r8   r=   )r   r   r    s      r$   check_drawn_card_eventrh      s     ~~' zzY^^#(8(8A(=||y'''D);;KKt$$$T*  
--	--;;KKt$$$T*  
.r&   c                   UR                   (       d  gU R                  USSUR                  S9  U R                  S5        [	        X[
        R                  5      (       a  [        X[
        R                  5        gUR                   R                  5       nUS:  a:  X2R                   l	        U R                  U5      nU(       a  UR                  SUS9  ggg)	zApply Earthquake effect: Target player's armies are disabled for one turn.

Armies become 'earthquaked' and cannot be used until next turn.
Can be blocked by Fortune card.
Nz"ageofheroes-earthquake-strikes-youzageofheroes-earthquake-strikesattackerrX   r   zageofheroes-armies-disabled)count)r   rA   rS   rB   rO   r	   r\   rV   get_available_armiesearthquaked_armiesrE   rG   )r   r_   target_playeravailable_armiesrI   s        r$   apply_earthquake_effectrq   
  s     $$,(##	   	OO34 tI,=,=>>D1B1BC %00EEG!7G!!4}}]+LL6>NLO 	 r&   c                \   UR                   (       d  gU R                  USSUR                  S9  U R                  S5        [	        X[
        R                  5      (       a  [        X[
        R                  5        g[	        X[
        R                  5      (       a  [        X[
        R                  5        gUR                   R                  S:  a_  UR                   =R                  S-  sl	        U =R                  S-  sl
        U R                  U5      nU(       a  UR                  S5        ggg)	zbApply Eruption effect: Target player loses one city.

Can be blocked by Fortune or Olympics card.
Nz ageofheroes-eruption-strikes-youzageofheroes-eruption-strikesrj   rX   r   r   zageofheroes-city-destroyed)r   rA   rS   rB   rO   r	   r\   rV   rb   r@   r?   rE   rG   )r   r_   ro   rI   s       r$   apply_eruption_effectrs   ,  s     $$*&##	   	OO34 tI,=,=>>D1B1BC tI,>,>??D1C1CD   ''!+!!((A-(A}}]+LL56  ,r&   c                    U R                    HT  nX1:X  a  M
  U R                  U5      nU(       d  M$  [        X$R                  5      nUR	                  SUR
                  US9  MV     g)z(Broadcast card discard to other players.zageofheroes-discard-cardrQ   N)rR   rE   r
   rF   rG   rS   )r   r   r    rT   rI   rJ   s         r$   rH   rH   R  sP    \\;}}Q4%dKK8ILL3FKKiLX r&   N)r   r   r   r   returnNone)r   r   r   boolru   zlist[tuple[int, Card, str]])r    r   r   rw   ru   z
str | None)
r   r   r   r   r    r   r#   strru   rv   )r   r   r   r   r    r   ru   rv   )r   r   r   r   rN   rx   ru   rw   )r   r   r_   r   ru   rv   )r   r   r_   r   ro   r   ru   rv   )__doc__
__future__r   typingr   cardsr   r   r   r	   r
   stater   r   r   r   r%   r   r*   r   r:   r;   rO   rV   r<   r=   rh   rq   rs   rH    r&   r$   <module>r      s    #    8$</3 
  	
 
*2+6D(V+8P
P*;PL]P	PD#7
#7*;#7L]#7	#7LYr&   