def get(self, *args, **kwargs): # there is such user in db, double check after authentication # add bans, etc here if self.db_manager.get_user(self.current_user): character = self.db_manager.get_character(self.current_user) if not character: # no such user - redirect to creation self.render("create_character.html", name=self.current_user, classes=smarty.get_classes(self.locale), races=smarty.get_races(self.locale)) else: self.users_manager.on_user_enter(self.current_user, self.locale) div_users = self.render_div_users() # prepare skirmish.html database = dict() database["Items"] = items_manager.get_all(self.locale) database["Spells"] = spells_manager.get_all_spells(self.locale) locations = smarty.get_locations(self.locale) locations.insert(0, locations.pop(self.users_holder.online_users[self.current_user].location)) self.render("skirmish.html", substance=smarty.get_substance_name(character.class_id, self.locale), shop={"Items" : items_manager.get_shop(self.locale)}, database=database, locations=locations, div_users=div_users) else: self.clear_all_cookies() self.redirect("/")
def character_spells_action(self, user_name): character = self.online_users[user_name].character locale = self.online_users[user_name].locale return Action(202, { "spells" : spells_manager.get_spells(character, locale), "spells_to_learn" : spells_manager.get_spells_to_learn(character, locale), "substance_name" : smarty.get_substance_name(character.class_id, locale) })
def div_args(self, user_name, skirmish_users): user = skirmish_users[user_name] actions = list() count = smarty.get_attack_count(user.battle_character.class_id, user.battle_character.level) for i in range(count): actions.append((0, user.locale.translate(smarty.main_abilities[0]))) count = smarty.get_defence_count(user.battle_character.class_id, user.battle_character.level) for i in range(count): actions.append((1, user.locale.translate(smarty.main_abilities[1]))) count = smarty.get_spell_count(user.battle_character.class_id, user.battle_character.level) for i in range(count): actions.append((2, smarty.get_ability_name(user.battle_character.class_id, user.locale))) actions.append((3, smarty.get_substance_name(user.battle_character.class_id, user.locale))) return { "actions" : actions, "spells" : spells_manager.get_spells(user.battle_character, user.locale) }
def post(self, *args, **kwargs): if self.get_argument("action") == 'drop': self.db_manager.remove_character(self.current_user) elif self.get_argument("action") == 'change_location': self.battle_manager.user_leave(self.current_user) self.users_manager.change_location(self.current_user, int(self.get_argument("location"))) self.write(self.render_div_users()) elif self.get_argument("action") == 'put_on': if not self.characters_manager.put_on_item(self.current_user, self.get_argument("item_id")): self.write("false") elif self.get_argument("action") == 'take_off': self.characters_manager.take_off_item(self.current_user, self.get_argument("item_id")) elif self.get_argument("action") == "create_team": self.write(self.characters_manager.create_team(self.current_user, self.get_argument("team_name"))) elif self.get_argument("action") == "promote_team": self.characters_manager.promote_user(self.current_user, self.get_argument("user_name")) elif self.get_argument("action") == "demote_team": self.characters_manager.demote_user(self.current_user, self.get_argument("user_name")) elif self.get_argument("action") == "remove_team": self.characters_manager.remove_user_from_team(self.current_user, self.get_argument("user_name")) elif self.get_argument("action") == "invite_team": self.write(self.characters_manager.invite_user_to_team(self.current_user, self.get_argument("user_name"))) elif self.get_argument("action") == "confirm_team": self.characters_manager.user_join_team(self.current_user, self.get_argument("user_name"), self.get_argument("team_name")) elif self.get_argument("action") == "decline_team": pass elif self.get_argument("action") == "leave_team": self.characters_manager.user_leave_team(self.current_user) elif self.get_argument("action") == "learn_spell": self.characters_manager.learn_spell(self.current_user, self.get_argument("spell_id")) elif self.get_argument("action") == 'join': self.battle_manager.user_join(self.current_user) elif self.get_argument("action") == 'leave': self.battle_manager.user_leave(self.current_user) elif self.get_argument("action") == 'turn_do': self.battle_manager.user_turn(self.current_user, self.get_argument("turn_info")) elif self.get_argument("action") == 'turn_cancel': self.battle_manager.user_turn_cancel(self.current_user) elif self.get_argument("action") == 'new_message': message = { "from": self.current_user, "message_type": self.get_argument("message_type"), "body": self.get_argument("body") } if self.get_argument("message_type") == "private": message["to"] = self.get_argument("to") self.messager.new_message(self.current_user, message) elif self.get_argument("action") == 'shop_get_item': item_id = int(self.get_argument("item_id")) self.write(self.render_item_description(item_id, True)) elif self.get_argument("action") == 'db_get_item': item_id = int(self.get_argument("item_id")) if item_id >= items_manager.build_id(10, 0) and item_id < items_manager.build_id(18, 0): spell = spells_manager.get_spell(item_id, self.locale) self.write(self.render_string("spell_description.html", spell=spell, class_name=smarty.get_class_name(spell.class_id, self.locale), substance_name=smarty.get_substance_name(spell.class_id, self.locale))) else: self.write(self.render_item_description(item_id, False)) elif self.get_argument("action") == 'buy_item': self.characters_manager.buy_item(self.current_user, self.get_argument("item_id")) elif self.get_argument("action") == 'open_chat': self.users_manager.open_chat(self.current_user, self.get_argument("user_name"), self.get_argument("message", "")) elif self.get_argument("action") == 'close_chat': self.users_manager.close_chat(self.current_user, self.get_argument("user_name")) elif self.get_argument("action") == 'change_gold_tax': self.characters_manager.change_gold_tax(self.current_user, self.get_argument("strategy")) elif self.get_argument("action") == 'change_gold_sharing': self.characters_manager.change_gold_sharing(self.current_user, self.get_argument("strategy")) elif self.get_argument("action") == 'change_experience_sharing': self.characters_manager.change_experience_sharing(self.current_user, self.get_argument("strategy"))