#!/usr/bin/python
|
# -*- coding: GBK -*-
|
#-------------------------------------------------------------------------------
|
#
|
##@package Player.PlayerHJG
|
#
|
# @todo:»Ã¾³¸ó
|
# @author hxp
|
# @date 2025-10-15
|
# @version 1.0
|
#
|
# ÏêϸÃèÊö: »Ã¾³¸ó£¨¹ÜÀí ÐÎÏó¡¢Í·Ïñ¡¢Í·Ïñ¿ò¡¢ÆøÅÝ¡¢³ÆºÅ£©
|
#
|
#-------------------------------------------------------------------------------
|
#"""Version = 2025-10-15 09:30"""
|
#-------------------------------------------------------------------------------
|
|
import GameWorld
|
import ItemCommon
|
import PlayerOnline
|
import PlayerChatBox
|
import PlayerControl
|
import IpyGameDataPY
|
import ChPyNetSendPack
|
import IPY_GameWorld
|
import NetPackCommon
|
import PlayerFace
|
import PlayerHero
|
import ChConfig
|
import ObjPool
|
|
import random
|
import time
|
|
HJGType_Model = 1
|
HJGType_Face = 2
|
HJGType_FacePic = 3
|
HJGType_ChatBox = 4
|
HJGType_Title = 5
|
|
def OnPlayerLogin(curPlayer):
|
SyncTitleInfo(curPlayer)
|
SyncModelInfo(curPlayer)
|
PlayerFace.OnPlayerLogin(curPlayer)
|
PlayerChatBox.OnPlayerLogin(curPlayer)
|
return
|
|
def OnMinute(curPlayer):
|
OnMinuteTitle(curPlayer)
|
OnMinuteModel(curPlayer)
|
PlayerFace.OnMinute(curPlayer)
|
PlayerChatBox.OnMinute(curPlayer)
|
return
|
|
#// B2 25 »Ã¾³¸ó²Ù×÷ #tagCSHJGOP
|
#
|
#struct tagCSHJGOP
|
#{
|
# tagHead Head;
|
# BYTE Type; // ÀàÐÍ 1-ÐÎÏó£»2-Í·Ïñ£»3-Í·Ïñ¿ò£»4-ÆøÅÝ£»5-³ÆºÅ
|
# BYTE OPType; // ²Ù×÷ 1-¼¤»î£»2-Åå´÷£»3-жÏ£»4-ÉýÐÇ
|
# DWORD OPID; // ²Ù×÷¶ÔÓ¦µÄID£¬ÈçÐÎÏóIDµÈ
|
#};
|
def OnHJGOP(index, clientData, tick):
|
curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
|
hjgType = clientData.Type
|
opType = clientData.OPType
|
opID = clientData.OPID
|
|
# ¼¤»î
|
if opType == 1:
|
OnHJGActivate(curPlayer, hjgType, opID)
|
# Åå´÷
|
elif opType == 2:
|
OnHJGUse(curPlayer, hjgType, opID)
|
# жÏÂ
|
elif opType == 3:
|
# Ôݽö³ÆºÅÖ§³ÖжÏÂ
|
if hjgType == HJGType_Title:
|
OnTakeOffTitle(curPlayer, opID)
|
# Éý¼¶
|
elif opType == 4:
|
OnHJGStarUP(curPlayer, hjgType, opID)
|
|
return
|
|
def OnHJGActivate(curPlayer, hjgType, opID):
|
## »Ã¾³¸ó¼¤»î
|
if hjgType == HJGType_Model:
|
AddModel(curPlayer, opID)
|
elif hjgType == HJGType_Face:
|
PlayerFace.AddFace(curPlayer, opID)
|
elif hjgType == HJGType_FacePic:
|
PlayerFace.AddFacePic(curPlayer, opID)
|
elif hjgType == HJGType_ChatBox:
|
PlayerChatBox.AddChatBox(curPlayer, opID)
|
elif hjgType == HJGType_Title:
|
AddTitle(curPlayer, opID)
|
return
|
|
def OnHJGUse(curPlayer, hjgType, opID):
|
## »Ã¾³¸óʹÓÃ/Åå´÷
|
if hjgType == HJGType_Model:
|
OnUseModel(curPlayer, opID)
|
elif hjgType == HJGType_Face:
|
PlayerFace.OnUseFace(curPlayer, opID)
|
elif hjgType == HJGType_FacePic:
|
PlayerFace.OnUseFacePic(curPlayer, opID)
|
elif hjgType == HJGType_ChatBox:
|
PlayerChatBox.OnUseChatBox(curPlayer, opID)
|
elif hjgType == HJGType_Title:
|
OnUseTitle(curPlayer, opID)
|
return
|
|
def OnHJGStarUP(curPlayer, hjgType, opID):
|
## »Ã¾³¸óÉýÐÇ
|
if hjgType == HJGType_Model:
|
OnModelStarUP(curPlayer, opID)
|
elif hjgType == HJGType_Face:
|
PlayerFace.OnFaceStarUP(curPlayer, opID)
|
elif hjgType == HJGType_FacePic:
|
PlayerFace.OnFacePicStarUP(curPlayer, opID)
|
elif hjgType == HJGType_ChatBox:
|
PlayerChatBox.OnChatBoxStarUP(curPlayer, opID)
|
elif hjgType == HJGType_Title:
|
OnTitleStarUP(curPlayer, opID)
|
return
|
|
def RefreshHJGAttr(curPlayer):
|
CalcHJGAttr(curPlayer)
|
PlayerOnline.GetOnlinePlayer(curPlayer).RefreshRoleAttr()
|
return
|
|
def CalcHJGAttr(curPlayer):
|
|
playerID = curPlayer.GetPlayerID()
|
attrDict = {}
|
|
ipyDataMgr = IpyGameDataPY.IPY_Data()
|
# ³ÆºÅ
|
for index in range(ipyDataMgr.GetTitleCount()):
|
ipyData = ipyDataMgr.GetTitleByIndex(index)
|
titleID = ipyData.GetTitleID()
|
if not IsTitleCanUse(curPlayer, titleID, ipyData):
|
continue
|
attrIDList = ipyData.GetAttrIDList()
|
if not attrIDList:
|
continue
|
initAttrValueList = ipyData.GetInitAttrValueList()
|
perStarAddList = ipyData.GetAttrPerStarAddList()
|
star = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TitleStar % titleID)
|
for aIndex, attrID in enumerate(attrIDList):
|
initValue = initAttrValueList[aIndex] if len(initAttrValueList) > aIndex else 0
|
perStarAdd = perStarAddList[aIndex] if len(perStarAddList) > aIndex else 0
|
attrValue = initValue + perStarAdd * star
|
attrDict[attrID] = attrDict.get(attrID, 0) + attrValue
|
#GameWorld.DebugLog("»Ã¾³¸óÀۼӳƺţ¬×ÜÊôÐÔ: %s" % attrDict)
|
|
# ÐÎÏó
|
for index in range(ipyDataMgr.GetModelCount()):
|
ipyData = ipyDataMgr.GetModelByIndex(index)
|
modelID = ipyData.GetModelID()
|
if not IsModelCanUse(curPlayer, modelID, ipyData):
|
continue
|
attrIDList = ipyData.GetAttrIDList()
|
if not attrIDList:
|
continue
|
initAttrValueList = ipyData.GetInitAttrValueList()
|
perStarAddList = ipyData.GetAttrPerStarAddList()
|
star = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ModelStar % modelID)
|
for aIndex, attrID in enumerate(attrIDList):
|
initValue = initAttrValueList[aIndex] if len(initAttrValueList) > aIndex else 0
|
perStarAdd = perStarAddList[aIndex] if len(perStarAddList) > aIndex else 0
|
attrValue = initValue + perStarAdd * star
|
attrDict[attrID] = attrDict.get(attrID, 0) + attrValue
|
#GameWorld.DebugLog("»Ã¾³¸óÀÛ¼ÓÐÎÏó£¬×ÜÊôÐÔ: %s" % attrDict)
|
|
# Í·Ïñ
|
for index in range(ipyDataMgr.GetPlayerFaceCount()):
|
ipyData = ipyDataMgr.GetPlayerFaceByIndex(index)
|
faceID = ipyData.GetFaceID()
|
if not PlayerFace.IsFaceCanUse(curPlayer, faceID, ipyData):
|
continue
|
attrIDList = ipyData.GetAttrIDList()
|
if not attrIDList:
|
continue
|
initAttrValueList = ipyData.GetInitAttrValueList()
|
perStarAddList = ipyData.GetAttrPerStarAddList()
|
star = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FaceStar % faceID)
|
for aIndex, attrID in enumerate(attrIDList):
|
initValue = initAttrValueList[aIndex] if len(initAttrValueList) > aIndex else 0
|
perStarAdd = perStarAddList[aIndex] if len(perStarAddList) > aIndex else 0
|
attrValue = initValue + perStarAdd * star
|
attrDict[attrID] = attrDict.get(attrID, 0) + attrValue
|
#GameWorld.DebugLog("»Ã¾³¸óÀÛ¼ÓÍ·Ïñ£¬×ÜÊôÐÔ: %s" % attrDict)
|
|
# Í·Ïñ¿ò
|
for index in range(ipyDataMgr.GetPlayerFacePicCount()):
|
ipyData = ipyDataMgr.GetPlayerFacePicByIndex(index)
|
facePicID = ipyData.GetFacePicID()
|
if not PlayerFace.IsFacePicCanUse(curPlayer, facePicID, ipyData):
|
continue
|
attrIDList = ipyData.GetAttrIDList()
|
if not attrIDList:
|
continue
|
initAttrValueList = ipyData.GetInitAttrValueList()
|
perStarAddList = ipyData.GetAttrPerStarAddList()
|
star = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FacePicStar % facePicID)
|
for aIndex, attrID in enumerate(attrIDList):
|
initValue = initAttrValueList[aIndex] if len(initAttrValueList) > aIndex else 0
|
perStarAdd = perStarAddList[aIndex] if len(perStarAddList) > aIndex else 0
|
attrValue = initValue + perStarAdd * star
|
attrDict[attrID] = attrDict.get(attrID, 0) + attrValue
|
#GameWorld.DebugLog("»Ã¾³¸óÀÛ¼ÓÍ·¿ò£¬×ÜÊôÐÔ: %s" % attrDict)
|
|
# ÆøÅÝ¿ò
|
for index in range(ipyDataMgr.GetChatBoxCount()):
|
ipyData = ipyDataMgr.GetChatBoxByIndex(index)
|
boxID = ipyData.GetBoxID()
|
if not PlayerChatBox.IsBoxCanUse(curPlayer, boxID, ipyData):
|
continue
|
attrIDList = ipyData.GetAttrIDList()
|
if not attrIDList:
|
continue
|
initAttrValueList = ipyData.GetInitAttrValueList()
|
perStarAddList = ipyData.GetAttrPerStarAddList()
|
star = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ChatBoxStar % boxID)
|
for aIndex, attrID in enumerate(attrIDList):
|
initValue = initAttrValueList[aIndex] if len(initAttrValueList) > aIndex else 0
|
perStarAdd = perStarAddList[aIndex] if len(perStarAddList) > aIndex else 0
|
attrValue = initValue + perStarAdd * star
|
attrDict[attrID] = attrDict.get(attrID, 0) + attrValue
|
#GameWorld.DebugLog("»Ã¾³¸óÀÛ¼ÓÆøÅÝ£¬×ÜÊôÐÔ: %s" % attrDict)
|
|
# ±£´æ¼ÆËãÖµ
|
GameWorld.DebugLog("»Ã¾³¸óÊôÐÔ: %s" % attrDict, playerID)
|
PlayerOnline.GetOnlinePlayer(curPlayer).SetCalcAttr(ChConfig.Def_CalcAttr_HJG, attrDict)
|
return
|
|
## ----------------------------------------- ³ÆºÅ --------------------------------------------------
|
|
def OnMinuteTitle(curPlayer):
|
curTime = int(time.time())
|
|
delIDList = []
|
ipyDataMgr = IpyGameDataPY.IPY_Data()
|
for index in range(ipyDataMgr.GetTitleCount()):
|
ipyData = ipyDataMgr.GetTitleByIndex(index)
|
titleID = ipyData.GetTitleID()
|
if not GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_TitleState, titleID):
|
# δ¼¤»îµÄ²»´¦Àí
|
continue
|
endTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TitleEndTime % titleID)
|
if not endTime or endTime > curTime:
|
# ÓÀ¾Ã»òδ¹ýÆÚ
|
continue
|
if DelTitle(curPlayer, titleID, False, "TitleTimeout"):
|
delIDList.append(titleID)
|
|
if delIDList:
|
RefreshHJGAttr(curPlayer)
|
return
|
|
def AddTitle(curPlayer, titleID, setExpireTimes=None, isFree=False):
|
if titleID <= 0:
|
return
|
playerID = curPlayer.GetPlayerID()
|
ipyData = IpyGameDataPY.GetIpyGameData("Title", titleID)
|
if not ipyData:
|
return
|
if ipyData.GetUnlockWay() != 2:
|
GameWorld.DebugLog("·ÇµÀ¾ß¼¤»îµÄ²»ÓÃÌí¼Ó: titleID=%s" % (titleID), playerID)
|
return
|
if not isFree:
|
itemID = ipyData.GetUnlockValue()
|
itemCount = ipyData.GetUnlockNeedCnt()
|
if not itemID or not itemCount:
|
return
|
needItemList = [[itemID, itemCount]]
|
itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
|
lackItemDict, delInfoDict = ItemCommon.GetCostItemIndexList(needItemList, itemPack)
|
if lackItemDict:
|
GameWorld.DebugLog("¼¤»îËùÐèÎïÆ·²»×ã! titleID=%s,lackItemDict=%s" % (titleID, lackItemDict), playerID)
|
return
|
ItemCommon.DelCostItem(curPlayer, itemPack, delInfoDict, "AddTitle")
|
|
ipyExpireSeconds = ipyData.GetExpireMinutes() * 60
|
|
curTime = int(time.time())
|
state = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_TitleState, titleID)
|
endTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TitleEndTime % titleID)
|
GameWorld.Log("Ìí¼Ó³ÆºÅ: titleID=%s,setExpireTimes=%s,state=%s,endTime=%s,ipyExpireSeconds=%s,curTime=%s"
|
% (titleID, setExpireTimes, state, endTime, ipyExpireSeconds, curTime), playerID)
|
updEndTime = endTime
|
|
# Ö¸¶¨Ê±³¤µÄ£¬ÈçGMÖ¸¶¨
|
if setExpireTimes > 0:
|
updEndTime = curTime + setExpireTimes
|
GameWorld.Log(" Ö¸¶¨Ê±³¤: titleID=%s,updEndTime=%s" % (titleID, updEndTime), playerID)
|
|
# ÓÀ¾Ã
|
elif ipyExpireSeconds == 0 or setExpireTimes == 0:
|
updEndTime = 0
|
GameWorld.Log(" ÓÀ¾Ãʱ³¤: titleID=%s,updEndTime=%s" % (titleID, updEndTime), playerID)
|
|
else:
|
# δ¹ýÆÚ
|
if endTime > curTime:
|
updEndTime = endTime + ipyExpireSeconds
|
GameWorld.Log(" ÀÛ¼Óʱ³¤: titleID=%s,updEndTime=%s" % (titleID, updEndTime), playerID)
|
else:
|
updEndTime = curTime + ipyExpireSeconds
|
GameWorld.Log(" ÖØÐ¼¤»î: titleID=%s,updEndTime=%s" % (titleID, updEndTime), playerID)
|
|
GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_TitleState, titleID, 1)
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TitleEndTime % titleID, updEndTime)
|
RefreshHJGAttr(curPlayer)
|
SyncTitleInfo(curPlayer, [titleID])
|
return True
|
|
def DelTitle(curPlayer, titleID, isRefreshAttr=True, notifyMail=""):
|
playerID = curPlayer.GetPlayerID()
|
ipyData = IpyGameDataPY.GetIpyGameData("Title", titleID)
|
if not ipyData:
|
return
|
if not GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_TitleState, titleID):
|
return
|
GameWorld.Log("ɾ³ý³ÆºÅ: titleID=%s,notifyMail=%s" % (titleID, notifyMail), playerID)
|
GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_TitleState, titleID, 0)
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TitleEndTime % titleID, 0)
|
# ÐǼ¶²»ÖØÖã¬ÖØÐ¼¤»îºóÔÙ´ÎÉúЧ
|
|
if PlayerControl.GetTitleID(curPlayer) == titleID:
|
defaultIDList = GetDefaultTitleIDList()
|
randID = random.choice(defaultIDList) if defaultIDList else 0
|
PlayerControl.SetTitleID(curPlayer, randID)
|
GameWorld.DebugLog("Íæ¼ÒÅå´÷µÄ³ÆºÅ±»É¾³ý£¬Ëæ»úÖØÖÃĬÈÏ! randID=%s" % randID, playerID)
|
|
if isRefreshAttr:
|
RefreshHJGAttr(curPlayer)
|
SyncTitleInfo(curPlayer, [titleID])
|
if notifyMail:
|
PlayerControl.SendMailByKey(notifyMail, [playerID], [], [titleID])
|
|
return True
|
|
def GetDefaultTitleIDList():
|
defaultIDList = []
|
ipyDataMgr = IpyGameDataPY.IPY_Data()
|
for index in range(ipyDataMgr.GetTitleCount()):
|
ipyData = ipyDataMgr.GetTitleByIndex(index)
|
titleID = ipyData.GetTitleID()
|
if ipyData.GetUnlockWay() != 1:
|
continue
|
defaultIDList.append(titleID)
|
return defaultIDList
|
|
def IsTitleCanUse(curPlayer, titleID, ipyData=None):
|
## ³ÆºÅÊÇ·ñ¿ÉÓÃ
|
state = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_TitleState, titleID)
|
if state:
|
return True
|
|
if not ipyData:
|
ipyData = IpyGameDataPY.GetIpyGameData("Title", titleID)
|
if ipyData:
|
unlockWay = ipyData.GetUnlockWay()
|
if unlockWay == 1: # ĬÈϼ¤»îµÄ
|
return True
|
|
return False
|
|
def OnUseTitle(curPlayer, titleID):
|
playerID = curPlayer.GetPlayerID()
|
if not IsTitleCanUse(curPlayer, titleID):
|
GameWorld.DebugLog("¸Ã³ÆºÅ²»¿ÉÓÃ! titleID=%s" % (titleID), playerID)
|
return
|
GameWorld.DebugLog("ʹÓóƺÅ! titleID=%s" % (titleID), playerID)
|
PlayerControl.SetTitleID(curPlayer, titleID)
|
return
|
|
def OnTakeOffTitle(curPlayer, titleID):
|
if PlayerControl.GetTitleID(curPlayer) != titleID:
|
return
|
PlayerControl.SetTitleID(curPlayer, 0)
|
return
|
|
def OnTitleStarUP(curPlayer, titleID):
|
playerID = curPlayer.GetPlayerID()
|
if not IsTitleCanUse(curPlayer, titleID):
|
GameWorld.DebugLog("¸Ã³ÆºÅ²»¿ÉÓÃ! titleID=%s" % (titleID), playerID)
|
return
|
ipyData = IpyGameDataPY.GetIpyGameData("Title", titleID)
|
if not ipyData:
|
return
|
starMax = ipyData.GetStarMax()
|
curStar = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TitleStar % titleID)
|
if curStar >= starMax:
|
GameWorld.DebugLog("ÐǼ¶ÒÑÂú! titleID=%s,curStar=%s >= %s" % (titleID, curStar, starMax), playerID)
|
return
|
if ipyData.GetUnlockWay() != 2:
|
return
|
itemID = ipyData.GetUnlockValue()
|
itemCount = ipyData.GetUnlockNeedCnt()
|
if not itemID or not itemCount:
|
return
|
needItemList = [[itemID, itemCount]]
|
itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
|
lackItemDict, delInfoDict = ItemCommon.GetCostItemIndexList(needItemList, itemPack)
|
if lackItemDict:
|
GameWorld.DebugLog("ÉýÐÇËùÐèÎïÆ·²»×ã! titleID=%s,lackItemDict=%s" % (titleID, lackItemDict), playerID)
|
return
|
ItemCommon.DelCostItem(curPlayer, itemPack, delInfoDict, "TitleStarUP")
|
|
nextStar = curStar + 1
|
GameWorld.DebugLog("ÉýÐÇ! titleID=%s,nextStar=%s" % (titleID, nextStar), playerID)
|
SetTitleStar(curPlayer, titleID, nextStar)
|
return
|
|
def SetTitleStar(curPlayer, titleID, setStar):
|
if not IsTitleCanUse(curPlayer, titleID):
|
return
|
ipyData = IpyGameDataPY.GetIpyGameData("Title", titleID)
|
if not ipyData:
|
return
|
setStar = min(setStar, ipyData.GetStarMax())
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TitleStar % titleID, setStar)
|
RefreshHJGAttr(curPlayer)
|
SyncTitleInfo(curPlayer, [titleID])
|
return True
|
|
def SyncTitleInfo(curPlayer, titleIDList=None):
|
if titleIDList == None:
|
syncIDList = []
|
ipyDataMgr = IpyGameDataPY.IPY_Data()
|
for index in range(ipyDataMgr.GetTitleCount()):
|
ipyData = ipyDataMgr.GetTitleByIndex(index)
|
syncIDList.append(ipyData.GetTitleID())
|
else:
|
syncIDList = titleIDList
|
|
titleList = []
|
for titleID in syncIDList:
|
state = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_TitleState, titleID)
|
if not state and titleIDList == None:
|
continue
|
title = ObjPool.GetPoolMgr().acquire(ChPyNetSendPack.tagSCTitle)
|
title.TitleID = titleID
|
title.State = state
|
title.EndTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TitleEndTime % titleID)
|
title.Star = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TitleStar % titleID)
|
titleList.append(title)
|
|
if not titleList:
|
return
|
|
clientPack = ObjPool.GetPoolMgr().acquire(ChPyNetSendPack.tagSCTitleInfo)
|
clientPack.TitleList = titleList
|
clientPack.Count = len(clientPack.TitleList)
|
NetPackCommon.SendFakePack(curPlayer, clientPack)
|
return
|
## -------------------------------------------------------------------------------------------------
|
|
## ----------------------------------------- ÐÎÏó --------------------------------------------------
|
|
def OnMinuteModel(curPlayer):
|
curTime = int(time.time())
|
|
delIDList = []
|
ipyDataMgr = IpyGameDataPY.IPY_Data()
|
for index in range(ipyDataMgr.GetModelCount()):
|
ipyData = ipyDataMgr.GetModelByIndex(index)
|
modelID = ipyData.GetModelID()
|
if not GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ModelState, modelID):
|
# δ¼¤»îµÄ²»´¦Àí
|
continue
|
endTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ModelEndTime % modelID)
|
if not endTime or endTime > curTime:
|
# ÓÀ¾Ã»òδ¹ýÆÚ
|
continue
|
if DelModel(curPlayer, modelID, False, "ModelTimeout"):
|
delIDList.append(modelID)
|
|
if delIDList:
|
RefreshHJGAttr(curPlayer)
|
return
|
|
def AddModel(curPlayer, modelID, setExpireTimes=None, isFree=False):
|
if modelID <= 0:
|
return
|
playerID = curPlayer.GetPlayerID()
|
ipyData = IpyGameDataPY.GetIpyGameData("Model", modelID)
|
if not ipyData:
|
return
|
if ipyData.GetUnlockWay() != 2:
|
GameWorld.DebugLog("·ÇµÀ¾ß¼¤»îµÄ²»ÓÃÌí¼Ó: modelID=%s" % (modelID), playerID)
|
return
|
if not isFree:
|
itemID = ipyData.GetUnlockValue()
|
itemCount = ipyData.GetUnlockNeedCnt()
|
if not itemID or not itemCount:
|
return
|
needItemList = [[itemID, itemCount]]
|
itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
|
lackItemDict, delInfoDict = ItemCommon.GetCostItemIndexList(needItemList, itemPack)
|
if lackItemDict:
|
GameWorld.DebugLog("¼¤»îËùÐèÎïÆ·²»×ã! modelID=%s,lackItemDict=%s" % (modelID, lackItemDict), playerID)
|
return
|
ItemCommon.DelCostItem(curPlayer, itemPack, delInfoDict, "AddModel")
|
|
ipyExpireSeconds = ipyData.GetExpireMinutes() * 60
|
|
curTime = int(time.time())
|
state = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ModelState, modelID)
|
endTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ModelEndTime % modelID)
|
GameWorld.Log("Ìí¼ÓÐÎÏó: modelID=%s,setExpireTimes=%s,state=%s,endTime=%s,ipyExpireSeconds=%s,curTime=%s"
|
% (modelID, setExpireTimes, state, endTime, ipyExpireSeconds, curTime), playerID)
|
updEndTime = endTime
|
|
# Ö¸¶¨Ê±³¤µÄ£¬ÈçGMÖ¸¶¨
|
if setExpireTimes > 0:
|
updEndTime = curTime + setExpireTimes
|
GameWorld.Log(" Ö¸¶¨Ê±³¤: modelID=%s,updEndTime=%s" % (modelID, updEndTime), playerID)
|
|
# ÓÀ¾Ã
|
elif ipyExpireSeconds == 0 or setExpireTimes == 0:
|
updEndTime = 0
|
GameWorld.Log(" ÓÀ¾Ãʱ³¤: modelID=%s,updEndTime=%s" % (modelID, updEndTime), playerID)
|
|
else:
|
# δ¹ýÆÚ
|
if endTime > curTime:
|
updEndTime = endTime + ipyExpireSeconds
|
GameWorld.Log(" ÀÛ¼Óʱ³¤: modelID=%s,updEndTime=%s" % (modelID, updEndTime), playerID)
|
else:
|
updEndTime = curTime + ipyExpireSeconds
|
GameWorld.Log(" ÖØÐ¼¤»î: modelID=%s,updEndTime=%s" % (modelID, updEndTime), playerID)
|
|
GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_ModelState, modelID, 1)
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ModelEndTime % modelID, updEndTime)
|
RefreshHJGAttr(curPlayer)
|
SyncModelInfo(curPlayer, [modelID])
|
return True
|
|
def DelModel(curPlayer, modelID, isRefreshAttr=True, notifyMail=""):
|
playerID = curPlayer.GetPlayerID()
|
ipyData = IpyGameDataPY.GetIpyGameData("Model", modelID)
|
if not ipyData:
|
return
|
if not GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ModelState, modelID):
|
return
|
GameWorld.Log("ɾ³ýÐÎÏó: modelID=%s,notifyMail=%s" % (modelID, notifyMail), playerID)
|
GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_ModelState, modelID, 0)
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ModelEndTime % modelID, 0)
|
# ÐǼ¶²»ÖØÖã¬ÖØÐ¼¤»îºóÔÙ´ÎÉúЧ
|
|
if curPlayer.GetModelMark() == modelID:
|
defaultIDList = GetDefaultModelIDList()
|
randID = random.choice(defaultIDList) if defaultIDList else 0
|
curPlayer.SetModelMark(randID)
|
GameWorld.DebugLog("Íæ¼ÒʹÓõÄÐÎÏó±»É¾³ý£¬Ëæ»úÖØÖÃĬÈÏ! randID=%s" % randID, playerID)
|
|
if isRefreshAttr:
|
RefreshHJGAttr(curPlayer)
|
SyncModelInfo(curPlayer, [modelID])
|
if notifyMail:
|
PlayerControl.SendMailByKey(notifyMail, [playerID], [], [modelID])
|
|
return True
|
|
def GetDefaultModelIDList():
|
defaultIDList = []
|
ipyDataMgr = IpyGameDataPY.IPY_Data()
|
for index in range(ipyDataMgr.GetModelCount()):
|
ipyData = ipyDataMgr.GetModelByIndex(index)
|
modelID = ipyData.GetModelID()
|
if ipyData.GetUnlockWay() != 1:
|
continue
|
defaultIDList.append(modelID)
|
return defaultIDList
|
|
def IsModelCanUse(curPlayer, modelID, ipyData=None):
|
## ÐÎÏóÊÇ·ñ¿ÉÓÃ
|
state = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ModelState, modelID)
|
if state:
|
return True
|
|
if not ipyData:
|
ipyData = IpyGameDataPY.GetIpyGameData("Model", modelID)
|
if ipyData:
|
unlockWay = ipyData.GetUnlockWay()
|
unlockValue = ipyData.GetUnlockValue()
|
if unlockWay == 1: # ĬÈϼ¤»îµÄ
|
return True
|
if unlockWay == 3: # ¹ØÁªÎ佫
|
heroID = unlockValue
|
return True if PlayerHero.GetHeroActivite(curPlayer, heroID) else False
|
|
return False
|
|
def OnUseModel(curPlayer, modelID):
|
playerID = curPlayer.GetPlayerID()
|
if not IsModelCanUse(curPlayer, modelID):
|
GameWorld.DebugLog("¸ÃÐÎÏ󲻿ÉÓÃ! modelID=%s" % (modelID), playerID)
|
return
|
GameWorld.DebugLog("ʹÓÃÐÎÏó! modelID=%s" % (modelID), playerID)
|
curPlayer.SetModelMark(modelID)
|
return
|
|
def OnModelStarUP(curPlayer, modelID):
|
playerID = curPlayer.GetPlayerID()
|
if not IsModelCanUse(curPlayer, modelID):
|
GameWorld.DebugLog("¸ÃÐÎÏ󲻿ÉÓÃ! modelID=%s" % (modelID), playerID)
|
return
|
ipyData = IpyGameDataPY.GetIpyGameData("Model", modelID)
|
if not ipyData:
|
return
|
starMax = ipyData.GetStarMax()
|
curStar = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ModelStar % modelID)
|
if curStar >= starMax:
|
GameWorld.DebugLog("ÐǼ¶ÒÑÂú! modelID=%s,curStar=%s >= %s" % (modelID, curStar, starMax), playerID)
|
return
|
if ipyData.GetUnlockWay() != 2:
|
return
|
itemID = ipyData.GetUnlockValue()
|
itemCount = ipyData.GetUnlockNeedCnt()
|
if not itemID or not itemCount:
|
return
|
needItemList = [[itemID, itemCount]]
|
itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
|
lackItemDict, delInfoDict = ItemCommon.GetCostItemIndexList(needItemList, itemPack)
|
if lackItemDict:
|
GameWorld.DebugLog("ÉýÐÇËùÐèÎïÆ·²»×ã! modelID=%s,lackItemDict=%s" % (modelID, lackItemDict), playerID)
|
return
|
ItemCommon.DelCostItem(curPlayer, itemPack, delInfoDict, "ModelStarUP")
|
|
nextStar = curStar + 1
|
GameWorld.DebugLog("ÉýÐÇ! modelID=%s,nextStar=%s" % (modelID, nextStar), playerID)
|
SetModelStar(curPlayer, modelID, nextStar)
|
return
|
|
def SetModelStar(curPlayer, modelID, setStar):
|
if not IsModelCanUse(curPlayer, modelID):
|
return
|
ipyData = IpyGameDataPY.GetIpyGameData("Model", modelID)
|
if not ipyData:
|
return
|
setStar = min(setStar, ipyData.GetStarMax())
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ModelStar % modelID, setStar)
|
RefreshHJGAttr(curPlayer)
|
SyncModelInfo(curPlayer, [modelID])
|
return True
|
|
def SyncModelInfo(curPlayer, modelIDList=None):
|
if modelIDList == None:
|
syncIDList = []
|
ipyDataMgr = IpyGameDataPY.IPY_Data()
|
for index in range(ipyDataMgr.GetModelCount()):
|
ipyData = ipyDataMgr.GetModelByIndex(index)
|
syncIDList.append(ipyData.GetModelID())
|
else:
|
syncIDList = modelIDList
|
|
modelList = []
|
for modelID in syncIDList:
|
state = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_ModelState, modelID)
|
if not state and modelIDList == None:
|
continue
|
model = ObjPool.GetPoolMgr().acquire(ChPyNetSendPack.tagSCModel)
|
model.ModelID = modelID
|
model.State = state
|
model.EndTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ModelEndTime % modelID)
|
model.Star = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ModelStar % modelID)
|
modelList.append(model)
|
|
if not modelList:
|
return
|
|
clientPack = ObjPool.GetPoolMgr().acquire(ChPyNetSendPack.tagSCModelInfo)
|
clientPack.ModelList = modelList
|
clientPack.Count = len(clientPack.ModelList)
|
NetPackCommon.SendFakePack(curPlayer, clientPack)
|
return
|
## -------------------------------------------------------------------------------------------------
|