Ejemplo n.º 1
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)
Ejemplo n.º 2
0
def get_faction_info(factionID):
    faction = Faction.get(factionID)
    if not faction:
        return {}
    player = Player.simple_load(faction.leaderID, ['prototypeID', 'name'])
    return dict(
        factionID=factionID,
        name=faction.name,
        level=FactionRankRanking.get_score(faction.factionID) or 1,
        mcount=len(faction.memberset),
        acount=len(faction.applyset),
        totalfp=faction.totalfp,
        todayfp=faction.todayfp,
        rank=FactionRankRanking.get_rank(factionID),
        prototypeID=player.prototypeID,
        leader=player.name,
        createtime=faction.createtime,
        notice=faction.notice,
        mode=faction.mode,
        strengthen_hp_level=faction.strengthen_hp_level,
        strengthen_at_level=faction.strengthen_at_level,
        strengthen_ct_level=faction.strengthen_ct_level,
        strengthen_df_level=faction.strengthen_df_level,
        can_strengthen=get_config(CanStrengthenConfig)[1].can,
        leaderID=faction.leaderID,
        dflag=faction.dflag,
    )
Ejemplo n.º 3
0
 def faction_create(self, msgtype, body):
     p = self.player
     # 判断是否可以创建公会
     if p.factionID:
         return fail_msg(msgtype,
                         msgTips.FAIL_MSG_FACTION_ALREADY_HAD_FACTION)
     # if is_applied(p):
     #     return fail_msg(
     #         msgtype, msgTips.FAIL_MSG_FACTION_ALREADY_APPLYED)
     req = poem_pb.AlterNameFaction()
     req.ParseFromString(body)
     name, err = validate_name(req.name)
     if err:
         return fail_msg(msgtype, err)
     try:
         FactionnameIndexing.register(0, name)  # 占位
     except DuplicateIndexException:
         return fail_msg(msgtype,
                         msgTips.FAIL_MSG_FACTION_DUPLICATE_FACTION_NAME)
     try:
         now = int(time.time())
         faction = Faction.create(name=name,
                                  createtime=now,
                                  leaderID=p.entityID)
     except EntityExistsException:
         FactionnameIndexing.unregister(name)
         return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_CREATE_FAIL)
     try:
         apply_reward(p, {},
                      cost={'gold': 500},
                      type=RewardType.CreateFaction)
     except AttrNotEnoughError:
         FactionnameIndexing.unregister(name)
         return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_NOT_ENOUGH_GOLD)
     FactionnameIndexing.pool.execute('HSET', FactionnameIndexing.key, name,
                                      faction.entityID)  # 更新
     faction.save()
     gm_logger.info({
         'faction': {
             'entityID': p.entityID,
             'type': 'create_faction',
             'factionName': faction.name,
             'factionLevel': 1,
             'factionID': faction.factionID,
         }
     })
     join_faction(p.entityID, faction.factionID)
     p.faction_is_leader = True
     p.save()
     p.sync()
     recommend(faction.factionID)  # 加入推荐列表
     FactionRankRanking.update_score(faction.factionID, 1)
     rsp = poem_pb.FactionInfo(**get_faction_info(faction.factionID))
     return success_msg(msgtype, rsp)
Ejemplo n.º 4
0
 def faction_rank(self, msgtype, body):
     req = poem_pb.RequestFactionRankList()
     req.ParseFromString(body)
     rsp = poem_pb.FactionInfos()
     rank = 0
     if req.type == poem_pb.RequestFactionRankList.Self:
         if self.player.factionID:
             rank = FactionRankRanking.get_rank(self.player.factionID)
     count = 50
     page = req.index
     if rank <= count:
         start = '-inf'
         end = '+inf'
         offset = count * page
         rankscores = FactionRankRanking.get_range_by_score(
             start,
             end,
             count=count + 1,  # 多取一条,用于判断是否有下一页
             offset=offset,
             withscores=True,
         )
         infos = convert_list_to_dict(rankscores)
         rankers = [c for i, c in enumerate(rankscores) if i % 2 == 0]
         offset += 1
     else:
         start = max(rank - 1 + count * page, 0)
         end = start + count
         rankers = FactionRankRanking.get_by_range(
             start,
             end + 1,  # 多取一条,用于判断是否有下一页
         )
         offset = start - 1
         scores = FactionRankRanking.get_scores(rankers)
         infos = dict(zip(rankers, scores))
     thumbs = []
     for i in rankers:
         thumb = get_faction_thumb(i)
         if not thumb:
             continue
         thumbs.append(thumb)
     for thumb in thumbs[:count]:
         thumb['rank'] = rankers.index(thumb['factionID']) + offset
         thumb['level'] = infos.get(thumb['factionID'], 1)
         rsp.infos.add(**thumb)
     thumbs.sort(key=lambda s: s['rank'])
     if len(thumbs) > count:
         rsp.hasnext = True
     else:
         rsp.hasnext = False
     return success_msg(msgtype, rsp)
Ejemplo n.º 5
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
Ejemplo n.º 6
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, '')
Ejemplo n.º 7
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
Ejemplo n.º 8
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,
        }
    })
Ejemplo n.º 9
0
Archivo: city.py Proyecto: kimch2/x8623
 def get_faction_ranking(self, ranking):
     faction_rankers = convert_list_to_dict(
         ranking.get_range_by_score(
             "-inf", "+inf", count=10, withscores=True),
         dictcls=OrderedDict)
     factions = Faction.batch_load(
         faction_rankers.keys(),
         ["entityID", "name", "level"])
     for faction in factions:
         score = faction_rankers[faction.entityID]
         faction_rankers[faction.entityID] = {
             "name": faction.name,
             "score": score,
             "level": FactionRankRanking.get_score(faction.factionID) or 1,
         }
     faction_rankers = sorted(
         faction_rankers.values(), key=lambda s: s["score"], reverse=True)
     return faction_rankers
Ejemplo n.º 10
0
Archivo: city.py Proyecto: kimch2/x8623
 def get_panel(self, p, rsp):
     rsp.faction_rank = CityDungeonKillRanking.get_rank(p.factionID)
     rsp.self_rank = CityDungeonSelfRanking.get_rank(p.entityID)
     faction_rankers = convert_list_to_dict(
         CityDungeonKillRanking.get_range_by_score(
             "-inf", "+inf", count=10, withscores=True),
         dictcls=OrderedDict)
     factions = Faction.batch_load(
         faction_rankers.keys(),
         ["entityID", "name", "level"])
     for faction in factions:
         if not faction:
             continue
         score = faction_rankers[faction.entityID]
         faction_rankers[faction.entityID] = {
             "name": faction.name,
             "score": score,
             "level": FactionRankRanking.get_score(faction.factionID) or 1,
         }
     player_rankers = convert_list_to_dict(
         CityDungeonSelfRanking.get_range_by_score(
             "-inf", "+inf", count=10, withscores=True),
         dictcls=OrderedDict)
     players = Player.batch_load(
         player_rankers.keys(),
         ["entityID", "name", "faction_name", "level"])
     for player in players:
         score = player_rankers[player.entityID]
         player_rankers[player.entityID] = {
             "name": player.name,
             "score": score,
             "level": player.level,
             "name2": player.faction_name,
         }
     rsp.faction_ranking = sorted(
         faction_rankers.values(), key=lambda s: s["score"], reverse=True)
     rsp.self_ranking = sorted(
         player_rankers.values(), key=lambda s: s["score"], reverse=True)
     rsp.top_prototypeID = p.prototypeID
     rsp.current_info = self.get_current_info(p)
     rsp.top_member_info = self.get_top_member_info(p)
     rsp.reds = g_redManager.get_red_messages(
         module=RedModuleType.CityDungeon)
Ejemplo n.º 11
0
 def faction_research(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 1
     faction = Faction.load(factionID)
     req = poem_pb.FactionResearchOrLearn()
     req.ParseFromString(body)
     prefix = {
         poem_pb.FactionStrengthen.hp: 'strengthen_hp',
         poem_pb.FactionStrengthen.at: 'strengthen_at',
         poem_pb.FactionStrengthen.ct: 'strengthen_ct',
         poem_pb.FactionStrengthen.df: 'strengthen_df',
     }[req.type]
     k = prefix + '_level'
     slevel = getattr(faction, k, 0)
     if slevel >= level:
         return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_MAX_LEVEL)
     configs = get_config(FactionStrengthenConfig)
     config = configs.get(slevel + 1)
     if not config:
         return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_MAX_LEVEL)
     if faction.totalfp < config.cost:
         return fail_msg(msgtype,
                         msgTips.FAIL_MSG_FACTION_NOT_ENOUGH_TOTALFP)
     faction.totalfp -= config.cost
     setattr(faction, k, slevel + 1)
     faction.save()
     FactionSkillRanking.incr_score(faction.factionID, 1)
     notify_strengthen_change(factionID)
     return success_msg(msgtype, '')
Ejemplo n.º 12
0
def notify_change(factionID):
    faction = Faction.simple_load(factionID,
                                  ['level', 'name', 'memberset', 'leaderID'])
    level = FactionRankRanking.get_score(factionID) or 1
    for e in faction.memberset:
        proxy.sync_faction(e, factionID, level, faction.name)