ScriptName aaaKimachuuSO3Combat Extends ActiveMagicEffect

Explosion property brExplosion auto
Explosion property coExplosion auto
Explosion property prExplosion auto
Sound Property breakSound Auto
Sound Property protectSound Auto
Sound Property counterSound Auto
Spell Property attackSpell Auto
Spell Property staggerSpell Auto
MagicEffect Property attackME Auto

Actor actCaster

Bool bPA = False

Event OnEffectStart(Actor akTarget, Actor akCaster)
    actCaster = Self.GetCasterActor() ;攻撃を受ける側
    RegisterForAnimationEvent(actCaster, "preHitFrame")
    RegisterForAnimationEvent(actCaster, "HitFrame")
EndEvent

Event OnAnimationEvent(ObjectReference akSource, string asEventName)
	If asEventName == "HitFrame"
		bPA = False
	Else
		If bPA == False
			attackSpell.Cast(actCaster)
			bPA = True
		EndIf
	EndIf
EndEvent

Event OnImpact(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)
	Actor actAggressor = akAggressor As Actor

	Float fGutsP = actCaster.GetActorValuePercentage("Stamina")

	If actCaster.hasMagicEffect(attackME) ;大攻撃を阻止するとよろめく
		Game.ShakeCamera(None, 1.5, 0.8)
		;Debug.Notification("Interrupt")
		GotoState("Busy")

		counterSound.play(actCaster)
		actCaster.PlaceAtMe(coExplosion, 1, False, False)
		Debug.SendAnimationEvent(actCaster, "BleedOutStart")
		actCaster.DamageActorValue("Stamina", 150.0)

		Utility.Wait(3.0)
		Debug.SendAnimationEvent(actCaster, "BleedOutStop") ;ブレイクから回復
		Utility.Wait(1.0)
		GotoState("")
	ElseIf fGutsP >= 1.0 && akSource == abPowerAttack ;ガッツ最大時に大攻撃を受けるとブレイク
		Game.ShakeCamera(None, 1.5, 0.8)
		;Debug.Notification("Break")
		GotoState("Busy")

		breakSound.play(actCaster)
		actCaster.PlaceAtMe(brExplosion, 1, False, False)
		Debug.SendAnimationEvent(actCaster, "BleedOutStart")
		actCaster.DamageActorValue("Stamina", 150.0)

		Utility.Wait(3.0)
		Debug.SendAnimationEvent(actCaster, "BleedOutStop") ;ブレイクから回復
		Utility.Wait(1.0)
		GotoState("")
	ElseIf fGutsP >= 1.0 && akSource != abPowerAttack ;ガッツ最大時に小攻撃を受けるとプロテクト
		;Debug.Notification("Protect")
		GotoState("Busy")

		protectSound.play(actCaster)
		actCaster.PlaceAtMe(prExplosion, 1, False, False)
		staggerSpell.Cast(actAggressor)
		actAggressor.DamageActorValue("Stamina", 150.0)
		Debug.SendAnimationEvent(actCaster,"attackStop")
		Float fHealth = actCaster.GetActorValue("Health") / 10
		actCaster.RestoreActorValue("Health", fHealth)
		
		Utility.Wait(3.0)
		GotoState("")
	Else
		;empty
	EndIf
EndEvent

Event OnEffectFinish(Actor akTarget, Actor akCaster)
	actCaster = None
endEvent

State Busy
	Event OnImpact(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)
	EndEvent
EndState