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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
#
##@package Player.PlayerDiceEx
#
# @todo:ÎÒҪ̫¼«
# @author xdh
# @date 2016-09-12 16:00
# @version 1.0
#
# ÏêϸÃèÊö: ÎÒҪ̫¼«
#---------------------------------------------------------------------
#"""Version = 2016-09-26 20:00"""
#---------------------------------------------------------------------
 
import GameWorld
import IPY_GameWorld
import PlayerControl
import ShareDefine
import ItemControler
import ChPyNetSendPack
import NetPackCommon
import ChConfig
import IpyGameDataPY
import PlayerActivity
import PlayerSuccess
import ItemCommon
import PlayerTongTianLing
 
 
## OnLogin
#  @param curPlayer
#  @return
def DiceExOnLogin(curPlayer):
    NotifyDiceResult(curPlayer)
    return
 
def OnDay(curPlayer):
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_Dice_FreeChangeCnt, 0)
    NotifyDiceResult(curPlayer, 2)
    return
 
#// AB 0C Ò¡÷»×Ó #tagCMDiceEx
#
#struct     tagCMDiceEx
#{
#    tagHead        Head;
#    BYTE        Type;    // 0-Ͷ÷»×Ó 1-¸ÄͶ 2-¼ûºÃ¾ÍÊÕ
#};
#  @param index
#  @param clientData
#  @param tick
#  @return None
def OnDice(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    diceType = clientData.Type
    hasOpen = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_DailyActionState % ShareDefine.DailyActionID_Dice)
    if not hasOpen and diceType != 2:
        GameWorld.DebugLog("    Ò¡÷»×ӻ먦Æô£¡")
        return
    
    diceResult = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_Dice_Result, 0)
    
    if diceType == 0:
        if diceResult:
            GameWorld.DebugLog("    Ò¡÷»×ÓÉϾֻ¹Î´½áË㣡")
            return
        #ÿÈջ
        if not PlayerActivity.AddDailyActionFinishCnt(curPlayer, ShareDefine.DailyActionID_Dice):
            return
        if not __DoDicelogic(curPlayer):
            return
        PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_FeastRedPack_Dice, 1)
        PlayerTongTianLing.AddTongTianTaskValue(curPlayer, ChConfig.TTLTaskType_Dice, 1)
        
    elif diceType == 1:
        if not diceResult:
            GameWorld.DebugLog("    Ò¡÷»×ÓûÓнá¹û²»ÄܸÄͶ£¡")
            return
        if diceResult == 666666:
            return
        #Ãâ·Ñ´ÎÊýÅжÏ
        hasChangeCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_Dice_FreeChangeCnt, 0)
        freeCnt = IpyGameDataPY.GetFuncCfg('DiceFreeNum')
        if hasChangeCnt >=freeCnt:
            return
        if not __DoDicelogic(curPlayer, diceResult, True):
            return
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_Dice_FreeChangeCnt, hasChangeCnt+1)
        
        
    elif diceType == 2:
        if not diceResult:
            GameWorld.DebugLog("    Ò¡÷»×ÓûÓнá¹û²»ÄܽáË㣡")
            return
        __DoGiveDiceAward(curPlayer, diceResult)
    NotifyDiceResult(curPlayer, diceType)
    return
 
def __DoDicelogic(curPlayer, result=0, isChange=False):
    diceRandomDict = IpyGameDataPY.GetFuncEvalCfg('DiceRandomList')
    
    diceRandomList = diceRandomDict.get(str(result).count('6'), [])
    hasAdd = False #ÊÇ·ñÓÐÔö¼Ó6µÄÊýÁ¿
    changeIndex = -1 #·Ç6µÄË÷Òý
    for i in range(6):
        if isChange and GameWorld.GetDataByDigitPlace(result, i) == 6:
            continue
        resultNum = GameWorld.GetResultByRandomList(diceRandomList)
        
        if not resultNum:
            GameWorld.ErrLog("    Ò¡÷»×ÓûÓÐËæ»úµ½½á¹û DiceRandomListÒì³££¡")
            return
        result = GameWorld.ChangeDataByDigitPlace(result, i, resultNum)
        if resultNum == 6:
            hasAdd = True
        elif changeIndex == -1:
            changeIndex = i
        
        #GameWorld.DebugLog("    Ò¡÷»×Ó½á¹û resultNum=%s, result=%s" % (resultNum, result))
    if isChange and not hasAdd and changeIndex >=0:
        result = GameWorld.ChangeDataByDigitPlace(result, changeIndex, 6)
    GameWorld.DebugLog("    Ò¡÷»×Ó½á¹û result=%s,isChange=%s" % (result, isChange))
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_Dice_Result, result)
    if result == 666666:
        PlayerControl.WorldNotify(0, 'WytjReward', [curPlayer.GetName()])
    return True
 
def __DoGiveDiceAward(curPlayer, result):
    ## ¸ø½±Àø
    prizeDict = IpyGameDataPY.GetFuncEvalCfg('DiceReward')
    goodCnt = str(result).count('6')
    if str(goodCnt) not in prizeDict:
        GameWorld.DebugLog("    Ò¡÷»×ÓDiceRewardδÅäÖÃ6µÄ¸öÊý goodCnt=%s" % goodCnt)
        return
    prizeInfo = prizeDict[str(goodCnt)]
    itemInfo = prizeInfo.get("item", [])
    if itemInfo:
        # ¼ì²é±³°ü
        packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem)
        if 1 > packSpace:
            PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_998371")
            return
        # ¸øÎïÆ·
        ItemControler.GivePlayerItem(curPlayer, itemInfo[0], itemInfo[1], 0, [IPY_GameWorld.rptItem], 
                                     event=[ChConfig.ItemGive_DiceEx, False, {}])
    reExp = PlayerControl.GetPlayerReExp(curPlayer)
    exp = eval(prizeInfo.get("exp", '0'))
    if exp:
        PlayerControl.PlayerControl(curPlayer).AddExp(exp)
    money = prizeInfo.get("gold", 0)
    if money:
        PlayerControl.GiveMoney(curPlayer, IPY_GameWorld.TYPE_Price_Silver_Money, money)
    
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_Dice_Result, 0)
    #½±Àø»Ø°ü
    NotifyDiceAwardResult(curPlayer, goodCnt)
    return
 
#// AB 22 Ò¡÷»×Ó½á¹û #tagMCDiceExResult
#
#struct    tagMCDiceExResult
#{
#    tagHead        Head;
#    DWORD        ResultNum;    // ÷»×Ó½á¹û
#    BYTE        DiceType;    // 0-Õý³£ 1-¸ÄͶ 2-ÖØÖÃ
#};
def NotifyDiceResult(curPlayer, diceType=0):
    diceResult = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_Dice_Result, 0)
    useFreeCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_Dice_FreeChangeCnt, 0)
    if not diceResult and diceType != 2 and not useFreeCnt:
        return
    packData = ChPyNetSendPack.tagMCDiceExResult()
    packData.ResultNum = diceResult
    packData.DiceType = diceType
    packData.UseFreeCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_Dice_FreeChangeCnt, 0)
    NetPackCommon.SendFakePack(curPlayer, packData)
    return
 
#// AB 23 Ò¡÷»×Ó½±Àø»Ø°ü #tagMCDiceAward
#
#struct    tagMCDiceAward
#{
#    tagHead        Head;
#    BYTE        AwardCnt;    // Ì«¼«ÊýÁ¿
#};
def NotifyDiceAwardResult(curPlayer, awardCnt):
    packData = ChPyNetSendPack.tagMCDiceAward()
    packData.AwardCnt = awardCnt
    NetPackCommon.SendFakePack(curPlayer, packData)
    return