Skip to content

Commit

Permalink
reorder conditions for perf
Browse files Browse the repository at this point in the history
  • Loading branch information
Pospelove committed Nov 15, 2023
1 parent ab69b8b commit 4757fdc
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions skymp5-server/cpp/server_guest_lib/ActionListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,48 +856,48 @@ void ActionListener::OnHit(const RawMessageData& rawMsgData_,

float healthPercentage = currentActorValues.healthPercentage;

bool isRemoteBowAttack = false;

auto sourceLookupResult =
targetActor.GetParent()->GetEspm().GetBrowser().LookupById(hitData.source);
if (sourceLookupResult.rec &&
sourceLookupResult.rec->GetType() == espm::WEAP::kType) {
auto weapData =
espm::GetData<espm::WEAP>(hitData.source, targetActor.GetParent());
if (weapData.weapDNAM) {
if (weapData.weapDNAM->animType == espm::WEAP::AnimType::Bow ||
weapData.weapDNAM->animType == espm::WEAP::AnimType::Crossbow) {
if (!hitData.isBashAttack) {
isRemoteBowAttack = true;
if (targetActor.IsBlockActive()) {
if (ShouldBeBlocked(*aggressor, targetActor)) {
bool isRemoteBowAttack = false;

auto sourceLookupResult =
targetActor.GetParent()->GetEspm().GetBrowser().LookupById(
hitData.source);
if (sourceLookupResult.rec &&
sourceLookupResult.rec->GetType() == espm::WEAP::kType) {
auto weapData =
espm::GetData<espm::WEAP>(hitData.source, targetActor.GetParent());
if (weapData.weapDNAM) {
if (weapData.weapDNAM->animType == espm::WEAP::AnimType::Bow ||
weapData.weapDNAM->animType == espm::WEAP::AnimType::Crossbow) {
if (!hitData.isBashAttack) {
isRemoteBowAttack = true;
}
}
}
}
}
}

bool isBlockingByShield = false;

auto targetActorEquipmentEntries = targetActor.GetEquipment().inv.entries;
for (auto& entry : targetActorEquipmentEntries) {
if (entry.extra.worn != Inventory::Worn::None) {
auto res = targetActor.GetParent()->GetEspm().GetBrowser().LookupById(
entry.baseId);
if (res.rec && res.rec->GetType() == espm::ARMO::kType) {
auto data =
espm::GetData<espm::ARMO>(entry.baseId, targetActor.GetParent());
bool isShield = data.equipSlotId > 0;
if (isShield) {
isBlockingByShield = isShield;
bool isBlockingByShield = false;

auto targetActorEquipmentEntries =
targetActor.GetEquipment().inv.entries;
for (auto& entry : targetActorEquipmentEntries) {
if (entry.extra.worn != Inventory::Worn::None) {
auto res =
targetActor.GetParent()->GetEspm().GetBrowser().LookupById(
entry.baseId);
if (res.rec && res.rec->GetType() == espm::ARMO::kType) {
auto data =
espm::GetData<espm::ARMO>(entry.baseId, targetActor.GetParent());
bool isShield = data.equipSlotId > 0;
if (isShield) {
isBlockingByShield = isShield;
}
}
}
}
}
}

spdlog::trace("isRemoteBowAttack={}, isBlockingByShield={}",
isRemoteBowAttack, isBlockingByShield);

if (!isRemoteBowAttack || isBlockingByShield) {
if (targetActor.IsBlockActive()) {
if (ShouldBeBlocked(*aggressor, targetActor)) {
if (!isRemoteBowAttack || isBlockingByShield) {
hitData.isHitBlocked = true;
}
}
Expand Down

0 comments on commit 4757fdc

Please sign in to comment.