예제 #1
0
    def checklevel(self):
        if self.points == 0:
            return 0, 55 # if you change the 18 you'll have to change the 55
        
        # increase the 18 to decrease the change, decrease the 18 to increase the difference
        K = int(self.level * 1000 * (float(self.level) / float(18)))
        level = self.level
        while self.points >= K:
            level += 1
            K = int(level * 1000 * (float(level) / float(18)))
            
        if self.level != level:
            salaryraise = (level - self.level) * 5000
            if not self.salaryincrease:
                self.salaryincrease = 0.0
                self.put()
            self.salaryincrease += salaryraise
            
            self.level = level
            self.put()
            
            doo.message(self, "Sweet! You leveled up to level %s and got a raise of %s!" % (self.level, formattar.getmoney(salaryraise)))

        if self.level == 1:
            J = 0
        else:
            J = int((self.level-1) * 1000 * (float(self.level-1) / float(18)))
        
        levelprogress = (float(self.points - J) / float(K - J)) * 100
        
        return levelprogress, K
예제 #2
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()
예제 #3
0
 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.")
예제 #4
0
 def checksalary(self):
     day = datetime.timedelta(hours=24)
     delta = datetime.datetime.now() - self.lastpayday
     if delta >= day:
         payday = round(float(float((self.getoccupation().salary + self.salaryincrease) / 365) * delta.days), 2)
         self.money += round(payday, 2)
         self.money = round(self.money, 2)
         self.lastpayday = datetime.datetime.now()
         self.put()
         doo.message(self, "You got paid %s! Don't spend it all in one place!" % (payday))
예제 #5
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})
예제 #6
0
 def sendmessage(self, toplayer, messagetext):
     if not toplayer.solid and self.money >= doo.getmessageprice() and len(messagetext) > 0 and len(messagetext) < 300:
         messagetext = '<span title="message sent %s"><a style="cursor:pointer;" onclick="gohere(\'playerinfo\', \'%s\');"><b>%s</b></a> says: %s<span>' % (formattar.prettydate(datetime.datetime.now()), self.playerid, self.name, messagetext)
         if doo.message(toplayer, messagetext):
             self.money -= float(doo.getmessageprice())
             self.put()
             return True
         else:
             #doo.makealert(self, 'Error sending message to %s' % (toplayer.name))
             #self.error(404)
             logging.info('here?')
             return False
     else:
         #doo.makealert(self, 'Error sending message to %s' % (toplayer.name))
         #self.error(404)
         logging.info('or here?')
         return False
예제 #7
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
예제 #8
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)