97 lines
2.6 KiB
Python
97 lines
2.6 KiB
Python
from app.models import Event, EventType
|
|
|
|
|
|
class PointsService:
|
|
"""Service for calculating points and penalties"""
|
|
|
|
STREAK_MULTIPLIERS = {
|
|
0: 0.0,
|
|
1: 0.0,
|
|
2: 0.1,
|
|
3: 0.2,
|
|
4: 0.3,
|
|
}
|
|
MAX_STREAK_MULTIPLIER = 0.4
|
|
|
|
DROP_PENALTIES = {
|
|
0: 0, # First drop is free
|
|
1: 10,
|
|
2: 25,
|
|
}
|
|
MAX_DROP_PENALTY = 50
|
|
|
|
# Event point multipliers
|
|
EVENT_MULTIPLIERS = {
|
|
EventType.GOLDEN_HOUR.value: 1.5,
|
|
EventType.DOUBLE_RISK.value: 0.5,
|
|
EventType.JACKPOT.value: 3.0,
|
|
EventType.REMATCH.value: 0.5,
|
|
}
|
|
|
|
def calculate_completion_points(
|
|
self,
|
|
base_points: int,
|
|
current_streak: int,
|
|
event: Event | None = None,
|
|
) -> tuple[int, int, int]:
|
|
"""
|
|
Calculate points earned for completing a challenge.
|
|
|
|
Args:
|
|
base_points: Base points for the challenge
|
|
current_streak: Current streak before this completion
|
|
event: Active event (optional)
|
|
|
|
Returns:
|
|
Tuple of (total_points, streak_bonus, event_bonus)
|
|
"""
|
|
# Apply event multiplier first
|
|
event_multiplier = 1.0
|
|
if event:
|
|
event_multiplier = self.EVENT_MULTIPLIERS.get(event.type, 1.0)
|
|
|
|
adjusted_base = int(base_points * event_multiplier)
|
|
event_bonus = adjusted_base - base_points
|
|
|
|
# Then apply streak bonus
|
|
streak_multiplier = self.STREAK_MULTIPLIERS.get(
|
|
current_streak,
|
|
self.MAX_STREAK_MULTIPLIER
|
|
)
|
|
streak_bonus = int(adjusted_base * streak_multiplier)
|
|
|
|
total_points = adjusted_base + streak_bonus
|
|
return total_points, streak_bonus, event_bonus
|
|
|
|
def calculate_drop_penalty(
|
|
self,
|
|
consecutive_drops: int,
|
|
event: Event | None = None
|
|
) -> int:
|
|
"""
|
|
Calculate penalty for dropping a challenge.
|
|
|
|
Args:
|
|
consecutive_drops: Number of drops since last completion
|
|
event: Active event (optional)
|
|
|
|
Returns:
|
|
Penalty points to subtract
|
|
"""
|
|
# Double risk event = free drops
|
|
if event and event.type == EventType.DOUBLE_RISK.value:
|
|
return 0
|
|
|
|
return self.DROP_PENALTIES.get(
|
|
consecutive_drops,
|
|
self.MAX_DROP_PENALTY
|
|
)
|
|
|
|
def apply_event_multiplier(self, base_points: int, event: Event | None) -> int:
|
|
"""Apply event multiplier to points"""
|
|
if not event:
|
|
return base_points
|
|
|
|
multiplier = self.EVENT_MULTIPLIERS.get(event.type, 1.0)
|
|
return int(base_points * multiplier)
|