Beispiel #1
0
    def post(self, location_id):
        """
            This handler is a bit more complex - handles the actions that can 
            be taken at this location. For instance:
            
            - extort
            - take control
            - leave guards
            - battle
        """
        user_id = self.get_secure_cookie("user_id")
        user = db.get_user(user_id)
                    
        location = db.get_or_create_location_by_id(location_id)
        action = self.get_argument("action")

        if action == "take-control":
            # TODO: Do an additional check to make sure this isn't owned
            # by someone else and there are no guards here.
            location["owner"] = { "name" : user["name"], "user_id" : user["id"] }
            db.save_location(location)
        elif action == "extort" and location["owner"]["user_id"] == user["id"]:
            inventory = db.get_inventory_for_user(user)
            extortion_value = 5 * location["checkins"]
            inventory["money"] += extortion_value
            db.save_inventory(inventory)
            
            location["last_extort_time"] = datetime.datetime.now()
            db.save_location(location)
            
        self.redirect("/location/%s" % location_id)
Beispiel #2
0
    def post(self, location_id):
        """
            This handler is a bit more complex - handles the actions that can 
            be taken at this location. For instance:
            
            - extort
            - take control
            - leave guards
            - battle
        """
        user_id = self.get_secure_cookie("user_id")
        user = db.get_user(user_id)

        location = db.get_or_create_location_by_id(location_id)
        action = self.get_argument("action")

        if action == "take-control":
            # TODO: Do an additional check to make sure this isn't owned
            # by someone else and there are no guards here.
            location["owner"] = {"name": user["name"], "user_id": user["id"]}
            db.save_location(location)
        elif action == "extort" and location["owner"]["user_id"] == user["id"]:
            inventory = db.get_inventory_for_user(user)
            extortion_value = 5 * location["checkins"]
            inventory["money"] += extortion_value
            db.save_inventory(inventory)

            location["last_extort_time"] = datetime.datetime.now()
            db.save_location(location)

        self.redirect("/location/%s" % location_id)
Beispiel #3
0
 def post(self):
     """
         Allows a user to make purchases. In the case of armor or weapons, we
         simply increment the number of items a user has.
         
         In the case of mobsters, we append to the current list of mobsters in the
         player's inventory because each mobster has its own state.
     """
     user_id = self.get_secure_cookie("user_id")
     user = db.get_user(user_id)
     inventory = self.get_inventory_for_user(user)
     
     action = self.get_argument("action")
     item_id = self.get_argument("id")
     
     # Probably could have collapsed armor and weapons into a single
     # type and used a field to designate type.
     if action == "buy-weapon":
         # User already has item, increment quantity
         weapon = items.weapons[item_id]
         if item_id in inventory["weapons"].keys():
             inventory["weapons"][item_id]["quantity"] += 1
         else:
             inventory["weapons"][item_id] = {
                 "name" : weapon["name"],
                 "quantity" : 1
             }
     elif action == "buy-armor":
         armor = items.armor_list[item_id]
         if item_id in inventory["armor"].keys():
             inventory["armor"][item_id]["quantity"] += 1
         else:
             inventory["armor"][item_id] = {
                 "name" : armor["name"],
                 "quantity" : 1
             }
     elif action == "recruit-mobster":
         # We are recruiting someone to our gang. We persist this data
         # differently because we have to store the state of each mobster.
         mobster_prototype = items.mobsters[item_id]
         
         # We create a new instance of a mobster to track state
         mobster_instance = {
             "name" : mobster_prototype["name"],
             "image_url" : mobster_prototype["image_url"],
             "level" : mobster_prototype["level"],
             "hp" : mobster_prototype["base_hitpoints"],
             # We may want to modify this later with bonuses
             "damage" : mobster_prototype["base_damage"]
         }
         inventory["mobsters"].append(mobster_instance)
         
     db.save_inventory(inventory)
     self.redirect("/store")
Beispiel #4
0
    def post(self):
        """
            Allows a user to make purchases. In the case of armor or weapons, we
            simply increment the number of items a user has.
            
            In the case of mobsters, we append to the current list of mobsters in the
            player's inventory because each mobster has its own state.
        """
        user_id = self.get_secure_cookie("user_id")
        user = db.get_user(user_id)
        inventory = self.get_inventory_for_user(user)

        action = self.get_argument("action")
        item_id = self.get_argument("id")

        # Probably could have collapsed armor and weapons into a single
        # type and used a field to designate type.
        if action == "buy-weapon":
            # User already has item, increment quantity
            weapon = items.weapons[item_id]
            if item_id in inventory["weapons"].keys():
                inventory["weapons"][item_id]["quantity"] += 1
            else:
                inventory["weapons"][item_id] = {
                    "name": weapon["name"],
                    "quantity": 1
                }
        elif action == "buy-armor":
            armor = items.armor_list[item_id]
            if item_id in inventory["armor"].keys():
                inventory["armor"][item_id]["quantity"] += 1
            else:
                inventory["armor"][item_id] = {
                    "name": armor["name"],
                    "quantity": 1
                }
        elif action == "recruit-mobster":
            # We are recruiting someone to our gang. We persist this data
            # differently because we have to store the state of each mobster.
            mobster_prototype = items.mobsters[item_id]

            # We create a new instance of a mobster to track state
            mobster_instance = {
                "name": mobster_prototype["name"],
                "image_url": mobster_prototype["image_url"],
                "level": mobster_prototype["level"],
                "hp": mobster_prototype["base_hitpoints"],
                # We may want to modify this later with bonuses
                "damage": mobster_prototype["base_damage"]
            }
            inventory["mobsters"].append(mobster_instance)

        db.save_inventory(inventory)
        self.redirect("/store")