403 lines
11 KiB
C++
403 lines
11 KiB
C++
#include "precompile.h"
|
|
|
|
#include "frameevent.h"
|
|
#include "human.h"
|
|
#include "bullet.h"
|
|
#include "metamgr.h"
|
|
#include "typeconvert.h"
|
|
#include "buff.h"
|
|
#include "human.h"
|
|
#include "room.h"
|
|
|
|
void FrameEvent::AddAirDrop(int appear_time, int box_id, a8::Vec2 box_pos)
|
|
{
|
|
cs::MFAirDrop* airdrop = airdrops_.Add();
|
|
airdrop->set_appear_time(appear_time);
|
|
airdrop->set_box_id(box_id);
|
|
TypeConvert::ToPb(box_pos, airdrop->mutable_pos());
|
|
}
|
|
|
|
void FrameEvent::AddEmote(Human* sender, int emote_id)
|
|
{
|
|
{
|
|
auto& tuple = a8::FastAppend(emotes_);
|
|
std::get<0>(tuple) = sender;
|
|
auto& p = std::get<1>(tuple);
|
|
|
|
p.set_emote_id(emote_id);
|
|
p.set_player_id(sender->GetEntityUniId());
|
|
}
|
|
{
|
|
int emote_idx = emotes_.size() - 1;
|
|
sender->TouchAllLayerHumanList
|
|
(
|
|
[emote_idx] (Human* hum, bool& stop)
|
|
{
|
|
hum->emotes_.push_back(emote_idx);
|
|
});
|
|
}
|
|
}
|
|
|
|
void FrameEvent::AddShot(Creature* sender)
|
|
{
|
|
{
|
|
auto& tuple = a8::FastAppend(shots_);
|
|
std::get<0>(tuple) = sender;
|
|
auto& p = std::get<1>(tuple);
|
|
|
|
p.set_player_id(sender->GetEntityUniId());
|
|
if (sender->second_weapon.meta) {
|
|
sender->second_weapon.ToPB(p.mutable_weapon());
|
|
} else {
|
|
sender->GetCurrWeapon()->ToPB(p.mutable_weapon());
|
|
}
|
|
}
|
|
{
|
|
int shot_idx = shots_.size() - 1;
|
|
sender->TouchAllLayerHumanList
|
|
(
|
|
[shot_idx] (Human* hum, bool& stop)
|
|
{
|
|
hum->shots_.push_back(shot_idx);
|
|
});
|
|
}
|
|
}
|
|
|
|
void FrameEvent::AddBullet(Creature* sender,
|
|
MetaData::Equip* weapon_meta,
|
|
int weapon_lv,
|
|
a8::Vec2 born_pos,
|
|
a8::Vec2 dir,
|
|
float fly_distance)
|
|
{
|
|
{
|
|
auto& tuple = a8::FastAppend(bullets_);
|
|
std::get<0>(tuple) = sender;
|
|
auto& p = std::get<1>(tuple);
|
|
|
|
p.set_player_id(sender->GetEntityUniId());
|
|
p.set_bullet_id(weapon_meta->i->use_bullet());
|
|
TypeConvert::ToPb(born_pos, p.mutable_pos());
|
|
TypeConvert::ToPb(dir, p.mutable_dir());
|
|
#if 0
|
|
p.set_bulletskin(10001);
|
|
#endif
|
|
p.set_gun_id(weapon_meta->i->id());
|
|
p.set_gun_lv(weapon_lv);
|
|
p.set_fly_distance(fly_distance);
|
|
}
|
|
{
|
|
int bullet_idx = bullets_.size() - 1;
|
|
sender->TouchAllLayerHumanList
|
|
(
|
|
[bullet_idx] (Human* hum, bool& stop)
|
|
{
|
|
hum->bullets_.push_back(bullet_idx);
|
|
});
|
|
}
|
|
}
|
|
|
|
void FrameEvent::AddExplosion(Bullet* bullet, int item_id, a8::Vec2 bomb_pos)
|
|
{
|
|
AddExplosionEx(bullet->sender, item_id, bomb_pos, 0);
|
|
}
|
|
|
|
void FrameEvent::AddExplosionEx(CreatureWeakPtr& sender, int item_id, a8::Vec2 bomb_pos, int effect)
|
|
{
|
|
if (!sender.Get()) {
|
|
return;
|
|
}
|
|
{
|
|
auto& tuple = a8::FastAppend(explosions_);
|
|
std::get<0>(tuple).Attach(sender.Get());
|
|
auto& p = std::get<1>(tuple);
|
|
|
|
p.set_item_id(item_id);
|
|
TypeConvert::ToPb(bomb_pos, p.mutable_pos());
|
|
p.set_player_id(sender.Get()->GetEntityUniId());
|
|
p.set_effect(effect);
|
|
}
|
|
{
|
|
int explosion_idx = explosions_.size() - 1;
|
|
sender.Get()->TouchAllLayerHumanList
|
|
(
|
|
[explosion_idx] (Human* hum, bool& stop)
|
|
{
|
|
hum->explosions_.push_back(explosion_idx);
|
|
});
|
|
}
|
|
}
|
|
|
|
void FrameEvent::AddBulletNumChg(Human* hum)
|
|
{
|
|
chged_bullet_nums_.push_back(hum);
|
|
int idx = chged_bullet_nums_.size() - 1;
|
|
hum->chged_bullet_nums_.push_back(idx);
|
|
}
|
|
|
|
void FrameEvent::AddSmoke(Bullet* bullet, int item_id, a8::Vec2 pos)
|
|
{
|
|
if (!bullet->sender.Get()) {
|
|
return;
|
|
}
|
|
{
|
|
auto& tuple = a8::FastAppend(smokes_);
|
|
std::get<0>(tuple).Attach(bullet->sender.Get());
|
|
auto& p = std::get<1>(tuple);
|
|
|
|
p.set_item_id(item_id);
|
|
TypeConvert::ToPb(pos, p.mutable_pos());
|
|
p.set_player_id(bullet->sender.Get()->GetEntityUniId());
|
|
}
|
|
{
|
|
int idx = smokes_.size() - 1;
|
|
bullet->sender.Get()->TouchAllLayerHumanList
|
|
(
|
|
[idx] (Human* hum, bool& stop)
|
|
{
|
|
hum->smokes_.push_back(idx);
|
|
});
|
|
}
|
|
}
|
|
|
|
void FrameEvent::AddPlaySkill(CreatureWeakPtr& sender, int skill_id)
|
|
{
|
|
if (!sender.Get()) {
|
|
return;
|
|
}
|
|
{
|
|
auto& tuple = a8::FastAppend(play_skills_);
|
|
std::get<0>(tuple).Attach(sender.Get());
|
|
auto& p = std::get<1>(tuple);
|
|
p.set_obj_uniid(sender.Get()->GetEntityUniId());
|
|
p.set_skill_id(skill_id);
|
|
}
|
|
{
|
|
int idx = play_skills_.size() - 1;
|
|
sender.Get()->TouchAllLayerHumanList
|
|
(
|
|
[idx] (Human* hum, bool& stop)
|
|
{
|
|
hum->play_skills_.push_back(idx);
|
|
});
|
|
}
|
|
}
|
|
|
|
void FrameEvent::AddHpChg(Human* sender)
|
|
{
|
|
chged_hps_.push_back(sender);
|
|
int idx = chged_hps_.size() - 1;
|
|
sender->TouchAllLayerHumanList
|
|
(
|
|
[idx] (Human* hum, bool& stop)
|
|
{
|
|
hum->chged_hps_.push_back(idx);
|
|
});
|
|
}
|
|
|
|
void FrameEvent::AddWeaponAmmoChg(Human* hum)
|
|
{
|
|
if (hum->GetCurrWeapon()) {
|
|
chged_weapon_ammo_.push_back
|
|
(
|
|
std::make_tuple(hum,
|
|
hum->GetCurrWeapon()->weapon_idx,
|
|
hum->GetCurrWeapon()->ammo
|
|
)
|
|
);
|
|
int idx = chged_weapon_ammo_.size() - 1;
|
|
hum->chged_weapon_ammo_.push_back(idx);
|
|
}
|
|
}
|
|
|
|
void FrameEvent::AddBuff(Human* sender, Buff* buff)
|
|
{
|
|
{
|
|
cs::MFBuffChg chged_buff_pb;
|
|
chged_buff_pb.set_obj_id(sender->GetEntityUniId());
|
|
chged_buff_pb.set_chg(0);
|
|
buff->FillMFBuff(chged_buff_pb.mutable_buff());
|
|
chged_buffs_.push_back(std::make_tuple(sender, chged_buff_pb));
|
|
}
|
|
{
|
|
int idx = chged_buffs_.size() - 1;
|
|
sender->TouchAllLayerHumanList
|
|
(
|
|
[idx] (Human* hum, bool& stop)
|
|
{
|
|
hum->chged_buffs_.push_back(idx);
|
|
});
|
|
}
|
|
}
|
|
|
|
void FrameEvent::RemoveBuff(Human* sender, int buff_id)
|
|
{
|
|
{
|
|
cs::MFBuffChg chged_buff_pb;
|
|
chged_buff_pb.set_obj_id(sender->GetEntityUniId());
|
|
chged_buff_pb.set_chg(1);
|
|
chged_buff_pb.mutable_buff()->set_buff_id(buff_id);
|
|
chged_buffs_.push_back(std::make_tuple(sender, chged_buff_pb));
|
|
}
|
|
{
|
|
int idx = chged_buffs_.size() - 1;
|
|
sender->TouchAllLayerHumanList
|
|
(
|
|
[idx] (Human* hum, bool& stop)
|
|
{
|
|
hum->chged_buffs_.push_back(idx);
|
|
});
|
|
}
|
|
}
|
|
|
|
void FrameEvent::AddSkillCdChg(CreatureWeakPtr sender, int skill_id, int left_time)
|
|
{
|
|
if (sender.Get() && sender.Get()->IsHuman()) {
|
|
chged_skillcds_.push_back(std::make_tuple(sender, skill_id, left_time));
|
|
int idx = chged_skillcds_.size() - 1;
|
|
((Human*)sender.Get())->chged_skillcds_.push_back(idx);
|
|
}
|
|
}
|
|
|
|
void FrameEvent::AddSkillCurrTimesChg(CreatureWeakPtr sender, int skill_id, int curr_times)
|
|
{
|
|
if (sender.Get() && sender.Get()->IsHuman()) {
|
|
chged_skill_curr_times_.push_back(std::make_tuple(sender, skill_id, curr_times));
|
|
int idx = chged_skill_curr_times_.size() - 1;
|
|
((Human*)sender.Get())->chged_skill_curr_times_.push_back(idx);
|
|
}
|
|
}
|
|
|
|
void FrameEvent::AddItemChg(Human* hum, int item_id, int item_num)
|
|
{
|
|
chged_items_.push_back(std::make_tuple(hum, item_id, item_num));
|
|
int idx = chged_items_.size() - 1;
|
|
hum->chged_items_.push_back(idx);
|
|
}
|
|
|
|
void FrameEvent::AddZombieIdChg(Human* sender)
|
|
{
|
|
chged_zombieids_.push_back(sender);
|
|
int idx = chged_zombieids_.size() - 1;
|
|
{
|
|
sender->TouchAllLayerHumanList
|
|
(
|
|
[idx] (Human* hum, bool& stop)
|
|
{
|
|
hum->chged_zombieid_.push_back(idx);
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
void FrameEvent::AddDead(Human* sender, int revive_time)
|
|
{
|
|
{
|
|
dead_alive_objs_.push_back(
|
|
std::make_tuple(
|
|
sender->GetEntityUniId(),
|
|
revive_time,
|
|
0
|
|
)
|
|
);
|
|
}
|
|
{
|
|
int dead_idx = dead_alive_objs_.size() - 1;
|
|
sender->TouchAllLayerHumanList
|
|
(
|
|
[dead_idx] (Human* hum, bool& stop)
|
|
{
|
|
hum->dead_alive_objs_.push_back(dead_idx);
|
|
});
|
|
}
|
|
}
|
|
|
|
void FrameEvent::AddRevive(Human* sender)
|
|
{
|
|
{
|
|
dead_alive_objs_.push_back(
|
|
std::make_tuple(
|
|
sender->GetEntityUniId(),
|
|
0,
|
|
1
|
|
)
|
|
);
|
|
}
|
|
{
|
|
int revive_idx = dead_alive_objs_.size() - 1;
|
|
sender->TouchAllLayerHumanList
|
|
(
|
|
[revive_idx] (Human* hum, bool& stop)
|
|
{
|
|
hum->dead_alive_objs_.push_back(revive_idx);
|
|
});
|
|
}
|
|
}
|
|
|
|
void FrameEvent::AddCarChg(Human* sender)
|
|
{
|
|
chged_cars_.push_back(sender);
|
|
int idx = chged_cars_.size() - 1;
|
|
sender->TouchAllLayerHumanList
|
|
(
|
|
[idx] (Human* hum, bool& stop)
|
|
{
|
|
hum->chged_cars_.push_back(idx);
|
|
});
|
|
}
|
|
|
|
void FrameEvent::Clear()
|
|
{
|
|
if (!explosions_.empty()) {
|
|
explosions_.clear();
|
|
}
|
|
if (!smokes_.empty()) {
|
|
smokes_.clear();
|
|
}
|
|
if (!play_skills_.empty()) {
|
|
play_skills_.clear();
|
|
}
|
|
if (!emotes_.empty()) {
|
|
emotes_.clear();
|
|
}
|
|
if (!bullets_.empty()) {
|
|
bullets_.clear();
|
|
}
|
|
if (!shots_.empty()) {
|
|
shots_.clear();
|
|
}
|
|
if (airdrops_.size() > 0) {
|
|
airdrops_.Clear();
|
|
}
|
|
if (!chged_bullet_nums_.empty()) {
|
|
chged_bullet_nums_.clear();
|
|
}
|
|
if (!chged_buffs_.empty()) {
|
|
chged_buffs_.clear();
|
|
}
|
|
if (!chged_hps_.empty()) {
|
|
chged_hps_.clear();
|
|
}
|
|
if (!chged_skillcds_.empty()) {
|
|
chged_skillcds_.clear();
|
|
}
|
|
if (!chged_skill_curr_times_.empty()) {
|
|
chged_skill_curr_times_.clear();
|
|
}
|
|
if (!chged_items_.empty()) {
|
|
chged_items_.clear();
|
|
}
|
|
if (!chged_weapon_ammo_.empty()) {
|
|
chged_weapon_ammo_.clear();
|
|
}
|
|
if (!chged_zombieids_.empty()) {
|
|
chged_zombieids_.clear();
|
|
}
|
|
if (!dead_alive_objs_.empty()) {
|
|
dead_alive_objs_.clear();
|
|
}
|
|
if (!chged_cars_.empty()) {
|
|
chged_cars_.clear();
|
|
}
|
|
}
|