#!/usr/bin/python
|
# -*- coding: GBK -*-
|
#-------------------------------------------------------------------------------
|
#
|
##@package PlayerFamilyZhenbaoge
|
#
|
# @todo:Õ䱦¸ó
|
# @author hxp
|
# @date 2024-10-29
|
# @version 1.0
|
#
|
# ÏêϸÃèÊö: Õ䱦¸ó
|
#
|
#-------------------------------------------------------------------------------
|
#"""Version = 2024-10-29 17:30"""
|
#-------------------------------------------------------------------------------
|
|
import ChConfig
|
import ShareDefine
|
import IpyGameDataPY
|
import NetPackCommon
|
import ChPyNetSendPack
|
import ItemControler
|
import PlayerControl
|
import PlayerFamily
|
import GameWorld
|
import DBDataMgr
|
|
import random
|
import time
|
|
ActionType = ShareDefine.Def_ActionType_Zhenbaoge
|
ActionGlobalID = 1 # È«¾Ö¼Ç¼ID
|
|
# È«¾Ö¼Ç¼
|
#Time ±¾ÂÖ¿ªÊ¼Ê±¼ä´Á
|
#Value1 ActionGlobalID
|
def GetFAPrice(gActionData): return gActionData.GetValue2()
|
def SetFAPrice(gActionData, price): return gActionData.SetValue2(price)
|
def GetFAIsNegative(gActionData): return gActionData.GetValue3() # ÊÇ·ñ¸ºÖµ
|
def SetFAIsNegative(gActionData, isNegative): return gActionData.SetValue3(isNegative)
|
def GetFAPriceFinal(gActionData):
|
## »ñÈ¡×îÖÕ¼Û¸ñ
|
price = GetFAPrice(gActionData)
|
isNegative = GetFAIsNegative(gActionData)
|
return price if not isNegative else -price
|
def SetFAPriceFinal(gActionData, totalPrice):
|
SetFAPrice(gActionData, abs(totalPrice))
|
SetFAIsNegative(gActionData, 1 if totalPrice < 0 else 0)
|
return
|
def GetFAItemList(gActionData): return eval(gActionData.GetUserData()) # ÎïÆ·Áбí
|
def SetFAItemList(gActionData, itemList): gActionData.SetUserData(itemList)
|
|
# ³ÉÔ±¿³¼Û¼Ç¼
|
#Time ¿³¼Ûʱ¼ä´Á
|
#Name Íæ¼ÒÃû
|
def GetFAPlayerID(actionData): return actionData.GetValue1()
|
def SetFAPlayerID(actionData, playerID): return actionData.SetValue1(playerID)
|
def GetFACutPrice(actionData): return actionData.GetValue2() # Íæ¼Ò¿³Á˶àÉÙ
|
def SetFACutPrice(actionData, cutPrice): return actionData.SetValue2(cutPrice)
|
def GetFABuyState(actionData): return actionData.GetValue3() # Íæ¼ÒÊÇ·ñÒѹºÂò
|
def SetFABuyState(actionData, buyState): return actionData.SetValue3(buyState)
|
|
def OnDay(family):
|
OnZhenbaogeReset(family)
|
return
|
|
def OnPlayerLogin(curPlayer):
|
Sync_ZhenbaogeInfo(curPlayer)
|
return
|
|
def PlayerOnDay(curPlayer):
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_FamilyZhenbaogeCut, 0)
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_FamilyZhenbaogeBuy, 0)
|
Sync_ZhenbaogeInfo(curPlayer)
|
return
|
|
def OnZhenbaogeReset(family):
|
## Õ䱦¸óÖØÖÃ
|
|
familyID = family.GetID()
|
|
actionMgr = DBDataMgr.GetFamilyActionMgr()
|
actionMgr.DelFamilyAction(familyID, ActionType)
|
familyAction = actionMgr.GetFamilyAction(familyID, ActionType)
|
gActionData = familyAction.AddAction()
|
SetFAPlayerID(gActionData, ActionGlobalID)
|
|
initPrice = IpyGameDataPY.GetFuncCfg("Zhenbaoge", 2)
|
|
randItemList = []
|
ipyDataMgr = IpyGameDataPY.IPY_Data()
|
for index in range(ipyDataMgr.GetFamilyZhenbaogeItemCount()):
|
ipyData = ipyDataMgr.GetFamilyZhenbaogeItemByIndex(index)
|
randItemList.append([ipyData.GetItemWeight(), ipyData.GetItemList()])
|
|
itemList = GameWorld.GetResultByWeightList(randItemList, [])
|
|
SetFAPriceFinal(gActionData, initPrice)
|
SetFAItemList(gActionData, itemList)
|
|
PlayerFamily.SendFamilyAction(gActionData)
|
#GameWorld.DebugLog("Õ䱦¸óÖØÖÃ! familyID=%s,itemList=%s" % (familyID, itemList), familyID)
|
return
|
|
def GetZhenbaogeActionData(familyID, playerID):
|
## »ñÈ¡Õ䱦¸óAction
|
findActionData = None
|
familyAction = DBDataMgr.GetFamilyActionMgr().GetFamilyAction(familyID, ActionType)
|
for index in range(0, familyAction.Count()):
|
actionData = familyAction.At(index)
|
if GetFAPlayerID(actionData) == playerID:
|
findActionData = actionData
|
break
|
return findActionData
|
|
def CalcCutPrice(curFamily, gActionData, playerID):
|
## ¼ÆË㿳¼Û¼Û¸ñ
|
# @return: None-¿³¼ÛÏÞÖÆµÈ£»>0-¿³¼ÛÖµ
|
|
if not curFamily:
|
return
|
|
familyID = curFamily.GetID()
|
familyAction = DBDataMgr.GetFamilyActionMgr().GetFamilyAction(familyID, ActionType)
|
actionCount = familyAction.Count() # ÆäÖÐ1ÌõÊǹ«¹²Êý¾Ý
|
hadCutCount = actionCount - 1
|
|
familyLV = curFamily.GetLV()
|
fmLVIpyData = IpyGameDataPY.GetIpyGameData("Family", familyLV)
|
if not fmLVIpyData:
|
return
|
maxMemberCnt = fmLVIpyData.GetMemberMax()
|
if hadCutCount >= maxMemberCnt:
|
GameWorld.ErrLog("ÒÑ´ïµ½ÏÉÃË¿³¼ÛÈË´ÎÉÏÏÞ! hadCutCount=%s >= %s,familyID=%s,familyLV=%s"
|
% (hadCutCount, maxMemberCnt, familyID, familyLV), playerID)
|
return
|
|
actionData = GetZhenbaogeActionData(familyID, playerID)
|
if actionData and GetFACutPrice(actionData):
|
GameWorld.DebugLog("ÒѾÔÚ¸ÃÃËÕ䱦¸ó¿³¼Û¹ýÁË! familyID=%s" % familyID, playerID)
|
return
|
|
cutNum = hadCutCount + 1
|
cutIpyData = IpyGameDataPY.GetIpyGameData("FamilyZhenbaogeCut", cutNum)
|
if not cutIpyData:
|
return
|
cutWeight = cutIpyData.GetCutWeight()
|
minRatio = cutIpyData.GetMinRatio()
|
randRatio = cutIpyData.GetRandRatio()
|
totalWeight = fmLVIpyData.GetZhenbaogeWeights()
|
rand = random.random() #Ëæ»úÖµ 0~1
|
|
initPrice = IpyGameDataPY.GetFuncCfg("Zhenbaoge", 2)
|
|
cutPrice = max(1, eval(IpyGameDataPY.GetFuncCompileCfg("ZhenbaogeCut", 2)))
|
|
nowPrice = GetFAPriceFinal(gActionData)
|
updPrice = nowPrice - cutPrice
|
|
lowestPrice = IpyGameDataPY.GetFuncCfg("ZhenbaogeCut", 1) # ×îµÍ¼Û¸ñ±£»¤
|
if updPrice < lowestPrice:
|
if nowPrice > lowestPrice:
|
updPrice = int(lowestPrice - random.randint(0, 2)) # ֮ǰ»¹Î´µ½´ï×îµÍ¼Û£¬¹Ì¶¨×îµÍ¼Û+Ëæ»ú0~2
|
cutPrice = nowPrice - updPrice
|
else:
|
cutPrice = random.randint(1, 2) # µÍÓÚ×îµÍ¼Û¸ñºó¿³¼ÛÖ»ÄÜËæ»ú1»ò2
|
updPrice = nowPrice - cutPrice
|
GameWorld.DebugLog("Õ䱦¸ó¿³¼Û¼ÆËãµØ°å¼Û±£»¤: cutPrice=%s,nowPrice=%s,updPrice=%s" % (cutPrice, nowPrice, updPrice), playerID)
|
else:
|
GameWorld.DebugLog("Õ䱦¸ó¿³¼Û¼ÆËã: cutPrice=%s,nowPrice=%s,updPrice=%s,cutWeight=%s/%s,minRatio=%s,randRatio=%s,rand=%s,initPrice=%s"
|
% (cutPrice, nowPrice, updPrice, cutWeight, totalWeight, minRatio, randRatio, rand, initPrice), playerID)
|
|
return max(1, cutPrice)
|
|
def AddCutPrice(familyID, playerID, playerName, cutPrice, gActionData, isNotify=True):
|
## Ìí¼Ó¿³¼Û¼Ç¼
|
familyAction = DBDataMgr.GetFamilyActionMgr().GetFamilyAction(familyID, ActionType)
|
actionData = familyAction.AddAction()
|
actionData.SetName(playerName)
|
SetFAPlayerID(actionData, playerID)
|
SetFACutPrice(actionData, cutPrice)
|
|
# ¸üÐÂ×îÖÕ¼Û¸ñ
|
nowPrice = GetFAPriceFinal(gActionData)
|
updPrice = nowPrice - cutPrice
|
SetFAPriceFinal(gActionData, updPrice)
|
GameWorld.DebugLog("Õ䱦¸ó¿³¼Û¸üÐÂ: playerID=%s,cutPrice=%s,nowPrice=%s,updPrice=%s,familyID=%s"
|
% (playerID, cutPrice, nowPrice, updPrice, familyID), playerID)
|
if isNotify:
|
PlayerFamily.SendFamilyAction([gActionData, actionData])
|
return actionData
|
|
#// A6 16 Õ䱦¸ó²Ù×÷ #tagCMZhenbaogeOP
|
#
|
#struct tagCMZhenbaogeOP
|
#{
|
# tagHead Head;
|
# BYTE OpType; // ²Ù×÷£º0-¿³¼Û£»1-¹ºÂò
|
#};
|
def OnZhenbaogeOP(index, clientData, tick):
|
curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
|
opType = clientData.OpType
|
playerID = curPlayer.GetPlayerID()
|
familyID = curPlayer.GetFamilyID()
|
if not familyID:
|
GameWorld.DebugLog("ûÓÐÏÉÃËÎÞ·¨²Ù×÷Õ䱦¸ó!", playerID)
|
return
|
curFamily = DBDataMgr.GetFamilyMgr().FindFamily(familyID)
|
if not curFamily:
|
return
|
gActionData = GetZhenbaogeActionData(familyID, ActionGlobalID)
|
if not gActionData:
|
GameWorld.DebugLog("Õ䱦¸ó»¹Ã»ÓÐË¢ÐÂ! familyID=%s" % familyID, playerID)
|
return
|
|
# ¿³¼Û
|
if opType == 0:
|
leaveTimeEx = PlayerControl.GetLeaveFamilyTimeEx(curPlayer)
|
cutState = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FamilyZhenbaogeCut)
|
if cutState and leaveTimeEx:
|
cutCDTimes = IpyGameDataPY.GetFuncCfg("Zhenbaoge", 3) * 60
|
passTimes = int(time.time()) - leaveTimeEx
|
if passTimes < cutCDTimes:
|
GameWorld.DebugLog("½ñÈÕÒÑ¿³¼Û±ä¸üÏÉÃË¿³¼ÛCDÖÐ! passTimes=%s < %s" % (passTimes, cutCDTimes), playerID)
|
return
|
|
cutPrice = CalcCutPrice(curFamily, gActionData, playerID)
|
if not cutPrice:
|
return
|
|
AddCutPrice(familyID, playerID, curPlayer.GetName(), cutPrice, gActionData)
|
PlayerControl.NotifyCode(curPlayer, "ZhenbaogeCut", [cutPrice])
|
if not curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FamilyZhenbaogeCut):
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_FamilyZhenbaogeCut, 1)
|
Sync_ZhenbaogeInfo(curPlayer)
|
|
# ¹ºÂò
|
elif opType == 1:
|
buyState = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FamilyZhenbaogeBuy)
|
if buyState:
|
GameWorld.DebugLog("Õ䱦¸ó½ñÈÕÒѹºÂò!", playerID)
|
return
|
moneyType = IpyGameDataPY.GetFuncCfg("Zhenbaoge", 1)
|
playerMoneyValue = PlayerControl.GetMoney(curPlayer, moneyType)
|
|
actionData = GetZhenbaogeActionData(familyID, playerID)
|
if not actionData:
|
GameWorld.DebugLog("Õ䱦¸óδ¿³¼Û£¬ÎÞ·¨¹ºÂò! familyID=%s" % familyID, playerID)
|
return
|
if GetFABuyState(actionData):
|
GameWorld.DebugLog("Õ䱦¸óÒѾ¹ºÂò¹ýÁË! familyID=%s" % familyID, playerID)
|
return
|
|
nowPrice = GetFAPriceFinal(gActionData)
|
if nowPrice > 0 and playerMoneyValue < nowPrice:
|
GameWorld.DebugLog("Íæ¼Òµ±Ç°»õ±Ò²»×㣬ÎÞ·¨¹ºÂòÕ䱦¸óÎïÆ·! playerMoneyValue=%s < %s" % (playerMoneyValue, nowPrice), playerID)
|
return
|
|
giveItemList = GetFAItemList(gActionData)
|
GameWorld.DebugLog("Õ䱦¸ó¹ºÂò! familyID=%s,nowPrice=%s,giveItemList=%s" % (familyID, nowPrice, giveItemList), playerID)
|
|
# ÉèÖÃÒÑÂò
|
SetFABuyState(actionData, 1)
|
PlayerFamily.SendFamilyAction(actionData)
|
|
if nowPrice > 0:
|
if not PlayerControl.PayMoney(curPlayer, moneyType, nowPrice, "Zhenbaoge"):
|
GameWorld.ErrLog("Õ䱦¸ó¹ºÂò»õ±Ò²»×ã! nowPrice=%s" % nowPrice, playerID)
|
return
|
elif nowPrice < 0:
|
PlayerControl.GiveMoney(curPlayer, moneyType, -nowPrice, "Zhenbaoge")
|
else: # 0²»´¦Àí
|
pass
|
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_FamilyZhenbaogeBuy, 1)
|
Sync_ZhenbaogeInfo(curPlayer)
|
|
if giveItemList:
|
ItemControler.GivePlayerItemOrMail(curPlayer, giveItemList, event=["Zhenbaoge", False, {}], isNotifyAward=False)
|
ItemControler.NotifyGiveAwardInfo(curPlayer, giveItemList, "Zhenbaoge", moneyInfo={moneyType:0 if nowPrice > 0 else -nowPrice})
|
|
return
|
|
def Sync_ZhenbaogeInfo(curPlayer):
|
clientPack = ChPyNetSendPack.tagMCFamilyZhenbaogeInfo()
|
clientPack.CutState = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FamilyZhenbaogeCut)
|
clientPack.BuyState = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FamilyZhenbaogeBuy)
|
NetPackCommon.SendFakePack(curPlayer, clientPack)
|
return
|