#!/usr/bin/python # -*- coding: GBK -*- #------------------------------------------------------------------------------- # #------------------------------------------------------------------------------- # ##@package Player.PlayerGodWeapon # # @todo:Éñ±ø # @author alee # @date 2017-07-20 # @version 1.0 # # ÏêϸÃèÊö: Éñ±ø # #--------------------------------------------------------------------- #"""Version = 2017-07-20 16:00""" #--------------------------------------------------------------------- import GameWorld import EventShell import ChConfig import PlayerControl import ItemCommon import IPY_GameWorld import ChPyNetSendPack import NetPackCommon import PlayerSuccess import ShareDefine import SkillShell import DataRecordPack import GameFuncComm import SkillCommon import BuffSkill import ItemControler #import EventReport import IpyGameDataPY import PassiveBuffEffMng import random ## ÉñÆ÷¹¦ÄܵǼ´¦Àí # @param curPlayer Íæ¼Ò # @return None def OnLogin(curPlayer): if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_GodWeapon): return Sync_GodWeaponLVInfo(curPlayer) return ## ÉñÆ÷¿ªÆô # @return: ÊÇ·ñ¼¤»î³É¹¦ def DoGodWeaponOpen(curPlayer): # ĬÈϼ¤»î1¼¶µÄÀàÐÍ for i in IpyGameDataPY.GetFuncEvalCfg('GodWeaponActive'): PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GodWeaponLV % i, 1) PlayerSuccess.UptateSuccessProgress(curPlayer, ShareDefine.SuccType_GodWeapon, 1, [i]) Sync_GodWeaponLVInfo(curPlayer) return True ## Ë¢ÐÂÉñ±øÊôÐÔ def RefreshGodWeaponAttr(curPlayer): CalcGodWeaponAttr(curPlayer) # ²»Á¢¼´Ë¢Ð PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState() return ## ¼ÆËãÊôÐÔ # @param curPlayer Íæ¼Ò # @param allAttrList ÊôÐÔÁбí # @return None def CalcGodWeaponAttr(curPlayer): if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_GodWeapon): return ipyDataMgr = IpyGameDataPY.IPY_Data() maxType = ipyDataMgr.GetGodWeaponByIndex(ipyDataMgr.GetGodWeaponCount()-1).GetType() allAttrList = [{} for i in range(4)] for gwType in xrange(1, maxType + 1): # ÒòΪÉñ±ø½âËøÌõ¼þ×öÁ˵÷Õû£¬ÓÉ֮ǰµÄ0~1½×½âËø¸ÄΪÓÉǰÖÃÉñ±øÀàÐ͵ȼ¶½âËø£¬Ä¬ÈϽâËøºóΪ1½× # Ϊ¼æÈÝÀϺţ¬Ë¢ÊôÐÔʱֻҪÅжϵȼ¶ÊÇ·ñ´óÓÚ0£¬²»¹ÜÊÇ·ñ½âËø£¬ÐºŽâËøÓÉÉñ±øÉý¼¶µÄʱºò½øÐнâËø attrLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponLV % gwType) if not attrLV: continue godWeaponData = IpyGameDataPY.GetIpyGameData('GodWeapon', gwType, attrLV) if not godWeaponData: continue attrTypeList, attrValueList = godWeaponData.GetAttrType(), godWeaponData.GetAttrNum() for i, attrID in enumerate(attrTypeList): PlayerControl.CalcAttrDict_Type(attrID, attrValueList[i], allAttrList) GameWorld.DebugLog("Éñ±øÊôÐÔ£º%s" % allAttrList) # ±£´æ¼ÆËãÖµ PlayerControl.SetCalcAttrListValue(curPlayer, ChConfig.Def_CalcAttrFunc_GodWeapon, allAttrList) return #--------------------------------------------------------------------------------------------------- #=============================================================================== #// A5 55 Éñ±øÉý¼¶ #tagCMGodWeaponPlus # #struct tagCMGodWeaponPlus #{ # tagHead Head; # DWORD WeaponType; // Éñ±øÀàÐÍ # DWORD ItemID; //ÏûºÄµÄÎïÆ·ID # BYTE ItemCount; //ÏûºÄ¸öÊý£¬Ä¬ÈÏ1 # BYTE IsAutoBuy; //ÊÇ·ñ×Ô¶¯¹ºÂò£¬Ä¬ÈÏ0 #}; #=============================================================================== def OnPlusGodWeapon(index, clientData, tick): curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index) weaponType = clientData.WeaponType useItemID = clientData.ItemID useItemCount = max(1, clientData.ItemCount) isAutoBuy = clientData.IsAutoBuy if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_GodWeapon): #µÈ¼¶²»×ã return #1.ÅжϱíÖÐÓÐû´ËÀàÐÍ£¬2.ÊÇ·ñÂú¼¶£¬3.ÅжÏÊÇ·ñÓÐÎïÆ· attrLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponLV % weaponType) if not attrLV: GameWorld.DebugLog("Éñ±øÎ´½âËø£¬ÎÞ·¨Éý¼¶£¡weaponType=%s,attrLV=%s" % (weaponType, attrLV)) return beforeAttrLV = attrLV # ÓÃÓÚÌáʾ godWeaponData = IpyGameDataPY.GetIpyGameData('GodWeapon', weaponType, attrLV) if not godWeaponData: GameWorld.DebugLog('Éñ±øÉý¼¶ÕÒ²»µ½Êý¾Ý %s-%s'%(weaponType, attrLV)) return totalExp = godWeaponData.GetExp() if totalExp == 0: #Âú¼¶ return #ÑéÖ¤ÊÇ·ñÖ¸¶¨µÄÎïÆ·ID if useItemID not in IpyGameDataPY.GetFuncEvalCfg("GodWeapon%s"%weaponType): return itemData = GameWorld.GetGameData().GetItemByTypeID(useItemID) if not itemData: return effect = ItemCommon.GetItemEffectByEffectID(itemData, ChConfig.Def_Item_Eff_GodWeaponExp) if not effect: GameWorld.DebugLog('###Éñ±ø¼Ù°ü£¬ÎïÆ·ID=%sûÓо­ÑéÖµ'%useItemID) return addExp = effect.GetEffectValue(0) if not addExp: GameWorld.DebugLog('###Éñ±ø¼Ù°ü£¬ÎïÆ·ID=%sûÓо­ÑéÖµ'%useItemID) return costItemIndexList, bindCnt, unBindCnt = ItemCommon.GetPackItemBindStateIndexInfo(curPlayer, useItemID, useItemCount) lackCount = max(0, useItemCount - (bindCnt + unBindCnt)) if lackCount > 0: if not isAutoBuy: GameWorld.DebugLog("Éñ±øÉý¼¶ÏûºÄ²»×ã!useItemID=%s,useItemCount=%s,bindCnt=%s,unBindCnt=%s,lackCount=%s" % (useItemID, useItemCount, bindCnt, unBindCnt, lackCount)) return lackCost = ItemCommon.GetAutoBuyItemNeedGold({useItemID:lackCount}) if lackCost <= 0: return infoDict = {ChConfig.Def_Cost_Reason_SonKey:useItemID} if not PlayerControl.PayMoney(curPlayer, IPY_GameWorld.TYPE_Price_Gold_Money, lackCost, ChConfig.Def_Cost_BuyStoreItem, infoDict, lackCount): return delUseItemCount = useItemCount - lackCount # ¿Û³ýÏûºÄ if delUseItemCount: ItemCommon.DelCostItemByBind(curPlayer, costItemIndexList, bindCnt, unBindCnt, delUseItemCount, ChConfig.ItemDel_GodWeapon) addTotalExp = addExp * useItemCount befExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponExp % weaponType) curExp = befExp + addTotalExp GameWorld.DebugLog("Ö´ÐÐÉñ±øÉý¼¶: weaponType=%s,beforeAttrLV=%s,befExp=%s,addTotalExp=%s(%s*%s),curExp=%s" % (weaponType, beforeAttrLV, befExp, addTotalExp, addExp, useItemCount, curExp)) isLVUP = False # °²È«ÎªÖ÷²»ÓÃwhile for _ in xrange(100): if curExp < totalExp: break godWeaponData = IpyGameDataPY.GetIpyGameData('GodWeapon', weaponType, attrLV+1) if not godWeaponData: GameWorld.DebugLog('Éñ±øÉý¼¶ÕÒ²»µ½Êý¾Ý %s-%s'%(weaponType, attrLV)) break GameWorld.DebugLog(" Éñ±øÉý¼¶: attrLV=%s,needExp=%s" % (attrLV, totalExp)) curExp = curExp - totalExp attrLV += 1 isLVUP = True GodWeaponLVUP(curPlayer, godWeaponData, attrLV) totalExp = godWeaponData.GetExp() if totalExp == 0: curExp = 0 #Âú¼¶ break PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GodWeaponLV % weaponType, attrLV) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GodWeaponExp % weaponType, curExp) if isLVUP: GameWorld.DebugLog("Éñ±øÉý¼¶½á¹û: attrLV=%s,curExp=%s" % (attrLV, curExp)) RefreshGodWeaponAttr(curPlayer) #xÉñÆ÷´ïµ½X¼¶³É¾Í PlayerSuccess.UptateSuccessProgress(curPlayer, ShareDefine.SuccType_GodWeapon, attrLV, [weaponType]) if beforeAttrLV == 0: # ½â·â֪ͨ sysMark = IpyGameDataPY.GetFuncEvalCfg('GodWeaponSys', 1, {}).get(weaponType, 'GetGodWeapon') PlayerControl.WorldNotify(0, sysMark, [curPlayer.GetName(), weaponType]) #{1:[100,200,300,400],2:[100,200,300,400],3:[100,200,300,400]} notifyDict = IpyGameDataPY.GetFuncEvalCfg('GodLv', 1, {}) if weaponType in notifyDict: for notifyLV in notifyDict[weaponType]: if beforeAttrLV < notifyLV and attrLV >= notifyLV: PlayerControl.WorldNotify(0, 'GodWeaponLv', [curPlayer.GetName(), weaponType, notifyLV]) #Éý¼¶ÅжÏÊÇ·ñ¿É½âËøÆäËûÉñ±ø godWeaponUnlockDict = IpyGameDataPY.GetFuncEvalCfg("GodWeaponActive", 2, {}) for unlockGodWeaponType, unlockConditionList in godWeaponUnlockDict.items(): unlockGodWeaponType = int(unlockGodWeaponType) if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponLV % unlockGodWeaponType): GameWorld.DebugLog("ÒѾ­½âËøµÄÉñ±ø²»ÐèÒªÔÙÅжÏ!unlockGodWeaponType=%s" % unlockGodWeaponType) continue isUnlock = True for needType, needLV in unlockConditionList: needTypeLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponLV % needType) if needTypeLV < needLV: isUnlock = False GameWorld.DebugLog("ËùÐèǰÖÃÉñ±øµÈ¼¶²»×㣬ÎÞ·¨½âËø£¡unlockGodWeaponType=%s,needType=%s,needLV=%s > needTypeLV(%s)" % (unlockGodWeaponType, needType, needLV, needTypeLV)) break if isUnlock: PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GodWeaponLV % unlockGodWeaponType, 1) GameWorld.DebugLog("½âËøÉñ±ø: unlockGodWeaponType=%s" % unlockGodWeaponType) Sync_GodWeaponLVInfo(curPlayer, unlockGodWeaponType) Sync_GodWeaponLVInfo(curPlayer, weaponType) #ÈÎÎñ EventShell.EventRespons_PlusGodWeapon(curPlayer) return #Éñ±øÉý¼¶´¥·¢ÆäËû¹¦ÄÜ£º¼¼ÄÜ def GodWeaponLVUP(curPlayer, godWeaponData, attrLV): skillID = godWeaponData.GetSkillID() if skillID: if __GiveGodWeaponSkill(curPlayer, skillID): sysMark = godWeaponData.GetSysMark() if sysMark: PlayerControl.WorldNotify(0, sysMark, [curPlayer.GetName(), attrLV, skillID]) ## ͬ²½ÉñÆ÷µÈ¼¶ # @param curPlayer # @param godWeaponId ÉñÆ÷ID # @return None def Sync_GodWeaponLVInfo(curPlayer, godWeaponID=0): sendPack = ChPyNetSendPack.tagMCGodWeaponLVList() sendPack.Clear() sendPack.WeaponInfoList = [] if godWeaponID <= 0: # weaponStateStr = bin(curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponState))[::-1][:-2] # for i in range(0, len(weaponStateStr)): # if weaponStateStr[i] == '0': # #ÕÒ³ö¼¤»îµÄÉñ±ø # continue ipyDataMgr = IpyGameDataPY.IPY_Data() maxType = ipyDataMgr.GetGodWeaponByIndex(ipyDataMgr.GetGodWeaponCount()-1).GetType() for i in xrange(1, maxType + 1): weaponInfo = ChPyNetSendPack.tagMCGodWeaponLVInfo() weaponInfo.Clear() weaponInfo.WeaponType = i weaponInfo.WeaponLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponLV % i) weaponInfo.WeaponExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponExp % i) sendPack.WeaponInfoList.append(weaponInfo) else: weaponInfo = ChPyNetSendPack.tagMCGodWeaponLVInfo() weaponInfo.Clear() weaponInfo.WeaponType = godWeaponID weaponInfo.WeaponLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponLV % godWeaponID) weaponInfo.WeaponExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponExp % godWeaponID) sendPack.WeaponInfoList.append(weaponInfo) sendPack.WeaponNum = len(sendPack.WeaponInfoList) NetPackCommon.SendFakePack(curPlayer, sendPack) return def __GiveGodWeaponSkill(curPlayer, skillResId): # ÉñÆ÷ѧϰ¼¼ÄÜ skillManager = curPlayer.GetSkillManager() if skillManager.FindSkillBySkillTypeID(skillResId): GameWorld.DebugLog("godSkill() have learned skill(%s)" % skillResId) return skillData = GameWorld.GetGameData().FindSkillByType(skillResId, 1) if skillData == None: GameWorld.DebugLog("godSkill() hasn't find skill(%s)" % skillResId) return if not SkillShell.CheckLearnSkillCondition(curPlayer, skillData): GameWorld.DebugLog("godSkill() learn skill(%s) condition isn't enough" % skillResId) return skillManager.LVUpSkillBySkillTypeID(skillResId) #PlayerControl.NotifyCode(curPlayer, "Skill_andyshao_31379", [skillResId]) GameWorld.DebugLog("godSkill() skill(%s) success!" % skillResId) DataRecordPack.DR_LearnORUPSkill(curPlayer, skillResId, 0) #if SkillCommon.isPassiveSkill(skillData): # buffType = SkillCommon.GetBuffType(skillData) # BuffSkill.DoAddBuff(curPlayer, buffType, skillData, GameWorld.GetGameWorld().GetTick(), [], curPlayer) PassiveBuffEffMng.GetPassiveEffManager().RegistPassiveEff(curPlayer, skillResId) PlayerControl.PlayerControl(curPlayer).RefreshSkillFightPowerEx(skillResId, 0) return True