Exemplo n.º 1
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))
Exemplo n.º 2
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))
Exemplo n.º 3
0
    def addinvestment(self, investment, amount):
        amount = round(float(amount), 2)
        
        if investment.playerid == self.playerid:
            return False
        
#        if self.getpower() <=0:
#            doo.makealert(self, "You don't have enough Power to do this--go to the store and buy some Power")
#            return False
        
        if round(amount, 2) <= round(self.money, 2):
            pi = doo.getplayerinvestment(self.playerid, investment.playerid)
            if pi:
                pi.amount += amount
                pi.amount = round(pi.amount, 2)
                pi.interestpercent = investment.percent # a new investment resets the interest percent
                pi.put()
                #doo.makealert(investment, 'You have a new investor: %s' % (self.name))
            else:
                pi = PlayerInvestment()
                pi.playerid = self.playerid
                pi.investmentid = investment.playerid
                pi.amount = round(amount, 2)
                pi.interestpercent = investment.percent
                pi.solid = investment.solid
                pi.put()
            
#            if investment.playerid in self.getinvestmentskeys():
#                self.setinvestmentamount(investment.playerid, (self.getinvestmentamount(investment.playerid) + float(amount)))
#            else:
#                self.setinvestmentamount(investment.playerid, float(amount))

            self.money -= amount
            self.money = round(self.money, 2)
            self.totalinvestedamount += amount
            self.totalinvestedamount = round(self.totalinvestedamount, 2)
            investment.money += amount
            investment.money = round(investment.money, 2)
            investment.totalinvestorsamount += amount
            investment.totalinvestorsamount = round(investment.totalinvestorsamount, 2)
#            if amount > 999:
#                self.points += 1
#                investment.points += 1
            
            numpoints = int(amount) / 100
            if numpoints > 0:
                #tenminutes = datetime.timedelta(minutes=2)
                #sincelastinvestment = datetime.datetime.now() - pi.modified
                #logging('%s|%s' % (sincelastinvestment, tenminutes))
                #if sincelastinvestment > tenminutes:
                    #self.points += numpoints
                investment.points += numpoints

            self.put()
            investment.put()
            
#            investment.addinvestee(self, amount)
            # investor
            
            

            #doo.payoutdividendonnewinvestment(investment, amount, self)
            if not investment.solid: # solid investments pay on cron job with payoutgrowth
                taskqueue.add(url='/tasks/payinterest', params={'playerid': self.playerid, 
                                                                'amount': amount, 
                                                                'investmentid': investment.playerid})
            
            #doo.makealert(self, 'You invested %s in %s' % (amount, investment.name))
            #doo.makealert(investment, '%s invested %s in you' % (self.name, amount))
            
            if investment.solid:
                investment.calculatenewstuffs()
            return True
        else:
            doo.makealert(self, 'Hey there, you\'re not carrying enough cash to make that investment')
            return False
Exemplo n.º 4
0
    def withdraw(self, investment, amount):
        amount = round(float(amount), 2)
        
        pi = doo.getplayerinvestment(self.playerid, investment.playerid)
        if pi:
            logging.info(amount)
            logging.info(pi.amount)
            logging.info(round(amount, 2) - round(pi.amount, 2))
            if round(amount, 2) > round(pi.amount, 2): # you're asking for more than you invested
                doo.makealert(self, 'Failed: %s is more than you have invested in %s' % 
                              (amount, investment.name))
                #self.error(404)
                return False
            elif round(investment.money, 2) < round(amount, 2): # They don't have the full amount to pay you back
                moneytemp = investment.money
                investment.money = 0.0
                self.money += moneytemp
                
                pi.amount -= moneytemp
                pi.amount = round(pi.amount, 2)
                self.totalinvestedamount -= moneytemp
                self.totalinvestedamount = round(self.totalinvestedamount, 2)
                investment.totalinvestorsamount -= moneytemp
                investment.totalinvestorsamount = round(investment.totalinvestorsamount, 2)
                #self.setinvestmentamount(investment.playerid, (self.getinvestmentamount(investment.playerid) - float(moneytemp)))
                if pi.amount == 0.0:
                    pi.delete()
                else:
                    pi.put()
                #if self.getinvestmentamount(investment.playerid) == float(0):
                #    self.deleteinvestment(investment.playerid)

                #investment.setinvesteesamount(self.playerid, (investment.getinvesteesamount(self.playerid) - float(moneytemp)))
                #if investment.getinvesteesamount(self.playerid) == float(0):
                #    investment.deleteinvestee(self.playerid)
                    
                investment.put()
                self.put()
                
                if round(moneytemp, 2) == 0.0:
                    doo.makealert(self, "They didn't have any money to pay you back")
                else:
                    doo.makealert(self, 'They only had %s to pay you back.' % (moneytemp))
                doo.message(investment, 'There is a run on your account! You were unable to make a full payment of %s to %s' % 
                              (amount, self.name))
                
                if amount > 99:
                    investment.trust -= 0.01
                    investment.put()
                    
                #if self.alerts:
                    #self.error(404)
                    
                return False
            else: # they have enough to pay you back
                investment.money -= amount
                investment.money = round(investment.money, 2)
                #self.money += amount * .99
                self.money += amount
                self.money = round(self.money, 2)

                pi.amount -= amount
                pi.amount = round(pi.amount, 2)
                
                self.totalinvestedamount -= amount
                self.totalinvestedamount = round(self.totalinvestedamount, 2)
                investment.totalinvestorsamount -= amount
                investment.totalinvestorsamount = round(investment.totalinvestorsamount, 2)
                #self.setinvestmentamount(investment.playerid, (self.getinvestmentamount(investment.playerid) - float(amount)))
                if round(pi.amount, 2) <= 0.0:
                    pi.delete()
                else:
                    pi.put()
                
                #if self.getinvestmentamount(investment.playerid) == float(0):
                #    self.deleteinvestment(investment.playerid)

                #investment.setinvesteesamount(self.playerid, (investment.getinvesteesamount(self.playerid) - float(amount)))
                #if investment.getinvesteesamount(self.playerid) == float(0):
                #    investment.deleteinvestee(self.playerid)
                    
                investment.put()
                self.put()
                
                return True
        return False