This commit is contained in:
aozhiwei 2021-08-27 02:18:16 +00:00
parent 438cc7f3af
commit 8decba0470
2 changed files with 37 additions and 35 deletions

View File

@ -1199,11 +1199,7 @@ void Player::_CMExecCommand(f8::MsgHdr& hdr, const cs::CMExecCommand& msg)
} else if (cmd == "infinite_bullet_mode") {
room->SetInfiniteBulletMode();
} else if (cmd == "watchwar") {
Human* target = room->GetWatchWarTarget(this);
if (target) {
FollowTarget(target);
target->StartRefreshViewTimer();
}
AsyncRequestWatchWar(false);
} else if (cmd == "shuaguai" && cmds.size() >= 3) {
int hero_id = a8::XValue(cmds[1]);
int hero_num = a8::XValue(cmds[2]);
@ -1399,36 +1395,7 @@ void Player::_CMGameOver(f8::MsgHdr& hdr, const cs::CMGameOver& msg)
void Player::_CMWatchWar(f8::MsgHdr& hdr, const cs::CMWatchWar& msg)
{
if (watch_war_req_timer_) {
return;
}
auto cb =
[] (const a8::XParams& param) {
Player* hum = (Player*)param.sender.GetUserData();
cs::SMWatchWar respmsg;
Human* target = hum->room->GetWatchWarTarget(hum);
if (target) {
hum->SendNotifyMsg(respmsg);
hum->FollowTarget(target);
target->StartRefreshViewTimer();
} else {
respmsg.set_error_code(1);
hum->SendNotifyMsg(respmsg);
}
};
watch_war_req_timer_ = room->xtimer.AddDeadLineTimerAndAttach
(
NEXT_FRAME_TIMER,
a8::XParams()
.SetSender(this),
cb,
&xtimer_attacher.timer_list_,
[] (const a8::XParams& param)
{
Player* hum = (Player*)param.sender.GetUserData();
hum->watch_war_req_timer_ = nullptr;
});
AsyncRequestWatchWar(true);
}
void Player::_CMLeave(f8::MsgHdr& hdr, const cs::CMLeave& msg)
@ -1798,3 +1765,37 @@ void Player::SetAttackDir(const a8::Vec2& attack_dir)
{
MoveableEntity::SetAttackDir(attack_dir);
}
void Player::AsyncRequestWatchWar(bool send_rsp_msg)
{
if (watch_war_req_timer_) {
return;
}
auto cb =
[] (const a8::XParams& param) {
Player* hum = (Player*)param.sender.GetUserData();
cs::SMWatchWar respmsg;
Human* target = hum->room->GetWatchWarTarget(hum);
if (target) {
hum->SendNotifyMsg(respmsg);
hum->FollowTarget(target);
target->StartRefreshViewTimer();
} else {
respmsg.set_error_code(1);
hum->SendNotifyMsg(respmsg);
}
};
watch_war_req_timer_ = room->xtimer.AddDeadLineTimerAndAttach
(
NEXT_FRAME_TIMER,
a8::XParams()
.SetSender(this),
cb,
&xtimer_attacher.timer_list_,
[] (const a8::XParams& param)
{
Player* hum = (Player*)param.sender.GetUserData();
hum->watch_war_req_timer_ = nullptr;
});
}

View File

@ -130,6 +130,7 @@ private:
void InternalUpdate(int delta_time);
std::vector<std::tuple<int, int, int>>* GetBox(int box_id);
void CheckShotHoldState(Weapon* weapon);
void AsyncRequestWatchWar(bool send_rsp_msg);
private:
std::map<int, std::vector<std::tuple<int, int, int>>> box_hash_;