;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[@Main]
  #IF
    StartDailyQuest
  #SAY
    <[ Accept Daily Quest ]/@ReceiveTodayQuestNPC>\\
  #ACT
    break
  #IF
    Check [409] 0
    !StartDailyQuest
  #ACT
    FormatStr "FLD_USERNAME='%s'" %USERNAME
    ReadValueSql "TBL_DairyQuestUser" %A9 "FLD_QuestIdx,FLD_Step,FLD_TQCASE,FLD_Condition1,FLD_Condition1Amount,FLD_Condition2" [@NPCACT_QuestDairyToday_Next]
  #SAY
    Daily Quest Loading..\\


#ELSESAY
Daily Quest Complete...\



[@ReceiveTodayQuestNPC]
  #IF
  #SAY
    Loading Daily Quest...\\
  #ACT
    goto @ReceiveTodayQuest_SettingNPC
    break

[@ReceiveTodayQuest_SettingNPC]
  #CALL [TodayQuest\QT_SettingBook.txt] @SetDairyQuest


[@NPCACT_QuestDairyToday_Next()]
  #ACT
    Mov D0 %ARG(1)
    Mov A0 %ARG(2)
    Mov D1 %ARG(3)
    Mov A1 %ARG(4)
    Mov D2 %ARG(5)
    Mov A2 %ARG(6)
    ReadValueSql "TBL_DairyQuestUser" %A9 "FLD_Condition2Amount,FLD_Condition3,FLD_Condition3Amount" [@NPCACT_QuestDairyToday_Next1]

[@NPCACT_QuestDairyToday_Next1()]
  #ACT
    Mov D3 %ARG(1)
    Mov A3 %ARG(2)
    Mov D4 %ARG(3)
  #IF
    Equal D1 0
  #ACT
    Goto @NPCACT_QuestDairyToday_Case0
    break
  #IF
    Equal D1 1
  #ACT
    goto @NPCACT_QuestDairyToday_Case1
    break
  #IF
    Equal D1 2
  #ACT
    goto @NPCACT_QuestDairyToday_Case2
    break
  #IF
    Equal D1 3
  #ACT
    goto @NPCACT_QuestDairyToday_Case3
    break

[@NPCACT_QuestDairyToday_Case3]
  #ACT
    Mov D5 %D2
    Inc D5 1
  #IF
    !Checkitem %A1 %D5
    Checkitem %A1 %D2
  #ELSEACT
    break
  #ELSESAY
    I Need <$OUTPUT(D2)> <$OUTPUT(A1)> Exactly!\\
    <[ Exit ]/@exit>
  #IF
    !Checkitem %A1 %D5
    Checkitem %A1 %D2
    Checkduraeva %A1 %D3
  #ACT
    take %A1 %D2
    goto @NPCACT_QuestDairyToday_Result
  #ELSEACT
    goto @NPCACT_QuestDairyToday_ExceptSay

[@NPCACT_QuestDairyToday_Case2]
  #IF
    Equal A0 "PreEnd"
  #ACT
    goto @NPCACT_QuestDairyToday_Case2_Step0
  #ELSEACT
    goto @NPCACT_QuestDairyToday_ExceptSay

[@NPCACT_QuestDairyToday_Case2_Step0]
  #IF
    checkitem %A2 %D3
  #ACT
    take %A2 %D3
    goto @NPCACT_QuestDairyToday_Result
  #ELSEACT
    goto @NPCACT_QuestDairyToday_ExceptSay
  
[@NPCACT_QuestDairyToday_Case1]
  #IF
    Equal A0 "PreEnd"
  #ACT
    goto @NPCACT_QuestDairyToday_Result
  #ELSEACT
    goto @NPCACT_QuestDairyToday_ExceptSay

[@NPCACT_QuestDairyToday_Case0]
  #IF
    Equal A1 "Money"
    CheckGold %D2
  #ACT
    take Gold %D2
    goto @NPCACT_QuestDairyToday_Case0_Step1
    break
  #IF
    !Equal A1 "Money"
    checkitem %A1 %D2
  #ACT
    take %A1 %D2
    goto @NPCACT_QuestDairyToday_Case0_Step1
    break
  #IF
  #ACT
    goto @NPCACT_QuestDairyToday_ExceptSay
    break

[@NPCACT_QuestDairyToday_Case0_Step1]
  #IF
    Equal A2 "NULL"
  #ACT
    goto @NPCACT_QuestDairyToday_Result
    break
  #IF
    Checkitem %A2 %D3
  #ACT
    take %A2 %D3
    goto @NPCACT_QuestDairyToday_Case0_Step2
    break
  #IF
    Equal A1 "Money"
    !Equal A2 "NULL"
  #ACT
    Give Gold %D2
    goto @NPCACT_QuestDairyToday_ExceptSay
    break
  #IF
    !Equal A1 "Money"
    !Equal A2 "NULL"
  #ACT
    Give %A1 %D2
    goto @NPCACT_QuestDairyToday_ExceptSay
    break

[@NPCACT_QuestDairyToday_Case0_Step2]
  #IF
    Equal A3 "NULL"
  #ACT
    goto @NPCACT_QuestDairyToday_Result
    break
  #IF
    checkitem %A3 %D4
  #ACT
    take %A3 %D4
    goto @NPCACT_QuestDairyToday_Result
    break
  #IF
    Equal A1 "Money"
    !Equal A3 "NULL"
  #ACT
    Give Gold %D2
    give %A2 %D3
    goto @NPCACT_QuestDairyToday_ExceptSay
    break
  #IF
    !Equal A1 "Money"
    !Equal A3 "NULL"
  #ACT
    give %A1 %D2
    give %A2 %D3
    goto @NPCACT_QuestDairyToday_ExceptSay
    break
  

[@NPCACT_QuestDairyToday_ExceptSay]
  #ACT
    FormatStr "FLD_TQIDX=%s" %D0
    ReadStringSql "TBL_DairyQuestSet" %A9 "FLD_TQNPCContent1" [@NPCACT_ExceptSayDB]

[@NPCACT_ExceptSayDB]
  #ACT
    Mov A5 %ARG(1)
  #SAY
    <$OUTPUT(A5)>\\
    <[ Continue with Quest ]/@exit>\


[@NPCACT_QuestDairyToday_Result]
#IF
#ACT
   FormatStr "FLD_TQIDX=%s" %D0
   ReadValueSql "TBL_DairyQuestSet" %A9 "FLD_TQReword1,FLD_TQReword1Amount,FLD_TQFame" [@NPCReword_QuestDairyToday_Result_Next]
   break

[@NPCReword_QuestDairyToday_Result_Next()]
#IF
   Checkfame
#SAY
   Please wait...\\
#ACT
   mov A4 %ARG(1)
   mov D4 %ARG(2)
   mov D5 %ARG(3)
   mov D6 %P9
   inc D6 %D5
   FormatStr "FLD_TQIDX=%s" %D0
#IF
   Equal A4 "Exp"
#SAY
   Here is your Exp\\
   <[ Exit ]/@exit>\
#ACT
   GiveExp %USERNAME %D4
   Set [210] 0
   Set [409] 1
   goto @NPCReword_QuestDairyToday_GiveFame
   break
#IF
   Equal A4 "Money"
#SAY
   Here is your Cash\\
   <[ Exit ]/@exit>\
#ACT
   Give Gold %D4
   Set [210] 0
   Set [409] 1
   goto @NPCReword_QuestDairyToday_GiveFame
   break
#IF
#SAY
   Here is your <$OUTPUT(A4)>\\
   <[ Exit ]/@exit>\
#ACT
   Give %A4 %D4
   Set [210] 0
   Set [409] 1
   goto @NPCReword_QuestDairyToday_GiveFame
   break


[@NPCReword_QuestDairyToday_GiveFame]
  #IF
    !Equal D5 0
  #ACT
    SetFame %D6
    Mov  A7  "(!)<$OUTPUT(D5)> Fame Points Receieved!"
    SysMsg %A7
    Mov  A7  "<$USERNAME> you currently have '<$OUTPUT(D6)>' fame points"
    SysMsg %A7
    FormatStr "FLD_USERNAME='%s'" %USERNAME
    UpdateValueSql "TBL_DairyQuestUser" %A9 "FLD_Status='End',FLD_Step='NULL'"
  #ELSEACT
    FormatStr "FLD_USERNAME='%s'" %USERNAME
    UpdateValueSql "TBL_DairyQuestUser" %A9 "FLD_Status='End',FLD_Step='NULL'"

[@SayHello]
#ACT
Speak "Hello Venom :P"
Break

[@SayGoodBye]
#ACT
Speak "Cya Venom :)"
Break

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;