#!/usr/bin/python # -*- coding: GBK -*- #------------------------------------------------------------------------------- # #------------------------------------------------------------------------------- # ##@package Player.PlayerCoat # # @todo:Íæ¼ÒʱװÍâÌ× # @author xdh # @date 2019-01-07 # @version 1.0 # # ÏêϸÃèÊö: Íæ¼ÒʱװÍâÌ× # #--------------------------------------------------------------------- """Version = 2019-01-07 10:00""" #--------------------------------------------------------------------- import NetPackCommon import IPY_GameWorld import PlayerControl import ItemControler import ChPyNetSendPack import ShareDefine import ItemCommon import DataRecordPack import IpyGameDataPY import GameWorld import ChConfig import math ## µÇ¼ # @param curPlayer # @return None def OnLogin_Coat(curPlayer): Sync_ClothesCoatSkinInfo(curPlayer) return #// A5 0B Íæ¼ÒʱװÉý¼¶ #tagCMCoatUp # #struct tagCMCoatUp #{ # tagHead Head; # BYTE CoatIndex; // ʱװË÷Òý #}; def OnPlayerCoatUp(index, clientData, tick): curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index) playerID = curPlayer.GetPlayerID() coatIndex = clientData.CoatIndex ipyData = IpyGameDataPY.GetIpyGameData('Coat', coatIndex) if not ipyData: return curSkinLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinLV % coatIndex) if curSkinLV >= ipyData.GetMaxLV(): GameWorld.DebugLog("¸ÃʱװÒÑÂú¼¶£¬ÎÞ·¨Éý¼¶!coatIndex=%s,curSkinLV=%s" % (coatIndex, curSkinLV), playerID) return needCntList = ipyData.GetCostItemCnt() if curSkinLV >= len(needCntList): return plusCost = needCntList[curSkinLV] 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() ʱװÉý¼¶²ÄÁϲ»×ã, coatIndex=%s, costItemID=%s, needCnt=%s" % (coatIndex, costItemID, plusCost)) return reduceCnt = plusCost aftlv = curSkinLV + 1 #¿Û³ýÎïÆ· 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() 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]: GameWorld.Log('ʱװ·Ö½â ·¢µÄÎïÆ·ID²»¶ÔÓ¦index=%s eatItemID=%s,ItemIDList[i]=%s'%(index, eatItemID, ItemIDList[i]), playerID) 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: GameWorld.Log(' ʱװ·Ö½â, ûÓпɷֽâµÄItemIDList=%s'%ItemIDList, playerID) 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 def GetCoatQualityLVInfo(curPlayer): costQualityLVDict = {} ipyMgr = IpyGameDataPY.IPY_Data() for i in xrange(ipyMgr.GetCoatCount()): ipyData = ipyMgr.GetCoatByIndex(i) coatID = ipyData.GetCoatID() costQuality = ipyData.GetCostQuality() skinLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinLV % coatID) if not skinLV: continue costQualityLVDict[costQuality] = costQualityLVDict.get(costQuality, 0) + skinLV return costQualityLVDict ## ¼ÆËãʱװÊôÐÔ # @param curPlayer Íæ¼Ò # @param allAttrList ÊôÐÔÁбí # @return None def CalcClothesCoatSkinAttr(curPlayer): initFPAdd = 0 #³õʼսÁ¦ 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 initFPAdd += ipyData.GetInitFightPower() 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) #ʱװ¹ñÊôÐÔ curChestLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesChestLV) ipyData = IpyGameDataPY.GetIpyGameDataNotLog('CoatChestUp', curChestLV) if ipyData: for attrID, attrValue in ipyData.GetAddAttr().items(): PlayerControl.CalcAttrDict_Type(int(attrID), attrValue, allAttrList) # ±£´æ¼ÆËãÖµ curPlayer.SetDict(ChConfig.Def_PlayerKey_MFPEx % ShareDefine.Def_MFPType_Coat, initFPAdd) PlayerControl.SetCalcAttrListValue(curPlayer, ChConfig.Def_CalcAttrFunc_Coat, allAttrList) return ##´©ÉÏ/ÍÑÏÂʱװ # @param curPlayer Íæ¼ÒʵÀý # @param srcBackpack Æðµã±³°ü # @param desBackPack Ä¿±ê±³°ü # @param srcIndex ÆðµãË÷Òý # @param destIndex Ä¿±êË÷Òý # @return def SwitchCoat(curPlayer, srcBackpack, desBackPack, srcIndex, destIndex): clothesPlaceList = [6,7,8]#[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 #=============================================================================================== # # ²»¿ÉÒÔ½»»»Ê±×° # if curPlayer.GetMapID() in [ChConfig.Def_FBMapID_RedFort]: # PlayerControl.NotifyCode(curPlayer, "GeRen_liubo_422737") # return True #=============================================================================================== playerID = curPlayer.GetPlayerID() # ´©Ê±×° if desBackPack == IPY_GameWorld.rptEquip: # ´©µÄʱºòsrcIndex´ú±íʱװµÄË÷Òý skinLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinLV%srcIndex) if skinLV <= 0: GameWorld.Log("ʱװδ¼¤»î£¬²»ÄÜ´©£¡srcIndex=%s" % (srcIndex), playerID) return True 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= 0 # ¸øÁÙʱ½»»»ÎïÆ· if not ItemControler.PutItemInTempSwap(curPlayer, equipItemID): GameWorld.Log("ʱװID(%s)·ÅÈëÁÙʱ½»»»±³°üʧ°Ü!" % (equipItemID), playerID) return True # ÍÑʱװ else: ItemControler.ClearPack(curPlayer, ShareDefine.rptTempSwap) destIndex = 0 isOK = ItemCommon.DoLogicSwitchItemEx(curPlayer, srcBackpack, desBackPack, srcIndex, destIndex) # Ï·¢ÖÜÎ§Íæ¼Òʱװ´©´÷״̬ if isOK: if desBackPack == IPY_GameWorld.rptEquip: packIndex = IPY_GameWorld.rptEquip itemPlace = destIndex itemPack = curPlayer.GetItemManager().GetPack(packIndex) curItem = itemPack.GetAt(itemPlace) itemId = curItem.GetItemTypeID() itemStarLV = 0#curItem.GetItemStarLV() itemHoleCnt = 0#curItem.GetCanPlaceStoneCount() itemStoneCnt = 0#curItem.GetUseStoneCount() itemUseData = curItem.GetUserData() curPlayer.ChangeEquip(itemId, itemPlace, itemStarLV, itemHoleCnt, itemStoneCnt, itemUseData) else: packIndex = ShareDefine.rptTempSwap itemPack = curPlayer.GetItemManager().GetPack(packIndex) curItem = itemPack.GetAt(0) if curItem: curPlayer.Sync_UnEquipItem(curItem.GetItemTypeID(), srcIndex) GameWorld.DebugLog("SwitchCoat isOK=%s" % isOK) return True ## ֪ͨ¿Í»§¶Ëʱװ¿ªÆô״̬ # @param curPlayer # @return None def Sync_ClothesCoatSkinInfo(curPlayer, coatIndex= -1): stateData = ChPyNetSendPack.tagMCClothesCoatSkinState() stateData.Clear() stateData.CoatChestExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesChestEXP) stateData.CoatChestLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesChestLV) stateData.CoatInfoList = [] if coatIndex == -1: 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 = coatID coatInfo.CoatLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinLV % coatID) stateData.CoatInfoList.append(coatInfo) stateData.CoatNum = len(stateData.CoatInfoList) NetPackCommon.SendFakePack(curPlayer, stateData) return