ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerFamilyZhenbaoge.py
@@ -18,16 +18,16 @@
import ChConfig
import ShareDefine
import IpyGameDataPY
import NetPackCommon
import ChPyNetSendPack
import PlayerControl
import PlayerFamily
import CrossPlayer
import GameWorld
import DBDataMgr
import random
import time
import ChPyNetSendPack
import NetPackCommon
import ItemControler
import PlayerControl
ActionType = ShareDefine.Def_ActionType_Zhenbaoge
ActionGlobalID = 1 # 全局记录ID
@@ -48,11 +48,8 @@
    SetFAPrice(gActionData, abs(totalPrice))
    SetFAIsNegative(gActionData, 1 if totalPrice < 0 else 0)
    return
def GetFAItemList(gActionData): return eval(gActionData.GetUseData()) # 物品列表
def SetFAItemList(gActionData, itemList):
    dataStr = str(itemList)
    gActionData.SetUseData(dataStr, len(dataStr))
    return
def GetFAItemList(gActionData): return eval(gActionData.GetUserData()) # 物品列表
def SetFAItemList(gActionData, itemList): gActionData.SetUserData(itemList)
# 成员砍价记录
#Time    砍价时间戳
@@ -64,8 +61,18 @@
def GetFABuyState(actionData): return actionData.GetValue3() # 玩家是否已购买
def SetFABuyState(actionData, buyState): return actionData.SetValue3(buyState)
def OnDayEx(family):
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):
@@ -73,7 +80,9 @@
    
    familyID = family.GetID()
    
    familyAction = DBDataMgr.GetFamilyActionMgr().GetFamilyAction(familyID, ActionType)
    actionMgr = DBDataMgr.GetFamilyActionMgr()
    actionMgr.DelFamilyAction(familyID, ActionType)
    familyAction = actionMgr.GetFamilyAction(familyID, ActionType)
    gActionData = familyAction.AddAction()
    SetFAPlayerID(gActionData, ActionGlobalID)
    
@@ -90,12 +99,12 @@
    SetFAPriceFinal(gActionData, initPrice)
    SetFAItemList(gActionData, itemList)
    
    #PlayerFamilyAction.SendFamilyAction(gActionData)
    GameWorld.DebugLog("珍宝阁重置! familyID=%s,itemList=%s" % (familyID, itemList), familyID)
    PlayerFamily.SendFamilyAction(gActionData)
    #GameWorld.DebugLog("珍宝阁重置! familyID=%s,itemList=%s" % (familyID, itemList), familyID)
    return
def GetZhenbaogeActionData(familyID, playerID):
    ## 获取Action
    ## 获取珍宝阁Action
    findActionData = None
    familyAction = DBDataMgr.GetFamilyActionMgr().GetFamilyAction(familyID, ActionType)
    for index in range(0, familyAction.Count()):
@@ -105,57 +114,28 @@
            break
    return findActionData
def MapServer_ZhenbaogeOP(curPlayer, msgList):
    mapID = curPlayer.GetRealMapID()
    playerID = curPlayer.GetPlayerID()
    GameWorld.DebugLog("MapServer_ZhenbaogeOP mapID=%s,msgList=%s" % (mapID, msgList), playerID)
    if not msgList:
        return
    curFamily = curPlayer.GetFamily()
    if not curFamily:
        return
    familyID = curFamily.GetID()
    gActionData = GetZhenbaogeActionData(familyID, ActionGlobalID)
    if not gActionData:
        GameWorld.DebugLog("珍宝阁还没有刷新! familyID=%s" % familyID, playerID)
        return
    msgType, dataMsg = msgList
    ret = None
    if msgType == "Cut":
        cutPrice = CalcCutPrice(curFamily, gActionData, playerID)
        if cutPrice:
            AddCutPrice(familyID, playerID, curPlayer.GetName(), cutPrice, gActionData)
        ret = [cutPrice]
    elif msgType == "Buy":
        buyRet = __DoZhenbaogeBuy(familyID, playerID, gActionData, dataMsg)
        if buyRet:
            ret = [True] + list(buyRet)
        else:
            ret = [False]
    if ret == None:
        return
    return msgList + (ret if isinstance(ret, list) else [ret])
def CalcCutPrice(curFamily, gActionData, playerID):
    ## 计算砍价价格
    # @return: None-砍价限制等;>0-砍价值
    
    familyID = curFamily.GetID()
    if not curFamily:
        return
    
    familyID = curFamily.GetID()
    familyAction = DBDataMgr.GetFamilyActionMgr().GetFamilyAction(familyID, ActionType)
    actionCount = familyAction.Count() # 其中1条是公共数据
    hadCutCount = actionCount - 1
    maxMemberCnt = PlayerFamily.GetFamilySetting(curFamily, ChConfig.Def_FamilySetting_MaxMemberCnt)
    if hadCutCount >= maxMemberCnt:
        GameWorld.ErrLog("已达到仙盟砍价人次上限! hadCutCount=%s >= %s,familyID=%s,familyLV=%s"
                         % (hadCutCount, maxMemberCnt, familyID, curFamily.GetLV()), playerID)
    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):
@@ -169,7 +149,7 @@
    cutWeight = cutIpyData.GetCutWeight()
    minRatio = cutIpyData.GetMinRatio()
    randRatio = cutIpyData.GetRandRatio()
    totalWeight = PlayerFamily.GetFamilySetting(curFamily, ChConfig.Def_FamilySetting_ZhenbaogeWeights)
    totalWeight = fmLVIpyData.GetZhenbaogeWeights()
    rand = random.random()  #随机值 0~1
    
    initPrice = IpyGameDataPY.GetFuncCfg("Zhenbaoge", 2)
@@ -185,7 +165,11 @@
            updPrice = int(lowestPrice - random.randint(0, 2)) # 之前还未到达最低价,固定最低价+随机0~2
            cutPrice = nowPrice - updPrice
        else:
            cutPrice = random.randint(1, 2) # 低于最低价格后砍价只能随机1或2
            randPriceRange = IpyGameDataPY.GetFuncEvalCfg("ZhenbaogeCut", 3)
            if len(randPriceRange) == 2:
                cutPrice = random.randint(randPriceRange[0], randPriceRange[1])
            else:
                cutPrice = random.randint(1, 2) # 低于最低价格后砍价只能随机1或2
            updPrice = nowPrice - cutPrice
        GameWorld.DebugLog("珍宝阁砍价计算地板价保护: cutPrice=%s,nowPrice=%s,updPrice=%s" % (cutPrice, nowPrice, updPrice), playerID)
    else:
@@ -198,9 +182,6 @@
    ## 添加砍价记录
    familyAction = DBDataMgr.GetFamilyActionMgr().GetFamilyAction(familyID, ActionType)
    actionData = familyAction.AddAction()
    actionData.SetFamilyId(familyID)
    actionData.SetActionType(ActionType)
    actionData.SetTime(int(time.time()))
    actionData.SetName(playerName)
    SetFAPlayerID(actionData, playerID)
    SetFACutPrice(actionData, cutPrice)
@@ -212,35 +193,9 @@
    GameWorld.DebugLog("珍宝阁砍价更新: playerID=%s,cutPrice=%s,nowPrice=%s,updPrice=%s,familyID=%s" 
                       % (playerID, cutPrice, nowPrice, updPrice, familyID), playerID)
    if isNotify:
        pass
        #PlayerFamilyAction.SendFamilyAction([gActionData, actionData])
        PlayerFamily.SendFamilyAction([gActionData, actionData])
    return actionData
def __DoZhenbaogeBuy(familyID, playerID, gActionData, dataMsg):
    playerMoneyValue = dataMsg[0]
    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)
    #PlayerFamilyAction.SendFamilyAction(actionData)
    return nowPrice, giveItemList
##----------------------------------------- 珍宝阁 --------------------------------------------------
#// A6 16 珍宝阁操作 #tagCMZhenbaogeOP
#
#struct    tagCMZhenbaogeOP
@@ -250,12 +205,10 @@
#};
def OnZhenbaogeOP(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    opType = clientData.OpType
    playerID = curPlayer.GetPlayerID()
    if not curPlayer.GetFamilyID():
        GameWorld.DebugLog("没有仙盟无法操作珍宝阁!", playerID)
        return
    opType = clientData.OpType
    
    reqDataEx = {}
    # 砍价
    if opType == 0:
        leaveTimeEx = PlayerControl.GetLeaveFamilyTimeEx(curPlayer)
@@ -266,8 +219,7 @@
            if passTimes < cutCDTimes:
                GameWorld.DebugLog("今日已砍价变更仙盟砍价CD中! passTimes=%s < %s" % (passTimes, cutCDTimes), playerID)
                return
        SendGameServer_FamilyZhenbaoge(curPlayer, "Cut", [])
        reqDataEx["cutState"] = cutState
    # 购买
    elif opType == 1:
        buyState = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FamilyZhenbaogeBuy)
@@ -276,64 +228,90 @@
            return
        moneyType = IpyGameDataPY.GetFuncCfg("Zhenbaoge", 1)
        playerMoneyValue = PlayerControl.GetMoney(curPlayer, moneyType)
        SendGameServer_FamilyZhenbaoge(curPlayer, "Buy", [playerMoneyValue])
        reqDataEx["playerMoneyValue"] = playerMoneyValue
        
    PlayerFamily.FamilyPyPackForwarding(curPlayer, clientData, tick, "PlayerFamilyZhenbaoge.__OnZhenbaogeOP", True, 20, reqDataEx=reqDataEx)
    return
def SendGameServer_FamilyZhenbaoge(curPlayer, msgType, msgData):
    playerID = curPlayer.GetPlayerID()
    tick = GameWorld.GetGameWorld().GetTick()
    if not GameWorld.SetPlayerTickTime(curPlayer, ChConfig.TYPE_Player_Tick_FamilyZhenbaoge, tick):
        GameWorld.DebugLog("请求CD中...", playerID)
def __OnZhenbaogeOP(crossPlayer, clientData, tick, fromServerID=0, reqDataEx=None):
    opType = clientData.OpType
    playerID = crossPlayer.GetPlayerID()
    familyID = crossPlayer.GetFamilyID()
    if not familyID:
        GameWorld.DebugLog("没有仙盟无法操作珍宝阁!", playerID)
        return
    GameWorld.DebugLog("珍宝阁同步GameServer: msgType=%s,%s" % (msgType, msgData), playerID)
    msgInfo = str([msgType, msgData])
    GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(playerID, 0, 0, "FamilyZhenbaoge", msgInfo, len(msgInfo))
    return
def GameServer_FamilyZhenbaogeRet(curPlayer, resultList):
    curPlayer.SetTickByType(ChConfig.TYPE_Player_Tick_FamilyZhenbaoge, 0)
    playerID = curPlayer.GetPlayerID()
    msgType, _ = resultList[:2]
    retData = resultList[2:]
    GameWorld.Log("仙盟珍宝阁GameServer返回: %s" % str(resultList), playerID)
    if msgType == "Cut":
        cutPrice = retData[0]
    curFamily = DBDataMgr.GetFamilyMgr().FindFamily(familyID)
    if not curFamily:
        return
    gActionData = GetZhenbaogeActionData(familyID, ActionGlobalID)
    if not gActionData:
        GameWorld.DebugLog("珍宝阁还没有刷新! familyID=%s" % familyID, playerID)
        return
    if not reqDataEx:
        return
    # 砍价
    if opType == 0:
        cutState = reqDataEx["cutState"]
        cutPrice = CalcCutPrice(curFamily, gActionData, playerID)
        if not cutPrice:
            # 砍价失败不处理后续
            return
        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 msgType == "Buy":
        isOK = retData[0]
        if not isOK:
            return
        buyState = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FamilyZhenbaogeBuy)
        if buyState:
            #一天只能买一次,防止变更仙盟刷
            return
        nowPrice, giveItemList = retData[1:]
        AddCutPrice(familyID, playerID, crossPlayer.GetPlayerName(), cutPrice, gActionData)
        CrossPlayer.NotifyCode(crossPlayer, "ZhenbaogeCut", [cutPrice])
        if not cutState:
            CrossPlayer.SetPlayerNomalDict(crossPlayer, {ChConfig.Def_Player_Dict_FamilyZhenbaogeCut:1}, True)
            #Sync_ZhenbaogeInfo(crossPlayer)
    # 购买
    elif opType == 1:
        #buyState = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FamilyZhenbaogeBuy)
        #if buyState:
        #    GameWorld.DebugLog("珍宝阁今日已购买!", playerID)
        #    return
        moneyType = IpyGameDataPY.GetFuncCfg("Zhenbaoge", 1)
        playerMoneyValue = reqDataEx["playerMoneyValue"]
        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)
        moneyDict = {moneyType:0} # 奖励货币
        if nowPrice > 0:
            if not PlayerControl.PayMoney(curPlayer, moneyType, nowPrice, "Zhenbaoge"):
                GameWorld.ErrLog("珍宝阁购买货币不足! nowPrice=%s" % nowPrice, playerID)
                return
            CrossPlayer.CostPlayerResources(crossPlayer, "Zhenbaoge", {moneyType:nowPrice})
        elif nowPrice < 0:
            PlayerControl.GiveMoney(curPlayer, moneyType, -nowPrice, "Zhenbaoge")
            moneyDict[moneyType] = -nowPrice
        else: # 0不处理
            pass
        
        if giveItemList:
            ItemControler.GivePlayerItemOrMail(curPlayer, giveItemList, event=["Zhenbaoge", False, {}], isNotifyAward=False)
        ItemControler.NotifyGiveAwardInfo(curPlayer, giveItemList, "Zhenbaoge", moneyInfo={moneyType:0 if nowPrice > 0 else -nowPrice})
        CrossPlayer.SetPlayerNomalDict(crossPlayer, {ChConfig.Def_Player_Dict_FamilyZhenbaogeBuy:1}, True)
        #Sync_ZhenbaogeInfo(curPlayer)
        
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_FamilyZhenbaogeBuy, 1)
        Sync_ZhenbaogeInfo(curPlayer)
        CrossPlayer.GivePlayerResources(crossPlayer, giveItemList, moneyDict, eventName="Zhenbaoge")
    return True
def __OnZhenbaogeOP_Ret(curPlayer, clientData, isOK):
    if not isOK:
        return
    Sync_ZhenbaogeInfo(curPlayer)
    return
def Sync_ZhenbaogeInfo(curPlayer):
@@ -342,6 +320,3 @@
    clientPack.BuyState = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FamilyZhenbaogeBuy)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return
##--------------------------------------------------------------------------------------------------