from .base import Plant
from ...config import CELL_W, CELL_H

class VineTrap(Plant):
    def __init__(self, col, row):
        super().__init__(col, row, "vine_trap")
        self.hp = 500
        self.max_hp = 500
        self.shoot_interval = 0
        self.cost = 125
        self.life_timer = 0

    def update(self, dt, game_state):
        if getattr(self, 'coffee_boosted', False):
            self.sleep_timer = 0
        if self.sleep_timer > 0:
            self.sleep_timer -= dt
            return

        self.life_timer += dt
        if self.life_timer >= 15.0:
            self.active = False
            return

        # Apply slow to zombies in 3x3 area
        cx = self.col
        cy = self.row
        
        for z in game_state.zombies:
            z_col = int((z.x + z.w/2) / CELL_W)
            z_row = z.row
            
            if abs(z_col - cx) <= 1 and abs(z_row - cy) <= 1:
                z.apply_slow(0.2, 0.5) # 0.2s duration (refreshed every frame), 50% speed
