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

The player can cancel fights by entering a room #14

merged 3 commits into from Apr 3, 2021

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 validation: validated and removed validation: required labels Jan 28, 2021
@AmProsius AmProsius removed this from To Do in v1.0.0 Feb 9, 2021
@AmProsius
Copy link
Owner Author

@AmProsius AmProsius commented Feb 16, 2021

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 label Feb 16, 2021
@szapp szapp added compatibility: difficult type: session fix 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 compatibility: easy and removed compatibility: difficult labels Mar 17, 2021
@szapp
Copy link
Collaborator

@szapp 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 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 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 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 label Mar 30, 2021
@szapp
Copy link
Collaborator

@szapp 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 Mar 30, 2021
@szapp szapp removed their assignment Mar 30, 2021
@szapp szapp added provided fix impl: add/modify if-condition and removed impl: hook script func labels Mar 30, 2021
@szapp
Copy link
Collaborator

@szapp 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 AmProsius commented Apr 3, 2021

@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 Apr 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility: easy impl: add/modify if-condition provided fix type: session fix validation: validated
Projects
Fix templates
Modify NPC function
v1.1.0
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants