Skip to content

Commit b84931d

Browse files
Grenade penguin htn (space-wizards#34935)
* we can do better * better * slightlybetter * remove unused dependency * uplink description more descriptive * more intentional explosion stats * cleanup --------- Co-authored-by: iaada <iaada@users.noreply.github.com> Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
1 parent 61cab59 commit b84931d

5 files changed

Lines changed: 141 additions & 5 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using Content.Shared.NPC.Systems;
2+
using Robust.Shared.Containers;
3+
using Robust.Server.Containers;
4+
using Robust.Shared.GameObjects;
5+
6+
namespace Content.Server.NPC.HTN.Preconditions;
7+
8+
/// <summary>
9+
/// Checks if the owner is in a friendly container.
10+
/// Recursively checks if container's container is friendly.
11+
/// </summary>
12+
public sealed partial class InFriendlyContainerPrecondition : HTNPrecondition
13+
{
14+
private ContainerSystem _container = default!;
15+
private NpcFactionSystem _npcFaction = default!;
16+
17+
[DataField] public bool IsInFriendlyContainer = true;
18+
19+
public override void Initialize(IEntitySystemManager sysManager)
20+
{
21+
base.Initialize(sysManager);
22+
_container = sysManager.GetEntitySystem<ContainerSystem>();
23+
_npcFaction = sysManager.GetEntitySystem<NpcFactionSystem>();
24+
}
25+
26+
public override bool IsMet(NPCBlackboard blackboard)
27+
{
28+
var owner = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner);
29+
30+
if (!_container.TryGetContainingContainer(owner, out var container))
31+
return !IsInFriendlyContainer;
32+
33+
return IsInFriendlyContainer == IsContainerOrParentFriendly(owner, container.Owner);
34+
}
35+
36+
/// <summary>
37+
/// Recursively check if a container or any parent container is friendly.
38+
/// </summary>
39+
/// <returns>True if any container is friendly.</returns>
40+
private bool IsContainerOrParentFriendly(EntityUid owner, EntityUid containerOwner)
41+
{
42+
if (_npcFaction.IsEntityFriendly(owner, containerOwner))
43+
return true;
44+
45+
if (!_container.TryGetContainingContainer(containerOwner, out var nextContainer))
46+
return false;
47+
48+
return IsContainerOrParentFriendly(owner, nextContainer.Owner);
49+
}
50+
}

Resources/Locale/en-US/store/uplink-catalog.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ uplink-whitehole-grenade-name = Whitehole Grenade
5454
uplink-whitehole-grenade-desc = Grenade that repulses everything around for about 10 seconds. Very useful in small rooms and for chasing someone.
5555
5656
uplink-penguin-grenade-name = Grenade Penguin
57-
uplink-penguin-grenade-desc = A small, highly-aggressive penguin with a grenade strapped around its neck. Harvested by the Syndicate from icy shit-hole planets.
57+
uplink-penguin-grenade-desc = A small, highly-aggressive penguin with a grenade strapped around its neck. Trained to ignore all Syndicate agents and relentlessly pursue a single, random nearby target when released.
5858
5959
uplink-c4-name = C-4
6060
uplink-c4-desc = Use it to breach walls, airlocks or sabotage equipment. It can be attached to almost all objects and has a modifiable timer with a minimum setting of 10 seconds.

Resources/Prototypes/Entities/Mobs/NPCs/animals.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,7 +2346,7 @@
23462346
- type: MobMover
23472347
- type: HTN
23482348
rootTask:
2349-
task: SimpleHostileCompound
2349+
task: GrenadePenguinCompound
23502350
- type: NpcFactionMember
23512351
factions:
23522352
- Syndicate
@@ -2394,9 +2394,9 @@
23942394
beepInterval: 1
23952395
- type: Explosive
23962396
explosionType: Default
2397-
maxIntensity: 20
2398-
intensitySlope: 20
2399-
totalIntensity: 225
2397+
maxIntensity: 10
2398+
intensitySlope: 3
2399+
totalIntensity: 150
24002400
- type: ExplodeOnTrigger
24012401
keysIn:
24022402
- timer

Resources/Prototypes/NPCs/Combat/melee.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,13 @@
178178
id: MeleeService
179179
proto: OrderedTargets
180180
key: Target
181+
182+
- type: htnCompound
183+
id: DoNotEscapeCompound
184+
branches:
185+
- preconditions:
186+
- !type:InFriendlyContainerPrecondition
187+
isInFriendlyContainer: true
188+
tasks:
189+
- !type:HTNPrimitiveTask
190+
operator: !type:NoOperator
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
- type: htnCompound
2+
id: GrenadePenguinCompound
3+
branches:
4+
- tasks:
5+
- !type:HTNCompoundTask
6+
task: GrenadePenguinMeleeCombatPrecondition
7+
- tasks:
8+
- !type:HTNCompoundTask
9+
task: IdleCompound
10+
11+
- type: htnCompound
12+
id: GrenadePenguinMeleeCombatPrecondition
13+
branches:
14+
- preconditions:
15+
- !type:BuckledPrecondition
16+
isBuckled: true
17+
tasks:
18+
- !type:HTNPrimitiveTask
19+
operator: !type:UnbuckleOperator
20+
shutdownState: TaskFinished
21+
22+
- preconditions:
23+
- !type:InFriendlyContainerPrecondition
24+
isInFriendlyContainer: true
25+
tasks:
26+
- !type:HTNCompoundTask
27+
task: DoNotEscapeCompound
28+
29+
- preconditions:
30+
- !type:InContainerPrecondition
31+
isInContainer: true
32+
tasks:
33+
- !type:HTNCompoundTask
34+
task: EscapeCompound
35+
36+
- preconditions:
37+
- !type:PulledPrecondition
38+
isPulled: true
39+
tasks:
40+
- !type:HTNPrimitiveTask
41+
operator: !type:UnPullOperator
42+
shutdownState: TaskFinished
43+
44+
- tasks:
45+
- !type:HTNPrimitiveTask
46+
operator: !type:UtilityOperator
47+
proto: NearbyMeleeTargets
48+
- !type:HTNCompoundTask
49+
task: GrenadePenguinMeleeCombatCompound
50+
51+
- type: htnCompound
52+
id: GrenadePenguinMeleeCombatCompound
53+
branches:
54+
- preconditions:
55+
- !type:KeyExistsPrecondition
56+
key: Target
57+
tasks:
58+
- !type:HTNPrimitiveTask
59+
operator: !type:MoveToOperator
60+
shutdownState: PlanFinished
61+
pathfindInPlanning: true
62+
removeKeyOnFinish: false
63+
targetKey: TargetCoordinates
64+
pathfindKey: TargetPathfind
65+
rangeKey: MeleeRange
66+
# too angry to juke
67+
- !type:HTNPrimitiveTask
68+
operator: !type:MeleeOperator
69+
targetKey: Target
70+
preconditions:
71+
- !type:KeyExistsPrecondition
72+
key: Target
73+
- !type:TargetInRangePrecondition
74+
targetKey: Target
75+
rangeKey: MeleeRange
76+
# no service, no changing target

0 commit comments

Comments
 (0)