修复 .加血道具,存在延迟
This commit is contained in:
parent
78e32712c6
commit
b3fa342e62
@ -3152,64 +3152,59 @@ void Human::ProcReloadAction()
|
||||
|
||||
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) {
|
||||
case IS_HEALTHKIT:
|
||||
{
|
||||
MetaData::Equip* item_meta = MetaMgr::Instance()->GetEquipBySlotId(action_item_id);
|
||||
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);
|
||||
need_sync_active_player = true;
|
||||
SyncAroundPlayers(__FILE__, __LINE__, __func__);
|
||||
}
|
||||
}
|
||||
AddHp(item_meta->i->heal());
|
||||
DecInventory(item_meta->i->_inventory_slot(), 1);
|
||||
}
|
||||
break;
|
||||
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) {
|
||||
int passed_time = (room->GetFrameNo() - pain_killer_frameno) * FRAME_RATE_MS;
|
||||
int left_time = std::max(0, pain_killer_lastingtime * 1000 - passed_time);
|
||||
int anodyne_max_time = MetaMgr::Instance()->GetSysParamAsInt("anodyne_max_time");
|
||||
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;
|
||||
need_sync_active_player = true;
|
||||
} else {
|
||||
pain_killer_frameno = room->GetFrameNo();
|
||||
pain_killer_lastingtime = item_meta->i->time();
|
||||
pain_killer_timer = room->xtimer.AddRepeatTimerAndAttach
|
||||
(
|
||||
SERVER_FRAME_RATE,
|
||||
a8::XParams()
|
||||
.SetSender(this)
|
||||
.SetParam1(item_meta->i->heal()),
|
||||
[] (const a8::XParams& param)
|
||||
{
|
||||
Human* hum = (Human*)param.sender.GetUserData();
|
||||
float old_health = hum->GetHP();
|
||||
hum->ability.hp += param.param1.GetDouble();
|
||||
hum->ability.hp = std::min(hum->GetHP(), hum->GetMaxHP());
|
||||
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->pain_killer_timer = nullptr;
|
||||
}
|
||||
},
|
||||
&xtimer_attacher.timer_list_
|
||||
);
|
||||
}
|
||||
DecInventory(item_meta->i->_inventory_slot(), 1);
|
||||
need_sync_active_player = true;
|
||||
if (pain_killer_timer) {
|
||||
int passed_time = (room->GetFrameNo() - pain_killer_frameno) * FRAME_RATE_MS;
|
||||
int left_time = std::max(0, pain_killer_lastingtime * 1000 - passed_time);
|
||||
int anodyne_max_time = MetaMgr::Instance()->GetSysParamAsInt("anodyne_max_time");
|
||||
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;
|
||||
} else {
|
||||
pain_killer_frameno = room->GetFrameNo();
|
||||
pain_killer_lastingtime = item_meta->i->time();
|
||||
if (pain_killer_lastingtime > 0) {
|
||||
pain_killer_timer = room->xtimer.AddRepeatTimerAndAttach
|
||||
(
|
||||
SERVER_FRAME_RATE,
|
||||
a8::XParams()
|
||||
.SetSender(this)
|
||||
.SetParam1(item_meta->i->heal()),
|
||||
[] (const a8::XParams& param)
|
||||
{
|
||||
Human* hum = (Human*)param.sender.GetUserData();
|
||||
hum->AddHp(param.param1.GetDouble());
|
||||
if (hum->room->GetFrameNo() - hum->pain_killer_frameno >
|
||||
hum->pain_killer_lastingtime * SERVER_FRAME_RATE) {
|
||||
hum->room->xtimer.DeleteTimer(hum->pain_killer_timer);
|
||||
}
|
||||
},
|
||||
&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);
|
||||
need_sync_active_player = true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -3653,3 +3648,12 @@ void Human::GMAddItem(int item_id, int item_num)
|
||||
need_sync_active_player = true;
|
||||
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__);
|
||||
}
|
||||
|
@ -246,6 +246,7 @@ class Human : public Creature
|
||||
virtual std::string GetName() override { return name;};
|
||||
void UpdateViewObjects();
|
||||
void GMAddItem(int item_id, int item_num);
|
||||
void AddHp(float hp);
|
||||
|
||||
protected:
|
||||
void _InternalUpdateMove(float speed);
|
||||
|
Loading…
x
Reference in New Issue
Block a user