hxp
2025-11-21 caba629e01f8f603b8e05f588688c40e82eb6c88
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerTreasure.py
@@ -33,6 +33,14 @@
import random
(
CostType_Money, # 消耗货币 0
CostType_DayFree, # 每日免费 1
CostType_Item, # 消耗道具 2
CostType_ADFree, # 广告免费 3
) = range(4)
CostFreeTypes = [CostType_DayFree, CostType_ADFree]
# 寻宝类型: >=100的为策划自行配置的自定义寻宝类型,<100的用于指定系统寻宝功能
TreasureTypeList = (
TreasureType_Jipin, # 极品寻宝 1
@@ -78,6 +86,7 @@
            ItemControler.RecycleItem(curPlayer, costItemID, recycleItemMail)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureFreeCount % (treasureType), 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureCount % (treasureType), 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureCountEx % (treasureType), 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureCountToday % (treasureType), 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureLuck % (treasureType), 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureCntAward % (treasureType), 0)
@@ -106,12 +115,15 @@
#};
def OnRequestTreasure(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    playerLV = curPlayer.GetLV()
    playerID = curPlayer.GetPlayerID()
    treasureType = clientData.TreasureType
    treasureIndex = clientData.TreasureIndex
    costType = clientData.CostType
    DoTreasure(curPlayer, treasureType, costType, treasureIndex)
    return
def DoTreasure(curPlayer, treasureType, costType, treasureIndex=0):
    playerLV = curPlayer.GetLV()
    playerID = curPlayer.GetPlayerID()
    GameWorld.DebugLog("玩家寻宝: treasureType=%s,treasureIndex=%s,costType=%s,playerLV=%s" 
                       % (treasureType, treasureIndex, costType, playerLV), playerID)
    
@@ -126,6 +138,9 @@
    if not treasureCountList:
        GameWorld.DebugLog("没有寻宝次数列表配置!", playerID)
        return
    if costType == CostType_ADFree:
        treasureIndex = 0
        GameWorld.DebugLog("广告寻宝强制设置: treasureIndex=%s" % treasureIndex, playerID)
    if treasureIndex < 0 or treasureIndex >= len(treasureCountList):
        GameWorld.ErrLog("寻宝次数索引不存在!treasureType=%s,treasureIndex=%s" % (treasureType, treasureIndex), playerID)
        return
@@ -148,7 +163,7 @@
            return
        
    # 免费次数
    if costType == 1:
    if costType == CostType_DayFree:
        dailyFreeCount = setIpyData.GetDailyFreeCount()
        if not dailyFreeCount:
            GameWorld.ErrLog("该寻宝类型索引不支持免费次数寻宝!treasureType=%s,treasureIndex=%s" % (treasureType, treasureIndex), playerID)
@@ -158,9 +173,11 @@
        if updFreeCountToday > dailyFreeCount:
            GameWorld.DebugLog("今日免费次数不足,无法使用免费寻宝! freeCountToday=%s + %s > %s" % (freeCountToday, treasureCount, dailyFreeCount), playerID)
            return
    # 广告免费
    elif costType == CostType_ADFree:
        pass
    # 寻宝道具, 目前默认消耗1个
    elif costType == 2:
    elif costType == CostType_Item:
        costItemID = setIpyData.GetCostItemID()
        costItemList = setIpyData.GetCostItemCountList() # 消耗道具物品ID列表
        if not costItemID or not costItemList or treasureIndex >= len(costItemList):
@@ -240,6 +257,18 @@
        gridNumCountInfo[int(gridNumStr)] = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureGridCnt % (treasureType, gridNumStr))
    GameWorld.DebugLog("gridNumMaxLimitInfo=%s,gridNumCountInfo=%s" % (gridNumMaxLimitInfo, gridNumCountInfo), playerID)
    
    treasureCountEx = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureCountEx % (treasureType)) # 当前第x次单抽、x抽
    curIndexCount, maxIndexCount = 0, 0
    beSureCountByIndexDict = {}
    beSureCountByIndexList = ipyData.GetGridItemRateList4() # 第x次x抽必出,最多支持定制到9次
    if beSureCountByIndexList and treasureIndex < len(beSureCountByIndexList):
        beSureCountByIndexDict = beSureCountByIndexList[treasureIndex]
        maxIndexCount = min(9, max(beSureCountByIndexDict))
        curIndexCount = GameWorld.GetDataByDigitPlace(treasureCountEx, treasureIndex) + 1
    beSureCountByIndexCfg = []
    if curIndexCount <= maxIndexCount and curIndexCount in beSureCountByIndexDict:
        beSureCountByIndexCfg = beSureCountByIndexDict[curIndexCount]
    # 单抽产出优先级: 幸运物品 > 必出 > 保底 > 普通
    # 连抽没有优先级限制,只要满足条件即可产出
    getGridResult = []
@@ -260,8 +289,17 @@
        
        curRateList = [] # 可能会改变饼图,每次抽奖使用新的饼图对象,不要改变配置的饼图概率
        
        # 第x次x抽必出,优先级最高,无视其他
        if not curRateList and beSureCountByIndexCfg:
            if tIndex == 0:
                curRateList = [[10000, beSureCountByIndexCfg[0]]]
            else:
                curRateList = beSureCountByIndexCfg[1]
            GameWorld.DebugLog("    【第x次x抽必出】: treasureIndex=%s,curIndexCount=%s,%s"
                               % (treasureIndex, curIndexCount, curRateList), playerID)
        # 满幸运必出
        if stageLuck and updLuck >= stageLuck and luckItemRateList:
        if not curRateList and stageLuck and updLuck >= stageLuck and luckItemRateList:
            curRateList = GetRemoveLimitGridRateList(luckItemRateList, gridNumCountInfo, gridNumMaxLimitInfo)
            GameWorld.DebugLog("    【满幸运必出饼图】: %s" % curRateList, playerID)
            
@@ -368,10 +406,12 @@
        treasureResult.append([gridNum, itemID, itemCount, isTrans])
        
    # 扣消耗
    if costType == 1:
    if costType == CostType_DayFree:
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureFreeCount % (treasureType), updFreeCountToday)
        GameWorld.DebugLog("消耗免费次数,更新今日已使用免费次数: %s" % updFreeCountToday, playerID)
    elif costType == 2:
    elif costType == CostType_ADFree:
        GameWorld.DebugLog("广告寻宝免费", playerID)
    elif costType == CostType_Item:
        ItemCommon.DelCostItemByBind(curPlayer, costItemIndexList, bindCnt, unBindCnt, delCostItemCount, ChConfig.ItemDel_Treasure)
        GameWorld.DebugLog("扣除寻宝道具,costItemID=%s,delCostItemCount=%s" % (costItemID, delCostItemCount), playerID)
        if lackCountCostMoney:
@@ -388,6 +428,10 @@
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureLuck % (treasureType), updLuck)
    for gridNum, updCount in gridNumCountInfo.items():
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureGridCnt % (treasureType, gridNum), updCount)
    if curIndexCount <= maxIndexCount:
        treasureCountEx = GameWorld.ChangeDataByDigitPlace(treasureCountEx, treasureIndex, curIndexCount)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureCountEx % (treasureType), treasureCountEx)
        GameWorld.DebugLog("更新第x次x抽次数: treasureIndex=%s,curIndexCount=%s,maxIndexCount=%s,treasureCountEx=%s" % (treasureIndex, curIndexCount, maxIndexCount, treasureCountEx))
        
    addScoreType = setIpyData.GetAwardMoneyType() # 额外奖励货币类型
    addScore = setIpyData.GetAwardMoneyValue() # 单次奖励货币数
@@ -436,8 +480,8 @@
    if mailItemList:
        PlayerControl.SendMailByKey("HappyXBUnEnough", [playerID], mailItemList)
        
    GameWorld.DebugLog("寻宝成功: treasureType=%s,updTreasureCount=%s(%s),updLuck=%s,addScoreType=%s,addScore=%s,gridNumCountInfo=%s"
                       % (treasureType, updTreasureCount, updTreasureCountToday, updLuck, addScoreType, addScore, gridNumCountInfo), playerID)
    GameWorld.DebugLog("寻宝成功: treasureType=%s,updTreasureCount=%s(%s),updLuck=%s,addScoreType=%s,addScore=%s,gridNumCountInfo=%s,treasureCountEx=%s"
                       % (treasureType, updTreasureCount, updTreasureCountToday, updLuck, addScoreType, addScore, gridNumCountInfo, treasureCountEx), playerID)
    GameWorld.DebugLog("    treasureResult=%s" % (treasureResult), playerID)
    GameWorld.DebugLog("    mailItemList=%s" % (mailItemList), playerID)
    
@@ -508,7 +552,7 @@
def GetUpdLuckyItemRateList(ipyData, luckyGridNumList, curLuck, luckFormula, costType):
    # 获取幸运物品提升概率后的饼图
    treasureType = ipyData.GetTreasureType()
    srcPieList = ipyData.GetGridItemRateListFree() if costType == 1 else ipyData.GetGridItemRateList1()
    srcPieList = ipyData.GetGridItemRateListFree() if costType in CostFreeTypes else ipyData.GetGridItemRateList1()
    if not srcPieList:
        srcPieList = ipyData.GetGridItemRateList1()