This commit is contained in:
aozhiwei 2024-01-09 11:45:54 +08:00
parent 363871a5f4
commit 02622323ac

View File

@ -1,9 +1,12 @@
#include "precompile.h"
#include <math.h>
#include "ability.h"
#include "buff.h"
#include "creature.h"
#include "netdata.h"
#include "room.h"
#include "mt/Equip.h"
#include "mt/Buff.h"
@ -143,6 +146,7 @@ bool Ability::CanImmune(const std::set<int>& tags)
AttrHandle Ability::AddAttr(int attr_id, float val)
{
float old_max_hp = owner_.Get()->GetMaxHP();
if (IsValidHumanAttr(attr_id) ||
IsValidHumanVirtualAttr(attr_id)) {
auto p = std::make_shared<AttrAddition>(attr_id, val);
@ -166,6 +170,11 @@ AttrHandle Ability::AddAttr(int attr_id, float val)
}
RecalcAttrRuduce(attr_id);
}
if (std::fabs(owner_.Get()->GetMaxHP() - old_max_hp) > 0.000001f) {
owner_.Get()->SetMaxHP(owner_.Get()->GetMaxHP());
owner_.Get()->SetHP(owner_.Get()->GetHP() * (old_max_hp / owner_.Get()->GetMaxHP()));
owner_.Get()->room->frame_event.AddHpChg(owner_);
}
return p;
}
return AttrHandle();
@ -173,6 +182,7 @@ AttrHandle Ability::AddAttr(int attr_id, float val)
void Ability::RemoveAttr(AttrHandle handle)
{
float old_max_hp = owner_.Get()->GetMaxHP();
if (!handle.expired()) {
auto p = handle.lock();
list_del_init(&p->entry);
@ -183,6 +193,11 @@ void Ability::RemoveAttr(AttrHandle handle)
RecalcAttrRuduce(p->attr_id);
}
p->holder = nullptr;
if (std::fabs(owner_.Get()->GetMaxHP() - old_max_hp) > 0.000001f) {
owner_.Get()->SetMaxHP(owner_.Get()->GetMaxHP());
owner_.Get()->SetHP(owner_.Get()->GetHP() * (old_max_hp / owner_.Get()->GetMaxHP()));
owner_.Get()->room->frame_event.AddHpChg(owner_);
}
}
}