Beispiel #1
0
    def make_3_way_clubs(self, _id, _info):
        """

        :rtype: list[core.abstract.AbstractClub]
        """
        clubs = []
        skill_sequences = []

        if is_npc(_id):
            for i in range(1, 4):
                npc_id = _info['ways_npc'][i - 1]
                club = ConfigNPCFormation.get(npc_id)
                club.id = _id
                club.name = _info['name']
                club.flag = _info['flag']

                clubs.append(club)
                skill_sequences.append({})
        else:
            cs = Championship(self.server_id, int(_id))
            for i in range(1, 4):
                way = cs.get_way_object(i)
                club = Club(self.server_id, int(_id), load_staffs=False)
                club.formation_staffs = way.formation_staffs

                clubs.append(club)
                skill_sequences.append(way.get_skill_sequence())

        return clubs, skill_sequences
Beispiel #2
0
    def load_formation_staffs(self):
        # NOTE: 这段代码其实是从 Club.force_load_staffs 抄来的
        from core.formation import Formation
        from core.unit import UnitManager
        from core.talent import TalentManager
        from core.collection import Collection
        from core.party import Party
        from core.inspire import Inspire

        self.formation_staffs = []
        """:type: list[core.staff.Staff]"""

        sm = StaffManger(self.server_id, self.char_id)
        fm = Formation(self.server_id, self.char_id)
        um = UnitManager(self.server_id, self.char_id)
        ins = Inspire(self.server_id, self.char_id)

        staffs = sm.get_staffs_data()
        in_formation_staffs = self.in_formation_staffs()

        for k, v in in_formation_staffs.iteritems():
            obj = Staff(self.server_id, self.char_id, k, staffs[k])
            self.formation_staffs.append(obj)

            obj.policy = in_formation_staffs[k]['policy']
            obj.formation_position = in_formation_staffs[k]['position']
            unit_id = in_formation_staffs[k]['unit_id']
            if unit_id:
                obj.set_unit(um.get_unit_object(unit_id))

        club = Club(self.server_id, self.char_id, load_staffs=False)
        club.formation_staffs = self.formation_staffs

        working_staff_oids = self.working_staff_oids()

        for obj in self.formation_staffs:
            obj.check_qianban(working_staff_oids)
            obj.add_self_talent_effect(club)

        talent_effects_1 = TalentManager(self.server_id,
                                         self.char_id).get_talent_effects()
        talent_effects_2 = Collection(self.server_id,
                                      self.char_id).get_talent_effects()
        talent_effects_3 = fm.get_talent_effects()
        talent_effects_4 = Party(self.server_id,
                                 self.char_id).get_talent_effects()

        club.add_talent_effects(talent_effects_1)
        club.add_talent_effects(talent_effects_2)
        club.add_talent_effects(talent_effects_3)
        club.add_talent_effects(talent_effects_4)

        config_inspire_level_addition, config_inspire_step_addition = ins.get_addition_config(
        )

        for obj in self.formation_staffs:
            obj.config_inspire_level_addition = config_inspire_level_addition
            obj.config_inspire_step_addition = config_inspire_step_addition
            obj.calculate()
Beispiel #3
0
    def make_way_club(self, way_id):
        """

        :rtype: core.abstract.AbstractClub
        """
        way = self.get_way_object(way_id)

        club = Club(self.server_id, self.char_id, load_staffs=False)
        club.formation_staffs = way.formation_staffs
        return club
Beispiel #4
0
    def make_way_club(self, way_id):
        """

        :rtype: core.abstract.AbstractClub
        """
        way = self.get_way_object(way_id)

        club = Club(self.server_id, self.char_id, load_staffs=False)
        club.formation_staffs = way.formation_staffs
        return club
Beispiel #5
0
    def load_formation_staffs(self):
        # NOTE: 这段代码其实是从 Club.force_load_staffs 抄来的
        from core.formation import Formation
        from core.unit import UnitManager
        from core.talent import TalentManager
        from core.collection import Collection
        from core.party import Party
        from core.inspire import Inspire

        self.formation_staffs = []
        """:type: list[core.staff.Staff]"""

        sm = StaffManger(self.server_id, self.char_id)
        fm = Formation(self.server_id, self.char_id)
        um = UnitManager(self.server_id, self.char_id)
        ins = Inspire(self.server_id, self.char_id)

        staffs = sm.get_staffs_data()
        in_formation_staffs = self.in_formation_staffs()

        for k, v in in_formation_staffs.iteritems():
            obj = Staff(self.server_id, self.char_id, k, staffs[k])
            self.formation_staffs.append(obj)

            obj.policy = in_formation_staffs[k]['policy']
            obj.formation_position = in_formation_staffs[k]['position']
            unit_id = in_formation_staffs[k]['unit_id']
            if unit_id:
                obj.set_unit(um.get_unit_object(unit_id))

        club = Club(self.server_id, self.char_id, load_staffs=False)
        club.formation_staffs = self.formation_staffs

        working_staff_oids = self.working_staff_oids()

        for obj in self.formation_staffs:
            obj.check_qianban(working_staff_oids)
            obj.add_self_talent_effect(club)

        talent_effects_1 = TalentManager(self.server_id, self.char_id).get_talent_effects()
        talent_effects_2 = Collection(self.server_id, self.char_id).get_talent_effects()
        talent_effects_3 = fm.get_talent_effects()
        talent_effects_4 = Party(self.server_id, self.char_id).get_talent_effects()

        club.add_talent_effects(talent_effects_1)
        club.add_talent_effects(talent_effects_2)
        club.add_talent_effects(talent_effects_3)
        club.add_talent_effects(talent_effects_4)

        config_inspire_level_addition, config_inspire_step_addition = ins.get_addition_config()

        for obj in self.formation_staffs:
            obj.config_inspire_level_addition = config_inspire_level_addition
            obj.config_inspire_step_addition = config_inspire_step_addition
            obj.calculate()
Beispiel #6
0
    def send_revenge_notify(self):
        notify = PlunderRevengeNotify()
        notify.remained_times = self.get_revenge_remained_times()
        for unique_id, real_id in self.doc['revenge_list']:
            notify_target = notify.target.add()
            notify_target.id = unique_id

            club = Club(self.server_id, real_id, load_staffs=False)
            target_plunder = Plunder(self.server_id, real_id)
            notify_target.name = club.name

            for way_id in [1, 2, 3]:
                way_object = target_plunder.get_way_object(way_id)
                club.formation_staffs = way_object.formation_staffs
                skill_sequence = way_object.get_skill_sequence()

                _club_match = ClubMatch(None, None, 3, None, None)

                notify_target_troop = notify_target.troop.add()
                notify_target_troop.MergeFrom(_club_match.make_club_troop_msg(club, skill_sequence))

        MessagePipe(self.char_id).put(msg=notify)
Beispiel #7
0
    def send_revenge_notify(self):
        notify = PlunderRevengeNotify()
        notify.remained_times = self.get_revenge_remained_times()
        for unique_id, real_id in self.doc['revenge_list']:
            notify_target = notify.target.add()
            notify_target.id = unique_id

            club = Club(self.server_id, real_id, load_staffs=False)
            target_plunder = Plunder(self.server_id, real_id)
            notify_target.name = club.name

            for way_id in [1, 2, 3]:
                way_object = target_plunder.get_way_object(way_id)
                club.formation_staffs = way_object.formation_staffs
                skill_sequence = way_object.get_skill_sequence()

                _club_match = ClubMatch(None, None, 3, None, None)

                notify_target_troop = notify_target.troop.add()
                notify_target_troop.MergeFrom(
                    _club_match.make_club_troop_msg(club, skill_sequence))

        MessagePipe(self.char_id).put(msg=notify)
Beispiel #8
0
    def plunder_start(self, _id, tp, formation_slots=None, win=None):
        if tp not in [PLUNDER_TYPE_PLUNDER, PLUNDER_TYPE_REVENGE]:
            raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE"))

        for i in [0, 1, 2]:
            if self.doc['matching']['result'][i] == 0:
                way = i + 1
                break
        else:
            # 都打完了
            raise GameException(
                ConfigErrorMessage.get_error_id("PLUNDER_MATCH_ALL_FINISHED"))

        target_id = self.doc['matching']['id']
        if not target_id:
            if tp == PLUNDER_TYPE_PLUNDER:
                _index = self.find_search_target_index_by_target_id(_id)
                target_id = self.doc['search'][_index]['id']
            else:
                _index = self.find_revenge_target_index_by_target_id(_id)
                target_id = self.doc['revenge_list'][_index][0]
        else:
            # 要保证target_id 一样
            if str(target_id) != _id:
                raise GameException(
                    ConfigErrorMessage.get_error_id(
                        "PLUNDER_TARGET_ID_NOT_SAME"))

        updater = {}
        if not self.doc['matching']['id']:
            self.doc['matching']['id'] = target_id
            self.doc['matching']['tp'] = tp
            updater['matching.id'] = target_id
            updater['matching.tp'] = tp

        if way == 1:
            # 开始的第一路,这时候要判断次数
            if tp == PLUNDER_TYPE_PLUNDER:
                if not self.doc['plunder_remained_times']:
                    self.buy_plunder_times()

                PlunderMatchCD(self.server_id, self.char_id, target_id).set(
                    GlobalConfig.value("PLUNDER_MATCH_CD"))

            else:
                if not self.get_revenge_remained_times():
                    raise GameException(
                        ConfigErrorMessage.get_error_id(
                            "PLUNDER_REVENGE_NO_TIMES"))

                self.send_revenge_notify()

        if updater:
            MongoPlunder.db(self.server_id).update_one({'_id': self.char_id},
                                                       {'$set': updater})

        if win is not None:
            self.plunder_report(way, win)
            return None

        my_way = self.get_way_object(way)
        if formation_slots:
            my_way.sync_slots(formation_slots)
            my_way.load_formation_staffs()
            self.send_formation_notify()

        my_club = Club(self.server_id, self.char_id, load_staffs=False)
        my_club.formation_staffs = my_way.formation_staffs

        match = ClubMatch(my_club, None, 3, my_way.get_skill_sequence(), {})
        msg = match.start(auto_load_staffs=False)
        msg.key = str(way)
        msg.map_name = GlobalConfig.value_string("MATCH_MAP_PLUNDER")

        return msg
Beispiel #9
0
    def plunder_start(self, _id, tp, formation_slots=None, win=None):
        if tp not in [PLUNDER_TYPE_PLUNDER, PLUNDER_TYPE_REVENGE]:
            raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE"))

        for i in [0, 1, 2]:
            if self.doc['matching']['result'][i] == 0:
                way = i + 1
                break
        else:
            # 都打完了
            raise GameException(ConfigErrorMessage.get_error_id("PLUNDER_MATCH_ALL_FINISHED"))

        target_id = self.doc['matching']['id']
        if not target_id:
            if tp == PLUNDER_TYPE_PLUNDER:
                _index = self.find_search_target_index_by_target_id(_id)
                target_id = self.doc['search'][_index]['id']
            else:
                _index = self.find_revenge_target_index_by_target_id(_id)
                target_id = self.doc['revenge_list'][_index][0]
        else:
            # 要保证target_id 一样
            if str(target_id) != _id:
                raise GameException(ConfigErrorMessage.get_error_id("PLUNDER_TARGET_ID_NOT_SAME"))

        updater = {}
        if not self.doc['matching']['id']:
            self.doc['matching']['id'] = target_id
            self.doc['matching']['tp'] = tp
            updater['matching.id'] = target_id
            updater['matching.tp'] = tp

        if way == 1:
            # 开始的第一路,这时候要判断次数
            if tp == PLUNDER_TYPE_PLUNDER:
                if not self.doc['plunder_remained_times']:
                    self.buy_plunder_times()

                PlunderMatchCD(self.server_id, self.char_id, target_id).set(GlobalConfig.value("PLUNDER_MATCH_CD"))

            else:
                if not self.get_revenge_remained_times():
                    raise GameException(ConfigErrorMessage.get_error_id("PLUNDER_REVENGE_NO_TIMES"))

                self.send_revenge_notify()

        if updater:
            MongoPlunder.db(self.server_id).update_one(
                {'_id': self.char_id},
                {'$set': updater}
            )

        if win is not None:
            self.plunder_report(way, win)
            return None

        my_way = self.get_way_object(way)
        if formation_slots:
            my_way.sync_slots(formation_slots)
            my_way.load_formation_staffs()
            self.send_formation_notify()

        my_club = Club(self.server_id, self.char_id, load_staffs=False)
        my_club.formation_staffs = my_way.formation_staffs

        match = ClubMatch(my_club, None, 3, my_way.get_skill_sequence(), {})
        msg = match.start(auto_load_staffs=False)
        msg.key = str(way)
        msg.map_name = GlobalConfig.value_string("MATCH_MAP_PLUNDER")

        return msg