Beispiel #1
0
    def start(self, dungeon_id, formation_slots=None):
        grade_conf = ConfigDungeonGrade.get(dungeon_id)
        if not grade_conf:
            raise GameException(
                ConfigErrorMessage.get_error_id("DUNGEON_NOT_EXIST"))

        map_name = ConfigDungeon.get(grade_conf.belong).map_name

        club_level = get_club_property(self.server_id, self.char_id, 'level')
        if grade_conf.need_level > club_level:
            raise GameException(
                ConfigErrorMessage.get_error_id(
                    "DUNGEON_CLUB_LEVEL_NOT_ENOUGH"))

        f = Formation(self.server_id, self.char_id)
        if formation_slots:
            f.sync_slots(formation_slots)

        Energy(self.server_id,
               self.char_id).check(ConfigDungeon.get(grade_conf.belong).cost)

        ri = TimesInfo(self.server_id, self.char_id, grade_conf.belong)
        if not ri.remained_match_times:
            # 购买
            self.buy_times(grade_conf.belong)

        club_one = Club(self.server_id, self.char_id)
        club_two = ConfigNPCFormation.get(grade_conf.npc)
        msg = ClubMatch(club_one, club_two, 6, f.get_skill_sequence(),
                        {}).start()
        msg.key = str(dungeon_id)
        msg.map_name = map_name
        return msg
Beispiel #2
0
    def check_exist(self, server_id, char_id):
        from core.club import Club
        from core.bag import Bag
        from core.staff import StaffManger, StaffRecruit
        from core.territory import Territory
        from core.arena import Arena
        from core.energy import Energy

        money_text = self.money_as_text_dict()
        if money_text:
            Club(server_id, char_id).check_money(**money_text)
        if self.bag:
            Bag(server_id, char_id).check_items(self.bag)
        if self.staff:
            StaffManger(server_id,
                        char_id).check_original_staff_is_initial_state(
                            self.staff)
        if self.territory_product:
            Territory(server_id, char_id).check_product(self.territory_product)
        if self.work_card:
            Territory(server_id, char_id).check_work_card(self.work_card)
        if self.arena_point:
            Arena(server_id, char_id).check_point(self.arena_point)
        if self.energy:
            Energy(server_id, char_id).check(self.energy)
        if self.staff_recruit_score:
            StaffRecruit(server_id,
                         char_id).check_score(self.staff_recruit_score)
        if self.resource_data:
            _r = _Resource()
            _r.resource = dict(self.resource_data)
            _r.check_exists(server_id, char_id)
Beispiel #3
0
    def job_of_energy_notification(cls):
        # 找最近登陆的,并且在多少时间内没操作的(认为已经下线了
        connection.close()

        account_ids = AccountLoginLog.get_recent_login_account_ids(2)
        action_limit = arrow.utcnow().timestamp - 60 * 30

        count = 0
        for account_id, server_id in account_ids.iteritems():
            try:
                model_char = ModelCharacter.objects.get(
                    Q(account_id=account_id) & Q(server_id=server_id))
            except ModelCharacter.DoesNotExist:
                continue

            char_id = model_char.id

            if OperationLog.get_char_last_action_at(server_id,
                                                    char_id) > action_limit:
                continue

            if not Energy(server_id, char_id).is_full():
                continue

            title = u"体力满了"
            content = u"您在 {0} 服的角色 {1} 体力满了,赶快上线吧".format(
                server_id, model_char.name)

            pushed = GeTui(account_id).push_of_energy(title, content)
            if pushed:
                count += 1

        return count
Beispiel #4
0
    def add(self, server_id, char_id, message=""):
        from core.club import Club
        from core.bag import Bag
        from core.staff import StaffManger, StaffRecruit
        from core.talent import TalentManager
        from core.territory import Territory
        from core.vip import VIP
        from core.arena import Arena
        from core.energy import Energy
        from core.plunder import Plunder

        club_property = self.money_as_text_dict()
        if self.club_exp:
            club_property['exp'] = self.club_exp
        if club_property:
            club_property['message'] = message
            Club(server_id, char_id).update(**club_property)

        if self.vip_exp:
            VIP(server_id, char_id).add_exp(self.vip_exp)

        if self.bag:
            bag = Bag(server_id, char_id)
            bag.batch_add(self.bag)

        sm = StaffManger(server_id, char_id)
        if self.staff:
            sm.batch_add(self.staff)

        if self.staff_exp_pool:
            sm.add_exp_pool(self.staff_exp_pool)

        if self.talent_point:
            TalentManager(server_id,
                          char_id).add_talent_points(self.talent_point)

        if self.arena_point:
            Arena(server_id, char_id).add_point(self.arena_point)

        if self.territory_product:
            Territory(server_id, char_id).add_product(self.territory_product)

        if self.work_card:
            Territory(server_id, char_id).add_work_card(self.work_card)

        if self.energy:
            Energy(server_id, char_id).add(self.energy)

        if self.staff_recruit_score:
            StaffRecruit(server_id,
                         char_id).add_score(self.staff_recruit_score)

        if self.station_exp:
            Plunder(server_id, char_id).add_station_exp(self.station_exp)

        if self.resource_data:
            _r = _Resource()
            _r.resource = dict(self.resource_data)
            _r.add(server_id, char_id)
Beispiel #5
0
def buy(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    Energy(server_id, char_id).buy()

    response = EnergyBuyResponse()
    response.ret = 0
    return ProtobufResponse(response)
Beispiel #6
0
def club_level_up_handler(server_id, char_id, new_level, **kwargs):
    TaskDaily(server_id, char_id).try_open()

    energy_add = ConfigClubLevel.get(new_level - 1).energy
    Energy(server_id, char_id).add(energy_add)

    UnitManager(server_id, char_id).try_unlock()
    Welfare(server_id, char_id).send_level_reward_notify()
    Championship(server_id, char_id).try_initialize()
    ActivityLevelGrowing(server_id, char_id).record(new_level)
Beispiel #7
0
    def remove(self, server_id, char_id, message=""):
        from core.club import Club
        from core.bag import Bag
        from core.staff import StaffManger, StaffRecruit
        from core.territory import Territory
        from core.arena import Arena
        from core.energy import Energy

        money_text = self.money_as_text_dict()
        if money_text:
            money_text = {k: -v for k, v in money_text.iteritems()}
            money_text['message'] = message
            Club(server_id, char_id).update(**money_text)

        if self.bag:
            bag = Bag(server_id, char_id)
            for _id, _amount in self.bag:
                bag.remove_by_item_id(_id, _amount)

        if self.staff:
            StaffManger(server_id, char_id).internal_remove_by_oid(self.staff)

        if self.territory_product:
            Territory(server_id,
                      char_id).remove_product(self.territory_product)

        if self.work_card:
            Territory(server_id, char_id).remove_work_card(self.work_card)

        if self.arena_point:
            Arena(server_id, char_id).remove_point(self.arena_point)

        if self.energy:
            Energy(server_id, char_id).remove(self.energy)

        if self.staff_recruit_score:
            StaffRecruit(server_id,
                         char_id).remove_score(self.staff_recruit_score)

        if self.resource_data:
            _r = _Resource()
            _r.resource = dict(self.resource_data)
            _r.remove(server_id, char_id)
Beispiel #8
0
    def report(self, key, star):
        grade_id = int(key)
        conf = ConfigDungeonGrade.get(grade_id)
        if star > 0:
            Energy(self.server_id,
                   self.char_id).remove(ConfigDungeon.get(conf.belong).cost)
            ValueLogDungeonMatchTimes(self.server_id,
                                      self.char_id).record(sub_id=conf.belong,
                                                           value=1)

            resource_classified = ResourceClassification.classify(
                conf.get_drop())
            resource_classified.add(
                self.server_id,
                self.char_id,
                message="Dungeon.report:{0}".format(grade_id))
            ret = resource_classified
        else:
            ret = None

        self.send_notify(conf.belong)
        return ret
Beispiel #9
0
def game_start_handler(server_id, char_id, **kwargs):
    MessagePipe(char_id).clean()

    msg = UTCNotify()
    msg.timestamp = arrow.utcnow().timestamp
    MessagePipe(char_id).put(msg=msg)

    msg = SocketServerNotify()
    ss = random.choice(settings.SOCKET_SERVERS)
    msg.ip = ss['host']
    msg.port = ss['tcp']
    MessagePipe(char_id).put(msg=msg)

    _Resource.send_notify(server_id, char_id)

    UnitManager(server_id, char_id).send_notify()

    Bag(server_id, char_id).send_notify()

    StaffManger(server_id, char_id).send_notify()
    StaffRecruit(server_id, char_id).send_notify()

    f = Formation(server_id, char_id)
    f.send_formation_notify()
    f.send_slot_notify()

    club = Club(server_id, char_id)
    club.set_login()
    club.send_notify()

    msg = CreateDaysNotify()
    msg.days = days_passed(club.create_at)
    msg.create_at = club.create_at
    MessagePipe(char_id).put(msg=msg)

    chall = Challenge(server_id, char_id)
    chall.send_chapter_notify()
    chall.send_challenge_notify()

    FriendManager(server_id, char_id).send_notify()
    MailManager(server_id, char_id).send_notify()

    TaskMain(server_id, char_id).send_notify()
    TaskDaily(server_id, char_id).send_notify()

    Chat(server_id, char_id).send_notify()

    Notification(server_id, char_id).send_notify()

    FinanceStatistics(server_id, char_id).send_notify()

    TalentManager(server_id, char_id).send_notify()

    Dungeon(server_id, char_id).send_notify()

    a = Arena(server_id, char_id)
    a.send_notify()
    a.send_honor_notify()

    t = Tower(server_id, char_id)
    t.send_notify()
    t.send_goods_notify()

    Territory(server_id, char_id).send_notify()
    TerritoryStore(server_id, char_id).send_notify()
    TerritoryFriend(server_id, char_id).send_remained_times_notify()

    Store(server_id, char_id).send_notify()
    VIP(server_id, char_id).send_notify()
    Collection(server_id, char_id).send_notify()

    Energy(server_id, char_id).send_notify()

    w = Welfare(server_id, char_id)
    w.send_signin_notify()
    w.send_new_player_notify()
    w.send_level_reward_notify()
    w.send_energy_reward_notify()

    Union(server_id, char_id).send_all_notify()

    Purchase(server_id, char_id).send_notify()

    ac = ActivityNewPlayer(server_id, char_id)
    ac.send_notify()
    ac.send_daily_buy_notify()

    ActivityOnlineTime(server_id, char_id).send_notify()
    ActivityChallenge(server_id, char_id).send_notify()
    ActivityPurchaseDaily(server_id, char_id).send_notify()
    ActivityPurchaseContinues(server_id, char_id).send_notify()
    ActivityLevelGrowing(server_id, char_id).send_notify()

    p = Plunder(server_id, char_id)

    p.send_search_notify()
    p.send_result_notify()
    p.send_revenge_notify()
    p.send_station_notify()
    p.send_formation_notify()
    p.send_plunder_times_notify()
    p.send_plunder_daily_reward_notify()

    SpecialEquipmentGenerator(server_id, char_id).send_notify()

    Party(server_id, char_id).send_notify()

    ins = Inspire(server_id, char_id)
    ins.try_open_slots(send_notify=False)
    ins.send_notify()

    cs = Championship(server_id, char_id)
    cs.try_initialize(send_notify=False)
    cs.send_notify()

    WinningPlunder(server_id, char_id).send_notify()
    WinningArena(server_id, char_id).send_notify()
    WinningChampionship(server_id, char_id).send_notify()
    Worship(server_id, char_id).send_notify()
    CommonArenaWinningChat(server_id, char_id).send_notify()
    CommonPlunderWinningChat(server_id, char_id).send_notify()
    CommonChampionshipChat(server_id, char_id).send_notify()

    send_system_notify(server_id, char_id)
    BroadCast(server_id, char_id).try_cast_login_notify()
Beispiel #10
0
    def sweep(self, challenge_id, tp):
        # 扫荡
        config = ConfigChallengeMatch.get(challenge_id)
        if not config:
            raise GameException(ConfigErrorMessage.get_error_id("CHALLENGE_NOT_EXIST"))

        doc = MongoChallenge.db(self.server_id).find_one(
            {'_id': self.char_id},
            {
                'challenge_star.{0}'.format(challenge_id): 1,
                'challenge_drop.{0}'.format(challenge_id): 1,
            }
        )

        star = doc['challenge_star'].get(str(challenge_id), None)
        if star is None:
            raise GameException(ConfigErrorMessage.get_error_id("CHALLENGE_NOT_OPEN"))
        if star != 3:
            raise GameException(ConfigErrorMessage.get_error_id("CHALLENGE_NOT_3_STAR"))

        if tp == CHALLENGE_SWEEP_TYPE_ONE:
            sweep_times = 1
        else:
            sweep_times = 10
            need_vip_level = GlobalConfig.value("CHALLENGE_SWEEP_10_VIP_LEVEL")
            VIP(self.server_id, self.char_id).check(need_vip_level)

        rt = RemainedTimes(self.server_id, self.char_id, challenge_id)
        if not rt.remained_match_times:
            raise GameException(ConfigErrorMessage.get_error_id("CHALLENGE_WITHOUT_TIMES"))

        # 剩余次数限制
        if rt.remained_match_times < sweep_times:
            sweep_times = rt.remained_match_times

        # 体力限制
        en = Energy(self.server_id, self.char_id)
        # NOTE 要保证至少可以打一次!
        en.check(config.energy)

        current_energy_can_sweep_times = en.energy / config.energy
        if sweep_times > current_energy_can_sweep_times:
            sweep_times = current_energy_can_sweep_times

        en.remove(sweep_times * config.energy)

        drop_times = doc['challenge_drop'].get(str(challenge_id), {})
        drops = {}
        resource_classified_list = []
        for i in range(sweep_times):
            _drop = config.get_drop(drop_times)
            for _id, _amount in _drop:
                if _id in drops:
                    drops[_id] += _amount
                else:
                    drops[_id] = _amount

            resource_classified_list.append(ResourceClassification.classify(_drop))

        MongoChallenge.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': {
                'challenge_drop.{0}'.format(challenge_id): drop_times
            }}
        )

        ValueLogChallengeMatchTimes(self.server_id, self.char_id).record(sub_id=challenge_id, value=sweep_times)
        ValueLogAllChallengeWinTimes(self.server_id, self.char_id).record(value=sweep_times)

        resource_classified = ResourceClassification.classify(drops.items())
        resource_classified.add(self.server_id, self.char_id, message="Challenge.sweep:{0}".format(challenge_id))

        self.send_challenge_notify(ids=[challenge_id])
        return resource_classified_list