hxp
2025-11-28 e732d41e0cb359b658cb0a1091b2aa0101b8f108
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerHero.py
@@ -21,9 +21,11 @@
import IPY_GameWorld
import ItemControler
import ChPyNetSendPack
import PlayerActivity
import NetPackCommon
import PlayerControl
import PlayerOnline
import PlayerTask
import GameWorld
import ChConfig
@@ -38,6 +40,7 @@
def OnPlayerLogin(curPlayer):
    Sync_HeroInfo(curPlayer)
    Sync_PlayerHeroInfo(curPlayer)
    Sync_LineupRecommendInfo(curPlayer)
    return
def OnPlayerFirstLogin(curPlayer):
@@ -349,6 +352,9 @@
    heroItem.SetUserAttr(ShareDefine.Def_IudetHeroLV, updHeroLV)
    
    PlayerOnline.GetOnlinePlayer(curPlayer).OnHeroItemUpate([itemIndex])
    PlayerActivity.AddDailyTaskValue(curPlayer, ChConfig.DailyTask_HeroLVUP, 1)
    PlayerTask.AddTaskValue(curPlayer, ChConfig.TaskType_HeroLVUP)
    return
def GetHeroLVMax(heroItem):
@@ -442,10 +448,13 @@
        return 0
    InitStarUpper = qualityIpyData.GetInitStarUpper()
    
    awakeLV = heroItem.GetUserAttr(ShareDefine.Def_IudetHeroAwakeLV)
    if not awakeLV:
        return InitStarUpper
    addStarUpper = 0
    heroAwakeIpyDataList = IpyGameDataPY.GetIpyGameDataListNotLog("HeroAwake", heroID)
    if heroAwakeIpyDataList:
        awakeLV = heroItem.GetUserAttr(ShareDefine.Def_IudetHeroAwakeLV)
        for ipyData in heroAwakeIpyDataList:
            if ipyData.GetAwakeLV() > awakeLV:
                break
@@ -464,6 +473,9 @@
    item.SetUserAttr(ShareDefine.Def_IudetHeroStar, updStar)
    if addStar > 0:
        __DoHeroStarTalentUp(item, addStar)
        PlayerActivity.AddDailyTaskValue(curPlayer, ChConfig.DailyTask_HeroStarUP, addStar)
        PlayerTask.AddTaskValue(curPlayer, ChConfig.TaskType_HeroStarUP, addStar)
    if isSync:
        heroItem.Sync_Item()
    
@@ -478,12 +490,25 @@
def __DoHeroStarTalentUp(singleItem, addLV):
    ## 执行武将星级天赋等级提升
    
    heroID = singleItem.GetItemTypeID()
    commTalentSlot = IpyGameDataPY.GetFuncCfg("HeroStarTalent", 1) # 常规天赋槽个数
    talentMaxLV = IpyGameDataPY.GetFuncCfg("HeroStarTalent", 2) # 每个天赋最大等级
    maxUnlockSlot = commTalentSlot # 最大有效的已解锁槽位
    awakeIpyDataList = IpyGameDataPY.GetIpyGameDataListNotLog("HeroAwake", heroID)
    if awakeIpyDataList:
        awakeLV = singleItem.GetUserAttr(ShareDefine.Def_IudetHeroAwakeLV)
        for ipyData in awakeIpyDataList[:awakeLV][::-1]: # 倒序遍历,第一个命中的就是最大的
            unlockTalentSlot = ipyData.GetUnlockTalentSlot()
            if unlockTalentSlot and unlockTalentSlot :
                maxUnlockSlot = unlockTalentSlot
                break
    idCount = singleItem.GetUserAttrCount(ShareDefine.Def_IudetHeroTalentID)
    lvCount = singleItem.GetUserAttrCount(ShareDefine.Def_IudetHeroTalentIDLV)
    idList, lvList = [], [] # 记录在物品上的值,有顺序
    unfullLVIDList = [] # 未满级的天赋ID
    unfullLVIDListUnlock = [] # 未满级的天赋ID,仅已解锁槽位,重生可能导致觉醒已解锁槽位暂时被锁住
    haveUp = False
    for index in range(min(idCount, lvCount)):
        talentID = singleItem.GetUserAttrByIndex(ShareDefine.Def_IudetHeroTalentID, index)
@@ -492,14 +517,16 @@
        lvList.append(talentLV)
        if talentLV < talentMaxLV:
            unfullLVIDList.append(talentID)
            if index < maxUnlockSlot:
                unfullLVIDListUnlock.append(talentID)
    if len(idList) < commTalentSlot:
        idList += [0] * (commTalentSlot - len(idList))
        lvList += [0] * (commTalentSlot - len(lvList))
        
    GameWorld.DebugLog("执行武将星级天赋等级提升: addLV=%s" % addLV)
    GameWorld.DebugLog("当前星级天赋: idList=%s,lvList=%s" % (idList, lvList))
    GameWorld.DebugLog("未满级星级天赋ID: %s" % unfullLVIDList)
    GameWorld.DebugLog("当前星级天赋: idList=%s,lvList=%s,maxUnlockSlot=%s" % (idList, lvList, maxUnlockSlot))
    GameWorld.DebugLog("未满级星级天赋ID: %s,unfullLVIDListUnlock=%s" % (unfullLVIDList, unfullLVIDListUnlock))
    
    # 有空余槽位,优先给空余槽位天赋,额外解锁的槽位是需要先选择的,所以一定不为空,故这里只判断常规槽位即可
    if 0 in idList:
@@ -531,6 +558,7 @@
            idList[zeroIndex] = randTalentID
            lvList[zeroIndex] = 1
            unfullLVIDList.append(randTalentID)
            unfullLVIDListUnlock.append(randTalentID)
            GameWorld.DebugLog("新增星级天赋ID: %s" % (randTalentID))
            addLV -= 1
            haveUp = True
@@ -540,9 +568,9 @@
        for _ in range(addLV):
            if not unfullLVIDList:
                break
            randID = random.choice(unfullLVIDList)
            # 优先随机已解锁的
            randID = random.choice(unfullLVIDListUnlock) if unfullLVIDListUnlock else random.choice(unfullLVIDList)
            if randID not in idList:
                unfullLVIDList.remove(randID)
                continue
            randIndex = idList.index(randID)
            idLV = lvList[randIndex]
@@ -553,8 +581,11 @@
                GameWorld.DebugLog("升级星级天赋ID: %s,idLV=%s,index=%s" % (randID, idLV, randIndex))
                
            if idLV >= talentMaxLV:
                unfullLVIDList.remove(randID)
                GameWorld.DebugLog("    移除未满级ID: %s,unfullLVIDList=%s" % (randID, unfullLVIDList))
                if randID in unfullLVIDList:
                    unfullLVIDList.remove(randID)
                if randID in unfullLVIDListUnlock:
                    unfullLVIDListUnlock.remove(randID)
                GameWorld.DebugLog("    移除满级ID: %s,unfullLVIDList=%s,unfullLVIDListUnlock=%s" % (randID, unfullLVIDList, unfullLVIDListUnlock))
                
            haveUp = True
            
@@ -1031,6 +1062,20 @@
        __doHeroBookAct(curPlayer, heroID)
    return
def GetHeroBookActCnt(curPlayer):
    ## 获取武将图鉴已激活数量
    bookCnt = 0
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for index in range(ipyDataMgr.GetHeroCount()):
        ipyData = ipyDataMgr.GetHeroByIndex(index)
        heroID = ipyData.GetHeroID()
        if not ipyData.GetPlayerCanUse():
            continue
        if not GetHeroBookInitState(curPlayer, heroID):
            continue
        bookCnt += 1
    return bookCnt
def __doHeroBookAct(curPlayer, heroID):
    ## 图鉴激活
    playerID = curPlayer.GetPlayerID()
@@ -1054,11 +1099,13 @@
    if awardMoneyInfo and len(awardMoneyInfo) == 2:
        moneyType, moneyValue = awardMoneyInfo
        if moneyType and moneyValue:
            PlayerControl.GiveMoney(curPlayer, moneyType, moneyValue, "HeroBookAct")
            PlayerControl.GiveMoney(curPlayer, moneyType, moneyValue, "HeroBookAct", notifyAward=True)
                    
    Sync_HeroInfo(curPlayer, [heroID])
    
    RefreshLordAttr(curPlayer)
    PlayerTask.UpdTaskValue(curPlayer, ChConfig.TaskType_HeroBook)
    return
def __doHeroBookStarLVUP(curPlayer, heroID):
@@ -1183,6 +1230,7 @@
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_HeroAwakeRebirthCnt, rebirthCnt + 1)
        Sync_PlayerHeroInfo(curPlayer)
        
    PlayerOnline.GetOnlinePlayer(curPlayer).OnHeroItemUpate([itemIndex])
    return
def __calcHeroLVReturnitem(quality, heroLV, returnItemDict, ratio):
@@ -1392,7 +1440,7 @@
    for syncItem in syncItemDict.values():
        syncItem.Sync_Item()
        
    lineup = PlayerOnline.GetOnlinePlayer(curPlayer).GetLineup(lineupID)
    lineup = PlayerOnline.GetOnlinePlayer(curPlayer).GetLineup(lineupID, False)
    lineup.UpdLineup(heroItemDict, shapeType)
    return
@@ -1408,6 +1456,41 @@
#    curPlayer.SetResetItemTick(0)
#    ItemControler.ResetItem(curPlayer, ShareDefine.rptHero, 0, 0, tick)
#    return
def GetLineupRecommendAward(curPlayer, recommendID, index):
    ## 领取阵容推荐奖励
    index = GameWorld.ToIntDef(index)
    awardState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_HeroRecommend % recommendID)
    if awardState & pow(2, index):
        GameWorld.DebugLog("阵容推荐奖励已领取! recommendID=%s,index=%s" % (recommendID, index))
        return
    ipyData = IpyGameDataPY.GetIpyGameData("LineupRecommend", recommendID)
    if not ipyData:
        return
    heroIDList = ipyData.GetHeroIDList()
    if index >= len(heroIDList):
        return
    heroID = heroIDList[index]
    heroIpyData = IpyGameDataPY.GetIpyGameData("Hero", heroID)
    if not heroIpyData:
        return
    quality = heroIpyData.GetQuality()
    qualityIpyData = IpyGameDataPY.GetIpyGameData("HeroQuality", quality)
    if not qualityIpyData:
        return
    awardMoneyInfo = qualityIpyData.GetRecommendAwardMoney()
    if not awardMoneyInfo or len(awardMoneyInfo) != 2:
        return
    moneyType, moneyValue = awardMoneyInfo
    if GetHeroActivite(curPlayer, heroID) != 1:
        GameWorld.DebugLog("武将未获得过,不可激活阵容推荐! heroID=%s" % (heroID))
        return
    awardState |= pow(2, index)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_HeroRecommend % recommendID, awardState)
    GameWorld.DebugLog("阵容推荐领奖! recommendID=%s,index=%s,heroID=%s,awardState=%s" % (recommendID, index, heroID, awardState))
    PlayerControl.GiveMoney(curPlayer, moneyType, moneyValue, "LineupRecommend", notifyAward=True)
    Sync_LineupRecommendInfo(curPlayer, [recommendID])
    return
def RefreshLordAttr(curPlayer):
    ## 刷新主公属性
@@ -1425,6 +1508,8 @@
    for index in range(ipyDataMgr.GetHeroCount()):
        ipyData = ipyDataMgr.GetHeroByIndex(index)
        heroID = ipyData.GetHeroID()
        if not ipyData.GetPlayerCanUse():
            continue
        if not GetHeroBookInitState(curPlayer, heroID):
            # 图鉴未激活
            continue
@@ -1453,6 +1538,8 @@
        ipyDataMgr = IpyGameDataPY.IPY_Data()
        for index in range(ipyDataMgr.GetHeroCount()):
            ipyData = ipyDataMgr.GetHeroByIndex(index)
            if not ipyData.GetPlayerCanUse():
                continue
            syncHeroIDList.append(ipyData.GetHeroID())
    
    if not syncHeroIDList:
@@ -1495,7 +1582,7 @@
    lineupList = []
    olPlayer = PlayerOnline.GetOnlinePlayer(curPlayer)
    for lineupID in syncIDList:
        lineup = olPlayer.GetLineup(lineupID)
        lineup = olPlayer.GetLineup(lineupID, False)
        if not lineup:
            continue
        
@@ -1528,3 +1615,30 @@
    clientPack.AwakeRebirthCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_HeroAwakeRebirthCnt)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return
def Sync_LineupRecommendInfo(curPlayer, syncIDList=None):
    recommendList = []
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for index in range(ipyDataMgr.GetLineupRecommendCount()):
        ipyData = ipyDataMgr.GetLineupRecommendByIndex(index)
        recommendID = ipyData.GetRecommendID()
        awardState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_HeroRecommend % recommendID)
        if syncIDList != None:
            if recommendID not in syncIDList:
                continue
        elif not awardState:
            continue
        recommend = ChPyNetSendPack.tagSCLineupRecommend()
        recommend.RecommendID = recommendID
        recommend.AwardState = awardState
        recommendList.append(recommend)
    if not recommendList:
        return
    clientPack = ChPyNetSendPack.tagSCLineupRecommendInfo()
    clientPack.RecommendList = recommendList
    clientPack.Count = len(clientPack.RecommendList)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return