def usepower(self, amount): query = PlayerStuff.all() query.filter("playerid =", self.playerid) stuffid = doo.getstuffbyname('Power').stuffid query.filter("stuffid = ", stuffid) ps = query.get() if not ps: return False if amount <= ps.forsale: ps.forsale -= amount ps.total -= amount amount = 0 else: if amount == ps.total: ps.forsale = 0 ps.total = 0 amount = 0 elif amount > ps.total: ps.forsale = 0 ps.total = 0 else: logging.info('I do not think this should ever happen') if amount != 0: # they have a problem doo.message(self, "You're out of power, which means you won't be able to make investments until you get more power.")
def getnumstuff(self, stuffname): query = PlayerStuff.all() query.filter("playerid =", self.playerid) stuffid = doo.getstuffbyname(stuffname).stuffid query.filter("stuffid = ", stuffid) ps = query.get() if ps: return ps.total else: return 0
def calculatenewstuffs(self): solidstuff = doo.getsolidstuffbyplayerid(self.playerid) stuff = doo.getstuffbyname(solidstuff.stuffname) should = int(self.totalinvestorsamount / solidstuff.ratio) needtocreate = int(should - solidstuff.count) if solidstuff.count + needtocreate > solidstuff.cap: needtocreate = solidstuff.cap - solidstuff.count #ingroup = 10 #groupnum = needtocreate / ingroup #rem = needtocreate % ingroup #logging.info('needtocreate: %s, %s, %s' % (needtocreate, should, stuff.name)) if needtocreate > 0: solidstuff.count += needtocreate solidstuff.put() stuff.total += needtocreate stuff.forsale += needtocreate stuff.put() self.addplayerstuff(stuff.stuffid, needtocreate)
def get(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('param') if not stuffname: self.error(404) return stuff = doo.getstuffbyname(stuffname) solidstuff = doo.getsolidstuffbystuffname(stuffname) playerstuff = player.getplayerstuffbystuffid(stuff.stuffid) if stuff.total: ownershippercent = '%.2f' % (float(playerstuff.total) / float(stuff.total) * 100) else: ownershippercent = '0.00' template_values = { 'stuff': stuff, 'player': player, 'playerstuff': playerstuff, 'ownershippercent': ownershippercent, 'solidstuff': solidstuff, } if player.mobile: templatefile = 'm_storebystuffname.html' else: templatefile = 'storebystuffname.html' path = os.path.join(os.path.dirname(__file__), templatefile) self.response.out.write(template.render(path, template_values))
def getstuff(self): return doo.getstuffbyname(self.stuffname)
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)