提交 | 用户 | age
3d3a72 1 #!/usr/bin/python
H 2 # -*- coding: GBK -*-
3 #-------------------------------------------------------------------------------
4 #
5 ##@package Player.PlayerMineArea
6 #
7 # @todo:矿物福地
8 # @author hxp
9 # @date 2024-03-07
10 # @version 1.0
11 #
12 # 详细描述: 矿物福地
13 #
14 #-------------------------------------------------------------------------------
15 #"""Version = 2024-03-07 19:30"""
16 #-------------------------------------------------------------------------------
17
18 import ChConfig
19 import PlayerControl
20 import IpyGameDataPY
21 import IPY_GameWorld
22 import ChPyNetSendPack
789490 23 import PlayerActTask
3d3a72 24 import NetPackCommon
H 25 import ItemControler
3b08e8 26 import PlayerSuccess
H 27 import ShareDefine
3d3a72 28 import ItemCommon
H 29 import GameWorld
30
31 # 聚宝盆默认最大进度
32 MineTreasureProgressMax = 100
33
34 def OnPlayerLogin(curPlayer):
174784 35     freeWorkerCount = 0
H 36     workerNeedItemList = IpyGameDataPY.GetFuncEvalCfg("MineAreaWorker", 3)
37     for needItemCount in workerNeedItemList:
38         if needItemCount:
39             break
40         freeWorkerCount += 1
41     if freeWorkerCount > curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MineWorkerCount):
42         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MineWorkerCount, freeWorkerCount)
3d3a72 43     SyncPlayerMineAreaInfo(curPlayer)
H 44     return
45
46 def PlayerOnDay(curPlayer):
d7e6ef 47     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MineHelpAwardCount, 0)
3d3a72 48     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MineWorkerEnergyUsed, 0)
H 49     for refreshType in [0, 1]:
50         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MineRefreshCount % refreshType, 0)
51     SyncPlayerMineAreaInfo(curPlayer)
52     return
53
54 def GetWorkerTotal(curPlayer):
55     ## 获取玩家工人总数
56     initCount = 0 # 起始默认工人数
57     employCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MineWorkerCount)
58     return initCount + employCount
59
60 def GetWorkerState(curPlayer):
61     ## 获取工人疲劳状态
62     workerStateEnergyList = IpyGameDataPY.GetFuncEvalCfg("MineAreaWorker", 1) # 工人疲劳状态体力列表 [充沛体力, 正常, 虚弱, 枯竭],总体力=所有体力相加
63     funcEnergy = 0 # 其他功能增加的体力
64     stateEnergy = 0
65     energyUsed = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MineWorkerEnergyUsed)
66     for state, energy in enumerate(workerStateEnergyList):
67         if state == 0:
68             energy += funcEnergy
69         stateEnergy += energy
70         if energyUsed <= stateEnergy:
71             return state
72     return len(workerStateEnergyList) - 1 # 默认最大疲劳
73
74 #// B0 30 福地物品拉 #tagCMMineItemPull
75 #
76 #struct    tagCMMineItemPull
77 #{
78 #    tagHead        Head;
79 #    DWORD        PlayerID;        // 福地所属玩家ID,0默认自己
80 #    BYTE        ItemIndex;    // 物品所在位置索引0~n
81 #    BYTE        WorkerCount;    // 上工人人数
82 #    BYTE        IsPreview;    // 是否预览;0-直接拉,1-预览大概时间
83 #};
84 def OnMineItemPull(index, clientData, tick):
85     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
86     areaPlayerID = clientData.PlayerID
87     itemIndex = clientData.ItemIndex
88     workerCount = clientData.WorkerCount
89     isPreview = clientData.IsPreview
90     if not areaPlayerID:
91         areaPlayerID = curPlayer.GetPlayerID()
92         
93     workerTotal = GetWorkerTotal(curPlayer)
94     workerState = GetWorkerState(curPlayer)
95     
96     SendToGameServer_MineArea(curPlayer, "Pull", [areaPlayerID, itemIndex, workerCount, workerState, workerTotal, isPreview])
97     return
98
99 #// B0 31 福地物品刷新 #tagCMMineItemRefresh
100 #
101 #struct    tagCMMineItemRefresh
102 #
103 #{
104 #    tagHead        Head;
105 #    BYTE        IsSuper;    // 是否超级刷新
106 #};
107 def OnMineItemRefresh(index, clientData, tick):
108     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
109     playerID = curPlayer.GetPlayerID()
110     isSuper = clientData.IsSuper
111     
112     refreshType = str(1 if isSuper else 0)
113     
114     moneyDict = IpyGameDataPY.GetFuncEvalCfg("MineAreaRefresh", 1, {})
115     if refreshType not in moneyDict:
116         return
117     moneyType, moneyValue = moneyDict[refreshType]
118     if not PlayerControl.HaveMoney(curPlayer, moneyType, moneyValue):
119         return
120     
121     refreshMaxDict = IpyGameDataPY.GetFuncEvalCfg("MineAreaRefresh", 2, {})
122     refreshCountMax = refreshMaxDict.get(refreshType, 0)
123     refreshCountNow = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MineRefreshCount % refreshType)
124     if refreshCountMax and refreshCountNow >= refreshCountMax:
125         GameWorld.DebugLog("福地物品刷新次数已达今日上限! isSuper=%s,refreshCountNow=%s >= %s" % (isSuper, refreshCountNow, refreshCountMax), playerID)
126         return
127     
128     PlayerControl.PayMoney(curPlayer, moneyType, moneyValue, "MineItemRefresh")
129     if refreshCountMax:
130         refreshCountUpd = refreshCountNow + 1
131         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MineRefreshCount % refreshType, refreshCountUpd)            
132         SyncPlayerMineAreaInfo(curPlayer)
133         
134     SendToGameServer_MineArea(curPlayer, "MineItemRefresh", [playerID, isSuper])
135     return
136
137 #// B0 32 福地工人雇佣 #tagCMMineWorkerEmploy
138 #
139 #struct    tagCMMineWorkerEmploy
140 #
141 #{
142 #    tagHead        Head;
143 #};
144 def OnMineWorkerEmploy(index, clientData, tick):
145     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
146     playerID = curPlayer.GetPlayerID()
147     employCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MineWorkerCount)
148     
149     costItemCountList = IpyGameDataPY.GetFuncEvalCfg("MineAreaWorker", 3)
150     if employCount >= len(costItemCountList):
151         GameWorld.DebugLog("已达到福地雇佣工人数上限! employCount=%s" % employCount)
152         return
153     costItemCount = costItemCountList[employCount]
154     costItemID = IpyGameDataPY.GetFuncCfg("MineAreaWorker", 2)
155     if not costItemID:
156         return
157     
158     # 支持配0不消耗个数
159     if costItemCount > 0:
160         costItemIndexList, bindCnt, unBindCnt = ItemCommon.GetPackItemBindStateIndexInfo(curPlayer, costItemID, costItemCount)
161         lackCnt = costItemCount - bindCnt - unBindCnt
162         if lackCnt > 0:
163             GameWorld.DebugLog("福地雇佣工人道具不足! costItemID=%s,costItemCount=%s,bindCnt=%s,unBindCnt=%s,lackCnt=%s,已雇佣数=%s" 
164                                % (costItemID, costItemCount, bindCnt, unBindCnt, lackCnt, employCount))
165             return
166         delCnt = costItemCount
167         ItemCommon.DelCostItemByBind(curPlayer, costItemIndexList, bindCnt, unBindCnt, delCnt, "MineWorkerEmploy")
168         
169     updEmployCount = employCount + 1
170     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MineWorkerCount, updEmployCount)
171     SyncPlayerMineAreaInfo(curPlayer)
172     GameWorld.DebugLog("福地雇佣工人! costItemID=%s,costItemCount=%s,updEmployCount=%s" % (costItemID, costItemCount, updEmployCount), playerID)
173     return
174
175 def SendToGameServer_MineArea(curPlayer, msgType, dataMsg=""):
176     playerID = curPlayer.GetPlayerID()
177     msgList = str([msgType, dataMsg])
178     GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(playerID, 0, 0, "MineArea", msgList, len(msgList))
179     GameWorld.Log("福地发送GameServer: %s, %s" % (msgType, dataMsg), playerID)
180     return
181
182 def GameServer_MineArea_DoResult(curPlayer, msgData):
183     
184     msgType, dataMsg, _ = msgData
185     
186     ## 结算奖励
187     if msgType == "MineAreaAwardGet":
188         awardInfoList = dataMsg[0]
189         __DoGiveMineAreaAward(curPlayer, awardInfoList)
789490 190           
H 191     ## 取消拉取 (包含主动 或 被动驱赶)
192     elif msgType == "MineAreaCancelPull":
193         areaPlayerID, reason =  dataMsg
194         __OnMineAreaPullEnd(curPlayer, areaPlayerID, reason)
195         
3d3a72 196     return
H 197
198 def __DoGiveMineAreaAward(curPlayer, awardInfoList):
199     
200     playerID = curPlayer.GetPlayerID()
201     energyUsed = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MineWorkerEnergyUsed)
202     addEnergyUsed = 0
203     awardItemDict = {}
204     robCount = 0 # 抢劫数
3b08e8 205     selfCount = 0 # 自己数量
3d3a72 206     GUIDList = []
H 207     for awardInfo in awardInfoList:
208         GUID, awardTime, workerCount, areaPlayerID, mineID, itemLV, itemID, itemCount = awardInfo
209         isToday = GameWorld.CheckTimeIsSameServerDayEx(awardTime)
210         if isToday:
211             addEnergyUsed += workerCount
212         if playerID != areaPlayerID:
213             robCount += 1
3b08e8 214         else:
H 215             selfCount += 1
3d3a72 216         awardItemDict[itemID] = awardItemDict.get(itemID, 0) + itemCount
H 217         GUIDList.append(GUID)
218         GameWorld.DebugLog("结算福地奖励! areaPlayerID=%s,mineID=%s,itemLV=%s,itemID=%s,itemCount=%s,awardTime=%s,isToday=%s,workerCount=%s %s" 
219                            % (areaPlayerID, mineID, itemLV, itemID, itemCount, GameWorld.ChangeTimeNumToStr(awardTime), isToday, workerCount, GUID), playerID)
789490 220         __OnMineAreaPullEnd(curPlayer, areaPlayerID, "OK")
3d3a72 221         
H 222     if addEnergyUsed:
223         energyUsed += addEnergyUsed
224         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MineWorkerEnergyUsed, energyUsed)
225         GameWorld.DebugLog("    增加福地工人已用精力! addEnergyUsed=%s,updEnergyUsed=%s" % (addEnergyUsed, energyUsed), playerID)
226         
3b08e8 227     PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_MineAreaCnt, selfCount + robCount)
H 228     if selfCount:
229         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_MineAreaSelfCnt, selfCount)
3d3a72 230     if robCount:
3b08e8 231         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_MineAreaRobCnt, robCount)
3d3a72 232         OnAddMineTreasureProgress(curPlayer, robCount, False)
H 233         
234     SyncPlayerMineAreaInfo(curPlayer)
235     
236     awardItemList = [[itemID, itemCount, 0] for itemID, itemCount in awardItemDict.items()]
237     ItemControler.GivePlayerItemOrMail(curPlayer, awardItemList, None, ["MineAreaAward", False, {}])
238     
239     SendToGameServer_MineArea(curPlayer, "MineAreaAwardGetOK", [GUIDList, awardItemList])
240     return
241
789490 242 def __OnMineAreaPullEnd(curPlayer, areaPlayerID, reason):
H 243     ## 拉取结束额外处理, 包含拉完、取消、被驱赶等
244     GameWorld.DebugLog("__OnMineAreaPullEnd: areaPlayerID=%s, reason=%s" % (areaPlayerID, reason))
245     if curPlayer.GetPlayerID() == areaPlayerID:
246         PlayerActTask.AddActTaskValue(curPlayer, ChConfig.ActTaskType_MineAreaEndSelf)
247     else:
248         PlayerActTask.AddActTaskValue(curPlayer, ChConfig.ActTaskType_MineAreaEndOther)
249     return
250
3d3a72 251 def OnMineTreasureByCTGID(curPlayer, ctgID):
H 252     ## 充值激活聚宝盆
253     treasureCTGIDList = IpyGameDataPY.GetFuncEvalCfg("MineAreaTreasure", 1)
254     for treasureType, ctgIDList in enumerate(treasureCTGIDList):
255         if not ctgIDList or ctgID not in ctgIDList: # 配空列表的默认激活
256             continue
257         state = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MineTreasureState)
258         if state&pow(2, treasureType):
259             break
260         updState = state|pow(2, treasureType)
261         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MineTreasureState, updState)
262         SyncPlayerMineAreaInfo(curPlayer)
263         GameWorld.Log("激活福地聚宝盆: treasureType=%s,updState=%s" % (treasureType, updState), curPlayer.GetPlayerID())
264         break
265     
266     return
267
268 def OnAddMineTreasureProgress(curPlayer, robCount, isNotify=True):
269     ## 增加聚宝盆进度
270     # @param robCount: 抢夺物品数
271     if robCount <= 0:
272         return
273     
274     playerID = curPlayer.GetPlayerID()
275     treasureCTGIDList = IpyGameDataPY.GetFuncEvalCfg("MineAreaTreasure", 1)    
276     treasureAddProgressList = IpyGameDataPY.GetFuncEvalCfg("MineAreaTreasure", 2)
277     treasureState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MineTreasureState)
278     for treasureType, addProgressSet in enumerate(treasureAddProgressList):
279         ctgIDList = treasureCTGIDList[treasureType]
280         isActivite = 1 if (not ctgIDList or treasureState&pow(2, treasureType)) else 0
281         if not isActivite:
282             continue
283         curProgress = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MineTreasureProgess % treasureType)
284         if curProgress >= MineTreasureProgressMax:
285             continue
286         addProgress = addProgressSet * robCount
287         updProgress = min(curProgress + addProgress, MineTreasureProgressMax)
288         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MineTreasureProgess % treasureType, updProgress)
289         GameWorld.DebugLog("    增加福地聚宝盆进度: robCount=%s,treasureType=%s,curProgress=%s,addProgress=%s,updProgress=%s" 
290                            % (robCount, treasureType, curProgress, addProgress, updProgress), playerID)
291         
292     if isNotify:
293         SyncPlayerMineAreaInfo(curPlayer)
294     return
295
296 def GetMineTreasureAward(curPlayer, treasureType):
297     ## 领取聚宝盆奖励
298     
299     playerID = curPlayer.GetPlayerID()
300     
301     treasureAward = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MineTreasureAward)
302     if treasureAward&pow(2, treasureType):
303         GameWorld.DebugLog("福地聚宝盆奖励已领取过! treasureType=%s,treasureAward=%s" % (treasureType, treasureAward), playerID)
304         return
305     
306     curProgress = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MineTreasureProgess % treasureType)
307     if curProgress < MineTreasureProgressMax:
308         GameWorld.DebugLog("福地聚宝盆进度未满,无法领奖! treasureType=%s,curProgress=%s" % (treasureType, curProgress), playerID)
309         return
310     
311     treasureAwardList = IpyGameDataPY.GetFuncEvalCfg("MineAreaTreasure", 3)
312     if treasureType >= len(treasureAwardList):
313         return
314     awardItemList = treasureAwardList[treasureType]
315     
316     if not ItemControler.CheckPackSpaceEnough(curPlayer, awardItemList):
317         return
318     
319     updAward = treasureAward|pow(2, treasureType)
320     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MineTreasureAward, updAward)
321     SyncPlayerMineAreaInfo(curPlayer)
322     
323     for itemID, itemCount, isAuctionItem in awardItemList:
324         ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isAuctionItem, [IPY_GameWorld.rptItem])
325         
326     GameWorld.DebugLog("福地聚宝盆领奖! treasureType=%s,updAward=%s,awardItemList=%s" % (treasureType, updAward, awardItemList), playerID)
327     return
328
329 def SyncPlayerMineAreaInfo(curPlayer):
330     clientPack = ChPyNetSendPack.tagMCPlayerMineAreaInfo()
331     clientPack.WorkerCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MineWorkerCount)
332     clientPack.EnergyUsed = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MineWorkerEnergyUsed)
d7e6ef 333     clientPack.HelpAwardCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MineHelpAwardCount)
3d3a72 334     clientPack.RefreshCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MineRefreshCount % 0)
H 335     clientPack.RefreshCountSuper = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MineRefreshCount % 1)
336     
337     treasureState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MineTreasureState)
338     treasureAward = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MineTreasureAward)
339     treasureCTGIDList = IpyGameDataPY.GetFuncEvalCfg("MineAreaTreasure", 1)
340     clientPack.TreasureCount = len(treasureCTGIDList)
341     clientPack.TreasureState = [0] * clientPack.TreasureCount
342     clientPack.TreasureAward = [0] * clientPack.TreasureCount
343     clientPack.TreasureProgress = [0] * clientPack.TreasureCount
344     for treasureType, ctgIDList in enumerate(treasureCTGIDList):
345         isActivite = 1 if (not ctgIDList or treasureState&pow(2, treasureType)) else 0
346         clientPack.TreasureState[treasureType] = isActivite
347         clientPack.TreasureAward[treasureType] = 1 if treasureAward&pow(2, treasureType) else 0
348         clientPack.TreasureProgress[treasureType] = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MineTreasureProgess % treasureType)
349         
350     NetPackCommon.SendFakePack(curPlayer, clientPack)
351     return