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