修复 .加血道具,存在延迟
This commit is contained in:
parent
78e32712c6
commit
b3fa342e62
@ -3152,64 +3152,59 @@ 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){
|
DecInventory(item_meta->i->_inventory_slot(), 1);
|
||||||
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__);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case IS_PAIN_KILLER:
|
case IS_PAIN_KILLER:
|
||||||
{
|
{
|
||||||
MetaData::Equip* item_meta = MetaMgr::Instance()->GetEquipBySlotId(action_item_id);
|
if (pain_killer_timer) {
|
||||||
if (item_meta){
|
int passed_time = (room->GetFrameNo() - pain_killer_frameno) * FRAME_RATE_MS;
|
||||||
if (GetInventory(item_meta->i->_inventory_slot()) > 0) {
|
int left_time = std::max(0, pain_killer_lastingtime * 1000 - passed_time);
|
||||||
if (pain_killer_timer) {
|
int anodyne_max_time = MetaMgr::Instance()->GetSysParamAsInt("anodyne_max_time");
|
||||||
int passed_time = (room->GetFrameNo() - pain_killer_frameno) * FRAME_RATE_MS;
|
left_time = std::min(left_time, anodyne_max_time * 1000);
|
||||||
int left_time = std::max(0, pain_killer_lastingtime * 1000 - passed_time);
|
pain_killer_lastingtime += std::min(item_meta->i->time() * 1000,
|
||||||
int anodyne_max_time = MetaMgr::Instance()->GetSysParamAsInt("anodyne_max_time");
|
anodyne_max_time * 1000 - left_time) / 1000;
|
||||||
left_time = std::min(left_time, anodyne_max_time * 1000);
|
} else {
|
||||||
pain_killer_lastingtime += std::min(item_meta->i->time() * 1000, anodyne_max_time * 1000 - left_time) / 1000;
|
pain_killer_frameno = room->GetFrameNo();
|
||||||
need_sync_active_player = true;
|
pain_killer_lastingtime = item_meta->i->time();
|
||||||
} else {
|
if (pain_killer_lastingtime > 0) {
|
||||||
pain_killer_frameno = room->GetFrameNo();
|
pain_killer_timer = room->xtimer.AddRepeatTimerAndAttach
|
||||||
pain_killer_lastingtime = item_meta->i->time();
|
(
|
||||||
pain_killer_timer = room->xtimer.AddRepeatTimerAndAttach
|
SERVER_FRAME_RATE,
|
||||||
(
|
a8::XParams()
|
||||||
SERVER_FRAME_RATE,
|
.SetSender(this)
|
||||||
a8::XParams()
|
.SetParam1(item_meta->i->heal()),
|
||||||
.SetSender(this)
|
[] (const a8::XParams& param)
|
||||||
.SetParam1(item_meta->i->heal()),
|
{
|
||||||
[] (const a8::XParams& param)
|
Human* hum = (Human*)param.sender.GetUserData();
|
||||||
{
|
hum->AddHp(param.param1.GetDouble());
|
||||||
Human* hum = (Human*)param.sender.GetUserData();
|
if (hum->room->GetFrameNo() - hum->pain_killer_frameno >
|
||||||
float old_health = hum->GetHP();
|
hum->pain_killer_lastingtime * SERVER_FRAME_RATE) {
|
||||||
hum->ability.hp += param.param1.GetDouble();
|
hum->room->xtimer.DeleteTimer(hum->pain_killer_timer);
|
||||||
hum->ability.hp = std::min(hum->GetHP(), hum->GetMaxHP());
|
}
|
||||||
hum->stats.heal_amount += hum->GetHP() - old_health;
|
},
|
||||||
hum->SyncAroundPlayers(__FILE__, __LINE__, __func__);
|
&xtimer_attacher.timer_list_,
|
||||||
if (hum->room->GetFrameNo() - hum->pain_killer_frameno > hum->pain_killer_lastingtime * SERVER_FRAME_RATE) {
|
[] (const a8::XParams& param)
|
||||||
hum->room->xtimer.DeleteTimer(hum->pain_killer_timer);
|
{
|
||||||
hum->pain_killer_timer = nullptr;
|
Human* hum = (Human*)param.sender.GetUserData();
|
||||||
}
|
hum->pain_killer_timer = nullptr;
|
||||||
},
|
});
|
||||||
&xtimer_attacher.timer_list_
|
|
||||||
);
|
|
||||||
}
|
|
||||||
DecInventory(item_meta->i->_inventory_slot(), 1);
|
|
||||||
need_sync_active_player = true;
|
|
||||||
}
|
}
|
||||||
|
AddHp(item_meta->i->heal());
|
||||||
}
|
}
|
||||||
|
DecInventory(item_meta->i->_inventory_slot(), 1);
|
||||||
|
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__);
|
||||||
|
}
|
||||||
|
@ -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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user