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

Fleeing NPCs will now attack player that got too close #77622

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Night-Pryanik
Copy link
Contributor

@Night-Pryanik Night-Pryanik commented Nov 6, 2024

Summary

Features "Fleeing NPCs will now attack player that got too close"

Purpose of change

Describe the solution

Player gets adjacent to fleeing NPC -> NPC (if they have more than 30% health) attacks the player.
Also NPC will change their attitude to NPCATT_FLEE_TEMP if they decide to flee during danger assessment. This fixes the issue of NPC still having the attitude of Attacking to kill despite they decided to flee when they realized that things are going bad for them.

Describe alternatives you've considered

Make NPCs attack only 50% or 75% of time.
Make NPCs fire their ranged weapons when distance between him and player is 2 or 3.

Testing

Spawned NPC, gave him fleeing attitude. Ran to him, got a hit in the face.

Additional context

None.

@Night-Pryanik Night-Pryanik added <Enhancement / Feature> New features, or enhancements on existing NPC / Factions NPCs, AI, Speech, Factions, Ownership [C++] Changes (can be) made in C++. Previously named `Code` labels Nov 6, 2024
@github-actions github-actions bot added <Bugfix> This is a fix for a bug (or closes open issue) json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions labels Nov 6, 2024
@RenechCDDA
Copy link
Member

This doesn't appear to consider cases where the fleeing state was just set. If you're fighting with a NPC and wound them they might decide to flee, but will instead always choose to attack you with this PR. Therefore they will just stand there and fight to the death as long as you're in melee range.

@Night-Pryanik
Copy link
Contributor Author

Ok, have something to suggest to resolve this case?

@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Nov 6, 2024
@RenechCDDA
Copy link
Member

Not any good ones, unfortunately. Maybe they should just directly compare their speed to the target's speed to see if they even have a chance of getting away. The player changing stance is the only thing that normally changes a creature's speed, and the player's ability to sprint is limited... so this should mostly work.

src/npcmove.cpp Outdated Show resolved Hide resolved
Co-authored-by: RenechCDDA <[email protected]>
@Night-Pryanik
Copy link
Contributor Author

Not any good ones, unfortunately. Maybe they should just directly compare their speed to the target's speed to see if they even have a chance of getting away. The player changing stance is the only thing that normally changes a creature's speed, and the player's ability to sprint is limited... so this should mostly work.

You mean, if NPC is faster than a PC, then NPC should always run and don't strike PC when the latter got too close?

@github-actions github-actions bot removed the BasicBuildPassed This PR builds correctly, label assigned by github actions label Nov 6, 2024
@RenechCDDA
Copy link
Member

Yes. It doesn't make sense for them to flee if they can't reasonably get away.

Ideally we would track this in a more complicated manner where they try to flee and then reconsider if their attacker is able to catch up to them. But then you'll need to cache it into their 'memory' and handle the considerations for that. It would be a much more difficult and invasive change

@Night-Pryanik
Copy link
Contributor Author

I encountered the case where this solution fails - when NPC is cornered, he won't fight back, but will endlessly and foolishly try to move, despite there's nowhere left to go.

I guess I'll go the other way - fleeing NPC will fight back unless his HP isn't lower than some threshold. In that case he won't fight back, but will flee no matter what.

@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Nov 6, 2024
@Nebnis
Copy link
Contributor

Nebnis commented Nov 6, 2024

Maybe could give them a cooldown timer before they aggro back? Let's say, they will only attack you if they are cornered for more than 2~3 turns. This should resolve the problem of the npc never running if they are meleeing you

…alth

Also NPCs will change their attitude to `NPCATT_FLEE_TEMP ` when they decide to flee during danger assessment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` <Enhancement / Feature> New features, or enhancements on existing json-styled JSON lint passed, label assigned by github actions NPC / Factions NPCs, AI, Speech, Factions, Ownership
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fleeing NPCs should at least try to defend themselves if player gets close
3 participants