예제 #1
0
    def add(self, **kwargs):
        from core.character import Char
        from core.hero import save_hero, HeroSoul, FakeSaveHeroResult
        from core.item import Item

        data = _get_resource_data(**kwargs)
        purchase_got = kwargs.get('purchase_got', 0)
        purchase_actual_got = kwargs.get('purchase_actual_got', 0)

        if data['gold'] or data['sycee'] or data['exp'] or data['official_exp'] or purchase_got:
            char = Char(self.char_id)
            char.update(gold=data['gold'], sycee=data['sycee'], exp=data['exp'], official_exp=data['official_exp'],
                        purchase_got=purchase_got,
                        purchase_actual_got=purchase_actual_got,
                        )
    
        if data['heros']:
            heros = []
            for _id, _amount in data['heros']:
                heros.extend([_id] * _amount)
            sh_res = save_hero(self.char_id, heros)
        else:
            sh_res = FakeSaveHeroResult
    
        if data['souls']:
            hs = HeroSoul(self.char_id)
            hs.add_soul(data['souls'])
    
        item = Item(self.char_id)
        for _id, _level, _amount in data['equipments']:
            for i in range(_amount):
                item.equip_add(_id, _level)
    
        if data['gems']:
            item.gem_add(data['gems'])
    
        if data['stuffs']:
            item.stuff_add(data['stuffs'])
    
        # normalize the data
        if data['heros']:
            data['heros'] = sh_res.actual_heros
            souls = dict(data['souls'])
    
            for _sid, _samount in sh_res.to_souls:
                souls[_sid] = souls.get(_sid, 0) + _samount

            data['souls'] = souls.items()

        data['income'] = 1
        data['func_name'] = self.func_name
        data['des'] = self.des
        resource_logger(self.char_id, data)

        data.pop('income')
        data.pop('func_name')
        data.pop('des')
        return data
예제 #2
0
def _check_character(char_id, gold=0, sycee=0, func_name=""):
    from core.character import Char
    c = Char(char_id)
    mc = c.mc
    if gold < 0 and mc.gold < abs(gold):
        raise SanguoException(GOLD_NOT_ENOUGH, char_id, func_name, 'Gold Not Enough. {0} < {1}'.format(mc.gold, abs(gold)))
    if sycee < 0 and mc.sycee < abs(sycee):
        raise SanguoException(SYCEE_NOT_ENOUGH, char_id, func_name, 'Sycee Not Enough. {0} < {1}'.format(mc.sycee, abs(sycee)))

    yield

    if gold or sycee:
        c.update(gold=gold, sycee=sycee)
예제 #3
0
def _check_character(char_id, gold=0, sycee=0, func_name=""):
    from core.character import Char
    c = Char(char_id)
    mc = c.mc
    if gold < 0 and mc.gold < abs(gold):
        raise SanguoException(
            GOLD_NOT_ENOUGH, char_id, func_name,
            'Gold Not Enough. {0} < {1}'.format(mc.gold, abs(gold)))
    if sycee < 0 and mc.sycee < abs(sycee):
        raise SanguoException(
            SYCEE_NOT_ENOUGH, char_id, func_name,
            'Sycee Not Enough. {0} < {1}'.format(mc.sycee, abs(sycee)))

    yield

    if gold or sycee:
        c.update(gold=gold, sycee=sycee)
예제 #4
0
    def add(self, **kwargs):
        from core.character import Char
        from core.hero import save_hero, HeroSoul, FakeSaveHeroResult
        from core.item import Item
        from core.horse import Horse
        from core.union.member import Member

        notify_settings = {}
        notify_settings['purchase_notify'] = kwargs.get('purchase_notify', True)

        data = _get_resource_data(**kwargs)
        purchase_got = kwargs.get('purchase_got', 0)
        purchase_actual_got = kwargs.get('purchase_actual_got', 0)

        if data['gold'] or data['sycee'] or data['exp'] or data['official_exp'] or purchase_got:
            char = Char(self.char_id)
            char.update(gold=data['gold'], sycee=data['sycee'], exp=data['exp'], official_exp=data['official_exp'],
                        purchase_got=purchase_got,
                        purchase_actual_got=purchase_actual_got,
                        notify_settings=notify_settings
                        )

        union_coin = kwargs.get('union_coin', 0)
        union_contribute_points = kwargs.get('union_contribute_points', 0)
        if union_coin or union_contribute_points:
            m = Member(self.char_id)
            m.add_coin(union_coin, send_notify=False)
            m.add_contribute_points(union_contribute_points)

    
        if data['heros']:
            heros = []
            for _id, _amount in data['heros']:
                heros.extend([_id] * _amount)
            sh_res = save_hero(self.char_id, heros)
        else:
            sh_res = FakeSaveHeroResult
    
        if data['souls']:
            hs = HeroSoul(self.char_id)
            hs.add_soul(data['souls'])
    
        item = Item(self.char_id)
        for _id, _level, _amount in data['equipments']:
            for i in range(_amount):
                item.equip_add(_id, _level)
    
        if data['gems']:
            item.gem_add(data['gems'])
    
        if data['stuffs']:
            item.stuff_add(data['stuffs'])

        if data['horses']:
            horse = Horse(self.char_id)
            for _id, _amount in data['horses']:
                for i in range(_amount):
                    horse.add(_id)
    
        # normalize the data
        if data['heros']:
            data['heros'] = sh_res.actual_heros
            souls = dict(data['souls'])
    
            for _sid, _samount in sh_res.to_souls:
                souls[_sid] = souls.get(_sid, 0) + _samount

            data['souls'] = souls.items()

        data['income'] = 1
        data['func_name'] = self.func_name
        data['des'] = self.des
        resource_logger(self.char_id, data)

        data.pop('income')
        data.pop('func_name')
        data.pop('des')
        return data
예제 #5
0
    def add(self, **kwargs):
        from core.character import Char
        from core.hero import save_hero, HeroSoul
        from core.item import Item

        data = _get_resource_data(**kwargs)
        purchase_got = kwargs.get('purchase_got', 0)
        purchase_actual_got = kwargs.get('purchase_actual_got', 0)

        if data['gold'] or data['sycee'] or data['exp'] or data[
                'official_exp'] or purchase_got:
            char = Char(self.char_id)
            char.update(
                gold=data['gold'],
                sycee=data['sycee'],
                exp=data['exp'],
                official_exp=data['official_exp'],
                purchase_got=purchase_got,
                purchase_actual_got=purchase_actual_got,
            )

        if data['heros']:
            heros = []
            for _id, _amount in data['heros']:
                heros.extend([_id] * _amount)
            sh_res = save_hero(self.char_id, heros)

        if data['souls']:
            hs = HeroSoul(self.char_id)
            hs.add_soul(data['souls'])

        item = Item(self.char_id)
        for _id, _level, _amount in data['equipments']:
            for i in range(_amount):
                item.equip_add(_id, _level)

        if data['gems']:
            item.gem_add(data['gems'])

        if data['stuffs']:
            item.stuff_add(data['stuffs'])

        # normalize the data
        if data['heros']:
            data['heros'] = sh_res.actual_heros
            souls = dict(data['souls'])

            for _sid, _samount in sh_res.to_souls:
                souls[_sid] = souls.get(_sid, 0) + _samount

            data['souls'] = souls.items()

        data['income'] = 1
        data['func_name'] = self.func_name
        data['des'] = self.des
        resource_logger(self.char_id, data)

        data.pop('income')
        data.pop('func_name')
        data.pop('des')
        return data
예제 #6
0
    def add(self, **kwargs):
        from core.character import Char
        from core.hero import save_hero, HeroSoul, FakeSaveHeroResult
        from core.item import Item
        from core.horse import Horse
        from core.union.member import Member

        update_settings = {}
        update_settings['purchase_notify'] = kwargs.get(
            'purchase_notify', True)
        update_settings['as_vip_exp'] = kwargs.get('as_vip_exp', True)

        data = _get_resource_data(**kwargs)
        purchase_got = kwargs.get('purchase_got', 0)
        purchase_actual_got = kwargs.get('purchase_actual_got', 0)

        if data['gold'] or data['sycee'] or data['exp'] or data[
                'official_exp'] or purchase_got:
            char = Char(self.char_id)
            char.update(gold=data['gold'],
                        sycee=data['sycee'],
                        exp=data['exp'],
                        official_exp=data['official_exp'],
                        purchase_got=purchase_got,
                        purchase_actual_got=purchase_actual_got,
                        update_settings=update_settings)

        union_coin = kwargs.get('union_coin', 0)
        union_contribute_points = kwargs.get('union_contribute_points', 0)
        if union_coin or union_contribute_points:
            m = Member(self.char_id)
            m.add_coin(union_coin, send_notify=False)
            m.add_contribute_points(union_contribute_points)

        if data['heros']:
            heros = []
            for _id, _amount in data['heros']:
                heros.extend([_id] * _amount)
            sh_res = save_hero(self.char_id, heros)
        else:
            sh_res = FakeSaveHeroResult

        if data['souls']:
            hs = HeroSoul(self.char_id)
            hs.add_soul(data['souls'])

        item = Item(self.char_id)
        for _id, _level, _amount in data['equipments']:
            for i in range(_amount):
                item.equip_add(_id, _level)

        if data['gems']:
            item.gem_add(data['gems'])

        if data['stuffs']:
            item.stuff_add(data['stuffs'])

        if data['horses']:
            horse = Horse(self.char_id)
            for _id, _amount in data['horses']:
                for i in range(_amount):
                    horse.add(_id)

        # normalize the data
        if data['heros']:
            data['heros'] = sh_res.actual_heros
            souls = dict(data['souls'])

            for _sid, _samount in sh_res.to_souls:
                souls[_sid] = souls.get(_sid, 0) + _samount

            data['souls'] = souls.items()

        data['income'] = 1
        data['func_name'] = self.func_name
        data['des'] = self.des
        resource_logger(self.char_id, data)

        data.pop('income')
        data.pop('func_name')
        data.pop('des')
        return data