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

Add some vanilla behavior for npcs #653

Merged
merged 9 commits into from
Jul 24, 2024
Merged

Add some vanilla behavior for npcs #653

merged 9 commits into from
Jul 24, 2024

Conversation

thokkat
Copy link
Contributor

@thokkat thokkat commented Jul 16, 2024

If a npc comes into visibility range:

  • Best weapons are automatically equipped. For ranged weapons ammo has to be in inventory. From testing turns out this is checked in equipBestRangedWeapon. Bartok can be used as test npc.

  • Script function B_RefreshAtInsert that restores health is called in G2.

Additionally clean up some leftover of 1hp npc handling and setting the damage type to 2 if its default was 0. Needed for the hero in G1. Tested as behaving the same in G2 for some monsters and humans by setting their damage type to 0 in script.

Closes #354

Copy link
Owner

@Try Try left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @thokkat and thanks for PR!

Can you also have a look here: #305 (last few comments), as this seem to be related?

game/world/objects/npc.cpp Show resolved Hide resolved
@@ -1128,6 +1128,14 @@ void GameScript::invokePickLock(Npc& npc, int bSuccess, int bBrokenOpen) {
vm.call_function<void>(fn, bSuccess, bBrokenOpen);
}

void GameScript::invokeRefreshAtInsert(Npc& npc) {
auto fn = vm.find_symbol_by_name("B_RefreshAtInsert");
if(fn==nullptr)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be good idea to cache function in GameScript, similar to ItKE_lockpick, as there will be burst of this calls after "sleep".

game/game/inventory.cpp Show resolved Hide resolved
@Try
Copy link
Owner

Try commented Jul 22, 2024

I've tested path today: it seems we missing a case, when autoEquipWeapons should be invoked. In G2 insert PC_ROCKEFELLER inserts an paladin with berserkers-axe and dragon-crossbow. In opengothic - default paladin sword. Would it be correct to also call autoEquipWeapons in Npc constructor? Not sure about different cases, such as summons.

@@ -169,7 +169,9 @@ Npc::Npc(World &owner, size_t instance, std::string_view waypoint)
owner.script().initializeInstanceNpc(hnpc, instance);
hnpc->wp = std::string(waypoint);

// vanilla forces non-zero damage type
// vanilla behavior: equip best weapon and set non-zero damage type
if(!isMonster() && !isPlayer())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more question: isMonster is truly relevant? For wolfs/snappers should not mater; but maybe relevant for skeletons

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes best weapon autoequip works for skeletons and from what I tested it seems to only work for skeletons. Other monsters just have the weapon in their inventory.

For like a wolf weapon inserted with CreateInvItem is equipped and visible in OpenGothic, that's why I excluded monsters in general.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some thinking it's maybe best to prevent weapon equipping for monsters somewhere in the equip function directly in case someone adds a EquipItem call in script.

Skeleton is detected based on guild in vanilla. Changing the guild of a golem to skeleton resulted in a draw/remove weapon stall.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it not directly related to isMonster would be nice to at least understand how it intended to work.
I've done some testing with marvin - guild by itself seem to be irrelevant. Maybe it's related to npc having some builtin bones, such as ZS_SWORD/ZS_RIGHTHAND ?

Can you test what will happen if you assign GIL_SHEEP to skeleton or "Ske_Body" to sheep, while having weapon in inventory?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UPD:
Tested by editing Nikolas guild: as GIL_SKELETON or GIL_SHEEP he still equips best weapon.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GIL_SHEEP to skeleton

Nothing.

"Ske_Body" to sheep

Nothing but if Mdl_SetVisual (self, "HumanS.mds") with Sheep_Body sword is visible.

For default sheep both Npc_HasEquippedWeapon and Npc_HasEquippedMeleeWeapon return true.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GIL_SHEEP to skeleton
Nothing.

You mean nothing changed, or skeleton does not equip weapons any more?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing changed.

@Try Try merged commit 349a237 into Try:master Jul 24, 2024
1 check was pending
@Try
Copy link
Owner

Try commented Jul 24, 2024

I've decide to file another ticket for monster/non-monster topic;
Merged, with minor changes, thanks!

@thokkat thokkat deleted the npc branch July 25, 2024 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NPC problems
2 participants