ScriptName aaaKimachuuBountyHunterOR Extends ObjectReference

Actor Property PlayerRef Auto ;プレイヤー
Actor Property contRef Auto ;コンテナNPC
Formlist Property fl01 Auto ;アクターベースを入れるリスト
GlobalVariable Property glo01 Auto ;フェイルセーフ用
GlobalVariable Property glo02 Auto ;距離計算用
LocationAlias Property locLA Auto ;ロケーション名表示用
Message Property mes00 Auto ;処理中メッセージ
Message Property mes01 Auto ;中断選択メッセージ
Message Property mes02 Auto ;受注確認メッセージ
Message Property mes03 Auto ;エラーメッセージ
Quest Property que01 Auto ;検索および実行クエスト
ReferenceAlias Property markerRA Auto ;マーカーのエイリアス
ReferenceAlias Property bossRA Auto ;ボスのエイリアス
Spell Property spell01 Auto ;設置用魔法

aaaKimachuuBountyHunterMCM Property config Auto

Event OnActivate(ObjectReference akActionRef)

	If !PlayerRef.HasSpell(spell01)
		PlayerRef.AddSpell(spell01)
	EndIf

	;検索中に多重起動を防ぐ

	If glo01.GetValueInt() == 1
		mes00.Show()
		Return
	EndIf

	;クエスト実行中の場合、中断処理に移す

	If que01.GetCurrentStageID() == 10
		Int iIndex = mes01.Show()
		If iIndex == 1
			Actor actBoss = bossRA.GetActorRef()
			que01.SetObjectiveDisplayed(1,0)
			actBoss.Disable()
			actBoss.Delete()
			que01.Reset()
			que01.SetStage(0)
			Utility.Wait(0.1)

			If !actBoss.IsDisabled()
				Debug.Notification("ERROR! : Disable failed.")
			EndIf

			If !actBoss.IsDeleted()
				Debug.Notification("ERROR! : Delete failed.")
			EndIf

			que01.Stop()
			actBoss = None
		EndIf
		Return
	EndIf

	;受注確認

	Int iIndex = mes02.Show()
	If iIndex == 0 ;1なら続行
		Return
	ElseIf iIndex == 2 ;戦利品回収
		contRef.OpenInventory(True)
		Return
	EndIf

	;ここから検索処理

	glo01.SetValueInt(1)
	que01.Stop()
	que01.Start()
	If markerRA != None
		ObjectReference objMarker = markerRA.GetReference()
		Actor actBoss = objMarker.PlaceActorAtMe(bossSelection(), 3)
		ActorBase abBoss = actBoss.GetActorBase()
		If actBoss != None && !abBoss.IsUnique()
			bossRA.ForceRefTo(actBoss)
			Location locLocation = actBoss.GetCurrentLocation()
			locLA.ForceLocationTo(locLocation)
			;-----ここで賞金を計算
			Float fDist = PlayerRef.GetDistance(actBoss) / config.iDistanceDivision
			If config.bFurtherDivision == True
				fDist = fDist / config.iDistanceDivision
			EndIf
			If PlayerRef.IsInInterior()
				fDist = 0.0
			ElseIf fDist < 0.0
				fDist = 0.0
			EndIf
			Int iGold = actBoss.GetLevel() * config.iLevelMult
			glo02.SetValueInt(iGold + fDist As Int)
			;Debug.MessageBox("Distance Bonus:" + fDist As Int)
			;-----------------
			aaaKimachuuBountyHunterRun scrRun = que01 as aaaKimachuuBountyHunterRun
			scrRun.gloUpdate()
			actBoss.SetActorValue("health", actBoss.GetBaseActorValue("health") * config.iEnemyHealthMult)
			actBoss.RestoreActorValue("Health", 9999)

			que01.SetStage(10)
			que01.SetObjectiveDisplayed(1,1)
			locLocation = None
		Else
			mes03.Show()
		EndIf
		objMarker = None
		actBoss = None
	Else
		mes03.Show()
	EndIf
	glo01.SetValueInt(0)
EndEvent

ActorBase Function bossSelection()
	Int iMax = fl01.GetSize()
	Int iRnd = Utility.RandomInt(0, iMax - 1)
	ActorBase tempAB = fl01.GetAt(iRnd) As ActorBase
	Return tempAB
EndFunction