watchwar ok

This commit is contained in:
aozhiwei 2021-08-26 19:42:29 +08:00
parent 97ee3ee957
commit a379893fe5
6 changed files with 66 additions and 21 deletions

View File

@ -3277,22 +3277,7 @@ void Human::OnLand()
MustBeAddBuff(this, kBeRecycleBuffId); MustBeAddBuff(this, kBeRecycleBuffId);
} }
if (IsPlayer()) { if (IsPlayer()) {
refresh_view_timer_ = room->xtimer.AddRepeatTimerAndAttach StartRefreshViewTimer();
(
SERVER_FRAME_RATE * MetaMgr::Instance()->refresh_view_time,
a8::XParams()
.SetSender(this),
[] (const a8::XParams& param)
{
Human* hum = (Human*)param.sender.GetUserData();
hum->UpdateViewObjects();
},
&xtimer_attacher.timer_list_,
[] (const a8::XParams& param)
{
Human* hum = (Human*)param.sender.GetUserData();
hum->refresh_view_timer_ = nullptr;
});
} }
if (CheckCollision()) { if (CheckCollision()) {
a8::Vec2 old_pos = GetPos(); a8::Vec2 old_pos = GetPos();
@ -3880,3 +3865,26 @@ Weapon* Human::TakeonWeapon(MetaData::Equip* equip_meta)
} }
return weapon; return weapon;
} }
void Human::StartRefreshViewTimer()
{
if (refresh_view_timer_) {
return;
}
refresh_view_timer_ = room->xtimer.AddRepeatTimerAndAttach
(
SERVER_FRAME_RATE * MetaMgr::Instance()->refresh_view_time,
a8::XParams()
.SetSender(this),
[] (const a8::XParams& param)
{
Human* hum = (Human*)param.sender.GetUserData();
hum->UpdateViewObjects();
},
&xtimer_attacher.timer_list_,
[] (const a8::XParams& param)
{
Human* hum = (Human*)param.sender.GetUserData();
hum->refresh_view_timer_ = nullptr;
});
}

View File

@ -283,6 +283,7 @@ class Human : public Creature
void UpdateViewObjects(); void UpdateViewObjects();
void GMAddItem(int item_id, int item_num); void GMAddItem(int item_id, int item_num);
void ProcUseItem(int item_id); void ProcUseItem(int item_id);
void StartRefreshViewTimer();
protected: protected:
void _InternalUpdateMove(float speed); void _InternalUpdateMove(float speed);

View File

@ -128,22 +128,22 @@ void Incubator::RecycleAndroid(Human* hum)
bool Incubator::CanSee(Human* hum, Human* exclude_hum) bool Incubator::CanSee(Human* hum, Human* exclude_hum)
{ {
Human* target = hum; Human* target = hum;
bool can_set = true; bool can_see = true;
room->TraverseAlivePlayers room->TraverseAlivePlayers
( (
a8::XParams(), a8::XParams(),
[target, exclude_hum, &can_set] (Human* hum, a8::XParams& param) -> bool [target, exclude_hum, &can_see] (Human* hum, a8::XParams& param) -> bool
{ {
if (hum != exclude_hum) { if (hum != exclude_hum) {
if (target->GetPos().ManhattanDistance(hum->GetPos()) < if (target->GetPos().ManhattanDistance(hum->GetPos()) <
MetaMgr::Instance()->incubator_canset_distance) { MetaMgr::Instance()->incubator_canset_distance) {
can_set = false; can_see = false;
return false; return false;
} }
} }
return true; return true;
}); });
return can_set; return can_see;
} }
void Incubator::AutoAllocAndroid() void Incubator::AutoAllocAndroid()

View File

@ -1198,6 +1198,12 @@ void Player::_CMExecCommand(f8::MsgHdr& hdr, const cs::CMExecCommand& msg)
GMAddItem(item_id, item_num); GMAddItem(item_id, item_num);
} else if (cmd == "infinite_bullet_mode") { } else if (cmd == "infinite_bullet_mode") {
room->SetInfiniteBulletMode(); room->SetInfiniteBulletMode();
} else if (cmd == "watchwar") {
Human* target = room->GetWatchWarTarget(hum);
if (target) {
FollowTarget(target);
target->StartRefreshViewTimer();
}
} else if (cmd == "shuaguai" && cmds.size() >= 3) { } else if (cmd == "shuaguai" && cmds.size() >= 3) {
int hero_id = a8::XValue(cmds[1]); int hero_id = a8::XValue(cmds[1]);
int hero_num = a8::XValue(cmds[2]); int hero_num = a8::XValue(cmds[2]);
@ -1405,6 +1411,7 @@ void Player::_CMWatchWar(f8::MsgHdr& hdr, const cs::CMWatchWar& msg)
if (target) { if (target) {
hum->SendNotifyMsg(respmsg); hum->SendNotifyMsg(respmsg);
hum->FollowTarget(target); hum->FollowTarget(target);
target->StartRefreshViewTimer();
} else { } else {
respmsg.set_error_code(1); respmsg.set_error_code(1);
hum->SendNotifyMsg(respmsg); hum->SendNotifyMsg(respmsg);

View File

@ -2847,7 +2847,7 @@ void Room::CheckAutoDie(Human* target,
&target->xtimer_attacher.timer_list_); &target->xtimer_attacher.timer_list_);
} else { } else {
std::vector<Human*> alive_humans; std::vector<Human*> alive_humans;
GetAliveHumans(alive_humans, 5, target); GetCanAutoDieHumans(alive_humans, 5, target);
if (!alive_humans.empty()) { if (!alive_humans.empty()) {
Human* killer = alive_humans[rand() % alive_humans.size()]; Human* killer = alive_humans[rand() % alive_humans.size()];
a8::UnSetBitFlag(target->status, CS_Disable); a8::UnSetBitFlag(target->status, CS_Disable);
@ -3023,6 +3023,34 @@ void Room::GetAliveHumans(std::vector<Human*>& alive_humans, size_t num, Human*
} }
} }
void Room::GetCanAutoDieHumans(std::vector<Human*>& alive_humans, size_t num, Human* exclude_hum)
{
alive_humans.reserve(num);
{
if (GetFrameNo() % 8 < 5) {
for (auto itr = human_hash_.begin(); itr != human_hash_.end(); ++itr) {
if (itr->second == exclude_hum) {
continue;
}
CheckAliveHuman(itr->second, alive_humans);
if (alive_humans.size() > num) {
break;
}
}
} else {
for (auto itr = human_hash_.rbegin(); itr != human_hash_.rend(); ++itr) {
if (itr->second == exclude_hum) {
continue;
}
CheckAliveHuman(itr->second, alive_humans);
if (alive_humans.size() > num) {
break;
}
}
}
}
}
void Room::CheckAliveHuman(Human* hum, std::vector<Human*>& alive_humans) void Room::CheckAliveHuman(Human* hum, std::vector<Human*>& alive_humans)
{ {
if (hum->IsAndroid() && if (hum->IsAndroid() &&

View File

@ -270,6 +270,7 @@ private:
void OnHumanGridChg(Human* target); void OnHumanGridChg(Human* target);
void ShuaGridRound(Human* target); void ShuaGridRound(Human* target);
void GetAliveHumans(std::vector<Human*>& alive_humans, size_t num, Human* exclude_hum); void GetAliveHumans(std::vector<Human*>& alive_humans, size_t num, Human* exclude_hum);
void GetCanAutoDieHumans(std::vector<Human*>& alive_humans, size_t num, Human* exclude_hum);
void CheckAliveHuman(Human* hum, std::vector<Human*>& alive_humans); void CheckAliveHuman(Human* hum, std::vector<Human*>& alive_humans);
a8::Vec2 GetDefaultBornPoint(); a8::Vec2 GetDefaultBornPoint();