def post(self): user = users.get_current_user() if not user: self.redirect("/") player = doo.getplayerbyuser(user) if not player: player = doo.makeplayer(user.nickname(), user=user) stuffname = self.request.get('stuffname') if not stuffname: self.error(404) return solidstuff = doo.getsolidstuffbystuffname(stuffname) amount = int(self.request.get('amount')) if not amount: self.error(404) return doo.makepurchaseprogress(player.playerid, stuffname, amount, amount) taskqueue.add(url='/tasks/makepurchase', params={'stuffname': stuffname, 'amount': amount, 'playerid': player.playerid})
def post(self): stuffname = self.request.get('stuffname') amount = int(self.request.get('amount')) beginningamount = amount playerid = self.request.get('playerid') stuff = doo.getstuffbyname(stuffname) solidstuff = stuff.getsolidstuff() solidinvestment = stuff.getsolidinvestment() tax = stuff.price * solidstuff.gettax() player = doo.getplayer(playerid) myplayerstuff = player.getplayerstuffbystuffid(stuff.stuffid) if amount > stuff.getforsaleminusplayer(player): doo.makealert(player, "You asked to buy more than are for sale. There are currently %s for sale." % (stuff.getforsaleminusplayer(player))) #self.error(404) doo.deletepurchaseprogress(player.playerid, stuffname) return False if round(player.money, 2) < round((stuff.price * amount), 2): doo.makealert(player, "You don't have enough money") #self.error(404) doo.deletepurchaseprogress(player.playerid, stuffname) return False sips = solidinvestment.getplayerstuffbystuffid(stuff.stuffid) # sips = solid investment player stuff # track mplogger.track("make-purchase", {"stuffname": stuff.name, "amount": amount}) try: myplayerstuff.lastprice = stuff.price if sips.forsale <= amount: amount -= sips.forsale stuff.forsale -= sips.forsale myplayerstuff.total += sips.forsale sips.total -= sips.forsale solidinvestment.money += stuff.price * sips.forsale solidinvestment.taxes += tax * sips.forsale solidinvestment.taxes = round(solidinvestment.taxes, 2) solidinvestment.money = round(solidinvestment.money, 2) solidinvestment.points += int((stuff.price * sips.forsale) / 10) player.money -= stuff.price * sips.forsale player.money = round(player.money, 2) player.points += int((stuff.price * sips.forsale) / 10) sips.forsale = 0 # last thing sips.put() else: # they have more than you're asking for sips.forsale -= amount stuff.forsale -= amount myplayerstuff.total += amount sips.total -= amount solidinvestment.money += stuff.price * amount solidinvestment.taxes += tax * amount solidinvestment.taxes = round(solidinvestment.taxes, 2) solidinvestment.money = round(solidinvestment.money, 2) solidinvestment.points += int((stuff.price * amount) / 10) player.money -= stuff.price * amount player.money = round(player.money, 2) player.points += int((stuff.price * amount) / 10) amount = 0 # last thing sips.put() if amount > 0: playerstuffs = doo.getplayerstuffsforpurchase(stuff.stuffid, playerid) for ps in playerstuffs: if ps.playerid == player.playerid: continue if ps.playerid == solidinvestment.playerid: continue if ps.forsale <= amount: # they have less than or equal to the amount you ask for amount -= ps.forsale stuff.forsale -= ps.forsale myplayerstuff.total += ps.forsale ps.total -= ps.forsale seller = doo.getplayer(ps.playerid) seller.money += (stuff.price - tax) * ps.forsale seller.money = round(seller.money, 2) seller.points += int((stuff.price * ps.forsale) / 10) seller.put() player.money -= stuff.price * ps.forsale player.money = round(player.money, 2) player.points += int((stuff.price * ps.forsale) / 10) solidinvestment.money += tax * ps.forsale solidinvestment.taxes += tax * ps.forsale solidinvestment.taxes = round(solidinvestment.taxes, 2) doo.message(seller, "You sold %s %s to %s for %s each." % (ps.forsale, stuff.name, player.name, stuff.getpricedisplay())) ps.forsale = 0 # last thing ps.put() else: # they have more than you're asking for ps.forsale -= amount stuff.forsale -= amount myplayerstuff.total += amount ps.total -= amount seller = doo.getplayer(ps.playerid) seller.money += (stuff.price - tax) * amount seller.money = round(seller.money, 2) seller.points += int((stuff.price * amount) / 10) seller.put() player.money -= stuff.price * amount player.money = round(player.money, 2) player.points += int((stuff.price * amount) / 10) solidinvestment.money += tax * amount solidinvestment.taxes += tax * amount solidinvestment.taxes = round(solidinvestment.taxes, 2) doo.message(seller, "You sold %s %s to %s for %s each." % (amount, stuff.name, player.name, stuff.getpricedisplay())) amount = 0 # last thing ps.put() if amount == 0: break except: doo.deletepurchaseprogress(player.playerid, stuffname) return finally: player.put() myplayerstuff.put() solidinvestment.money = round(solidinvestment.money, 2) solidinvestment.put() stuff.put() if amount != 0: doo.makepurchaseprogress(player.playerid, stuffname, beginningamount, amount) taskqueue.add(url='/tasks/makepurchase', params={'stuffname': stuffname, 'amount': amount, 'playerid': player.playerid}) else: doo.deletepurchaseprogress(player.playerid, stuffname)