From b6cdee38c23b505a1d38cf09100b5f7aa52904c9 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 16 Apr 2019 17:30:28 +0800 Subject: [PATCH] 1 --- server/gameserver/human.h | 1 + server/gameserver/player.cc | 68 +++++++++++++++++--------- server/tools/protobuild/cs_proto.proto | 9 ++++ 3 files changed, 54 insertions(+), 24 deletions(-) diff --git a/server/gameserver/human.h b/server/gameserver/human.h index 9645b1e..a8f5b83 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -73,6 +73,7 @@ class Human : public Entity bool send_gameover = false; int pain_killer_frameno = 0; + int pain_killer_lastingtime = 0; xtimer_list* pain_killer_timer = nullptr; std::set* team_members = nullptr; diff --git a/server/gameserver/player.cc b/server/gameserver/player.cc index 3b942a0..e972700 100644 --- a/server/gameserver/player.cc +++ b/server/gameserver/player.cc @@ -204,31 +204,39 @@ void Player::UpdateAction() case IS_PAIN_KILLER: { MetaData::Equip* item_meta = MetaMgr::Instance()->GetEquipBySlotId(action_item_id); - if (item_meta && !pain_killer_timer){ + if (item_meta){ if (inventory[item_meta->i->_inventory_slot()] > 0) { - pain_killer_frameno = room->frame_no; - pain_killer_timer = room->xtimer.AddRepeatTimerAndAttach( - SERVER_FRAME_RATE, - a8::XParams() - .SetSender(this) - .SetParam1(item_meta->i->heal()) - .SetParam2(item_meta->i->time()) - .SetParam3(0), - [] (const a8::XParams& param) - { - Human* hum = (Human*)param.sender.GetUserData(); - float old_health = hum->health; - hum->health += param.param2.GetDouble(); - hum->health = std::min(hum->health, hum->GetMaxHP()); - hum->stats.heal_amount += hum->health - old_health; - hum->SyncAroundPlayers(); - if (hum->room->frame_no - hum->pain_killer_frameno > param.param2.GetInt() * SERVER_FRAME_RATE) { - hum->room->xtimer.DeleteTimer(hum->pain_killer_timer); - hum->pain_killer_timer = nullptr; - } - }, - &xtimer_attacher.timer_list_ - ); + if (pain_killer_timer) { + int passed_time = (room->frame_no - 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->frame_no; + 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->health; + hum->health += param.param1.GetDouble(); + hum->health = std::min(hum->health, hum->GetMaxHP()); + hum->stats.heal_amount += hum->health - old_health; + hum->SyncAroundPlayers(); + if (hum->room->frame_no - 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_ + ); + } --inventory[item_meta->i->_inventory_slot()]; need_sync_active_player = true; } @@ -859,6 +867,18 @@ void Player::FillMFActivePlayerData(cs::MFActivePlayerData* player_data) for (auto& num : inventory) { player_data->add_inventory(num); } + if (pain_killer_timer) { + int passed_time = (room->frame_no - 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); + int lasting_time = std::min(pain_killer_lastingtime * 1000, anodyne_max_time * 1000); + + cs::MFBodyState* p = player_data->add_states(); + p->set_state_type(1); + p->set_left_time(left_time); + p->set_lasting_time(lasting_time); + } } void Player::FillMFGasData(cs::MFGasData* gas_data) diff --git a/server/tools/protobuild/cs_proto.proto b/server/tools/protobuild/cs_proto.proto index 49a8cf9..c2d6100 100755 --- a/server/tools/protobuild/cs_proto.proto +++ b/server/tools/protobuild/cs_proto.proto @@ -385,6 +385,7 @@ message MFActivePlayerData repeated MFWeapon weapons = 16; //武器列表1-4 0:拳头 1:枪 2:枪 3:手雷 4:烟雾弹 optional int32 spectator_count = 20; + repeated MFBodyState states = 27; //角色状态 } //毒圈数据 @@ -508,6 +509,14 @@ message MFAirDrop optional MFVector2D pos = 3; //位置 } +//对象状态(只同步一次客户端自己到及时,有变化时服务器会再次下发) +message MFBodyState +{ + optional int32 state_type = 1; //1:止痛药持续加血 + optional float left_time = 2; //剩余时间 + optional float lasting_time = 3; //持续时间(总时间) +} + //end mfmsg //加入