Skip to content

Commit

Permalink
Fix an issue with TimedDrop.can_earn_within not ignoring sub-based drops
Browse files Browse the repository at this point in the history
  • Loading branch information
DevilXD committed Sep 11, 2024
1 parent 84d0dc1 commit c7b89ca
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,27 @@ def _all_preconditions(self) -> set[str]:
)
)

def _base_can_earn(self) -> bool:
def _base_earn_conditions(self) -> bool:
# define when a drop can be earned or not
return (
self.preconditions_met # preconditions are met
and not self.is_claimed # isn't already claimed
)

def _base_can_earn(self) -> bool:
# cross-participates in can_earn and can_earn_within handling, where a timeframe is added
return (
self._base_earn_conditions()
# is within the timeframe
and self.starts_at <= datetime.now(timezone.utc) < self.ends_at
)

def can_earn(self, channel: Channel | None = None) -> bool:
return self.campaign._base_can_earn(channel) and self._base_can_earn()
return self._base_can_earn() and self.campaign._base_can_earn(channel)

def can_earn_within(self, stamp: datetime) -> bool:
return (
self.preconditions_met # preconditions are met
and not self.is_claimed # isn't already claimed
self._base_earn_conditions()
and self.ends_at > datetime.now(timezone.utc)
and self.starts_at < stamp
)
Expand Down Expand Up @@ -226,8 +232,8 @@ def progress(self) -> float:
return 1.0
return self.current_minutes / self.required_minutes

def _base_can_earn(self) -> bool:
return self.required_minutes > 0 and super()._base_can_earn()
def _base_earn_conditions(self) -> bool:
return super()._base_earn_conditions() and self.required_minutes > 0

def _on_claim(self) -> None:
result = super()._on_claim()
Expand Down

0 comments on commit c7b89ca

Please sign in to comment.