添加在水中恢复氧气功能

This commit is contained in:
aozhiwei 2021-10-21 19:28:04 +08:00
parent caa9b70671
commit 9ec6455b7c
7 changed files with 69 additions and 10 deletions

View File

@ -746,15 +746,6 @@ void Buff::CalcPassengerShotOffset()
void Buff::ProcDive()
{
if (owner->IsHuman()) {
owner->AsHuman()->SetOxygen(MetaMgr::Instance()->dive_oxygen_total);
owner->AsHuman()->room->frame_event.AddPropChg
(owner->AsHuman()->GetWeakPtrRef(),
kPropDive,
MetaMgr::Instance()->dive_oxygen_total,
owner->AsHuman()->GetOxygen(),
true);
}
owner->room->xtimer.AddRepeatTimerAndAttach
(
SERVER_FRAME_RATE,
@ -792,3 +783,50 @@ void Buff::ProcRemoveDive()
owner->AsHuman()->SetOxygen(0);
}
}
void Buff::ProcInWater()
{
if (owner->IsHuman()) {
owner->AsHuman()->SetOxygen(MetaMgr::Instance()->dive_oxygen_total);
owner->AsHuman()->room->frame_event.AddPropChg
(owner->AsHuman()->GetWeakPtrRef(),
kPropDive,
MetaMgr::Instance()->dive_oxygen_total,
owner->AsHuman()->GetOxygen(),
true);
if (owner->IsPlayer()) {
owner->room->xtimer.AddRepeatTimerAndAttach
(
SERVER_FRAME_RATE,
a8::XParams()
.SetSender(this),
[] (const a8::XParams& param)
{
Buff* buff = (Buff*)param.sender.GetUserData();
if (buff->owner->dead || !buff->owner->IsHuman()) {
return;
}
Human* hum = buff->owner->AsHuman();
if (hum->GetOxygen() < MetaMgr::Instance()->dive_oxygen_total) {
hum->AddOxygen(MetaMgr::Instance()->inwater_oxygen_recover);
hum->room->frame_event.AddPropChg(hum->GetWeakPtrRef(),
kPropDive,
MetaMgr::Instance()->dive_oxygen_total,
hum->GetOxygen(),
true);
return;
}
},
&xtimer_attacher.timer_list_
);
}
}
}
void Buff::ProcRemoveInWater()
{
if (owner->IsHuman()) {
owner->AsHuman()->SetOxygen(0);
}
}

View File

@ -75,6 +75,8 @@ class Buff
void ProcDisperse();
void ProcDive();
void ProcRemoveDive();
void ProcInWater();
void ProcRemoveInWater();
void CalcPassengerShotOffset();

View File

@ -1391,6 +1391,11 @@ void Creature::ProcBuffEffect(Creature* caster, Buff* buff)
buff->ProcDive();
}
break;
case kBET_InWater:
{
buff->ProcInWater();
}
break;
default:
{
}

View File

@ -1187,7 +1187,7 @@ void Human::FillMFActivePlayerData(cs::MFActivePlayerData* player_data)
player_data->set_max_health(GetMaxHP());
player_data->set_cur_weapon_idx(GetCurrWeapon()->weapon_idx);
player_data->set_cur_scope(curr_scope_idx);
if (HasBuffEffect(kBET_Dive)) {
if (HasBuffEffect(kBET_InWater)) {
player_data->set_dive_oxygen_max(MetaMgr::Instance()->dive_oxygen_total);
player_data->set_dive_oxygen_curr(oxygen_);
}
@ -2887,6 +2887,11 @@ void Human::OnBuffRemove(Buff& buff)
buff.ProcRemoveDive();
}
break;
case kBET_InWater:
{
buff.ProcRemoveInWater();
}
break;
case kBET_AddInventory:
{
for (int slot : buff.meta->param2_int_list) {
@ -3860,6 +3865,12 @@ void Human::TraverseObservers(std::function<void (Human*, bool&)> func)
}
}
void Human::AddOxygen(int val)
{
oxygen_ += val;
oxygen_ = std::min(MetaMgr::Instance()->dive_oxygen_total, oxygen_);
}
void Human::DecOxygen(int val)
{
oxygen_ -= val;

View File

@ -269,6 +269,7 @@ class Human : public Creature
FrameData& GetFrameData() { return framedata_; };
int GetOxygen() { return oxygen_; };
void SetOxygen(int oxygen) { oxygen_ = oxygen; };
void AddOxygen(int val);
void DecOxygen(int val);
protected:

View File

@ -519,6 +519,7 @@ public:
METAMGR_READ(dive_oxygen_consume, 20);
METAMGR_READ(dive_hp_consume, 20);
METAMGR_READ(dive_explosion_dmg_switch, 0);
METAMGR_READ(inwater_oxygen_recover, 20);
}
if (MetaMgr::Instance()->K < 0.01f) {
abort();

View File

@ -188,6 +188,7 @@ class MetaMgr : public a8::Singleton<MetaMgr>
int dive_oxygen_consume = 0;
int dive_hp_consume = 0;
int dive_explosion_dmg_switch = 0;
int inwater_oxygen_recover = 0;
private:
MetaDataLoader* loader_ = nullptr;