add a optional limit on number of npcs per scene default = 40

This commit is contained in:
UbitUmarov
2021-07-16 01:52:03 +01:00
parent 03239dfbca
commit fbc10387c8
3 changed files with 21 additions and 0 deletions

View File

@@ -51,6 +51,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC
private readonly Dictionary<UUID, NPCAvatar> m_avatars = new Dictionary<UUID, NPCAvatar>();
private NPCOptionsFlags m_NPCOptionFlags;
private int m_MaxNumberNPCperScene = 40;
public NPCOptionsFlags NPCOptionFlags {get {return m_NPCOptionFlags;}}
public bool Enabled { get; private set; }
@@ -74,6 +76,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC
if(config.GetBoolean("NoNPCGroup", true))
m_NPCOptionFlags |= NPCOptionsFlags.NoNPCGroup;
m_MaxNumberNPCperScene = config.GetInt("MaxNumberNPCsPerScene", m_MaxNumberNPCperScene);
}
}
@@ -161,6 +165,12 @@ namespace OpenSim.Region.OptionalModules.World.NPC
Vector3 position, UUID agentID, UUID owner, string groupTitle, UUID groupID, bool senseAsAgent, Scene scene,
AvatarAppearance appearance)
{
if(m_MaxNumberNPCperScene > 0)
{
if(scene.GetRootNPCCount() >= m_MaxNumberNPCperScene)
return UUID.Zero;
}
NPCAvatar npcAvatar = null;
string born = DateTime.UtcNow.ToString();

View File

@@ -1208,6 +1208,11 @@
;# {Enabled} {} {Enable Non Player Character (NPC) facilities} {true false} false
; Enabled = false
;; max number of NPCs per scene default: 40
;; set to a negative value to allow any number
;; note that a NPC is almost as heavy as a normal avatar, so you should limit them
;; MaxNumberNPCsPerScene = 40
;; several options to control NPCs creation
;# {AllowNotOwned} {} {allow NPCs to be created not Owned} {true false} true

View File

@@ -2142,6 +2142,12 @@
[NPC]
;; Enable Non Player Character (NPC) facilities
Enabled = false
;; max number of NPCs per scene default: 40
;; set to a negative value to allow any number
;; note that a NPC is almost as heavy as a normal avatar, so you should limit them
;; MaxNumberNPCsPerScene = 40
;; several options to control NPCs creation
;; allow NPCs to be created not Owned {true false} default: true