Skip to content

Commit

Permalink
IsAbleToBeMarkedStale
Browse files Browse the repository at this point in the history
  • Loading branch information
LtRipley36706 committed Feb 18, 2024
1 parent d3c4471 commit 556da0c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 20 deletions.
12 changes: 9 additions & 3 deletions Source/ACE.Server/Command/Handlers/DeveloperCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2786,9 +2786,15 @@ public static void HandleGeneratorDump(Session session, params string[] paramete
msg += $"AdjustedProbability: {wo.GetAdjustedProbability(activeProfile)} / {wo.GetTotalProbability()}\n";
msg += $"MostRecentSpawnTime: {profile.MostRecentSpawnTime.ToLocalTime()}\n";
if (wo.IsEncounter)
{
msg += $"StaleTime: {profile.StaleTime.ToLocalTime()}\n";
msg += $"HasAwakeCreaturesOrOpenContainers: {profile.HasAwakeCreaturesOrOpenContainers}\n";
{
var hasNonWorldObjects = 0;
var hasAwakeCreatures = 0;
var hasOpenContainers = 0;
var hasUnlockedChests = 0;
var isAbleToBeMarkedStale = profile.IsAbleToBeMarkedStale(ref hasNonWorldObjects, ref hasAwakeCreatures, ref hasOpenContainers, ref hasUnlockedChests);
msg += $"IsAbleToBeMarkedStale: {isAbleToBeMarkedStale}\n";
if (isAbleToBeMarkedStale)
msg += $"StaleTime: {profile.StaleTime.ToLocalTime()}\n";
}
msg += $"--====--\n";
if (profile.Spawned.Count > 0)
Expand Down
59 changes: 43 additions & 16 deletions Source/ACE.Server/Entity/GeneratorProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,31 +141,58 @@ public float Delay
/// </summary>
public bool IsMaxed => MaxCreate != -1 && CurrentCreate >= MaxCreate;

/// <summary>
/// Returns TRUE if this profile has any Creatures with IsAwake being true or any Containers with IsOpen being true
/// </summary>
public bool HasAwakeCreaturesOrOpenContainers
///// <summary>
///// Returns TRUE if this profile has any non-Creature WorldObjects, Creatures with IsAwake being false, any Containers with IsOpen being false,
///// any Chests with DefaultLocked true and IsLocked being true
///// </summary>
public bool IsAbleToBeMarkedStale(ref int hasNonWorldObjects, ref int hasAwakeCreatures, ref int hasOpenContainers, ref int hasUnlockedChests)
{
get
//var hasNonWorldObjects = 0;
//var hasAwakeCreatures = 0;
//var hasOpenContainers = 0;
//var hasUnlockedChests = 0;

if (Spawned.Count == 0)
return false;

foreach (var spawn in Spawned.Values)
{
foreach (var spawn in Spawned.Values)
var wo = spawn.TryGetWorldObject();
if (wo != null)
{
var wo = spawn.TryGetWorldObject();
if (wo != null)
if (wo is not Creature && !wo.IsGenerator)
hasNonWorldObjects++;

if (wo.IsGenerator)
{
if (wo is Creature creature && creature.IsAwake)
return true;
//if (wo is not Creature)
// hasNonWorldObjects++;

if (wo is Container container && container.IsOpen)
return true;
//if (wo is not Creature && wo is not GenericObject)
// hasNonWorldObjects++;

if (wo.IsGenerator && wo.GeneratorProfiles.Any(p => p.HasAwakeCreaturesOrOpenContainers))
return true;
//if (wo is Switch)
// hasNonWorldObjects++;

foreach (var profile in wo.GeneratorProfiles)
{
if (profile.IsAbleToBeMarkedStale(ref hasNonWorldObjects, ref hasAwakeCreatures, ref hasOpenContainers, ref hasUnlockedChests))
hasNonWorldObjects++;
}
}
}

return false;
if (wo is Creature creature && creature.IsAwake)
hasAwakeCreatures++;

if (wo is Container container && container.IsOpen)
hasOpenContainers++;

if (wo is Chest chest && (chest.GetProperty(PropertyBool.DefaultLocked) ?? false) && !chest.IsLocked)
hasUnlockedChests++;
}
}

return hasNonWorldObjects > 0 && hasAwakeCreatures == 0 && hasOpenContainers == 0 && hasUnlockedChests == 0;
}

/// <summary>
Expand Down
7 changes: 6 additions & 1 deletion Source/ACE.Server/WorldObjects/WorldObject_Generators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,12 @@ public void CheckForStaleEncounters()
{
if (!IsEncounter) return;

var idleStaleProfiles = GeneratorProfiles.Where(p => p.IsMaxed && (DateTime.UtcNow > p.StaleTime) && !p.HasAwakeCreaturesOrOpenContainers);
var hasNonWorldObjects = 0;
var hasAwakeCreatures = 0;
var hasOpenContainers = 0;
var hasUnlockedChests = 0;

var idleStaleProfiles = GeneratorProfiles.Where(p => p.IsMaxed && (DateTime.UtcNow > p.StaleTime) && p.IsAbleToBeMarkedStale(ref hasNonWorldObjects, ref hasAwakeCreatures, ref hasOpenContainers, ref hasUnlockedChests));

foreach (var profile in idleStaleProfiles)
profile.Reset();
Expand Down

0 comments on commit 556da0c

Please sign in to comment.