xdh
2018-10-25 6366979426fccd97c0cb0bd384ada3a8b9843a24
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package GM.Commands.AddLegendAttr
#
# @todo:Ìí¼Ó/ÖØÐÂÉú³É´«ÆæÊôÐÔ
# @author hxp
# @date 2017-08-23
# @version 1.0
#
# ÏêϸÃèÊö: Ìí¼Ó/ÖØÐÂÉú³É´«ÆæÊôÐÔ
#
#-------------------------------------------------------------------------------
#"""Version = 2017-08-23 23:00"""
#-------------------------------------------------------------------------------
 
import GameWorld
import ItemCommon
import ItemControler
import IPY_GameWorld
import IpyGameDataPY
import ShareDefine
import ChConfig
 
import random
 
#---------------------------------------------------------------------
#Âß¼­ÊµÏÖ
## GMÃüÁîÖ´ÐÐÈë¿Ú
#  @param curPlayer µ±Ç°Íæ¼Ò
#  @param cmdList ²ÎÊýÁбí [index£¬attrIndexList]
#  @return None
def OnExec(curPlayer, cmdList):
    cmdlen = len(cmdList)
    if cmdlen < 1:
        GameWorld.DebugAnswer(curPlayer, "ÖØÐÂËæ»ú´«ÆæÊôÐÔ: AddLegendAttr ±³°ü¸ñ×ÓË÷Òý")
        GameWorld.DebugAnswer(curPlayer, "Ìí¼ÓÖ¸¶¨´«ÆæÊôÐÔ: AddLegendAttr ±³°ü¸ñ×ÓË÷Òý ÊôÐÔID1 ÊôÐÔID2 ...")
        GameWorld.DebugAnswer(curPlayer, "Ìí¼ÓËùÓд«ÆæÊôÐÔ: AddLegendAttr ±³°ü¸ñ×ÓË÷Òý 0")
        return
    
    #»ñÈ¡ÎïÆ·
    index = cmdList[0]
    curItem = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem).GetAt(index)
    if not ItemCommon.CheckItemIsEquip(curItem):
        GameWorld.DebugAnswer(curPlayer, "·Ç×°±¸ÎÞ·¨»ñµÃ´«ÆæÊôÐÔ!")
        return
    
    attrIDList, attrValueList = [], [] # ÖØÐÂˢеÄÊôÐÔ
    addAttrIDList, addAttrValueList = [], [] # Ìí¼ÓµÄÊôÐÔ
    if curItem.GetType() == ChConfig.Def_ItemType_retWing:
        attrInfo = __GetWingGMAddLegendAttrInfo(curPlayer, curItem, cmdList)
    else:
        attrInfo = __GetEquipGMAddLegendAttrInfo(curPlayer, curItem, cmdList)
        
    if not attrInfo or (not attrInfo[0] and not attrInfo[1]):
        GameWorld.DebugAnswer(curPlayer, "»ñÈ¡¸Ã×°±¸´«ÆæÊôÐÔʧ°Ü»òûÓд«ÆæÊôÐÔ!")
        return
    
    if attrInfo[0]:
        attrIDList, attrValueList = attrInfo[0]
    if attrInfo[1]:
        addAttrIDList, addAttrValueList = attrInfo[1]
        
    # ´«ÆæÊôÐÔ
    if attrIDList and attrValueList and len(attrIDList) == len(attrValueList):
        curItem.ClearUserAttr(ShareDefine.Def_IudetLegendAttrID)
        curItem.ClearUserAttr(ShareDefine.Def_IudetLegendAttrValue)
        GameWorld.DebugLog("ˢд«ÆæÊôÐÔ: ID=%s,value=%s" % (attrIDList, attrValueList))
        for i, attrID in enumerate(attrIDList):
            curItem.AddUserAttr(ShareDefine.Def_IudetLegendAttrID, attrID)
            curItem.AddUserAttr(ShareDefine.Def_IudetLegendAttrValue, attrValueList[i])
            
    # Ö±½ÓÌí¼ÓµÄ
    if addAttrIDList and addAttrValueList and len(addAttrIDList) == len(addAttrValueList):
        GameWorld.DebugLog("Ìí¼Ó´«ÆæÊôÐÔ: ID=%s,value=%s" % (addAttrIDList, addAttrValueList))
        for i, attrID in enumerate(addAttrIDList):
            curItem.AddUserAttr(ShareDefine.Def_IudetLegendAttrID, attrID)
            curItem.AddUserAttr(ShareDefine.Def_IudetLegendAttrValue, addAttrValueList[i])
            
        idList = [curItem.GetUserAttrByIndex(ShareDefine.Def_IudetLegendAttrID, i) \
                  for i in range(curItem.GetUserAttrCount(ShareDefine.Def_IudetLegendAttrID))]
        valueList = [curItem.GetUserAttrByIndex(ShareDefine.Def_IudetLegendAttrValue, i) \
                     for i in range(curItem.GetUserAttrCount(ShareDefine.Def_IudetLegendAttrValue))]
        GameWorld.DebugLog("µ±Ç°´«ÆæÊôÐÔ: ID=%s,value=%s" % (idList, valueList))
                    
    return
 
def __GetEquipGMAddLegendAttrInfo(curPlayer, curItem, cmdList):
    isAdd = False
    cmdlen = len(cmdList)
    equipPlace = curItem.GetEquipPlace()
    itemColor = curItem.GetItemColor()
    if cmdlen == 1:
        return ItemControler.GetAddEquipLegendAttr(curItem), []
    
    if cmdList[1] == 0:
        legAttrRuleDict = IpyGameDataPY.GetFuncEvalCfg("LegendAttrRule")
        if equipPlace not in legAttrRuleDict:
            GameWorld.DebugAnswer(curPlayer, "¸Ã×°±¸Î»ÎÞ·¨»ñµÃ´«ÆæÊôÐÔ£¡equipPlace=%s" % equipPlace)
            return
        commAttrList, goodAttrList, specAttrList = legAttrRuleDict[equipPlace]
        attrIDList = commAttrList + goodAttrList
        if specAttrList:
            if type(specAttrList) == int:
                attrIDList.append(specAttrList)
            else:
                attrIDList += specAttrList
    else:
        isAdd = True
        attrIDList = cmdList[1:]
        
    legAttrIDList = []
    legAttrValueList = []
    
    legAttrValueDict = IpyGameDataPY.GetFuncEvalCfg("LegendAttrValue")
    for attrID in attrIDList:
        if attrID not in legAttrValueDict:
            GameWorld.DebugAnswer(curPlayer, "ûÓиô«ÆæÊôÐÔ: %s" % attrID)
            continue
        colorValueDict = legAttrValueDict[attrID]
        if itemColor not in colorValueDict:
            continue
        legAttrIDList.append(attrID)
        legAttrValueList.append(colorValueDict[itemColor])
        
    if not legAttrIDList or not legAttrValueList:
        return
    return ([], [legAttrIDList, legAttrValueList]) if isAdd else ([legAttrIDList, legAttrValueList], [])
 
def __GetWingGMAddLegendAttrInfo(curPlayer, curItem, cmdList):
    isAdd = False
    cmdlen = len(cmdList)
    if cmdlen == 1:
        return ItemControler.GetAddEquipLegendAttr(curItem), []
        
    itemClassLV = ItemCommon.GetItemClassLV(curItem)
    wingLegAttrValueDict = IpyGameDataPY.GetFuncEvalCfg("WingLegendAttrValue")
    if itemClassLV not in wingLegAttrValueDict:
        GameWorld.DebugAnswer(curPlayer, "¸Ã³á°ò½×¼¶ÎÞ·¨»ñµÃ´«ÆæÊôÐÔ£¡itemClassLV=%s" % itemClassLV)
        return
    curClassLVLegAttrDict = wingLegAttrValueDict[itemClassLV]
    if cmdList[1] == 0:
        attrIDList = curClassLVLegAttrDict.keys()
    else:
        isAdd = True
        attrIDList = cmdList[1:]
        
    legAttrIDList = []
    legAttrValueList = []
    for attrID in attrIDList:
        if attrID not in curClassLVLegAttrDict:
            GameWorld.DebugAnswer(curPlayer, "ûÓиóá°ò´«ÆæÊôÐÔ: %s" % attrID)
            continue
        legAttrIDList.append(attrID)
        legAttrValueList.append(random.choice(curClassLVLegAttrDict[attrID]))
        
    if not legAttrIDList or not legAttrValueList:
        return
    return ([], [legAttrIDList, legAttrValueList]) if isAdd else ([legAttrIDList, legAttrValueList], [])