Ejemplo n.º 1
0
    def win(self, target_player):
        '''
        PVP胜利调用
        '''

        result_score = int(32 * (1-(1/(1 + math.pow(10, (-(self.score - target_player.PVP.score)/250))))))
        self.add_score(result_score)

        result, upScore = self.checkUpgrade()

        if result:
            upScoreInfo = get_pvpUpgradeScore(upScore)

            rewards = []
            for reward in upScoreInfo.rewards:
                rewards.append(reward.to_dict())

            contents = []
            contents.append({
                "content": upScoreInfo.mulLang,
                "paramList": [str(upScore), str(upScoreInfo.upgrade)],
            })

            send_system_mail(player=self.player, sender=None, title="fytext_300725", contents=contents, rewards=rewards)
            

        return result_score
Ejemplo n.º 2
0
def send_daily_pvp_rewards():
    """
    发放昨天竞技场奖励
    """
    yesterday_pvpdata = []
    #删除之前数据
    # PlayerPVPYesterday.objects.all().delete()
    # 获取昨天1-500名
    rank_datas = PVPRank.get_yesterday_ranks(0, 499)

    date = datetime.datetime.now().isocalendar()
    dateStr = str(datetime.datetime.now().today())

    pvpRanks = get_pvpRanks()
    pvpRanks = sorted(pvpRanks, key=lambda x: x.rank)
    for rank, (p_id, p_score) in enumerate(rank_datas):
        rank += 1
        rewards = []
        if not p_id or p_id == "None":
            continue

        p_id = int(p_id)
        opp_player = get_player(p_id, False)
        yesterday_pvpdata.append(opp_player.pvp_view_data())

        #保存前一天数据
        #PlayerPVPYesterday.objects.create(pk=opp_player.pk, rank=rank, score=p_score)

        if p_id > 0:  #非机器人
            if opp_player and opp_player.level >= Static.PVP_LEVEL:
                for pvpRank in pvpRanks:
                    if rank <= pvpRank.rank:
                        rewards = pvpRank.dailyRewards
                        break

            if not rewards:
                break
            reward_list = []
            for reward in rewards:
                reward_list.append(reward.to_dict())

            print "%s:send Daily PVP Rewards:player id %s player name %s send reward id %s" % (
                dateStr, opp_player.pk, opp_player.name, pvpRank.pk)
            #发奖
            contents = []
            contents.append({
                "content": "fytext_300709",
                "paramList": [str(opp_player.PVP.yesterdayRank)],
            })
            send_system_mail(player=opp_player,
                             sender=None,
                             title="fytext_300723",
                             contents=contents,
                             rewards=reward_list)

    PlayerPVPYesterdayData.set_data(yesterday_pvpdata)
Ejemplo n.º 3
0
def send_mail(request):
    '''
        发送邮件
    '''
    playerIdList_int = request.REQUEST.get("playerIdList",
                                           "").strip()  # 逗号隔开的id字符串
    serverId = request.REQUEST.get("serverId", str(settings.SERVERID)).strip()
    title = request.REQUEST.get("title", "").strip()  # "fytext_300723"
    attachments_str = request.REQUEST.get("attachments",
                                          "").strip()  # t1000c1002,t1001c1003
    content = request.REQUEST.get("content", "").strip()  # "fytext_301064"
    paramList = request.REQUEST.get("paramList", "").strip()

    print title, "*****"
    if playerIdList_int == "all":
        players = get_all_player()
    else:
        players = [pk for pk in playerIdList_int.strip().split(",") if pk]

    rewards = []
    attachments = [pk for pk in attachments_str.strip().split(",") if pk]
    for attachment in attachments:
        reward = get_commonreward(attachment)
        rewards.append({"type": reward.type, "count": reward.count})

    contents = []
    paramList = [pk for pk in paramList.strip().split(",") if pk]
    contents.append({"content": content, "paramList": paramList})

    data = []
    for player in players:
        if not isinstance(player, Player):
            _player = get_player_by_id_or_str(player, int(serverId))
        else:
            _player = player
        meta = {}
        meta["success"] = False
        if not _player:
            meta["id"] = player
            meta["message"] = u"该玩家不存在!"
            meta["errorcode"] = ErrorCode.ERROR_PLAYER_IS_NONE
            data.append(meta)
            continue
        send_system_mail(player=_player,
                         sender=None,
                         title=title,
                         contents=contents,
                         rewards=rewards)
        meta["id"] = _player.id
        meta["success"] = True
        meta["message"] = "Send success!"
        data.append(meta)

    return HttpResponseJson(data)
Ejemplo n.º 4
0
def send_weekly_pvp_rewards():
    """
    发放上周竞技场奖励
    """

    lastweek_pvpdata = []
    # 获取上周800积分到100000积分之间的玩家
    rank_datas = PVPRank.get_last_ranks_by_score(800, 100000)  #假定最大上线10w分
    pvpRanks = get_pvpRanks()
    pvpRanks = sorted(pvpRanks, key=lambda x: x.rank)

    dateStr = str(datetime.datetime.now().today())
    for p_id, p_score in rank_datas:
        rewards = []
        if not p_id or p_id == "None":
            continue

        p_id = int(p_id)
        opp_player = get_player(p_id, False)
        lastweek_pvpdata.append(opp_player.pvp_view_data(last_rank=True))
        if p_id > 0:  #非机器人
            if opp_player and opp_player.level >= Static.PVP_LEVEL:
                for pvpRank in pvpRanks:
                    if p_score >= pvpRank.score:
                        rewards = pvpRank.weeklyRewards
                        break

            if not rewards:
                break
            reward_list = []
            for reward in rewards:
                reward_list.append(reward.to_dict())

            print "%s: send Weekly PVP Rewards:player id %s player name %s send reward id %s" % (
                dateStr, opp_player.pk, opp_player.name, pvpRank.pk)
            #发奖
            contents = []
            contents.append({
                "content":
                "fytext_300710",
                "paramList": [str(int(opp_player.PVP.lastWeekRank))],
            })

            send_system_mail(player=opp_player,
                             sender=None,
                             title="fytext_300724",
                             contents=contents,
                             rewards=reward_list)
    PlayerPVPLastWeekData.set_data(lastweek_pvpdata)
Ejemplo n.º 5
0
def packageUse(request, response):
    """
    礼包使用
    status: 1 成功;2 兑换码不存在;3 兑换码已使用;4 兑换码过期;5 兑换码无法在该渠道使用;6 兑换码无法在此服使用;7 该礼包已兑换
    """
    player = request.player
    package_code_id = getattr(request.logic_request, "packageCode", "").upper()
    package_code = get_package_code(package_code_id)

    status = 1
    if not package_code:
        status = 2
    elif package_code.is_use:
        status = 3
    elif package_code.is_expired:
        status = 4
    elif not package_code.check_channel(player.channel):
        status = 5
    elif not package_code.check_server(settings.SERVERID):
        status = 6
    else:
        playerpackage = get_playerpackage(player, package_code.package.name)

        if playerpackage and playerpackage.package_code:
            status = 7
        else:
            use_package_code(player, package_code)
            rewards = package_code.package.rewards
            rewards_dict = []
            for _reward in rewards:
                rewards_dict.append({
                    "type": _reward.type,
                    "count": _reward.count
                })
            contents = []
            contents.append({
                "content": package_code.package.gift_body,
                "paramList": [],
            })

            send_system_mail(player=player,
                             sender=None,
                             title=package_code.package.gift_title,
                             contents=contents,
                             rewards=rewards_dict)
    response.logic_response.set("status", status)

    return response
Ejemplo n.º 6
0
def send_mail(request):
    from module.mail.api import send_system_mail
    from module.player.api import get_player, get_all_player
    player_code = request.REQUEST.get("player_code")
    title = request.REQUEST.get("title")
    content = request.REQUEST.get("content")
    typel = request.REQUEST.get("typel")
    count = request.REQUEST.get("count")

    players = []

    if int(player_code) == 123456:
        players = get_all_player()

    else:
        for id in player_code.strip().split(','):
            player = get_player_by_id_or_str(id)
            players.append(player)

    rewards = []
    if typel and count:

        typelst = typel.strip().split(',')
        countlst = count.strip().split(',')

        for i in range(len(typelst)):
            redict = {}
            redict['type'] = int(typelst[i])
            redict['count'] = int(countlst[i])
            rewards.append(redict)

    contents = []
    contents.append({
        "content": content,
        "paramList": [],
    })

    for player in players:
        send_system_mail(player=player,
                         sender=None,
                         title=title,
                         contents=contents,
                         rewards=rewards)
    return HttpResponseRedirect(reverse("mobile_debug_index"))
Ejemplo n.º 7
0
def task_balance_guildauctionmaxinfo(id):
    """
    公会拍卖结算
    """
    task_del_balance_guildauctionmaxinfo(id)
    maxinfo = get_guildmaxinfo(id)
    msg = ""
    if not maxinfo:
        msg = "guild auction balance maxinfo %s not existed" % id
    else:
        if maxinfo.timeLeft > 0 and abs(maxinfo.timeLeft -
                                        int(time.time())) > 120:  #超过两分钟不结算
            task_add_balance_guildauctionmaxinfo(maxinfo)
            msg = "guild auction balance error , right at %s" % str(
                maxinfo.aucEndAt)
        else:
            auctionInfos = zip(maxinfo.playerIds, maxinfo.prices)
            auctionInfos.sort(lambda x, y: cmp(y[1], x[1]))
            successContents = []  #竞拍成功内容
            successContents.append({
                "content": "fytext_300752",
            })
            successContents.append({
                "content": "fytext_300753",
                "paramList": [str(maxinfo.maxPrice)],
            })
            successContents.append({
                "content": "fytext_300754",
            })

            failContents = []  #竞拍失败内容
            failContents.append({
                "content":
                "fytext_300756",
                "paramList": [str(maxinfo.auctionReward.reward.name)],
            })

            players = get_players_by_ids(maxinfo.playerIds)

            for playerId, price in auctionInfos:
                player = players[playerId]
                successContents.append({
                    "content": "fytext_301170",
                    "paramList": [player.name, str(price)]
                })
                failContents.append({
                    "content": "fytext_301170",
                    "paramList": [player.name, str(price)]
                })
            failContents.append({
                "content": "fytext_300757",
            })
            for playerId, price in auctionInfos:
                player = players[playerId]
                rewards = []
                if playerId == maxinfo.maxPlayerId:
                    rewards.append(maxinfo.auctionReward.reward.to_dict())
                    send_system_mail(player,
                                     None,
                                     "fytext_300751",
                                     contents=successContents,
                                     rewards=rewards)
                else:
                    rewards.append({
                        "type": Static.GUILDGOLD_ID,
                        "count": price
                    })
                    send_system_mail(player,
                                     None,
                                     "fytext_300755",
                                     contents=failContents,
                                     rewards=rewards)

            maxinfo.delete()
            msg = "guild auction balance success %s" % simplejson.dumps(
                auctionInfos)

    return msg
Ejemplo n.º 8
0
def speedUpHero(request, response):
    """
    为社团成员加速
    """
    player = request.player
    targetPlayerId = getattr(request.logic_request, "targetPlayerId", 0)
    category = getattr(request.logic_request, "category", 0)

    # 每人每天的加速和被加速的次数是有限制的
    # if player.speedCount <= 0:
    #     AlertHandler(player, response, AlertID.ALERT_PLAYER_HAS_NO_SPEEDING_COUNT,  u"speedUpHero PLAYER has no speeding count %s" %player.id)
    #     return response

    #每日最多加速5次
    if player.guild.isMaxSpeed:
        response.common_response.player.set("guild", player.guild.to_dict())
        return response

    targetPlayer = None
    if targetPlayerId:
        if targetPlayerId == player.id:
            return response
        targetPlayer = get_player(targetPlayerId)
        if not targetPlayer:
            return response
        #不在公会
        if targetPlayerId not in player.guild.guildInfo.membersIds:
            player.guild.guildInfo.self_release_lock()
            targetPlayer.self_release_lock()
            response.common_response.player.set("guild",
                                                player.guild.to_dict(True))
            return response

        #modify by ljdong 同一个用户可以被多次加速
        #if targetPlayerId in player.guild.speedPlayerIds:
        #response.common_response.player.set("guild", player.guild.to_dict(True))
        #return response

        #每日最多被加速5次
        if targetPlayer.guild.isMaxSpeeded:
            player.guild.guildInfo.self_release_lock()
            targetPlayer.self_release_lock()
            response.common_response.player.set("guild",
                                                player.guild.to_dict(True))
            return response
    else:
        memberIds = copy.copy(player.guild.guildInfo.membersIds)
        random.shuffle(memberIds)
        for memberId in memberIds:
            #modify by ljdong
            #if memberId in player.guild.speedPlayerIds:
            #continue
            if memberId == player.id:
                continue
            targetPlayer = get_player(memberId)
            #每日最多被加速5次
            if targetPlayer.guild.isMaxSpeeded:
                targetPlayer.self_release_lock()
                continue

            targetPlayerId = memberId
            break

        if not targetPlayerId:
            return response

    guildLevel = get_guild(player.guild.guildInfo.level)

    player.guild.speed(targetPlayer)

    contents = []
    contents.append({
        "content":
        "fytext_301171",
        "paramList": [player.guild.guildInfo.name, targetPlayer.name],
    })

    send_system_mail(player,
                     None,
                     "fytext_301173",
                     contents=contents,
                     rewards=guildLevel.speedRewards)
    contents = []
    contents.append({
        "content": "fytext_301172",
        "paramList": [player.guild.guildInfo.name, player.name],
    })
    send_system_mail(targetPlayer,
                     None,
                     "fytext_301173",
                     contents=contents,
                     rewards=guildLevel.speedRewards)
    response.common_response.player.set("guild", player.guild.to_dict())

    return response
Ejemplo n.º 9
0
def allowedMemberJoinGuild(request, response):
    """
    加入或者拒绝社团
    """
    player = request.player

    category = getattr(request.logic_request, "category", 0)  # 1允许 2 拒绝
    targetPlayerId = getattr(request.logic_request, "targetPlayerId", 0)

    if player.guild.position not in [
            Static.GUILD_CHAIRMAN_POSITION, Static.GUILD_VI_CHAIRMAN_POSITION
    ]:
        # 不是会长不可以审核
        return response

    guildInfo = player.guild.guildInfo

    if targetPlayerId and targetPlayerId not in guildInfo.requestMemberIds:  #检查是否在请求列表中
        guildInfo.self_release_lock()
        return response

    # 如果是拒绝的话,分为单个拒绝和拒绝所有
    if category == 2:
        if targetPlayerId:
            targetPlayer = get_player(targetPlayerId, False)
            # 从列表里面删除
            player.guild.disallow_join_guild(targetPlayerId)
            contents = []
            contents.append({
                "content": "fytext_300760",
                "paramList": [guildInfo.name],
            })

            # 发送邮件通知对方,没有加入成功
            send_system_mail(targetPlayer,
                             None,
                             "fytext_300762",
                             contents=contents)
        else:
            # 所有
            for targetPlayerId in guildInfo.requestMemberIds:
                targetPlayer = get_player(targetPlayerId, False)
                # 再进行一次验证
                if not targetPlayer.guildId:
                    contents = []
                    contents.append({
                        "content": "fytext_300760",
                        "paramList": [guildInfo.name],
                    })

                    send_system_mail(targetPlayer,
                                     None,
                                     "fytext_300762",
                                     contents=contents)

                player.guild.disallow_join_guild(targetPlayerId)

    # 如果同意操作基本类似
    elif category == 1:
        targetPlayers = []
        if targetPlayerId:
            targetPlayer = get_player(targetPlayerId)
            targetPlayers.append(targetPlayer)
        else:
            for id in guildInfo.requestMemberIds:
                targetPlayer = get_player(id)
                targetPlayers.append(targetPlayer)

        for targetPlayer in targetPlayers:
            contents = []
            contents.append({
                "content": "fytext_300759",
                "paramList": [guildInfo.name],
            })

            send_system_mail(targetPlayer,
                             None,
                             "fytext_300761",
                             contents=contents)
            player.guild.allow_join_guild(targetPlayer)

    guildInfo.save()
    response.common_response.player.set("guild", player.guild.to_dict())

    return response