コード例 #1
0
ファイル: investnow.py プロジェクト: rscottfree/hastymoney
    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
コード例 #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)
            
        stuff = doo.getstuffbyid(self.request.get('stuffid'))
        if not stuff:
            self.error(404)

        if stuff.ownerid != player.playerid:
            self.error(404)
            
        if not doo.liquidatestuff(stuff.stuffid):
            doo.makealert(player, 'Liquidation of %s failed' % (stuff.name))
コード例 #3
0
ファイル: buystuffnow.py プロジェクト: rscottfree/hastymoney
    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"))

        if not player.buystuff(stuff):
            if player.money <= stuff.price:
                doo.makealert(player, "Hey Mcfly, you don't have enough money to purchase this item")
            else:
                doo.makealert(player, "Darn it, something went wrong with that purchase.")

            self.response.out.write("0")  # fail
        else:
            self.response.out.write("1")  # success
コード例 #4
0
ファイル: paydividend.py プロジェクト: rscottfree/hastymoney
    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)
        
        if self.request.get('dividendamount'):
            divamount = float(self.request.get('dividendamount'))
        else:
            self.redirect(404)
        
        if divamount <= player.money and divamount:
            player.payoutdividendamount(float(divamount))
            return
        else:
            doo.makealert(player, "You don't have that much to pay out")
            self.error(404)
            return
コード例 #5
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)
            
        messagenum = int(self.request.get('messagenum'))
        if messagenum is None:
            doo.makealert(player, "Error archiving that message--um, I'm not sure what went wrong.")
            self.error(404)
            return
        
        try:
            message = player.messages.pop(messagenum)
            player.messagearchive.append(message)
            player.put()
            self.response.out.write('done archiving')
        except:
            doo.makealert(player, "Error archiving that message--it's as simple as that.")
            self.error(404)
            return
コード例 #6
0
ファイル: editstuff.py プロジェクト: rscottfree/hastymoney
    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)

        stuff = doo.getstuffbyid(self.request.get("stuffid"))

        if self.request.get("stuffforsale") == "on":
            forsale = True
        else:
            forsale = False

        description = str(self.request.get("stuffdescription"))

        price = round(float(self.request.get("stuffprice")), 2)
        if price < 0:
            doo.makealert(player, "sale price must be greater than zero")
            stuff.update(stuff.price, forsale, description)
        else:
            stuff.update(price, forsale, description)
コード例 #7
0
ファイル: editplayer.py プロジェクト: rscottfree/hastymoney
    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)

        if self.request.get("playername"):
            name = " ".join(self.request.get("playername").split())
            name = name.strip()
            if validator.validateplayername(str(name)):
                if doo.getplayerbyname(name, ignorecase=True) and player.namenormal != str(name).upper():
                    doo.makealert(player, "Rats, that name is already taken")
                else:
                    if player.name != str(name):
                        # doo.makealert(player, 'Name changed to %s' % (str(name)))
                        player.name = str(name)
                        player.namenormal = player.name.upper()
            else:
                doo.makealert(
                    player, "Invalid player name. You can only use letters and there must be more than 2 letters."
                )
        if self.request.get("playerpercent"):
            if validator.validatepercent(self.request.get("playerpercent")):
                player.percent = round(float(self.request.get("playerpercent")), 2) / 100
            else:
                doo.makealert(player, "Invalid percent")
        if len(self.request.get("playerabout")) < 300:
            player.about = str(self.request.get("playerabout"))

        if self.request.get("playeravatar"):
            player.avatar = db.Blob(images.resize(self.request.get("playeravatar"), 100, 100))
            player.avatarsmall = db.Blob(images.resize(self.request.get("playeravatar"), 30, 30))

        player.put()

        self.redirect("/hastymoney#!frontpage")
コード例 #8
0
ファイル: models.py プロジェクト: rscottfree/hastymoney
    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
コード例 #9
0
ファイル: models.py プロジェクト: rscottfree/hastymoney
    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
コード例 #10
0
ファイル: makepurchase.py プロジェクト: rscottfree/hastymoney
    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)