修复 .加血道具,存在延迟

This commit is contained in:
aozhiwei 2021-05-13 15:53:35 +08:00
parent 78e32712c6
commit b3fa342e62
2 changed files with 54 additions and 49 deletions

View File

@ -3152,38 +3152,33 @@ void Human::ProcReloadAction()
void Human::ProcUseItemAction() void Human::ProcUseItemAction()
{ {
MetaData::Equip* item_meta = MetaMgr::Instance()->GetEquipBySlotId(action_item_id);
if (!item_meta) {
return;
}
if (GetInventory(item_meta->i->_inventory_slot()) <= 0) {
return;
}
switch (action_item_id) { switch (action_item_id) {
case IS_HEALTHKIT: case IS_HEALTHKIT:
{ {
MetaData::Equip* item_meta = MetaMgr::Instance()->GetEquipBySlotId(action_item_id); AddHp(item_meta->i->heal());
if (item_meta){
if (GetInventory(item_meta->i->_inventory_slot()) > 0) {
float old_health = GetHP();
ability.hp += item_meta->i->heal();
ability.hp = std::min(GetHP(), GetMaxHP());
stats.heal_amount += GetHP() - old_health;
DecInventory(item_meta->i->_inventory_slot(), 1); DecInventory(item_meta->i->_inventory_slot(), 1);
need_sync_active_player = true;
SyncAroundPlayers(__FILE__, __LINE__, __func__);
}
}
} }
break; break;
case IS_PAIN_KILLER: case IS_PAIN_KILLER:
{ {
MetaData::Equip* item_meta = MetaMgr::Instance()->GetEquipBySlotId(action_item_id);
if (item_meta){
if (GetInventory(item_meta->i->_inventory_slot()) > 0) {
if (pain_killer_timer) { if (pain_killer_timer) {
int passed_time = (room->GetFrameNo() - pain_killer_frameno) * FRAME_RATE_MS; int passed_time = (room->GetFrameNo() - pain_killer_frameno) * FRAME_RATE_MS;
int left_time = std::max(0, pain_killer_lastingtime * 1000 - passed_time); int left_time = std::max(0, pain_killer_lastingtime * 1000 - passed_time);
int anodyne_max_time = MetaMgr::Instance()->GetSysParamAsInt("anodyne_max_time"); int anodyne_max_time = MetaMgr::Instance()->GetSysParamAsInt("anodyne_max_time");
left_time = std::min(left_time, anodyne_max_time * 1000); left_time = std::min(left_time, anodyne_max_time * 1000);
pain_killer_lastingtime += std::min(item_meta->i->time() * 1000, anodyne_max_time * 1000 - left_time) / 1000; pain_killer_lastingtime += std::min(item_meta->i->time() * 1000,
need_sync_active_player = true; anodyne_max_time * 1000 - left_time) / 1000;
} else { } else {
pain_killer_frameno = room->GetFrameNo(); pain_killer_frameno = room->GetFrameNo();
pain_killer_lastingtime = item_meta->i->time(); pain_killer_lastingtime = item_meta->i->time();
if (pain_killer_lastingtime > 0) {
pain_killer_timer = room->xtimer.AddRepeatTimerAndAttach pain_killer_timer = room->xtimer.AddRepeatTimerAndAttach
( (
SERVER_FRAME_RATE, SERVER_FRAME_RATE,
@ -3193,24 +3188,24 @@ void Human::ProcUseItemAction()
[] (const a8::XParams& param) [] (const a8::XParams& param)
{ {
Human* hum = (Human*)param.sender.GetUserData(); Human* hum = (Human*)param.sender.GetUserData();
float old_health = hum->GetHP(); hum->AddHp(param.param1.GetDouble());
hum->ability.hp += param.param1.GetDouble(); if (hum->room->GetFrameNo() - hum->pain_killer_frameno >
hum->ability.hp = std::min(hum->GetHP(), hum->GetMaxHP()); hum->pain_killer_lastingtime * SERVER_FRAME_RATE) {
hum->stats.heal_amount += hum->GetHP() - old_health;
hum->SyncAroundPlayers(__FILE__, __LINE__, __func__);
if (hum->room->GetFrameNo() - hum->pain_killer_frameno > hum->pain_killer_lastingtime * SERVER_FRAME_RATE) {
hum->room->xtimer.DeleteTimer(hum->pain_killer_timer); hum->room->xtimer.DeleteTimer(hum->pain_killer_timer);
hum->pain_killer_timer = nullptr;
} }
}, },
&xtimer_attacher.timer_list_ &xtimer_attacher.timer_list_,
); [] (const a8::XParams& param)
{
Human* hum = (Human*)param.sender.GetUserData();
hum->pain_killer_timer = nullptr;
});
}
AddHp(item_meta->i->heal());
} }
DecInventory(item_meta->i->_inventory_slot(), 1); DecInventory(item_meta->i->_inventory_slot(), 1);
need_sync_active_player = true; need_sync_active_player = true;
} }
}
}
break; break;
default: default:
{ {
@ -3653,3 +3648,12 @@ void Human::GMAddItem(int item_id, int item_num)
need_sync_active_player = true; need_sync_active_player = true;
SyncAroundPlayers(__FILE__, __LINE__, __func__); SyncAroundPlayers(__FILE__, __LINE__, __func__);
} }
void Human::AddHp(float hp)
{
float old_health = GetHP();
ability.hp += hp;
ability.hp = std::min(GetHP(), GetMaxHP());
stats.heal_amount += GetHP() - old_health;
SyncAroundPlayers(__FILE__, __LINE__, __func__);
}

View File

@ -246,6 +246,7 @@ class Human : public Creature
virtual std::string GetName() override { return name;}; virtual std::string GetName() override { return name;};
void UpdateViewObjects(); void UpdateViewObjects();
void GMAddItem(int item_id, int item_num); void GMAddItem(int item_id, int item_num);
void AddHp(float hp);
protected: protected:
void _InternalUpdateMove(float speed); void _InternalUpdateMove(float speed);