Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hunting (Aggression) #307

Closed
GregHib opened this issue Dec 17, 2022 · 4 comments · Fixed by #364
Closed

Hunting (Aggression) #307

GregHib opened this issue Dec 17, 2022 · 4 comments · Fixed by #364
Labels
enhancement New feature or request npc-ai npcs

Comments

@GregHib
Copy link
Owner

GregHib commented Dec 17, 2022

Invokes any interaction not just combat.

  • Happens outside the measurable cycle time. (Either before player packets or after all pending packets have been flushed - thus can be multithreaded
  • Shouldn't mutate any variables on the creatures
  • Content devs have incredible control over the conditions for it
  • It is used for a lot more than just combat which is why it's called "hunt" and used for hunter npcs reacting to traps around them. (Hunter traps are dummy npcs which hunter npcs can "hook onto")
  • Also used for scenery. e.g. death plataeu two trolls that begin a humorous conversation between themselves if a player get's near (only can occur ever 40 mins) https://media.z-kris.com/2022/03/javaw_14d-23h-10m-23s-298ms.mp4
  • Target they pick is random from a list of possible targets
  • There's probably a limit (like 20) but it is not known
  • Could possibly be made more efficient with [reservoir sampling](https://en.wikipedia.org/wiki/Reservoir_sampling
  • Would recommend soft-reference based cache for temporary lists to reduce generating unnecessary garbage.
  • Areas like godwars and battlefield are eventually marked as inactive and stop processing aggression for the entire area
  • Aggression doesn't use "local npcs" from npcs info as some servers have suggested.

(10 min) Timeout

The game tracks targets in a FIFO queue of 21x21 squares around the player and counts down so long as you remain in it. If you step out, the older square is wiped and a new square is built around the new tile you're on and the timer resets to 10 mins.

Eventually turns most (not all i.e. dark beasts) creatures around you unaggressive (just towards you, they can still aggro others).

Scripts are very configurable.
Not tied to combat at all.
Use for waking up cerberus too.

RS has hundreds of hunt modes.
e.g. some are used for starting npc cutscenes when you walk near to them.

Switching

Gwd npcs sometimes switch targets mid-combat to opposing factions. Caused by a hunt timeout? Caused by targets death

Neitiznot trolls fighting guards seem to switch every 3-10 ticks. Far more frequently than in GWD.

Cave lizards in Ourania/ZMI also switch frequently

Other gwd examples:
zamorakian npcs that are in another god's corner are completely unaggressive but will be if in the center.

Tolerance

After 10 minutes npcs will no longer flee from you and will fight back (with flawed anims?)
https://media.z-kris.com/2022/05/idea64_05d-19h-27m-34s-047ms.png

Player zones

Tracked by two 10x10 boxes
After teleport the first box is around where you arrive
The first tile outside of the first box is the first tile of the second box.
Then it's a FIFO queue of 2 boxes, remove the oldest one each time you leave the bounds of the two boxes.

Can be parallel processed.
Same boxes as discussed in Timeout ?

Kris' builder

Stack a bunch of predicates
https://media.z-kris.com/2022/07/IMoDMB251d.png

@GregHib GregHib added this to the Advanced Movement milestone Dec 17, 2022
@GregHib GregHib added enhancement New feature or request npcs labels Dec 17, 2022
@GregHib GregHib mentioned this issue Dec 17, 2022
@GregHib GregHib added the npc-ai label Dec 17, 2022
@GregHib

This comment was marked as outdated.

@GregHib
Copy link
Owner Author

GregHib commented Jul 12, 2023

hunt-1

Original - Mirror

@GauCho88664610: @jagexash Heya! Would you be willing to share a list of all permitted values for huntmode?

@JagexAsh: I'm not sure what you're referring to as a "value" here. There are a few dozen custom ones defined, with different settings for what trigger they call when they find a target, what kind of NPC/LOC/OBJ they seek, and whether to consider changing target after finding one.

@GauCho88664610: I was hoping for a list of labels so that we could try to categorize npc behaviour on the wiki. I was looking for possible values you could write while defining an npc. For example, one such valid huntmode "value" would be "aggressive_melee".

@JagexAsh: Alright, here's the main ones: {image}

[ranged]
[constant_melee]
[constant_ranged]
[cowardly]
[notbusy_melee]
[notbusy_range]
[aggressive_melee]
[aggressive_melee_extra]
[aggressive_ranged]
[aggressive_ranged_extra]
[ap1_trigger_constant]
[ap1_trigger]
[ap2_trigger_constant]
[ap2_trigger]
[op1_trigger_constant]
[op1_trigger]
[op2_trigger_constant]
[op2_trigger]
[queue11_trigger_constant]
[queue11_trigger]
[bigmonster_melee]
[bigmonster_ranged]

hunt-2

Original

@ZenKris21: @JagexAsh Could you show an example of a .hunt config? Curious how you define all the parameters that make up a hunt mode.

@JagexAsh: The variables are trackers for when the player/NPC last got attacked.

[aggressive_melee]
type=player
check_vis=lineofsight
check_nottoostrong=off
check_notcombat=%lastcombat
check_notcombat_self=%npc_lastcombat
check_notbusy=off
find_keephunting=off
find_newmode=opplayer2

@ZenKris21: That's interesting! What kind of other types exist, besides the obvious player and npc, if any?

@JagexAsh: NPCs can target scenery - see Pest Control.
Also objects, as used by the sweeper in Varrock.

@ZenKris21: Ooh, that's kind of surprising actually - thought those would be handled in content with eg loc_findallzone. Are there any other visibility types besides line of walk and line of sight too?

@JagexAsh: 'off', i.e. no check for line of walk/sight at all.

@ZenKris21: Cool! :) Mod Kieren iirc mentioned using NPC dormancy to help reduce cycle times. Is this dormancy something you can configure in Runescript, or is that entirely baked into the engine? Do all creatures stop their hunt scripts if there's no one around?

@JagexAsh: Baked into the engine, I believe. For hunts of things that aren't players, one can specify one of these to customise it:
nobodynear=keephunting
nobodynear=pausehunt

@ZenKris21: Ooh, interesting. Is the distance for this configurable? If not, do you happen to know how far it checks?

@JagexAsh: It is not, and I don't remember ever hearing a number for that.

@ZenKris21: How do you handle making hunt scripts check for targets less frequently than every cycle? Most hunt scripts seem to check every single cycle, however some, such as the cleaner in Varrock, Penance fighters and box traps, seem to do it less frequently.

@JagexAsh: There's a rate setting available in .hunt files, though for hunting non-player targets, the engine won't accept low numbers of ticks (presumably to minimise load). I don't recall what the minimum is.

@ZenKris21: Cool! :)
Does the engine always provide a single random target, or do you get kind of a list/sequence of targets which you can then furthermore filter in Runescript?

@JagexAsh: Single random target. The documentation says that prefer=nearest could exist, but if you try it, the compiler says it was never implemented.

@ZenKris21: So if you need more than one target, or someone that's nearest, you'd do it in Runescript?
On a side question - how does GWD hunt work, since they seem to target NPCs and players alike. Is it two separate hunt scripts? Can NPCs even have multiple hunt scripts?

@JagexAsh: 1. Yes.
2. Having defined different .hunt configs, one can tell an NPC which one to use. And GWD creatures switch occasionally.

@ZenKris21: How about filtering out players who wear god items that belong to the specific faction? Is this a config property, or handled within Runescript?

@JagexAsh: There's a config property for checking quantities of items with a specified parameter.

@ZenKris21: Are you able to write specific scripts in Runescript that fire when the hunt provides a target?
Is this what queue11_trigger is for?

@JagexAsh: Rather than setting the NPC into a behaviour mode, the hunt can tell the NPC to execute a particular queue. Queues 1-20 can exist; while 1, 3 and 8 are conventionally used for retaliation, death and holdspells, 11 has no standard purpose so it could be used for anything.

@ZenKris21: Earlier in the hunt config you showed:
check_notbusy=off

What does this "busy" status consist of?

@JagexAsh: Having a menu open.
That's why it's usually set to off, since a dev will generally want their NPC to be able to aggro a player regardless of that. Though for a *really* newbie area we might choose differently.

hunt-3

Original

@Skretzo: @JagexAsh What makes most monsters in the Wilderness aggressive regardless of the player's combat level? Is it a property of the NPC, like a huntmode category? Or maybe location based? How come the level 2 man in The Forgotten Cemetery is not aggressive?

@JagexAsh: In the huntmodes, the check_nottoostrong property accepts off or outside_wilderness. That man may simply not have hunting enabled at all.

@Skretzo: Thank you! What kind of property lets certain slayer monsters like the dark beast always be aggressive, even after the 10 minutes when most other NPCs lose interest?

@JagexAsh: check_afk can be on or off.

https://neptune-ps.gitlab.io/runescript/releases/hunt.html

hunt-4

Original

@ZenKris21: @JagexAsh What's responsible for switching the hunt modes for the monsters found in God Wars Dungeon? Would it be a NPC timer or some other mechanism?

@JagexAsh: On an NPC's death, if it thinks it died to an NPC (which happens there), it'll try triggering that NPC to randomise its huntmode.

@ZenKris21: Slight confusion here; does it trigger the NPC who died or the one who dealt the killing blow to switch the hunt mode? Can the game even track damage dealt by other NPCs?

@JagexAsh:  The dying one triggers it on whatever NPC did the final blow. Which may not have been the NPC that did the most damage, since the game doesn't track their damage like it does for players.

@GregHib
Copy link
Owner Author

GregHib commented Jul 14, 2023

Blurites hunt ranges

Hunt range 1 has 82 configs, npcs: Zombie, Skeleton, Ghost, Rocks, Wolf, Hole in the wall, Wall beast, Pirate, Rock, Stick, Pee Hat, Kraka, Mountain troll, Guard Bandit, Bloodworm, Crypt rat, Giant crypt rat, Crypt spider, Giant crypt spider, Giant bat, Grizzly bear, Magic axe, Fly trap, Giant rat, Shadow spider, Deadly red spider, Ice spider, Poison spider, Scorpion, Hobgoblin, Sergeant, Troll general, Sandy rocks, Mammoth, Ankou
Hunt range 2 has 34 configs, npcs: Hellhound, White wolf, Chaos dwarf, Lesser demon, Ice giant, Moss giant, Hill Giant, Flesh Crawler, Black unicorn, King Scorpion, Scorpia's offspring, Sandy Boulder
Hunt range 3 has 61 configs, npcs: Black dragon, Green dragon, Dark wizard, Chaos druid, Thug, Dark warrior, Battle mage, Greater demon, Black demon, Fire giant, Earth warrior, Chronozon, Guard, Flax keeper, Lava dragon, Elder Chaos druid, Cave lizard, Revenant imp, Revenant goblin, Revenant pyrefiend, Revenant hobgoblin, Revenant cyclops, Revenant hellhound, Revenant demon, Revenant ork, Revenant dark beast, Revenant knight, Revenant dragon
Hunt range 4 has 24 configs, npcs: Ice warrior, Cleaner, Ice troll runt, Ent, Soldier, Lizardman, Lizardman brute, Ranger, Doyen, Necromancer
Hunt range 5 has 131 configs, npcs: Swarm, Ice wolf, Bandit, Kalphite Soldier, Kalphite Guardian, Kalphite Worker, Kalphite Larva, Ice troll runt, Ice troll male, Ice troll grunt, Honour guard, Ducklings, Dark wizard, Ogre, Cyclops, Saradomin priest, Spiritual warrior, Spiritual ranger, Spiritual mage, Knight of Saradomin, Jogre, Ork, Hobgoblin, Goblin, Hellhound, Imp, Werewolf, Feral Vampyre, Bloodveld, Pyrefiend, Icefiend, Gorak, Aviansie, Jail guard, Khazard trooper, Gnome troop, Gnome, Mounted terrorbird gnome, Tortoise, Spawn, Dark Ankou, Zamorak warrior, Zamorak ranger, Zamorak mage, Zombie
Hunt range 6 has 7 configs, npcs: Black Knight, Bandit, Ice warrior, Scorpia, Crazy archaeologist, Chaos Fanatic
Hunt range 7 has 2 configs, npcs: Lizardman shaman
Hunt range 8 has 14 configs, npcs: Ash, Thrower Troll, Dark beast, Thrower troll, Cerberus
Hunt range 10 has 7 configs, npcs: Ice troll female, Chaos Elemental, Gnome Mage, Ancient Wyvern, Shaeded Beast
Hunt range 16 has 2 configs, npcs: Kalphite Queen
Hunt range 20 has 2 configs, npcs: Obor, Hespori
Hunt range 25 has 30 configs, npcs: Commander Zilyana, Starlight, Growler, Bree, General Graardor, Sergeant Strongstack, Sergeant Steelwill, Sergeant Grimspike, K'ril Tsutsaroth, Tstanon Karlak, Zakl'n Gritch, Balfrug Kreeyath, Kree'arra, Wingman Skree, Flockleader Geerin, Flight Kilisa, Growthling, Bryophyta, Alchemical Hydra
Hunt range 30 has 1 configs, npcs: Scorpia's guardian
Hunt range 50 has 6 configs, npcs: King Black Dragon, Cerberus, Sarachnis, Spawn of Sarachnis
Hunt range 64 has 1 configs, npcs: Skotizo

GregHib added a commit that referenced this issue Jul 15, 2023
GregHib added a commit that referenced this issue Jul 15, 2023
* Add player tolerance

* Add getOrDefault Variable getter

* Remove get and getOrNull Variables extensions

* Return nothing when yaml file is empty

* Add basic hunting modes #307

* Iterate batch zones in south-west upwards order

* Store FloorItems by Zone

* Add varrock ash cleaner

* Separate Player and NPCs from Interaction

* Fix floor items with reveal and remove timers

* Don't send update when clearing turn

* Fix delaying npcs

* Add cowardly hunt mode to giant spiders and dark wizards

* Add aggression attacking

* Remove NPC and PlayerActions

* Make player and npc interactions character agnostic

* Add dark wizard and delrith stats

* Fix Zone package

* Add demonbane passive weapon damage multipliers

* Fix clearing players collision in WorldTest

* Add floor item spawning to WorldTest

* Rename in_combat to underAttack

* Fix ranged combat test
@GregHib
Copy link
Owner Author

GregHib commented Jul 15, 2023

More hunt modes will be added over time for Monster v Monster and other scenarios.

Will need to add hunt mode switching when gwd targets die, and perhaps after a timeout too?

As more aggressive npcs are added performance may become an issue.

Possible performance improvements:

  • Dormancy when players not near
  • Reusing target lists
  • Reservoir sampling instead of collecting all targets into lists
  • Multithreading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request npc-ai npcs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant