501 lines
14 KiB
C++
501 lines
14 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"
|
|
#include "car.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::AddAirRaid(int appear_time, const a8::Vec2& raid_pos, float raid_rad)
|
|
{
|
|
cs::MFAirRaid* airraid = airraids_.Add();
|
|
airraid->set_appear_time(appear_time);
|
|
airraid->set_rad(raid_rad);
|
|
TypeConvert::ToPb(raid_pos, airraid->mutable_pos());
|
|
}
|
|
|
|
void FrameEvent::AddEmote(CreatureWeakPtr& 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.Get()->GetUniId());
|
|
}
|
|
{
|
|
int emote_idx = emotes_.size() - 1;
|
|
sender.Get()->TraverseAllLayerHumanList
|
|
(
|
|
[emote_idx] (Human* hum, bool& stop)
|
|
{
|
|
hum->emotes_.push_back(emote_idx);
|
|
});
|
|
}
|
|
}
|
|
|
|
void FrameEvent::AddShot(CreatureWeakPtr& sender)
|
|
{
|
|
{
|
|
auto& tuple = a8::FastAppend(shots_);
|
|
std::get<0>(tuple) = sender;
|
|
auto& p = std::get<1>(tuple);
|
|
|
|
p.set_player_id(sender.Get()->GetUniId());
|
|
if (sender.Get()->second_weapon.meta) {
|
|
sender.Get()->second_weapon.ToPB(p.mutable_weapon());
|
|
} else {
|
|
sender.Get()->GetCurrWeapon()->ToPB(p.mutable_weapon());
|
|
}
|
|
if (sender.Get()->IsCar()) {
|
|
p.set_hole(sender.Get()->shot_hole);
|
|
}
|
|
}
|
|
{
|
|
int shot_idx = shots_.size() - 1;
|
|
sender.Get()->TraverseAllLayerHumanList
|
|
(
|
|
[shot_idx] (Human* hum, bool& stop)
|
|
{
|
|
hum->shots_.push_back(shot_idx);
|
|
});
|
|
}
|
|
}
|
|
|
|
void FrameEvent::AddBullet(CreatureWeakPtr& 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.Get()->GetUniId());
|
|
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.Get()->TraverseAllLayerHumanList
|
|
(
|
|
[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 0
|
|
if (!sender.Get()) {
|
|
return;
|
|
}
|
|
#endif
|
|
#if 1
|
|
Player* hum = room->GetOneAlivePlayer();
|
|
sender.Attach((Creature*)hum);
|
|
item_id = 66001;
|
|
#ifdef DEBUG
|
|
a8::XPrintf("AddExplosion pos=%d,%d effect:%d\n",
|
|
{
|
|
bomb_pos.x,
|
|
bomb_pos.y,
|
|
effect
|
|
});
|
|
#endif
|
|
#endif
|
|
{
|
|
auto& tuple = a8::FastAppend(explosions_);
|
|
if (sender.Get()) {
|
|
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());
|
|
#if 0
|
|
p.set_player_id(sender.Get()->GetUniId());
|
|
#endif
|
|
p.set_effect(effect);
|
|
}
|
|
{
|
|
std::set<GridCell*> grid_list;
|
|
room->grid_service->GetAllCellsByXy
|
|
(
|
|
room,
|
|
bomb_pos.x,
|
|
bomb_pos.y,
|
|
grid_list
|
|
);
|
|
|
|
int explosion_idx = explosions_.size() - 1;
|
|
room->grid_service->TraverseAllLayerHumanList
|
|
(
|
|
room->GetRoomIdx(),
|
|
grid_list,
|
|
[explosion_idx] (Human* hum, bool& stop)
|
|
{
|
|
hum->explosions_.push_back(explosion_idx);
|
|
});
|
|
}
|
|
}
|
|
|
|
void FrameEvent::AddBulletNumChg(CreatureWeakPtr& sender)
|
|
{
|
|
chged_bullet_nums_.push_back(sender);
|
|
int idx = chged_bullet_nums_.size() - 1;
|
|
if (sender.Get()->IsHuman()) {
|
|
sender.Get()->AsHuman()->chged_bullet_nums_.push_back(idx);
|
|
} else {
|
|
sender.Get()->TraverseAllLayerHumanList
|
|
(
|
|
[idx] (Human* hum, bool& stop)
|
|
{
|
|
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()->GetUniId());
|
|
}
|
|
{
|
|
int idx = smokes_.size() - 1;
|
|
bullet->sender.Get()->TraverseAllLayerHumanList
|
|
(
|
|
[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()->GetUniId());
|
|
p.set_skill_id(skill_id);
|
|
}
|
|
{
|
|
int idx = play_skills_.size() - 1;
|
|
sender.Get()->TraverseAllLayerHumanList
|
|
(
|
|
[idx] (Human* hum, bool& stop)
|
|
{
|
|
hum->play_skills_.push_back(idx);
|
|
});
|
|
}
|
|
}
|
|
|
|
void FrameEvent::AddHpChg(CreatureWeakPtr& sender)
|
|
{
|
|
chged_hps_.push_back(sender);
|
|
int idx = chged_hps_.size() - 1;
|
|
sender.Get()->TraverseAllLayerHumanList
|
|
(
|
|
[idx] (Human* hum, bool& stop)
|
|
{
|
|
hum->chged_hps_.push_back(idx);
|
|
});
|
|
}
|
|
|
|
void FrameEvent::AddWeaponAmmoChg(CreatureWeakPtr& sender)
|
|
{
|
|
if (sender.Get()->GetCurrWeapon()) {
|
|
chged_weapon_ammo_.push_back
|
|
(
|
|
std::make_tuple(sender,
|
|
sender.Get()->GetCurrWeapon()->weapon_idx,
|
|
sender.Get()->GetCurrWeapon()->ammo
|
|
)
|
|
);
|
|
int idx = chged_weapon_ammo_.size() - 1;
|
|
if (sender.Get()->IsHuman()) {
|
|
sender.Get()->AsHuman()->chged_weapon_ammo_.push_back(idx);
|
|
} else {
|
|
sender.Get()->TraverseAllLayerHumanList
|
|
(
|
|
[idx] (Human* hum, bool& stop)
|
|
{
|
|
hum->chged_weapon_ammo_.push_back(idx);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
void FrameEvent::AddBuff(CreatureWeakPtr& sender, Buff* buff)
|
|
{
|
|
{
|
|
cs::MFBuffChg chged_buff_pb;
|
|
chged_buff_pb.set_obj_id(sender.Get()->GetUniId());
|
|
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.Get()->TraverseAllLayerHumanList
|
|
(
|
|
[idx] (Human* hum, bool& stop)
|
|
{
|
|
hum->chged_buffs_.push_back(idx);
|
|
});
|
|
}
|
|
}
|
|
|
|
void FrameEvent::RemoveBuff(CreatureWeakPtr& sender, int buff_id)
|
|
{
|
|
{
|
|
cs::MFBuffChg chged_buff_pb;
|
|
chged_buff_pb.set_obj_id(sender.Get()->GetUniId());
|
|
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.Get()->TraverseAllLayerHumanList
|
|
(
|
|
[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(CreatureWeakPtr& sender, int item_id, int item_num)
|
|
{
|
|
if (sender.Get()->IsHuman()) {
|
|
chged_items_.push_back(std::make_tuple(sender, item_id, item_num));
|
|
int idx = chged_items_.size() - 1;
|
|
((Human*)sender.Get())->chged_items_.push_back(idx);
|
|
}
|
|
}
|
|
|
|
void FrameEvent::AddZombieIdChg(CreatureWeakPtr& sender)
|
|
{
|
|
chged_zombieids_.push_back(sender);
|
|
int idx = chged_zombieids_.size() - 1;
|
|
{
|
|
sender.Get()->TraverseAllLayerHumanList
|
|
(
|
|
[idx] (Human* hum, bool& stop)
|
|
{
|
|
hum->chged_zombieid_.push_back(idx);
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
void FrameEvent::AddDead(CreatureWeakPtr& sender, int revive_time)
|
|
{
|
|
if (sender.Get()) {
|
|
{
|
|
dead_alive_objs_.push_back(
|
|
std::make_tuple(
|
|
sender.Get()->GetUniId(),
|
|
revive_time,
|
|
0
|
|
)
|
|
);
|
|
}
|
|
{
|
|
int dead_idx = dead_alive_objs_.size() - 1;
|
|
sender.Get()->TraverseAllLayerHumanList
|
|
(
|
|
[dead_idx] (Human* hum, bool& stop)
|
|
{
|
|
hum->dead_alive_objs_.push_back(dead_idx);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
void FrameEvent::AddRevive(CreatureWeakPtr& sender)
|
|
{
|
|
if (sender.Get()) {
|
|
{
|
|
dead_alive_objs_.push_back(
|
|
std::make_tuple(
|
|
sender.Get()->GetUniId(),
|
|
0,
|
|
1
|
|
)
|
|
);
|
|
}
|
|
{
|
|
int revive_idx = dead_alive_objs_.size() - 1;
|
|
sender.Get()->TraverseAllLayerHumanList
|
|
(
|
|
[revive_idx] (Human* hum, bool& stop)
|
|
{
|
|
hum->dead_alive_objs_.push_back(revive_idx);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
void FrameEvent::AddCarChg(CreatureWeakPtr& sender)
|
|
{
|
|
chged_cars_.push_back(sender);
|
|
int idx = chged_cars_.size() - 1;
|
|
sender.Get()->TraverseAllLayerHumanList
|
|
(
|
|
[idx] (Human* hum, bool& stop)
|
|
{
|
|
hum->chged_cars_.push_back(idx);
|
|
});
|
|
}
|
|
|
|
void FrameEvent::AddPropChg(CreatureWeakPtr& sender, int type, int subtype, float value, bool only_self)
|
|
{
|
|
if (!sender.Get()) {
|
|
return;
|
|
}
|
|
auto& p = a8::FastAppend(chged_props_);
|
|
std::get<0>(p) = sender;
|
|
std::get<1>(p).set_obj_id(sender.Get()->GetUniId());
|
|
std::get<1>(p).set_property_type(type);
|
|
std::get<1>(p).set_property_subtype(subtype);
|
|
std::get<1>(p).set_value(value);
|
|
int idx = chged_props_.size() - 1;
|
|
if (only_self) {
|
|
if (sender.Get()->IsHuman()) {
|
|
sender.Get()->AsHuman()->chged_props_.push_back(idx);
|
|
}
|
|
} else {
|
|
sender.Get()->TraverseAllLayerHumanList
|
|
(
|
|
[idx] (Human* hum, bool& stop)
|
|
{
|
|
hum->chged_props_.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 (airraids_.size() > 0) {
|
|
airraids_.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();
|
|
}
|
|
if (!chged_props_.empty()) {
|
|
chged_props_.clear();
|
|
}
|
|
}
|