#!/usr/bin/python # -*- coding: GBK -*- #------------------------------------------------------------------------------- # ##@package Player.PlayerFamilyStore # # @todo:Õ½Ã˱¦¿â # @author hxp # @date 2017-09-09 # @version 1.0 # # ÏêϸÃèÊö: Õ½Ã˱¦¿â # #------------------------------------------------------------------------------- #"""Version = 2017-09-09 18:30""" #------------------------------------------------------------------------------- import GameWorld import ItemCommon import IPY_GameWorld import IpyGameDataPY import PlayerControl import ItemControler import ShareDefine import ChConfig import EventShell import math #// A6 09 ¼Ò×å²Ö¿â¾èÔùÎïÆ· #tagCMFamilyStoreDonate # #struct tagCMFamilyStoreDonate #{ # tagHead Head; # BYTE ItemIndex; // ¾èÔùÎïÆ·ÔÚ±³°üÖеÄË÷Òý #}; def OnFamilyStoreDonate(index, clientData, tick): curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index) itemIndex = clientData.ItemIndex familyID = curPlayer.GetFamilyID() if not familyID: GameWorld.DebugLog("ûÓÐÕ½ÃË£¬ÎÞ·¨¾èÔù£¡", curPlayer.GetPlayerID()) return itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem) curItem = itemPack.GetAt(itemIndex) if not ItemCommon.CheckItemCanUse(curItem): GameWorld.DebugLog("ÎïÆ·²»¿ÉÓã¬ÎÞ·¨¾èÔù£¡itemIndex=%s" % itemIndex) return if curItem.GetIsBind(): GameWorld.DebugLog("×°±¸ÒѰ󶨣¬ÎÞ·¨¾èÔù£¡itemIndex=%s" % itemIndex) return if curItem.GetEndureReduceType(): GameWorld.DebugLog("ÓÐʱЧÄ;ÃÎïÆ·£¬ÎÞ·¨¾èÔù£¡itemIndex=%s" % itemIndex) return if not ItemCommon.CheckItemIsEquip(curItem): GameWorld.DebugLog("·Ç×°±¸£¬ÎÞ·¨¾èÔù£¡itemIndex=%s" % itemIndex) return if ItemCommon.CheckHasStone(curItem): GameWorld.DebugLog("×°±¸Óб¦Ê¯£¬ÎÞ·¨¾èÔù£¡itemIndex=%s" % itemIndex) return curPlaceRule = None equipPlace = curItem.GetEquipPlace() # Ôݶ¨×î¶àÖ§³Ö1~5ÖÖ¹æÔò for i in xrange(1, 6): itemRule = IpyGameDataPY.GetFuncCfgIpyData("FamilyStoreItemRule%s" % i) if not itemRule: break if equipPlace in itemRule.GetNumerical1(): curPlaceRule = itemRule.GetNumerical2() break if not curPlaceRule: GameWorld.ErrLog("ÕÒ²»µ½¸Ã×°±¸Î»¶ÔÓ¦µÄ¾èÔù¹æÔò£¬ÎÞ·¨¾èÔù!equipPlace=%s" % equipPlace) return reqClassLV, reqStar, reqColor = curPlaceRule itemClassLV = ItemCommon.GetItemClassLV(curItem) itemStar = curItem.GetItemQuality() itemColor = curItem.GetItemColor() if itemClassLV < reqClassLV: GameWorld.DebugLog("×°±¸½×¼¶²»×㣬²»ÄܾèÔù!itemIndex=%s,equipPlace=%s,reqClassLV=%s > itemClassLV=%s" % (itemIndex, equipPlace, reqClassLV, itemClassLV)) return if itemStar < reqStar: GameWorld.DebugLog("×°±¸ÐǼ¶²»×㣬²»ÄܾèÔù!itemIndex=%s,equipPlace=%s,reqStar=%s > itemStar=%s" % (itemIndex, equipPlace, reqStar, itemStar)) return if itemColor < reqColor: GameWorld.DebugLog("×°±¸ÑÕÉ«²»×㣬²»ÄܾèÔù!itemIndex=%s,equipPlace=%s,reqColor=%s > itemColor=%s" % (itemIndex, equipPlace, reqColor, itemColor)) return ipyData = IpyGameDataPY.GetIpyGameData("PetEatEquip", itemColor, itemClassLV) if not ipyData or not ipyData.GetFamilyStoreItemScore(): GameWorld.DebugLog("¸Ã×°±¸Ã»ÓÐÅäÖþèÔù»ý·Ö£¬ÎÞ·¨¾èÔù£¡itemColor=%s,itemClassLV=%s" % (itemColor, itemClassLV)) return itemScore = ipyData.GetFamilyStoreItemScore() if not __CheckCanFamilyStoreOperate(curPlayer, tick): return msgList = ["DonateReq", itemIndex, itemScore, curItem.GetGUID()] GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(curPlayer.GetID(), 0, 0, "FamilyStore", '%s' % (msgList), len(str(msgList))) return def __DoFamilyStoreDonateItem(curPlayer, itemIndex, itemScore, itemGUID): itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem) curItem = itemPack.GetAt(itemIndex) if not ItemCommon.CheckItemCanUse(curItem): GameWorld.ErrLog("¾èÔùÏÉÃËÎïƷʧ°Ü!ÎïÆ·²»¿ÉÓÃ!itemIndex=%s,itemGUID=%s" % (itemIndex, itemGUID), curPlayer.GetPlayerID()) return if itemGUID != curItem.GetGUID(): GameWorld.ErrLog("¾èÔùÏÉÃËÎïƷʧ°Ü!ÎïÆ·GUID²»Ò»ÖÂ!itemIndex=%s,itemGUID=%s,newGUID=%s" % (itemIndex, itemGUID, curItem.GetGUID()), curPlayer.GetPlayerID()) return itemID = curItem.GetItemTypeID() userData = curItem.GetUserData() itemDict = {"ItemID":itemID, "IsSuit":int(curItem.GetIsSuite()), "UserData":userData, "EquipGS":ItemCommon.GetEquipGearScore(curItem)} # ɾ³ýÎïÆ·, ¾èÔùµÄĬÈÏΪװ±¸£¬Ö»¿Û³ýÊýÁ¿1 ItemCommon.DelItem(curPlayer, curItem, 1, False, ChConfig.ItemDel_FamilyStore) # Ôö¼Ó¾èÔù»ý·Ö PlayerControl.GiveMoney(curPlayer, ShareDefine.TYPE_Price_FamilyStoreScore, itemScore) # ¹ã²¥Õ½ÃËƵµÀ PlayerControl.FamilyNotify(curPlayer.GetFamilyID(), "TreasuryDonation", [curPlayer.GetName(), itemID, userData]) # ͬ²½µ½GameServer²Ö¿â±£´æ msgList = ["DonateItem", itemDict] GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(curPlayer.GetID(), 0, 0, "FamilyStore", '%s' % (msgList), len(str(msgList))) EventShell.EventRespons_StoreDonate(curPlayer) return def OnFamilyStoreQueryResult(curPlayer, result): opType = result[0] # ¾èÏ×ÇëÇó·µ»Ø if opType == "DonateReq": itemIndex, itemScore, itemGUID, hasSpace = result[1:] if hasSpace: __DoFamilyStoreDonateItem(curPlayer, itemIndex, itemScore, itemGUID) return GameWorld.DebugLog("Õ½Ã˲ֿâûÓпռ䣬ÎÞ·¨¾èÔù!") # ¾èÏ×ÎïÆ·½á¹û·µ»Ø elif opType == "DonateItem": pass # ¶Ò»»ÎïÆ· elif opType == "Exchange": itemID = result[2] needScore = result[3] itemDict = result[4] if itemDict: # ¶Ò»»×°±¸Ä¬ÈÏ1¸ö£¬²»°ó¶¨ __DoGiveExchangeItem(curPlayer, itemID, 1, False, needScore, itemDict) curPlayer.SetDict(ChConfig.Def_PlayerKey_QueryFamilyStoreTick, 0) return #// A6 10 ¼Ò×å²Ö¿â¶Ò»»ÎïÆ· #tagCMFamilyStoreExchange # #struct tagCMFamilyStoreExchange #{ # tagHead Head; # BYTE StoreItemIndex; // 0-¶Ò»»¿ÚÁ¸£»>0-¶Ò»»²Ö¿âÎïÆ·£¬1´ú±íË÷Òý0µÄÎïÆ· # DWORD ItemID; // ¶Ò»»µÄÎïÆ·ID # WORD ExcangeCount; // ¶Ò»»¸öÊý #}; def OnFamilyStoreExchange(index, clientData, tick): curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index) itemIndex = clientData.StoreItemIndex itemID = clientData.ItemID excangeCount = clientData.ExcangeCount # Áé³è¿ÚÁ¸¶Ò»» if itemIndex <= 0: __DoExchangePetFood(curPlayer, excangeCount) return # ·Ç¿ÚÁ¸¶Ò»»µÄ»°Ä¬È϶һ»1¸ö hasSpace = ItemCommon.CheckPackHasSpace(curPlayer, IPY_GameWorld.rptItem) if not hasSpace: GameWorld.DebugLog("±³°üûÓпռ䣬ÎÞ·¨¶Ò»»£¡") return itemData = GameWorld.GetGameData().GetItemByTypeID(itemID) if not itemData: GameWorld.DebugLog("¶Ò»»ÎïÆ·ID²»´æÔÚ£¡itemID=%s" % itemID) return itemClassLV = ItemCommon.GetItemClassLV(itemData) itemColor = itemData.GetItemColor() ipyData = IpyGameDataPY.GetIpyGameData("PetEatEquip", itemColor, itemClassLV) if not ipyData or not ipyData.GetFamilyStoreItemScore(): GameWorld.DebugLog("¸Ã×°±¸Ã»ÓÐÅäÖþèÔù»ý·Ö£¬ÎÞ·¨¶Ò»»£¡itemColor=%s,itemClassLV=%s" % (itemColor, itemClassLV)) return needScore = ipyData.GetFamilyStoreItemScore() # ¶Ò»»ËùÐè»ý·Ö if not PlayerControl.HaveMoney(curPlayer, ShareDefine.TYPE_Price_FamilyStoreScore, needScore): GameWorld.DebugLog("²Ö¿â»ý·Ö²»×ã¶Ò»»£¡needScore=%s" % (needScore)) return if not __CheckCanFamilyStoreOperate(curPlayer, tick): return msgList = ["Exchange", itemIndex - 1, itemID, needScore] GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(curPlayer.GetID(), 0, 0, "FamilyStore", '%s' % (msgList), len(str(msgList))) return def __DoExchangePetFood(curPlayer, excangeCount): petFoodExchange = IpyGameDataPY.GetFuncCfgIpyData("PetFoodExchange") petFoodID = petFoodExchange.GetNumerical1() petFoodCount = petFoodExchange.GetNumerical2() # µ¥´Î¶Ò»»»ñµÃµÄ¸öÊý petFoodScore = petFoodExchange.GetNumerical3() itemData = GameWorld.GetGameData().GetItemByTypeID(petFoodID) if not itemData: return totalCount = excangeCount * petFoodCount packCount = itemData.GetPackCount() # ¶ÑµþÉÏÏÞ needSpace = int(math.ceil((totalCount) / float(packCount))) spaceCount = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, needSpace) if spaceCount < needSpace: GameWorld.DebugLog("±³°ü¿Õ¼ä²»×㣬ÎÞ·¨¶Ò»»¿ÚÁ¸£¡excangeCount=%s,needSpace=%s > spaceCount=%s" % (excangeCount, needSpace, spaceCount)) return costScore = petFoodScore * excangeCount if not PlayerControl.HaveMoney(curPlayer, ShareDefine.TYPE_Price_FamilyStoreScore, costScore): GameWorld.DebugLog("²Ö¿â»ý·Ö²»×ã¶Ò»»£¡costScore=%s" % (costScore)) return # ¶Ò»»¿ÚÁ¸Ä¬ÈÏ°ó¶¨ __DoGiveExchangeItem(curPlayer, petFoodID, totalCount, True, costScore) return def __DoGiveExchangeItem(curPlayer, itemID, itemCount, isBind, costScore, itemDict={}): # ¿ÛÇ® PlayerControl.PayMoney(curPlayer, ShareDefine.TYPE_Price_FamilyStoreScore, costScore) # ¸øÎïÆ· if itemDict: itemDict['IsBind'] = isBind ItemControler.GivePlayerEquip(curPlayer, itemDict, event=[ChConfig.ItemGive_FamilyStore, False, {}]) else: ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, 0, [IPY_GameWorld.rptItem], event=[ChConfig.ItemGive_FamilyStore, False, {}]) # ¹ã²¥Õ½ÃËƵµÀ PlayerControl.FamilyNotify(curPlayer.GetFamilyID(), "TreasuryExchange", [curPlayer.GetName(), costScore, itemID, itemDict.get("UserData","")]) GameWorld.DebugLog("__DoGiveExchangeItem, itemID=%s,itemCount=%s,isBind=%s,costScore=%s,itemDict=%s" % (itemID, itemCount, isBind, costScore, itemDict)) return def __CheckCanFamilyStoreOperate(curPlayer, tick): ## ¼ì²éÕ½Ã˲ֿâ²Ù×÷CD lastTick = curPlayer.GetDictByKey(ChConfig.Def_PlayerKey_QueryFamilyStoreTick) if lastTick and tick - lastTick < 5000: GameWorld.DebugLog("Õ½Ã˲ֿâ²Ù×÷CDÖÐ..., ÎÞ·¨´¦Àí£¡", curPlayer.GetPlayerID()) return False curPlayer.SetDict(ChConfig.Def_PlayerKey_QueryFamilyStoreTick, tick) return True