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