Add market transactions

This commit is contained in:
Nate Bowman
2026-11-07 19:56:09 -05:00
parent 4d9da78842
commit 5f1999caac
6 changed files with 195 additions and 1 deletions

View File

@@ -48,7 +48,6 @@ class World():
# reseeding of farms
# queuing of villagers
# possibly other things
# TODO use market for buy/sell
MAX_WORLD_TIME = 3*60*60 # 3 hours
@@ -60,6 +59,35 @@ class World():
self.gather.spend_resources(cost)
def market_buy(self, resource, amount):
self._use_market(resource, amount, buy=True)
def market_sell(self, resource, amount):
self._use_market(resource, amount, buy=False)
def _use_market(self, resource, amount, buy=True):
if amount % self.costs.market_transaction_amount != 0:
raise InvalidMarketAmountException
for i in range(amount//self.costs.market_transaction_amount):
cost = self.costs.compute_market_price(resource, buy=buy)
gold_amount = [0, 0, cost, 0]
resource_amount = [0, 0, 0, 0]
resource_amount[int(resource)] = self.costs.market_transaction_amount
if buy:
self.gather.spend_resources(gold_amount)
self.gather.acquire_resources_without_gather(resource_amount)
else:
self.gather.spend_resources(resource_amount)
self.gather.acquire_resources_without_gather(gold_amount)
self.costs.adjust_market_price(resource, buy=buy)
def has_building(self, building):
return building in self.buildings