Add market transactions
This commit is contained in:
29
aoe/world.py
29
aoe/world.py
@@ -60,6 +60,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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user