From b2e2ebd12c8d1754ebfcee7f38f59f68b25c91c8 Mon Sep 17 00:00:00 2001 From: xdh <xiefantasy@qq.com> Date: 星期一, 07 一月 2019 17:07:27 +0800 Subject: [PATCH] 5730 【后端】【1.5】时装功能开发 --- ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerCoat.py | 337 +++++++++++++++++++++++--------------------------------- 1 files changed, 139 insertions(+), 198 deletions(-) diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerCoat.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerCoat.py index 8a879f7..56f28aa 100644 --- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerCoat.py +++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerCoat.py @@ -7,18 +7,16 @@ ##@package Player.PlayerCoat # # @todo:玩家时装外套 -# @author hxp -# @date 2015-6-15 -# @version 1.1 +# @author xdh +# @date 2019-01-07 +# @version 1.0 # -# @change: "2015-08-10 10:00" ljd 下发周围玩家时装穿戴状态 # 详细描述: 玩家时装外套 # #--------------------------------------------------------------------- -"""Version = 2015-08-10 10:00""" +"""Version = 2019-01-07 10:00""" #--------------------------------------------------------------------- -import ReadChConfig import NetPackCommon import IPY_GameWorld import PlayerControl @@ -26,10 +24,10 @@ import ChPyNetSendPack import ShareDefine import ItemCommon -import EventReport +import DataRecordPack +import IpyGameDataPY import GameWorld import ChConfig -import ChEquip import math @@ -39,83 +37,6 @@ def OnLogin_Coat(curPlayer): Sync_ClothesCoatSkinInfo(curPlayer) return - - -## 激活时装衣服皮肤 -# @param curPlayer -# @return None -def ActivateClothesCoatSkinItem(curPlayer, clothesCoatSkinID): - - playerID = curPlayer.GetPlayerID() - - clothesCoatSkinDict = ReadChConfig.GetEvalChConfig("ClothesCoatSkin") - if clothesCoatSkinID not in clothesCoatSkinDict: - GameWorld.ErrLog("激活时装皮肤异常,无该时装皮肤物品信息!ClothesCoatSkin.txt! ID=%s" % clothesCoatSkinID, playerID) - return False - - clotherSkinInfo = clothesCoatSkinDict[clothesCoatSkinID] - if not clotherSkinInfo: - return False - - curSkinIndex = clotherSkinInfo[0] - skinOpenState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinOpenState) - curSkinState = skinOpenState & pow(2, curSkinIndex) - - if curSkinState: -# GameWorld.Log("该时装皮肤已经激活过!clothesCoatSkinID=%s,index=%s,skinOpenState=%s" -# % (clothesCoatSkinID, curSkinIndex, skinOpenState), playerID) -# PlayerControl.NotifyCode(curPlayer, "GeRen_hgg_850801") - #当使用已激活过的时装激活道具时,将获得一定数量的物品 返回Ture扣除物品 - clothesCoatUpDict = ReadChConfig.GetEvalChConfig("ClothesCoatUp") - if curSkinIndex not in clothesCoatUpDict: - PlayerControl.NotifyCode(curPlayer, "GeRen_hgg_850801") - return False - packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, 1) - if packSpace < 1: - PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_998371") - return False - itemId, getItemCntList = clothesCoatUpDict[curSkinIndex] - if not getItemCntList: - return False - getItemCnt = getItemCntList[0] - - packIndexList = [IPY_GameWorld.rptItem] - ItemControler.GivePlayerItem(curPlayer, itemId, getItemCnt, True, packIndexList, True, showSysInfo=True) - return True - - isOK = ItemControler.PutItemInTempSwap(curPlayer, clothesCoatSkinID) - if not isOK: - GameWorld.Log("时装放入临时交换背包失败!", playerID) - return False - - #=========================================================================== - # # 获得放入的时装 - # clothesItem = ItemCommon.FindItemInPackByItemID(curPlayer, clothesCoatSkinID, - # ShareDefine.rptTempSwap) - # if not clothesItem: - # return False - # - # tick = GameWorld.GetGameWorld().GetTick() - # ChEquip.DoPlayerEquipItem(curPlayer, clothesItem, IPY_GameWorld.retClothesCoat, tick) - #=========================================================================== - - # 更新幻化状态 - updSkinOpenState = skinOpenState | pow(2, curSkinIndex) - PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ClothesSkinOpenState, updSkinOpenState) - Sync_ClothesCoatSkinInfo(curPlayer, curSkinIndex) - GameWorld.Log("时装激活成功!clothesCoatSkinID=%s,index=%s,skinOpenState=%s,updSkinOpenState=%s" - % (clothesCoatSkinID, curSkinIndex, skinOpenState, updSkinOpenState), playerID) - - # 刷属性 - PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState() - - ClothesCoaSkinNotifyDict = ReadChConfig.GetEvalChConfig("ClothesCoaSkinNotify") - if clothesCoatSkinID in ClothesCoaSkinNotifyDict: - notifyMark = ClothesCoaSkinNotifyDict[clothesCoatSkinID] - PlayerControl.WorldNotify(0, notifyMark, [curPlayer.GetPlayerName(), clothesCoatSkinID]) - - return True - #// A5 0B 玩家时装升级 #tagCMCoatUp # @@ -128,98 +49,126 @@ curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index) playerID = curPlayer.GetPlayerID() coatIndex = clientData.CoatIndex - clothesCoatUpDict = ReadChConfig.GetEvalChConfig("ClothesCoatUp") - if coatIndex not in clothesCoatUpDict: - GameWorld.DebugLog("clothesCoatUpDict.txt 未配置该索引 coatIndex=%s" % (coatIndex), playerID) + ipyData = IpyGameDataPY.GetIpyGameData('Coat', coatIndex) + if not ipyData: return - - skinOpenState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinOpenState) - if not skinOpenState & pow(2, coatIndex): - GameWorld.DebugLog("该时装未激活, 无法升级! coatIndex=%s" % (coatIndex), playerID) - return - costItemID, needCntList = clothesCoatUpDict[coatIndex] curSkinLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinLV % coatIndex) - - - if curSkinLV >= len(needCntList) - 1: + if curSkinLV >= ipyData.GetMaxLV(): GameWorld.DebugLog("该时装已满级,无法升级!coatIndex=%s,curSkinLV=%s" % (coatIndex, curSkinLV), playerID) return - plusCost = needCntList[curSkinLV + 1] - curBless = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinCurBless % coatIndex) - lackCnt = plusCost - curBless - - curPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem) - hasEnough, itemIndexList = ItemCommon.GetItem_FromPack_ByID(costItemID, curPack, lackCnt) - if not itemIndexList: - GameWorld.DebugLog("OnPlayerCoatUp() 时装升级材料不足, needCnt=%s" % (lackCnt)) + needCntList = ipyData.GetCostItemCnt() + if curSkinLV >= len(needCntList): return - if hasEnough: - reduceCnt = lackCnt - aftBless = 0 #升级后的经验值 - aftlv = curSkinLV + 1 - else: - reduceCnt = 0 - for itemIndex in itemIndexList: - curItem = curPack.GetAt(itemIndex) - itemCount = curItem.GetCount() - reduceCnt += itemCount - - aftBless = curBless + reduceCnt - aftlv = curSkinLV - + plusCost = needCntList[curSkinLV + 1] + costItemID = ipyData.GetUnlockItemID() + curPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem) + hasEnough, itemIndexList = ItemCommon.GetItem_FromPack_ByID(costItemID, curPack, plusCost) + if not hasEnough: + GameWorld.DebugLog("OnPlayerCoatUp() 时装升级材料不足, needCnt=%s" % (plusCost)) + return + + reduceCnt = plusCost + aftlv = curSkinLV + 1 + #扣除物品 - ItemCommon.ReduceItem(curPlayer, curPack, itemIndexList, reduceCnt, True) - if aftlv != curSkinLV: - PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ClothesSkinLV % coatIndex, aftlv) - if aftBless != curBless: - PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ClothesSkinCurBless % coatIndex, aftBless) - + ItemCommon.ReduceItem(curPlayer, curPack, itemIndexList, reduceCnt, True, 'CoatUp') + PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ClothesSkinLV % coatIndex, aftlv) + Sync_ClothesCoatSkinInfo(curPlayer, coatIndex) # 刷属性 + CalcClothesCoatSkinAttr(curPlayer) PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState() - clothesID = GetClothesIDByIndex(coatIndex) - itemData = GameWorld.GetGameData().GetItemByTypeID(clothesID) - coatName = clothesID if not itemData else itemData.GetName() - EventReport.WriteEvent_coat_lv(curPlayer, coatName, curSkinLV, curBless, reduceCnt, aftlv, aftBless) - GameWorld.DebugLog("时装升级!coatIndex=%s,coatName=%s,curSkinLV=%s,curBless=%s,reduceCnt=%s,aftlv=%s,aftBless=%s" - % (coatIndex, coatName, curSkinLV, curBless, reduceCnt, aftlv, aftBless), playerID) + extraInfoDict = {"coatID":coatIndex} + DataRecordPack.DR_ClassUpSystem(curPlayer, "CoatUp", aftlv, extraInfoDict) + + GameWorld.DebugLog("时装升级!coatIndex=%s,curSkinLV=%s,reduceCnt=%s,aftlv=%s" + % (coatIndex, curSkinLV, reduceCnt, aftlv), playerID) return +#// A5 20 时装分解 #tagCMCoatDecompose +# +#struct tagCMCoatDecompose +#{ +# tagHead Head; +# BYTE Count; //材料所在背包索引的数量 +# WORD IndexList[Count]; //材料所在背包索引列表 +# DWORD ItemIDList[Count]; //材料所在背包物品ID列表 +#}; +def OnCoatDecompose(index, clientData, tick): + curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index) + playerID = curPlayer.GetPlayerID() + indexList = clientData.IndexList + ItemIDList = clientData.ItemIDList + itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem) + addExp = 0 + for i, index in enumerate(indexList): + eatItem = itemPack.GetAt(index) + if not eatItem or eatItem.IsEmpty(): + continue + eatItemID = eatItem.GetItemTypeID() + if eatItemID != ItemIDList[i]: + continue + itemData = GameWorld.GetGameData().GetItemByTypeID(eatItemID) + if not itemData: + continue + curEff = itemData.GetEffectByIndex(0) + coatID = curEff.GetEffectValue(0) + ipyData = IpyGameDataPY.GetIpyGameData('Coat', coatID) + if not ipyData: + continue + curSkinLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinLV % coatID) + if curSkinLV >= ipyData.GetMaxLV(): + continue + itemCnt = eatItem.GetCount() + addExp += itemCnt * curEff.GetEffectValue(1) + ItemCommon.DelItem(curPlayer, eatItem, itemCnt, True, ChConfig.ItemDel_CoatDecompose) + if not addExp: + return + totalExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesChestEXP) + addExp + curChestLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesChestLV) + updChestLV = curChestLV + maxChestLV = IpyGameDataPY.IPY_Data().GetCoatChestUpByIndex(IpyGameDataPY.IPY_Data().GetCoatChestUpCount() - 1).GetLV() + for chestLV in xrange(curChestLV + 1, maxChestLV + 1): + ipyData = IpyGameDataPY.GetIpyGameData('CoatChestUp', chestLV) + if not ipyData: + break + needExp = ipyData.GetNeedExp() + if totalExp < needExp: + break + updChestLV = chestLV + totalExp -= needExp + if updChestLV != curChestLV: + PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ClothesChestLV, updChestLV) + # 刷属性 + CalcClothesCoatSkinAttr(curPlayer) + PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState() + PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ClothesChestEXP, min(totalExp, ChConfig.Def_UpperLimit_DWord)) + + Sync_ClothesCoatSkinInfo(curPlayer, coatID) + return ## 计算时装属性 # @param curPlayer 玩家 # @param allAttrList 属性列表 # @return None -def CalcClothesCoatSkinAttr(curPlayer, allAttrList): - skinOpenState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinOpenState) - - if not skinOpenState: - return - - clothesCoatSkinDict = ReadChConfig.GetEvalChConfig("ClothesCoatSkin") - clothesCoatUpDict = ReadChConfig.GetEvalChConfig("ClothesCoatUp") - for clothesInfo in clothesCoatSkinDict.values(): - curIndex, attrDict = clothesInfo - - if not skinOpenState & pow(2, curIndex): +def CalcClothesCoatSkinAttr(curPlayer): + allAttrList = [{} for _ in range(4)] + ipyMgr = IpyGameDataPY.IPY_Data() + for i in xrange(ipyMgr.GetCoatCount()): + ipyData = ipyMgr.GetCoatByIndex(i) + coatID = ipyData.GetCoatID() + skinLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinLV % coatID) + if not skinLV: continue - skinLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinLV % curIndex) - curExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinCurBless % curIndex) - if curIndex not in clothesCoatUpDict: - expPer = 0 - else: - itemCntList = clothesCoatUpDict[curIndex][1] - maxExp = itemCntList[skinLV + 1] if skinLV + 1 < len(itemCntList) else 0 - expPer = float(curExp) / maxExp if maxExp != 0 else 0 - for attrName, attrLVList in attrDict.items(): - attrValue = attrLVList[skinLV] if skinLV < len(attrLVList) else attrLVList[-1] - nextValue = attrLVList[skinLV + 1] if skinLV + 1 < len(attrLVList) else attrLVList[-1] - addValue = int(math.ceil((nextValue-attrValue) * expPer)) - PlayerControl.CalcAttrDict_Type(attrName, attrValue + addValue, allAttrList) - GameWorld.DebugLog(' 时装属性curIndex=%s attrName=%s,expPer=%s,attrValue=%s,addValue=%s' % (curIndex, attrName, expPer, attrValue, addValue)) - + starAttrDict = ipyData.GetStarAttr() + if str(skinLV) not in starAttrDict: + continue + for attrID, attrValue in starAttrDict[str(skinLV)].items(): + PlayerControl.CalcAttrDict_Type(int(attrID), attrValue, allAttrList) + # 保存计算值 + PlayerControl.SetCalcAttrListValue(curPlayer, ChConfig.Def_CalcAttrFunc_Coat, allAttrList) return @@ -231,8 +180,9 @@ # @param destIndex 目标索引 # @return def SwitchCoat(curPlayer, srcBackpack, desBackPack, srcIndex, destIndex): - if not ((desBackPack == IPY_GameWorld.rptEquip and srcBackpack == ShareDefine.rptTempSwap and destIndex == IPY_GameWorld.retClothesCoat) \ - or (srcBackpack == IPY_GameWorld.rptEquip and desBackPack == ShareDefine.rptTempSwap and srcIndex == IPY_GameWorld.retClothesCoat)): + clothesPlaceList = [ShareDefine.retWeaponSkin, ShareDefine.retClothesSkin, ShareDefine.retWeapon2Skin] + if not ((desBackPack == IPY_GameWorld.rptEquip and srcBackpack == ShareDefine.rptTempSwap and destIndex in clothesPlaceList) \ + or (srcBackpack == IPY_GameWorld.rptEquip and desBackPack == ShareDefine.rptTempSwap and srcIndex in clothesPlaceList)): return False #=============================================================================================== @@ -243,36 +193,38 @@ #=============================================================================================== playerID = curPlayer.GetPlayerID() - clothesIndex = IPY_GameWorld.retClothesCoat # 穿时装 if desBackPack == IPY_GameWorld.rptEquip: # 穿的时候srcIndex代表时装的索引 - skinOpenState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinOpenState) - if not skinOpenState & pow(2, srcIndex): - GameWorld.Log("时装未激活,不能穿!state=%s,srcIndex=%s" % (skinOpenState, srcIndex), playerID) + skinLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinLV%srcIndex) + if skinLV <= 0: + GameWorld.Log("时装未激活,不能穿!srcIndex=%s" % (srcIndex), playerID) return True - - findSwichClothesID = GetClothesIDByIndex(srcIndex) - - if findSwichClothesID <= 0: - GameWorld.Log("找不到时装ID,不能穿!srcIndex=%s" % (srcIndex), playerID) + ipyData = IpyGameDataPY.GetIpyGameData('Coat', srcIndex) + if not ipyData: return True - + EquipItemIDList = ipyData.GetEquipItemID + job = curPlayer.GetJob() + if job > len(EquipItemIDList): + GameWorld.Log("找不到该职业时装配置,不能穿!srcIndex=%s,job=%s" % (srcIndex, job), playerID) + return True + equipItemID = EquipItemIDList[job-1] # 找到时装ID后,srcIndex转化为交换物品的格子索引,默认0 - srcIndex, destIndex = 0, clothesIndex + srcIndex= 0 # 给临时交换物品 - if not ItemControler.PutItemInTempSwap(curPlayer, findSwichClothesID): - GameWorld.Log("时装ID(%s)放入临时交换背包失败!" % (findSwichClothesID), playerID) + if not ItemControler.PutItemInTempSwap(curPlayer, equipItemID): + GameWorld.Log("时装ID(%s)放入临时交换背包失败!" % (equipItemID), playerID) return True # 脱时装 else: ItemControler.ClearPack(curPlayer, ShareDefine.rptTempSwap) - srcIndex, destIndex = clothesIndex, 0 + destIndex = 0 isOK = ItemCommon.DoLogicSwitchItemEx(curPlayer, srcBackpack, desBackPack, srcIndex, destIndex) + ItemControler.ClearPack(curPlayer, ShareDefine.rptTempSwap) # 下发周围玩家时装穿戴状态 if isOK: if desBackPack == IPY_GameWorld.rptEquip: @@ -295,16 +247,6 @@ GameWorld.DebugLog("SwitchCoat isOK=%s" % isOK) return True -## 根据索引获取装备时装ID -def GetClothesIDByIndex(coatIndex): - findSwichClothesID = 0 - clothesCoatSkinDict = ReadChConfig.GetEvalChConfig("ClothesCoatSkin") - for clothesID, clothesInfo in clothesCoatSkinDict.items(): - index = clothesInfo[0] - if index == coatIndex: - findSwichClothesID = clothesID - break - return findSwichClothesID ## 通知客户端时装开启状态 # @param curPlayer @@ -312,26 +254,25 @@ def Sync_ClothesCoatSkinInfo(curPlayer, coatIndex= -1): stateData = ChPyNetSendPack.tagMCClothesCoatSkinState() stateData.Clear() - stateData.SkinOpenState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinOpenState) + stateData.CoatChestExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesChestEXP) + stateData.CoatChestLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesChestLV) stateData.CoatInfoList = [] - if coatIndex == -1: - clothesCoatSkinDict = ReadChConfig.GetEvalChConfig("ClothesCoatSkin") - for index in range(len(clothesCoatSkinDict)): - coatInfo = ChPyNetSendPack.tagMCClothesCoatLVInfo() - coatInfo.Clear() - coatInfo.CoatIndex = index - coatInfo.CoatLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinLV % index) - coatInfo.CoatExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinCurBless % index) - stateData.CoatInfoList.append(coatInfo) + coatIDList =[] + ipyMgr = IpyGameDataPY.IPY_Data() + for i in xrange(ipyMgr.GetCoatCount()): + ipyData = ipyMgr.GetCoatByIndex(i) + coatID = ipyData.GetCoatID() + coatIDList.append(coatID) else: + coatIDList = [coatIndex] + + for coatID in coatIDList: coatInfo = ChPyNetSendPack.tagMCClothesCoatLVInfo() coatInfo.Clear() - coatInfo.CoatIndex = coatIndex - coatInfo.CoatLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinLV % coatIndex) - coatInfo.CoatExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinCurBless % coatIndex) + coatInfo.CoatIndex = coatID + coatInfo.CoatLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinLV % coatID) stateData.CoatInfoList.append(coatInfo) - stateData.CoatNum = len(stateData.CoatInfoList) NetPackCommon.SendFakePack(curPlayer, stateData) return -- Gitblit v1.8.0