def query_pay_detail(self, gid, mi, request): conf = Context.Configure.get_game_item_json(gid, 'product.config') pids = [] for pid in conf.iterkeys(): pids.append('product_' + pid) start = mi.get_param('start') end = mi.get_param('end') start_day = Time.str_to_datetime(start, '%Y-%m-%d') end_day = Time.str_to_datetime(end, '%Y-%m-%d') mo = MsgPack(0) while start_day <= end_day: fmt = Time.datetime_to_str(start_day, '%Y-%m-%d') timess = Context.Stat.get_day_data(gid, fmt, *pids) kvs = {'product_100646': 0, 'product_100710': 0} for k, v in zip(pids, timess): pid = k.replace('product_', '') if pid in ('100646', '100647', '100648', '100649', '100650', '100651', '100652', '100653', '100654', '100655'): kvs['product_100646'] += Tool.to_int(v, 0) elif pid in ('100710', '100711', '100712', '100713', '100714', '100715', '100716'): kvs['product_100710'] += Tool.to_int(v, 0) else: kvs[k] = Tool.to_int(v, 0) mo.set_param(fmt, kvs) start_day = Time.next_days(start_day) return mo
def get_login_info(cls, uid, gid): now_day = Time.up_days() last_login, ns_login = Context.Data.get_game_attrs( uid, gid, ['lastlogin', 'nslogin']) last_login = Tool.to_int(last_login, 0) ns_login = Tool.to_int(ns_login, 0) return now_day, last_login, ns_login
def get_total_degree(self, uid, gid): task_list = Context.Daily.get_daily_data(uid, gid, 'task.list') if not task_list: return 0 task_list = Context.json_loads(task_list) degree = 0 for task in task_list: if task['type'] == 1: count = Context.Daily.get_daily_data(uid, gid, 'fish.' + str(task['fish_type'])) task['count'] = Tool.to_int(count, 0) elif task['type'] == 2: count = Context.Daily.get_daily_data(uid, gid, 'class.boss') task['count'] = Tool.to_int(count, 0) elif task['type'] == 3: count = Context.Daily.get_daily_data(uid, gid, 'class.bonus') task['count'] = Tool.to_int(count, 0) elif task['type'] == 11: count = Context.Daily.get_daily_data(uid, gid, 'win.chip') task['count'] = Tool.to_int(count, 0) elif task['type'] == 21: degree += task['degree'] if 'count' in task and task['count'] >= task['total']: task['done'] = 1 degree += task['degree'] return degree
def query_carrying(self, gid, mi, request): start = mi.get_param('start') end = mi.get_param('end') start_day = Time.str_to_datetime(start, '%Y-%m-%d') end_day = Time.str_to_datetime(end, '%Y-%m-%d') mo = MsgPack(0) while start_day <= end_day: fmt = Time.datetime_to_str(start_day, '%Y-%m-%d') _login, _total = Context.Stat.get_day_data(gid, fmt, 'login.carrying.volume.chip', 'carrying.volume.chip') _login = Tool.to_int(_login, 0) _total = Tool.to_int(_total, 0) mo.set_param(fmt, {'carrying': _login, 'total': _total}) start_day = Time.next_days(start_day) return mo
def gm_pool_pump(self, gid, mi, request): delta = mi.get_param('delta') assert isinstance(delta, int) room_type = mi.get_param('room_type') assert room_type in (201, 202, 203) final = Context.RedisMix.hash_incrby('game.%d.info.hash' % gid, 'official.macro.control.%d' % room_type, delta) fields = ['pool.shot.%d' % room_type, 'pool.reward.%d' % room_type, 'out.chip.pump.%d' % room_type] shot, reward, pump = Context.RedisMix.hash_mget('game.%d.info.hash' % gid, *fields) shot = Tool.to_int(shot, 0) reward = Tool.to_int(reward, 0) pump = Tool.to_int(pump, 0) mo = MsgPack(0) mo.set_param('delta', delta) mo.set_param('room_type', room_type) mo.set_param('pool', shot - pump - reward + final) return mo
def check_bankrupt(cls, uid, gid): benefit_times, bankrupt_ts = Context.Daily.get_daily_data( uid, gid, 'benefit_times', 'bankrupt_ts') benefit_times = Tool.to_int(benefit_times, 0) wait, which = None, None if bankrupt_ts: # 已经在破产状态, 未领取 which = benefit_times + 1 wait = int(bankrupt_ts) - Time.current_ts() if wait < 0: wait = 0 else: conf = Context.Configure.get_game_item_json(gid, 'benefit.config') if benefit_times < len(conf['reward']): reward = conf['reward'][benefit_times] bankrupt_ts = Time.current_ts() + reward['wait'] Context.Daily.set_daily_data(uid, gid, 'bankrupt_ts', bankrupt_ts) wait = reward['wait'] which = benefit_times + 1 mo = MsgPack(Message.FISH_MSG_BANKRUPT | Message.ID_NTF) mo.set_param('userId', uid) if wait is not None: mo.set_param('wait', wait) if which is not None: mo.set_param('which', which) # 可以领取哪一次 return mo
def query_chip_consume(self, gid, mi, request): room_types = (201, 202, 203) mini_games = (10002, 10003) fields = ['out.chip.attack'] for room_type in room_types: fields.append('out.chip.game.shot.bullet.%d' % room_type) for game in mini_games: fields.append('out.chip.game.%d' % game) start = mi.get_param('start') end = mi.get_param('end') start_day = Time.str_to_datetime(start, '%Y-%m-%d') end_day = Time.str_to_datetime(end, '%Y-%m-%d') mo = MsgPack(0) while start_day <= end_day: fmt = Time.datetime_to_str(start_day, '%Y-%m-%d') chips = Context.Stat.get_day_data(gid, fmt, *fields) attack = Tool.to_int(chips[0], 0) info = [] for chip in chips[1:]: if chip: info.append(int(chip)) else: info.append(0) info[2] += attack mo.set_param(fmt, info) start_day = Time.next_days(start_day) return mo
def on_raffle(self, uid, gid, mi): _id = mi.get_param('i') _button = mi.get_param('bt') mo = MsgPack(Message.MSG_SYS_RAFFLE | Message.ID_ACK) raffle_config = Context.Configure.get_game_item_json( gid, 'raffle.config') raffle_config = Context.copy_json_obj(raffle_config) loop_config = raffle_config['loop'] raffle_config = raffle_config['config'] class_pool, loop_times = Context.Daily.get_daily_data( uid, gid, 'fake.bonus.count', 'bonus.loop.times') class_pool = Tool.to_int(class_pool, 0) loop_times = Tool.to_int(loop_times, 0) if loop_times > len(loop_config) - 1: this_count = loop_config[-1] else: this_count = loop_config[loop_times] if class_pool < this_count: return mo.set_error(1, 'lack fish') for item in raffle_config: if item['id'] == _id: bonus_pool = Context.Data.get_game_attr_int( uid, gid, 'bonus_pool', 0) if bonus_pool < item['limit']: return mo.set_error(2, 'lack chip') # 发放奖励 index, which = Algorithm.choice_by_ratio(item['reward'], 10000, func=lambda l: l[0]) reward = FishProps.issue_rewards(uid, gid, which[1], 'bonus.raffle') mo.set_param('bt', _button) mo.set_param('i', index + 1) rw = FishProps.convert_reward(reward) mo.update_param(rw) # 重置数据 pipe_args = [ 'fake.bonus.count', -class_pool, 'bonus.loop.times', 1 ] Context.Daily.mincr_daily_data(uid, gid, *pipe_args) Context.Data.hincr_game(uid, gid, 'bonus_pool', -bonus_pool) self.__pub_raffle_led(uid, gid, item['name'], reward) return mo return mo.set_error(3, 'error id')
def on_consume_task(self, uid, gid, mi): _id = mi.get_param('id') mo = MsgPack(Message.MSG_SYS_CONSUME_TASK | Message.ID_ACK) task_list = Context.Daily.get_daily_data(uid, gid, 'task.list') if not task_list: return mo.set_error(1, 'no task') task_list = Context.json_loads(task_list) degree = 0 for task in task_list: if task['type'] == 1: count = Context.Daily.get_daily_data(uid, gid, 'fish.' + str(task['fish_type'])) task['count'] = Tool.to_int(count, 0) elif task['type'] == 2: count = Context.Daily.get_daily_data(uid, gid, 'class.boss') task['count'] = Tool.to_int(count, 0) elif task['type'] == 3: count = Context.Daily.get_daily_data(uid, gid, 'class.bonus') task['count'] = Tool.to_int(count, 0) elif task['type'] == 11: count = Context.Daily.get_daily_data(uid, gid, 'win.chip') task['count'] = Tool.to_int(count, 0) elif task['type'] == 21: degree += task['degree'] if 'count' in task and task['count'] >= task['total']: task['done'] = 1 degree += task['degree'] conf = Context.Configure.get_game_item_json(gid, 'task.config') for i, reward in enumerate(conf['reward']): if i == _id: if degree < reward['degree']: return mo.set_error(2, 'not done') state = Context.Daily.incr_daily_data(uid, gid, 'task.reward.%d' % _id, 1) if state > 1: return mo.set_error(3, 'received') reward = FishProps.issue_rewards(uid, gid, reward['reward'], 'task.reward.%d' % _id) _reward = FishProps.convert_reward(reward) mo.update_param(_reward) break else: mo.set_error(4, 'error id') return mo
def __get_user_info(self, uid, gid): game_attr = ['chip', 'exp'] chip, exp = Context.Data.get_game_attrs(uid, gid, game_attr) chip = Tool.to_int(chip, 0) exp = Tool.to_int(exp, 0) user_attr = ['nick', 'avatar', 'sex'] nick, avatar, sex = Context.Data.get_attrs(uid, user_attr) sex = Tool.to_int(sex, 0) level = FishAccount.get_vip_level(uid, gid) return { 'uid': uid, 'chip': chip, 'exp': exp, 'sex': sex, 'nick': nick, 'avatar': avatar, 'vip': level }
def on_user_login(cls, uid, gid): Context.Data.set_game_attr(uid, gid, 'session_login', Time.datetime_now()) login = Context.Daily.incr_daily_data(uid, gid, 'login.times', 1) if login == 1: channel = Context.Data.get_game_attr(uid, gid, 'session_channel', 'jiyu') login_user_count = Context.Stat.incr_daily_data( gid, '%s.login.user.count' % channel, 1) if login_user_count <= 10: # 多次测试 in_chip, out_chip = Context.RedisMix.hash_mget( 'game.%d.info.hash' % gid, 'in.chip', 'out.chip') in_chip = Tool.to_int(in_chip, 0) out_chip = Tool.to_int(out_chip, 0) Context.Stat.setnx_daily_data(gid, 'carrying.volume.chip', in_chip - out_chip) Context.Log.report('user.login:', [uid, gid, login]) return login
def check_benefit(cls, uid, gid): conf = Context.Configure.get_game_item_json(gid, 'benefit.config') total_times = len(conf['reward']) benefit_times, bankrupt_ts = Context.Daily.get_daily_data( uid, gid, 'benefit_times', 'bankrupt_ts') benefit_times = Tool.to_int(benefit_times, 0) if benefit_times >= total_times: return total_times, total_times, 0, conf now_ts = Time.current_ts() if bankrupt_ts and bankrupt_ts >= now_ts: return total_times, benefit_times, 0, conf else: return total_times, benefit_times, now_ts - bankrupt_ts, conf
def get_raffle_config(self, uid, gid): raffle_config = Context.Configure.get_game_item_json( gid, 'raffle.config') raffle_config = Context.copy_json_obj(raffle_config) loop_config = raffle_config['loop'] raffle_config = raffle_config['config'] for item in raffle_config: for i, reward in enumerate(item['reward']): item['reward'][i] = reward[1] class_pool, loop_times = Context.Daily.get_daily_data( uid, gid, 'fake.bonus.count', 'bonus.loop.times') class_pool = Tool.to_int(class_pool, 0) loop_times = Tool.to_int(loop_times, 0) if loop_times > len(loop_config) - 1: this_count = loop_config[-1] else: this_count = loop_config[loop_times] info = {'config': raffle_config} bonus_pool = Context.Data.get_game_attr_int(uid, gid, 'bonus_pool', 0) info['pool'] = bonus_pool info['progress'] = [class_pool, this_count] return info
def query_raffle(self, gid, mi, request): start = mi.get_param('start') end = mi.get_param('end') start_day = Time.str_to_datetime(start, '%Y-%m-%d') end_day = Time.str_to_datetime(end, '%Y-%m-%d') eggs = (211, 212, 213, 214) fileds = ['in.chip.bonus.raffle', 'in.diamond.bonus.raffle', 'in.coupon.bonus.raffle'] for egg in eggs: fileds.append('in.props.%d.bonus.raffle' % egg) mo = MsgPack(0) while start_day <= end_day: kvs = {} fmt = Time.datetime_to_str(start_day, '%Y-%m-%d') values = Context.Stat.get_day_data(gid, fmt, *fileds) kvs['chip'] = Tool.to_int(values[0], 0) kvs['diamond'] = Tool.to_int(values[1], 0) kvs['coupon'] = Tool.to_int(values[2], 0) egg_list = [] for egg in values[3:]: egg_list.append(Tool.to_int(egg, 0)) kvs['egg'] = egg_list mo.set_param(fmt, kvs) start_day = Time.next_days(start_day) return mo
def onServerInfo(self, uid, gid, mi): mo = MsgPack(Message.MSG_SYS_SERVER_INFO | Message.ID_ACK) game_room = Context.GData.map_room_type.get(gid) if game_room is None: mo.set_error(1, 'not found game') else: total, online_list = 0, [] room_types = sorted(game_room.keys()) onlines = Context.Online.get_online(gid, *room_types) for _type, _online in zip(room_types, onlines): _online = Tool.to_int(_online, 0) if _online < 1000: _online = 1000 + random.randint(0, 10) total += _online online_list.append([_type, _online]) mo.set_param('gameId', gid) mo.set_param('list', online_list) mo.set_param('online', total) return Context.GData.send_to_connect(uid, mo)
def on_benefit(self, uid, gid, mi): mo = MsgPack(Message.MSG_SYS_BENEFIT | Message.ID_ACK) conf = Context.Configure.get_game_item_json(gid, 'benefit.config') total_times = len(conf['reward']) benefit_times, bankrupt_ts = Context.Daily.get_daily_data( uid, gid, 'benefit_times', 'bankrupt_ts') benefit_times = Tool.to_int(benefit_times, 0) if benefit_times >= total_times: return mo.set_error(1, 'none') now_ts = Time.current_ts() if not bankrupt_ts or int(bankrupt_ts) > now_ts: return mo.set_error(2, 'wait') result = Context.Daily.issue_benefit(uid, gid) if not result: return mo.set_error(3, 'failed') Context.Daily.del_daily_data(uid, gid, 'bankrupt_ts') mo.update_param(result) return mo
def query_overview(self, gid, mi, request): kvs = Context.Stat.get_daily_data(gid) out_chip_pump = 0 out_chip, in_chip = 0, 0 in_diamond, out_diamond = 0, 0 fall_egg, shot_times = 0, 0 new_user_count, login_user_count = 0, 0 today_pay_total = 0 for k, v in kvs.iteritems(): if k.startswith('in.chip.'): in_chip += int(v) elif k.startswith('out.chip.'): if (k.startswith('out.chip.pump.') or k.startswith('out.chip.buff.pump.') or k.startswith('out.chip.red.pump.')): out_chip_pump += int(v) else: # pump 已经被game.shot.bullet包含 out_chip += int(v) elif k.startswith('in.diamond.'): in_diamond += int(v) elif k.startswith('out.diamond.'): out_diamond += int(v) elif k.startswith('shot.times.'): shot_times += int(v) elif k.endswith('.new.user.count'): new_user_count += int(v) elif k.endswith('.login.user.count'): login_user_count += int(v) elif k.endswith('.new.pay.user.pay_total'): pass elif k.endswith('.pay.user.pay_total'): today_pay_total += int(v) elif re.match(r'in\.props\.21[1234]\.fish\.fall\.', k): fall_egg += int(v) room_types = (201, 202, 203) # pool.chip pool_chip = [] for room_type in room_types: fields = ['pool.shot.%d' % room_type, 'pool.reward.%d' % room_type, 'out.chip.pump.%d' % room_type, 'official.macro.control.%d' % room_type] _shot, _reward, _pump, _control = Context.RedisMix.hash_mget('game.%d.info.hash' % gid, *fields) _shot = Tool.to_int(_shot, 0) _reward = Tool.to_int(_reward, 0) _pump = Tool.to_int(_pump, 0) _control = Tool.to_int(_control, 0) pool_chip.append(_shot - _pump - _reward + _control) # red.pool.chip _shot, _reward, _pump = Context.RedisMix.hash_mget('game.%d.info.hash' % gid, 'red.pool.shot.203', 'red.pool.reward.203', 'out.chip.red.pump.203') _shot = Tool.to_int(_shot, 0) _reward = Tool.to_int(_reward, 0) _pump = Tool.to_int(_pump, 0) red_pool_chip = _shot - _pump - _reward carrying_volume, login_carrying_volume = 0, 0 if 'carrying.volume.chip' in kvs: carrying_volume = int(kvs['carrying.volume.chip']) if 'login.carrying.volume.chip' in kvs: login_carrying_volume = int(kvs['login.carrying.volume.chip']) # online total, online_list = 0, [] onlines = Context.Online.get_online(gid, *room_types) for _online in onlines: _online = Tool.to_int(_online, 0) online_list.append(_online) # total kvs = Context.RedisMix.hash_getall('game.%d.info.hash' % gid) user_count, pay_user, pay_total = 0, 0, 0 for k, v in kvs.iteritems(): if k.endswith('.new.user.count'): user_count += int(v) elif k.endswith('.pay.user.count'): pay_user += int(v) elif k.endswith('.pay.user.pay_total'): pay_total += int(v) param = { 'total': { 'user.count': user_count, 'pay.user.count': pay_user, 'pay.total': pay_total }, 'today': { 'new.user.count': new_user_count, 'login.user.count': login_user_count, 'pay.total': today_pay_total, 'out.chip.pump': out_chip_pump, 'out.chip': out_chip, 'in.chip': in_chip, 'out.diamond': out_diamond, 'in.diamond': in_diamond, 'online': online_list, 'fall.egg': fall_egg, 'shot.times': shot_times, 'pool.chip': pool_chip, 'red.pool.chip': red_pool_chip, 'carrying.volume': carrying_volume, 'login.carrying.volume': login_carrying_volume } } return MsgPack(0, param)
def on_task_list(self, uid, gid, mi): conf = Context.Configure.get_game_item_json(gid, 'task.config') task_list = Context.Daily.get_daily_data(uid, gid, 'task.list') if task_list: task_list = Context.json_loads(task_list) else: what_day = Time.weekday(today=True) task_types = conf['daily'][what_day] task_map = {} for task in conf['task']: task_map[task['type']] = task total_degree, task_list = 0, [] for i, task_type in enumerate(task_types): task = {'id': i, 'type': task_type} if task_type == 2: # boss task['total'] = random.randint(*task_map[task_type]['range']) task['desc'] = task_map[task_type]['desc'] task['degree'] = task_map[task_type]['degree'] elif task_type == 3: task['total'] = random.randint(*task_map[task_type]['range']) task['desc'] = task_map[task_type]['desc'] task['degree'] = task_map[task_type]['degree'] elif task_type == 11: barrel_level = Context.Data.get_game_attr_int(uid, gid, 'barrel_level', 1) task['total'] = random.randint(*task_map[task_type]['range']) * barrel_level task['desc'] = task_map[task_type]['desc'] task['degree'] = task_map[task_type]['degree'] elif task_type == 21: task['desc'] = task_map[task_type]['desc'] task['degree'] = task_map[task_type]['degree'] elif task_type == 31: task['desc'] = task_map[task_type]['desc'] task['degree'] = task_map[task_type]['degree'] else: break total_degree += task['degree'] task_list.append(task) if total_degree < conf['total_degree']: fish_config = Context.Configure.get_game_item_json(gid, 'fish.201.config') fish_config = Context.copy_json_obj(fish_config) while total_degree < conf['total_degree']: # 普通鱼填充, 直到达到最大活跃值 task_type = 1 task = {'id': len(task_list), 'type': task_type} index = random.randrange(0, len(fish_config['common'])) fish = fish_config['common'][index] del fish_config['common'][index] task['total'] = random.randint(*task_map[task_type]['range']) task['desc'] = task_map[task_type]['desc'] task['fish_type'] = fish['type'] if isinstance(task_map[task_type]['degree'], list): for rg in task_map[task_type]['degree']: if task['total'] >= rg[0]: task['degree'] = rg[1] break else: task['degree'] = task_map[task_type]['degree'][-1][1] else: task['degree'] = task_map[task_type]['degree'] total_degree += task['degree'] task_list.insert(0, task) Context.Daily.set_daily_data(uid, gid, 'task.list', Context.json_dumps(task_list)) rewards, degree = [], 0 for task in task_list: if task['type'] == 1: count = Context.Daily.get_daily_data(uid, gid, 'fish.' + str(task['fish_type'])) task['count'] = Tool.to_int(count, 0) elif task['type'] == 2: count = Context.Daily.get_daily_data(uid, gid, 'class.boss') task['count'] = Tool.to_int(count, 0) elif task['type'] == 3: count = Context.Daily.get_daily_data(uid, gid, 'class.bonus') task['count'] = Tool.to_int(count, 0) elif task['type'] == 11: count = Context.Daily.get_daily_data(uid, gid, 'win.chip') task['count'] = Tool.to_int(count, 0) elif task['type'] == 21: task['done'] = 1 degree += task['degree'] if 'count' in task and task['count'] >= task['total']: task['done'] = 1 degree += task['degree'] # 处理奖励 _ids = range(len(conf['reward'])) for i, _id in enumerate(_ids): _ids[i] = 'task.reward.%d' % _id _states = Context.Daily.get_daily_data(uid, gid, *_ids) for _state, reward in zip(_states, conf['reward']): _state = 1 if _state else 0 _reward = FishProps.convert_reward(reward['reward']) rewards.append({'degree': reward['degree'], 'state': _state, 'reward': _reward}) mo = MsgPack(Message.MSG_SYS_TASK_LIST | Message.ID_ACK) mo.set_param('tasks', task_list) mo.set_param('reward', rewards) mo.set_param('degree', degree) return mo