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_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_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_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 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