Class NPCGroup
- Namespace
- FishMMO.Server.Implementation.World.SceneServer.AI
- Assembly
- FishMMO.Server.dll
A pack of NPCs that fight together: a shared focus target, group alerts, roles, and a tactic that arranges members around the enemy while they orbit it.
public sealed class NPCGroup
- Inheritance
-
NPCGroup
- Inherited Members
Remarks
A plain runtime object, owned by whatever founded it. A spawner whose pack is enabled
(Enabled) founds one when its first NPC spawns and adds every
NPC it spawns after that, with the role its entry names; a boss founds one for the adds it
calls in. It used to be a scene MonoBehaviour with inspector-assigned members and its
own Update, and nothing ever created one: NPC brains are added to pooled instances at
runtime on the server, so there was never a brain in a scene for an inspector to point at,
and Group was never set.
Membership is the living members. A brain leaves on death (SuspendForCorpse()), on despawn and pool reset (FishMMO.Server.Implementation.World.SceneServer.AI.AIController.ResetForPool()) and when it is destroyed with its scene. A pack whose last member leaves is Released: it stops ticking, refuses members, and its founder makes a new one for the next spawn. So a respawn rejoins its spawner's pack while any member of it still stands, and founds the next one after a wipe.
Ticked by the brain host, inside the AI contract. AIBrainHost calls Tick(float, int) on every network tick; the pack thinks only on AI ticks (the same whole divisor of the network tick the brains use), only while a member is in a tier that fights (TierEvaluates(AILodTier)), and every EVALUATE_INTERVAL seconds scaled by that member's LOD interval. A pack with nobody near it costs a tier read per member per AI tick and does nothing else.
Constructors
NPCGroup(NPCPackSettings)
Founds a pack with authored tuning.
public NPCGroup(NPCPackSettings settings)
Parameters
settingsNPCPackSettingsThe spawner's pack block; null founds an untuned pack.
NPCGroup(PackTactic, bool, float, float)
Founds a pack.
public NPCGroup(PackTactic tactic, bool focusTargeting, float tacticOrbitRadius, float kiteRotationSpeed)
Parameters
tacticPackTacticHow members arrange themselves while orbiting the focus.
focusTargetingboolWhether the focus follows the tank's target.
tacticOrbitRadiusfloatThe tactic ring's radius, in metres.
kiteRotationSpeedfloatDegrees per second the Kite ring turns.
Fields
CLUSTER_SPREAD
Total arc, in radians, a FocusFire cluster is spread over (about 30°).
public const float CLUSTER_SPREAD = 0.52
Field Value
DEFAULT_KITE_ROTATION_SPEED
Default KiteRotationSpeed for a pack founded without authored settings.
public const float DEFAULT_KITE_ROTATION_SPEED = 30
Field Value
DEFAULT_ORBIT_RADIUS
Default TacticOrbitRadius for a pack founded without authored settings.
public const float DEFAULT_ORBIT_RADIUS = 5
Field Value
EVALUATE_INTERVAL
Seconds of AI time between evaluations for a pack whose most active member is in the Active tier. Other tiers multiply it by their LOD interval.
public const float EVALUATE_INTERVAL = 0.5
Field Value
Properties
AliveMemberCount
Living members at the last evaluation.
public int AliveMemberCount { get; }
Property Value
FocusTargeting
When true, the pack's focus follows the target of its living, fighting tank.
public bool FocusTargeting { get; }
Property Value
GroupTarget
The focused enemy's transform, or null. See GroupTargetCharacter.
public Transform GroupTarget { get; }
Property Value
- Transform
GroupTargetCharacter
The enemy the pack is focusing, or null.
public ICharacter GroupTargetCharacter { get; }
Property Value
Remarks
Set by AlertGroup(ICharacter) and, with FocusTargeting, by the tank's target at each evaluation; dropped when the pack is no longer fighting. Held with the ID it had, for the reason TargetCharacter is: a pooled character's object is re-issued to somebody else after a despawn, and a bare reference would hand the pack's DPS the pool's next occupant as their focus.
IsInCombat
True when a member was fighting (in any combat state) at the last evaluation.
public bool IsInCombat { get; }
Property Value
KiteRotationSpeed
Degrees per second the Kite ring turns.
public float KiteRotationSpeed { get; }
Property Value
LowestHealthMember
The most wounded living member, or null when every living member is at full health.
public AIController LowestHealthMember { get; }
Property Value
Remarks
Null rather than "whoever happened to be first" when nobody is hurt: a defender reads this to decide whom to body-block for, and shielding a healthy packmate took it out of the fight for nothing.
LowestHealthPercent
Health fraction (0-1) of LowestHealthMember; 1 when nobody is wounded.
public float LowestHealthPercent { get; }
Property Value
MemberCount
Members, living or not yet pruned.
public int MemberCount { get; }
Property Value
Members
The members, in joining order.
public IReadOnlyList<NPCGroupMember> Members { get; }
Property Value
Released
True once the last member has left. A released pack never takes a member again.
public bool Released { get; }
Property Value
Tactic
How the pack arranges itself around the enemy it focuses.
public PackTactic Tactic { get; }
Property Value
TacticOrbitRadius
Radius of the ring an orbiting member takes its tactic slot on, in metres.
public float TacticOrbitRadius { get; }
Property Value
Methods
AddMember(AIController, NPCGroupRole)
Adds a brain with a role, taking it out of any other pack first. Adding a member again updates its role.
public bool AddMember(AIController controller, NPCGroupRole role)
Parameters
controllerAIControllerThe brain joining.
roleNPCGroupRoleThe role it plays here.
Returns
- bool
False when the brain is null or this pack has been released.
Remarks
The first member hands the pack to its brain's host, which ticks it from then on.
AlertGroup(ICharacter)
Tells the pack that one of its members has engaged enemy: the pack
focuses it, and every member free to fight joins in.
public void AlertGroup(ICharacter enemy)
Parameters
enemyICharacterThe character a member has engaged.
Remarks
Called by ChangeState(BaseAIState, List<ICharacter>) whenever a member enters an attacking state with a target. Who answers is decided by the member, with the same rule a hit is asked (MayAnswerPackAlert(bool, bool, bool, bool, bool, bool, bool)): not a member already fighting, evading on a leash, immortal, dead or without a brain that runs.
AssignFormation(PackTactic, IReadOnlyList<NPCGroupRole>, IReadOnlyList<float>, float, float, List<int>, List<float>)
Assigns each formation member a bearing around the focus for a tactic.
public static void AssignFormation(PackTactic tactic, IReadOnlyList<NPCGroupRole> roles, IReadOnlyList<float> bearings, float flankFront, float kiteAdvance, List<int> order, List<float> angles)
Parameters
tacticPackTacticThe tactic.
rolesIReadOnlyList<NPCGroupRole>Each formation member's role.
bearingsIReadOnlyList<float>Each member's current bearing from the focus, in radians.
flankFrontfloatThe Flank tactic's front bearing: the tank's, or the direction the enemy faces.
kiteAdvancefloatRadians the Kite ring turns this evaluation.
orderList<int>Scratch list, overwritten.
anglesList<float>Receives each member's assigned bearing, index for index; a member's current bearing when the tactic is None.
Remarks
Fitted to where the members already stand, never to the world axes. The slots used to be absolute angles from world +X, so a Flank's "front" was east whatever the enemy faced and a FocusFire cluster formed on the east side even when the pack had come from the west. Now:
- Surround — an even ring, rotated to the angle that moves the members least (the circular mean of each member's bearing less its ring step), members kept in the order they stand around the enemy.
- Kite — the same ring advanced by
kiteAdvance, so the ring turns from wherever the members are rather than from a stored angle they have drifted away from. - FocusFire — a CLUSTER_SPREAD arc centred on the members' mean bearing: they converge from the side they are already on.
- Flank — tanks at
flankFront, everyone else across the rear half-circle in the order they stand; a single flanker directly behind. (It used to put a lone flanker at the side, 90° from the front.)
Pure, so every tactic's geometry can be pinned without a scene.
BearingOf(Vector3)
The bearing of a horizontal offset, in the convention OrbitState places by:
(cos a, 0, sin a).
public static float BearingOf(Vector3 offset)
Parameters
offsetVector3The offset.
Returns
- float
The bearing in radians; 0 for an offset with no horizontal length.
Dissolve()
Removes every member and releases the pack. Called when its founder stops — a spawner whose scene unloads.
public void Dissolve()
GetMemberByRole(NPCGroupRole)
The first living member with a role, or null.
public AIController GetMemberByRole(NPCGroupRole role)
Parameters
roleNPCGroupRoleThe role to look for.
Returns
- AIController
The member's brain, or null.
IsWounded(float)
Whether a member at this health fraction needs help. Pure, so the rule can be pinned.
public static bool IsWounded(float healthFraction)
Parameters
healthFractionfloatCurrent over maximum health.
Returns
- bool
True below full health.
MostActiveTier(AILodTier, AILodTier)
The more active of two tiers. Pure, so the pack's tier rule can be pinned.
public static AILodTier MostActiveTier(AILodTier a, AILodTier b)
Parameters
Returns
- AILodTier
Whichever does more work.
RemoveMember(AIController)
Removes a brain. Removing the last member releases the pack.
public void RemoveMember(AIController controller)
Parameters
controllerAIControllerThe brain leaving; compared by reference, so a destroyed brain can still leave.
ResolveEvaluateInterval(int)
Seconds between evaluations for a member tier's LOD interval.
public static float ResolveEvaluateInterval(int lodInterval)
Parameters
lodIntervalintThe tier's interval, in AI ticks.
Returns
- float
The evaluation interval, in seconds.
Remarks
The pack slows with its members: a Nearby brain thinking every third AI tick is read by a pack that evaluates a third as often. Pure, so it can be pinned.
TierEvaluates(AILodTier)
Whether a pack whose most active member is in tier evaluates at all.
public static bool TierEvaluates(AILodTier tier)
Parameters
tierAILodTierThe tier.
Returns
- bool
True when the pack evaluates.
Remarks
Active and Nearby, the tiers whose brains still fight. Pure, so it can be pinned.
Wrap(float)
An angle wrapped to [0, 2π).
public static float Wrap(float angle)
Parameters
anglefloatAny angle, in radians.
Returns
- float
The same direction in [0, 2π).