<commit_before>scriptname _Seed_FatigueSystem extends Quest

import Utility

GlobalVariable property _Seed_VitalitySystemEnabled auto
GlobalVariable property _Seed_AttributeFatigue auto
GlobalVariable property _Seed_FatigueRate auto 							; Default - 1.66
GlobalVariable property _Seed_FatigueActionRateMasterSpells auto 		; Default - 10.0
GlobalVariable property _Seed_FatigueActionRateExpertSpells auto 		; Default - 2.0
GlobalVariable property _Seed_FatigueActionRateAdeptSpells auto 		; Default - 1.0
GlobalVariable property _Seed_FatigueActionRateApprenticeSpells auto 	; Default - 0.5
GlobalVariable property _Seed_Setting_VampireBehavior auto
Actor property PlayerRef auto
Keyword property ActorTypeUndead auto
Keyword property ImmuneParalysis auto

float property MAX_FATIGUE = 120.0 autoReadOnly
float property MIN_FATIGUE = 0.0 autoReadOnly
float property SLEEP_RESTORE_RATE = 3.0 autoReadOnly

float property update_interval = 1.0 auto hidden
float property last_update_time auto hidden
bool property was_sleeping = false auto hidden
float last_sleep_duration

Event OnInit()
	Initialize()
EndEvent

function Initialize()
    RegisterForSingleUpdateGameTime(update_interval)
    last_update_time = GetCurrentGameTime() * 24.0
    RegisterForSleep()
endFunction

Event OnUpdateGameTime()
	if was_sleeping
		was_sleeping = false
		return
	endif

	if _Seed_Setting_VampireBehavior.GetValueInt() == 2 && IsUndead()
		return
	endif

	float rate = _Seed_FatigueRate.GetValue()
	float this_time = GetCurrentGameTime() * 24.0
	int cycles = Math.Floor((this_time - last_update_time))
	float fatigue_increase = rate * cycles
	
    IncreaseFatigue(fatigue_increase)
    last_update_time = this_time
    if _Seed_VitalitySystemEnabled.GetValueInt() == 2
        RegisterForSingleUpdateGameTime(update_interval)
    endif
EndEvent

Event OnSleepStart(float afSleepStartTime, float afDesiredSleepEndTime)
	was_sleeping = true
	last_sleep_duration = (afDesiredSleepEndTime - afSleepStartTime) * 24.0
EndEvent

Event OnSleepStop(bool abInterrupted)
	;@TODO: Modify by current hunger and thirst.
	float fatigue_decrease = last_sleep_duration * SLEEP_RESTORE_RATE
	DecreaseFatigue(fatigue_decrease)
EndEvent

function SpellCast(Spell akSpell)
	;@TODO: Player ReferenceAlias needs to call this from OnSpellCast().
	;@TODO: Increase Fatigue during concentration spell cast.
	if akSpell
		int mag_level = (akSpell.GetNthEffectMagicEffect(akSpell.GetCostliestEffectIndex())).GetSkillLevel()
		if mag_level >= 100
			IncreaseFatigue(_Seed_FatigueActionRateMasterSpells.GetValue())
		elseif mag_level >= 75
			IncreaseFatigue(_Seed_FatigueActionRateExpertSpells.GetValue())
		elseif mag_level >= 50
			IncreaseFatigue(_Seed_FatigueActionRateAdeptSpells.GetValue())
		elseif mag_level >= 25
			IncreaseFatigue(_Seed_FatigueActionRateApprenticeSpells.GetValue())
		else
			return
		endif
	endif<commit_msg>Added new events to fatigue system.<commit_after>scriptname _Seed_FatigueSystem extends Quest

import Utility

GlobalVariable property _Seed_VitalitySystemEnabled auto
GlobalVariable property _Seed_AttributeFatigue auto
GlobalVariable property _Seed_FatigueRate auto 							; Default - 1.66
GlobalVariable property _Seed_FatigueActionRateMasterSpells auto 		; Default - 10.0
GlobalVariable property _Seed_FatigueActionRateExpertSpells auto 		; Default - 2.0
GlobalVariable property _Seed_FatigueActionRateAdeptSpells auto 		; Default - 1.0
GlobalVariable property _Seed_FatigueActionRateApprenticeSpells auto 	; Default - 0.5
GlobalVariable property _Seed_Setting_VampireBehavior auto
Actor property PlayerRef auto
Keyword property ActorTypeUndead auto
Keyword property ImmuneParalysis auto

float property MAX_FATIGUE = 120.0 autoReadOnly
float property MIN_FATIGUE = 0.0 autoReadOnly
float property SLEEP_RESTORE_RATE = 3.0 autoReadOnly

float property update_interval = 1.0 auto hidden
float property last_update_time auto hidden
bool property was_sleeping = false auto hidden
float last_sleep_duration

int locks_picked

Event OnInit()
	Initialize()
EndEvent

function Initialize()
    RegisterForSingleUpdateGameTime(update_interval)
    last_update_time = GetCurrentGameTime() * 24.0
    RegisterForSleep()

    ; Register for lockpicking and archery attacks.
    locks_picked = Game.QueryStat("Locks Picked")
    RegisterForTrackedStatsEvent()
    RegisterForAnimationEvent(PlayerRef, "BowRelease")
endFunction

Event OnAnimationEvent(ObjectReference akSource, string asEventName)
	if asEventName == "BowRelease"
		debug.trace("[Seed] Player Archery Attack")
		IncreaseFatigue(0.2)
	endif
EndEvent

Event OnTrackedStatsEvent(string arStatName, int aiStatValue)
	if arStatName == "Locks Picked"
		if aiStatValue > locks_picked
			debug.trace("[Seed] Player Picked Lock")
			locks_picked = aiStatValue
			IncreaseFatigue(1.0)
		endif
	endif
EndEvent

Event OnUpdateGameTime()
	if was_sleeping
		was_sleeping = false
		return
	endif

	if _Seed_Setting_VampireBehavior.GetValueInt() == 2 && IsUndead()
		return
	endif

	float rate = _Seed_FatigueRate.GetValue()
	float this_time = GetCurrentGameTime() * 24.0
	int cycles = Math.Floor((this_time - last_update_time))
	float fatigue_increase = rate * cycles
	
    IncreaseFatigue(fatigue_increase)
    last_update_time = this_time
    if _Seed_VitalitySystemEnabled.GetValueInt() == 2
        RegisterForSingleUpdateGameTime(update_interval)
    endif
EndEvent

Event OnSleepStart(float afSleepStartTime, float afDesiredSleepEndTime)
	was_sleeping = true
	last_sleep_duration = (afDesiredSleepEndTime - afSleepStartTime) * 24.0
EndEvent

Event OnSleepStop(bool abInterrupted)
	;@TODO: Modify by current hunger and thirst.
	float fatigue_decrease = last_sleep_duration * SLEEP_RESTORE_RATE
	DecreaseFatigue(fatigue_decrease)
EndEvent

function SpellCast(Spell akSpell)
	;@TODO: Increase Fatigue during concentration spell cast.
	if akSpell
		int mag_level = (akSpell.GetNthEffectMagicEffect(akSpell.GetCostliestEffectIndex())).GetSkillLevel()
		if mag_level >= 100
			IncreaseFatigue(_Seed_FatigueActionRateMasterSpells.GetValue())
		elseif mag_level >= 75
			IncreaseFatigue(_Seed_FatigueActionRateExpertSpells.GetValue())
		elseif mag_level >= 50
			IncreaseFatigue(_Seed_FatigueActionRateAdeptSpells.GetValue())
		elseif mag_level >= 25
			IncreaseFatigue(_Seed_FatigueActionRateApprenticeSpells.GetValue())
		else
			return
		endif
	endif
{'fraction_non_alphanumeric': 0.05545112781954887, 'fraction_numerical': 0.013784461152882205, 'mean_word_length': 6.016483516483516, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1066844', 'n_tokens_mistral': 2149, 'n_tokens_neox': 1980, 'n_words': 478}