def get_card_souls(rk_user,params): ''' 获取用户的武将碎片信息 miaoyichao ''' user_souls_obj = UserSouls.get_instance(rk_user.uid) return 0, user_souls_obj.get_card_souls()
def get_card_souls(rk_user, params): ''' 获取用户的武将碎片信息 miaoyichao ''' user_souls_obj = UserSouls.get_instance(rk_user.uid) return 0, user_souls_obj.get_card_souls()
def exchange_card(rk_user, params): """ 将魂卡兑换成武将 miaoyichao """ # 需要兑换的武将 cid = params['cid'] user_souls_obj = UserSouls.get_instance(rk_user.uid) user_card_obj = UserCards.get_instance(rk_user.uid) needed_souls = int(game_config.card_config[cid]['souls_needed']) # 将魂不足 if not user_souls_obj.is_normal_soul_enough(cid,needed_souls): return 11, {'msg': utils.get_msg('soul','not_enough_soul')} #减武将碎片 user_souls_obj.minus_card_soul(cid, needed_souls, 'soul_exchange_card') # 加武将 success_fg, p1, ucid, is_first = user_card_obj.add_card(cid, where='soul_exchange_card') new_card = { 'ucid':ucid, 'is_first':is_first, } new_card.update(user_card_obj.get_card_dict(ucid)) return 0, { 'new_card': new_card, }
def exchange_card(rk_user, params): """ 将魂卡兑换成武将 miaoyichao """ # 需要兑换的武将 cid = params['cid'] user_souls_obj = UserSouls.get_instance(rk_user.uid) user_card_obj = UserCards.get_instance(rk_user.uid) needed_souls = int(game_config.card_config[cid]['souls_needed']) # 将魂不足 if not user_souls_obj.is_normal_soul_enough(cid, needed_souls): return 11, {'msg': utils.get_msg('soul', 'not_enough_soul')} #减武将碎片 user_souls_obj.minus_card_soul(cid, needed_souls, 'soul_exchange_card') # 加武将 success_fg, p1, ucid, is_first = user_card_obj.add_card( cid, where='soul_exchange_card') new_card = { 'ucid': ucid, 'is_first': is_first, } new_card.update(user_card_obj.get_card_dict(ucid)) return 0, { 'new_card': new_card, }
def ttest_give_award(): user_property = UserProperty.get_instance(uid) uc = UserCards.get_instance(uid) ue = UserEquips.get_instance(uid) up = UserPack.get_instance(uid) us = UserSouls.get_instance(uid) #award = {'card':{'1_card':1}} #award = {'equip':{'13001_equip': 2}} #award = {'props':{'1_props':2}} #award = {'soul':{'card':{'1_card':1}}} award = {'soul':{'equip':{'13001_equip':1}}} print user_property.test_give_award(award) uc.do_put() ue.do_put() up.do_put() us.do_put()
def tranform_equip_soul_to_equip(rk_user, params): """将装备碎片 合成 装备 params: euqip_id 必须集齐这个装备所有的碎片类型才能合成 """ equip_id = params['equip_id'] user_souls_obj = UserSouls.get_instance(rk_user.uid) equip_type = int( game_config.equip_config.get(equip_id, {}).get('eqtype', 7)) if 1 <= equip_type <= 4: #处理普通装备的合成 needed_souls = int(game_config.equip_config[equip_id]['need_souls']) if user_souls_obj.is_equip_soul_enough(equip_id, needed_souls): #添加装备 user_equip_obj = UserEquips.get(rk_user.uid) fg, all_equips_num, ueid, is_first = user_equip_obj.add_equip( equip_id, 'tranform_equip_soul_to_equip') data = {} if fg: tmp = { 'ueid': ueid, 'is_first': is_first, } tmp.update(user_equip_obj.get_equip_dict(ueid)) data['equips'] = tmp #删除碎片 user_souls_obj.minus_equip_soul(equip_id, needed_souls) #结果返回 return 0, data else: return 11, {'msg': utils.get_msg('pack', 'not_enough_material')} elif 5 <= equip_type <= 6: #处理宝物的合成 need_soul_types_num = game_config.equip_config[equip_id].get( 'need_soul_types_num', 0) all_equips = [ equip_id + '_' + str(i) for i in xrange(1, need_soul_types_num + 1) ] #获取需要多少份碎片 needed_souls = int(game_config.equip_config[equip_id].get( 'need_souls', 1)) #判断碎片是否足够 for need_equip in all_equips: if not user_souls_obj.is_equip_soul_enough(need_equip, needed_souls): return 11, { 'msg': utils.get_msg('pack', 'not_enough_material') } # 消耗 装备碎片 for need_equip in all_equips: user_souls_obj.minus_equip_soul(need_equip, 1, 'tranform_equip_soul_to_equip') # 加 装备 user_equip_obj = UserEquips.get(rk_user.uid) fg, all_equips_num, ueid, is_first = user_equip_obj.add_equip( equip_id, 'tranform_equip_soul_to_equip') data = {} if fg: tmp = { 'ueid': ueid, 'is_first': is_first, } tmp.update(user_equip_obj.get_equip_dict(ueid)) data['equips'] = tmp #判断新手引导 newbie_step = int(params.get('newbie_step', 0)) if newbie_step: rk_user.user_property.set_newbie_steps( newbie_step, "tranform_equip_soul_to_equip") return 0, data else: return 11, {'msg': utils.get_msg('pack', 'not_enough_material')}
def give_award(self, award, where=None): """ 给用户奖励 """ tmp = {} for key in award: if key == 'gold': self.add_gold(award[key], 'award_%s' % where) tmp[key] = award[key] elif key == 'coin': self.add_coin(award[key], 'award_%s' % where) tmp[key] = award[key] elif key == 'card': tmp[key] = {} from apps.models.user_cards import UserCards uc = UserCards.get(self.uid) for cid in award[key]: this_card = CardMod.get(cid, game_config=self.game_config) lv = min(award[key][cid].get('lv', 1), this_card.max_lv) num = award[key][cid].get("num", 1) category = award[key][cid].get("category", '') quality = award[key][cid].get("quality", '') for index in range(num): fg, all_cards_num, ucid, is_first = uc.add_card( cid, lv, where='award_%s' % where, category=category, quality=quality) tmp[key][ucid] = uc.get_card_dict(ucid) elif key == 'equip': tmp[key] = {} from apps.models.user_equips import UserEquips eq_obj = UserEquips.get(self.uid) for equip in award[key]: num = award[key][equip].get("num", 1) for ind in range(num): fg, all_equips_num, ueid, is_first = eq_obj.add_equip( equip, 'award_%s' % where) tmp[key][ueid] = eq_obj.get_equip_dict(ueid) elif key == 'item': tmp[key] = {} user_pack_obj = self.user_pack for item_id in award[key]: user_pack_obj.add_item(item_id, award[key][item_id], 'award_%s' % where) tmp[key][item_id] = award[key][item_id] elif key == 'material': tmp[key] = {} user_pack_obj = self.user_pack for material_id in award[key]: user_pack_obj.add_material(material_id, award[key][material_id], 'award_%s' % where) tmp[key][material_id] = award[key][material_id] elif key == 'stamina': self.add_stamina(int(award[key])) tmp[key] = award[key] #elif key == 'super_soul': # user_souls_obj = UserSouls.get_instance(self.uid) # user_souls_obj.add_super_soul(int(award[key]), 'award_%s' % where) # tmp[key] = award[key] elif key == 'normal_soul': tmp[key] = {} user_souls_obj = UserSouls.get_instance(self.uid) for soul_id in award[key]: user_souls_obj.add_normal_soul(soul_id, award[key][soul_id], 'award_%s' % where) tmp[key][soul_id] = award[key][soul_id] elif key == 'renown': user_pvp_obj = self.user_base.user_pvp user_pvp_obj.add_renown(int(award[key])) elif key == 'honor': user_real_pvp = self.user_real_pvp user_real_pvp.add_honor(award[key]) tmp[key] = award[key] return tmp
def edit_user(request): """ 编辑用户页 """ uid = request.GET.get('uid', '').strip() if not uid: pid = request.GET.get('pid', '').strip() if not pid: username = request.GET.get('username', '') if not username: return HttpResponseRedirect('/admin/user/?status=1') try: uid = ocapp.mongo_store.mongo.db['username'].find( {'name': username})[0]['uid'] except: return HttpResponseRedirect('/admin/user/?status=1') else: account = AccountMapping.get(pid) if not account: return HttpResponseRedirect('/admin/user/?status=1') uid = account.uid user = UserBase.get(uid) if not user or not user.account: return HttpResponseRedirect('/admin/user/?status=1') user_equips_obj = UserEquips.get_instance(uid) user_pack_obj = UserPack.get_instance(uid) user_property_obj = UserProperty.get(uid) user_card_obj = UserCards.get(user.uid) user_real_pvp_obj = user.user_real_pvp game_config.set_subarea(user.subarea) data = { 'deck_cards': [], 'other_cards': [], } if not user.client_type: data['client_type'] = 'appstore_ios' else: data['client_type'] = user.client_type all_cards = [] all_cids = game_config.card_config.keys() all_cids_cp = copy.deepcopy(game_config.card_config) for k, v in all_cids_cp.iteritems(): all_cids_cp[k]['no'] = int(k.split('_')[0]) all_cids.sort(key=lambda x: (all_cids_cp[x]['no'])) for cid in all_cids: all_cards.append(Card.get(cid)) data['all_cards'] = all_cards #用户当前战场信息 user_dungeon_obj = UserDungeon.get_instance(user.uid) #充值信息 data['charge_sum_money'] = user_property_obj.charge_sum_money data['last_charge_record'] = ChargeRecord.find( {'uid': uid})[-1] if ChargeRecord.find({'uid': uid}) else {} ######神秘商店 代码往前方 因为此操作会改变玩家武将,物品等信息############## # 刷新 物品列表 if request.POST.get('refresh_mystery_store', ''): store_type = request.POST.get('store_type') params = {} mystery_store.refresh_store_by_self(user, params) # 购买 物品 if request.POST.get('buy_mystery_store_goods', ''): store_type = request.POST.get('store_type') goods_index = int(request.POST.get('goods_index')) params = { 'store_type': store_type, 'goods_index': goods_index, } mystery_store.buy_store_goods(user, params) ######Pk商店 ## # 刷新 物品列表 if request.POST.get('refresh_pk_store', ''): pk_store.refresh_store_by_self(user, {}) # 购买 物品 if request.POST.get('buy_pk_store_goods', ''): goods_index = int(request.POST.get('goods_index')) params = { 'goods_index': goods_index, } pk_store.buy_store_goods(user, params) #################### moderator = auth.get_moderator_by_request(request) qa_edit = 'qa edited by ' + str(moderator.username) #提交状态 if request.method == "POST": state = int(request.POST.get("state", "0")) state = bool(state) #冻结 if state != user.in_frozen: if state: user.froze() #解冻 else: user.unfroze() #删除账号 if request.POST.get('del_user', ''): if not user.account: return HttpResponseRedirect('/admin/user/?status=1') user.account.delete() if request.POST.get('add_gold', ''): add_gold = int(request.POST.get('add_gold')) if add_gold > 0: user_property_obj.add_gold(add_gold, where=qa_edit) else: user_property_obj.minus_gold(add_gold) #增加元宝 if request.POST.get('add_coin', ''): add_coin = int(request.POST.get('add_coin')) if add_coin > 0: user_property_obj.add_coin(add_coin, where=qa_edit) else: user_property_obj.minus_coin(add_coin, where=qa_edit) #增加 经验点 if request.POST.get('add_card_point', ''): add_card_point = int(request.POST.get('add_card_point')) if add_card_point > 0: user_property_obj.add_card_exp_point(add_card_point, qa_edit) else: user_property_obj.minus_card_exp_point(add_card_point, qa_edit) #增加经验 if request.POST.get('add_exp', ''): add_exp = int(request.POST.get('add_exp')) user_property_obj.add_exp(add_exp, where=qa_edit) #更改等级 if request.POST.get('modify_lv', ''): lv = request.POST.get('modify_lv') lv_exp = game_config.user_level_config[lv]['exp'] now_exp = user_property_obj.property_info['exp'] user_property_obj.add_exp(lv_exp - now_exp, where=qa_edit) # 增加pk 积分 if request.POST.get('add_pk_pt', 0): pvp_pt = int(request.POST.get('add_pk_pt')) user_real_pvp_obj.add_pt(pvp_pt) # 加功勋 if request.POST.get('add_honor', ''): honor = int(request.POST.get('add_honor')) urp = UserRealPvp.get(user.uid) urp.add_honor(honor, where=qa_edit) # 加战魂 if request.POST.get('add_fight_soul', ''): fight_soul_num = int(request.POST.get('add_fight_soul')) user_property_obj.add_fight_soul(fight_soul_num, where=qa_edit) #发邮件 if request.POST.get('mail_title') or request.POST.get('mail_goods'): from apps.models.user_mail import UserMail from apps.common import utils sid = 'system_%s' % (utils.create_gen_id()) mail_title = request.POST.get('mail_title', '') mail_content = request.POST.get('mail_content', '') goods_str = request.POST.get('mail_goods', '').strip() award = {} for goods_info in goods_str.split(";"): goods_info = goods_info.strip() print "debug guochen email", goods_info if not goods_info: continue goods_id, num = goods_info.strip().split(":") award.setdefault(goods_id, 0) award[goods_id] += int(num) mailtype = 'system_qa' user_mail_obj = UserMail.hget(uid, sid) user_mail_obj.set_mail(mailtype=mailtype, title=mail_title, content=mail_content, award=award) # 修改vip等级 if request.POST.get('modify_vip_lv'): vip_lv = request.POST.get('modify_vip_lv') vip_conf = game_config.user_vip_config.get(str(vip_lv)) if vip_conf: coin = vip_conf['coin'] user_property_obj.property_info["charge_coins"] = coin user_property_obj.put() #补武将 if request.POST.get("add_card_ex", ""): user_card_obj = UserCards.get(user.uid) strCardInfo = request.POST.get("add_card_ex") lstCardInfo = strCardInfo.strip().split(";") for strAddCard in lstCardInfo: cid = strAddCard.split(":")[0] cid = cid.strip() + '_card' num = int(strAddCard.split(":")[1]) for i in range(num): clv = 1 user_card_obj.add_card(cid, clv, where=qa_edit) #增加武将 if request.POST.getlist('add_card'): add_cids = request.POST.getlist('add_card') user_card_obj = UserCards.get(user.uid) for add_cid in add_cids: if add_cid in game_config.card_config: clv = 1 user_card_obj.add_card(add_cid, clv, where=qa_edit) #增加武将经验 if request.POST.get('add_card_exp', ''): add_exp = int(request.POST.get('add_card_exp')) ucid = request.POST.get('ucid') user_card_obj.add_card_exp(ucid, add_exp) #增加武将技能级别 if request.POST.get('add_card_sk_lv', ''): ucid = request.POST.get('ucid') user_card_obj.add_card_sk_lv(ucid) #卖掉卡片 if request.POST.get('sell_card', ''): ucid = request.POST.get('ucid') #this_card = Card.get(user_card_obj.cards[ucid]['cid'],user_card_obj.cards[ucid]['lv']) user_card_obj.del_card_info([ucid]) #user.user_property.add_gold(this_card.sell_gold,where=qa_edit) #踢出队伍 if request.POST.get('kick_deck', ''): kick_index = int(request.POST.get('deck_index')) if user_card_obj.deck[kick_index].get( 'ucid', '') != user_card_obj.get_leader( user_card_obj.cur_deck_index): user_card_obj.deck[kick_index] = {} user_card_obj.put() #设置主将 if request.POST.get('set_deck_main', ''): ucid = request.POST.get('ucid') find_fg = False for card in user_card_obj.deck: if card.get('leader', 0): card['ucid'] = ucid user_card_obj.put() find_fg = True break if not find_fg: user_card_obj.deck[0] = {'ucid': ucid, 'leader': 1} user_card_obj.put() #设置副将 if request.POST.get('set_deck_sub', ''): ucid = request.POST.get('ucid') for card in user_card_obj.deck: if not card: card['ucid'] = ucid user_card_obj.put() break #一键送所有武将碎片 if request.POST.get('give_all_card_soul', ''): for cid in game_config.card_config: user_card_obj.add_card(cid, 1, where=qa_edit) user_card_obj.put() #一键送所有武将 if request.POST.get('give_all_card', ''): #一键送所有武将 for cid in all_cids: ucid = user_card_obj.add_card(cid, 1, where=qa_edit)[2] # if request.POST.get('give_all_card',''): # user_card_obj.cards = {} # user_card_obj.cards_info = { # "decks":[[{}] * 5] * 10, # "cur_deck_index":0, # } # for eid in user_equips_obj.equips: # if user_equips_obj.equips[eid].get("used_by"): # user_equips_obj.equips[eid]['used_by'] = '' # user_equips_obj.put() # card_index = 0 # for cid in all_cids: # clv = 1 # ucid = user_card_obj.add_card(cid,clv,where=qa_edit)[2] # if card_index < 5: # user_card_obj.deck[card_index]['ucid'] = ucid # card_index += 1 #一键删除军队外的所有武将 if request.POST.get('del_other_card', ''): decks = [] for deck in user_card_obj.decks: decks.extend( [card['ucid'] for card in deck if card.get('ucid', '')]) del_cids = filter(lambda x: x not in decks, user_card_obj.cards.keys()) user_card_obj.del_card_info(del_cids) for eid in user_equips_obj.equips: if user_equips_obj.equips[eid].get("used_by"): user_equips_obj.equips[eid]['used_by'] = '' user_equips_obj.put() #开放战场 if request.POST.get('open_dungeon', ''): open_dungeon = request.POST.get('open_dungeon') floor_id = open_dungeon.split('-')[0] room_id = open_dungeon.split('-')[1] user_dungeon_obj.dungeon_info['normal_current'][ 'floor_id'] = floor_id user_dungeon_obj.dungeon_info['normal_current'][ 'room_id'] = room_id user_dungeon_obj.dungeon_info['normal_current']['status'] = 0 user_dungeon_obj.put() #回复体力 if request.POST.get('add_stamina', ''): add_stamina = int(request.POST.get('add_stamina')) user_property_obj.add_stamina(add_stamina) #equip if request.POST.get("add_equips", ""): user_equips_obj = UserEquips.get(uid) strEquipsInfo = request.POST.get("add_equips") lstEquipsInfo = strEquipsInfo.strip().split(";") for strAddEquip in lstEquipsInfo: eid = strAddEquip.split(":")[0] eid = eid.strip() + '_equip' num = int(strAddEquip.split(":")[1]) for i in range(num): user_equips_obj.add_equip(eid, where=qa_edit) #材料 if request.POST.get("add_mats", ""): strItemsInfo = request.POST.get("add_mats") lstItemsInfo = strItemsInfo.strip().split(";") for strAddItem in lstItemsInfo: mid = strAddItem.split(":")[0] mid = mid.strip() + '_mat' num = int(strAddItem.split(":")[1]) user_pack_obj.add_material(mid, num, where=qa_edit) #道具 if request.POST.get("add_props", ""): strPropsInfo = request.POST.get("add_props") lstPropsInfo = strPropsInfo.strip().split(";") for strAddProps in lstPropsInfo: pid = strAddProps.split(":")[0] pid = pid.strip() + '_props' num = int(strAddProps.split(":")[1]) user_pack_obj.add_props(pid, num, where=qa_edit) if request.POST.get("add_materials_num", 0): mid = request.POST.get("mid") user_pack_obj.add_material( mid, int(request.POST.get("add_materials_num", 0)), where=qa_edit) if request.POST.get("add_props_num", 0): pid = request.POST["prop"] user_pack_obj.add_props(pid, int(request.POST.get("add_props_num", 0)), where=qa_edit) if request.POST.get('give_all_props'): num = int(request.POST.get('all_props_num')) if request.POST.get( 'all_props_num') else 99 for iid in game_config.props_config: user_pack_obj.add_props(iid, num, where=qa_edit) if request.POST.get('del_all_props'): user_pack_obj.props = {} user_pack_obj.put() if request.POST.get('give_all_equips'): user_equips = UserEquips.get(uid) for eid in game_config.equip_config: user_equips.add_equip(eid, where=qa_edit) #一键送所有的装备碎片 if request.POST.get('give_all_equip_soul'): user_souls_obj = UserSouls.get(uid) for eid in game_config.equip_config: if game_config.equip_config[eid].get('need_soul_types_num', 0): parts = game_config.equip_config[eid].get( 'need_soul_types_num', 0) for i in xrange(1, parts + 1): user_souls_obj.add_equip_soul(eid + '_' + str(i), 100, where=qa_edit) else: user_souls_obj.add_equip_soul(eid, 1, where=qa_edit) #一键删除所有的装备碎片 if request.POST.get('del_all_equip_soul'): user_souls_obj = UserSouls.get(uid) user_souls_obj.equip_souls_info = {} user_souls_obj.put() #添加单个装备碎片 if request.POST.get('add_single_equip_soul'): sid = request.POST.get('sid') num = int(request.POST.get('add_single_equip_soul')) user_souls_obj = UserSouls.get_instance(uid) user_souls_obj.add_equip_soul(sid, num, where=qa_edit) user_souls_obj.put() if request.POST.get('del_other_equips'): user_equips = UserEquips.get(uid) ueids = [ ueid for ueid in user_equips.equips if not user_equips.is_used(ueid) ] user_equips.delete_equip(ueids) if request.POST.get('give_all_materials'): num = int(request.POST.get('all_materials_num') ) if request.POST.get('all_materials_num') else 99 user_pack_obj = UserPack.get_instance(uid) for mid in game_config.material_config: user_pack_obj.add_material(mid, num, where=qa_edit) if request.POST.get('del_all_materials'): user_pack_obj = UserPack.get_instance(uid) user_pack_obj.materials = {} user_pack_obj.put() #一键过新手引导 if request.POST.get('newbie_pass', '') and user.user_property.newbie: newbie_steps_num = int( user.game_config.system_config.get('newbie_steps', 6)) user.user_property.property_info['newbie_steps'] = ( 1 << newbie_steps_num) - 1 user.user_property.set_newbie() user.user_property.do_put() data['status'] = 1 data['current_dungeon'] = user_dungeon_obj.dungeon_info['normal_current'] #配置中的所有战场 data['all_dungeon'] = [] floor_ids = sorted( map(lambda x: int(x), game_config.normal_dungeon_config.keys())) for floor_id in floor_ids: for room_id in sorted(game_config.normal_dungeon_config[str(floor_id)] ['rooms'].keys()): data['all_dungeon'].append('%d-%s' % (floor_id, room_id)) #用户已经达到最深层时 if '%s-%s' % (data['current_dungeon']['floor_id'], data['current_dungeon'] ['room_id']) == data['all_dungeon'][-1]: data['max_dungeon'] = True else: data['max_dungeon'] = False now_index = data['all_dungeon'].index( '%s-%s' % (data['current_dungeon']['floor_id'], data['current_dungeon']['room_id'])) data['all_dungeon'] = data['all_dungeon'][now_index + 1:] #装备 equips = user_equips_obj.equips eqids_dict = [user_equips_obj.get_equip_dict(ueid) for ueid in equips] data['user_equips'] = [ game_config.equip_config.get(eid_dict['eid']) for eid_dict in eqids_dict ] all_equips_tag = sorted( [int(i.split('_')[0]) for i in game_config.equip_config.keys()]) data['all_equips'] = [(i, game_config.equip_config.get(str(i) + '_equip')) for i in all_equips_tag] #mat data['user_materials'] = { mid: { 'name': game_config.material_config.get(mid, {}).get('name', ''), 'num': user_pack_obj.materials[mid] } for mid in user_pack_obj.materials } all_materials_tag = sorted( [int(i.split('_')[0]) for i in game_config.material_config.keys()]) data['all_materials'] = [(i, game_config.material_config.get(str(i) + '_mat')) for i in all_materials_tag] #props data['user_props'] = { pid: { 'name': game_config.props_config.get(pid, {}).get('name'), 'num': user_pack_obj.props[pid] } for pid in user_pack_obj.props } all_props_tag = sorted( [int(i.split('_')[0]) for i in game_config.props_config.keys()]) data['all_props'] = [(i, game_config.props_config.get(str(i) + '_props')) for i in all_props_tag] ######将魂系统 代码要在其他逻辑偏后 以保证是最新的信息############## user_souls_obj = UserSouls.get_instance(uid) # 添加 普通将魂 if request.POST.get('add_normal_soul', ''): add_normal_soul_num = int(request.POST.get('add_normal_soul')) sid = request.POST.get('sid') user_souls_obj.add_normal_soul(sid, add_normal_soul_num, where=qa_edit) # 批量添加 普通将魂 if request.POST.get('dump_normal_soul'): dump_normal_soul_str = request.POST.get('dump_normal_soul').strip() for item in dump_normal_soul_str.split(';'): sid, num = item.split(':') user_souls_obj.add_normal_soul(sid + '_card', int(num), where=qa_edit) # 批量添加 装备碎片 if request.POST.get('add_equip_soul'): add_equip_soul_str = request.POST.get('add_equip_soul').strip() for equip_info in add_equip_soul_str.split(';'): eid, num = equip_info.split(':') user_souls_obj.add_equip_soul(eid, int(num), where=qa_edit) # 添加 英雄将魂 if request.POST.get('add_super_soul', ''): add_super_soul_num = int(request.POST.get('add_super_soul')) if add_super_soul_num >= 0: user_souls_obj.add_super_soul(add_super_soul_num, where=qa_edit) else: user_souls_obj.minus_card_soul('super_soul', -add_super_soul_num, where=qa_edit) # 武将碎片兑换武将 if request.POST.get('soul_exchange_card'): sid = request.POST.get('sid') params = {'cid': sid} user['uid'] = uid soul.exchange_card(user, params) # 删除将魂 if request.POST.get('delete_card_soul'): sid = request.POST.get('sid') num = int(request.POST.get('num')) user_souls_obj = UserSouls.get_instance(uid) user_souls_obj.minus_card_soul(sid, num, where=qa_edit) user_souls_obj.put() data.update(copy.deepcopy(soul.get_all(user, None)[1])) #武将碎片的显示 for sid, soul_conf in data['normal_souls'].items(): soul_conf['name'] = game_config.card_config[sid].get( 'star', '') + u'星 ' + game_config.card_config[sid].get('name', '') + u' 碎片' #装备碎片的显示 for sid, soul_conf in data['equip_souls_info'].items(): all_parts = sid.split('_') if len(all_parts) == 2: soul_conf['name'] = str(game_config.equip_config[sid].get( 'star', '')) + u'星 ' + game_config.equip_config[sid].get( 'name', '') + u' 碎片' else: sid = '%s_%s' % (all_parts[0], all_parts[1]) soul_conf['name'] = str(game_config.equip_config[sid].get( 'star', '')) + u'星 ' + game_config.equip_config[sid].get( 'name', '') + u' 碎片第%s部分' % all_parts[2] # 获取玩家武将信息 代码往后放 以保证是最新的信息 deck_num = 0 for card in user_card_obj.deck: if card: ucid = card['ucid'] card_info = user_card_obj.cards[ucid] this_card = Card.get_from_dict(card_info) this_card.ucid = ucid this_card.is_leader = card.get('leader', 0) eid = '' #user_card_obj.get_eid(ucid) if eid: this_card.equip = game_config.equip_config[eid]['name'] else: this_card.equip = '' this_card.now_exp = card_info['exp'] data['deck_cards'].append(this_card) deck_num += 1 else: data['deck_cards'].append(None) data['deck_num'] = deck_num other_ucids = user_card_obj.cards.keys() for card in user_card_obj.deck: ucid = card.get('ucid') if ucid and ucid in other_ucids: other_ucids.remove(ucid) for ucid in other_ucids: card_info = user_card_obj.cards[ucid] this_card = Card.get_from_dict(card_info) this_card.ucid = ucid this_card.now_exp = card_info['exp'] eid = '' #user_card_obj.get_eid(ucid) if eid: this_card.equip = game_config.equip_config[eid]['name'] else: this_card.equip = '' data['other_cards'].append(this_card) #重新整理 下编队 user_card_obj.decks # 邮件 show_mails = mails.show_mails(user, {})['show_mails'] temp_mails = show_mails.values() # 整理awards内容,就显示good_id和num for mail in temp_mails: for award in mail['awards'][:]: if not 'good_id' in award.values()[0]: continue mail['awards'].append({ award.values()[0]['good_id']: award.values()[0].get('num', 0) }) mail['awards'].pop(0) data.update({ 'mails': sorted(temp_mails, key=operator.itemgetter('can_get', 'create_time'), reverse=True), 'user_property_obj': user_property_obj, 'user': user, 'add_time': timestamp_toString(user.add_time), 'last_login_time': timestamp_toString(user.user_property.login_time), 'login_record': UserLogin.get(uid).login_info['login_record'], 'user_real_pvp_obj': user_real_pvp_obj.pvp_detail, 'mystery_store': mystery_store.get_store_info(user, {}), 'pk_store': pk_store.get_store_info(user, {}), }) return 'user/edit.html', data
def edit_user(request): """ 编辑用户页 """ uid = request.GET.get('uid','').strip() if not uid: pid = request.GET.get('pid','').strip() if not pid: username = request.GET.get('username','') if not username: return HttpResponseRedirect('/admin/user/?status=1') try: uid=ocapp.mongo_store.mongo.db['username'].find({'name':username})[0]['uid'] except: return HttpResponseRedirect('/admin/user/?status=1') else: account = AccountMapping.get(pid) if not account: return HttpResponseRedirect('/admin/user/?status=1') uid = account.uid user = UserBase.get(uid) if not user or not user.account: return HttpResponseRedirect('/admin/user/?status=1') user_equips_obj = UserEquips.get_instance(uid) user_pack_obj = UserPack.get_instance(uid) user_property_obj = UserProperty.get(uid) user_card_obj = UserCards.get(user.uid) user_real_pvp_obj = user.user_real_pvp game_config.set_subarea(user.subarea) data = { 'deck_cards':[], 'other_cards':[], } if not user.client_type: data['client_type'] = 'appstore_ios' else: data['client_type'] = user.client_type all_cards = [] all_cids = game_config.card_config.keys() all_cids_cp = copy.deepcopy(game_config.card_config) for k,v in all_cids_cp.iteritems(): all_cids_cp[k]['no'] = int(k.split('_')[0]) all_cids.sort(key = lambda x :(all_cids_cp[x]['no'])) for cid in all_cids: all_cards.append(Card.get(cid)) data['all_cards'] = all_cards #用户当前战场信息 user_dungeon_obj = UserDungeon.get_instance(user.uid) #充值信息 data['charge_sum_money'] = user_property_obj.charge_sum_money data['last_charge_record'] = ChargeRecord.find({'uid':uid})[-1] if ChargeRecord.find({'uid':uid}) else {} ######神秘商店 代码往前方 因为此操作会改变玩家武将,物品等信息############## # 刷新 物品列表 if request.POST.get('refresh_mystery_store',''): store_type = request.POST.get('store_type') params = { } mystery_store.refresh_store_by_self(user, params) # 购买 物品 if request.POST.get('buy_mystery_store_goods',''): store_type = request.POST.get('store_type') goods_index = int(request.POST.get('goods_index')) params = { 'store_type': store_type, 'goods_index': goods_index, } mystery_store.buy_store_goods(user, params) ######Pk商店 ## # 刷新 物品列表 if request.POST.get('refresh_pk_store', ''): pk_store.refresh_store_by_self(user, {}) # 购买 物品 if request.POST.get('buy_pk_store_goods',''): goods_index = int(request.POST.get('goods_index')) params = { 'goods_index': goods_index, } pk_store.buy_store_goods(user, params) #################### moderator = auth.get_moderator_by_request(request) qa_edit = 'qa edited by '+str(moderator.username) #提交状态 if request.method == "POST": state = int(request.POST.get("state","0")) state = bool(state) #冻结 if state != user.in_frozen: if state: user.froze() #解冻 else: user.unfroze() #删除账号 if request.POST.get('del_user',''): if not user.account: return HttpResponseRedirect('/admin/user/?status=1') user.account.delete() if request.POST.get('add_gold',''): add_gold = int(request.POST.get('add_gold')) if add_gold>0: user_property_obj.add_gold(add_gold,where=qa_edit) else: user_property_obj.minus_gold(add_gold) #增加元宝 if request.POST.get('add_coin',''): add_coin = int(request.POST.get('add_coin')) if add_coin>0: user_property_obj.add_coin(add_coin, where=qa_edit) else: user_property_obj.minus_coin(add_coin, where=qa_edit) #增加 经验点 if request.POST.get('add_card_point',''): add_card_point = int(request.POST.get('add_card_point')) if add_card_point>0: user_property_obj.add_card_exp_point(add_card_point, qa_edit) else: user_property_obj.minus_card_exp_point(add_card_point, qa_edit) #增加经验 if request.POST.get('add_exp',''): add_exp = int(request.POST.get('add_exp')) user_property_obj.add_exp(add_exp,where=qa_edit) #更改等级 if request.POST.get('modify_lv',''): lv = request.POST.get('modify_lv') lv_exp = game_config.user_level_config[lv]['exp'] now_exp = user_property_obj.property_info['exp'] user_property_obj.add_exp(lv_exp-now_exp,where=qa_edit) # 增加pk 积分 if request.POST.get('add_pk_pt', 0): pvp_pt = int(request.POST.get('add_pk_pt')) user_real_pvp_obj.add_pt(pvp_pt) # 加功勋 if request.POST.get('add_honor',''): honor = int(request.POST.get('add_honor')) urp = UserRealPvp.get(user.uid) urp.add_honor(honor, where=qa_edit) # 加战魂 if request.POST.get('add_fight_soul',''): fight_soul_num = int(request.POST.get('add_fight_soul')) user_property_obj.add_fight_soul(fight_soul_num, where=qa_edit) #发邮件 if request.POST.get('mail_title') or request.POST.get('mail_goods'): from apps.models.user_mail import UserMail from apps.common import utils sid = 'system_%s' % (utils.create_gen_id()) mail_title = request.POST.get('mail_title', '') mail_content = request.POST.get('mail_content', '') goods_str = request.POST.get('mail_goods', '').strip() award = {} for goods_info in goods_str.split(";"): goods_info = goods_info.strip() print "debug guochen email", goods_info if not goods_info: continue goods_id, num = goods_info.strip().split(":") award.setdefault(goods_id, 0) award[goods_id] += int(num) mailtype = 'system_qa' user_mail_obj = UserMail.hget(uid, sid) user_mail_obj.set_mail(mailtype=mailtype, title=mail_title, content=mail_content, award=award) # 修改vip等级 if request.POST.get('modify_vip_lv'): vip_lv = request.POST.get('modify_vip_lv') vip_conf = game_config.user_vip_config.get(str(vip_lv)) if vip_conf: coin = vip_conf['coin'] user_property_obj.property_info["charge_coins"] = coin user_property_obj.put() #补武将 if request.POST.get("add_card_ex", ""): user_card_obj = UserCards.get(user.uid) strCardInfo = request.POST.get("add_card_ex") lstCardInfo = strCardInfo.strip().split(";") for strAddCard in lstCardInfo: cid = strAddCard.split(":")[0] cid = cid.strip() + '_card' num = int(strAddCard.split(":")[1]) for i in range(num): clv = 1 user_card_obj.add_card(cid,clv,where=qa_edit) #增加武将 if request.POST.getlist('add_card'): add_cids = request.POST.getlist('add_card') user_card_obj = UserCards.get(user.uid) for add_cid in add_cids: if add_cid in game_config.card_config: clv = 1 user_card_obj.add_card(add_cid,clv,where=qa_edit) #增加武将经验 if request.POST.get('add_card_exp',''): add_exp = int(request.POST.get('add_card_exp')) ucid = request.POST.get('ucid') user_card_obj.add_card_exp(ucid,add_exp) #增加武将技能级别 if request.POST.get('add_card_sk_lv',''): ucid = request.POST.get('ucid') user_card_obj.add_card_sk_lv(ucid) #卖掉卡片 if request.POST.get('sell_card',''): ucid = request.POST.get('ucid') #this_card = Card.get(user_card_obj.cards[ucid]['cid'],user_card_obj.cards[ucid]['lv']) user_card_obj.del_card_info([ucid]) #user.user_property.add_gold(this_card.sell_gold,where=qa_edit) #踢出队伍 if request.POST.get('kick_deck',''): kick_index = int(request.POST.get('deck_index')) if user_card_obj.deck[kick_index].get('ucid','') != user_card_obj.get_leader(user_card_obj.cur_deck_index): user_card_obj.deck[kick_index] = {} user_card_obj.put() #设置主将 if request.POST.get('set_deck_main',''): ucid = request.POST.get('ucid') find_fg = False for card in user_card_obj.deck: if card.get('leader',0): card['ucid'] = ucid user_card_obj.put() find_fg = True break if not find_fg: user_card_obj.deck[0] = {'ucid':ucid,'leader':1} user_card_obj.put() #设置副将 if request.POST.get('set_deck_sub',''): ucid = request.POST.get('ucid') for card in user_card_obj.deck: if not card: card['ucid'] = ucid user_card_obj.put() break #一键送所有武将碎片 if request.POST.get('give_all_card_soul',''): for cid in game_config.card_config: user_card_obj.add_card(cid,1,where=qa_edit) user_card_obj.put() #一键送所有武将 if request.POST.get('give_all_card',''): #一键送所有武将 for cid in all_cids: ucid = user_card_obj.add_card(cid, 1, where=qa_edit)[2] # if request.POST.get('give_all_card',''): # user_card_obj.cards = {} # user_card_obj.cards_info = { # "decks":[[{}] * 5] * 10, # "cur_deck_index":0, # } # for eid in user_equips_obj.equips: # if user_equips_obj.equips[eid].get("used_by"): # user_equips_obj.equips[eid]['used_by'] = '' # user_equips_obj.put() # card_index = 0 # for cid in all_cids: # clv = 1 # ucid = user_card_obj.add_card(cid,clv,where=qa_edit)[2] # if card_index < 5: # user_card_obj.deck[card_index]['ucid'] = ucid # card_index += 1 #一键删除军队外的所有武将 if request.POST.get('del_other_card',''): decks = [] for deck in user_card_obj.decks: decks.extend([card['ucid'] for card in deck if card.get('ucid','')]) del_cids = filter(lambda x:x not in decks,user_card_obj.cards.keys()) user_card_obj.del_card_info(del_cids) for eid in user_equips_obj.equips: if user_equips_obj.equips[eid].get("used_by"): user_equips_obj.equips[eid]['used_by'] = '' user_equips_obj.put() #开放战场 if request.POST.get('open_dungeon',''): open_dungeon = request.POST.get('open_dungeon') floor_id = open_dungeon.split('-')[0] room_id = open_dungeon.split('-')[1] user_dungeon_obj.dungeon_info['normal_current']['floor_id'] = floor_id user_dungeon_obj.dungeon_info['normal_current']['room_id'] = room_id user_dungeon_obj.dungeon_info['normal_current']['status'] = 0 user_dungeon_obj.put() #回复体力 if request.POST.get('add_stamina', ''): add_stamina = int(request.POST.get('add_stamina')) user_property_obj.add_stamina(add_stamina) #equip if request.POST.get("add_equips", ""): user_equips_obj = UserEquips.get(uid) strEquipsInfo = request.POST.get("add_equips") lstEquipsInfo = strEquipsInfo.strip().split(";") for strAddEquip in lstEquipsInfo: eid = strAddEquip.split(":")[0] eid = eid.strip() + '_equip' num = int(strAddEquip.split(":")[1]) for i in range(num): user_equips_obj.add_equip(eid,where=qa_edit) #材料 if request.POST.get("add_mats", ""): strItemsInfo = request.POST.get("add_mats") lstItemsInfo = strItemsInfo.strip().split(";") for strAddItem in lstItemsInfo: mid = strAddItem.split(":")[0] mid = mid.strip() + '_mat' num = int(strAddItem.split(":")[1]) user_pack_obj.add_material(mid,num,where=qa_edit) #道具 if request.POST.get("add_props", ""): strPropsInfo = request.POST.get("add_props") lstPropsInfo = strPropsInfo.strip().split(";") for strAddProps in lstPropsInfo: pid = strAddProps.split(":")[0] pid = pid.strip() + '_props' num = int(strAddProps.split(":")[1]) user_pack_obj.add_props(pid,num,where=qa_edit) if request.POST.get("add_materials_num", 0): mid = request.POST.get("mid") user_pack_obj.add_material(mid,int(request.POST.get("add_materials_num", 0)),where=qa_edit) if request.POST.get("add_props_num", 0): pid = request.POST["prop"] user_pack_obj.add_props(pid, int(request.POST.get("add_props_num", 0)),where=qa_edit) if request.POST.get('give_all_props'): num = int(request.POST.get('all_props_num'))if request.POST.get('all_props_num') else 99 for iid in game_config.props_config: user_pack_obj.add_props(iid,num,where=qa_edit) if request.POST.get('del_all_props'): user_pack_obj.props = {} user_pack_obj.put() if request.POST.get('give_all_equips'): user_equips = UserEquips.get(uid) for eid in game_config.equip_config: user_equips.add_equip(eid,where=qa_edit) #一键送所有的装备碎片 if request.POST.get('give_all_equip_soul'): user_souls_obj = UserSouls.get(uid) for eid in game_config.equip_config: if game_config.equip_config[eid].get('need_soul_types_num',0): parts = game_config.equip_config[eid].get('need_soul_types_num',0) for i in xrange(1,parts+1): user_souls_obj.add_equip_soul(eid+'_'+str(i),100,where=qa_edit) else: user_souls_obj.add_equip_soul(eid,1,where=qa_edit) #一键删除所有的装备碎片 if request.POST.get('del_all_equip_soul'): user_souls_obj = UserSouls.get(uid) user_souls_obj.equip_souls_info = {} user_souls_obj.put() #添加单个装备碎片 if request.POST.get('add_single_equip_soul'): sid = request.POST.get('sid') num = int(request.POST.get('add_single_equip_soul')) user_souls_obj = UserSouls.get_instance(uid) user_souls_obj.add_equip_soul(sid, num,where=qa_edit) user_souls_obj.put() if request.POST.get('del_other_equips'): user_equips = UserEquips.get(uid) ueids = [ ueid for ueid in user_equips.equips if not user_equips.is_used(ueid)] user_equips.delete_equip(ueids) if request.POST.get('give_all_materials'): num = int(request.POST.get('all_materials_num'))if request.POST.get('all_materials_num') else 99 user_pack_obj = UserPack.get_instance(uid) for mid in game_config.material_config: user_pack_obj.add_material(mid,num,where=qa_edit) if request.POST.get('del_all_materials'): user_pack_obj = UserPack.get_instance(uid) user_pack_obj.materials = {} user_pack_obj.put() #一键过新手引导 if request.POST.get('newbie_pass','') and user.user_property.newbie: newbie_steps_num = int(user.game_config.system_config.get('newbie_steps', 6)) user.user_property.property_info['newbie_steps'] = (1 << newbie_steps_num) - 1 user.user_property.set_newbie() user.user_property.do_put() data['status'] = 1 data['current_dungeon'] = user_dungeon_obj.dungeon_info['normal_current'] #配置中的所有战场 data['all_dungeon'] = [] floor_ids = sorted(map(lambda x:int(x),game_config.normal_dungeon_config.keys())) for floor_id in floor_ids: for room_id in sorted(game_config.normal_dungeon_config[str(floor_id)]['rooms'].keys()): data['all_dungeon'].append('%d-%s' % (floor_id,room_id)) #用户已经达到最深层时 if '%s-%s' % (data['current_dungeon']['floor_id'],data['current_dungeon']['room_id']) == data['all_dungeon'][-1]: data['max_dungeon'] = True else: data['max_dungeon'] = False now_index = data['all_dungeon'].index('%s-%s' % (data['current_dungeon']['floor_id'],data['current_dungeon']['room_id'])) data['all_dungeon'] = data['all_dungeon'][now_index + 1:] #装备 equips = user_equips_obj.equips eqids_dict = [user_equips_obj.get_equip_dict(ueid) for ueid in equips ] data['user_equips'] = [game_config.equip_config.get(eid_dict['eid']) for eid_dict in eqids_dict] all_equips_tag = sorted([int(i.split('_')[0]) for i in game_config.equip_config.keys()]) data['all_equips'] = [(i,game_config.equip_config.get(str(i)+'_equip')) for i in all_equips_tag] #mat data['user_materials'] = {mid :{'name':game_config.material_config.get(mid, {}).get('name', ''),'num':user_pack_obj.materials[mid]} for mid in user_pack_obj.materials } all_materials_tag = sorted([int(i.split('_')[0]) for i in game_config.material_config.keys()]) data['all_materials'] = [(i,game_config.material_config.get(str(i)+'_mat')) for i in all_materials_tag] #props data['user_props'] = {pid :{'name':game_config.props_config.get(pid, {}).get('name'),'num':user_pack_obj.props[pid]} for pid in user_pack_obj.props } all_props_tag = sorted([int(i.split('_')[0]) for i in game_config.props_config.keys()]) data['all_props'] = [(i,game_config.props_config.get(str(i)+'_props')) for i in all_props_tag] ######将魂系统 代码要在其他逻辑偏后 以保证是最新的信息############## user_souls_obj = UserSouls.get_instance(uid) # 添加 普通将魂 if request.POST.get('add_normal_soul',''): add_normal_soul_num = int(request.POST.get('add_normal_soul')) sid = request.POST.get('sid') user_souls_obj.add_normal_soul(sid, add_normal_soul_num, where=qa_edit) # 批量添加 普通将魂 if request.POST.get('dump_normal_soul'): dump_normal_soul_str = request.POST.get('dump_normal_soul').strip() for item in dump_normal_soul_str.split(';'): sid, num = item.split(':') user_souls_obj.add_normal_soul(sid + '_card', int(num), where=qa_edit) # 批量添加 装备碎片 if request.POST.get('add_equip_soul'): add_equip_soul_str = request.POST.get('add_equip_soul').strip() for equip_info in add_equip_soul_str.split(';'): eid, num = equip_info.split(':') user_souls_obj.add_equip_soul(eid, int(num), where=qa_edit) # 添加 英雄将魂 if request.POST.get('add_super_soul',''): add_super_soul_num = int(request.POST.get('add_super_soul')) if add_super_soul_num >= 0: user_souls_obj.add_super_soul(add_super_soul_num, where=qa_edit) else: user_souls_obj.minus_card_soul('super_soul', -add_super_soul_num, where=qa_edit) # 武将碎片兑换武将 if request.POST.get('soul_exchange_card'): sid = request.POST.get('sid') params = {'cid':sid} user['uid'] = uid soul.exchange_card(user, params) # 删除将魂 if request.POST.get('delete_card_soul'): sid = request.POST.get('sid') num = int(request.POST.get('num')) user_souls_obj = UserSouls.get_instance(uid) user_souls_obj.minus_card_soul(sid, num,where=qa_edit) user_souls_obj.put() data.update(copy.deepcopy(soul.get_all(user, None)[1])) #武将碎片的显示 for sid, soul_conf in data['normal_souls'].items(): soul_conf['name'] = game_config.card_config[sid].get('star','') + u'星 ' + game_config.card_config[sid].get('name','') + u' 碎片' #装备碎片的显示 for sid, soul_conf in data['equip_souls_info'].items(): all_parts = sid.split('_') if len(all_parts) == 2: soul_conf['name'] = str(game_config.equip_config[sid].get('star','')) + u'星 ' + game_config.equip_config[sid].get('name','') + u' 碎片' else: sid = '%s_%s'%(all_parts[0],all_parts[1]) soul_conf['name'] = str(game_config.equip_config[sid].get('star','')) + u'星 ' + game_config.equip_config[sid].get('name','') + u' 碎片第%s部分'%all_parts[2] # 获取玩家武将信息 代码往后放 以保证是最新的信息 deck_num = 0 for card in user_card_obj.deck: if card: ucid = card['ucid'] card_info = user_card_obj.cards[ucid] this_card = Card.get_from_dict(card_info) this_card.ucid = ucid this_card.is_leader = card.get('leader',0) eid = ''#user_card_obj.get_eid(ucid) if eid: this_card.equip = game_config.equip_config[eid]['name'] else: this_card.equip = '' this_card.now_exp = card_info['exp'] data['deck_cards'].append(this_card) deck_num += 1 else: data['deck_cards'].append(None) data['deck_num'] = deck_num other_ucids = user_card_obj.cards.keys() for card in user_card_obj.deck: ucid = card.get('ucid') if ucid and ucid in other_ucids: other_ucids.remove(ucid) for ucid in other_ucids: card_info = user_card_obj.cards[ucid] this_card = Card.get_from_dict(card_info) this_card.ucid = ucid this_card.now_exp = card_info['exp'] eid = ''#user_card_obj.get_eid(ucid) if eid: this_card.equip = game_config.equip_config[eid]['name'] else: this_card.equip = '' data['other_cards'].append(this_card) #重新整理 下编队 user_card_obj.decks # 邮件 show_mails = mails.show_mails(user, {})['show_mails'] temp_mails = show_mails.values() # 整理awards内容,就显示good_id和num for mail in temp_mails: for award in mail['awards'][:]: if not 'good_id' in award.values()[0]: continue mail['awards'].append({award.values()[0]['good_id']: award.values()[0].get('num', 0)}) mail['awards'].pop(0) data.update({ 'mails': sorted(temp_mails, key=operator.itemgetter('can_get', 'create_time'), reverse=True), 'user_property_obj':user_property_obj, 'user':user, 'add_time':timestamp_toString(user.add_time), 'last_login_time':timestamp_toString(user.user_property.login_time), 'login_record':UserLogin.get(uid).login_info['login_record'], 'user_real_pvp_obj': user_real_pvp_obj.pvp_detail, 'mystery_store': mystery_store.get_store_info(user, {}), 'pk_store': pk_store.get_store_info(user, {}), }) return 'user/edit.html', data
def test_give_award(self, award, where=None): ''' 发奖励 返回格式化后的信息 ''' data = {} for k in award: if k == 'coin': #处理元宝奖励 self.add_coin(award[k], where=where) #格式化返回的参数 data[k] = award[k] elif k == 'gold': #处理金币的奖励 self.add_gold(award[k], where=where) #格式化返回的参数 data[k] = award[k] elif k == 'card': #处理武将的奖励 from apps.models.user_cards import UserCards uc = UserCards.get(self.uid) data[k] = [] for cid in award[k]: #获取武将的数量 num = int(award[k][cid]) for i in xrange(num): #添加武将并记录 fg, all_cards_num, ucid, is_first = uc.add_card( cid, 1, where=where) tmp = {'ucid': ucid} tmp.update(uc.cards[ucid]) #格式化返回的参数 data[k].append(tmp) elif k == 'equip': from apps.models.user_equips import UserEquips ue = UserEquips.get(self.uid) data[k] = [] for eid in award[k]: #获取装备的数量 num = int(award[k][eid]) for i in xrange(num): #添加装备并记录 fg, all_equips_num, ueid, is_first = ue.add_equip( eid, where=where) tmp = {'ueid': ueid} tmp.update(ue.equips[ueid]) #格式化返回的参数 data[k].append(tmp) elif k == 'mat': data[k] = {} from apps.models.user_pack import UserPack up = UserPack.get_instance(self.uid) for material_id in award[k]: num = int(award[k][material_id]) if material_id not in data[k]: data[k][material_id] = 0 #格式化返回的参数 data[k][material_id] += num up.add_material(material_id, num, where=where) elif k == 'item': data[k] = {} from apps.models.user_pack import UserPack up = UserPack.get_instance(self.uid) for item_id in award[k]: num = int(award[k][item_id]) if item_id not in data[k]: data[k][item_id] = 0 #格式化返回的参数 data[k][item_id] += num up.add_item(item_id, num, where=where) elif k == 'props': data[k] = {} from apps.models.user_pack import UserPack up = UserPack.get_instance(self.uid) for props_id in award[k]: num = int(award[k][props_id]) if props_id not in data[k]: data[k][props_id] = 0 #格式化返回的参数 data[k][props_id] += num #用户添加道具 up.add_props(props_id, num, where=where) elif k == 'soul': #处理碎片的逻辑 data[k] = {} soul_info = award[k] us = UserSouls.get_instance(self.uid) for soul_type in soul_info: if soul_type == 'card': #处理武将碎片的逻辑 data[k][soul_type] = {} card_soul_info = soul_info[soul_type] for card_id in card_soul_info: num = int(card_soul_info[card_id]) if card_id not in data[k][soul_type]: data[k][soul_type][card_id] = 0 #格式化返回的参数 data[k][soul_type][card_id] += num #用户添加碎片 us.add_normal_soul(card_id, num, where=where) elif soul_type == 'equip': #处理装备碎片的逻辑 data[k][soul_type] = {} equip_soul_info = soul_info[soul_type] for equip_id in equip_soul_info: num = int(equip_soul_info[equip_id]) if equip_id not in data[k][soul_type]: data[k][soul_type][equip_id] = 0 #格式化返回的参数 data[k][soul_type][equip_id] += num #用户添加碎片 us.add_equip_soul(equip_id, num, where=where) else: #未识别碎片 pass elif k == 'stamina': #添加体力信息 self.add_stamina(int(award[k])) #格式化返回的参数 data[k] = int(award[k]) elif k == 'normal_soul': data[k] = {} user_souls_obj = self.user_souls for soul_id in award[k]: user_souls_obj.add_normal_soul(soul_id, award[k][soul_id], where) data[k][soul_id] = award[k][soul_id] elif k == 'exp': # 经验 self.add_exp(award[k], where=where) data[k] = award[k] elif k == 'exp_point': # 卡经验 self.add_card_exp_point(award[k], where=where) data[k] = award[k] else: pass return data
from apps.models.user_real_pvp import UserRealPvp from apps.models.user_base import UserBase # from apps.models.user_property import UserProperty # from apps.models.friend import Friend from apps.models import pvp_redis from apps.oclib import app from apps.models.user_mail import UserMail from apps.realtime_pvp import readying_player_redis from apps.config.game_config import game_config from apps.models.pvp_redis import get_pvp_redis from apps.models.user_property import UserProperty from apps.models.user_gift import UserGift from apps.models.user_souls import UserSouls game_config.subareas_conf() game_config.set_subarea('1') us = UserSouls.get_instance(uid) def clear_equip_souls(): us.equip_souls_info = {} us.do_put() #clear_equip_souls() def clear_card_souls(): us.normal_souls = {} us.do_put() #clear_card_souls() def show_card_souls(): us = UserSouls.get_instance(uid) print us.normal_souls #show_card_souls()
def wipe_out(): ''' 扫荡 目前只有普通战场有扫荡 ''' d_type = 'normal' floor_id = '1' room_id = '1' do_times = 1 # 扫荡次数 data = {} if d_type not in ['normal'] or not floor_id or not room_id or do_times not in [1, 10]: return 11,{'msg':utils.get_msg('dungeon', 'invalid_params')} # user_dungeon = UserDungeon.get(uid) has_played_info = user_dungeon.has_played_info ''' has_played_floor = has_played_info[d_type].get(floor_id) # 未达到此战场 if not has_played_floor: return 11,{'msg':utils.get_msg('dungeon', 'not_arrived')} # has_played_room = has_played_floor['rooms'].get(room_id) if not has_played_room: return 11,{'msg':utils.get_msg('dungeon', 'not_arrived')} # # 没达到3星 if not has_played_room['perfect']: return 11,{'msg':utils.get_msg('dungeon', 'not_three_star')} # ''' try: has_played_info[d_type][floor_id]['rooms'][room_id] except: return 11,{'msg':utils.get_msg('dungeon', 'not_three_star')} # 没达到3星(完美过关) if not has_played_info[d_type][floor_id]['rooms'][room_id]['perfect']: return 11,{'msg':utils.get_msg('dungeon', 'not_three_star')} # 扫荡券不够 user_pack = UserPack.get_instance(uid) if not user_pack.is_props_enough('24_props', do_times): return 11,{'msg':utils.get_msg('dungeon', 'wipe_out_not_enough')} # # 目前只有普通战场 dungeon_config = game_config.normal_dungeon_config room_config = dungeon_config[floor_id]['rooms'][room_id] # 计算能够扫荡次数 can_make_copy_cnt = room_config['can_make_copy_cn'] if d_type == 'normal': try: # 判断dungeon_repeat_info中有无此关卡记录 user_dungeon.dungeon_repeat_info[d_type][floor_id][room_id] += 0 except : # 无此关卡记录时,把此关卡今日完成次数置零 if d_type not in user_dungeon.dungeon_repeat_info: user_dungeon.dungeon_repeat_info[d_type]={} if floor_id not in user_dungeon.dungeon_repeat_info[d_type]: user_dungeon.dungeon_repeat_info[d_type][floor_id] = {} if room_id not in user_dungeon.dungeon_repeat_info[d_type][floor_id]: user_dungeon.dungeon_repeat_info[d_type][floor_id][room_id] = 0 user_dungeon.do_put() has_played_cnt = user_dungeon.dungeon_repeat_info[d_type][floor_id][room_id] can_wipe_out_cnt = can_make_copy_cnt - has_played_cnt print can_make_copy_cnt, has_played_cnt # 进入战场次数用完,不能扫荡 if can_wipe_out_cnt <= 0: return 11,{'msg':utils.get_msg('dungeon', 'invalid_limit_dungeon')} # 剩余战场次数不够扫荡十次 if can_wipe_out_cnt < do_times: return 11,{'msg':utils.get_msg('dungeon', 'can_not_do_ten_times')} # 扫荡战利品 get_goods = { 'exp': 0, 'exp_point': 0, 'gold': 0, 'card': {}, 'equip': {}, 'soul':{ 'card': {}, 'equip': {}, }, 'mat': {}, 'props': {}, } # 扫荡一次能够得到的经验,卡经验点,和钱币 get_goods['exp'] += room_config.get('exp', 0) * do_times get_goods['exp_point'] += room_config.get('exp_point', 0) * do_times get_goods['gold'] += room_config.get('gold', 0) * do_times # 扫荡能够得到的物品 drop_info = _pack_drop_info(room_config.get('drop_info', {})) invisible_drop = _pack_drop_info(room_config.get('invisible_drop', {})) drop_info.extend(invisible_drop) # 有掉落物品(包括可见和不可见)时计算掉落, 不用战斗所以不区分可见不可见 if drop_info: # sample ['12002_equip', '5_card_soul', '53001_equip_1_soul', '6_card', '23_props', '8_props'] drop_info = list(set(drop_info)) # list去重 drop_info_config = game_config.drop_info_config['normal_dungeon'] # 检查战场掉落配置中是否有此物品 for goods_id in drop_info: print 'goods_id------*--*-*-*-*-*--*-*-*-*-------', goods_id if 'soul' in goods_id: if goods_id[:-5] not in drop_info_config['soul']: return 11,{'msg':utils.get_msg('dungeon', 'no_this_goods')} else: if goods_id not in drop_info_config: return 11,{'msg':utils.get_msg('dungeon', 'no_this_goods')} # 计算掉落数量 for n in range(do_times): for goods_id in drop_info: if 'soul' in goods_id: goods_id = goods_id[:-5] # 去掉'_soul'后缀 value_config = drop_info_config['soul'][goods_id]['visible'] # 根据配置概率判断是否得到 if utils.is_happen(value_config[1]): num = random.randint(value_config[0][0], value_config[0][1]) soul_type = 'card' if 'card' in goods_id else 'equip' if goods_id not in get_goods['soul'][soul_type]: get_goods['soul'][soul_type][goods_id] = num else: get_goods['soul'][soul_type][goods_id] += num else: continue else: value_config = drop_info_config[goods_id]['visible'] # 根据配置概率判断是否得到 if utils.is_happen(value_config[1]): num = random.randint(value_config[0][0], value_config[0][1]) for t in ['card', 'equip', 'props', 'mat']: if t in goods_id: get_type = t if goods_id not in get_goods[get_type]: get_goods[get_type][goods_id] = num else: get_goods[get_type][goods_id] += num else: continue # 减扫荡券 user_pack = UserPack.get_instance(uid) user_pack.minus_props('24_props', do_times, 'wipe_out') # 添加扫荡奖励 user_property = UserProperty.get_instance(uid) tmpdata = user_property.test_give_award(get_goods, where='wipe out') user_property.do_put() uc = UserCards.get_instance(uid) uc.do_put() ue = UserEquips.get_instance(uid) ue.do_put() up = UserPack.get_instance(uid) up.do_put() us = UserSouls.get_instance(uid) us.do_put() # 记录repeat info user_dungeon.add_repeat_cnt(d_type, floor_id, room_id, do_times) user_dungeon.do_put() # 给前端 data['get_exp'] = tmpdata['exp'] data['get_exp_point'] = tmpdata['exp_point'] data['get_gold'] = tmpdata['gold'] data['get_card'] = tmpdata['card'] data['get_equip'] = tmpdata['equip'] data['get_souls'] = tmpdata['soul'] data['get_material'] = tmpdata['mat'] data['get_props'] = tmpdata['props'] print data
def show_card_souls(): us = UserSouls.get_instance(uid) print us.normal_souls
def show_equip_souls(): us = UserSouls.get_instance(uid) print us.equip_souls_info
def get_equip_souls(rk_user, params): ''' #获取用户的装备碎片信息 ''' user_souls_obj = UserSouls.get_instance(rk_user.uid) return 0, user_souls_obj.get_equip_souls()
def test_give_award(self, award, where=None): ''' 发奖励 返回格式化后的信息 ''' data = {} for k in award: if k == 'coin': #处理元宝奖励 self.add_coin(award[k],where=where) #格式化返回的参数 data[k] = award[k] elif k == 'gold': #处理金币的奖励 self.add_gold(award[k],where=where) #格式化返回的参数 data[k] = award[k] elif k == 'card': #处理武将的奖励 from apps.models.user_cards import UserCards uc = UserCards.get(self.uid) data[k] = [] for cid in award[k]: #获取武将的数量 num = int(award[k][cid]) for i in xrange(num): #添加武将并记录 fg,all_cards_num,ucid,is_first = uc.add_card(cid,1,where=where) tmp = {'ucid':ucid} tmp.update(uc.cards[ucid]) #格式化返回的参数 data[k].append(tmp) elif k == 'equip': from apps.models.user_equips import UserEquips ue = UserEquips.get(self.uid) data[k] = [] for eid in award[k]: #获取装备的数量 num = int(award[k][eid]) for i in xrange(num): #添加装备并记录 fg,all_equips_num,ueid,is_first = ue.add_equip(eid,where=where) tmp = {'ueid':ueid} tmp.update(ue.equips[ueid]) #格式化返回的参数 data[k].append(tmp) elif k == 'mat': data[k] = {} from apps.models.user_pack import UserPack up = UserPack.get_instance(self.uid) for material_id in award[k]: num = int(award[k][material_id]) if material_id not in data[k]: data[k][material_id] = 0 #格式化返回的参数 data[k][material_id] += num up.add_material(material_id,num,where=where) elif k == 'item': data[k] = {} from apps.models.user_pack import UserPack up = UserPack.get_instance(self.uid) for item_id in award[k]: num = int(award[k][item_id]) if item_id not in data[k]: data[k][item_id] = 0 #格式化返回的参数 data[k][item_id] += num up.add_item(item_id,num,where=where) elif k == 'props': data[k] = {} from apps.models.user_pack import UserPack up = UserPack.get_instance(self.uid) for props_id in award[k]: num = int(award[k][props_id]) if props_id not in data[k]: data[k][props_id] = 0 #格式化返回的参数 data[k][props_id] += num #用户添加道具 up.add_props(props_id,num,where=where) elif k == 'soul': #处理碎片的逻辑 data[k] = {} soul_info = award[k] us = UserSouls.get_instance(self.uid) for soul_type in soul_info: if soul_type == 'card': #处理武将碎片的逻辑 data[k][soul_type] = {} card_soul_info = soul_info[soul_type] for card_id in card_soul_info: num = int(card_soul_info[card_id]) if card_id not in data[k][soul_type]: data[k][soul_type][card_id] = 0 #格式化返回的参数 data[k][soul_type][card_id] += num #用户添加碎片 us.add_normal_soul(card_id,num,where=where) elif soul_type == 'equip': #处理装备碎片的逻辑 data[k][soul_type] = {} equip_soul_info = soul_info[soul_type] for equip_id in equip_soul_info: num = int(equip_soul_info[equip_id]) if equip_id not in data[k][soul_type]: data[k][soul_type][equip_id] = 0 #格式化返回的参数 data[k][soul_type][equip_id] += num #用户添加碎片 us.add_equip_soul(equip_id,num,where=where) else: #未识别碎片 pass elif k == 'stamina': #添加体力信息 self.add_stamina(int(award[k])) #格式化返回的参数 data[k] = int(award[k]) elif k == 'normal_soul': data[k] = {} user_souls_obj = self.user_souls for soul_id in award[k]: user_souls_obj.add_normal_soul(soul_id, award[k][soul_id], where) data[k][soul_id] = award[k][soul_id] elif k == 'exp': # 经验 self.add_exp(award[k], where=where) data[k] = award[k] elif k == 'exp_point': # 卡经验 self.add_card_exp_point(award[k], where=where) data[k] = award[k] else: pass return data
def give_award(self,award,where=None): """ 给用户奖励 """ tmp = {} for key in award: if key == 'gold': self.add_gold(award[key],'award_%s' % where) tmp[key] = award[key] elif key == 'coin': self.add_coin(award[key],'award_%s' % where) tmp[key] = award[key] elif key == 'card': tmp[key] = {} from apps.models.user_cards import UserCards uc = UserCards.get(self.uid) for cid in award[key]: this_card = CardMod.get(cid, game_config=self.game_config) lv = min(award[key][cid].get('lv',1),this_card.max_lv) num = award[key][cid].get("num", 1) category = award[key][cid].get("category", '') quality = award[key][cid].get("quality", '') for index in range(num): fg,all_cards_num,ucid,is_first = uc.add_card(cid,lv,where='award_%s' % where,category=category,quality=quality) tmp[key][ucid] = uc.get_card_dict(ucid) elif key == 'equip': tmp[key] = {} from apps.models.user_equips import UserEquips eq_obj = UserEquips.get(self.uid) for equip in award[key]: num = award[key][equip].get("num", 1) for ind in range(num): fg,all_equips_num,ueid,is_first = eq_obj.add_equip(equip,'award_%s' % where) tmp[key][ueid] = eq_obj.get_equip_dict(ueid) elif key == 'item': tmp[key] = {} user_pack_obj = self.user_pack for item_id in award[key]: user_pack_obj.add_item(item_id, award[key][item_id],'award_%s' % where) tmp[key][item_id] = award[key][item_id] elif key == 'material': tmp[key] = {} user_pack_obj = self.user_pack for material_id in award[key]: user_pack_obj.add_material(material_id, award[key][material_id],'award_%s' % where) tmp[key][material_id] = award[key][material_id] elif key == 'stamina': self.add_stamina(int(award[key])) tmp[key] = award[key] #elif key == 'super_soul': # user_souls_obj = UserSouls.get_instance(self.uid) # user_souls_obj.add_super_soul(int(award[key]), 'award_%s' % where) # tmp[key] = award[key] elif key == 'normal_soul': tmp[key] = {} user_souls_obj = UserSouls.get_instance(self.uid) for soul_id in award[key]: user_souls_obj.add_normal_soul(soul_id, award[key][soul_id], 'award_%s' % where) tmp[key][soul_id] = award[key][soul_id] elif key == 'renown': user_pvp_obj = self.user_base.user_pvp user_pvp_obj.add_renown(int(award[key])) elif key == 'honor': user_real_pvp = self.user_real_pvp user_real_pvp.add_honor(award[key]) tmp[key] = award[key] return tmp
def get_equip_souls(rk_user,params): ''' #获取用户的装备碎片信息 ''' user_souls_obj = UserSouls.get_instance(rk_user.uid) return 0, user_souls_obj.get_equip_souls()
def end(rk_user,params): """ 离开战场请求 """ data = {} user_dungeon_obj = UserDungeon.get(rk_user.uid) #记录中如果没有未完成的战场,则返回 if not user_dungeon_obj.dungeon_info['last'].get('floor_id'): return 11,{'msg':utils.get_msg('dungeon','already_end')} #给用户奖励 last_info = user_dungeon_obj.dungeon_info['last'] floor_id = last_info['floor_id'] room_id = last_info['room_id'] dungeon_type = last_info['dungeon_type'] #检查场和局 para_floor_id = params['floor_id'] para_room_id = params['room_id'] para_dungeon_type = params['dungeon_type'] where = 'dungeon_%s_%s_%s' % (para_dungeon_type, para_floor_id, para_room_id) if floor_id != para_floor_id or room_id != para_room_id or dungeon_type != para_dungeon_type: return 11,{'msg':utils.get_msg('dungeon','unsame_dungeon')} #检查战场唯一标识 para_dungeon_uid = params.get('dungeon_uid','') if para_dungeon_uid and para_dungeon_uid != last_info['dungeon_uid']: return 11,{'msg':utils.get_msg('dungeon','unsame_dungeon')} #判断战场是否是完成的 if params.get('result','1') == '0': data = {'dungeon_fail': True}#__resolve_fail(rk_user,user_dungeon_obj,ver=float(params['version'])) return 0,data #获取获得的金币 user_gold = int(params['user_gold']) #胜利扣除复活的元宝 if 'revive_coin' in last_info: if not rk_user.user_property.minus_coin(last_info['revive_coin'], 'revive_%s_%s_%s'%(last_info.get("floor_id"),last_info.get("room_id"),last_info.get("dungeon_type"))): return 11,{'msg':utils.get_msg('dungeon','revive_err')} #金币 打怪掉的 get_gold = min(user_gold,last_info['total_gold']) #获取打怪掉的和通关奖励的金币之和 get_gold = int((get_gold + last_info['dungeon_gold'])) if get_gold: rk_user.user_property.add_gold(get_gold,where) data['get_gold'] = get_gold ####异常记录#### if user_gold > last_info['total_gold']: dungeon_except = ExceptUsers.get_instance('normal_dungeon') dungeon_except.set_users('%s_%s'%(floor_id,room_id),rk_user.uid) # all_drop_info mat item props 添加背包里面的掉落信息 all_drop_info = last_info['all_drop_info'] user_pack_obj = UserPack.get(rk_user.uid) data['get_material'] = {} # data['get_item'] = {} data['get_props'] = {} pack_list = ['mat','item','props'] for drop_type in pack_list: drop_info = all_drop_info.get(drop_type,{}) for drop_id in drop_info: num = int(drop_info[drop_id]) if drop_type == 'mat': #添加素材 user_pack_obj.add_material(drop_id, num, where=where) data['get_material'][drop_id] = num elif drop_type == 'props': #添加道具 user_pack_obj.add_props(drop_id, num, where=where) data['get_props'][drop_id] = num else: pass # 成功打完战场才扣体力 need_stamina = last_info['dungeon_stamina'] #新手用户可以几天不用体力 # if datetime.datetime.now() < \ # utils.timestamp_toDatetime(rk_user.add_time) + datetime.timedelta(days=game_config.system_config.get('newbie_days',0)): # last_info['need_stamina'] = need_stamina # elif rk_user.user_property.charged_user and user_dungeon_obj.can_free_stamina(): # #付费用户每天可以有多少次可以不扣体力 # last_info['need_stamina'] = need_stamina # user_dungeon_obj.add_free_stamina_cnt() # else: # 需要扣除体力 进战场时已经扣一点 这里只扣剩下的 rk_user.user_property.minus_stamina(max(need_stamina - 1, 0)) #加碎片 data['get_souls'] = {} if last_info['all_drop_info'].get('soul'): user_souls_obj = UserSouls.get_instance(rk_user.uid) soul = last_info['all_drop_info']['soul'] for soul_type in soul: data['get_souls'][soul_type] = {} if soul_type == 'equip': #如果碎片是普通装备的话的处理逻辑 drop_soul_info = soul[soul_type] for drop_id in drop_soul_info: num = int(drop_soul_info[drop_id]) #装备的添加 user_souls_obj.add_equip_soul(drop_id,num,where=where) data['get_souls'][soul_type][drop_id] = num elif soul_type == 'card': #如果碎片类型是武将的话 drop_card_soul_info = soul[soul_type] for drop_id in drop_card_soul_info: num = int(drop_card_soul_info[drop_id]) user_souls_obj.add_normal_soul(drop_id,num,where=where) data['get_souls'][soul_type][drop_id] = num else: pass #处理装备掉落返回值 user_equip_obj = UserEquips.get(rk_user.uid) get_equips = [] for eid in last_info['all_drop_info'].get('equip',{}): num = int(last_info['all_drop_info']['equip'][eid]) for i in xrange(num): fg, all_equips_num, ueid, is_first = user_equip_obj.add_equip(eid, where=where) temp = { 'ueid':ueid, } temp.update(user_equip_obj.equips[ueid]) get_equips.append(temp) data['get_equip'] = get_equips user_card_obj = UserCards.get(rk_user.uid) #图鉴更新列表 get_cards = [] for cid in last_info['all_drop_info'].get('card',{}): num = int(last_info['all_drop_info']['card'][cid]) for i in xrange(num): card_lv = 1 success_fg,all_cards_num,ucid,is_first = user_card_obj.add_card(cid,card_lv,where=where) temp = { 'ucid':ucid, } temp.update(user_card_obj.cards[ucid]) get_cards.append(temp) #加经验 lv_up,get_upg_data = rk_user.user_property.add_exp(last_info['exp'],where) data['get_exp'] = last_info['exp'] get_cards.extend(get_upg_data.get('get_card',[])) #添加经验点 get_exp_point = last_info['exp_point'] if get_exp_point: rk_user.user_property.add_card_exp_point(get_exp_point, where) data['get_exp_point'] = get_exp_point data['get_card'] = get_cards #用户升级的用于引导奖励 if 'get_material' in get_upg_data: for mat_id in get_upg_data['get_material']: if mat_id in data['get_material']: data['get_material'][mat_id] += get_upg_data['get_material'][mat_id] else: data['get_material'][mat_id] = get_upg_data['get_material'][mat_id] #判断新手引导 newbie_step = int(params.get('newbie_step',0)) if newbie_step: rk_user.user_property.set_newbie_steps(newbie_step, where) #更新用户的迷宫状态 data['dungeon_info'] = user_dungeon_obj.update_dungeon_info(dungeon_type,floor_id,room_id,once_daily = last_info.get('once_daily',False)) if 'clear_floor_coin' in data['dungeon_info']: data['clear_floor_coin'] = data['dungeon_info'].pop('clear_floor_coin') log_data = { 'statament': 'end', 'dungeon_id': '%s_%s' % (para_floor_id,para_room_id), 'dungeon_type': para_dungeon_type, 'card_deck': user_card_obj.deck, 'exp_point': get_exp_point, 'lv': rk_user.user_property.lv, } #记录该次战场的星级 if dungeon_type in ['normal', 'daily']: #获取难度系数 hard_ratio = params.get('hard_ratio', 'normal') # 中等难度 #获取星级系数 star_ratio = int(params['star_ratio']) data['star_ratio'] = star_ratio user_dungeon_obj.update_has_played_info(dungeon_type,floor_id,room_id,hard_ratio,star_ratio) has_played_floor_info = user_dungeon_obj.has_played_info[dungeon_type].get(floor_id) if has_played_floor_info: #格式化要返回的部分数据 tmpdata = {} tmpdata['floor_id'] = floor_id tmpdata['rooms_id'] = room_id tmpdata['floor_get_star'] = has_played_floor_info['cur_star'] tmpdata['hard'] = hard_ratio tmpdata['room_get_star'] = has_played_floor_info['rooms'][room_id][hard_ratio]['get_star'] tmpdata['room_perfect'] = has_played_floor_info['rooms'][room_id]['perfect'] data['floor_info'] = tmpdata else: pass # 战场次数处理 因为每日战场和普通战场的每日可打次数的计算是不同的 # 普通战场要精确到每一个 room 但是每日活动战场则是精确到 floor dungeon_repeat_info = user_dungeon_obj.dungeon_repeat_info dungeon_repeat_info.setdefault(dungeon_type, {}) if dungeon_type == 'normal': #进入普通战场就减少当天进入的次数 dungeon_repeat_info[dungeon_type].setdefault(floor_id, {}) dungeon_repeat_info[dungeon_type][floor_id].setdefault(room_id, 0) dungeon_repeat_info[dungeon_type][floor_id][room_id] +=1 elif dungeon_type == 'daily': #进入每日战场就减少当天进入的次数 dungeon_repeat_info[dungeon_type].setdefault(floor_id, 0) dungeon_repeat_info[dungeon_type][floor_id] +=1 # #统计当日可以打多少次 # if dungeon_type == 'normal': # #获取该战场的今日次数 # data['copy_times'] = user_dungeon_obj.get_today_copy_info(dungeon_type,floor_id,room_id) # data['copy_times']['floor_id'] = floor_id # data['copy_times']['room_id'] = room_id # elif dungeon_type == 'daily': # data['daily_info'] = user_dungeon_obj.get_daily_info() # #获取该战场的今日次数 # data['copy_times'] = user_dungeon_obj.get_today_copy_info(dungeon_type,floor_id,room_id) # data['copy_times']['floor_id'] = floor_id user_dungeon_obj.put() if lv_up: rk_user.user_character.check_open_talent() data_log_mod.set_log('DungeonRecord', rk_user, **log_data) return 0,data
def tranform_equip_soul_to_equip(rk_user, params): """将装备碎片 合成 装备 params: euqip_id 必须集齐这个装备所有的碎片类型才能合成 """ equip_id = params['equip_id'] user_souls_obj = UserSouls.get_instance(rk_user.uid) equip_type = int(game_config.equip_config.get(equip_id,{}).get('eqtype',7)) if 1<=equip_type<=4: #处理普通装备的合成 needed_souls = int(game_config.equip_config[equip_id]['need_souls']) if user_souls_obj.is_equip_soul_enough(equip_id,needed_souls): #添加装备 user_equip_obj = UserEquips.get(rk_user.uid) fg, all_equips_num, ueid, is_first = user_equip_obj.add_equip(equip_id, 'tranform_equip_soul_to_equip') data = {} if fg: tmp = { 'ueid':ueid, 'is_first':is_first, } tmp.update(user_equip_obj.get_equip_dict(ueid)) data['equips'] = tmp #删除碎片 user_souls_obj.minus_equip_soul(equip_id,needed_souls) #结果返回 return 0, data else: return 11, {'msg': utils.get_msg('pack','not_enough_material')} elif 5<=equip_type<=6: #处理宝物的合成 need_soul_types_num = game_config.equip_config[equip_id].get('need_soul_types_num', 0) all_equips = [equip_id+'_'+str(i) for i in xrange(1,need_soul_types_num + 1)] #获取需要多少份碎片 needed_souls = int(game_config.equip_config[equip_id].get('need_souls',1)) #判断碎片是否足够 for need_equip in all_equips: if not user_souls_obj.is_equip_soul_enough(need_equip,needed_souls): return 11, {'msg': utils.get_msg('pack','not_enough_material')} # 消耗 装备碎片 for need_equip in all_equips: user_souls_obj.minus_equip_soul(need_equip, 1, 'tranform_equip_soul_to_equip') # 加 装备 user_equip_obj = UserEquips.get(rk_user.uid) fg, all_equips_num, ueid, is_first = user_equip_obj.add_equip(equip_id, 'tranform_equip_soul_to_equip') data = {} if fg: tmp = { 'ueid':ueid, 'is_first':is_first, } tmp.update(user_equip_obj.get_equip_dict(ueid)) data['equips'] = tmp #判断新手引导 newbie_step = int(params.get('newbie_step',0)) if newbie_step: rk_user.user_property.set_newbie_steps(newbie_step, "tranform_equip_soul_to_equip") return 0, data else: return 11, {'msg': utils.get_msg('pack','not_enough_material')}
def end(rk_user, params): """ 离开战场请求 """ data = {} user_dungeon_obj = UserDungeon.get(rk_user.uid) #记录中如果没有未完成的战场,则返回 if not user_dungeon_obj.dungeon_info['last'].get('floor_id'): return 11, {'msg': utils.get_msg('dungeon', 'already_end')} #给用户奖励 last_info = user_dungeon_obj.dungeon_info['last'] floor_id = last_info['floor_id'] room_id = last_info['room_id'] dungeon_type = last_info['dungeon_type'] #检查场和局 para_floor_id = params['floor_id'] para_room_id = params['room_id'] para_dungeon_type = params['dungeon_type'] where = 'dungeon_%s_%s_%s' % (para_dungeon_type, para_floor_id, para_room_id) if floor_id != para_floor_id or room_id != para_room_id or dungeon_type != para_dungeon_type: return 11, {'msg': utils.get_msg('dungeon', 'unsame_dungeon')} #检查战场唯一标识 para_dungeon_uid = params.get('dungeon_uid', '') if para_dungeon_uid and para_dungeon_uid != last_info['dungeon_uid']: return 11, {'msg': utils.get_msg('dungeon', 'unsame_dungeon')} #判断战场是否是完成的 if params.get('result', '1') == '0': data = { 'dungeon_fail': True } #__resolve_fail(rk_user,user_dungeon_obj,ver=float(params['version'])) return 0, data #获取获得的金币 user_gold = int(params['user_gold']) #胜利扣除复活的元宝 if 'revive_coin' in last_info: if not rk_user.user_property.minus_coin( last_info['revive_coin'], 'revive_%s_%s_%s' % (last_info.get("floor_id"), last_info.get("room_id"), last_info.get("dungeon_type"))): return 11, {'msg': utils.get_msg('dungeon', 'revive_err')} #金币 打怪掉的 get_gold = min(user_gold, last_info['total_gold']) #获取打怪掉的和通关奖励的金币之和 get_gold = int((get_gold + last_info['dungeon_gold'])) if get_gold: rk_user.user_property.add_gold(get_gold, where) data['get_gold'] = get_gold ####异常记录#### if user_gold > last_info['total_gold']: dungeon_except = ExceptUsers.get_instance('normal_dungeon') dungeon_except.set_users('%s_%s' % (floor_id, room_id), rk_user.uid) # all_drop_info mat item props 添加背包里面的掉落信息 all_drop_info = last_info['all_drop_info'] user_pack_obj = UserPack.get(rk_user.uid) data['get_material'] = {} # data['get_item'] = {} data['get_props'] = {} pack_list = ['mat', 'item', 'props'] for drop_type in pack_list: drop_info = all_drop_info.get(drop_type, {}) for drop_id in drop_info: num = int(drop_info[drop_id]) if drop_type == 'mat': #添加素材 user_pack_obj.add_material(drop_id, num, where=where) data['get_material'][drop_id] = num elif drop_type == 'props': #添加道具 user_pack_obj.add_props(drop_id, num, where=where) data['get_props'][drop_id] = num else: pass # 成功打完战场才扣体力 need_stamina = last_info['dungeon_stamina'] #新手用户可以几天不用体力 # if datetime.datetime.now() < \ # utils.timestamp_toDatetime(rk_user.add_time) + datetime.timedelta(days=game_config.system_config.get('newbie_days',0)): # last_info['need_stamina'] = need_stamina # elif rk_user.user_property.charged_user and user_dungeon_obj.can_free_stamina(): # #付费用户每天可以有多少次可以不扣体力 # last_info['need_stamina'] = need_stamina # user_dungeon_obj.add_free_stamina_cnt() # else: # 需要扣除体力 进战场时已经扣一点 这里只扣剩下的 rk_user.user_property.minus_stamina(max(need_stamina - 1, 0)) #加碎片 data['get_souls'] = {} if last_info['all_drop_info'].get('soul'): user_souls_obj = UserSouls.get_instance(rk_user.uid) soul = last_info['all_drop_info']['soul'] for soul_type in soul: data['get_souls'][soul_type] = {} if soul_type == 'equip': #如果碎片是普通装备的话的处理逻辑 drop_soul_info = soul[soul_type] for drop_id in drop_soul_info: num = int(drop_soul_info[drop_id]) #装备的添加 user_souls_obj.add_equip_soul(drop_id, num, where=where) data['get_souls'][soul_type][drop_id] = num elif soul_type == 'card': #如果碎片类型是武将的话 drop_card_soul_info = soul[soul_type] for drop_id in drop_card_soul_info: num = int(drop_card_soul_info[drop_id]) user_souls_obj.add_normal_soul(drop_id, num, where=where) data['get_souls'][soul_type][drop_id] = num else: pass #处理装备掉落返回值 user_equip_obj = UserEquips.get(rk_user.uid) get_equips = [] for eid in last_info['all_drop_info'].get('equip', {}): num = int(last_info['all_drop_info']['equip'][eid]) for i in xrange(num): fg, all_equips_num, ueid, is_first = user_equip_obj.add_equip( eid, where=where) temp = { 'ueid': ueid, } temp.update(user_equip_obj.equips[ueid]) get_equips.append(temp) data['get_equip'] = get_equips user_card_obj = UserCards.get(rk_user.uid) #图鉴更新列表 get_cards = [] for cid in last_info['all_drop_info'].get('card', {}): num = int(last_info['all_drop_info']['card'][cid]) for i in xrange(num): card_lv = 1 success_fg, all_cards_num, ucid, is_first = user_card_obj.add_card( cid, card_lv, where=where) temp = { 'ucid': ucid, } temp.update(user_card_obj.cards[ucid]) get_cards.append(temp) #加经验 lv_up, get_upg_data = rk_user.user_property.add_exp( last_info['exp'], where) data['get_exp'] = last_info['exp'] get_cards.extend(get_upg_data.get('get_card', [])) #添加经验点 get_exp_point = last_info['exp_point'] if get_exp_point: rk_user.user_property.add_card_exp_point(get_exp_point, where) data['get_exp_point'] = get_exp_point data['get_card'] = get_cards #用户升级的用于引导奖励 if 'get_material' in get_upg_data: for mat_id in get_upg_data['get_material']: if mat_id in data['get_material']: data['get_material'][mat_id] += get_upg_data['get_material'][ mat_id] else: data['get_material'][mat_id] = get_upg_data['get_material'][ mat_id] #判断新手引导 newbie_step = int(params.get('newbie_step', 0)) if newbie_step: rk_user.user_property.set_newbie_steps(newbie_step, where) #更新用户的迷宫状态 data['dungeon_info'] = user_dungeon_obj.update_dungeon_info( dungeon_type, floor_id, room_id, once_daily=last_info.get('once_daily', False)) if 'clear_floor_coin' in data['dungeon_info']: data['clear_floor_coin'] = data['dungeon_info'].pop('clear_floor_coin') log_data = { 'statament': 'end', 'dungeon_id': '%s_%s' % (para_floor_id, para_room_id), 'dungeon_type': para_dungeon_type, 'card_deck': user_card_obj.deck, 'exp_point': get_exp_point, 'lv': rk_user.user_property.lv, } #记录该次战场的星级 if dungeon_type in ['normal', 'daily']: #获取难度系数 hard_ratio = params.get('hard_ratio', 'normal') # 中等难度 #获取星级系数 star_ratio = int(params['star_ratio']) data['star_ratio'] = star_ratio user_dungeon_obj.update_has_played_info(dungeon_type, floor_id, room_id, hard_ratio, star_ratio) has_played_floor_info = user_dungeon_obj.has_played_info[ dungeon_type].get(floor_id) if has_played_floor_info: #格式化要返回的部分数据 tmpdata = {} tmpdata['floor_id'] = floor_id tmpdata['rooms_id'] = room_id tmpdata['floor_get_star'] = has_played_floor_info['cur_star'] tmpdata['hard'] = hard_ratio tmpdata['room_get_star'] = has_played_floor_info['rooms'][room_id][ hard_ratio]['get_star'] tmpdata['room_perfect'] = has_played_floor_info['rooms'][room_id][ 'perfect'] data['floor_info'] = tmpdata else: pass # 战场次数处理 因为每日战场和普通战场的每日可打次数的计算是不同的 # 普通战场要精确到每一个 room 但是每日活动战场则是精确到 floor dungeon_repeat_info = user_dungeon_obj.dungeon_repeat_info dungeon_repeat_info.setdefault(dungeon_type, {}) if dungeon_type == 'normal': #进入普通战场就减少当天进入的次数 dungeon_repeat_info[dungeon_type].setdefault(floor_id, {}) dungeon_repeat_info[dungeon_type][floor_id].setdefault(room_id, 0) dungeon_repeat_info[dungeon_type][floor_id][room_id] += 1 elif dungeon_type == 'daily': #进入每日战场就减少当天进入的次数 dungeon_repeat_info[dungeon_type].setdefault(floor_id, 0) dungeon_repeat_info[dungeon_type][floor_id] += 1 # #统计当日可以打多少次 # if dungeon_type == 'normal': # #获取该战场的今日次数 # data['copy_times'] = user_dungeon_obj.get_today_copy_info(dungeon_type,floor_id,room_id) # data['copy_times']['floor_id'] = floor_id # data['copy_times']['room_id'] = room_id # elif dungeon_type == 'daily': # data['daily_info'] = user_dungeon_obj.get_daily_info() # #获取该战场的今日次数 # data['copy_times'] = user_dungeon_obj.get_today_copy_info(dungeon_type,floor_id,room_id) # data['copy_times']['floor_id'] = floor_id user_dungeon_obj.put() if lv_up: rk_user.user_character.check_open_talent() data_log_mod.set_log('DungeonRecord', rk_user, **log_data) return 0, data