;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[@LottoSystem_Result]
{
#ACT
ReadValueSql "TBL_LottoServer" "FLD_Name='Current'" "FLD_Sequence" @LottoSystem_WinnerNum

[@LottoSystem_WinnerNum()]
#ACT
Mov N90 %ARG(1)
Inc N90 1
FormatStr "FLD_Sequence=%s" %N90
UpdateValueSql "TBL_LottoServer" "FLD_NAME='Current'" %A9
Dec N90 1
FormatStr "FLD_Name ='Lotto' and FLD_Sequence=%s" %N90
ReadValueSql "TBL_LottoServer" %A9 "FLD_Num1,FLD_Num2,FLD_Num3,FLD_HumanCount,FLD_TotalPrice" @LottoSystem_ResultBroadCast

[@LottoSystem_ResultBroadCast()]
#ACT
Mov N91 %ARG(1)
Mov N92 %ARG(2)
Mov N93 %ARG(3)
Mov N94 %ARG(4)
Mov N95 %ARG(5)
LineMsg [Grobal] "Sting Lotto (Week <$OUTPUT(N90)>) Here are the Results!"
Delaygoto [Grobal] 30 @LottoSystem_ResultNum1 1001

[@LottoSystem_ResultNum1]
#ACT
LineMsg [Grobal] "Sting Lotto (Week <$OUTPUT(N90)>) : 1st Number is <$OUTPUT(N91)>"
Delaygoto [Grobal] 10 @LottoSystem_ResultNum2 1001

[@LottoSystem_ResultNum2]
#ACT
LineMsg [Grobal] "Sting Lotto (Week <$OUTPUT(N90)>) : 2nd Number is <$OUTPUT(N92)>"
Delaygoto [Grobal] 10 @LottoSystem_ResultNum3 1001

[@LottoSystem_ResultNum3]
#ACT
LineMsg [Grobal] "Sting Lotto (Week <$OUTPUT(N90)>) : 3rd Number is <$OUTPUT(N93)>"
Delaygoto [Grobal] 10 @LottoSystem_ResultFinal 1001

[@LottoSystem_ResultFinal]
#ACT
LineMsg [Grobal] "Sting Lotto (Week <$OUTPUT(N90)>) : Winning Numbers are <$OUTPUT(N91)>, <$OUTPUT(N92)>, <$OUTPUT(N93)>"
goto @LottoSystem_WinnerReword

[@LottoSystem_WinnerReword]
#IF
Equal N94 0
#ACT
LineMsg [Grobal] "Sting Lotto (Week <$OUTPUT(N90)>) : There are no winners, the total prize of <$OUTPUT(N95)> will roll over to next week!"
Inc N90 1
FormatStr "FLD_Name='Lotto' and FLD_Sequence=%s" %N90
Mov A8 %A9
FormatStr "FLD_TotalPrice=%s" %N95
UpdateValueSql "TBL_LottoServer" %A8 %A9
#ELSEACT
Div N95 N94
mov D0 %P9
LineMsg [Grobal] "Sting Lotto (Week <$OUTPUT(N90)>) : There is <$OUTPUT(N94)> winner(s)! Each will receive <$OUTPUT(D0)> Gold"
LineMsg [Grobal] "Congratulations to all Winners!!"
FormatStr "FLD_UserPrice=%s" %D0
mov A8 %A9
FormatStr "FLD_Name='Lotto' and FLD_Sequence=%s" %N90
UpdateValueSql "TBL_LottoServer" %A9 %A8
;Inc N90 1
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;