Exemplo n.º 1
0
 def load_faction(self):
     from faction.model import Faction
     from faction.model import FactionRankRanking
     from faction.manager import update_strengthen_level
     # now = int(time.time())
     if self.factionID:
         faction = Faction.simple_load(
             self.factionID, [
                 'leaderID', 'name',
                 'strengthen_at_level',
                 'strengthen_hp_level',
                 'strengthen_ct_level'
             ])
         if faction:
             if self.entityID == faction.leaderID:
                 applyset = Faction.simple_load(
                     self.factionID, ['applyset']).applyset
                 self.applyMemberSet = applyset
             self.faction_name = faction.name
             level = self.faction_level = FactionRankRanking.get_score(
                 self.factionID) or 1
             from task.manager import on_faction_level
             on_faction_level(self, level)
             update_strengthen_level(self, self.factionID)
     # if self.applyFactionTime and self.applyFactionTime < now:
     #     self.applyFactionTime = 0
     #     self.applyFactionID = 0
     return
Exemplo n.º 2
0
def join_faction(entityID, factionID):
    faction = Faction.simple_load(factionID, [
        "level", "name", "memberset", "inviteset", "applyset",
        "strengthen_hp_level", "strengthen_at_level", "strengthen_ct_level",
        "strengthen_df_level"
    ])
    # recommend
    level = FactionRankRanking.get_score(factionID) or 1
    limit = get_config(FactionLimitConfig)[level].limit
    if limit - len(faction.memberset) <= 1:
        unrecommend(factionID)
    clean_faction(entityID)
    p = g_entityManager.get_player(entityID)
    if not p:
        p = Player.simple_load(entityID, [
            'inviteFactionSet',
            'factionID',
            'last_factionID',
            'strengthen_at_level',
            'strengthen_hp_level',
            'strengthen_ct_level',
            'strengthen_df_level',
        ])
    p.factionID = faction.factionID
    p.faction_name = faction.name
    p.faction_level = level
    now = int(time.time())
    p.joinFactionTime = now
    # FIXME
    for fid in p.inviteFactionSet:
        f = Faction.simple_load(fid, ['inviteset'])
        safe_remove(f.inviteset, p.entityID)
        f.save()
    p.inviteFactionSet.clear()
    if p.factionID != p.last_factionID:
        p.totalfp = 0
        p.todayfp_donate = 0
        p.todayfp_task = 0
        p.todayfp_sp = 0
    faction.memberset.add(p.entityID)
    safe_remove(faction.applyset, p.entityID)
    safe_remove(faction.inviteset, p.entityID)
    if g_entityManager.get_player(entityID):
        p.load_faction()
        p.sync()
    p.save()
    faction.save()
    gm_logger.info({
        'faction': {
            'entityID': p.entityID,
            'type': 'join_faction',
            'factionID': faction.factionID,
        }
    })
Exemplo n.º 3
0
 def faction_invite_infos(self, msgtype, body):
     factionID = self.player.factionID
     if not factionID:
         return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_HAS_NOT_FACTION)
     faction = Faction.simple_load(factionID, ['leaderID', 'inviteset'])
     if self.player.entityID != faction.leaderID:
         return fail_msg(msgtype,
                         msgTips.FAIL_MSG_FACTION_PERMISSION_DENIED)
     memberIDs = faction.inviteset
     thumbs = g_entityManager.get_players_info(memberIDs, [
         'entityID',
         'name',
         'career',
         'prototypeID',
         'totalfp',
         'level',
         'todayfp',
         'lastlogin',
     ])
     rsp = poem_pb.MemberInfos()
     now = int(time.time())
     for thumb in thumbs:
         last = int(time.mktime(thumb['lastlogin'].timetuple()))
         thumb['time'] = now - last
         # rs = get_lineup_details_atk(thumb['entityID'])
         detail = get_opponent_detail(thumb["entityID"])
         thumb.update(detail)
         rsp.members.add(**thumb)
     return success_msg(msgtype, rsp)
Exemplo n.º 4
0
 def faction_member_infos(self, msgtype, body):
     factionID = self.player.factionID
     if not factionID:
         return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_HAS_NOT_FACTION)
     faction = Faction.simple_load(factionID, ['memberset'])
     thumbs = g_entityManager.get_players_info(list(faction.memberset), [
         'entityID',
         'name',
         'career',
         'prototypeID',
         'totalfp',
         'level',
         'todayfp',
         'lastlogin',
         'joinFactionTime',
     ])
     rsp = poem_pb.MemberInfos()
     now = int(time.time())
     DAY = 86400
     for thumb in thumbs:
         last = int(time.mktime(thumb['lastlogin'].timetuple()))
         thumb['time'] = now - last
         if thumb['time'] >= DAY:
             thumb['todayfp'] = 0
         thumb['jointime'] = now - thumb['joinFactionTime']
         detail = get_opponent_detail(thumb["entityID"])
         detail['beMyFriend'] = thumb["entityID"] in self.player.friendset
         detail['applied'] = thumb["entityID"] in self.player.friend_applys
         thumb.update(detail)
     update_onlines(thumbs)
     rsp.members = thumbs
     return success_msg(msgtype, rsp)
Exemplo n.º 5
0
 def friend_invite_list(self, msgtype, body):
     p = self.player
     if not p.factionID:
         return success_msg(msgtype, "")
     req = poem_pb.InviteFriendList()
     req.ParseFromString(body)
     logger.debug(req)
     try:
         ownerID, fbID = simple_load_friendfb(req.friendfbID, 'ownerID',
                                              'fbID')
     except DoesNotExistsException:
         return fail_msg(msgtype,
                         msgTips.FAIL_MSG_FRIENDFB_ALREADY_DISAPPEARED)
     if p.entityID != ownerID:
         return fail_msg(msgtype, msgTips.FAIL_MSG_INVALID_REQUEST)
     invitees = load_friendfb_invitees(req.friendfbID)
     # invitees 起码会有发现者
     assert invitees, "impossible"
     fields = ['entityID', 'name', 'prototypeID', 'level', "borderID"]
     #  过滤已经邀请的好友(2016-02-18 改会公会成员)
     f = Faction.simple_load(p.factionID, ["memberset"])
     rs = Player.batch_load(list(set(f.memberset) - invitees), fields)
     rsp = poem_pb.InviteFriendListResponse()
     config = get_config(FriendfbConfig)[fbID]
     for each in rs:
         info = {}
         if each.level < config.openlv:
             continue
         for f in fields:
             info[f] = getattr(each, f)
         info['id'] = info['entityID']
         rsp.friends.add(**info)
     return success_msg(msgtype, rsp)
Exemplo n.º 6
0
 def city_treasure_recv(self, msgtype, body):
     if g_campaignManager.city_dungeon_campaign.is_open():
         return fail_msg(msgtype, reason="活动开启中")
     if g_campaignManager.city_contend_campaign.is_open():
         return fail_msg(msgtype, reason="活动开启中")
     p = self.player
     info = g_cityDungeon.get_top_info()
     top_factionID = info.get("top_factionID", 0)
     if not top_factionID:
         return fail_msg(msgtype, reason="还没有公会获得宝藏")
     if p.factionID != top_factionID:
         return fail_msg(msgtype, reason="您不属于这个公会")
     if p.city_treasure_recv_flag:
         return fail_msg(msgtype, reason="今天已经领取过了")
     f = Faction.simple_load(p.factionID, ["faction_treasure"])
     if not f.faction_treasure:
         return fail_msg(msgtype, reason="还没有公会获得宝藏")
     current = None
     configs = get_config(CityTreasureRecvConfig)
     for config in configs.values():
         if f.faction_treasure >= config.treasure_count:
             current = config
         else:
             break
     if not current:
         return fail_msg(msgtype, reason="没有奖励可以领取")
     result = apply_reward(p,
                           parse_reward(current.rewards),
                           type=RewardType.CityTreasure)
     rsp = poem_pb.CityTreasureRecv()
     build_reward_msg(rsp, result)
     p.city_treasure_recv_flag = True
     p.save()
     p.sync()
     return success_msg(msgtype, rsp)
Exemplo n.º 7
0
 def faction_info(self, msgtype, body):
     p = self.player
     factionID = p.factionID
     if not factionID:
         return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_HAS_NOT_FACTION)
     info = get_faction_info(p.factionID)
     if not info:
         p.factionID = 0
         p.save()
         p.sync()
         return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_HAS_NOT_FACTION)
     if info['dflag']:
         if info['leaderID'] == p.entityID:
             # 检查解散公会
             if p.dismissCD:
                 if p.dismissCD < int(time.time()):
                     faction = Faction.simple_load(factionID, ['name'])
                     faction.delete()
                     FactionnameIndexing.unregister(faction.name)
                     FactionRankRanking.del_key(factionID)
                     clean_faction(p.entityID)
                     p.dismissCD = 0
                     p.save()
                     p.sync()
                     return fail_msg(
                         msgtype,
                         msgTips.FAIL_MSG_FACTION_ALREADY_DISMISSED)
     if not info:
         return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_NOT_THIS_FACTION)
     rsp = poem_pb.FactionInfo(**info)
     return success_msg(msgtype, rsp)
Exemplo n.º 8
0
def clean_faction(entityID):
    p = g_entityManager.get_player(entityID)
    if not p:
        p = Player.simple_load(entityID, ['factionID', 'applyFactions'])
    if p.factionID:
        faction = Faction.simple_load(p.factionID, ['memberset'])
        if faction:
            safe_remove(faction.memberset, p.entityID)
            faction.save()
        p.last_factionID = p.factionID
        gm_logger.info({
            'faction': {
                'entityID': p.entityID,
                'type': 'quit_faction',
                'factionID': p.factionID,
            }
        })
    p.factionID = 0
    p.fp = 0
    p.faction_name = ''
    p.faction_level = 0
    p.faction_is_leader = False
    p.applyFactions.clear()
    # p.applyFactionTime = 0
    p.save()
    if g_entityManager.get_player(entityID):
        p.sync()
Exemplo n.º 9
0
Arquivo: city.py Projeto: kimch2/x8623
 def get_panel(self, p, rsp):
     if self.is_top_faction(p.factionID):  # 防守方
         rsp.self_rank = CityContendDefendRanking.get_rank(p.entityID)
         if not rsp.self_rank:
             CityContendDefendRanking.update_score(p.entityID, 0)
         rsp.self_ranking = self.get_player_ranking(
             CityContendDefendRanking)
         if not p.city_contend_treasure:
             configs = get_config(CityTreasureConfig)
             config = configs.get(p.level)
             if not config:
                 config = configs[max(configs)]
             p.city_contend_treasure = config.defend_treasure
             p.save()
             p.sync()
     else:  # 攻击方
         rsp.self_rank = CityContendAttackRanking.get_rank(p.entityID)
         if not rsp.self_rank:
             CityContendAttackRanking.update_score(p.entityID, 0)
         rsp.faction_rank = CityContendFactionRanking.get_rank(p.factionID)
         if not rsp.faction_rank:
             CityContendFactionRanking.update_score(p.factionID, 0)
         rsp.self_ranking = self.get_player_ranking(
             CityContendAttackRanking)
         rsp.faction_ranking = self.get_faction_ranking(
             CityContendFactionRanking)
     rsp.reds = list(g_redManager.get_red_messages(
         module=RedModuleType.CityContendDefend)) + list(
             g_redManager.get_red_messages(
                 module=RedModuleType.CityContendAttack))
     rsp.events = self.get_events(p)
     rsp.rewards = build_reward(parse_reward(p.city_contend_rewards))
     f = Faction.simple_load(p.factionID, ["faction_treasure"])
     rsp.faction_treasure = f.faction_treasure
Exemplo n.º 10
0
Arquivo: city.py Projeto: kimch2/x8623
 def incr_mg_kill(self, p, mg_id, incr=1):
     p.city_dungeon_kill_count += incr
     CityDungeonKillRanking.incr_score(p.factionID, incr)
     kill_key = self.get_mg_kill_key(p.factionID)
     entity_pool.execute("HINCRBY", kill_key, mg_id, incr)
     f = Faction.simple_load(p.factionID, ['city_top_member_kills'])
     if p.city_dungeon_kill_count > f.city_top_member_kills:
         dd = {
             "name": p.name,
             "prototypeID": p.prototypeID,
             "borderID": p.borderID,
         }
         lineup = p.lineups.get(LineupType.City, [])
         if not lineup:
             lineup = p.lineups.get(LineupType.ATK, [])
         if lineup:
             petID = filter(lambda s: s, lineup)[0]
             pet = p.pets.get(petID)
             if pet:
                 dd.update({
                     "petID": pet.prototypeID,
                     "pet_step": pet.breaklevel,
                 })
         f.city_top_member = dd
         f.city_top_member_kills = p.city_dungeon_kill_count
         f.save()
     p.save()
     p.sync()
Exemplo n.º 11
0
 def dlc_helper_list(self, msgtype, body):
     p = self.player
     req = poem_pb.DlcHelperListRequest()
     req.ParseFromString(body)
     now = int(time.time())
     if req.social == 1:  # friend
         helpers = list(p.friendset)
     else:
         if not p.factionID:
             helpers = []
         else:
             f = Faction.simple_load(p.factionID, ["memberset"])
             helpers = list(f.memberset)
             try:
                 helpers.remove(p.entityID)
             except ValueError:
                 pass
         if req.social == 3:  # both
             helpers += list(p.friendset)
             helpers = list(set(helpers))
     rsp = poem_pb.DlcHelperList()
     details = []
     for helper in helpers:
         detail = get_opponent_detail(helper)
         last = int(time.mktime(
             detail['lastlogin'].timetuple()
         ))
         detail['time'] = now - last
         detail["dlc_cd"] = get_helper_cd(p, helper, now=now)
         details.append(detail)
     update_onlines(details)
     rsp.helpers = details
     return success_msg(msgtype, rsp)
Exemplo n.º 12
0
def sync_apply(entityID):
    player = g_entityManager.get_player(entityID)
    if player:
        faction = Faction.simple_load(player.factionID,
                                      ['applyset', 'leaderID'])
        player.applyMemberSet = faction.applyset
        player.sync()
    return SUCCESS
Exemplo n.º 13
0
 def give_reward(self, date=None):
     if not date:
         now = int(time.time())
         tm = date = datedate.fromtimestamp(now).strftime("%Y-%m-%d")
     else:
         tm = date
     ranking = get_ranking_backup(self.type)
     key = ranking.key
     ll = get_config(RankingCampaignRewardByGroupConfig).get(
         self.config.group, [])
     configs = get_config(RankingCampaignRewardConfig)
     configs = [configs[i.id] for i in ll]
     key = "%s{%s}" % (key, tm)
     limit = get_ranking_limit(self.type)
     if limit is not None:
         rankers = ranking.get_range_by_score(limit,
                                              "+inf",
                                              withscores=True)
     else:
         rankers = ranking.get_range_by_score("-inf",
                                              "+inf",
                                              withscores=True)
     rankers = convert_list_to_dict(rankers, dictcls=OrderedDict).items()
     for rank, (entityID, score) in enumerate(rankers, 1):
         config = None
         for c in configs:
             start, end = c.range
             if start:
                 if start > rank:
                     continue
             if end:
                 if end < rank:
                     continue
             config = c
         if not config:
             continue
         title, content, ID = get_mail("RankingReward")
         content = content.format(self.config.day, self.config.title, rank)
         if self.type in get_faction_types():
             f = Faction.simple_load(entityID, ["leaderID", "memberset"])
             for i in set(f.memberset):
                 if i == f.leaderID:
                     rewards = parse_reward(config.rewards)
                 else:
                     rewards = parse_reward(config.rewards2)
                 try:
                     proxy.ranking_send_mail(i, title, content, rewards,
                                             key, ID)
                 except AttributeError:
                     pass
         else:
             rewards = parse_reward(config.rewards)
             try:
                 proxy.ranking_send_mail(entityID, title, content, rewards,
                                         key, ID)
             except AttributeError:
                 pass
Exemplo n.º 14
0
 def build_faction_item(self, factionID, item):
     f = Faction.simple_load(
         factionID, ["name", "leaderID", "memberset"]
     )
     if f:
         l = Player.simple_load(f.leaderID, ["prototypeID"])
         item.name = f.name
         item.prototypeID = l.prototypeID
         item.faction_count = len(f.memberset)
         item.faction_level = FactionRankRanking.get_score(factionID) or 1
         item.entityID = factionID
Exemplo n.º 15
0
Arquivo: city.py Projeto: kimch2/x8623
    def reset(self):
        from campaign.manager import g_campaignManager
        start_time = g_campaignManager.city_dungeon_campaign.get_start_time()
        final_time = g_campaignManager.city_dungeon_campaign.get_final_time()
        reset = int(float(index_pool.execute(
            "GETSET", CityDungeonReset, start_time) or 0))
        if reset >= start_time and reset <= final_time:
            index_pool.execute(
                "SET", CityDungeonReset, reset)
            logger.info("Not need reset city dungeon")
            return
        logger.info("Reset city dungeon")
        # 发送奖励
        self.give_reward()
        cmds = []
        # 备份
        self.set_top_info()
        CityDungeonKillRanking.pool.execute(
            'ZUNIONSTORE', CityDungeonKillBackupRanking.key,
            1, CityDungeonKillRanking.key)

        CityDungeonSelfRanking.pool.execute(
            'ZUNIONSTORE', CityDungeonSelfBackupRanking.key,
            1, CityDungeonSelfRanking.key)
        # 清除数据
        ranking = CityDungeonKillRanking.get_range_by_score("-inf", "+inf")
        for k in ranking:
            k = int(k)
            f = Faction.simple_load(k, [
                "entityID", "faction_treasure",
                "city_top_member_kills"])
            f.city_top_member_kills = 0
            f.faction_treasure = 0
            f.save()
            cmds.append([
                "DEL",
                self.get_mg_pool_key(k),
                self.get_mg_sums_key(k),
            ])
            cmds.append([
                "HCLEAR", self.get_mg_kill_key(k)
            ])
        entity_pool.execute_pipeline(*cmds)
        index_pool.execute_pipeline(
            ("DEL", CityDungeonKillRanking.key),
            ("DEL", CityDungeonSelfRanking.key),
            ("DEL", CityDungeonSumsRanking.key),
        )
        g_redManager.clean_red(module=RedModuleType.CityDungeon)
        top_faction = self.get_top_faction()
        if top_faction:
            g_cityContend.set_top_faction(top_faction)
        self.reset_players()
Exemplo n.º 16
0
def broadcast_faction_message(m):
    msg = success_msg(msgid.RECV_MESSAGE, m)
    from entity.manager import g_entityManager
    p = g_entityManager.get_player(m.entityID)
    if not p:
        p = Player.simple_load(m.entityID, ["factionID"])
    from player.manager import g_playerManager
    from faction.model import Faction
    if p.factionID:
        g_chatManager.cache_message(m, factionID=p.factionID)
        f = Faction.simple_load(p.factionID, ["memberset"])
        if f:
            g_playerManager.broadcast(f.memberset, msg)
Exemplo n.º 17
0
def deny_apply_failure(factionID, entityID):
    faction = Faction.simple_load(factionID, ['applyset', 'leaderID'])
    safe_remove(faction.applyset, entityID)
    faction.save()
    proxy.sync_apply(faction.leaderID)
    player = Player.simple_load(entityID, ['applyFactions'])
    if is_apply(player, factionID):  # 玩家还没有取消申请
        safe_remove(player.applyFactions, factionID)
        # player.applyFactionTime = 0
        faction.save()
        player.save()
        return SUCCESS
    return msgTips.FAIL_MSG_FACTION_ALREADY_CANCEL_APPLY
Exemplo n.º 18
0
def update_strengthen_level(p, factionID):
    faction = Faction.simple_load(factionID, [
        "strengthen_hp_level", "strengthen_at_level", "strengthen_ct_level",
        "strengthen_df_level"
    ])
    p.strengthen_at_level = min(p.strengthen_at_max_level,
                                faction.strengthen_at_level)
    p.strengthen_hp_level = min(p.strengthen_hp_max_level,
                                faction.strengthen_hp_level)
    p.strengthen_ct_level = min(p.strengthen_ct_max_level,
                                faction.strengthen_ct_level)
    p.strengthen_df_level = min(p.strengthen_df_max_level,
                                faction.strengthen_df_level)
Exemplo n.º 19
0
 def city_contend_end_panel(self, msgtype, body):
     p = self.player
     rsp = poem_pb.CityContendEndPanel()
     g_cityContend.get_end_panel(p, rsp)
     rsp.self_treasure = p.city_contend_total_treasure_backup or\
         p.city_contend_total_treasure
     rsp.count = p.city_contend_count_backup or \
         p.city_contend_count
     f = Faction.simple_load(p.factionID, ["faction_treasure"])
     rsp.faction_treasure = f.faction_treasure
     p.city_contend_rewards.clear()
     p.save()
     p.sync()
     return success_msg(msgtype, rsp)
Exemplo n.º 20
0
 def faction_cancel_dismiss(self, msgtype, body):
     player = self.player
     factionID = player.factionID
     faction = Faction.simple_load(factionID, ['leaderID', 'dflag'])
     if player.entityID != faction.leaderID:
         return fail_msg(msgtype,
                         msgTips.FAIL_MSG_FACTION_PERMISSION_DENIED)
     faction.dflag = False
     faction.save()
     recommend(factionID)
     player.dismissCD = 0
     player.save()
     player.sync()
     return success_msg(msgtype, '')
Exemplo n.º 21
0
 def faction_kick(self, msgtype, body):
     factionID = self.player.factionID
     faction = Faction.simple_load(factionID, ['leaderID'])
     if self.player.entityID != faction.leaderID:
         return fail_msg(msgtype,
                         msgTips.FAIL_MSG_FACTION_PERMISSION_DENIED)
     req = poem_pb.KickMember()
     req.ParseFromString(body)
     err = proxy.kick_member(factionID, req.entityID)
     if err:
         return fail_msg(msgtype, err)
     else:  # 加入推荐列表
         recommend(factionID)
     return success_msg(msgtype, '')
Exemplo n.º 22
0
 def faction_alter_notice(self, msgtype, body):
     factionID = self.player.factionID
     if not factionID:
         return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_HAS_NOT_FACTION)
     faction = Faction.simple_load(factionID, ['notice', 'leaderID'])
     if self.player.entityID != faction.leaderID:
         return fail_msg(msgtype,
                         msgTips.FAIL_MSG_FACTION_PERMISSION_DENIED)
     req = poem_pb.AlterNoticeFaction()
     req.ParseFromString(body)
     notice = trie.trie_replace(dirty_words_trie, req.notice, u'*')
     faction.notice = notice
     faction.save()
     rsp = poem_pb.AlterNoticeFaction(notice=notice)
     return success_msg(msgtype, rsp)
Exemplo n.º 23
0
def invite_member(factionID, entityID):
    player = g_entityManager.get_player(entityID)
    faction = Faction.simple_load(factionID, ['inviteset'])
    if player.factionID:
        return msgTips.FAIL_MSG_FACTION_ALREADY_HAD_FACTION
    # if player.applyFactionTime and \
    #         player.applyFactionTime < int(time.time()):
    #     return msgTips.FAIL_MSG_FACTION_ALREADY_APPLYED
    if player.level < INVITE_LEVEL_LIMIT:
        return msgTips.FAIL_MSG_FACTION_NOT_ENOUGH_LEVEL
    faction.inviteset.add(player.entityID)
    faction.save()
    player.inviteFactionSet.add(factionID)
    player.save()
    player.sync()
    return SUCCESS
Exemplo n.º 24
0
 def faction_alter_mode(self, msgtype, body):
     req = poem_pb.AlterModeFactionRequest()
     req.ParseFromString(body)
     factionID = self.player.factionID
     if not factionID:
         return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_HAS_NOT_FACTION)
     faction = Faction.simple_load(factionID, ['leaderID', 'mode'])
     if self.player.entityID != faction.leaderID:
         return fail_msg(msgtype,
                         msgTips.FAIL_MSG_FACTION_PERMISSION_DENIED)
     if req.mode not in (poem_pb.Check, poem_pb.Free, poem_pb.Deny):
         return fail_msg(msgtype, msgTips.FAIL_MSG_INVALID_REQUEST)
     faction.mode = req.mode
     faction.save()
     rsp = poem_pb.AlterModeFaction(mode=faction.mode)
     return success_msg(msgtype, rsp)
Exemplo n.º 25
0
def allow_apply(factionID, entityID):
    faction = Faction.simple_load(factionID,
                                  ['applyset', 'memberset', 'leaderID'])
    safe_remove(faction.applyset, entityID)
    faction.save()
    proxy.sync_apply(faction.leaderID)
    player = g_entityManager.get_player(entityID)
    if not isrecommend(factionID):
        return msgTips.FAIL_MSG_FACTION_MEMBERS_LIMIT_EXCEED
    if is_apply(player, factionID) and not player.factionID:
        # 玩家还没有取消申请
        join_faction(player.entityID, factionID)
        player.save()
        player.sync()
        faction.save()
        return SUCCESS
    return msgTips.FAIL_MSG_FACTION_ALREADY_CANCEL_APPLY
Exemplo n.º 26
0
 def faction_dismiss(self, msgtype, body):
     player = self.player
     factionID = player.factionID
     faction = Faction.simple_load(
         factionID, ['leaderID', 'name', 'memberset', 'dflag'])
     if player.entityID != faction.leaderID:
         return fail_msg(msgtype,
                         msgTips.FAIL_MSG_FACTION_PERMISSION_DENIED)
     if len(faction.memberset) > 1:
         return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_CAN_NOT_DISMISS)
     faction.dflag = True
     faction.save()
     unrecommend(factionID)
     player.dismissCD = int(time.time()) + DISMISSFACTIONCD
     player.save()
     player.sync()
     return success_msg(msgtype, '')
Exemplo n.º 27
0
 def faction_throne(self, msgtype, body):
     p = self.player
     factionID = self.player.factionID
     faction = Faction.simple_load(factionID, ['leaderID'])
     if self.player.entityID != faction.leaderID:
         return fail_msg(msgtype,
                         msgTips.FAIL_MSG_FACTION_PERMISSION_DENIED)
     req = poem_pb.ThroneMember()
     req.ParseFromString(body)
     if req.entityID == faction.leaderID:
         return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_ALREADY_LEADER)
     err = proxy.throne_member(factionID, req.entityID)
     if err:
         return fail_msg(msgtype, err)
     p.faction_is_leader = False
     p.save()
     p.sync()
     return success_msg(msgtype, '')
Exemplo n.º 28
0
def kick_member_failure(factionID, entityID):
    faction = Faction.simple_load(factionID, ['name', 'memberset'])
    player = Player.simple_load(entityID,
                                ['factionID', 'joinFactionTime', 'mailset'])
    if player.factionID == factionID:
        now = int(time.time())
        if player.joinFactionTime and \
                (now - player.joinFactionTime) < QUITFACTIONCD:
            return msgTips.FAIL_MSG_FACTION_CAN_NOT_LEAVE
        clean_faction(player.entityID)
        faction.save()
        dt = datetime.fromtimestamp(now).strftime("%Y-%m-%d %H:%M:%S")
        title, content, ID = get_mail("FactionKick")
        send_mail(entityID,
                  title,
                  content.format(dt, faction.name),
                  configID=ID)
        return SUCCESS
    return msgTips.FAIL_MSG_FACTION_MEMBER_ALREADY_QUIT
Exemplo n.º 29
0
 def faction_levelup(self, msgtype, body):
     '''只有会长能操作'''
     player = self.player
     factionID = player.factionID
     if not factionID:
         return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_HAS_NOT_FACTION)
     faction = Faction.simple_load(factionID, ['leaderID'])
     if player.entityID != faction.leaderID:
         return fail_msg(msgtype,
                         msgTips.FAIL_MSG_FACTION_PERMISSION_DENIED)
     level = FactionRankRanking.get_score(factionID) or 0
     configs = get_config(FactionLimitConfig)
     config = configs.get((level or 1) + 1)
     if not config:
         return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_MAX_LEVEL)
     faction = Faction.load(factionID)
     if faction.totalfp < config.exp:
         return fail_msg(msgtype,
                         msgTips.FAIL_MSG_FACTION_NOT_ENOUGH_TOTALFP)
     faction.incr('totalfp', -config.exp)
     faction.save()
     if not level:
         incr = 2
     else:
         incr = 1
     rs = FactionRankRanking.incr_score(factionID, incr)
     limit1 = get_config(FactionLimitConfig)[level or 1]
     limit2 = get_config(FactionLimitConfig).get((level or 1) + 1)
     if limit2 and limit2.limit > limit1.limit:
         recommend(factionID)
     player.save()
     player.sync()
     notify_change(factionID)
     gm_logger.info({
         'faction': {
             'entityID': player.entityID,
             'type': 'levelup_faction',
             'factionLevel': rs,
             'factionID': faction.factionID,
         }
     })
     return success_msg(msgtype, '')
Exemplo n.º 30
0
Arquivo: city.py Projeto: kimch2/x8623
 def set_top_info(self):
     ranking = CityDungeonKillRanking .get_range_by_score(
         "-inf", "+inf", count=1)
     if ranking:
         faction = Faction.simple_load(
             ranking[0],
             ["entityID", "name", "leaderID"])
         if faction:
             info = {
                 "top_factionID": faction.entityID,
                 "top_faction_name": faction.name,
             }
             player = Player.simple_load(
                 faction.leaderID, ["name"])
             if player:
                 info.update({
                     "top_faction_leader_name": player.name
                 })
             index_pool.execute(
                 "SET", CityDungeonTop, msgpack.dumps(info))