ScriptName aaaKimachuuFoodReviewRA Extends ReferenceAlias

Actor Property PlayerRef Auto
FormList Property aaaKimachuuFoodReviewBlackList Auto
Message Property aaaKimachuuFoodReviewMes Auto
MiscObject Property aaaKimachuuFoodReviewMisc Auto

aaaKimachuuFoodReviewItem Property scrItem Auto

String umaiFile = "../KimachuuFoodReview/StrList01.json"
String hutsuuFile = "../KimachuuFoodReview/StrList02.json"
String mazuiFile = "../KimachuuFoodReview/StrList03.json"
String judgementFile = "../KimachuuFoodReview/StrList04.json"

Bool bFlag = False

Import JsonUtil
Import UIExtensions

Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference)
	If bFlag == True
		Return
	EndIf

	bFlag = True
	If akBaseObject as Potion
		String strResult
		String strJudgement
		Potion PotionRef = akBaseObject as Potion
		Int iIndex = aaaKimachuuFoodReviewBlackList.Find(PotionRef)
		If PotionRef.IsFood() && iIndex == -1
			Utility.Wait(2.0)
			Int iChoice = aaaKimachuuFoodReviewMes.Show()
			If iChoice <= 2 ;キャンセル以外
				strResult = reviewFunction(iChoice)
				strJudgement = judgementFunction(iChoice)
				If strResult
					ObjectReference objReviewRef = PlayerRef.PlaceAtMe(aaaKimachuuFoodReviewMisc, 1, True, False)
					objReviewRef.SetDisplayName("[" + strJudgement + "]" + PotionRef.GetName())
					objReviewRef.SetActorOwner(PlayerRef.GetActorBase())
					objReviewRef.Activate(PlayerRef)
					aaaKimachuuFoodReviewBlackList.AddForm(PotionRef)

					aaaKimachuuFoodReviewItem scrRun1 = objReviewRef as aaaKimachuuFoodReviewItem
					scrRun1.strFoodName = objReviewRef.GetDisplayName()
					scrRun1.strReview = strResult
					Debug.Notification("Done.")
				Else
					;empty
				EndIf
			EndIf
		EndIf
	EndIf
	bFlag = False
EndEvent

String Function reviewFunction(Int i01)
	String strFileName
	Int iLength
	If i01 == 0 ;うまい
		strFileName = umaiFile
		iLength = GetIntValue(strFileName, "length")
	ElseIf i01 == 1 ;ふつう
		strFileName = hutsuuFile
		iLength = GetIntValue(strFileName, "length")
	ElseIf i01 == 2 ;まずい
		strFileName = mazuiFile
		iLength = GetIntValue(strFileName, "length")
	EndIf

	Int i = 0
	String[] iDialogueForm = new String[10]
	UIListMenu listMenu = GetMenu("UIListMenu") as UIListMenu

    While i < iLength
    	iDialogueForm[i] = GetStringValue(strFileName, "rank" + i)
    	listMenu.AddEntryItem(iDialogueForm[i])
    	i += 1
    EndWhile

    listMenu.OpenMenu()
    Int iResult = listMenu.GetResultInt()

   	If iResult == -1
		Debug.Notification("Cancelled...")
		Return None
	EndIf

	String strReview = GetStringValue(strFileName, "rank" + iResult)
	Return strReview
EndFunction

String Function judgementFunction(Int i01)
	String strFileName = judgementFile
	String strJ
	strJ = GetStringValue(strFileName, "rank" + i01)
	Return strJ
EndFunction