#!/usr/bin/python # -*- coding: GBK -*- #--------------------------------------------------------------------- # #--------------------------------------------------------------------- ##@package FunctionNPCCommon # @todo: ¹¦ÄÜNPC¹ÜÀíÆ÷ # # @author: panwei # @date 2010-4-26 # @version 4.4 # # @note: #--------------------------------------------------------------------- # @change: "2013-04-18 17:00" wdb ÎïÆ·ÑÕɫʹÓÃÐÞ¸Ä # @change: "2013-04-26 16:00" wdb npcÉ̵êÐÞ¸Ä # @change: "2013-05-03 17:00" wdb npcÉ̵êÅä±í·½Ê½ÐÞ¸Ä # @change: "2013-05-20 15:00" wdb ×°±¸¸½¼ÓÊôÐÔ½Ó¿ÚÐÞ¸Ä # @change: "2013-05-30 10:30" wdb ×°±¸±¦Ê¯ÏâǶµ÷Õû # @change: "2013-07-19 20:00" Alee Ìí¼Ó»Ø¹º # @change: "2013-07-22 17:00" Alee ÎïÆ·¿É°´ÊýÁ¿¹ºÂò # @change: "2013-10-12 21:10" Alee ϵͳÌáʾ # @change: "2013-10-22 11:10" Alee ÎïÆ·¼¼ÄÜÔöǿЧ¹û,ͳһº¯ÊýEquipAddAdditionEx # @change: "2013-11-08 22:30" Alee É̳ÇÌí¼Ó´ò¿× # @change: "2013-11-19 11:00" hxp Ð޸ijöÊÛÎïÆ·ÅжϽðÇ®ÉÏÏÞÂß¼­ # @change: "2014-01-16 13:54" xmnathan Õ½ÃËÉ̳ǹºÂò # @change: "2014-01-28 00:55" Alee ¶ñħÉ̵êĬÈÏ׿ԽºÍÌ××° # @change: "2014-02-12 14:00" Alee È¡ÏûºìÃû¹ºÂò³Í·£ # @change: "2014-04-07 11:30" Alee ·â°üDWORDµ¼Ö½ӿÚint±¨´í£¬·À·¶·¶Î§¹ý´ó # @change: "2014-05-05 15:00" xmnathan Ìæ»»ÏµÍ³Ìáʾ # @change: "2014-05-21 17:25" xcc Ôö¼Óħ·½Ñ°±¦»ý·Ö¶Ò»»ÎïÆ·¹¦ÄÜ # @change: "2014-06-05 15:30" hxp É̵êNPCÎïÆ·¹ºÂòÔö¼ÓÿÈտɹºÂò´ÎÊýÉÏÏÞÖ§³Ö # @change: "2014-08-04 16:00" Alee Ì××°ÎïÆ·É̵êÐÞ¸Ä # @change: "2014-08-07 20:40" Alee ±¦²Ø»ý·Ö¶Ò»»×¿Ô½ÊôÐÔ×°±¸¹Ì¶¨2ÌõÊôÐÔ # @change: "2014-08-12 11:30" xmnathan ÌìÌݾº¼¼ µãÊý¹ºÂò°ó¶¨ # @change: "2014-10-20 16:20" Alee ¶Ò»»Ì××°3׿Խ # @change: "2014-11-05 15:00" Alee É̵깺Âò°ó¶¨ÐÞ¸Ä # @change: "2014-12-11 16:30" hxp É̵ê¶Ò»»×°±¸Ôö¼ÓÖ§³ÖÅäÖÃ×°±¸¶ÔӦ׿ԽÌõÊý # @change: "2015-01-14 00:30" hxp Ôö¼ÓÎïÆ·±ä¸üʼþ»ã±¨ # @change: "2015-01-14 16:40" ljd Ôö¼ÓÎïÆ·¶Ò»»É̵ê # @change: "2015-01-27 10:50" ljd Ôö¼Ó×°±¸ÎïÆ·À´Ô´±ê¼Ç # @change: "2015-04-03 18:00" hxp ·À·¶»ØÊÕÕ¾Òì³£Çé¿öÎïÆ·Ïûʧ¶øÃ»ÓÐÖØÖñê¼Çλµ¼ÖÂÊýÖµÔ½½ç # @change: "2015-04-16 19:10" ljd É̵긶Ǯʱ´«ÈëÖ§¸¶ÀàÐÍ # @change: "2015-04-27 22:00" hxp Ôö¼ÓBuyItemÁ÷Ïò # @change: "2016-07-20 14:30" hxp »õ±ÒÖ§¸¶Á÷ÏòÕûºÏ # @change: "2016-08-04 18:00" hxp ³öÊۻعº¼Û¸ñÐÞ¸Ä #--------------------------------------------------------------------- #"""Version = 2016-08-04 18:00""" #--------------------------------------------------------------------- import ChPyNetSendPack import NetPackCommon import GameWorld import EventShell import IPY_GameWorld import ItemControler import ChConfig import PlayerControl import ItemCommon import ShareDefine import DataRecordPack import EventSrc import ChItem import IpyGameDataPY import PlayerRune import PlayerSuccess import PlayerFairyCeremony import PyGameData import random import math #--------------------------------------------------------------------- ##¿ªÊ¼½»Ò× # @param curPlayer Íæ¼ÒʵÀý # @param tick ʱ¼ä´Á # @return ·µ»ØÖµÕæ, Âß¼­ÔËÐгɹ¦ # @remarks ¿ªÊ¼½»Ò× def StartTrade(curPlayer, tick): curActionObj = curPlayer.GetActionObj() if curActionObj == None: return if curActionObj.GetGameObjType() != IPY_GameWorld.gotNPC: return curActionNPC = GameWorld.GetNPCManager().GetNPCByIndex(curActionObj.GetIndex()) curActionNPCID = curActionNPC.GetNPCID() # ÉèÖõ±Ç°É̵êµÄnpcid curPlayer.SetDict(ChConfig.Def_PlayerKey_TradeTagNPC, curActionNPCID) #É趨Ϊ½ûÖ¹ÕûÀí±³°ü curPlayer.SetForbiddenResetItem(1) curPlayer.BeginSpecialEvent(ShareDefine.TYPE_Event_Shop) return True #------------------------------------------------------------------------------ ## »ñȡԶ³ÌÉ̵êµÄnpc # @param curPlayer Íæ¼ÒʵÀý # @return Ô¶³ÌÉ̵êµÄnpc def GetDirectNpcID(): return 0 #--------------------------------------------------------------------- ##½áÊøÊ¼þ # @param curPlayer Íæ¼ÒʵÀý # @param tick ʱ¼ä´Á # @return ·µ»ØÖµÕæ, Âß¼­ÔËÐгɹ¦ # @remarks ½áÊøÊ¼þ def ExitEvent(curPlayer, tick): EventShell.DoExitEvent(curPlayer) return True #--------------------------------------------------------------------- ##ÇëÇóÉ̵êÎïÆ·Áбí # @param curPlayer Íæ¼ÒʵÀý # @param tick ʱ¼ä´Á # @return ·µ»ØÖµÕæ, Âß¼­ÔËÐгɹ¦ def QueryNPCShopItem(playerIndex, clientData, tick): curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(playerIndex) #ʱ¼ä¼ä¸ôδµ½ if tick - curPlayer.GetTickByType(ChConfig.TYPE_Player_Tick_QueryFuncData) \ < ChConfig.TYPE_Player_Tick_Time[ChConfig.TYPE_Player_Tick_QueryFuncData]: return curPlayer.SetTickByType(ChConfig.TYPE_Player_Tick_QueryFuncData, tick) #Ö±½Ó²éѯ£¬´æÔÚ¸ÃNPCID¾Í·¢°ü tradeTagNPC = clientData.NPCShopID GameWorld.GetGameData().FilterShopItemByShopType(tradeTagNPC) shopItemCount = GameWorld.GetGameData().GetFilterShopItemCount() if shopItemCount <= 0: return # # É̵ênpcidÓ뵱ǰ¶Ô»°npc¶ÔÓ¦,0ΪԶ³ÌÉ̵ê # tradeTagNPC = clientData.NPCShopID # if tradeTagNPC != 0 and not CheckTradeTagNPC(curPlayer, tradeTagNPC): # return # ·¢ËÍÉÌÆ·½ñÈÕÒѹºÂò´ÎÊý #SyncShopItemTodayBuyCount(curPlayer) # ·¢ËÍÉ̵êÎïÆ·Áбí curPlayer.BeginShopEx(tradeTagNPC) return ##ͬ²½É̵êNPCÎïÆ·½ñÈÕ¹ºÂò´ÎÊý # @param curPlayer Íæ¼ÒʵÀý # @param npcID # @param itemIndex -1ʱͬ²½¸ÃNPCËùÓÐÎïÆ· # @return def SyncShopItemTodayBuyCount(curPlayer, itemIndexList=[], isReset=False): dayBuyCntInfo = ChPyNetSendPack.tagMCShopItemDayBuyCntInfo() dayBuyCntInfo.DayBuyCntList = [] if itemIndexList: for itemIndex in itemIndexList: __AppendShopItemDayBuyCntInfo(curPlayer, itemIndex, dayBuyCntInfo.DayBuyCntList, isReset) else: ipyDataMgr = IpyGameDataPY.IPY_Data() for i in xrange(ipyDataMgr.GetStoreCount()): shopItem = ipyDataMgr.GetStoreByIndex(i) if not shopItem.GetLimitCnt(): continue dayBuyCntKey = ChConfig.Def_PDict_ShopItemDayBuyCnt % shopItem.GetID() curDayBuyCnt = curPlayer.NomalDictGetProperty(dayBuyCntKey) if curDayBuyCnt <= 0: continue __AppendShopItemDayBuyCntInfo(curPlayer, shopItem.GetID(), dayBuyCntInfo.DayBuyCntList, isReset) dayBuyCntInfo.Count = len(dayBuyCntInfo.DayBuyCntList) NetPackCommon.SendFakePack(curPlayer, dayBuyCntInfo) return ##Ôö¼ÓÉ̵êÎïÆ·½ñÈÕ¹ºÂò´ÎÊýÐÅÏ¢ # @param curPlayer Íæ¼ÒʵÀý # @param npcID # @param itemIndex # @return def __AppendShopItemDayBuyCntInfo(curPlayer, itemIndex, dayBuyCntList, isReset): itemDayBuyCnt = ChPyNetSendPack.tagMCShopItemDayBuyCnt() itemDayBuyCnt.ItemIndex = itemIndex dayBuyCntKey = ChConfig.Def_PDict_ShopItemDayBuyCnt % itemIndex curDayBuyCnt = curPlayer.NomalDictGetProperty(dayBuyCntKey) itemDayBuyCnt.BuyCnt = curDayBuyCnt itemDayBuyCnt.IsReset = int(isReset) dayBuyCntList.append(itemDayBuyCnt) return ## µÇ¼ def ShopItemOnLogin(curPlayer): SyncShopItemTodayBuyCount(curPlayer) return ##É̵êÎïÆ·OnDay # @param curPlayer Íæ¼ÒʵÀý # @return def ShopItemOnDay(curPlayer, onEventType): if onEventType == ShareDefine.Def_OnEventType: refreshType = [3] elif onEventType == ShareDefine.Def_OnEventTypeEx: refreshType = [4] openServerDay = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ServerDay) if openServerDay % 3 == 0: refreshType = [4,7] else: return __ResetShopItemBuyCount(curPlayer, refreshType) return ##É̵êÎïÆ·OnWeek # @param curPlayer Íæ¼ÒʵÀý # @return def ShopItemOnWeek(curPlayer, onEventType): __ResetShopItemBuyCount(curPlayer, [onEventType]) return ##É̵êÎïÆ·OnMonth # @param curPlayer Íæ¼ÒʵÀý # @return def ShopItemOnMonth(curPlayer, onEventType): if onEventType == ShareDefine.Def_OnEventType: refreshType = 5 elif onEventType == ShareDefine.Def_OnEventTypeEx: refreshType = 6 else: return __ResetShopItemBuyCount(curPlayer, [refreshType]) return def __ResetShopItemBuyCount(curPlayer, onEventTypeList): #ÖØÖÃÉ̵êÎïÆ·¹ºÂò´ÎÊý 1£ºÖÜÒ»0µãˢР2£ºÖÜÒ»5µãˢР3£ºÃ¿ÈÕ0µãˢР4£ºÃ¿ÈÕ5µãˢР5ÿÔÂ0µã 6ÿÔÂ5µã syncIndexList = [] ipyDataMgr = IpyGameDataPY.IPY_Data() for i in xrange(ipyDataMgr.GetStoreCount()): shopItem = ipyDataMgr.GetStoreByIndex(i) if not shopItem.GetLimitCnt(): continue if shopItem.GetRefreshType() not in onEventTypeList: continue dayBuyCntKey = ChConfig.Def_PDict_ShopItemDayBuyCnt % shopItem.GetID() curDayBuyCnt = curPlayer.NomalDictGetProperty(dayBuyCntKey) if curDayBuyCnt <= 0: continue PlayerControl.NomalDictSetProperty(curPlayer, dayBuyCntKey, 0) syncIndexList.append(shopItem.GetID()) if syncIndexList: SyncShopItemTodayBuyCount(curPlayer, syncIndexList, True) return def ResetShopItemBuyCountByShopType(curPlayer, shopTypeList): ##¸ù¾ÝÉ̵êÀàÐÍÖØÖÃÉ̵êÏÞ¹ºÎïÆ·´ÎÊý syncIndexList = [] ipyDataMgr = IpyGameDataPY.IPY_Data() for i in xrange(ipyDataMgr.GetStoreCount()): shopItem = ipyDataMgr.GetStoreByIndex(i) if not shopItem.GetLimitCnt(): continue if shopItem.GetShopType() not in shopTypeList: continue dayBuyCntKey = ChConfig.Def_PDict_ShopItemDayBuyCnt % shopItem.GetID() curDayBuyCnt = curPlayer.NomalDictGetProperty(dayBuyCntKey) if curDayBuyCnt <= 0: continue PlayerControl.NomalDictSetProperty(curPlayer, dayBuyCntKey, 0) syncIndexList.append(shopItem.GetID()) if syncIndexList: SyncShopItemTodayBuyCount(curPlayer, syncIndexList, True) return ## »Ø¹ºÎïÆ· # @param None # @return None def BuyItemBack(curPlayer, clientPack, tick): index = clientPack.Index backPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptRecycle) if index >= backPack.GetCount(): #¼Ù°üÍ˳ö return curItem = backPack.GetAt(index) if not curItem or curItem.IsEmpty(): #ûÓÐÎïÆ·Í˳ö return realPutCount = curItem.GetCount() itemControl = ItemControler.PlayerItemControler(curPlayer) if not itemControl.CanPutInItem(IPY_GameWorld.rptItem, curItem.GetItemTypeID(), realPutCount, curItem.GetIsBind()): #ÎïÆ·²»ÄÜ·ÅÈëÍ˳ö PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_676165", [IPY_GameWorld.rptItem]) return itemPrice, priceType = __GetItemSellPrice(curPlayer, curItem) itemPrice = int(itemPrice) * realPutCount if not priceType or not itemPrice: return #¸¶Ç® infoDict = {ChConfig.Def_Cost_Reason_SonKey:curItem.GetItemTypeID()} if not PlayerControl.PayMoney(curPlayer, priceType, itemPrice, ChConfig.Def_Cost_BuyItemBack, infoDict): return itemControl.PutInItem(IPY_GameWorld.rptItem, curItem, event=["BuyItemBack", False, {}]) itemIndexs = str(curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_DelPackIndex)) itemIndexs = itemIndexs.replace(str(index + 1), '') if itemIndexs == '': #ûÓÐÎïÆ·±£Áô 0 itemIndexs = '0' PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_DelPackIndex, int(itemIndexs)) return ##¹ºÂòÎïÆ· # @param curPlayer Íæ¼ÒʵÀý # @param tick ʱ¼ä´Á # @return ·µ»ØÖµÕæ, Âß¼­ÔËÐгɹ¦ def BuyItem(curPlayer, tick): buyItemList = IPY_GameWorld.IPY_CBuyItemList() itemIndex = buyItemList.GetBuyItemIndex() if itemIndex < 0: return clientBuyCount = buyItemList.GetBuyCount() if not clientBuyCount: return ipyData = IpyGameDataPY.GetIpyGameData("Store", itemIndex) if not ipyData: return shopType = ipyData.GetShopType() if ipyData.GetOperationActionShop(): actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_SpringSale, {}) state = actInfo.get(ShareDefine.ActKey_State, 0) if not state: GameWorld.DebugLog("ÏÞÊ±ÌØ»Ý·Ç»î¶¯ÖУ¡state=%s" % (state), curPlayer.GetPlayerID()) return shopTypeList = actInfo.get(ShareDefine.ActKey_ShopTypeList, []) if not shopTypeList: return actShopType = shopTypeList[-1] if state > len(shopTypeList) else shopTypeList[state - 1] if shopType != actShopType: GameWorld.DebugLog("ÏÞÊ±ÌØ»Ý·Ç»î¶¯ÖеÄÉ̵êÀàÐÍ£¡state=%s,shopType=%s,actShopType=%s,shopTypeList=%s" % (state, shopType, actShopType, shopTypeList), curPlayer.GetPlayerID()) return # ÎïÆ·ÐÅÏ¢ limitLV = ipyData.GetLimitLV() if limitLV and curPlayer.GetLV() < limitLV: return LimitVIPLVList = ipyData.GetLimitVIPLV() LimitCntList = ipyData.GetLimitCnt() limitBuyCnt = 0 if LimitVIPLVList or LimitCntList: if not LimitVIPLVList: LimitVIPLVList = [0] if not LimitCntList: LimitCntList = [0] if len(LimitVIPLVList) != len(LimitCntList): GameWorld.Log(" ¹ºÂòÎïÆ·LimitVIPLV LimitCnt ³¤¶È²»Í¬") return curVIPlv = curPlayer.GetVIPLv() limitBuyCnt = -1 for i, viplv in enumerate(LimitVIPLVList): if curVIPlv < viplv: break limitBuyCnt = LimitCntList[i] if limitBuyCnt == -1: GameWorld.DebugLog(" vip%s²ÅÄܹºÂò"%viplv) return curDayBuyCnt = 0 dayBuyCntKey = ChConfig.Def_PDict_ShopItemDayBuyCnt % itemIndex if limitBuyCnt > 0: curDayBuyCnt = curPlayer.NomalDictGetProperty(dayBuyCntKey) canBuyCnt = max(0, limitBuyCnt - curDayBuyCnt) if canBuyCnt <= 0: GameWorld.DebugLog("BuyShopItem ½ñÈÕ¹ºÂò´ÎÊýÒÑÂú£¡shopType=%s,itemIndex=%s" % (shopType, itemIndex)) return if clientBuyCount > canBuyCnt: GameWorld.DebugLog("BuyShopItem ÐÞÕý¹ºÂò´ÎÊý£¡shopType=%s,itemIndex=%s,clientBuyCount=%s,canBuyCnt=%s" % (shopType, itemIndex, clientBuyCount, canBuyCnt)) clientBuyCount = canBuyCnt itemID, itemCount, isBind = ipyData.GetItemID(), ipyData.GetItemCnt(), ipyData.GetIsBind() itemListEx = ipyData.GetItemListEx() priceType, itemPrice = ipyData.GetMoneyType(), ipyData.GetMoneyNum() itemPrice *= clientBuyCount job = curPlayer.GetJob() jobItemList = ipyData.GetJobItem() totalItemList = [] if itemID: jobItemID = __GetShopJobItem(job, itemID, jobItemList) totalItemList.append([jobItemID, itemCount * clientBuyCount, isBind]) for itemIDEx, itemCountEx, isBindEx in itemListEx: jobItemID = __GetShopJobItem(job, itemIDEx, jobItemList) totalItemList.append([jobItemID, itemCountEx * clientBuyCount, isBindEx]) #ÔÊÐí¼ÛÇ®ÅäÖÃ0£¬ÓÃÀ´Ãâ·Ñ¹ºÂò if not totalItemList: GameWorld.ErrLog("Store shop item error! shopType=%s,totalItemList=%s,itemPrice=%s" % (shopType, totalItemList, itemPrice)) return mainItemID = 0 needPackSpaceDict = {} for i, itemInfo in enumerate(totalItemList): itemID = itemInfo[0] itemCnt = itemInfo[1] curItem = GameWorld.GetGameData().GetItemByTypeID(itemID) if not curItem: GameWorld.ErrLog("Store shop item error! shopType=%s,itemID=%s" % (shopType, itemID)) return packType = ShareDefine.rptRune if curItem.GetType() == ChConfig.Def_ItemType_Rune else IPY_GameWorld.rptItem needSpace = int(math.ceil(float(itemCnt) / curItem.GetPackCount())) needPackSpaceDict[packType] = needPackSpaceDict.get(packType, 0) + needSpace if i == 0: mainItemID = itemID if not mainItemID: return GameWorld.DebugLog("¹ºÂòÎïÆ·: shopType=%s,itemIndex=%s,clientBuyCount=%s,totalItemList=%s,mainItemID=%s,needPackSpaceDict=%s" % (shopType, itemIndex, clientBuyCount, totalItemList, mainItemID, needPackSpaceDict), curPlayer.GetPlayerID()) for packType, needSpace in needPackSpaceDict.items(): if needSpace > ItemCommon.GetItemPackSpace(curPlayer, packType, needSpace): curPlayer.ShopResult(itemIndex, IPY_GameWorld.tsrNoPlace) PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_676165", [packType]) return # ¹ºÂòÏÞÖÆÌõ¼þÀ©Õ¹ if CheckBuyItemLimitEx(curPlayer, shopType, itemIndex, mainItemID, ipyData.GetLimitValue()): GameWorld.Log("Store shop item buy limit! shopType=%s,itemIndex=%s,limitValue=%s" % (shopType, itemIndex, ipyData.GetLimitValue()), curPlayer.GetPlayerID()) return #-------------------------¿ªÊ¼¹ºÂòÎïÆ·----------------------------- beforeMoney = PlayerControl.GetMoney(curPlayer, priceType) infoDict = {"TotalItemList":totalItemList, "ClientBuyCount":clientBuyCount, "ShopType":shopType, "ShopItemIndex":itemIndex, ChConfig.Def_Cost_Reason_SonKey:mainItemID} if not PlayerControl.PayMoney(curPlayer, priceType, itemPrice, ChConfig.Def_Cost_BuyStoreItem, infoDict, clientBuyCount): curPlayer.ShopResult(itemIndex, IPY_GameWorld.tsrNoMoney) return afterMoney = PlayerControl.GetMoney(curPlayer, priceType) # ½ñÈÕ¹ºÂò´ÎÊý+1 if limitBuyCnt > 0: PlayerControl.NomalDictSetProperty(curPlayer, dayBuyCntKey, curDayBuyCnt + clientBuyCount) SyncShopItemTodayBuyCount(curPlayer, [itemIndex]) dataDict = {"ShopType":shopType, "ShopItemIndex":itemIndex, "ClientBuyCount":clientBuyCount, "ItemPrice":itemPrice, "MoneyType":priceType, "BeforeMoney":beforeMoney, "AfterMoney":afterMoney} isForceEvent = priceType not in [IPY_GameWorld.TYPE_Price_Silver_Money] itemControl = ItemControler.PlayerItemControler(curPlayer) for itemID, itemCount, isBind in totalItemList: curItemObj = ItemControler.GetOutPutItemObj(itemID, itemCount, isBind) if not curItemObj: continue userData = curItemObj.GetUserData() packType = ShareDefine.rptRune if curItemObj.GetType() == ChConfig.Def_ItemType_Rune else IPY_GameWorld.rptItem if not itemControl.PutInItem(packType, curItemObj, event=[ChConfig.ItemGive_BuyItem, isForceEvent, dataDict]): curItemObj.Clear() continue EventShell.EventRespons_BuyItem(curPlayer, itemID, itemCount) if ipyData.GetNotifyMark() and itemID == mainItemID: PlayerControl.WorldNotify(0, ipyData.GetNotifyMark(), [curPlayer.GetName(), mainItemID, userData]) #´¥·¢ÈÎÎñ¹ºÂòÎïÆ· EventShell.EventRespons_ShopBuy(curPlayer, shopType) #curPlayer.ShopResult(itemIndex, IPY_GameWorld.tsrShopOK) SyncShoppingResult(curPlayer, itemIndex, clientBuyCount) if itemIndex in IpyGameDataPY.GetFuncEvalCfg('CeremonyFireParty', 1, {}).values(): PlayerFairyCeremony.AddFCPartyActionCnt(curPlayer, ChConfig.Def_PPAct_Fireworks, clientBuyCount) return def __GetShopJobItem(job, itemID, jobItemList): ## »ñÈ¡É̳ÇÎïÆ·¶ÔÓ¦µÄÖ°ÒµÎïÆ·£¬ Ö°Òµ´Ó1¿ªÊ¼ for jobItemIDList in jobItemList: if type(jobItemIDList) not in [list, tuple]: GameWorld.ErrLog("É̳ÇÖ°ÒµÎïÆ·×é¸ñʽ´íÎó!shopItemID=%s,jobItemList=%s" % (itemID, jobItemList)) return itemID if itemID in jobItemIDList: if job <= 0 or job > len(jobItemIDList): GameWorld.ErrLog("É̳ÇÖ°ÒµÎïÆ·ÅäÖôíÎó,ûÓиÃÖ°Òµ¶ÔÓ¦ÎïÆ·ID!shopItemID=%s,job=%s" % (itemID, job)) return itemID return jobItemIDList[job - 1] return itemID def SyncShoppingResult(curPlayer, itemIndex, itemCnt): #֪ͨ¹ºÂò½á¹û resultInfo = ChPyNetSendPack.tagMCShoppingResult() resultInfo.ItemIndex = itemIndex resultInfo.ItemCnt = itemCnt NetPackCommon.SendFakePack(curPlayer, resultInfo) return ## É̵깺ÂòÎïÆ·ÏÞÖÆÌõ¼þÀ©Õ¹ # @param curPlayer Íæ¼ÒʵÀý # @return def CheckBuyItemLimitEx(curPlayer, shopNPCID, itemIndex, curItemID, limitValue): if shopNPCID == 7: #·ûÓ¡É̵ê return not PlayerRune.GetIsOpenByRuneID(curPlayer, curItemID) if shopNPCID in [8, 9, 10]: #ÏÉÃËÉ̵ê if curPlayer.GetFamilyID() == 0: #ÎÞ¼Ò×å return True curFamilyLV = curPlayer.GetFamilyLV() if curFamilyLV <= 0: curFamilyLV = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FamilyLV) return curFamilyLV < limitValue if shopNPCID in [15]: # ÏÞÊ±ÌØ»ÝÉ̵ê playerCreateRoleDays = GameWorld.GetCreateRoleDays(curPlayer) return playerCreateRoleDays != limitValue #ÑÌ»¨¿ñ»¶ if itemIndex in IpyGameDataPY.GetFuncEvalCfg('CeremonyFireParty', 1, {}).values(): return not PlayerFairyCeremony.IsCanBuyFireworks(curPlayer, itemIndex) # # limitPlusDict = {shopItem.GetLimitPlusType1():shopItem.GetLimitPlusValue1(), # shopItem.GetLimitPlusType2():shopItem.GetLimitPlusValue2(), # shopItem.GetLimitPlusType3():shopItem.GetLimitPlusValue3(), # } # # for limitType, limitValue in limitPlusDict.items(): # if limitType <= 0: # continue # # # ÓÅÏÈÅжÏNPC¶ÀÓÐµÄ # callFunc = GameWorld.GetExecFunc(EventSrc, "FunctionNPCShopBuyCheck.CheckByNPC_%s_%s" # % (shopNPCID, limitType)) # # if callFunc: # return callFunc(curPlayer, shopItem.GetItemID(), limitValue) # # # ¹«¹²ÏÞÖÆÌõ¼þÅÐ¶Ï # callFunc = GameWorld.GetExecFunc(EventSrc, "FunctionNPCShopBuyCheck.CheckPublic_%s" % limitType) # # if callFunc: # return callFunc(curPlayer, shopItem.GetItemID(), limitValue) # ĬÈϲ»ÏÞÖÆ return False ## É̵ênpcid # @param curPlayer Íæ¼ÒʵÀý # @return def GetCurTradeTagNPC(curPlayer): curActionNPCID = -1 # µ±Ç°É̵êµÄnpcid tradeTagNPC = curPlayer.GetDictByKey(ChConfig.Def_PlayerKey_TradeTagNPC) # Ô¶³ÌÉ̵ê if not tradeTagNPC: return GetDirectNpcID() # É̵ênpcidÓ뵱ǰ¶Ô»°npc¶ÔÓ¦ elif CheckTradeTagNPC(curPlayer, tradeTagNPC): return tradeTagNPC else: GameWorld.ErrLog("GetCurStoreItemList:trade tag NPC not match:%s"%tradeTagNPC, curPlayer.GetPlayerID()) return curActionNPCID ## ÅжϼǼµÄÉ̵ênpcidÊÇ·ñÕýÈ· # @param curPlayer Íæ¼ÒʵÀý # @param tradeTagNPC # @return def CheckTradeTagNPC(curPlayer, tradeTagNPC): curActionObj = curPlayer.GetActionObj() if not curActionObj: return False if curActionObj.GetGameObjType() != IPY_GameWorld.gotNPC: return False curActionNPC = GameWorld.GetNPCManager().GetNPCByIndex(curActionObj.GetIndex()) if curActionNPC.GetNPCID() != tradeTagNPC: return False return True #--------------------------------------------------------------------- ##¼ì²éÎïÆ·¿É·ñÐÞÀí # @param curPlayer Íæ¼ÒʵÀý # @param curItem ÎïÆ·ÊµÀý # @param farRepair ÊÇ·ñÔ¶³ÌÐÞÀí # @return ·µ»ØÖµÕæ, ¼ì²éͨ¹ý # @remarks ¼ì²éÎïÆ·¿É·ñÐÞÀí #=============================================================================== # def __CheckRepairItem(curPlayer, curItem, farRepair): # # if not ItemCommon.CheckItemCanUse(curItem): # if not farRepair: # #·â°üÐÅÏ¢²»ÕýÈ· # PlayerControl.NotifyCode(curPlayer, "UseResLost04") # # return # # if curItem.GetCanRepair() == 0: # if not farRepair: # #ÎïÆ·²»¿ÉÐÞÀí # PlayerControl.NotifyCode(curPlayer, "UseResLost13") # # return # # if ItemControler.IsEventItem(curItem): # if not farRepair: # PlayerControl.NotifyCode(curPlayer, "itemuse_chenxin_31379") # # return # # if curItem.GetEndureReduceType() == ChConfig.Def_EquipReduceType_None or curItem.GetMaxEndure() == 0: # if not farRepair: # #Ä;Ã×Ö¶ÎΪ0£¬²»·ûºÏÒªÇ󣬷µ»Ø # PlayerControl.NotifyCode(curPlayer, "UseResLost13") # # return # # return True #=============================================================================== #--------------------³öÊÛÎïÆ· ##³öÊÛÎïÆ· # @param curPlayer Íæ¼ÒʵÀý # @param tick ʱ¼ä´Á # @return ·µ»ØÖµÕæ, Âß¼­ÔËÐгɹ¦ # @remarks ³öÊÛÎïÆ· def SellItem(curPlayer, tick): #1¼ì²éʼþ·¢ÉúµÄ˳Ðò sendData = IPY_GameWorld.IPY_CPlayerSellItem() packType = sendData.GetPackType() itemIndex = sendData.GetItemIndex() shopType = ChConfig.Def_ShopType_NpcShop return SellPackItem(curPlayer, packType, [itemIndex], shopType) #// A3 11 ÅúÁ¿³öÊÛÎïÆ· #tagCMSellItem # #struct tagCMSellItem #{ # tagHead Head; # BYTE PackType; //±³°üÀàÐÍ # BYTE Count; //Ë÷ÒýÊýÁ¿ # BYTE ItemIndex[Count]; //ÎïÆ·Ë÷Òý #}; def OnSellManyItem(index, clientData, tick): curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index) packType = clientData.PackType ItemIndexList = clientData.ItemIndex if not ItemIndexList: return shopType = ChConfig.Def_ShopType_NpcShop isOk = SellPackItem(curPlayer, packType, ItemIndexList, shopType) if isOk: curPlayer.Sync_MakeItemAnswer(ShareDefine.Def_mitKeySell, 1) return #--------------------------------------------------------------------- ##³öÊÛÖ¸¶¨±³°üÎïÆ· # @param curPlayer Íæ¼ÒʵÀý # @param packType ±³°üÀàÐÍ # @param itemIndex ÎïÆ·Ë÷Òý # @param shopType É̵êÀàÐÍ,1NPCÉ̵꣬2Ô¶³Ì··ÊÛ # @return ·µ»ØÖµÕæ, ¼ì²éͨ¹ý # @remarks ³öÊÛÖ¸¶¨±³°üÎïÆ· def SellPackItem(curPlayer, packType, itemIndexList, shopType): totalSellPrice = 0 backPack = curPlayer.GetItemManager().GetPack(packType) if backPack == None: return False hasSellOK = False notForceRecordEquipTypeList = range(ChConfig.Def_ItemType_retWeapon, ChConfig.Def_ItemType_retNeck) for itemIndex in itemIndexList: curItem = backPack.GetAt(itemIndex) if not __CheckItemSell(curPlayer, curItem): continue hasSellOK = True #µ±Ç°ÎïÆ·ÊýÁ¿ curItemCount = curItem.GetCount() #itemName = curItem.GetName() #»ñµÃµ¥¸öÎïÆ·ÏúÊÛ¼Û¸ñ curItemSellPrice, curItemSellType = __GetItemSellPrice(curPlayer, curItem) #»ñµÃÕû×éÏúÊÛ¼Û¸ñ curAllItemSellPrice = int(curItemSellPrice) * curItemCount totalSellPrice += curAllItemSellPrice #GameWorld.Log('curItemSellPrice=%s,curAllItemSellPrice=%s,curItemCount=%s'%(curItemSellPrice,curAllItemSellPrice,curItemCount)) #=========================================================================================== # #ÒòÈռǼǼ¹ý´ó, Ìí¼Ó¼Ç¼ɸѡÌõ¼þ # if ItemControler.ItemNeedRecord(curItem): # #Ïêϸ¼Ç¼װ±¸ÐÅÏ¢ # DataRecordPack.DR_GetMoneyBySellPackItem(curPlayer, curItemSellType, curAllItemSellPrice) #=========================================================================================== isForceDR = curItem.GetType() not in notForceRecordEquipTypeList and not ItemControler.ItemNotNeedRecord(curItem) #ÎïÆ·Ïûʧ ItemCommon.DelItem(curPlayer, curItem, curItemCount, False, ChConfig.ItemDel_SellPackItem, isForceDR=isForceDR) #PutItemInBuyBackPack(curPlayer, curItem) if not hasSellOK: return False #Íæ¼ÒÇ®Ôö¼Ó addDataDict = {} PlayerControl.GiveMoney(curPlayer, IPY_GameWorld.TYPE_Price_Silver_Money, totalSellPrice, ChConfig.Def_GiveMoney_SellPackItem, addDataDict, False) PlayerControl.NotifyCode(curPlayer, "GetMoney01", [IPY_GameWorld.TYPE_Price_Silver_Money, totalSellPrice]) return True ## ÊÛÂôÎïÆ·»Ø¹º±³°üµÄ´¦Àí, ·ÅÈë¿Õλ²»µþ¼Ó(±¾ÏîĿûÓлعº£¬ÏÈÆÁ±Î) # @param None # @return None def PutItemInBuyBackPack(curPlayer, curItem): return itemIndexs = str(curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_DelPackIndex)) backPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptRecycle) emptyIndex = ItemCommon.GetEmptyIndexInPack(curPlayer, IPY_GameWorld.rptRecycle) if emptyIndex == -1: #Çå³ý¾ÉÎïÆ· emptyIndex = int(itemIndexs[0]) - 1 item = backPack.GetAt(emptyIndex) item.Clear() itemIndexs = itemIndexs[1:] else: # Çå¿Õ¿Õ¸ñλ·À·¶, ·ÀÖ¹Òì³£Çé¿öÎïÆ·Ïûʧ¶øÃ»ÓÐÖØÖñê¼Çλµ¼ÖÂÊýÖµÔ½½ç itemIndexs = itemIndexs.replace(str(emptyIndex + 1), '') item = backPack.GetAt(emptyIndex) itemIndexs = "%s%s"%(itemIndexs, emptyIndex + 1) #·ÅÈëÐÂÎïÆ· item.PutIn(curItem) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_DelPackIndex, int(itemIndexs)) return ##¼ì²éÎïÆ·ÊÇ·ñ¿ÉÒÔ³öÊÛ # @param curPlayer Íæ¼ÒʵÀý # @param curItem ÎïÆ·ÊµÀý # @return ·µ»ØÖµÕæ, ¼ì²éͨ¹ý # @remarks ¼ì²éÎïÆ·ÊÇ·ñ¿ÉÒÔ³öÊÛ def __CheckItemSell(curPlayer, curItem) : if not ItemCommon.CheckItemCanUse(curItem): PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_644055") return if ItemControler.IsEventItem(curItem): PlayerControl.NotifyCode(curPlayer, "itemuse_chenxin_31379") return if curItem.GetCanSell() == 0: #²»ÄܳöÊÛµÄÎïÆ·,ÎÞ·¨³öÊÛ PlayerControl.NotifyCode(curPlayer, "GeRen_lhs_272921") return #»ñµÃµ¥¸öÎïÆ·ÏúÊÛ¼Û¸ñ itemPrice , priceType = __GetItemSellPrice(curPlayer, curItem) itemPrice = int(itemPrice) * curItem.GetCount() if not itemPrice or not priceType: PlayerControl.NotifyCode(curPlayer, "GeRen_lhs_272921") return if not PlayerControl.CanGiveMoney(curPlayer, priceType, itemPrice): # ¶Ô²»Æð£¬ÄúЯ´øµÄ½ðÇ®ÒѾ­´ïÉÏÏÞ,²Ù×÷ÎÞЧ #PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_609765") return return True #--------------------------------------------------------------------- ##»ñµÃÎïÆ·µÄ³öÊÛ¼Û¸ñ # @param curPlayer Íæ¼ÒʵÀý # @param curItem ÎïÆ·ÊµÀý # @return ·µ»ØÖµ, ÎïÆ·µÄ³öÊÛ¼Û¸ñ # @remarks »ñµÃÎïÆ·µÄ³öÊÛ¼Û¸ñ def __GetItemSellPrice(curPlayer, curItem): #ΪÅäºÏ¿Í»§¶Ë,½øÐÐÒÔÏÂÂß¼­(ÏòÉÏÈ¡Õû) #2012-03-26 jiang Ä;ÃÕâÀï²»½øÐгýChConfig.Def_EndureRepairParameterµÄת»»¸ÃÓй«Ê½×Ô¼º¼ÆËã #curItemEndure = curItem.GetCurDurg() #curItemMaxEndure = curItem.GetMaxEndure() # Ð޸Ĵ˺¯ÊýÇëͬʱÐÞ¸Ä ÍÑ»ú¹Ò³öÊÛ #µ±Ç°ÎïÆ·¼Û¸ñ Ô­¼Û³öÊÛ priceType = IPY_GameWorld.TYPE_Price_Silver_Money curItemPrice = curItem.GetSilverPrice() return curItemPrice, priceType #°ó¶¨¼Û¸ñÊÛ¼ÛΪ0, 2011.4.27 # if curItem.GetIsBind(): # itrmPrice_bind = eval(ReadChConfig.GetChConfig("ItemSellPrice_Bind")) # return itrmPrice_bind, priceType # # #ÎÞÄ;ÃÎïÆ· # if curItemEndure == 0 : # return curItemPrice * 0.5, priceType # # itrmPrice_notBind = eval(ReadChConfig.GetChConfig("ItemSellPrice_NotBind")) # return itrmPrice_notBind, priceType #=============================================================================== # 2010.11.25 °ó¶¨Êۼۺͷǰó¶¨Ò»Ö # #°ó¶¨µÄ # if curItem.GetIsBind(): # return curItemPrice * 0.5 * 0.5, curItemType # #·Ç°ó¶¨µÄ # return curItemPrice * 0.5, curItemType #=============================================================================== #=============================================================================== # # #°ó¶¨Õý³£ÎïÆ·³öÊÛ¼Û¸ñ # if curItem.GetIsBind() : # return eval(ChConfig.Def_Formula_ItemSellPrice) * 0.5, curItemType # # #δ°ó¶¨Õý³£ÎïÆ·³öÊÛ¼Û¸ñ # return eval(ChConfig.Def_Formula_ItemSellPrice), curItemType #=============================================================================== #--------------------------------------------------------------------- ##¼ì²éÍæ¼Ò¿É·ñ¿ªÊ¼NPCʼþ # @param curPlayer Íæ¼ÒʵÀý # @return ·µ»ØÖµÕæ, ¼ì²éͨ¹ý # @remarks ¼ì²éÍæ¼Ò¿É·ñ¿ªÊ¼NPCʼþ def CheckPlayerCanStateEvent(curPlayer): if curPlayer.GetPlayerAction() not in ChConfig.Def_Player_DoEvent_State : #CannotDoing ¶Ô²»Æð£¬Äúµ±Ç°×´Ì¬ÎÞ·¨½øÐд˲Ù×÷£¬²Ù×÷ÎÞЧ PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_740826") return False return True #--------------------------------------------------------------------- ##¼ì²éÎïÆ·ÊÇ·ñ¿ÉÒÔ·ÅÈëºÏ³É±³°ü. # @param curItem ÎïÆ·ÊµÀý # @return ²¼¶ûÖµ # @remarks ¼ì²éÎïÆ·ÊÇ·ñ¿ÉÒÔ·ÅÈëºÏ³É±³°ü def __CheckItemCanPutInComposePack(curItem): return curItem.GetType() in ChConfig.Def_Compose_Can_Put_List #--------------------------------------------------------------------- ##ͨÓñ³°ü·ÅÈë²Ù×÷ # @param curPlayer Íæ¼ÒʵÀý # @param srcBackpack Æðµã±³°ü # @param desBackPack Ä¿±ê±³°ü # @param srcIndex ÆðµãË÷Òý # @param destIndex Ä¿±êË÷Òý # @param putItemCount ·ÅÈëÊýÁ¿ # @param tick ʱ¼ä´Á # @return ·µ»ØÖµÎÞÒâÒå # @remarks ͨÓñ³°ü·ÅÈë²Ù×÷ def BackpackOperate(curPlayer, srcBackpack, desBackPack, srcIndex, destIndex, putItemCount, tick): #»ñµÃÐèÒª²Ù×÷µÄÎïÆ·µÄÎïÆ· scrItem = __GetBackPackOperateItem(curPlayer, srcBackpack, desBackPack, srcIndex) if scrItem == None: return itemControl = ItemControler.PlayerItemControler(curPlayer) if not itemControl.CanPutInItem(desBackPack, scrItem.GetItemTypeID(), putItemCount, scrItem.GetIsBind()): PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_676165", [desBackPack]) return #ÍÏ×§ÎïÆ· ItemControler.DragItem(curPlayer, srcBackpack, srcIndex, desBackPack, destIndex, putItemCount) return #--------------------------------------------------------------------- ##ͨÓñ³°ü²Ù×÷¼ì²é # @param scrItem ·ÅÈëÎïÆ· # @param desBackPack Ä¿±ê±³°ü # @return ²¼¶ûÖµ # @remarks ͨÓñ³°ü²Ù×÷¼ì²é def __CheckBackPackOperate(scrItem, desBackPack): #ÌØÊâ¼ì²é if desBackPack in ChConfig.Def_ComposePack_List: if not __CheckItemCanPutInComposePack(scrItem): GameWorld.ErrLog('BackpackOperate ItemErr = %s, ItemType = %s'%(scrItem.GetItemTypeID(), scrItem.GetType())) return False return True #--------------------------------------------------------------------- ##»ñµÃ±³°üµ±Ç°²Ù×÷µÄÎïÆ· # @param curPlayer Íæ¼ÒʵÀý # @param srcBackpack Æðʼ±³°ü # @param desBackPack Ä¿µÄ±³°ü # @param srcIndex ÆðʼÎïÆ·Ë÷Òý # @return ²Ù×÷ÎïÆ·ÊµÀý»òÕßNone # @remarks »ñµÃ±³°üµ±Ç°²Ù×÷µÄÎïÆ· def __GetBackPackOperateItem(curPlayer, srcBackpack, desBackPack, srcIndex): #²Ù×÷±³°ü¼ì²é if srcBackpack not in ChConfig.Def_BackpackOperate_List or desBackPack not in ChConfig.Def_BackpackOperate_List: GameWorld.ErrLog('PackItemExchange packErr, srcBackpack = %s, \ desBackPack = %s'%(srcBackpack, desBackPack), curPlayer.GetID()) return #»ñµÃ·ÅÈëµÄÎïÆ· scrItem = curPlayer.GetItemManager().GetPack(srcBackpack).GetAt(srcIndex) #---ÎïÆ·¼ì²é--- if not ItemCommon.CheckItemCanUse(scrItem): return #ÌØÊâ¼ì²é if not __CheckBackPackOperate(scrItem, desBackPack): return return scrItem #--------------------------------------------------------------------- ##ͨÓñ³°ü½»»»²Ù×÷ # @param curPlayer Íæ¼ÒʵÀý # @param srcBackpack Æðµã±³°ü # @param destBackPack Ä¿±ê±³°ü # @param srcIndex ÆðµãË÷Òý # @param destIndex Ä¿±êË÷Òý # @param tick ʱ¼ä´Á # @return ·µ»ØÖµÎÞÒâÒå # @remarks ͨÓñ³°ü½»»»²Ù×÷ def PackItemExchange(curPlayer, srcBackpack, destBackPack, srcIndex, destIndex, tick): #»ñµÃÐèÒª²Ù×÷µÄÎïÆ·µÄÎïÆ· scrItem = __GetBackPackOperateItem(curPlayer, srcBackpack, destBackPack, srcIndex) if scrItem == None: return #---Ñé֤Ŀ±ê±³°ü¸ñ×Ó-- destItem = curPlayer.GetItemManager().GetPack(destBackPack).GetAt(destIndex) #Ä¿±ê¸ñ×ÓÖ»ÑéÖ¤Ëø¶¨, ¿ÉÒÔÔÊÐí¿Õλ if destItem == None or destItem.GetIsLocked(): return ItemCommon.DoLogicSwitchItem(curPlayer, scrItem, destItem, destBackPack) return ## »ñµÃ½ðÇ®¸¶·Ñ×Öµä # @param moneyList ½ðÇ®Áбí [½ðÇ®ÀàÐÍ£¬ ½ðÇ®ÊýÁ¿£¬¡£¡£¡£] # @param payMoneyDict ½ðÇ®ÀÛ¼Ó×Öµä # @return ½ðÇ®ÀÛ¼Ó×Öµä # @remarks »ñµÃ½ðÇ®¸¶·Ñ×Öµä def GetPayMoneyDict(moneyList, payMoneyDict={}): length = len(moneyList) for index in range(0, length, 2): moneyType = moneyList[index] money = moneyList[index + 1] payMoney = payMoneyDict.get(moneyType) if payMoney == None: payMoneyDict[moneyType] = money else: payMoneyDict[moneyType] += money return payMoneyDict ## ¼ì²é½ðÇ® # @param curPlayer Íæ¼Ò # @param payMoneyDict ¸¶Ç®×Öµä # @return BOOLÊÇ·ñ×ã¹» # @remarks ¼ì²é½ðÇ® def CheckPayMoney(curPlayer, payMoneyDict): for moneyType, money in payMoneyDict.items(): #ÑéÖ¤ÊÖÐø·Ñ if not PlayerControl.HaveMoney(curPlayer, moneyType, money): return False return True