|
| 1 | +Scriptname PetFramework_PetQuest extends Quest Conditional |
| 2 | +{Manages the pet's home location, commands, etc. Some functions are called from the pet actor script.} |
| 3 | + |
| 4 | +PetFramework_ParentQuestScript Property PetFramework_ParentQuest Auto |
| 5 | +Message Property PetFramework_PetDismissMessage Auto |
| 6 | +Message Property PetFramework_PetMaxReachedMessage Auto |
| 7 | +Faction Property PetFramework_PetFollowingFaction Auto |
| 8 | +Faction Property PlayerFaction Auto |
| 9 | +Faction Property PetFramework_PetFaction Auto |
| 10 | +ReferenceAlias Property PetHomeMarker Auto |
| 11 | +ReferenceAlias Property PetRefAlias Auto |
| 12 | +ReferenceAlias Property PetDynamicHomeMarker Auto |
| 13 | +Bool Property MovingTogglePackageOn = False Auto Conditional Hidden ;Hearthfire adoption/move trick - turn on a temporary package |
| 14 | + |
| 15 | +Function MakePetAvailableToPlayer() |
| 16 | +{Called when the quest meets the criteria for the pet to be available, i.e. purchase, rescue, whatever scenario. Without this the pet cannot be talked to or recruited.} |
| 17 | + PetRefAlias.GetActorReference().SetFactionRank(PetFramework_PetFaction, 1) |
| 18 | + ;PetRefAlias.GetActorReference().AddToFaction(PlayerFaction) |
| 19 | +EndFunction |
| 20 | + |
| 21 | +Function MakePetUnavailableToPlayer() |
| 22 | +{If for some reason we want to make the pet unavailable to player, i.e. sell it someone else, etc. this function will do that} |
| 23 | + PetRefAlias.GetActorReference().SetFactionRank(PetFramework_PetFaction, 0) |
| 24 | + ;PetRefAlias.GetActorReference().RemoveFromFaction(PlayerFaction) |
| 25 | +EndFunction |
| 26 | + |
| 27 | +Function FollowPlayer(Bool snapIntoInteraction = False) |
| 28 | +{Called when the player recruits the pet via dialogue.} |
| 29 | + |
| 30 | + If(PetFramework_ParentQuest.HasMaxPets()) |
| 31 | + PetFramework_PetMaxReachedMessage.Show() |
| 32 | + Else |
| 33 | + |
| 34 | + debug.trace("Pet Framework: " + PetRefAlias.GetActorReference() + " setting to following player") |
| 35 | + debug.trace("Pet Framework: " + PetRefAlias.GetActorReference() + " PetFollowingFactionRank: " + PetRefAlias.GetActorReference().GetFactionRank(PetFramework_PetFollowingFaction)) |
| 36 | + |
| 37 | + ;If the pet was waiting for the player, clear the actor value (no need to check just run it) |
| 38 | + WaitForPlayer(False) |
| 39 | + |
| 40 | + ;Set the rank to 1, which will enable dialogue commands, etc. (used by shared pet framework) |
| 41 | + PetRefAlias.GetActorReference().SetFactionRank(PetFramework_PetFollowingFaction, 1) |
| 42 | + |
| 43 | + debug.trace("Pet Framework: " + PetRefAlias.GetActorReference() + " PetFollowingFactionRank: " + PetRefAlias.GetActorReference().GetFactionRank(PetFramework_PetFollowingFaction)) |
| 44 | + |
| 45 | + ;Some animals have very long idles they get 'stuck' which feels like recruiting them didn't do anything |
| 46 | + If(snapIntoInteraction) |
| 47 | + PetRefAlias.GetReference().Disable() |
| 48 | + PetRefAlias.GetReference().Enable() |
| 49 | + EndIf |
| 50 | + |
| 51 | + PetFramework_ParentQuest.IncrementPetCount() |
| 52 | + debug.trace("Pet Count: " + PetFramework_ParentQuest.GetCurrentPetCount()) |
| 53 | + |
| 54 | + ;Re-evaluate the package stack based on our new conditions |
| 55 | + PetRefAlias.GetActorReference().EvaluatePackage() |
| 56 | + |
| 57 | + EndIf |
| 58 | + |
| 59 | +EndFunction |
| 60 | + |
| 61 | +Function WaitForPlayer(Bool doWait = True) |
| 62 | +{True/False: Pet will wait for the player or continue to follow.} |
| 63 | + |
| 64 | + DEBUG.TRACE("WaitForPlayer called with value: " + doWait) |
| 65 | + |
| 66 | + If(doWait == True) |
| 67 | + debug.trace("PetFramework Setting pet to wait for player") |
| 68 | + PetRefAlias.GetActorReference().SetAV("WaitingForPlayer", 1) |
| 69 | + Else |
| 70 | + debug.trace("PetFramework Setting pet to stop waiting for player") |
| 71 | + PetRefAlias.GetActorReference().SetAV("WaitingForPlayer", 0) |
| 72 | + EndIf |
| 73 | + |
| 74 | + ;Re-evaluate the package stack based on our new conditions |
| 75 | + PetRefAlias.GetActorReference().EvaluatePackage() |
| 76 | + |
| 77 | +EndFunction |
| 78 | + |
| 79 | +Function SetHomeToCurrentLocation() |
| 80 | +{Makes the "Home" of the pet right where they stand, so they will dismiss and sandbox the area (house mods, camping, etc.)} |
| 81 | + |
| 82 | + ;Move the xmarker to where the pet is standing |
| 83 | + PetDynamicHomeMarker.GetReference().MoveTo(PetRefAlias.GetReference()) |
| 84 | + PetDynamicHomeMarker.GetReference().SetAngle(0,0,0) |
| 85 | + |
| 86 | + ;Set the home idle marker to the dynamic marker |
| 87 | + SetNewHome(PetDynamicHomeMarker, True) |
| 88 | + |
| 89 | +EndFunction |
| 90 | + |
| 91 | +Function SetNewHome(ReferenceAlias newLocation, Bool dismiss = True, Bool doWarp = False) |
| 92 | + |
| 93 | + debug.trace("Set New Home called from actor proxy") |
| 94 | + |
| 95 | + ;Clear the waiting flag |
| 96 | + WaitForPlayer(False) |
| 97 | + |
| 98 | + ;Turn on the temporary package while we change the ref alias data for their idle package - trick from Hearthfire adoption |
| 99 | + MovingTogglePackageOn = True ;"Hold"AI package looks at this quest var |
| 100 | + PetRefAlias.GetActorReference().EvaluatePackage() |
| 101 | + |
| 102 | + ;Set the ref alias to be the pet's new home |
| 103 | + PetHomeMarker.ForceRefTo(newLocation.GetReference()) |
| 104 | + |
| 105 | + ;Remove them from current following faction so they actually go to their new home |
| 106 | + If(dismiss) |
| 107 | + PetRefAlias.GetActorReference().SetFactionRank(PetFramework_PetFollowingFaction, 0) |
| 108 | + EndIf |
| 109 | + |
| 110 | + Utility.Wait(0.1) |
| 111 | + |
| 112 | + MovingTogglePackageOn = False |
| 113 | + PetRefAlias.GetActorReference().EvaluatePackage() |
| 114 | + |
| 115 | + If(doWarp) |
| 116 | + Utility.Wait(0.01) |
| 117 | + PetRefAlias.GetReference().MoveTo(newLocation.GetReference(), 0,0,0,False) |
| 118 | + EndIf |
| 119 | + |
| 120 | + PetFramework_PetDismissMessage.Show() |
| 121 | + PetFramework_ParentQuest.DecrementPetCount() |
| 122 | + |
| 123 | + debug.trace("Pet Count: " + PetFramework_ParentQuest.GetCurrentPetCount()) |
| 124 | + |
| 125 | +EndFunction |
| 126 | + |
| 127 | + |
| 128 | + |
0 commit comments