Skip to content

Commit

Permalink
Merge pull request #5186 from TracentEden2/fix_smn_pet_auto_attack_cl…
Browse files Browse the repository at this point in the history
…aim_issue

[core] Fix SMN player avatar auto attack issue (that can steal claim)
  • Loading branch information
zach2good authored Mar 12, 2024
2 parents 716881e + 683125d commit 8e96bfe
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/map/ai/controllers/mob_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,18 @@ void CMobController::TryLink()
{
if (PTarget->PPet->objtype == TYPE_PET && ((CPetEntity*)PTarget->PPet)->getPetType() == PET_TYPE::AVATAR)
{
petutils::AttackTarget(PTarget, PMob);
if (PTarget->objtype == TYPE_PC)
{
std::unique_ptr<CBasicPacket> errMsg;
if (PTarget->PPet->CanAttack(PMob, errMsg))
{
petutils::AttackTarget(PTarget, PMob);
}
}
else
{
petutils::AttackTarget(PTarget, PMob);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/map/entities/charentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ class CCharEntity : public CBattleEntity

virtual bool ValidTarget(CBattleEntity* PInitiator, uint16 targetFlags) override;
virtual bool CanUseSpell(CSpell*) override;
bool IsMobOwner(CBattleEntity* PTarget);

virtual void Die() override;
void Die(duration _duration);
Expand Down Expand Up @@ -600,7 +601,6 @@ class CCharEntity : public CBattleEntity

protected:
void changeMoghancement(uint16 moghancementID, bool isAdding);
bool IsMobOwner(CBattleEntity* PTarget);
void TrackArrowUsageForScavenge(CItemWeapon* PAmmo);

private:
Expand Down
17 changes: 17 additions & 0 deletions src/map/entities/petentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,23 @@ bool CPetEntity::ValidTarget(CBattleEntity* PInitiator, uint16 targetFlags)
return CMobEntity::ValidTarget(PInitiator, targetFlags);
}

bool CPetEntity::CanAttack(CBattleEntity* PTarget, std::unique_ptr<CBasicPacket>& errMsg)
{
// prevent pets from attacking mobs that the PC master does not own
if (this->PMaster)
{
auto* PChar = dynamic_cast<CCharEntity*>(this->PMaster);
if (PChar && !PChar->IsMobOwner(PTarget))
{
errMsg = std::make_unique<CMessageBasicPacket>(this, PTarget, 0, 0, MSGBASIC_ALREADY_CLAIMED);
PAI->Disengage();
return false;
}
}

return CBattleEntity::CanAttack(PTarget, errMsg);
}

void CPetEntity::OnPetSkillFinished(CPetSkillState& state, action_t& action)
{
TracyZoneScoped;
Expand Down
1 change: 1 addition & 0 deletions src/map/entities/petentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class CPetEntity : public CMobEntity
virtual void OnAbility(CAbilityState&, action_t&) override;
virtual bool ValidTarget(CBattleEntity* PInitiator, uint16 targetFlags) override;
void OnPetSkillFinished(CPetSkillState& state, action_t& action);
virtual bool CanAttack(CBattleEntity* PTarget, std::unique_ptr<CBasicPacket>& errMsg) override;

private:
PET_TYPE m_PetType; // the type of pet e.g. avatar/wyvern/jugpet etc
Expand Down

0 comments on commit 8e96bfe

Please sign in to comment.