Skip to content

Commit

Permalink
Clear active crime state like classic
Browse files Browse the repository at this point in the history
Active crime state is cleared when player exits location area or fast travels elsewhere.
City watch will despawn when active crime state returns to none. Specifically, gameobject is set to inactive and will be removed when player leaves area.
Added console commands to print and clear active crime state.
  • Loading branch information
Interkarma committed Oct 15, 2020
1 parent ce44855 commit cd33570
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Assets/Game/Addons/UnityConsole/Console/Scripts/DefaultCommands.cs
Expand Up @@ -110,6 +110,8 @@ void Start()

ConsoleCommandsDatabase.RegisterCommand(PlayFLC.name, PlayFLC.description, PlayFLC.usage, PlayFLC.Execute);
ConsoleCommandsDatabase.RegisterCommand(PlayVID.name, PlayVID.description, PlayVID.usage, PlayVID.Execute);
ConsoleCommandsDatabase.RegisterCommand(PrintCrimeCommitted.name, PrintCrimeCommitted.description, PrintCrimeCommitted.usage, PrintCrimeCommitted.Execute);
ConsoleCommandsDatabase.RegisterCommand(ClearCrimeCommitted.name, ClearCrimeCommitted.description, ClearCrimeCommitted.usage, ClearCrimeCommitted.Execute);
ConsoleCommandsDatabase.RegisterCommand(PrintLegalRep.name, PrintLegalRep.description, PrintLegalRep.usage, PrintLegalRep.Execute);
ConsoleCommandsDatabase.RegisterCommand(ClearNegativeLegalRep.name, ClearNegativeLegalRep.description, ClearNegativeLegalRep.usage, ClearNegativeLegalRep.Execute);

Expand Down Expand Up @@ -2491,6 +2493,31 @@ public static string Execute(params string[] args)
}
}

private static class PrintCrimeCommitted
{
public static readonly string name = "print_crimecommitted";
public static readonly string description = "Output active crime state";
public static readonly string usage = "print_crimecommitted";

public static string Execute(params string[] args)
{
return GameManager.Instance.PlayerEntity.CrimeCommitted.ToString();
}
}

private static class ClearCrimeCommitted
{
public static readonly string name = "clear_crimecommitted";
public static readonly string description = "Clear active crime state";
public static readonly string usage = "clear_crimecommitted";

public static string Execute(params string[] args)
{
GameManager.Instance.PlayerEntity.CrimeCommitted = PlayerEntity.Crimes.None;
return "Cleared active crime state";
}
}

private static class PrintLegalRep
{
public static readonly string name = "print_legalrep";
Expand Down
14 changes: 14 additions & 0 deletions Assets/Scripts/Game/Entities/EnemyEntity.cs
Expand Up @@ -153,6 +153,20 @@ public override int SetHealth(int amount, bool restoreMode = false)
return currentHealth;
}

public override void Update(DaggerfallEntityBehaviour sender)
{
base.Update(sender);

// Despawn city watch when active crime state returns to none
// This can happen when exiting city area, after fast travel, or via console
if (entityType == EntityTypes.EnemyClass &&
careerIndex == (int)MobileTypes.Knight_CityWatch - 128 &&
GameManager.Instance.PlayerEntity.CrimeCommitted == PlayerEntity.Crimes.None)
{
sender.gameObject.SetActive(false);
}
}

/// <summary>
/// Attempt to trap a soul.
/// </summary>
Expand Down
14 changes: 14 additions & 0 deletions Assets/Scripts/Game/Entities/PlayerEntity.cs
Expand Up @@ -203,6 +203,8 @@ public PlayerEntity(DaggerfallEntityBehaviour entityBehaviour)
{
StartGameBehaviour.OnNewGame += StartGameBehaviour_OnNewGame;
OnExhausted += PlayerEntity_OnExhausted;
PlayerGPS.OnExitLocationRect += PlayerGPS_OnExitLocationRect;
DaggerfallTravelPopUp.OnPostFastTravel += DaggerfallTravelPopUp_OnPostFastTravel;
}

#endregion
Expand Down Expand Up @@ -2411,6 +2413,18 @@ private void ExhaustedMessageBox_OnClose()
displayingExhaustedPopup = false;
}

private void PlayerGPS_OnExitLocationRect()
{
// Clear crime state when exiting location rect
CrimeCommitted = Crimes.None;
}

private void DaggerfallTravelPopUp_OnPostFastTravel()
{
// Clear crime state post fast travel
CrimeCommitted = Crimes.None;
}

#endregion
}
}

0 comments on commit cd33570

Please sign in to comment.