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

The player can cancel fights by entering a room #14

Merged
merged 3 commits into from Apr 3, 2021
Merged

Conversation

szapp
Copy link
Collaborator

@szapp szapp commented Mar 30, 2021

Describe the bug
The player can run into a room and immediately leave it to cancel a fight if the NPC has full HP.

Expected behavior
The player can no longer cancel fights by entering and leaving a room.

@AmProsius AmProsius added this to To Do in v1.0.0 Dec 30, 2020
@AmProsius AmProsius removed ai labels Jan 1, 2021
@AmProsius AmProsius added validation: required This issue needs validation from one of the validators. validation: validated This issue is still present even with Systempack/Union. and removed validation: required This issue needs validation from one of the validators. labels Jan 28, 2021
@AmProsius AmProsius removed this from To Do in v1.0.0 Feb 9, 2021
@AmProsius
Copy link
Owner Author

func void B_CombatAssessEnterRoom ()
{
PrintDebugNpc (PD_ZS_FRAME, "B_CombatAssessEnterRoom");
if (Wld_GetPlayerPortalGuild() == GIL_NONE
&& !Npc_HasNews(self, NEWS_THEFT, other, self))
{
PrintDebugNpc (PD_ZS_CHECK, "...SC hat Raum des NSCs verlassen und noch nichts geklaut!");
if (self.attribute[ATR_HITPOINTS]==self.attribute[ATR_HITPOINTS_MAX]) // ...und wurde der NSC noch nicht getroffen...
{
PrintDebugNpc (PD_ZS_CHECK, "...NSC unverletzt!");
B_FullStop (self);
B_ResetTempAttitude (self);
B_AssessRemoveWeapon(); // ...dann bricht der NSC den Kampf gerade noch ab!
};
};
};

changed to

func void B_CombatAssessEnterRoom ()
{
	PrintDebugNpc				(PD_ZS_FRAME, "B_CombatAssessEnterRoom");
	if (Wld_GetPlayerPortalGuild() == GIL_NONE
	&&	!Npc_HasNews(self, NEWS_THEFT, other, self)
	&& 	self.aivar[AIV_ATTACKREASON] == AIV_AR_INTRUDER ) // sonst braucht man nur in einen Raum rennen und der Kampf ist vorbei
	{
		PrintDebugNpc			(PD_ZS_CHECK,	"...SC hat Raum des NSCs verlassen und noch nichts geklaut!");

		if (self.attribute[ATR_HITPOINTS]==self.attribute[ATR_HITPOINTS_MAX])				// ...und wurde der NSC noch nicht getroffen...
		{
			PrintDebugNpc		(PD_ZS_CHECK,	"...NSC unverletzt!");
			B_FullStop			(self);
			B_SetAttackReason	(self,	AIV_AR_NONE);
			B_ResetTempAttitude	(self);	
			B_AssessRemoveWeapon();															// ...dann bricht der NSC den Kampf gerade noch ab!
		};
	};
};

@AmProsius AmProsius added the provided fix This issue has a fix provided in the comments. label Feb 16, 2021
@szapp szapp added compatibility: difficult This issue is difficult to make compatible. type: session fix The fix for this issues is persistent across a session. labels Feb 20, 2021
@AmProsius AmProsius added this to To Do in v1.1.0 via automation Mar 5, 2021
@AmProsius AmProsius added this to the v1.1.0 milestone Mar 5, 2021
@szapp szapp added this to NPC function in Fix templates Mar 17, 2021
@szapp szapp added impl: hook script func This issue requires hooking script functions. compatibility: easy This issue is easy to make compatible. and removed compatibility: difficult This issue is difficult to make compatible. labels Mar 17, 2021
@szapp
Copy link
Collaborator

szapp commented Mar 18, 2021

This fix could be implemented by hooking B_CombatAssessEnterRoom and return prematurely, if self.aivar[AIV_ATTACKREASON] != AIV_AR_INTRUDER. Otherwise call the original function.

@AmProsius
Copy link
Owner Author

AmProsius commented Mar 19, 2021

This fix could be implemented by hooking B_CombatAssessEnterRoom and return prematurely, if self.aivar[AIV_ATTACKREASON] != AIV_AR_INTRUDER. Otherwise call the original function.

What's with B_SetAttackReason(self, AIV_AR_NONE); then? Is it not needed anymore or did you overlook that?

@szapp
Copy link
Collaborator

szapp commented Mar 30, 2021

I can't reproduce the bug. @AmProsius can you give me a scenario how to trigger it reliably?

@szapp
Copy link
Collaborator

szapp commented Mar 30, 2021

Actually, the fix as proposed here does not work. (Where does it come from?) An attack reason (AIV_ATTACKREASON) of AIV_AR_INTRUDER is only used for actual intruders, that is, when the PC runs into the castle or other guild-restricted areas. It is unrelated to portals (= private huts).

All this suggested change does is completely disabling aborting an attack when the PC leaves a hut, because the condition will never be true. That's unfortunately not a fix, it actually removes a feature.

@szapp szapp removed the provided fix This issue has a fix provided in the comments. label Mar 30, 2021
@szapp
Copy link
Collaborator

szapp commented Mar 30, 2021

I found a solution that should work:

func void B_CombatAssessEnterRoom ()
{
PrintDebugNpc (PD_ZS_FRAME, "B_CombatAssessEnterRoom");
if (Wld_GetPlayerPortalGuild() == GIL_NONE
&& !Npc_HasNews(self, NEWS_THEFT, other, self))
{
PrintDebugNpc (PD_ZS_CHECK, "...SC hat Raum des NSCs verlassen und noch nichts geklaut!");
if (self.attribute[ATR_HITPOINTS]==self.attribute[ATR_HITPOINTS_MAX]) // ...und wurde der NSC noch nicht getroffen...
{
PrintDebugNpc (PD_ZS_CHECK, "...NSC unverletzt!");
B_FullStop (self);
B_ResetTempAttitude (self);
B_AssessRemoveWeapon(); // ...dann bricht der NSC den Kampf gerade noch ab!
};
};
};

changed to

 func void B_CombatAssessEnterRoom () 
 { 
     PrintDebugNpc               (PD_ZS_FRAME, "B_CombatAssessEnterRoom"); 
     if (Wld_GetPlayerPortalGuild() == GIL_NONE 
     &&  !Npc_HasNews(self, NEWS_THEFT, other, self))
     &&  ((Npc_WasInState(self, ZS_ClearRoom)) || (Npc_WasInState(self, ZS_ClearRoomWait)))
     { 
         PrintDebugNpc           (PD_ZS_CHECK,   "...SC hat Raum des NSCs verlassen und noch nichts geklaut!"); 
  
         if (self.attribute[ATR_HITPOINTS]==self.attribute[ATR_HITPOINTS_MAX])               // ...und wurde der NSC noch nicht getroffen... 
         { 
             PrintDebugNpc       (PD_ZS_CHECK,   "...NSC unverletzt!"); 
             B_FullStop          (self); 
             B_ResetTempAttitude (self); 
             B_AssessRemoveWeapon();                                                         // ...dann bricht der NSC den Kampf gerade noch ab! 
         }; 
     }; 
 };

@szapp szapp requested a review from AmProsius March 30, 2021 15:19
@szapp szapp removed their assignment Mar 30, 2021
@szapp szapp added provided fix This issue has a fix provided in the comments. impl: add/modify if-condition This issue requires adding/replacing conditions to if-statements. and removed impl: hook script func This issue requires hooking script functions. labels Mar 30, 2021
@szapp
Copy link
Collaborator

szapp commented Mar 30, 2021

The test is manual:

  • Cause a fight with an NPC (without causing them damage!) and enter and leave the nearby room: The NPC will continue the fight.
  • Enter a room and wait for an NPC to react and attack the PC. Leave the room (without causing them damage!). The NPC will stop the fight.

@szapp szapp moved this from To Do to In Progress in v1.1.0 Mar 30, 2021
@AmProsius
Copy link
Owner Author

@AmProsius can you give me a scenario how to trigger it reliably?

I reproduced the bug by attacking the immortal gate guard at the main gate of the Old Camp and then running into and out of a hut. The guard then stopped attacking me and returned to the gate.

@AmProsius AmProsius merged commit 266f24d into master Apr 3, 2021
v1.1.0 automation moved this from In Progress to Done Apr 3, 2021
@AmProsius AmProsius deleted the bug014 branch April 3, 2021 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility: easy This issue is easy to make compatible. impl: add/modify if-condition This issue requires adding/replacing conditions to if-statements. provided fix This issue has a fix provided in the comments. type: session fix The fix for this issues is persistent across a session. validation: validated This issue is still present even with Systempack/Union.
Projects
Fix templates
Modify NPC function
v1.1.0
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants