Skip to content

Commit

Permalink
♻️ use national_profit as the mechanism to calculate delta profit
Browse files Browse the repository at this point in the history
  • Loading branch information
YousefEZ committed Aug 24, 2024
1 parent c80c1cf commit 772413e
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions host/nation/bank.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,10 @@ def _update_treasury(self) -> None:
self.model.last_accessed = current_time
self._session.commit()

def _retrieve_revenue(self, delta: timedelta) -> Currency:
return self.national_revenue.amount_in_delta(delta)

def _retrieve_bill(self, delta: timedelta) -> Price:
return self.national_bill.amount_in_delta(delta)

def _retrieve_profit(self, delta: timedelta) -> Currency:
revenue: Currency = self._retrieve_revenue(delta)
expenses: Price = self._retrieve_bill(delta)
return revenue - expenses
return self.national_profit.amount_in_delta(delta)

def add(self, amount: Currency) -> None:
def _add(self, amount: Currency) -> None:
if amount < Currency(0):
raise ValueError("Cannot add negative funds")
logging.debug(f"Adding {amount} to {self._player.name}'s treasury, Previous: {self.funds}")
Expand Down Expand Up @@ -193,9 +185,9 @@ def send(self, amount: Price, target: FundReceiver) -> SendingResponses:
try:
target.receive(Currency(amount.amount))
except Exception as e:
self.add(Currency(amount.amount))
self._add(Currency(amount.amount))
raise e
return SendingResponses.SUCCESS

def receive(self, funds: Currency) -> None:
self.add(funds)
self._add(funds)

0 comments on commit 772413e

Please sign in to comment.