def on_consume_cdkey(self, uid, gid, mi): code = mi.get_param('code') imei = mi.get_param('imei') timestamp = (int(time.time())) # data = {'appId': 1002, 'code': code, 'userChannel': 0, 'imei': imei, 'userId': uid,'timestamp': timestamp ,'token':'asdsd'} data = 'code=' + str(code) + '&' + 'userId=' + str( uid) + '&' + 'timestamp=' + str(timestamp) + '&token=asdsd' cdkey_server_url = Context.Configure.get_game_item( gid, 'cdkey.server.url') Context.Log.info("cdkey_server_url:", cdkey_server_url) result = Context.WebPage.wait_for_json(cdkey_server_url, postdata=data) mo = MsgPack(Message.MSG_SYS_CONSUME_CDKEY | Message.ID_ACK) if result['result'] != 1: # 错误 mo.set_error(result['result']) else: try: Context.Log.info("desc:", result['desc']) reward = self.__convert_cdkey_desc(result['desc']) rewards = FishProps.issue_rewards(uid, gid, reward, 'cdkey.reward') _rewards = FishProps.convert_reward(rewards) mo.update_param(_rewards) except Exception, e: Context.Log.exception(uid, gid, result) return
def on_inner_buy(self, uid, gid, mi): mo = MsgPack(Message.MSG_SYS_INNER_BUY | Message.ID_ACK) _id = mi.get_param('id') if not isinstance(_id, int): return mo.set_error(1, 'error param') _count = mi.get_param('count') if not isinstance(_count, int) or _count <= 0: return mo.set_error(2, 'error param') if _id not in [201, 202, 203, 204, 205]: return mo.set_error(3, 'error id') conf = FishProps.get_config_by_id(gid, _id) if conf: if 'count' in conf: if _count % conf['count'] != 0: return mo.set_error(5, 'error count') real, final = Context.UserAttr.incr_diamond( uid, gid, -conf['diamond'], 'inner.buy.%d' % _id) if real != -conf['diamond']: return mo.set_error(6, 'not enough') mo.set_param('diamond', final) real, final = FishProps.incr_props(uid, gid, _id, _count, 'inner.buy') mo.set_param('id', _id) mo.set_param('count', final) return mo Context.Log.error('no props config found', _id) return mo.set_error(7, 'unknown')
def on_create_user(cls, uid, gid): super(FishAccount, cls).on_create_user(uid, gid) # 发放一级礼包 conf = Context.Configure.get_game_item_json(gid, 'exp.level.reward') rewards_info = FishProps.issue_rewards(uid, gid, conf[0], 'exp.upgrade') rewards_info = FishProps.convert_reward(rewards_info) mo = MsgPack(Message.FISH_MSG_EXP_UPGRADE | Message.ID_NTF) mo.set_param('exp', 0) mo.set_param('lv', 1) mo.set_param('df', [1, [0, conf[1]]]) mo.update_param(rewards_info) Context.GData.send_to_connect(uid, mo) # new user carrying pipe_args = [] for k in ('chip', 'diamond', 'coupon'): if k in rewards_info: pipe_args.append('login.carrying.volume.%s' % k) pipe_args.append(rewards_info[k]) if 'chip' in rewards_info: pipe_args.append('carrying.volume.chip') pipe_args.append(rewards_info['chip']) if pipe_args: Context.Stat.mincr_daily_data(gid, *pipe_args)
def on_use_props(self, uid, gid, mi): _id = mi.get_param('id') _count = mi.get_param('count') mo = MsgPack(Message.MSG_SYS_USE_PROPS | Message.ID_ACK) if _id not in [ FishProps.PROP_EGG_BRONZE, FishProps.PROP_EGG_SILVER, FishProps.PROP_EGG_GOLD, FishProps.PROP_EGG_COLOR ]: return mo.set_error(1, 'can not use') if not isinstance(_count, int) or _count <= 0: return mo.set_error(2, 'count error') conf = FishProps.get_config_by_id(gid, _id) if not conf: Context.Log.error('not found props:', uid, gid, _id, _count) return mo.set_error(4, 'not found props') real, final = FishProps.incr_props(uid, gid, _id, -_count, 'entity.use') if real != -_count: return mo.set_error(3, 'not enough') if _count == 1: reward = conf['content'] else: reward = FishProps.merge_reward(*[conf['content']] * _count) reward = Context.copy_json_obj(reward) reward = self.deal_reward(reward) reward = FishProps.issue_rewards(uid, gid, reward, 'entity.use') reward = FishProps.convert_reward(reward) mo.update_param(reward) return mo
def on_up_barrel(self, uid, gid, mi): # 强化万倍炮 # up type 1 石头 2 精华 mo = MsgPack(Message.MSG_SYS_UP_BARREL | Message.ID_ACK) up_type = mi.get_param('up_ty') conf = Context.Configure.get_game_item_json(gid, 'barrel.unlock.config') if not conf: return mo.set_error(1, 'system error') next_level = Context.Data.get_game_attr_int(uid, gid, 'barrel_level', 1) + 1 # if next_level > len(conf): if next_level <= 36 or next_level > 54: return mo.set_error(2, 'level error') level_conf = conf[next_level - 1] diamond_count = level_conf['diamond'] real, final = Context.UserAttr.incr_diamond(uid, gid, -diamond_count, 'up.barrel') if real != -diamond_count: return mo.set_error(3, 'lack diamond') if up_type == 1: count = -level_conf['stone'] if not FishProps.mincr_props(uid, gid, 'on_up_barrel', 215, count, 216, count, 217, count, 218, count): Context.UserAttr.incr_diamond(uid, gid, diamond_count, 'up.barrel.error') return mo.set_error(3, 'lack stone') res, gem = self.do_up_barrel(level_conf) if res: Context.Data.set_game_attr(uid, gid, 'barrel_level', next_level) else: FishProps.mincr_props(uid, gid, 'on_up_barrel.fail_reurn', 219, gem) mo.set_param('num', gem) elif up_type == 2: count = -level_conf['stone'] count_gem = -level_conf['gem'] if not FishProps.mincr_props(uid, gid, 'on_up_barrel', 215, count, 216, count, 217, count, 218, count, 219, count_gem): Context.UserAttr.incr_diamond(uid, gid, diamond_count, 'up.barrel.error') return mo.set_error(3, 'lack item') Context.Data.set_game_attr(uid, gid, 'barrel_level', next_level) else: return mo.set_error(4, 'type error') return mo
def on_get_config(self, uid, gid, mi): which = mi.get_param('which') if isinstance(which, (str, unicode)): which = [which] mo = MsgPack(Message.MSG_SYS_CONFIG | Message.ID_ACK) for name in which: if name == 'vip': conf = self.get_vip_config(uid, gid) elif name == 'shop': conf = self.get_shop_config(uid, gid) elif name == 'raffle': conf = self.get_raffle_config(uid, gid) elif name == 'props': conf = FishProps.get_props_config(gid) elif name == 'unlock': conf = self.get_unlock_config(uid, gid) elif name == 'barrel': conf = self.get_barrel_config(uid, gid) elif name == 'exchange': conf = self.get_exchange_config(uid, gid) elif name == 'benefit': conf = self.get_benefit_config(uid, gid) elif name == 'html': conf = self.get_html_config(uid, gid) elif name == 'exp': conf = self.get_exp_config(uid, gid) elif name == 'upbrrel': conf = self.get_upbrrel_config(uid, gid) else: continue mo.set_param(name, conf) return mo
def on_exchange(self, uid, gid, mi): mo = MsgPack(Message.MSG_SYS_EXCHANGE | Message.ID_ACK) _id = mi.get_param('id') if not isinstance(_id, int): return mo.set_error(1, 'error param') conf = Context.Configure.get_game_item_json(gid, 'exchange.config') if _id >= len(conf): return mo.set_error(1, 'error id') info = conf[_id] to_type = info['type'] if to_type not in ('diamond', 'props', 'phone'): raise Exception( str(to_type) + '<----error type, please check config') real, final = Context.UserAttr.incr_coupon(uid, gid, -info['cost'], 'exchange.' + to_type) if real != -info['cost']: return mo.set_error(2, 'not enough') mo.set_param('coupon', final) record = { 'uid': uid, 'type': 'exchange', 'ts': Time.current_ts(), 'from': 'coupon', 'to': to_type, 'cost': info['cost'], 'count': info['count'], 'desc': info['desc'] } if info['type'] == 'diamond': # 兑换钻石 real, final = Context.UserAttr.incr_diamond( uid, gid, info['count'], 'exchange.diamond') mo.set_param('diamond', final) state = 1 elif info['type'] == 'props': # 兑换道具 real, final = FishProps.incr_props(uid, gid, info['id'], info['count'], 'exchange.props') mo.set_param('id', info['id']) mo.set_param('count', final) state = 1 record['id'] = info['id'] elif info['type'] == 'phone': state = 0 record['phone'] = mi.get_param('phone') else: raise Exception('something error, please check config') seq_num = Context.RedisMix.hash_incrby('game.%d.info.hash' % gid, 'exchange.history.seq', 1) Context.RedisCluster.hash_set(uid, 'history:%d:%d' % (gid, uid), seq_num, state) record = Context.json_dumps(record) Context.RedisMix.hash_mset('game.%d.exchange.record' % gid, seq_num, record) fmt = Time.current_time('%Y-%m-%d') Context.RedisStat.hash_set('history:%d:%s' % (gid, fmt), seq_num, uid) return mo
def on_resolve_stone(self, uid, gid, mi): # 分解强化石 mo = MsgPack(Message.MSG_SYS_RESOLVE_STONE | Message.ID_ACK) stone_id = mi.get_param('id') if stone_id not in [215, 216, 217, 218]: return mo.set_error(1, 'id error') conf = FishProps.get_config_by_id(gid, stone_id) count = -conf['count'] if not FishProps.mincr_props(uid, gid, 'on_resolve_stone', stone_id, count): return mo.set_error(2, 'lack stone') gem_count = random.randint(conf['resolve'][0], conf['resolve'][1]) FishProps.mincr_props(uid, gid, 'on_resolve_stone', 219, gem_count) mo.set_param('num', gem_count) return mo
def __pub_raffle_led(self, uid, gid, level, reward_info): if 'reward' in reward_info: reward = reward_info['reward'] name = None if 'chip' in reward: Context.Data.hincr_game(uid, gid, 'chip_pool', -reward['chip']) elif 'coupon' in reward: name = u'%d鱼券' % reward['coupon'] elif 'diamond' in reward: name = u'%d钻石' % reward['diamond'] elif 'props' in reward: props = reward['props'] for one in props: name = FishProps.get_props_desc(one['id']) break if name: nick = Context.Data.get_attr(uid, 'nick') if nick: led = u'恭喜%s玩家,在%s中抽中%s' % (nick.decode('utf-8'), level, name) mo = MsgPack(Message.MSG_SYS_LED | Message.ID_NTF) mo.set_param('game', { 'list': [led], 'ts': Time.current_ts() }) Context.GData.broadcast_to_system(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 on_props_list(self, uid, gid, mi): props_list = FishProps.get_props_list(uid, gid) info = { 'c': Context.UserAttr.get_chip(uid, gid, 0), 'd': Context.UserAttr.get_diamond(uid, gid, 0), 'o': Context.UserAttr.get_coupon(uid, gid, 0) } if props_list: info['p'] = props_list # 升级礼包 conf = Context.Configure.get_game_item_json(gid, 'exp.level.reward') level, _ = FishAccount.get_exp_info(uid, gid) if level < len(conf): info['up'] = FishProps.convert_reward(conf[level]) mo = MsgPack(Message.MSG_SYS_PROPS_LIST | Message.ID_ACK) mo.update_param(info) return mo
def buy_props(self, pid): if self.game_info['diamond'] > 0: conf = FishProps.get_config_by_id(self.gid, pid) price = conf['price'] if self.game_info['diamond'] >= price: real, final = Context.UserAttr.incr_diamond( self.uid, self.gid, -price, 'table.buy.%d' % pid) self.game_info['diamond'] = final if real == -price: return final return None
def on_present(self, uid, gid, mi): mo = MsgPack(Message.MSG_SYS_PRESENT | Message.ID_ACK) _id = mi.get_param('id') if not isinstance(_id, int): return mo.set_error(1, 'error param') _count = mi.get_param('count') if not isinstance(_count, int) or _count <= 0: return mo.set_error(2, 'error param') if _id not in [ 201, 202, 203, 204, 205, 211, 212, 213, 214, 215, 216, 217, 218, 219 ]: return mo.set_error(3, 'error id') ta = mi.get_param('ta') if ta < 0 or not Context.UserAttr.check_exist(ta, gid): return mo.set_error(4, 'error uid') conf = FishProps.get_config_by_id(gid, _id) if conf: if 'count' in conf: if _count % conf['count'] != 0: return mo.set_error(5, 'error count') if 'present' in conf: pay_total = Context.Data.get_game_attr_int( uid, gid, 'pay_total', 0) if conf['present']['pay'] > pay_total: return mo.set_error(7, 'pay limit') real, final = FishProps.incr_props(uid, gid, _id, -_count, 'present.props', ta=ta) if real != -_count: return mo.set_error(6, 'not enough') mo.set_param('id', _id) mo.set_param('count', final) FishProps.incr_props(ta, gid, _id, _count, 'present.props', ta=uid) return mo Context.Log.error('no props config found', _id) return mo.set_error(7, 'unknown')
def get_game_info(cls, uid, gid): is_new, kvs = cls.get_common_game_info(uid, gid) conf = Context.Configure.get_game_item_json(gid, 'barrel.unlock.config') kvs['barrel_multiple'] = conf[kvs['barrel_level'] - 1]['multiple'] vip = cls.get_vip_info(uid, gid) if vip: kvs['vip'] = vip now_day, last_login, ns_login = cls.get_login_info(uid, gid) login = {'done': 0} if now_day == last_login: # 已经签到 login['done'] = 1 elif now_day == last_login + 1: # 连续登陆 ns_login += 1 else: ns_login = 0 # login conf = Context.Configure.get_game_item_json(gid, 'login.reward') if vip['level'] > 0: conf = conf['vip'] else: conf = conf['common'] login['conf'] = conf login['which'] = ns_login % len(conf) kvs['login'] = login # exp level, diff = cls.get_exp_info(uid, gid, kvs['exp']) kvs['exp_level'] = level if diff: kvs['exp_diff'] = diff # month card state, left_days = FishProps.get_vip(uid, gid) if left_days >= 0: kvs['card'] = {'state': state, 'left': left_days} # skill test vt, sw = Context.Data.get_game_attrs( uid, gid, ['try_violent', 'try_super_weapon']) can_try = [] if vt is None: can_try.append(203) if sw is None: can_try.append(204) if can_try: kvs['try'] = can_try return is_new, kvs
def gm_reward_card(self, gid, mi, request): uid = mi.get_param('userId') days = mi.get_param('days') if days <= 0: return MsgPack.Error(0, 1, 'error days') if not Context.UserAttr.check_exist(uid, gid): return MsgPack.Error(0, 2, 'not exist') state, days = FishProps.incr_vip(uid, gid, days, 'gm.reward') mo = MsgPack(0) mo.set_param('days', days) return mo
def use_props(self, pid, roomtype): left = self._props_info.get(pid) if left: real, final = FishProps.incr_props(self.uid, self.gid, pid, -1, 'game.use', roomtype=roomtype) self._props_info[pid] = final if real == -1: return True, final self._props_info[pid] = 0 return False, 0
def gm_reward_egg(self, gid, mi, request): uid = mi.get_param('userId') _id = mi.get_param('id') _count = mi.get_param('count') if _id not in (201, 202, 203, 204, 205, 211, 212, 213, 214, 215, 216, 217, 218, 219): return MsgPack.Error(0, 1, 'error id') if not Context.UserAttr.check_exist(uid, gid): return MsgPack.Error(0, 3, 'user not exist') real, final = FishProps.incr_props(uid, gid, _id, _count, 'gm.reward') mo = MsgPack(0) mo.set_param('delta', real) mo.set_param('id', _id) mo.set_param('count', final) return mo
def issue_rewards(self, rewards, event, **kwargs): result = FishProps.issue_rewards(self.uid, self.gid, rewards, event, **kwargs) if result: if 'chip' in result: self.game_info['chip'] = result['chip'] if 'coupon' in result: self.game_info['coupon'] = result['coupon'] if 'diamond' in result: self.game_info['diamond'] = result['diamond'] if 'props' in result: props = self._props_info for one in result['props']: if one['id'] in props: props[one['id']] += one['count'] else: props[one['id']] = one['count'] return result
def gm_reward_vip(self, gid, mi, request): uid = mi.get_param('userId') rmb = mi.get_param('rmb') if not isinstance(rmb, int): return MsgPack.Error(0, 1, 'int please') if not Context.UserAttr.check_exist(uid, gid): return MsgPack.Error(0, 2, 'not exist') if rmb < 0: pay_total = Context.Data.get_game_attr_int(uid, gid, 'pay_total', 0) if pay_total < -rmb: return MsgPack.Error(0, 3, 'too much') final = FishProps.incr_pay(uid, gid, rmb, 'gm.reward') level = FishAccount.get_vip_level(uid, gid, final) mo = MsgPack(0) mo.set_param('level', level) mo.set_param('pay_total', final) return mo
def query_user_info(self, gid, mi, request): uid = mi.get_param('userId') user_attrs = ['createTime', 'deviceId', 'nick', 'idType', 'userName', 'channel', 'platform'] kvs = Context.Data.get_attrs_dict(uid, user_attrs) game_attrs = ['pay_total', 'session_login', 'exp', 'barrel_level', 'chip', 'diamond', 'in_chip', 'out_chip'] _kvs = Context.Data.get_game_attrs_dict(uid, gid, game_attrs) kvs.update(_kvs) kvs['chip'] = int(kvs.get('chip', 0)) kvs['in_chip'] = int(kvs.get('in_chip', 0)) kvs['out_chip'] = int(kvs.get('out_chip', 0)) kvs['diamond'] = int(kvs.get('diamond', 0)) dt = Time.str_to_datetime(kvs['createTime'], '%Y-%m-%d %X.%f') kvs['createTime'] = Time.datetime_to_str(dt, '%Y-%m-%d %X') dt = Time.str_to_datetime(kvs['session_login'], '%Y-%m-%d %X.%f') kvs['session_login'] = Time.datetime_to_str(dt, '%Y-%m-%d %X') if int(kvs['idType']) == 13: kvs['phone'] = kvs['userName'] kvs['pay_total'] = int(kvs.get('pay_total', 0)) kvs['vip_level'] = FishAccount.get_vip_level(uid, gid, pay_total=int(kvs['pay_total'])) exp = int(kvs['exp']) kvs['level'], _ = FishAccount.get_exp_info(uid, gid, exp=exp) barrel_level = int(kvs['barrel_level']) kvs['barrel_multiple'] = FishAccount.trans_barrel_level(gid, barrel_level) l = (201, 202, 203, 204, 205, 211, 212, 213, 214, 215, 216, 217, 218, 219) _list = FishProps.get_props_list(uid, gid, l) props_map = dict(_list) props_list = [] for i in l: count = props_map.get(i, 0) props_list.append(count) kvs['props'] = props_list mo = MsgPack(0) mo.update_param(kvs) return mo
def on_sign_in(self, uid, gid, mi): mo = MsgPack(Message.MSG_SYS_SIGN_IN | Message.ID_ACK) conf = Context.Configure.get_game_item_json(gid, 'login.reward') if not conf: Context.Log.error('miss config') return mo.set_error(1, 'miss config') now_day, last_login, ns_login = FishAccount.get_login_info(uid, gid) if now_day == last_login: return mo.set_error(2, 'already sign in') elif now_day == last_login + 1: # 连续登陆 ns_login += 1 else: ns_login = 0 FishAccount.set_login_info(uid, gid, now_day, ns_login) vip_level = FishAccount.get_vip_level(uid, gid) if vip_level: conf = conf['vip'] else: conf = conf['common'] reward = conf[ns_login % len(conf)] real, final = Context.UserAttr.incr_chip(uid, gid, reward, 'signin.reward') pipe_args = [] delta_chip = real # 领取月卡奖励 success, left_days = FishProps.use_vip(uid, gid) if success: conf = Context.Configure.get_game_item_json( gid, 'month.card.reward') reward = FishProps.issue_rewards(uid, gid, conf, 'month.card.reward') if 'diamond' in reward: mo.set_param('diamond', reward['diamond']) pipe_args.append('login.carrying.volume.diamond') pipe_args.append(reward['reward']['diamond']) if 'coupon' in reward: mo.set_param('coupon', reward['coupon']) pipe_args.append('login.carrying.volume.coupon') pipe_args.append(reward['reward']['coupon']) if 'chip' in reward: final = reward['chip'] delta_chip += reward['reward']['chip'] pipe_args.append('login.carrying.volume.chip') pipe_args.append(delta_chip) pipe_args.append('carrying.volume.chip') pipe_args.append(delta_chip) Context.Daily.mincr_daily_data(uid, gid, *pipe_args) if vip_level: vip_conf = Context.Configure.get_game_item_json( gid, 'vip.config')[vip_level - 1] stone_count = vip_conf.get('stone', 0) if stone_count: FishProps.mincr_props(uid, gid, 'vip_reward', 215, stone_count, 216, stone_count, 217, stone_count, 218, stone_count) chip_num = vip_conf.get('chip') if chip_num and chip_num > final: add_num = chip_num - final real, final = Context.UserAttr.incr_chip( uid, gid, add_num, 'vip_reward') if final: mo.set_param('chip', final) return mo
def on_product_deliver(self, uid, gid, mi): orderId = mi.get_param('orderId') productId = mi.get_param('productId') payType = mi.get_param('payType') channel = mi.get_param('channel') cost = mi.get_param('cost') param = { 'orderId': orderId, 'productId': productId, 'payType': payType, 'channel': channel, 'cost': cost } Context.Log.report('product.issue: [%d, %d, %s, %s]' % (uid, gid, orderId, param)) all_product = Context.Configure.get_game_item_json( gid, 'product.config') if productId not in all_product: Context.Log.error('productId not exist', orderId, productId, all_product) return MsgPack.Error(0, 1, 'no product found') shop_config = Context.Configure.get_game_item_json(gid, 'shop.config') pipe_args = ['product_%s' % productId, 1] times = Context.Data.hincr_game(uid, gid, 'product_%s' % productId, 1) # 记录充值相关字段 pay_total = FishProps.incr_pay(uid, gid, cost, 'buy.product', orderId=orderId) today_pay_times, _ = Context.Daily.mincr_daily_data( uid, gid, 'pay_times', 1, 'pay_total', cost) is_reset_chance, is_first_double = False, False if productId in shop_config['chip']: if times == 1: is_first_double = True else: reset_choice = Context.Data.get_game_attr_int( uid, gid, 'reset_' + str(productId), 0) if reset_choice: is_reset_chance = True product = all_product[productId] if is_reset_chance: # reset chance reward = self.__rebate_reward(gid, pay_total, product['first'], channel) FishProps.issue_rewards(uid, gid, reward, 'buy.product', orderId=orderId, reset=1) Context.Data.del_game_attrs(uid, gid, 'reset_' + str(productId)) elif is_first_double: reward = self.__rebate_reward(gid, pay_total, product['first'], channel) FishProps.issue_rewards(uid, gid, reward, 'buy.product', orderId=orderId, first=1) elif productId in shop_config['card']: state, days = FishProps.incr_vip(uid, gid, 30, 'buy.product', orderId=orderId) if state == 0: # 今日未领取 sign_in = Context.Daily.get_daily_data(uid, gid, 'sign_in') if sign_in: success, left_days = FishProps.use_vip(uid, gid) if success: conf = Context.Configure.get_game_item_json( gid, 'month.card.reward') FishProps.issue_rewards(uid, gid, conf, 'month.card.reward') else: reward = self.__rebate_reward(gid, pay_total, product['content'], channel) FishProps.issue_rewards(uid, gid, reward, 'buy.product', orderId=orderId) if today_pay_times == 1: # today first pay pipe_args.append(channel + '.pay.user.count') pipe_args.append(1) pipe_args.append(channel + '.pay.user.pay_total') pipe_args.append(cost) pipe_args.append(channel + '.user.pay.times') pipe_args.append(1) if pay_total == cost: # life first pay pipe_args.append(channel + '.new.pay.user.count') pipe_args.append(1) pipe_args.append('new_pay_user') pipe_args.append(1) new_pay_user = 1 else: new_pay_user = Context.Daily.get_daily_data( uid, gid, 'new_pay_user') if new_pay_user: pipe_args.append(channel + '.new.pay.user.pay_total') pipe_args.append(cost) Context.Stat.mincr_daily_data(gid, *pipe_args) key = 'game.%d.info.hash' % gid pipe_args = [] if pay_total == cost: pipe_args.append(channel + '.pay.user.count') pipe_args.append(1) pipe_args.append(channel + '.pay.user.pay_total') pipe_args.append(cost) pipe_args.append(channel + '.user.pay.times') pipe_args.append(1) Context.RedisMix.hash_mincrby(key, *pipe_args) self.__handle_pay_effect(uid, gid, cost, today_pay_times) return MsgPack(0, {'msg': u'已到货'})
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