コード例 #1
0
ファイル: resource.py プロジェクト: hx002/sanguo-server
    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
ファイル: formation.py プロジェクト: wyrover/sanguo-server
    def special_buy(self, socket_id, tp):
        # FIXME
        try:
            this_socket = self.formation.sockets[str(socket_id)]
        except KeyError:
            raise SanguoException(errormsg.FORMATION_NONE_EXIST_SOCKET,
                                  self.char_id, "Formation Special Buy",
                                  "socket {0} not exist".format(socket_id))

        if not this_socket.hero:
            raise SanguoException(errormsg.FORMATION_NO_HERO, self.char_id,
                                  "Formation Special Buy",
                                  "socket {0} no hero".format(socket_id))

        oid = MongoHero.objects.get(id=this_socket.hero).oid

        this_hero = HEROS[oid]
        special_cls = [int(i) for i in this_hero.special_equip_cls.split(',')]

        def _find_speicial_id(equipments):
            for e in equipments:
                if e.step == 0 and e.cls in special_cls:
                    return e.id

            # FIXME
            raise Exception("Special buy, not find. tp = {0}".format(tp))

        from core.item import Item
        item = Item(self.char_id)

        if tp == SpecialEquipmentBuyRequest.SOCKET_WEAPON:
            on_id = _find_speicial_id(ALL_WEAPONS.values())
            new_id = item.equip_add(on_id)
            self.formation.sockets[str(socket_id)].weapon = new_id
        elif tp == SpecialEquipmentBuyRequest.SOCKET_ARMOR:
            on_id = _find_speicial_id(ALL_ARMORS.values())
            new_id = item.equip_add(on_id)
            self.formation.sockets[str(socket_id)].armor = new_id
        else:
            on_id = _find_speicial_id(ALL_JEWELRY.values())
            new_id = item.equip_add(on_id)
            self.formation.sockets[str(socket_id)].jewelry = new_id

        self.formation.save()
        socket_changed_signal.send(
            sender=None, socket_obj=self.formation.sockets[str(socket_id)])

        standard_drop = make_standard_drop_from_template()
        standard_drop['equipments'] = [(new_id, 1, 1)]
        standard_drop['income'] = 1
        standard_drop['func_name'] = "Special Buy"
        standard_drop['des'] = ''
        resource_logger(self.char_id, standard_drop)

        self.send_socket_changed_notify(socket_id,
                                        self.formation.sockets[str(socket_id)])
コード例 #3
0
ファイル: tests.py プロジェクト: hx002/sanguo-server
class EquipmentStepUpTest(TestCase):
    def setUp(self):
        char_initialize(1, 1, 1, 'a')
        self.char_id = 1
        self.session = crypto.encrypt('1:1:{0}'.format(self.char_id))
        self.item = Item(self.char_id)
        self.equip_id = self.item.equip_add(1)

    def tearDown(self):
        app_test_helper._teardown()

    def _step_up(self, _id, ret=0):
        req = protomsg.StepUpEquipRequest()
        req.session = self.session
        req.id = _id
        data = app_test_helper.pack_data(req)
        res = app_test_helper.make_request('/equip/stepup/', data)
        msgs = app_test_helper.unpack_data(res)
        for a, b, c in msgs:
            if a == protomsg.RESPONSE_NOTIFY_TYPE["StepUpEquipResponse"]:
                data = protomsg.StepUpEquipResponse()
                data.ParseFromString(c)
                self.assertEqual(data.ret, ret)

    def test_none_exist(self):
        self._step_up(999, 2)

    # def test_error_step_up(self):
    #     self._step_up(self.equip_id, 16)

    def test_normal_step_up(self):
        item = Item(self.char_id)
        item.stuff_add([(1, 1), (2, 1)])
        self._step_up(self.equip_id)
コード例 #4
0
ファイル: tests.py プロジェクト: zhifuliu/sanguo-server
class EquipmentStepUpTest(TestCase):
    def setUp(self):
        char_initialize(1, 1, 1, 'a')
        self.char_id = 1
        self.session = crypto.encrypt('1:1:{0}'.format(self.char_id))
        self.item = Item(self.char_id)
        self.equip_id = self.item.equip_add(1)

    def tearDown(self):
        app_test_helper._teardown()

    def _step_up(self, _id, ret=0):
        req = protomsg.StepUpEquipRequest()
        req.session = self.session
        req.id = _id
        data = app_test_helper.pack_data(req)
        res = app_test_helper.make_request('/equip/stepup/', data)
        msgs = app_test_helper.unpack_data(res)
        for a, b, c in msgs:
            if a == protomsg.RESPONSE_NOTIFY_TYPE["StepUpEquipResponse"]:
                data = protomsg.StepUpEquipResponse()
                data.ParseFromString(c)
                self.assertEqual(data.ret, ret)

    def test_none_exist(self):
        self._step_up(999, 2)

    # def test_error_step_up(self):
    #     self._step_up(self.equip_id, 16)

    def test_normal_step_up(self):
        item = Item(self.char_id)
        item.stuff_add([(1, 1), (2, 1)])
        self._step_up(self.equip_id)
コード例 #5
0
ファイル: tests.py プロジェクト: hx002/sanguo-server
    def setUp(self):
        char_initialize(1, 1, 1, 'a')
        self.char_id = 1
        self.session = crypto.encrypt('1:1:{0}'.format(self.char_id))

        item = Item(self.char_id)
        eid = item.equip_add(1)
        self.equip_id = eid

        gems = [(1, 10), (2, 1)]
        item.gem_add(gems)
コード例 #6
0
ファイル: tests.py プロジェクト: zhifuliu/sanguo-server
    def setUp(self):
        char_initialize(1, 1, 1, 'a')
        self.char_id = 1
        self.session = crypto.encrypt('1:1:{0}'.format(self.char_id))

        item = Item(self.char_id)
        eid = item.equip_add(1)
        self.equip_id = eid

        gems = [(1, 10), (2, 1)]
        item.gem_add(gems)
コード例 #7
0
ファイル: character.py プロジェクト: hx002/sanguo-server
def char_initialize(account_id, server_id, char_id, name):
    mc = MongoCharacter(id=char_id)
    mc.account_id = account_id
    mc.server_id = server_id
    mc.name = name
    mc.gold = CHARACTER_INIT['gold']
    mc.sycee = CHARACTER_INIT['sycee']
    mc.save()

    from core.item import Item
    item = Item(char_id)
    # save equipment
    for _id, _amount in CHARACTER_INIT['equipment']:
        for _x in range(_amount):
            item.equip_add(_id, notify=False)
    # save gem
    if CHARACTER_INIT['gem']:
        item.gem_add(CHARACTER_INIT['gem'], send_notify=False)
    # save stuff
    if CHARACTER_INIT['stuff']:
        item.stuff_add(CHARACTER_INIT['stuff'], send_notify=False)
    # save hero
    if CHARACTER_INIT['hero']:
        save_hero(char_id, CHARACTER_INIT['hero'], add_notify=False)
    # save souls:
    if CHARACTER_INIT['souls']:
        s = HeroSoul(char_id)
        s.add_soul(CHARACTER_INIT['souls'])

    # hero in formation!
    in_formaiton_heros = CHARACTER_INIT['hero_in_formation']

    final_in_formation_heros = {}
    for k, v in in_formaiton_heros.iteritems():
        new_ids = []
        for _equip_id in v:
            if not _equip_id:
                new_ids.append(0)
            else:
                new_ids.append(item.equip_add(_equip_id, notify=False))

        final_in_formation_heros[k] = new_ids

    hero_ids = save_hero(char_id, final_in_formation_heros.keys(), add_notify=False).id_range
    hero_new_id_to_oid_table = dict(zip(hero_ids, final_in_formation_heros.keys()))

    hero_oid_socket_id_table = {}
    f = Formation(char_id)

    for hid in hero_ids:
        this_oid = hero_new_id_to_oid_table[hid]
        weapon, armor, jewelry = final_in_formation_heros[this_oid]

        _sid = f.initialize_socket(hero=hid, weapon=weapon, armor=armor, jewelry=jewelry)
        hero_oid_socket_id_table[this_oid] = _sid

    socket_ids = FORMATION_INIT_TABLE[:]
    for index, oid in enumerate(socket_ids):
        if oid:
            socket_ids[index] = hero_oid_socket_id_table[oid]

    if FORMATION_INIT_OPENED_SOCKETS > len(hero_ids):
        for i in range(FORMATION_INIT_OPENED_SOCKETS - len(hero_ids)):
            _sid = f.initialize_socket()
            for index, sid in enumerate(socket_ids):
                if sid == 0:
                    socket_ids[index] = _sid
                    break

    f.save_formation(socket_ids, send_notify=False)
コード例 #8
0
def char_initialize(account_id, server_id, char_id, name):
    mc = MongoCharacter(id=char_id)
    mc.account_id = account_id
    mc.server_id = server_id
    mc.name = name
    mc.gold = CHARINIT.gold
    mc.sycee = CHARINIT.sycee
    mc.save()

    from core.item import Item

    init_heros = CHARINIT.decoded_heros

    init_heros_ids = init_heros.keys()

    transformed_init_heros = {}

    item = Item(char_id)
    for k, v in init_heros.iteritems():
        weapon, armor, jewelry = v
        new_ids = []
        if not weapon:
            new_ids.append(0)
        else:
            new_ids.append(item.equip_add(weapon, notify=False))
        if not armor:
            new_ids.append(0)
        else:
            new_ids.append(item.equip_add(armor, notify=False))
        if not jewelry:
            new_ids.append(0)
        else:
            new_ids.append(item.equip_add(jewelry, notify=False))

        transformed_init_heros[k] = new_ids

    init_heros_equips = transformed_init_heros.values()

    hero_ids = save_hero(char_id, init_heros_ids, add_notify=False).id_range

    f = Formation(char_id)

    hero_ids = hero_ids + (4 - len(hero_ids)) * [0]

    socket_ids = []
    for index, _id in enumerate(hero_ids):
        try:
            weapon, armor, jewelry = init_heros_equips[index]
        except IndexError:
            weapon, armor, jewelry = 0, 0, 0
        _sid = f.initialize_socket(hero=_id,
                                   weapon=weapon,
                                   armor=armor,
                                   jewelry=jewelry)
        socket_ids.append(_sid)

    socket_ids = [
        socket_ids[0],
        socket_ids[3],
        0,
        socket_ids[1],
        0,
        0,
        socket_ids[2],
        0,
        0,
    ]

    f.save_formation(socket_ids, send_notify=False)

    if CHARINIT.decoded_gems:
        item.gem_add(CHARINIT.decoded_gems, send_notify=False)
    if CHARINIT.decoded_stuffs:
        item.stuff_add(CHARINIT.decoded_stuffs, send_notify=False)
コード例 #9
0
ファイル: resource.py プロジェクト: yaosj/sanguo-server
    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
コード例 #10
0
ファイル: character.py プロジェクト: hx002/sanguo-server
def char_initialize(account_id, server_id, char_id, name):
    mc = MongoCharacter(id=char_id)
    mc.account_id = account_id
    mc.server_id = server_id
    mc.name = name
    mc.gold = CHARACTER_INIT['gold']
    mc.sycee = CHARACTER_INIT['sycee']
    mc.save()

    from core.item import Item
    item = Item(char_id)
    # save equipment
    for _id, _amount in CHARACTER_INIT['equipment']:
        for _x in range(_amount):
            item.equip_add(_id, notify=False)
    # save gem
    if CHARACTER_INIT['gem']:
        item.gem_add(CHARACTER_INIT['gem'], send_notify=False)
    # save stuff
    if CHARACTER_INIT['stuff']:
        item.stuff_add(CHARACTER_INIT['stuff'], send_notify=False)
    # save hero
    if CHARACTER_INIT['hero']:
        save_hero(char_id, CHARACTER_INIT['hero'], add_notify=False)
    # save souls:
    if CHARACTER_INIT['souls']:
        s = HeroSoul(char_id)
        s.add_soul(CHARACTER_INIT['souls'])

    # hero in formation!
    in_formaiton_heros = CHARACTER_INIT['hero_in_formation']

    final_in_formation_heros = {}
    for k, v in in_formaiton_heros.iteritems():
        new_ids = []
        for _equip_id in v:
            if not _equip_id:
                new_ids.append(0)
            else:
                new_ids.append(item.equip_add(_equip_id, notify=False))

        final_in_formation_heros[k] = new_ids

    hero_ids = save_hero(char_id,
                         final_in_formation_heros.keys(),
                         add_notify=False).id_range
    hero_new_id_to_oid_table = dict(
        zip(hero_ids, final_in_formation_heros.keys()))

    hero_oid_socket_id_table = {}
    f = Formation(char_id)

    for hid in hero_ids:
        this_oid = hero_new_id_to_oid_table[hid]
        weapon, armor, jewelry = final_in_formation_heros[this_oid]

        _sid = f.initialize_socket(hero=hid,
                                   weapon=weapon,
                                   armor=armor,
                                   jewelry=jewelry)
        hero_oid_socket_id_table[this_oid] = _sid

    socket_ids = FORMATION_INIT_TABLE[:]
    for index, oid in enumerate(socket_ids):
        if oid:
            socket_ids[index] = hero_oid_socket_id_table[oid]

    if FORMATION_INIT_OPENED_SOCKETS > len(hero_ids):
        for i in range(FORMATION_INIT_OPENED_SOCKETS - len(hero_ids)):
            _sid = f.initialize_socket()
            for index, sid in enumerate(socket_ids):
                if sid == 0:
                    socket_ids[index] = _sid
                    break

    f.save_formation(socket_ids, send_notify=False)
コード例 #11
0
ファイル: resource.py プロジェクト: wyrover/sanguo-server
    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
コード例 #12
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