コード例 #1
0
def add_attr(role, attrs):
    adds = {}
    for attr, value in attrs.items():
        assert value >= 0
        if attr == 'exp':
            set_exp(role, value)
        else:
            old = getattr(role, attr)
            new = old + value
            setattr(role, attr, new)
        if attr == 'totalfp':
            role.todayfp_task += value
            if role.factionID:
                Faction.incr_attribute(role.factionID, 'totalfp', value)
        if attr == 'money':
            from task.manager import on_money
            on_money(role, value)
        elif attr == "gold":
            from task.manager import on_gold
            on_gold(role, value)
        elif attr == "soul":
            from task.manager import on_soul
            on_soul(role, value)
        adds[attr] = value
    return adds
コード例 #2
0
def donate_sp(p, sp):
    # 并不消耗人物的能量
    # 推图等消耗能量后,贡献公会贡献
    if not p.factionID:
        return
    if p.todayfp_sp >= p.todayfp_sp_max:
        return
    configs = get_config(FactionDonateConfig)
    # 能量兑换贡献
    config = configs[4]
    mul = p.faction_sp / config.arg1
    base = config.arg2 * mul
    rest = p.todayfp_sp_max - p.todayfp_sp
    # 不能超过上限
    if base > rest:
        base = rest
    # 重新计算,需要消耗多少能量
    cost = base / config.arg2 * config.arg1
    # 贡献兑换声望
    fpconfig = configs[3]
    fp = base / fpconfig.arg1 * fpconfig.arg2
    logger.debug("donate sp %r", sp)
    logger.debug("faction_sp %r", p.faction_sp)
    logger.debug("cost sp %r", cost)
    p.faction_sp -= cost
    logger.debug("remain sp %r", p.faction_sp)
    p.fp += fp
    logger.debug("gain fp %r", fp)
    p.todayfp_sp += base
    logger.debug("donate %r", base)
    p.totalfp += base
    logger.debug("todayfp_sp %r", p.todayfp_sp)
    p.save()
    p.sync()
    Faction.incr_attribute(p.factionID, 'totalfp', base)
コード例 #3
0
 def faction_donate(self, msgtype, body):
     p = self.player
     if not p.factionID:
         return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_HAS_NOT_FACTION)
     if p.todayfp_donate >= p.todayfp_donate_max:
         return fail_msg(msgtype,
                         msgTips.FAIL_MSG_FACTION_EXCEED_DAILY_DONATE_LIMIT)
     req = poem_pb.FactionDonate()
     req.ParseFromString(body)
     config = get_config(FactionDonateConfig)[1]
     fp = req.gold / config.arg1 * config.arg2
     if req.gold < config.arg1 or \
             req.gold % 10 != 0 or \
             (p.todayfp_donate + fp) > p.todayfp_donate_max:
         return fail_msg(msgtype,
                         msgTips.FAIL_MSG_FACTION_DONATE_AMOUNT_INVALID)
     try:
         cc = get_config(FactionDonateConfig)[3]
         apply_reward(p, {'fp': fp / cc.arg1 * cc.arg2},
                      cost={'gold': req.gold},
                      type=RewardType.DonateFaction)
     except AttrNotEnoughError:
         return fail_msg(msgtype, msgTips.FAIL_MSG_FACTION_NOT_ENOUGH_GOLD)
     totalfp = Faction.incr_attribute(p.factionID, 'totalfp', fp)
     p.totalfp += fp
     p.todayfp_donate += fp
     p.save()
     p.sync()
     rsp = poem_pb.FactionDonateResponse()
     rsp.totalfp = totalfp
     return success_msg(msgtype, rsp)
コード例 #4
0
ファイル: city.py プロジェクト: kimch2/x8623
 def end_defend_event(self, p):
     Faction.incr_attribute(
         p.factionID, "faction_treasure", p.city_contend_treasure)
     p.city_contend_total_treasure += p.city_contend_treasure
     p.city_contend_treasure = 0
     p.city_contend_step = 0
     p.city_contend_events = []
     p.city_contend_count += 1
     p.save()
     p.sync()
     # self_count = CityContendDefendRanking.incr_score(
     #     p.entityID, p.city_contend_treasure)
     self_count = CityContendDefendRanking.update_score(
         p.entityID, p.city_contend_count)
     message_configs = get_config(CityContendDefendMessageConfig)
     message_config = message_configs.get(p.city_contend_count)
     if not message_config:
         message_config = message_configs[max(message_configs)]
     count = CityContendDefendRanking.pool.execute(
         "ZCOUNT", CityContendDefendRanking.key, self_count, "+inf")
     full_message = ""
     red_message = ""
     red_count = 0
     if message_config.multiple1 or message_config.multiple1 \
             and count == 1:
         full_message = message_config.defend_count_desc.format(
             p.name, p.city_contend_count
         )
         horn = message_config.horn1
     if message_config.multiple2 or message_config.multiple2 \
             and count == 1:
         red_count = message_config.red_paper_count
         red_message = message_config.red_paper_desc.format(
             p.faction_name, p.name, p.city_contend_count, red_count
         )
         red_drop = message_config.red_paper
     if full_message:
         g_redManager.send_red_message
         _type = RedType.Horn if horn else RedType.Normal
         g_redManager.send_red_message(
             p, full_message, type=_type)
     if red_message and red_count:
         g_redManager.send_red_message(
             p, red_message, red_drop=red_drop,
             red_count=red_count, type=RedType.Red,
             module=RedModuleType.CityContendDefend)