1
This commit is contained in:
parent
49537b8837
commit
b6cdee38c2
@ -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<Human*>* team_members = nullptr;
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
//加入
|
||||
|
Loading…
x
Reference in New Issue
Block a user