Beispiel #1
0
def add_equip():
    ue = UserEquips.get_instance(uid)
    ue.add_equip('12001_equip')  # 4个装备都是火云套
    ue.add_equip('22001_equip')
    ue.add_equip('32001_equip')
    ue.add_equip('42001_equip')
    ue.add_equip('53003_equip')   # 诗经
    ue.add_equip('63003_equip')   # 沙里飞
    ue.do_put()
Beispiel #2
0
 def is_equip_used(self,ucids):
     if not ucids:
         return False
     from apps.models.user_equips import UserEquips
     equips = UserEquips.get(self.uid).equips
     used_by_ucids = [equips[ueid]['used_by'] for ueid in equips if equips[ueid].get('used_by')]
     if set(used_by_ucids)&set(ucids):
         return True
     else:
         return False
Beispiel #3
0
 def is_equip_used(self, ucids):
     if not ucids:
         return False
     from apps.models.user_equips import UserEquips
     equips = UserEquips.get(self.uid).equips
     used_by_ucids = [
         equips[ueid]['used_by'] for ueid in equips
         if equips[ueid].get('used_by')
     ]
     if set(used_by_ucids) & set(ucids):
         return True
     else:
         return False
Beispiel #4
0
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()
Beispiel #5
0
def equip_stove(rk_user, params):
    """
    炼化
    """
    sell_ueids = params.get('sell_ueids')
    #卖出的装备为空的时候的处理
    if not sell_ueids:
        return 11, {'msg': utils.get_msg('equip', 'no_equip')}
    #获取装备的列表
    sell_ueids = sell_ueids.split(',')
    #装备列表去空
    sell_ueids = utils.remove_null(sell_ueids)
    #这里执行两次的原因是防止前台传递过来的是 ,,
    if not sell_ueids:
        return 11, {'msg': utils.get_msg('equip', 'no_equip')}
    #获取用户装备对象
    user_equip_obj = UserEquips.get_instance(rk_user.uid)
    user_equips = user_equip_obj.equips
    #循环要卖出的装备 判断是否可以卖出
    for sell_ueid in sell_ueids:
        #检查装备是否存在
        if sell_ueid not in user_equips:
            return 11, {'msg': utils.get_msg('equip', 'no_equip')}
        #检查装备是否装备武将
        try:
            sell_ueid_bind = user_equips[sell_ueid]['used_by']
        except:
            sell_ueid_bind = ''
        #判断装备是否已经装备在武将身上
        if sell_ueid_bind:
            return 11, {'msg': utils.get_msg('equip', 'is_used')}
    #计算卖出获得的铜钱数量
    #get_gold = 0
    #获取用户的装备的eid和等级
    sell_eids_info = [
        user_equip_obj.get_equip_dict(ueid) for ueid in sell_ueids
    ]
    #treasure_sell_gold = game_config.equip_exp_config['treasure_sell_gold']
    #common_base_gold = game_config.equip_exp_config['common_base_gold']
    return 0, {'equips_info': sell_eids_info, 'equips_ueids': sell_ueids}
Beispiel #6
0
def equip_stove():
    """
    炼化
    """
    sell_ueids ='201410201603035844619' 
    #卖出的装备为空的时候的处理
    if not sell_ueids:
        return 11,{'msg':utils.get_msg('equip','no_equip')}
    #获取装备的列表
    sell_ueids = sell_ueids.split(',')
    #装备列表去空
    sell_ueids = utils.remove_null(sell_ueids)
    #这里执行两次的原因是防止前台传递过来的是 ,,
    if not sell_ueids:
        return 11,{'msg':utils.get_msg('equip','no_equip')}
    #获取用户装备对象
    user_equip_obj = UserEquips.get_instance(uid)
    user_equips = user_equip_obj.equips
    #循环要卖出的装备 判断是否可以卖出
    for sell_ueid in sell_ueids:
        #检查装备是否存在
        if sell_ueid not in user_equips:
            return 11,{'msg':utils.get_msg('equip','no_equip')}
        #检查装备是否装备武将
        try:
            sell_ueid_bind = user_equips[sell_ueid]['used_by']
        except:
            sell_ueid_bind = ''
        #判断装备是否已经装备在武将身上
        if sell_ueid_bind:
            return 11,{'msg':utils.get_msg('equip','is_used')}
    #计算卖出获得的铜钱数量
    #get_gold = 0
    #获取用户的装备的eid和等级
    sell_eids_info = [user_equip_obj.get_equip_dict(ueid) for ueid in sell_ueids]
    #treasure_sell_gold = game_config.equip_exp_conf['treasure_sell_gold']
    #common_base_gold = game_config.equip_exp_conf['common_base_gold']
    return 0,{'equips_info':sell_eids_info,'equips_ueids':sell_ueids}
Beispiel #7
0
def view_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')

    ##### view raw db data
    check_raw_db_data = request.GET.get('check_raw_db_data', '').strip()
    db_data_name = request.GET.get('db_data_name', '').strip()

    #using exec/eval, need consider safety, or user could provide malicious
    #string, do bad behavior
    if db_data_name and db_data_name not in raw_db_data_list:
        return HttpResponse(
            'Wrong raw db data name, or not allowed to show yet')

    if check_raw_db_data in ('on', 'checked'):
        data = {'user': {}}
        data['user']['uid'] = uid
        data['user']['username'] = user.username
        module_name, data_class, db_data = db_data_name.split('.')

        #exec('from apps.models.' + module_name + ' import ' + data_class)
        exec 'from apps.models.' + module_name + ' import ' + data_class in globals(
        ), locals()

        if data_class == 'UserMail':
            raw_db_data = eval(data_class + '.hget("' + uid + '", "' + uid +
                               '").' + db_data)
        else:
            raw_db_data = eval(data_class + '.get(' + uid + ').' + db_data)

        data['db_data_name'] = db_data_name
        data['raw_db_data'] = pformat(raw_db_data)
        return render_to_response('user/view_raw.html', data,
                                  RequestContext(request))
    ###### end view raw db

    user_card_obj = UserCards.get(user.uid)
    user_equips_obj = UserEquips.get_instance(uid)
    user_property_obj = UserProperty.get(uid)
    user_pack_obj = UserPack.get_instance(uid)

    data = {
        'user_property_obj': user_property_obj,
        'user': user,
        'deck_cards': [],
        'other_cards': [],
        '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'],
    }
    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_Ex(user.uid)
    #pvp_obj = UserPvp.getEx(user.uid)
    #pvp 排名
    top_model = pvp_redis.get_pvp_redis('1')
    rank = top_model.rank(uid)
    #pvp_obj.rank = rank+1 if rank != None else 0
    #data['pvp'] = pvp_obj
    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:]

    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 = ''
            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:
            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 = ''
        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

    #装备
    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[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[str(i) + '_equip'])
                          for i in all_equips_tag]

    #mat
    data['user_materials'] = {
        mid: {
            'name': game_config.material_config[mid]['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[str(i) + '_mat'])
                             for i in all_materials_tag]
    #
    data['charge_sum_money'] = user.user_property.charge_sum_money
    data['last_charge_record'] = ChargeRecord.find(
        {'uid': uid})[-1] if ChargeRecord.find({'uid': uid}) else {}

    ######将魂系统##############

    data.update(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' 将魂'
    #data["index_list"] = request.index_list
    return render_to_response('user/view.html', data, RequestContext(request))
Beispiel #8
0
 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
Beispiel #9
0
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
Beispiel #10
0
    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
Beispiel #11
0
 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
Beispiel #12
0
    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
Beispiel #13
0
def view_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')




    ##### view raw db data
    check_raw_db_data = request.GET.get('check_raw_db_data','').strip()
    db_data_name = request.GET.get('db_data_name','').strip()

    #using exec/eval, need consider safety, or user could provide malicious
    #string, do bad behavior
    if db_data_name and db_data_name not in raw_db_data_list:
        return HttpResponse('Wrong raw db data name, or not allowed to show yet')

    if check_raw_db_data in ('on', 'checked'):
        data={ 'user': {} }
        data['user']['uid'] = uid
        data['user']['username'] = user.username
        module_name, data_class, db_data = db_data_name.split('.')

        #exec('from apps.models.' + module_name + ' import ' + data_class)
        exec 'from apps.models.' + module_name + ' import ' + data_class in globals(), locals() 

        if data_class == 'UserMail':
            raw_db_data = eval(data_class + '.hget("' + uid + '", "' + uid + '").' + db_data )
        else:
            raw_db_data = eval(data_class + '.get(' + uid + ').' + db_data )

        data['db_data_name'] = db_data_name
        data['raw_db_data'] = pformat(raw_db_data)
        return render_to_response('user/view_raw.html', data, 
                    RequestContext(request))
    ###### end view raw db


    user_card_obj = UserCards.get(user.uid)
    user_equips_obj = UserEquips.get_instance(uid)
    user_property_obj = UserProperty.get(uid)
    user_pack_obj = UserPack.get_instance(uid)

    data = {
        'user_property_obj':user_property_obj,
        'user':user,
        'deck_cards':[],
        'other_cards':[],
        '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'],
    }
    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_Ex(user.uid)
    #pvp_obj = UserPvp.getEx(user.uid)
    #pvp 排名
    top_model = pvp_redis.get_pvp_redis('1')
    rank = top_model.rank(uid)
    #pvp_obj.rank = rank+1 if rank != None else 0
    #data['pvp'] = pvp_obj
    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:]

    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 = ''
            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:
            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 = ''
        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

    #装备
    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[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[str(i)+'_equip']) for i in all_equips_tag]

    #mat
    data['user_materials'] = {mid :{'name':game_config.material_config[mid]['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[str(i)+'_mat']) for i in all_materials_tag]
    #
    data['charge_sum_money'] = user.user_property.charge_sum_money
    data['last_charge_record'] = ChargeRecord.find({'uid':uid})[-1] if ChargeRecord.find({'uid':uid}) else {}


######将魂系统##############

    data.update(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' 将魂'
    #data["index_list"] = request.index_list
    return render_to_response('user/view.html',data,RequestContext(request))
Beispiel #14
0
def stove(rk_user,params):
    """
    熔炼炉
    类似一个回收系统,消耗武将,装备等,来得到相应的资源,资源包括战魂,铜钱,素材,道具等。
    返还的范围包括物品的初始花费和后续花费,比如升级某样物品所花费的铜钱也返还
    """
    #练化类型
    category = params.get('category','')
    data = {}
    rc = 0
    user_property_obj = UserProperty.get_instance(rk_user.uid)
    user_card_obj = UserCards.get_instance(rk_user.uid)
    user_equip_obj = UserEquips.get_instance(rk_user.uid)
    user_pack_obj = UserPack.get_instance(rk_user.uid)
    user_property_obj = UserProperty.get_instance(rk_user.uid)
    #出售逻辑很炼丹炉一样,所以直接调用出售逻辑获得数据结构
    #武将
    if category == 'card':
        rc,msg = card.card_stove(rk_user,params)
        if rc:
            return rc,msg
        #获取武将计算系数                       card_update_config:武将强化
        card_stove_gold_coe = float(game_config.card_update_config['card_stove_gold_coe'])
        card_stove_props_coe = float(game_config.card_update_config['card_stove_props_coe'])
        #取得天赋进阶的配置信息                 talent_skill_config 武将天赋技能
        advanced_talent_config = game_config.talent_skill_config['advanced_talent_config']
        #总计获取的战魂
        fight_soul = 0
        #总计返回的进阶丹  
        return_props = 0
        #返回铜钱
        return_gold = 0
        for card_info in msg['cards_info']:
            cid = card_info['cid']
#           print '#### cid=', cid

            #获取武将的当前天赋等级
            cur_talent_lv = card_info['talent_lv']
#           print '#### cur_talent_lv=', cur_talent_lv

            #获取武将星级            card_config 武将设置
            star = str(game_config.card_config[cid].get('star',4))
#           print '#### card star=', star

            #读取计算战魂系统    card_update_config:武将强化
            stove_card_fight_soul = int(game_config.card_update_config['card_stove_fight_soul'].get(star,1))
            #获取当前经验
            cost_update_gold = card_info['exp']
            #武将炼化基础值
            base_gold = int(game_config.card_update_config['sell_base_gold'].get(star,3000))
            #获取当前进阶所需的配置(武将,铜钱,进阶丹)

            #铜钱计算公式 = 基础数值 + int(当前状态总共消耗铜钱 * 0.8)
            return_gold  += base_gold + int(cost_update_gold * card_stove_gold_coe)
            #战魂计算公式 =(1 + 进阶到当前状态总消耗武将个数)* 系数
            fight_soul  += stove_card_fight_soul

            for talent_lv in range(1, int(cur_talent_lv)+1):
                cur_talent = advanced_talent_config[star].get(str(talent_lv),{})
                cost_talent_gold  = int(cur_talent.get('cost_gold',0))
                cost_talent_card  = int(cur_talent.get('card',0))   #武将
                cost_talent_props = cur_talent.get('props',[]) #进阶丹

                #铜钱计算公式 = 基础数值 + int(当前状态总共消耗铜钱 * 0.8)
                return_gold  += int( cost_talent_gold * card_stove_gold_coe )
                #进阶丹 = int(当前状态总消耗 * 0.8)
                if cost_talent_props:
                    return_props += int(cost_talent_props[1] * card_stove_props_coe)
                #战魂计算公式 =(1 + 进阶到当前状态总消耗武将个数)* 系数
                fight_soul  += int(cost_talent_card * stove_card_fight_soul)

#               print '#### return_gold, return_props, fight_soul=', \
#                       return_gold, return_props, fight_soul

        #添加战魂
        user_property_obj.add_fight_soul(fight_soul, 'stove')
        #返还进阶丹
        user_pack_obj.add_props('8_props',return_props, 'stove')
        #用户删卡
        user_card_obj.del_card_info(msg['cards_ucids'], where='stove')
        #返还铜钱
        user_property_obj.add_gold(return_gold, 'stove')
        data = {'gold':return_gold,'fight_soul':fight_soul,'props':{'8_props':return_props}}

    #普通装备(1:武器(攻击),2:护甲(防御),3:头盔(血量),4:饰品(回复)
    elif category == 'common_equip':
        rc,msg = equip.equip_stove(rk_user,params)
        if rc:
            return rc,msg
        # category check,防止category和装备eid不匹配
        for equip_info in msg['equips_info']:
            eid = equip_info['eid']
            eqtype = game_config.equip_config[eid]['eqtype']
            if eqtype not in [1, 2, 3, 4]:
                return 11,{'msg':utils.get_msg('mystery_store','category_not_match')}
        #获取普通装备计算系数                      equip_exp_conf:装备等级配置
        common_stove_gold_coe = float(game_config.equip_exp_config['common_stove_gold_coe'])
        #返回铜钱
        return_gold = 0
        for equip_info in msg['equips_info']:
            # equip_info 是 UserEquips实例的equips[ueid]字段
            eid = equip_info['eid'] 
            uetype = int(game_config.equip_config[eid]['eqtype'])
            #获取当前等级
            cur_equip_lv = equip_info['cur_lv']
            #获取当前经验(升级到该经验所需铜钱)
            cost_update_gold = equip_info['cur_experience']

            #获取装备的星级
            star = str(game_config.equip_config[eid].get('star',1))
            #普通装备炼化基础值            equip_exp_config:装备等级配置

            base_gold = int(game_config.equip_exp_config['common_base_gold'].get(star,500))
            return_gold += int((base_gold + cost_update_gold) * common_stove_gold_coe)


        #用户删除装备
        user_equip_obj.delete_equip(msg['equips_ueids'], where='stove')
        #返还铜钱
        user_property_obj.add_gold(return_gold, 'stove')

        data = {'gold':return_gold}

    #宝物(5:兵法,6:坐骑)
    elif category == 'treasure_equip':
        rc,msg = equip.equip_stove(rk_user,params)
        if rc:
            return rc,msg
        # category check,防止category和装备eid不匹配
        for equip_info in msg['equips_info']:
            eid = equip_info['eid']
            eqtype = game_config.equip_config[eid]['eqtype']
            if eqtype not in [5, 6]:
                return 11,{'msg':utils.get_msg('mystery_store','category_not_match')}

        #获取宝物计算系数                             装备等级配置
        treasure_stove_gold_coe = float(game_config.equip_exp_config['treasure_stove_gold_coe'])
        #返回铜钱
        return_gold = 0
        #返回道具
        return_props = {}
        #返还的 不同等级的经验马/经验书数量
        num_book4=num_book3=num_book2=num_book1=num_horse4=num_horse3=num_horse2=num_horse1 = 0
        # 不同等级的经验马/经验书提供的经验
        props_conf = game_config.props_config
        equip5_prop_list = []
        equip6_prop_list = []
        for prop_id in props_conf:
            if props_conf[prop_id].get('used_by') == 'equip5':
                equip5_prop_list.append((prop_id, props_conf[prop_id]['exp']))
            elif props_conf[prop_id].get('used_by') == 'equip6':
                equip6_prop_list.append((prop_id, props_conf[prop_id]['exp']))
        equip5_prop_list.sort(reverse=True)
        equip6_prop_list.sort(reverse=True)

        def calculate_rebate(prop_exp_list, all_exp):
            rebate_props = {}
            left_exp = all_exp
            for prop, exp in prop_exp_list:
                rebate_props[prop] = left_exp // exp
                left_exp = left_exp % exp
                if not left_exp:
                    break
            return rebate_props

        for equip_info in msg['equips_info']:
            eid = equip_info['eid']
            #宝物装备升级所消耗铜钱
            cost_update_gold = equip_info['cur_experience'] * treasure_stove_gold_coe
            #获取装备的星级
            star = str(game_config.equip_config[eid].get('star',1))
            #宝物装备炼化基础值
            base_gold = game_config.equip_exp_config['treasure_sell_gold'].get(star,500)
            eqtype = game_config.equip_config[eid]['eqtype']
            #计算返还经验书的数量。经验书有不同等级,分别计算个数。5000 3000 1000 500为相应等级的经验书所提供的经验
            if eqtype == 5:
                return_props.update(calculate_rebate(equip5_prop_list, cost_update_gold))
            #计算返还经验马  逻辑同经验书
            elif eqtype == 6:
                return_props.update(calculate_rebate(equip6_prop_list, cost_update_gold))
            return_gold += int(base_gold + (cost_update_gold * treasure_stove_gold_coe))
        #返还道具
        for props_id in return_props:
            user_pack_obj.add_props(props_id,return_props[props_id], 'stove')
        #用户删除装备
        user_equip_obj.delete_equip(msg['equips_ueids'], where='stove')
        #返还铜钱
        user_property_obj.add_gold(return_gold, where='stove')
        data = {'gold':return_gold,'props':return_props}
    else:
        return 11,{'msg':utils.get_msg('mystery_store','no_stove_category')}

#   print '#### stove_info:', data

    return rc,{'stove_info':data}
Beispiel #15
0
def update(rk_user, params):
    """
    * 装备的升级
    * miaoyichao
    """
    #获取要升级的装备和升级所需要的参数  要升多少级 或者是升级的经验
    base_ueid = params['base_ueid']
    #获取前台传递过来的装备类型

    base_type = int(params['base_type'])

    #获取装备配置信息
    user_equips_obj = UserEquips.get_instance(rk_user.uid)
    #获取该用户的装备信息
    user_equips_lists = user_equips_obj.equips
    #武器、护甲、头盔、饰品4类通过游戏中的铜钱来升级强化  兵法及坐骑,升级方式通过消耗特定素材进行强化
    #获取装备的类型 1:武器(攻击),2:护甲(防御),3:头盔(血量),4:饰品(回复),5:兵法,6:坐骑
    base_eid = user_equips_lists[base_ueid]['eid']
    uetype = int(game_config.equip_config[base_eid]['eqtype'])
    #传递过来的参数类型和从配置数据库得到的不一致
    if not base_type == uetype:
        return 11, {'msg': utils.get_msg('equip', 'params_wrong')}
    #检查要强化的武器是不是在用户装备中
    if base_ueid not in user_equips_lists:
        return 11, {'msg': utils.get_msg('equip', 'no_equip')}
    #获取用户的该装备信息
    base_ueid_info = user_equips_obj.get_equip_dict(base_ueid)
    #获取用户的等级
    user_lv = get_user_lv(rk_user.uid)
    #检查base卡是是否满级
    if not __check_can_update(base_ueid_info, user_lv):
        return 11, {'msg': utils.get_msg('equip', 'cannot_update')}

    # 暴击次数
    crit_time = 0
    #只需要金钱就可以强化的
    if uetype <= 4:
        #获取vip等级
        vip_lv = rk_user.user_property.vip_cur_level
        #获取装备的当前等级
        cur_equip_lv = base_ueid_info['cur_lv']
        cur_cost_gold = game_config.equip_exp_config['common_gold'].get(
            str(cur_equip_lv), 0)
        next_cost_gold = game_config.equip_exp_config['common_gold'].get(
            str(cur_equip_lv + 1), 100)
        #获取装备的星级
        star = game_config.equip_config[base_ueid_info['eid']].get('star', 2)
        #获取系数
        coefficient = game_config.equip_exp_config['common_gold_coe'][str(
            star)]
        update_gold = int((next_cost_gold - cur_cost_gold) * coefficient)
        # #判断用户金币是否足够
        if not rk_user.user_property.is_gold_enough(update_gold):
            return 11, {'msg': utils.get_msg('user', 'not_enough_gold')}
        try:
            auto_flag = params['auto_flag']
        except:
            auto_flag = ''
        if not auto_flag:
            #给装备增加经验和等级
            crit_time, new_equip_info = user_equips_obj.add_com_equip_exp(
                base_ueid, vip_lv, user_lv, where='equip_update')
            #扣除消费的金币
            rk_user.user_property.minus_gold(update_gold,
                                             'common_equip_update')
            #格式化返回的数据的内容
            data = {}
            # tmp = {}
            # tmp['ueid'] = base_ueid
            # user_equips_obj = UserEquips.get_instance(rk_user.uid)
            # user_equips_lists = user_equips_obj.equips
            # tmp.update(user_equips_lists[base_ueid])
            data['up_lv'] = [new_equip_info['cur_lv']]
            data['new_equip_info'] = new_equip_info
        else:
            #自动强化装备
            crit_time, data = user_equips_obj.auto_update_equip(
                rk_user,
                base_ueid,
                vip_lv,
                user_lv,
                where='common_equip_auto_update')
        data['crit_time'] = crit_time

        return 0, data
    elif 5 <= uetype <= 6:
        #该部分需要特定的道具进行升级
        #检查参数是否合法
        try:
            cost_props = params['cost_props']
        except:
            return 11, {'msg': utils.get_msg('equip', 'params_wrong')}
        cost_props_list = cost_props.split(',')
        cost_props_list = utils.remove_null(cost_props_list)
        #格式化消耗的道具
        all_cost_props = {}
        for cost_props_id in cost_props_list:
            if cost_props_id not in all_cost_props:
                all_cost_props[cost_props_id] = 0
            all_cost_props[cost_props_id] += 1
        #获取用户背包信息
        user_pack_obj = UserPack.get_instance(rk_user.uid)
        check_use_type = 'equip%s' % uetype
        all_exp = 0
        #检查用户背包是否有这么多的道具和道具的使用类型
        for props_id in all_cost_props:
            num = int(all_cost_props[props_id])
            #检查数量是否足够
            if not user_pack_obj.is_props_enough(props_id, num):
                return 11, {'msg': utils.get_msg('pack', 'not_enough_props')}
            if not check_use_type == game_config.props_config[props_id][
                    'used_by']:
                return 11, {'msg': utils.get_msg('pack', 'wrong_used')}
            all_exp += int(game_config.props_config[props_id]['exp']) * num
        #计算升级所消耗的金钱 强制转化为int类型的
        update_gold = int(
            all_exp *
            game_config.equip_exp_config['gold_exp_transform_coe'].get(
                'treasure_update_coe', 1))
        #判断用户金币是否足够
        if not rk_user.user_property.is_gold_enough(update_gold):
            return 11, {'msg': utils.get_msg('user', 'not_enough_gold')}
        #所有条件都满足的情况下 开始扣除金币和道具 然后开始添加经验
        #扣除消费的金币
        rk_user.user_property.minus_gold(update_gold, 'treasure_equip_update')
        #扣除道具
        user_pack_obj.minus_multi_props(all_cost_props,
                                        where='treasure_equip_update')
        #添加经验
        new_equip_info = user_equips_obj.add_treasure_equip_exp(
            base_ueid, all_exp, user_lv, where='treasure_equip_update')
        #格式化返回的数据的内容
        data = {}
        data['up_lv'] = [new_equip_info['cur_lv']]
        data['new_equip_info'] = new_equip_info

        return 0, data
    else:
        return 11, {'msg': utils.get_msg('equip', 'params_wrong')}
Beispiel #16
0
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
Beispiel #17
0
def update(rk_user,params):
    """
    * 装备的升级
    * miaoyichao
    """
    #获取要升级的装备和升级所需要的参数  要升多少级 或者是升级的经验
    base_ueid = params['base_ueid']
    #获取前台传递过来的装备类型

    base_type = int(params['base_type'])

    #获取装备配置信息
    user_equips_obj = UserEquips.get_instance(rk_user.uid)
    #获取该用户的装备信息
    user_equips_lists = user_equips_obj.equips
    #武器、护甲、头盔、饰品4类通过游戏中的铜钱来升级强化  兵法及坐骑,升级方式通过消耗特定素材进行强化
    #获取装备的类型 1:武器(攻击),2:护甲(防御),3:头盔(血量),4:饰品(回复),5:兵法,6:坐骑
    base_eid = user_equips_lists[base_ueid]['eid']
    uetype = int(game_config.equip_config[base_eid]['eqtype'])
    #传递过来的参数类型和从配置数据库得到的不一致
    if not base_type == uetype:
        return 11,{'msg':utils.get_msg('equip','params_wrong')}
    #检查要强化的武器是不是在用户装备中
    if base_ueid not in user_equips_lists:
        return 11,{'msg':utils.get_msg('equip','no_equip')}
    #获取用户的该装备信息
    base_ueid_info = user_equips_obj.get_equip_dict(base_ueid)    
    #获取用户的等级
    user_lv = get_user_lv(rk_user.uid)
    #检查base卡是是否满级
    if not __check_can_update(base_ueid_info,user_lv):
        return 11,{'msg':utils.get_msg('equip','cannot_update')}

    # 暴击次数
    crit_time = 0
    #只需要金钱就可以强化的
    if uetype<=4:
        #获取vip等级
        vip_lv = rk_user.user_property.vip_cur_level
        #获取装备的当前等级
        cur_equip_lv = base_ueid_info['cur_lv']
        cur_cost_gold = game_config.equip_exp_config['common_gold'].get(str(cur_equip_lv),0)
        next_cost_gold = game_config.equip_exp_config['common_gold'].get(str(cur_equip_lv+1),100)
        #获取装备的星级
        star = game_config.equip_config[base_ueid_info['eid']].get('star',2)
        #获取系数
        coefficient =  game_config.equip_exp_config['common_gold_coe'][str(star)]
        update_gold = int((next_cost_gold - cur_cost_gold)*coefficient)
        # #判断用户金币是否足够
        if not rk_user.user_property.is_gold_enough(update_gold):
            return 11,{'msg':utils.get_msg('user','not_enough_gold')}
        try:
            auto_flag = params['auto_flag']
        except:
            auto_flag = ''
        if not auto_flag:
            #给装备增加经验和等级
            crit_time, new_equip_info = user_equips_obj.add_com_equip_exp(base_ueid,vip_lv,user_lv,where='equip_update')
            #扣除消费的金币
            rk_user.user_property.minus_gold(update_gold,'common_equip_update')
            #格式化返回的数据的内容
            data = {}
            # tmp = {}
            # tmp['ueid'] = base_ueid
            # user_equips_obj = UserEquips.get_instance(rk_user.uid)
            # user_equips_lists = user_equips_obj.equips
            # tmp.update(user_equips_lists[base_ueid])
            data['up_lv'] = [new_equip_info['cur_lv']]
            data['new_equip_info'] = new_equip_info
        else:
            #自动强化装备
            crit_time, data = user_equips_obj.auto_update_equip(rk_user,base_ueid,vip_lv,user_lv,where='common_equip_auto_update')
        data['crit_time'] = crit_time

        return 0, data
    elif 5<=uetype<=6:
        #该部分需要特定的道具进行升级
        #检查参数是否合法
        try:
            cost_props = params['cost_props']
        except:
            return 11,{'msg':utils.get_msg('equip','params_wrong')}
        cost_props_list = cost_props.split(',')
        cost_props_list = utils.remove_null(cost_props_list)
        #格式化消耗的道具
        all_cost_props = {}
        for cost_props_id in cost_props_list:
            if cost_props_id not in all_cost_props:
                all_cost_props[cost_props_id] = 0
            all_cost_props[cost_props_id] += 1
        #获取用户背包信息
        user_pack_obj = UserPack.get_instance(rk_user.uid)
        check_use_type = 'equip%s' %uetype
        all_exp = 0
        #检查用户背包是否有这么多的道具和道具的使用类型
        for props_id in all_cost_props:
            num = int(all_cost_props[props_id])
            #检查数量是否足够
            if not user_pack_obj.is_props_enough(props_id,num):
                return 11,{'msg':utils.get_msg('pack', 'not_enough_props')}
            if not check_use_type == game_config.props_config[props_id]['used_by']:
                return 11,{'msg':utils.get_msg('pack', 'wrong_used')}
            all_exp += int(game_config.props_config[props_id]['exp']) * num
        #计算升级所消耗的金钱 强制转化为int类型的
        update_gold = int(all_exp * game_config.equip_exp_config['gold_exp_transform_coe'].get('treasure_update_coe',1))
        #判断用户金币是否足够
        if not rk_user.user_property.is_gold_enough(update_gold):
            return 11,{'msg':utils.get_msg('user','not_enough_gold')}
        #所有条件都满足的情况下 开始扣除金币和道具 然后开始添加经验
        #扣除消费的金币
        rk_user.user_property.minus_gold(update_gold,'treasure_equip_update')
        #扣除道具
        user_pack_obj.minus_multi_props(all_cost_props,where='treasure_equip_update')
        #添加经验
        new_equip_info = user_equips_obj.add_treasure_equip_exp(base_ueid,all_exp,user_lv,where='treasure_equip_update')
        #格式化返回的数据的内容
        data = {}
        data['up_lv'] = [new_equip_info['cur_lv']]
        data['new_equip_info'] = new_equip_info

        return 0,data
    else:
        return 11,{'msg':utils.get_msg('equip','params_wrong')}
Beispiel #18
0
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')}
Beispiel #19
0
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')}
Beispiel #20
0
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
Beispiel #21
0
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
Beispiel #22
0
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