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 ItemControler
import PlayerControl
import PlayerFamily
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)
    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,56 +114,26 @@
            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)
    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, curFamily.GetLV()), playerID)
                         % (hadCutCount, maxMemberCnt, familyID, familyLV), playerID)
        return
    
    actionData = GetZhenbaogeActionData(familyID, playerID)
@@ -169,7 +148,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)
@@ -198,9 +177,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 +188,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
@@ -252,8 +202,16 @@
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    opType = clientData.OpType
    playerID = curPlayer.GetPlayerID()
    if not curPlayer.GetFamilyID():
    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
    
    # 砍价
@@ -266,8 +224,17 @@
            if passTimes < cutCDTimes:
                GameWorld.DebugLog("今日已砍价变更仙盟砍价CD中! passTimes=%s < %s" % (passTimes, cutCDTimes), playerID)
                return
        SendGameServer_FamilyZhenbaoge(curPlayer, "Cut", [])
        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)
@@ -276,48 +243,27 @@
            return
        moneyType = IpyGameDataPY.GetFuncCfg("Zhenbaoge", 1)
        playerMoneyValue = PlayerControl.GetMoney(curPlayer, moneyType)
        SendGameServer_FamilyZhenbaoge(curPlayer, "Buy", [playerMoneyValue])
        
    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)
        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]
        if not cutPrice:
            # 砍价失败不处理后续
        actionData = GetZhenbaogeActionData(familyID, playerID)
        if not actionData:
            GameWorld.DebugLog("珍宝阁未砍价,无法购买! familyID=%s" % familyID, playerID)
            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)
        if GetFABuyState(actionData):
            GameWorld.DebugLog("珍宝阁已经购买过了! familyID=%s" % familyID, playerID)
            return
        
    elif msgType == "Buy":
        isOK = retData[0]
        if not isOK:
        nowPrice = GetFAPriceFinal(gActionData)
        if nowPrice > 0 and playerMoneyValue < nowPrice:
            GameWorld.DebugLog("玩家当前货币不足,无法购买珍宝阁物品! playerMoneyValue=%s < %s" % (playerMoneyValue, nowPrice), playerID)
            return
        buyState = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FamilyZhenbaogeBuy)
        if buyState:
            #一天只能买一次,防止变更仙盟刷
            return
        nowPrice, giveItemList = retData[1:]
        
        moneyType = IpyGameDataPY.GetFuncCfg("Zhenbaoge", 1)
        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)
@@ -327,13 +273,13 @@
        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})
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_FamilyZhenbaogeBuy, 1)
        Sync_ZhenbaogeInfo(curPlayer)
    return
def Sync_ZhenbaogeInfo(curPlayer):
@@ -342,6 +288,3 @@
    clientPack.BuyState = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FamilyZhenbaogeBuy)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return
##--------------------------------------------------------------------------------------------------