Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions game/world/objects/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2299,13 +2299,16 @@ void Npc::tickRegen(int32_t& v, const int32_t max, const int32_t chg, const uint
uint64_t tick = owner.tickCount();
if(tick<dt || chg==0)
return;
int32_t time0 = int32_t(tick%1000);
int32_t time1 = time0+int32_t(dt);

int32_t val0 = (time0*chg)/1000;
int32_t val1 = (time1*chg)/1000;
// ATR_REGENERATE* is an interval: 1 point per 'chg' seconds.
// treating it as points-per-second made monsters in mods with hp-regeneration (L'Hiver)
// heal faster than the player can deal damage
const uint64_t period = uint64_t(std::abs(chg))*1000u;
const int32_t step = chg>0 ? 1 : -1;
const int32_t n = int32_t((tick%period+dt)/period);
if(n==0)
return;

int32_t nextV = std::max(0,std::min(v+val1-val0,max));
int32_t nextV = std::max(0,std::min(v+n*step,max));
if(v!=nextV) {
v = nextV;
// check health, in case of negative chg
Expand Down Expand Up @@ -4669,7 +4672,10 @@ bool Npc::canRayHitPoint(const Tempest::Vec3 self, const Tempest::Vec3 pos, floa
return !w->ray(self, pos).hasCol;
}

float dx = self.x-pos.x, dz=self.z-pos.z;
// measure view cone from npc position, not from head bone: in melee the head of an
// attacking monster dives into the target and the direction becomes numerical noise.
// L'Hiver anti-exploit scripts read this as "player ran away" and heal the monster
float dx = x-pos.x, dz = z-pos.z;
float dir = angleDir(dx,dz);
float da = float(M_PI)*(visual.viewDirection()-dir)/180.f;
auto ca = angOverride > 0 ? std::cos(angOverride*M_PI/180.0) : ref;
Expand Down