コード例 #1
0
ファイル: props.py プロジェクト: qianyc1020/FishServer
    def __merge_reward(self, prev, later):
        if not prev:
            return Context.copy_json_obj(later)
        if not later:
            return Context.copy_json_obj(prev)

        rewards = {}
        # merge金币
        if 'chip' in prev or 'chip' in later:
            rewards['chip'] = prev.get('chip', 0) + later.get('chip', 0)
        # merge钻石
        if 'diamond' in prev or 'diamond' in later:
            rewards['diamond'] = prev.get('diamond', 0) + later.get('diamond', 0)
        # merge兑换券
        if 'coupon' in prev or 'coupon' in later:
            rewards['coupon'] = prev.get('coupon', 0) + later.get('coupon', 0)
        # merge道具
        props = {}
        for tmp in [prev, later]:
            if 'props' in tmp:
                for prop in tmp['props']:
                    if prop['id'] not in props:
                        props[prop['id']] = prop
                    else:
                        props[prop['id']]['count'] += prop['count']

        if props:
            rewards['props'] = props.values()

        return rewards
コード例 #2
0
ファイル: props.py プロジェクト: qianyc1020/FishServer
    def __merge_reward_result(self, detail, prev, later):
        if not prev:
            return Context.copy_json_obj(later)
        if not later:
            return Context.copy_json_obj(prev)

        ret = {}

        # 合并最终的字段
        if 'chip' in later:
            ret['chip'] = later['chip']
        elif 'chip' in prev:
            ret['chip'] = prev['chip']

        if 'diamond' in later:
            ret['diamond'] = later['diamond']
        elif 'diamond' in prev:
            ret['diamond'] = prev['diamond']

        _props = {}
        for tmp in [prev, later]:
            if 'props' in tmp:
                for prop in tmp['props']:
                    _props[prop['id']] = prop
        if _props:
            ret['props'] = _props.values()

        if detail:
            # 合并奖励字段
            prev_reward, later_reward = prev['reward'], later['reward']
            rewards = {}
            # merge金币
            if 'chip' in prev_reward or 'chip' in later_reward:
                rewards['chip'] = prev_reward.get('chip', 0) + later_reward.get('chip', 0)
            # merge fake 金币
            if 'fake_chip' in prev_reward or 'fake_chip' in later_reward:
                rewards['fake_chip'] = prev_reward.get('fake_chip', 0) + later_reward.get('fake_chip', 0)
            # merge钻石
            if 'diamond' in prev_reward or 'diamond' in later_reward:
                rewards['diamond'] = prev_reward.get('diamond', 0) + later_reward.get('diamond', 0)
            # merge兑换券
            if 'coupon' in prev_reward or 'coupon' in later_reward:
                rewards['coupon'] = prev_reward.get('coupon', 0) + later_reward.get('coupon', 0)
            # merge道具
            props = {}
            for tmp in [prev_reward, later_reward]:
                if 'props' in tmp:
                    for prop in tmp['props']:
                        if prop['id'] not in props:
                            props[prop['id']] = prop
                        else:
                            props[prop['id']]['count'] += prop['count']

            if props:
                rewards['props'] = props.values()

            if rewards:
                ret['reward'] = rewards

        return ret
コード例 #3
0
ファイル: entity.py プロジェクト: panda2012/FishServer
    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
コード例 #4
0
ファイル: entity.py プロジェクト: panda2012/FishServer
    def on_room_list(self, uid, gid, mi):
        room_config = Context.Configure.get_room_config(gid)
        if not room_config:
            Context.Log.error(uid, 'req room list, but no config fetch')
            return False

        conf = Context.copy_json_obj(room_config)
        mo = MsgPack(Message.MSG_SYS_ROOM_LIST | Message.ID_ACK)
        mo.set_param('room_list', conf)
        return Context.GData.send_to_connect(uid, mo)
コード例 #5
0
ファイル: entity.py プロジェクト: panda2012/FishServer
    def __rebate_reward(self, gid, pay_total, reward, channel):
        reward = Context.copy_json_obj(reward)
        if 'chip' in reward:
            vip_config = Context.Configure.get_game_item_json(
                gid, 'vip.config')
            if vip_config:
                for item in reversed(vip_config):
                    if pay_total > item['pay'] and 'rebate' in item:
                        rebate = item['rebate']
                        reward['chip'] += int(reward['chip'] * rebate)
                        break

        return reward
コード例 #6
0
ファイル: account.py プロジェクト: qianyc1020/FishServer
    def get_common_game_info(cls, uid, gid):
        chip = Context.UserAttr.get_chip(uid, gid)
        if chip is None:
            kvs = Context.copy_json_obj(cls.game_attrs)
            Context.Data.set_game_attrs_dict(uid, gid, kvs)
            chip_startup = Context.Configure.get_game_item_int(
                gid, 'game.startup')
            Context.UserAttr.incr_chip(uid, gid, chip_startup, 'game.startup')
            kvs['chip'] = chip_startup
            is_new = True
        else:
            attrs = cls.game_attrs.keys()
            kvs = Context.copy_json_obj(cls.game_attrs)
            kvs.update(Context.Data.get_game_attrs_dict(uid, gid, attrs))
            for k, v in kvs.iteritems():
                kvs[k] = int(kvs[k])
            kvs['chip'] = chip
            is_new = False

        diamond = Context.UserAttr.get_diamond(uid, gid, 0)
        kvs['diamond'] = diamond
        coupon = Context.UserAttr.get_coupon(uid, gid, 0)
        kvs['coupon'] = coupon
        return is_new, kvs
コード例 #7
0
ファイル: entity.py プロジェクト: panda2012/FishServer
    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')
コード例 #8
0
    def load_config(cls, gid):
        for roomtype in (201, 202, 203):
            conf = Context.Configure.get_game_item_json(
                gid, 'timeline.%d.config' % roomtype)
            conf = Context.copy_json_obj(conf)
            for k in ('boss', 'tide', 'bounty'):
                conf[k] = [int(t * 10) for t in conf[k]]
            cls.timeline_map[roomtype] = conf

            conf = Context.Configure.get_game_item_json(
                gid, 'fish.%d.config' % roomtype)
            kvs = {}
            for k in ('common', 'boss', 'bonus'):
                types = [item['type'] for item in conf[k]]
                kvs[k] = types
            kvs['little'] = kvs['common'][:9]
            kvs['middle'] = kvs['common'][9:]
            kvs['bonus'] = kvs['bonus'][:-1]  # 红龙任务中红龙奖金鱼去掉
            kvs['boss'] = kvs['boss'][:-1]  # 红龙任务中红龙去掉
            cls.fish_info_map[roomtype] = kvs
コード例 #9
0
ファイル: entity.py プロジェクト: panda2012/FishServer
    def get_shop_config(self, uid, gid):
        product_config = Context.Configure.get_game_item_json(
            gid, 'product.config')
        shop_config = Context.Configure.get_game_item_json(gid, 'shop.config')
        if not shop_config or not product_config:
            return {}

        product_config = Context.copy_json_obj(product_config)
        attrs = list(shop_config['chip'])
        attrs.extend(shop_config['first'])
        fileds = []
        for attr in attrs:
            fileds.append('product_%s' % attr)
            fileds.append('reset_%s' % attr)

        counts = Context.Data.get_game_attrs(uid, gid, fileds)
        kvs = Tool.make_dict(attrs, counts[::2])
        reset_kvs = Tool.make_dict(attrs, counts[1::2])
        info = {}
        for k, pids in shop_config.iteritems():
            group = []
            for pid in pids:
                product = product_config[pid]
                del product['name']
                if k in ('chip', 'diamond'):
                    del product['content']
                if 'first' in product:
                    del product['first']
                if k == 'first' and kvs[pid] is None:
                    product['first'] = 1
                elif k == 'chip' and (kvs[pid] is None or reset_kvs[pid]):
                    product['first'] = 1
                product['id'] = pid
                group.append(product)
            info[k] = group
        info['card'] = info['card'][0]  # 只要一个
        if not counts[-2]:
            info['first'] = info['first'][1]  # 只要一个

        return info
コード例 #10
0
ファイル: entity.py プロジェクト: panda2012/FishServer
    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
コード例 #11
0
    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