Beispiel #1
0
    def post(self):
        playerid = self.request.get('playerid')
        amount = self.request.get('amount') # player.getnuminvestors()
        lastid = self.request.get('lastid')
        
        player = doo.getplayer(playerid)
        amount = round(float(amount), 2)
        
        numpi = 10
        
        query = PlayerInvestment.all()
        query.filter("investmentid =", player.playerid)
        if lastid:
            query.filter("playerid >", lastid)
        query.order("playerid")
        playerinvestments = query.fetch(numpi)
        
        for pi in playerinvestments:
            if not pi.amount:
                continue
            investor = doo.getplayer(pi.playerid)
            payout = round((player.money * player.growth) / amount, 2)

            investor.money += payout
            investor.money = round(investor.money, 2)
            
            investor.totalinvestedamount += payout
            investor.totalinvestedamount = round(investor.totalinvestedamount, 2)
            
            pi.amount += payout
            pi.amount = round(pi.amount, 2)
            
            player.money += payout
            player.money = round(player.money, 2)
            
            player.totalinvestorsamount += payout
            player.totalinvestorsamount = round(player.totalinvestorsamount, 2)

            pi.put()
            investor.put()
            
            #doo.message(investor, 'You received a dividend of %s from %s' % (payout, player.name))
        
        player.put()
        
        if len(playerinvestments) >= numpi:
            lastid = playerinvestments[-1].playerid
            taskqueue.add(url='/tasks/payoutgrowth', params={'amount': amount, 'playerid': playerid, 'lastid':lastid})
Beispiel #2
0
    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)
            
        toplayer = doo.getplayer(self.request.get('playerid'))
        if not toplayer:
            self.error(404)
            
        messagetext = self.request.get('messagetext')
        if not messagetext:
            self.error(404)
            return
            
        if player.money >= doo.getmessageprice() and not toplayer.solid:
            if not player.sendmessage(toplayer, messagetext):
                self.error(404)
                return
        else:
            self.error(404)
            return
Beispiel #3
0
    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)
            
        investment = doo.getplayer(self.request.get('param'))
        #totalinvestment = player.getinvestmentamount(investment.playerid)
        playerinvestment = doo.getplayerinvestment(player.playerid, investment.playerid)

        message = ''
        template_values = {
            'investment': investment,
            'playerinvestment': playerinvestment,
            'player': player,
            'message': message,
            }

        if player.mobile:
            templatefile = 'm_withdrawmoney.html'
        else:
            templatefile = 'withdrawmoney.html'
        path = os.path.join(os.path.dirname(__file__), templatefile)
        self.response.out.write(template.render(path, template_values))
Beispiel #4
0
    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)
            
        investmentamount = self.request.get('investmentamount')
        if investmentamount:
            investmentamount = round(float(investmentamount), 2)
        else:
            doo.makealert(player, 'eeeehhh, that amount does not compute, you\'re under arrest')
            self.error(404)
            return
        
        if not investmentamount:
            doo.makealert(player, 'eeeehhh, that amount does not compute, you\'re under arrest')
            self.error(404)
            return
        
        
        investment = doo.getplayer(self.request.get('investmentid'))

        if not player.addinvestment(investment, self.request.get('investmentamount')):
            self.error(404)
            return
Beispiel #5
0
 def playraffle(self):
     num = len(self.entries)
     if num < 1:
         return None
     winner = None
     while not winner:
         index = random.randrange(0, num, 1)
         winner = doo.getplayer(self.entries[index])
     
         
     towinner = round(float(self.fund * self.prizepercent), 2)
     tocharity = round(self.fund, 2) - round(towinner, 2)
     
     winner.money += round(float(towinner), 2)
     winner.money = round(winner.money, 2)
     doo.message(winner,
                   '''YOU WON THE RAFFLE!!! %s HAS BEEN DEPOSITED INTO YOUR ACCOUNT.
                   DON'T LET IT GO TO YOUR HEAD :)''' 
                   % (formattar.money(towinner)))
     winner.put()
     
     self.money += tocharity
     self.fund = 0.0
     self.entries = []
     self.stuffprize = None
     self.lastraffle = datetime.datetime.now()
     self.lastwinner = winner.playerid
     self.lastraffleprize = towinner
     self.put()
Beispiel #6
0
    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)
            
        toplayer = doo.getplayer(self.request.get('param'))
        if not toplayer:
            self.error(404)
        
        if toplayer.solid:
            return
            
        hasmoney = player.money >= doo.getmessageprice()
        
        messageprice = doo.getmessagepricedisplay()
        
        template_values = {
            'player': player,
            'toplayer': toplayer,
            'hasmoney': hasmoney,
            'messageprice': messageprice,
            }

        if player.mobile:
            templatefile = 'm_sendmessage.html'
        else:
            templatefile = 'sendmessage.html'
        path = os.path.join(os.path.dirname(__file__), templatefile)
        self.response.out.write(template.render(path, template_values))
Beispiel #7
0
    def post(self):
        playerid = self.request.get('playerid')
        amount = self.request.get('amount')
        lastid = self.request.get('lastid')
        
        player = doo.getplayer(playerid)
        amount = round(float(amount), 2)
        
        numpi = 10
        
        query = PlayerInvestment.all()
        query.filter("investmentid =", player.playerid)
        if lastid:
            query.filter("playerid >", lastid)
        query.order("playerid")
        playerinvestments = query.fetch(numpi)
        
        for pi in playerinvestments:
            if not pi.amount:
                continue
            investor = doo.getplayer(pi.playerid)
            payout = round(float(float((float(pi.amount) / float(player.totalinvestorsamount)))) * float(amount), 2)
            #tempplayer = doo.getplayer(pi.playerid)
            investor.money += payout
            investor.money = round(investor.money, 2)
            player.money -= payout
            player.money = round(player.money, 2)

            player.lastdividendamount += payout

            investor.put()
            doo.message(investor, 'You received a dividend of %s from %s' % (payout, player.name))
        
        if player.totalinvestorsamount > 0 and player.lastdividendamount > 99:
            player.points += 1
        
        player.put()
        
        if len(playerinvestments) < numpi:
            if player.solid:
                player.taxes = 0.0
                player.put()
        else:
            lastid = playerinvestments[-1].playerid
            taskqueue.add(url='/tasks/dividendpayer', params={'amount': amount, 'playerid': playerid, 'lastid':lastid})
Beispiel #8
0
    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)
            
        friend = doo.getplayer(self.request.get('playerid'))
        player.addfriend(friend)
Beispiel #9
0
    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)
            
        investment = doo.getplayer(self.request.get('investmentid'))

        message = player.withdraw(investment, self.request.get('withdrawamount'))
Beispiel #10
0
 def buystuff(self, stuff):
     if stuff.ownerid:
         owner = doo.getplayer(stuff.ownerid)
         if owner:
             return owner.sellstuff(stuff, self)
         else:
             return False
     else:
         success = stuff.sellto(self)
         if success:
             self.points += 1
             self.put()
             doo.collecttax(stuff, stuff.price)
             return True
         else:
             return False 
Beispiel #11
0
    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)
            
        investment = doo.getplayer(self.request.get('param'))
        
        levelprogress, nextlevel = investment.checklevel()
        
        occupation = investment.getoccupation()
        
        solidstuff = doo.getsolidstuffbyplayerid(investment.playerid)
        
        meinthem = doo.getplayerinvestment(player.playerid, investment.playerid)
        theminme = doo.getplayerinvestment(investment.playerid, player.playerid)
        
        if investment.playerid in player.friends:
            friend = True
        else:
            friend = False
            
        lastdividenddate = formattar.getprettydate(investment.lastdividenddate)
            
    	template_values = {
            'investment': investment,
            'friend': friend,
            'solidstuff': solidstuff,
            'lastdividenddate': lastdividenddate,
            'meinthem': meinthem,
            'theminme': theminme,
            'player': player,
            'occupation': occupation,
            'levelprogress': levelprogress,
            'nextlevel': nextlevel,
            }

        if player.mobile:
            templatefile = 'm_playerinfo.html'
        else:
            templatefile = 'playerinfo.html'
        path = os.path.join(os.path.dirname(__file__), templatefile)
        self.response.out.write(template.render(path, template_values))
Beispiel #12
0
    def get(self):
#        user = users.get_current_user()
#        if not user:
#            self.redirect("/")

#        player = doo.getplayerbyuser(user)
#        if not player:
#            self.redirect("/hastymoney")

        expires_date = datetime.datetime.utcnow() + datetime.timedelta(365)
        expires_str = expires_date.strftime("%d %b %Y %H:%M:%S GMT")
        self.response.headers.add_header("Expires", expires_str)
            
        player = doo.getplayer(self.request.get("playerid"))
        if player:
            if self.request.get('small'):
                if player.avatarsmall:
                    self.response.out.write(player.avatarsmall)
                else:
                    self.error(404)
            elif self.request.get('medium'):
                if player.avatarmedium:
                    self.response.out.write(player.avatarmedium)
                else:
                    self.error(404)
            elif player.avatar:
                self.response.out.write(player.avatar)
            else:
                self.error(404)
        else:
            if self.request.get('charityfund'):
                charityfund = doo.getcharityfund()
                if charityfund:
                    if self.request.get('small'):
                        self.response.out.write(doo.getcharityfund().avatarsmall)
                    elif self.request.get('medium'):
                        self.response.out.write(doo.getcharityfund().avatarmedium)
                    else:
                        self.response.out.write(doo.getcharityfund().avatar)
                else:
                    self.error(404)
            else:
                self.error(404)
Beispiel #13
0
    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)
            
        stuff = doo.getstuffbyid(self.request.get('stuffid'))
        owner = doo.getplayer(stuff.ownerid)
        
    	template_values = {
            'stuff': stuff,
            'player': player,
            'owner': owner,
            }

        path = os.path.join(os.path.dirname(__file__), 'storebuystuff.html')
        self.response.out.write(template.render(path, template_values))
Beispiel #14
0
    def calculatetax(self): # this is never called except for in a cron job
        solidinvestment = doo.getplayer(self.playerid)
        should = int(solidinvestment.totalinvestorsamount / self.ratio)
        if should == 0:
            self.tax = self.basetax
        elif self.oldcount == 0:
            self.tax = self.basetax
        else:
            self.tax = round(float(float(float(should) / float(self.oldcount)) * float(self.basetax)), 2)
            #cloud.call(lambda: _cloud_compute_tax(should, self.oldcount, self.basetax))

        #We are holding today's created stuffs until tomorrow; calculate tax on the number existing at beginning of 24 hour period, not the end
        self.oldcount = self.count 
#        needtocreate = int(should - self.count)
#        if needtocreate > 0:
#            self.count += needtocreate
#            self.put()
#            #stuffmaker.make(self.stuffname, self.playerid, needtocreate)
#            taskqueue.add(url='/tasks/createstuffs', params={'stuffname': self.stuffname, 'amount': needtocreate, 'playerid': self.playerid})

        self.put()
Beispiel #15
0
    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)
            
        investment = doo.getplayer(self.request.get('param'))

        template_values = {
            'investment': investment,
            'player': player,
            }

        if player.mobile:
            templatefile = 'm_investnow.html'
        else:
            templatefile = 'investnow.html'
        path = os.path.join(os.path.dirname(__file__), templatefile)
        self.response.out.write(template.render(path, template_values))
Beispiel #16
0
 def getsolidinvestment(self):
     investment = doo.getplayer(self.solidinvestment)
     return investment
Beispiel #17
0
 def getinvestors(self):
     """ returns a tuple of (Player, PlayerInvestment) """
     playerinvestors = self.getplayerinvestorsquery()
     investors = [(doo.getplayer(pi.playerid), pi) for pi in playerinvestors]
     return investors
Beispiel #18
0
    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)