#!/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
|