| | |
| | | GameWorld.DebugLog("物品过期时间" + timeStr)
|
| | | return GameWorld.ChangeTimeStrToNum(timeStr)
|
| | |
|
| | | def CreateSingleItem(itemID, itemCount=1, isAuctionItem=False, expireTime=0):
|
| | | def CreateSingleItem(itemID, itemCount=1, isAuctionItem=False, expireTime=0, curPlayer=None, setAttrDict=None):
|
| | | ''' 创建物品
|
| | | @param isAuctionItem: 是否拍品,默认非拍品
|
| | | @param expireTime: 有效时间,时间单位由时效类型决定
|
| | |
| | | # 英雄
|
| | | if curSingleItem.GetType() == ChConfig.Def_ItemType_Hero:
|
| | | PlayerHero.InitHeroItem(curSingleItem)
|
| | | elif GetIsEquip(curSingleItem):
|
| | | setAttrDict = GetCreateEquipAttr(curSingleItem, curPlayer, setAttrDict)
|
| | | if setAttrDict == None:
|
| | | curSingleItem.Clear()
|
| | | return
|
| | | AddCreateItemAttr(curSingleItem, setAttrDict)
|
| | |
|
| | | #这里返回的是SingleItem , 如果创建了,未使用,会找出C++内存泄露!!!
|
| | | return curSingleItem
|
| | |
|
| | | def AddCreateItemAttr(curItem, setAttrDict):
|
| | | ## 设置生成装备所有属性
|
| | | if not setAttrDict:
|
| | | return
|
| | | for key, value in setAttrDict.items():
|
| | | key = GameWorld.ToIntDef(key, key)
|
| | | # 需支持
|
| | | # 1. UserData格式: {'19': ['1889', '2034', '893', '927'], '50': ['1702622046'], '17': ['39', '33', '34', '9']}
|
| | | # 2. 自定义字典: {"key":value, ...} key支持自定义或与UserData的key,value支持数值或列表,列表元素支持字符串或数值,均默认转为数值
|
| | | # 数值类型的默认为UserData属性 |
| | | if isinstance(key, int):
|
| | | if key % 2 == 0: # 偶数是单数值
|
| | | v = 0
|
| | | if isinstance(value, int):
|
| | | v = value
|
| | | elif (isinstance(value, list) or isinstance(value, tuple)) and value:
|
| | | v = GameWorld.ToIntDef(value[0], 0)
|
| | | curItem.SetUserAttr(key, v)
|
| | | elif isinstance(value, list) or isinstance(value, tuple): # 单数一定是要列表
|
| | | curItem.ClearUserAttr(key)
|
| | | for v in value:
|
| | | v = GameWorld.ToIntDef(v, 0)
|
| | | curItem.AddUserAttr(key, v)
|
| | | # 其他指定字符串类型属性
|
| | | else:
|
| | | GameWorld.Log("###AddCreateItemAttr unknown key:%s, value:%s, itemID=%s" % (key, value, curItem.GetItemTypeID()))
|
| | | |
| | | #MakeEquipGS(curItem)
|
| | | return
|
| | |
|
| | | def GetCreateEquipAttr(curItem, curPlayer=None, setAttrDict=None):
|
| | | '''获取生成装备所有属性
|
| | | @param curPlayer: 可能为None
|
| | | @param setAttrDict: 直接设置物品的属性 {key:value, ...} key支持 ShareDefine.Def_IudetXXX字符串 或 自定key
|
| | | @return: None - 异常情况,物品实例需要clear
|
| | | equipAttrDict - 生成后的最新属性k:v字典,可直接用于 SetCreateEquipAttr
|
| | | '''
|
| | | if setAttrDict == None:
|
| | | setAttrDict = {}
|
| | | equipAttrDict = {}
|
| | | playerID = 0 if not curPlayer else curPlayer.GetPlayerID()
|
| | | itemID = curItem.GetItemTypeID()
|
| | | |
| | | appointID = setAttrDict.get(ShareDefine.Def_CItemKey_AppointID)
|
| | | # 定制属性ID
|
| | | if appointID > 0:
|
| | | ipyData = IpyGameDataPY.GetIpyGameData("AppointItem", appointID)
|
| | | if not ipyData:
|
| | | return
|
| | | if ipyData.GetCancelUseLimit():
|
| | | equipAttrDict[str(ShareDefine.Def_IudetCancelUseLimit)] = 1
|
| | | equipAttrDict[str(ShareDefine.Def_IudetItemLV)] = ipyData.GetItemLV()
|
| | | equipAttrDict[str(ShareDefine.Def_IudetBaseAttrID)] = ipyData.GetBaseAttrID()
|
| | | equipAttrDict[str(ShareDefine.Def_IudetBaseAttrValue)] = ipyData.GetBaseAttrValue()
|
| | | equipAttrDict[str(ShareDefine.Def_IudetLegendAttrID)] = ipyData.GetLegendAttrID()
|
| | | equipAttrDict[str(ShareDefine.Def_IudetLegendAttrValue)] = ipyData.GetLegendAttrValue()
|
| | | GameWorld.DebugLog(" 装备定制属性: itemID=%s,appointID=%s,equipAttrDict=%s,setAttrDict=%s" % (itemID, appointID, equipAttrDict, setAttrDict), playerID)
|
| | | return equipAttrDict
|
| | | |
| | | # 主线装备
|
| | | if GetIsMainEquip(curItem):
|
| | | return GetCreateMainEquipAttr(curItem, curPlayer, setAttrDict)
|
| | | |
| | | return equipAttrDict
|
| | | |
| | | def GetCreateMainEquipAttr(curItem, curPlayer, setAttrDict=None):
|
| | | ## 生成主线装备属性
|
| | | |
| | | equipAttrDict = {}
|
| | | itemID = curItem.GetItemTypeID()
|
| | | itemColor = curItem.GetItemColor()
|
| | | equipPlace = curItem.GetEquipPlace()
|
| | | |
| | | if not curPlayer:
|
| | | return equipAttrDict
|
| | | |
| | | colorIpyData = IpyGameDataPY.GetIpyGameData("EquipColor", itemColor)
|
| | | placeIpyData = IpyGameDataPY.GetIpyGameData("EquipPlace", equipPlace)
|
| | | if not colorIpyData or not placeIpyData:
|
| | | return equipAttrDict
|
| | | |
| | | playerLV = curPlayer.GetLV()
|
| | | playerID = curPlayer.GetPlayerID()
|
| | | randfloat = random.uniform # 随机一个ab区间的数 [a, b],ab支持小数
|
| | | |
| | | itemLV = setAttrDict.get(str(ShareDefine.Def_IudetItemLV), 0)
|
| | | if not itemLV:
|
| | | # 随机等级
|
| | | lowLV, highLV = IpyGameDataPY.GetFuncEvalCfg("MainEquipDrop", 3)
|
| | | randLVList = range(max(playerLV + lowLV, 1), playerLV + highLV)
|
| | | itemLV = random.choice(randLVList)
|
| | | equipAttrDict[str(ShareDefine.Def_IudetItemLV)] = itemLV
|
| | | |
| | | GameWorld.DebugLog("生成主线装备: itemID=%s,itemLV=%s,itemColor=%s,equipPlace=%s" % (itemID, itemLV, itemColor, equipPlace), playerID)
|
| | | |
| | | # 基础三维
|
| | | baseAttrIDList = setAttrDict.get(str(ShareDefine.Def_IudetBaseAttrID))
|
| | | baseAttrValueList = setAttrDict.get(str(ShareDefine.Def_IudetBaseAttrValue))
|
| | | # 这里注意None为未指定,支持当空列表[]时为不给该属性
|
| | | if baseAttrIDList != None and baseAttrValueList != None and len(baseAttrIDList) == len(baseAttrValueList):
|
| | | equipAttrDict[str(ShareDefine.Def_IudetBaseAttrID)] = baseAttrIDList
|
| | | equipAttrDict[str(ShareDefine.Def_IudetBaseAttrValue)] = baseAttrValueList
|
| | | else:
|
| | | attrProportion = placeIpyData.GetBaseAttrProportion()
|
| | | attrInfoList = [
|
| | | [ShareDefine.Def_Effect_Atk, colorIpyData.GetAtkStep()],
|
| | | [ShareDefine.Def_Effect_Def, colorIpyData.GetDefStep()],
|
| | | [ShareDefine.Def_Effect_MaxHP, colorIpyData.GetHPStep()],
|
| | | ]
|
| | | baseAttrIDList, baseAttrValueList = [], []
|
| | | for attrID, attrStep in attrInfoList:
|
| | | attrValue = eval(IpyGameDataPY.GetFuncCompileCfg("MainEquipDrop", 4))
|
| | | # int(itemLV*attrStep*attrProportion*randfloat(0.9,1.1))
|
| | | if not attrValue:
|
| | | continue
|
| | | baseAttrIDList.append(attrID)
|
| | | baseAttrValueList.append(attrValue)
|
| | | |
| | | if baseAttrIDList:
|
| | | equipAttrDict[str(ShareDefine.Def_IudetBaseAttrID)] = baseAttrIDList
|
| | | equipAttrDict[str(ShareDefine.Def_IudetBaseAttrValue)] = baseAttrValueList
|
| | | GameWorld.DebugLog(" baseAttrIDList=%s,baseAttrValueList=%s" % (baseAttrIDList, baseAttrValueList), playerID)
|
| | | |
| | | # 战斗属性
|
| | | legendAttrIDList = setAttrDict.get(str(ShareDefine.Def_IudetLegendAttrID))
|
| | | legendAttrValueList = setAttrDict.get(str(ShareDefine.Def_IudetLegendAttrValue))
|
| | | if legendAttrIDList != None and legendAttrValueList != None and len(legendAttrIDList) == len(legendAttrValueList):
|
| | | equipAttrDict[str(ShareDefine.Def_IudetLegendAttrID)] = legendAttrIDList
|
| | | equipAttrDict[str(ShareDefine.Def_IudetLegendAttrValue)] = legendAttrValueList
|
| | | else:
|
| | | legendAttrIDList = []
|
| | | legendAttrValueList = []
|
| | | |
| | | attrRangeDefault = colorIpyData.GetAttrRange()
|
| | | attrRangeDict = colorIpyData.GetAttrRangeDict() |
| | | libCntList = colorIpyData.GetAttrLibCntList()
|
| | | GameWorld.DebugLog(" libCntList=%s,attrRangeDict=%s, %s" % (libCntList, attrRangeDict, attrRangeDefault), playerID)
|
| | | for num, attrCnt in enumerate(libCntList, 1):
|
| | | if not hasattr(placeIpyData, "GetAttrLib%s" % num):
|
| | | continue
|
| | | libAttrList = getattr(placeIpyData, "GetAttrLib%s" % num)()
|
| | | if not libAttrList:
|
| | | continue
|
| | | random.shuffle(libAttrList)
|
| | | randAttrList = libAttrList[:attrCnt]
|
| | | for attrID in randAttrList:
|
| | | if attrID in legendAttrIDList:
|
| | | continue
|
| | | attrRange = attrRangeDict.get(attrID, attrRangeDefault)
|
| | | if not attrRange or len(attrRange) != 2:
|
| | | continue
|
| | | attrMin, attrMax = attrRange
|
| | | attrValue = random.randint(attrMin, attrMax)
|
| | | legendAttrIDList.append(attrID)
|
| | | legendAttrValueList.append(attrValue)
|
| | | GameWorld.DebugLog(" libNum=%s,attrID=%s,attrValue=%s(%s~%s)" % (num, attrID, attrValue, attrMin, attrMax), playerID)
|
| | | |
| | | if legendAttrIDList:
|
| | | equipAttrDict[str(ShareDefine.Def_IudetLegendAttrID)] = legendAttrIDList
|
| | | equipAttrDict[str(ShareDefine.Def_IudetLegendAttrValue)] = legendAttrValueList
|
| | | GameWorld.DebugLog(" legendAttrIDList=%s,legendAttrValueList=%s" % (legendAttrIDList, legendAttrValueList), playerID)
|
| | | |
| | | GameWorld.DebugLog(" 装备最终属性: equipAttrDict=%s,setAttrDict=%s" % (equipAttrDict, setAttrDict), playerID)
|
| | | return equipAttrDict
|
| | |
|
| | | def SetItemUserData(curItem, dataInfo):
|
| | | if isinstance(dataInfo, dict):
|
| | |
| | | def GetIsEquip(curItem):
|
| | | return curItem.GetType() in ChConfig.Def_EquipItemType
|
| | |
|
| | | def GetIsMainEquip(curItem):
|
| | | ## 是否主线装备
|
| | | return curItem.GetType() in ChConfig.Def_MainEquipType
|
| | |
|
| | | def GetIsDogzEquip(curItem):
|
| | | ## 返回是否神兽装备
|
| | | return curItem.GetType() in ChConfig.Def_DogzEquiipType
|