otland / forgottenserver

A free and open-source MMORPG server emulator written in C++
https://otland.net
GNU General Public License v2.0
1.58k stars 1.05k forks source link

Monster AI Revamp [$100] #922

Open tdshain opened 10 years ago

tdshain commented 10 years ago

The following was documented over several hours of observing all kinds of monster behavior. I don't believe anything important was missed, but please point out any mistakes. If you do point something out, make sure that you take the time to verify it in-game beforehand so that we don't waste any time on theories.

For starters, canpushcreatures and canpushitems flags can be removed, because by definition if a monster is pushable then it cannot push items or creatures and if it is not pushable then it can push items and pushable creatures.

Dancestep - the creatures attempts to step randomly (1 second interval between checks) to any open square (north, south, east, or west) that keeps the monster within range of the target. If the square is blocked or occupied then the monster stays still until the next check. If there is a player on screen, but no target is reachable then the monster will no longer be restricted by range and can step anywhere (n,s,e,w) on screen. Monsters will only dancestep if they are within their desired range of the target or if no target is reachable.

Turning/Facing - if a creature changes directions while while moving there is no delay before or after the turn, they turn and take their next step in a fluid motion. During dancestep if the creature turns away from the target when it moves, it will adjust the direction to face the target again during it's next attack interval (turn and attack in fluid motion)

Running Away/Escaping - if a creature is below it's runonhealth value it will no longer attack the target with melee, it will however still use any of it's other abilities

Pathfinding (general) - creatures will always run fluidly either towards or away from the target (depending on config) and will not pause while using any spells or abilities. The only time a creature will pause is if the pathfinding changes. The only three causes to change a monsters path are if a) the target changes direction and a new path is needed to maintain configured distance, b) if a new "impassible obstacle" (will cover these later) appears between the monster and it's next step, or c) if the monster hits (doesn't have to do damge, poof and spark count here too) the target with a melee atk

Pathfinding (passable objects) - non-pushable creatures will push any items cross their path, the item will randomly be moved to a square next to it's current position (highest probability to be pushed directly in front of where the creature is stepping), if the randomly chosen sqm for the item to move is blocked (ie it cannot be moved to that sqm) then the item will be destroyed instantly with a poff animation and disappear. Non pushable monsters also have the ability to push any pushable monster, this behavior works the same as pushing items except they can get instantly killed instead of destroyed (still poff animation and monster is turned into a corpse with no loot and fresh blood pool). Pushing another monster or item does not cause the attacking creature to pause or slow down, the item or pushable monster is instantly moved out of the way which can sometimes cause a glitchy walking animation for pushable monsters as they are moved at the speed of the pushing monster.

Pathfinding (impassable objects) - impassable objects include any non-pushable monster, wall (or other physical obstacle), player and sometimes elemental fields. If there is no path to the target due to impassible objects, the monster will attempt to switch targets or if none are available it will start to dancestep randomly but still use spells and continue to shoot the target unless it dances out of range.

Elemental Fields - fields are completely ignored (ie walked on like normal tiles) if a) the monster is immune to the element in question, or b) if the monster has a flag set to 1 in the xml file that tells it to ignore that element (this will need to be added individually to all monster files). Otherwise, fields act as a soft wall where creatures will always try to walk around if a path is available. All pushable monsters are unable to walk through elemental fields unless they are immune to that field's element (eg scorpions and poison fields) or if it is actively suffering from the status condition already and there is no other path to the target (eg you shoot a firebomb on a cyclops it will now chase you through any fire fields that block it's path to you as long as you are burning). If a monster is not pushable then it will still treat the fields as a wall unless they are already attacking the target and the only way to reach the target is by crossing fields (in this case they will always take the shortest path, even if it means diagonal stepping). Monsters should not be able to target across fields (that they aren't immune to) unless the player attacks first.

Walkback - monsters should return to their approximate spawnpoints if they are further than 15 sqm away from it, the path is not obstucted and there are no players within range.

There is a $40 open bounty on this issue. Add to the bounty at Bountysource.

Nu77 commented 10 years ago

TFS really need improvements in AI code :+1:

HeavenIsLost commented 10 years ago

:+1: Thanks for this issue, TFS really needs a better AI

EPuncker commented 10 years ago

that is a great thing :+1:

tdshain commented 10 years ago

I have already started fixing what I can, but will be needing some assistance with fresh code that will be needed to complete this system. Expect to see some pull requests soon and if anyone skilled in c++ would like to help, please leave a message for me here.

EPuncker commented 10 years ago

For starters, canpushcreatures and canpushcreatures flags can be removed, because by definition if a monster is pushable then it cannot push items or creatures and if it is not pushable then it can push items and pushable creatures.

typo =P two canpushcreatures xD

btw the monster Adventurer can't be pushed nor push anything according to http://tibia.wikia.com/wiki/Adventurer

while Amazon can be pushed while she can still push objects according to http://tibia.wikia.com/wiki/Amazon same with Bandits http://tibia.wikia.com/wiki/Bandit

and maybe lots of others =P http://tibia.wikia.com/wiki/List_of_Pushable_Creatures

need ingame test tho

tdshain commented 10 years ago

@EPuncker Thanks for catching the typo, however I am quite certain about the pushing. I even went all the way out to amazon camp to prove wiki wrong. Monsters that can push, cannot be pushed and vice versa. If you can find me an example to the contrary I will revise the first post again though.

Zbizu commented 9 years ago

running away/escaping: I playd on global and dragons still did melee attacks while running away (I used a knight with follow fight mode)

tdshain commented 9 years ago

@Zbizu This is false, to be sure I just logged on and hit a dragon down to low hp and followed it for about 5 minutes. Just as I described, it did not land a single melee attack while it was fleeing, though it did continue to use targeted and facing fire attacks.

@All As I have already stated, many hours of observation went into developing these notes. Tibia wiki and personal memory are not sufficient grounds to call any of these points into question. If you feel that something here needs correction or refinement, please provide picture or video evidence that supports your claim.

As for development, I've been chipping away at some of the smaller issues here. Definitely could use some assistance if anyone wants to contribute, I simply don't have the spare time these days that I had a couple years ago.

jo3bingham commented 9 years ago

The biggest issue we noticed with monster AI was response time to a fleeing target. For example, if a rat is standing adjacent to you, and attacking you; if you run away from the rat immediately after it attacks you (there is a poof/spark/blood hit on your character) it takes the rat quite a long time to react and start following you. Conversely, the longer you wait after being hit, the quicker the rat reacts to you fleeing. While there are a lot of issues with monster AI, and you touched upon most, if not all, our team unanimously agreed this was the worst when it came to player abuse. Unfortunately, I believe monster AI could use a complete recode, and I don't have the time to contribute to something of such a large scale. Hopefully, though, something will be done.

ranisalt commented 9 years ago

@jo3bingham I guess this decision taking (following target) is checked every "tick" of the scheduler, which is 1000ms, that's why if you leave just after this 1000ms started, the creature takes the rest of the time to recheck and decide to follow player.

What could be done is to callback whenever a target moves and recalculate the decisions instead of waiting for a scheduler tick.

peonso commented 9 years ago

@tdshain I confirmed that in oldcams, but I don't know the correct values nor if it still works this way at vanilla, but monsters chance to cast spells are lowered if they reach melee range. I compared GFB spam from demons in normal hunts and in annihilator quest (where they are forced to stay at range).

What is also different are monsters haste and paralyze spells. It was confirmed by bot users that paralyze slow spells and haste spell from monsters varies in a fixed range, despite player speed values. Despite that TFS monsters apply paralyze and self-haste in a multiplicative way. I can't have a mummy gives -145 to -175 speed, I'm forced to apply an speedchange="-600" for 60% reduced speed.

ranisalt commented 9 years ago

@peonso you can use a custom spell script to have a variable value of speed change in a monster. Lots of monsters already use custom spells for, for example, skill reducing attacks. You might do the same to cast a spell that changes speed variably.

peonso commented 9 years ago

@ranisalt Thanks for pointing dude, seems obvious now, but I never thought it.

Katherine1 commented 8 years ago

I'll take a crack at doing both this and the monster pathfinding through magic tiles issue. I see @jo3bingham thinks the AI code needs a complete recode. It's that bad? Is there anything else on the AI wishlist other than this issue and the issue I just linked?

marksamman commented 8 years ago

@Katherine1 It's not that bad unless you care about replicating the exact behavior of a specific game. What @jo3bingham brings up is intentional to not run pathfinding every time a creature moves. I wouldn't mind a complete rewrite with @tdshain's observations taken into consideration though if you have time for that. There are some functions with too much complexity, particularly Monster::getDistanceStep which I would like to see cleaned up or rewritten.

Katherine1 commented 8 years ago

I have time, just need to get acquainted with the project code.

nekiro commented 8 years ago

nothing new on this issue?

darkjav commented 8 years ago

Any new?

marksamman commented 8 years ago

There's no point in writing comments asking for anything new unless you have anything new to share yourself. If someone is working on this issue, I'm sure they'll mention it here, so you can just subscribe instead.

darkjav commented 8 years ago

I think that the issue is here: https://github.com/otland/forgottenserver/blob/master/src/tile.cpp#L542

Anybody know how fix it?

kito2 commented 8 years ago

Hey everyone,

I am back after a few years out of OTs... Today got a TFS 1.2 version and runned roshamuul with a MS 300+... It was a piece of cake since monsters are not having the real speed and also you can bluff monsters using energy/fire walls...

The monsters are running around them so it is easy to avoid them.

Currently I am working on a project which is intented to be as CipSoft it is and I would like to fix this problem... It is possible to modify this AI system?

Also other monsters are walking over the fields which they are not intented to do, for example Choking Fear should not walk over energy, only if you attack him he will run to you and will walk over the fields.

peonso commented 8 years ago

About the issue @jo3bingham pointed about monsters being to slow to follow players is covered here https://otland.net/threads/weird-monster-behaviour-in-tfs-1-1.228021/#post-2200365

About monsters change target strategies: https://github.com/TwistedScorpio/OTHire/commit/5abc8c58073cd24ddb13d4b0c0dbc20a6f9e2221 https://github.com/TwistedScorpio/OTHire/commit/8e567570eec5a2d4570a376bb7431ee280d36513

About monsters pushing pushable monsters: https://github.com/babymannen/theforgottenserver-7.4/commit/9b01f8bb3abe95df0c3c8012a72c6ebe0fed3db3

edit: said some bullshit about: https://github.com/otland/forgottenserver/commit/bc83c4e5bed96eaeb027b9d2aca75403733a74e2, but it's actually right

About monsters not ignoring fields https://github.com/otland/forgottenserver/issues/193: https://github.com/TwistedScorpio/OTHire/commit/e647da449f15adef8da67f3fbc0908e6a69a348d making monsters that can push items be able to go through fields is path if not "costly" enough.

About monsters casting area spells through blockprojectile items https://github.com/otland/forgottenserver/issues/1690: https://github.com/kamil-karkus/forgottenserver/commit/a9657bd208dbbb224e8fcb9bf5a4359de3f9ed3d

Kamenuvol commented 7 years ago

Rotworm is not pushable and cannot push items or pushable monsters Carrion Worm is not pushable and can push items but not pushable monsters

peonso commented 7 years ago

This should be pointed out here also. https://github.com/otland/forgottenserver/issues/1372

brunominervino commented 7 years ago

More $15.00 for help this issue. @ranisalt update title please.

GoularPink commented 7 years ago

https://github.com/otland/forgottenserver/pull/2207/files

joseluis2g commented 7 years ago

Mkalo version is working as it intended, he should take the money.

WibbenZ commented 7 years ago

Mkalo's PR isn't the same as this, he only fixed magic fields while this PR has alot more things that are required. It should be removed from the "todo" in this PR tho.

joseluis2g commented 7 years ago

@WibbenZ thats true, thanks for pointing it out.

Mkalo commented 7 years ago

AFAIK Dancestep - Already implemented. Turning/Facing - Already implemented Running Away/Escaping - Already implemented. Pathfinding (general) - Already implemented. Pathfinding (passable objects) - Already implemented, however the creature poffs without leaving a corpse and blood. Pathfinding (impassable objects) - Already implemented.

I don't know who made all this, as this is a bunch of issues together in one and probably solved by different people, so nobody can really claim the bounty :. Probably whoever made the majority of the changes should claim it.

joseluis2g commented 7 years ago

also there is missing "Walkback" feature

tdshain commented 7 years ago

@Mkalo I wrote the code for passable objects some time ago, will update and add that in this week or next if I can find a little spare time. While I'm at it, I'll take a look at the other changes and compare for accuracy. Glad to see so much progress has been made since I've been away though, exciting to see things moving forward.

rudger commented 7 years ago

Increased the bounty, @ranisalt .

brunominervino commented 7 years ago

@ranisalt now $100

bountysource

StefanEJonsson commented 7 years ago

I want to give this a try. Nobody else is working on it right? I'll send you a message if I have any questions.