xdh
2018-11-27 1df8a52965d43ccc8a1a40ec008f95d22ec485b1
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerTJG.py
@@ -50,7 +50,8 @@
import PlayerPet
import PlayerGeTui
import ChEquip
import QuestCommon
import random
# 可吞噬的装备位
Def_EatItem_EquipPlace = [
@@ -66,6 +67,15 @@
]
Def_EatSpace = 5    # 低于X格自动吞噬
def DoTJGOpen(curPlayer):
    ##脱机挂功能开启 赠送脱机时间
    addTime = IpyGameDataPY.GetFuncCfg('TJGGiftTime')
    AddTJGTime(curPlayer, addTime)
    GameWorld.DebugLog('脱机挂功能开启 赠送脱机时间 %s'%addTime, curPlayer.GetID())
    return
#===============================================================================
# //B2 01 脱机挂状态 # tagCMLoginState
# struct    tagCMLoginState
@@ -175,6 +185,7 @@
        return
    curPlayer.SetSight(min(ChConfig.Def_PlayerSight_Default, clientData.Sight))
    GameWorld.DebugLog("OnSightZoom:%s"%clientData.Sight)
    return
# 需要处理的点,防沉迷
@@ -198,6 +209,7 @@
    if curPlayer.GetIP() != "127.0.0.1":
        return
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PlayerKey_TJGNPC, clientData.NPCID)
    GameWorld.DebugLog("%s---OnTJGNPC:%s"%(curPlayer.GetName(),clientData.NPCID))
    return
@@ -438,7 +450,8 @@
    
    # 2.物品
    OnTJGDropItems(curPlayer, npcID, killCnt)
    #任务道具
    OnTJGDropTaskItems(curPlayer, npcData.GetLV(), killCnt)
    # VIP杀怪加攻
    PlayerVip.DoAddVIPKillLVExp(curPlayer, npcData, killCnt)
    
@@ -447,7 +460,10 @@
    
    # 击杀特定NPC成就
    PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_KillSpecificNPC, killCnt, [npcID])
    # 日常活动
    if not curPlayer.NomalDictGetProperty(ChConfig.Def_PDictType_TJGOnDayEx):
        if npcData.GetLV()>=curPlayer.GetLV() - IpyGameDataPY.GetFuncCfg('DailyQuestKillMonster'):
            PlayerActivity.AddDailyActionFinishCnt(curPlayer, ShareDefine.DailyActionID_KillNPC, killCnt)
    # 击杀任务怪, 杀怪日常已经没有了,暂时屏蔽
    #for _ in xrange(killCnt):
    #    EventShell.Event_OnKillByID(curPlayer, npcID)
@@ -556,6 +572,28 @@
    NoteEatEquip(curPlayer, eatCount, giveCnt)
    CheckPackFull(curPlayer)
    
def OnTJGDropTaskItems(curPlayer, npclv, killCnt):
    #掉落任务道具
    if curPlayer.GetDictByKey(ChConfig.Def_PlayerKey_TJGPackFullAfterEat):
        # 满了不再给物品
        return
    dropTaskItemDict = IpyGameDataPY.GetFuncEvalCfg('TJDropTaskItem', 1, {})
    for missionID, dropInfo in dropTaskItemDict.items():
        if not curPlayer.FindMission(missionID):
            continue
        npclvLimit, itemID, needItemCnt, itemCntFormula = dropInfo
        if npclv < npclvLimit:
            continue
        haveCnt = ItemControler.FindPlayerItemCountByItemID(curPlayer, IPY_GameWorld.rptItem, itemID)
        giveItemCnt = min(needItemCnt-haveCnt, eval(itemCntFormula))
        if giveItemCnt <= 0:
            continue
        packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, 1)
        if packSpace < 1:
            #GameWorld.Log('脱机挂掉落任务道具背包不足! missionID=%s,itemID=%s,giveItemCnt=%s'%(missionID, itemID, giveItemCnt))
            continue
        ItemControler.GivePlayerItem(curPlayer, itemID, giveItemCnt, 0, [IPY_GameWorld.rptItem])
    return
    
def CheckPackFull(curPlayer):
    if not ItemCommon.CheckPackHasSpace(curPlayer, IPY_GameWorld.rptItem):
@@ -627,7 +665,12 @@
def NotifyTJGInfo(curPlayer):
    
    if curPlayer.GetIP() == "127.0.0.1":
        LoginFixTJG(curPlayer, True)
        return
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDictType_TJGOnDayEx, 0)
    # 脱机挂没有运作情况下 弥补收益
    LoginFixTJG(curPlayer)
    
    times = curPlayer.NomalDictGetProperty(ChConfig.Def_PDictType_TJGNotify_Time, 0, ChConfig.Def_PDictType_TJGNotify)
    if times == 0:
@@ -747,12 +790,16 @@
 
# 过天清理
def TJGOnDay(curPlayer):
    times = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TJGDeadPayTime)
    if times == 0:
        return
    ResetTJGDeadInfo(curPlayer)
def TJGOnDay(curPlayer, onEventType):
    if onEventType == ShareDefine.Def_OnEventType:
        times = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TJGDeadPayTime)
        if times == 0:
            return
        ResetTJGDeadInfo(curPlayer)
    elif onEventType == ShareDefine.Def_OnEventTypeEx:
        if GetIsTJG(curPlayer):
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDictType_TJGOnDayEx, 1)
    return
def ResetTJGDeadInfo(curPlayer):
@@ -795,3 +842,193 @@
        ChPlayer.PlayerRebornByType(curPlayer, ChConfig.rebornType_City, tick)
        curPlayer.Kick(IPY_GameWorld.disMapCopyFull)  # 随便记录一个死亡
    return
def TJGGM(curPlayer, times):
    # 真实上线
    npcID = FindTJGNPC(curPlayer)
    if not npcID:
        return
    # 此时由服务端重新找一次挂机NPC
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PlayerKey_TJGNPC, npcID)
    GameWorld.DebugAnswer(curPlayer, "GM模拟脱机产出,npcid:%s, 时间秒:%s, 经验倍率:%s"%(
                    curPlayer.NomalDictGetProperty(ChConfig.Def_PlayerKey_TJGNPC), times,
                    curPlayer.GetDictByKey(ChConfig.Def_PlayerKey_TotalExpRate)))
    # 设置脱机登录时的等级, 上线通知清空, 没清空说明多次脱机挂登录 使用旧等级
    notifyLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDictType_TJGNotify_LV, 0, ChConfig.Def_PDictType_TJGNotify)
    if not notifyLV:
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDictType_TJGNotify_LV, curPlayer.GetLV(), ChConfig.Def_PDictType_TJGNotify)
    # 记录秒单位
    NoteTJGTime(curPlayer, times)
    OnTJGKillNPCByTimes(curPlayer, times)
    sendPack = ChPyNetSendPack.tagMCTJGInfo()
    sendPack.Clear()
    sendPack.Exp1 = curPlayer.NomalDictGetProperty(ChConfig.Def_PDictType_TJGNotify_Exp1, 0, ChConfig.Def_PDictType_TJGNotify)
    sendPack.Exp2 = curPlayer.NomalDictGetProperty(ChConfig.Def_PDictType_TJGNotify_Exp2, 0, ChConfig.Def_PDictType_TJGNotify)
    sendPack.Times = times
    sendPack.PurpleEquip = curPlayer.NomalDictGetProperty(ChConfig.Def_PDictType_TJGNotify_Purple, 0, ChConfig.Def_PDictType_TJGNotify)
    sendPack.OrangeEquip = curPlayer.NomalDictGetProperty(ChConfig.Def_PDictType_TJGNotify_Orange, 0, ChConfig.Def_PDictType_TJGNotify)
    sendPack.EatPurpleEquip = curPlayer.NomalDictGetProperty(ChConfig.Def_PDictType_TJGNotify_EatPurple, 0, ChConfig.Def_PDictType_TJGNotify)
    sendPack.GiveCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDictType_TJGNotify_GiveCnt, 0, ChConfig.Def_PDictType_TJGNotify)
    sendPack.BeforeLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDictType_TJGNotify_LV, 0, ChConfig.Def_PDictType_TJGNotify)
    sendPack.Items = []
    itemIDList = IpyGameDataPY.GetFuncEvalCfg('OfflinePostItem', 1)
    for itemID in itemIDList:
        count = curPlayer.NomalDictGetProperty(ChConfig.Def_PDictType_TJGNotify_ItemID%itemID, 0, ChConfig.Def_PDictType_TJGNotify)
        if count == 0:
            continue
        itemInfo = ChPyNetSendPack.tagMCTJGItems()
        itemInfo.ItemID = itemID
        itemInfo.Count = count
        sendPack.Items.append(itemInfo)
    sendPack.Cnt = len(sendPack.Items)
    NetPackCommon.SendFakePack(curPlayer, sendPack)
    curPlayer.ClearNomalDict(ChConfig.Def_PDictType_TJGNotify)
# 上线检查脱机时间是否正常运行, 弥补对应缺失时间,如维护2小时缺失的脱机挂收益
# 1. 非脱机死亡,2.存在脱机时间,3.离线时间超过5分钟;则一次补齐 离线时间-5分钟的收益并减少脱机时间
# 按当前经验倍率计算,且不会减buff时间
# 找到对应的NPC,需读取对应挂机表
def LoginFixTJG(curPlayer, isTJG=False):
    # 外层需判断是真实玩家登录
    tjgTime = GetTJGTime(curPlayer)     # 秒
    if not tjgTime:
        return
    if curPlayer.GetState() == 2:
        # 玩家脱机死亡不处理
        GameWorld.DebugLog("脱机死亡玩家不做时差补偿。")
        return
    # 超过5分钟部分补偿
    seconds = PlayerControl.GetPlayerLeaveServerSecond(curPlayer) - IpyGameDataPY.GetFuncCfg('AutoUseGuardian', 2)
    if seconds <= 0:
        return
    times = min(seconds, tjgTime)
    if not isTJG:
        # 真实上线
        npcID = FindTJGNPC(curPlayer)
        if not npcID:
            return
        # 此时由服务端重新找一次挂机NPC
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PlayerKey_TJGNPC, npcID)
    GameWorld.DebugLog("弥补脱机----playerID:%s ,npcid  %s-%s-%s"%(curPlayer.GetID(),
                    curPlayer.NomalDictGetProperty(ChConfig.Def_PlayerKey_TJGNPC), times,
                    curPlayer.GetDictByKey(ChConfig.Def_PlayerKey_TotalExpRate)))
    # 设置脱机登录时的等级, 上线通知清空, 没清空说明多次脱机挂登录 使用旧等级
    notifyLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDictType_TJGNotify_LV, 0, ChConfig.Def_PDictType_TJGNotify)
    if not notifyLV:
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDictType_TJGNotify_LV, curPlayer.GetLV(), ChConfig.Def_PDictType_TJGNotify)
    # 记录秒单位
    NoteTJGTime(curPlayer, times)
    SetTJGTime(curPlayer, max(tjgTime - times, 0))
    OnTJGKillNPCByTimes(curPlayer, times)
    return
def FindTJGNPC(curPlayer):
    # 1.找到对应等级点,判断任务是否完成,与策划约定挂机地图ID10000开头
    # 3.找到可以进入的野外地图后,根据等级防御在此地图挂机
    missionMapStep = GetMissionMapStep(curPlayer)
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    maxMapID = 0
    # ---找到可以挂机的最高级地图---
    for i in xrange(ipyDataMgr.GetMapEventPointCount()):
        mapInfo = ipyDataMgr.GetMapEventPointByIndex(i)
        mapID = mapInfo.GetMapID()
        if mapID/10000 != 1:
            # 非野外地图
            continue
        # ---判断地图表的任务和等级限制---
        mapData = GameWorld.GetGameData().GetChinMap().GetMapByID(mapID)
        if not mapData:
            continue
        enterLV = mapData.GetLV()
        if curPlayer.GetLV() < enterLV:
            continue
        openMapStep = mapData.GetTreasureID() #需要完成的主线任务ID
        if missionMapStep < openMapStep:
            continue
        if mapID < maxMapID:
            continue
        maxMapID = mapID
    if not maxMapID:
        return 0
    # ---找到挂机等级点---
    lv = curPlayer.GetLV()
    myPoint = None
    mapList = IpyGameDataPY.GetIpyGameDataByCondition("MapEventPoint", {"MapID":maxMapID}, True)
    mapEffList = []  # 有效挂机点,同地图中存在不需要挂机的NPC点
    for mapInfo in mapList:
        if mapInfo.GetLowLV() == 0:
            continue
        mapEffList.append(mapInfo)
        if lv >= mapInfo.GetLowLV():
            if myPoint and myPoint.GetLowLV() >= mapInfo.GetLowLV():
                continue
            myPoint = mapInfo
    if not mapEffList:
        return 0
    # ---根据防御上下调整
    if not myPoint:
        # 寻找异常取最低点
        return mapEffList[0].GetNPCID()
    pointLen = len(mapEffList)
    defense = curPlayer.GetDef()
    pIndex = mapEffList.index(myPoint)
    if defense >= mapEffList[min(pointLen-1, pIndex+1)].GetDefense():
        # 高一级
        return mapEffList[min(pointLen-1, pIndex+1)].GetNPCID()
    if defense < myPoint.GetDefense():
        # 低一级
        return mapEffList[max(0, pIndex-1)].GetNPCID()
    return myPoint.GetNPCID()
def GetMissionMapStep(curPlayer):
    # 主线任务完成时会设置标志可进地图标志
    mission_1 = QuestCommon.GetCommonMission(curPlayer)
    if not mission_1:
        return 0
    return mission_1.GetProperty("OpenMap")