添加延迟子弹功能

This commit is contained in:
aozhiwei 2021-07-16 13:47:21 +08:00
parent 9d7478854f
commit 4f72b959f0
3 changed files with 93 additions and 31 deletions

View File

@ -13,6 +13,77 @@
#include "trigger.h" #include "trigger.h"
#include "car.h" #include "car.h"
struct BulletInfo
{
CreatureWeakPtr c;
MetaData::Equip* weapon_meta = nullptr;
MetaData::EquipUpgrade* weapon_upgrade_meta = nullptr;
MetaData::Equip* bullet_meta = nullptr;
a8::Vec2 bullet_born_pos;
a8::Vec2 bullet_dir;
float fly_distance = 0;
bool is_tank_skin = false;
int weapon_lv = 0;
int delay_time = 0;
};
static void InternalCreateBullet(BulletInfo& bullet_info)
{
if (!bullet_info.c.Get()) {
return;
}
if (bullet_info.delay_time <= 0) {
int bullet_uniid = 0;
Creature* c = bullet_info.c.Get();
if (c->room->BattleStarted() ||
(c->room->GetGasData().gas_mode == GasJump &&
!c->HasBuffEffect(kBET_Jump))) {
bullet_uniid = c->room->CreateBullet
(c,
c->shot_passenger,
bullet_info.weapon_meta,
bullet_info.weapon_upgrade_meta,
bullet_info.bullet_meta,
bullet_info.bullet_born_pos,
bullet_info.bullet_dir,
bullet_info.fly_distance,
bullet_info.is_tank_skin);
}
if (bullet_uniid == 0) {
bullet_uniid = c->room->AllocUniid();
}
c->room->frame_event.AddBullet
(bullet_uniid,
c->GetWeakPtrRef(),
bullet_info.weapon_meta,
bullet_info.weapon_lv,
bullet_info.bullet_born_pos,
bullet_info.bullet_dir,
bullet_info.fly_distance);
} else {
BulletInfo* info_copy = new BulletInfo();
*info_copy = bullet_info;
bullet_info.c.Get()->room->xtimer.AddDeadLineTimerAndAttach
(
bullet_info.delay_time / FRAME_RATE_MS,
a8::XParams()
.SetSender(info_copy),
[] (const a8::XParams& param)
{
BulletInfo* info_copy = (BulletInfo*)param.sender.GetUserData();
info_copy->delay_time = 0;
InternalCreateBullet(*info_copy);
},
&bullet_info.c.Get()->xtimer_attacher.timer_list_,
[] (const a8::XParams& param)
{
BulletInfo* info_copy = (BulletInfo*)param.sender.GetUserData();
delete info_copy;
}
);
}
}
void InternalShot(Creature* c, void InternalShot(Creature* c,
MetaData::Equip* weapon_meta, MetaData::Equip* weapon_meta,
MetaData::EquipUpgrade* weapon_upgrade_meta, MetaData::EquipUpgrade* weapon_upgrade_meta,
@ -60,31 +131,20 @@ void InternalShot(Creature* c,
} }
} }
bullet_dir.Rotate(bullet_angle / 180.0f); bullet_dir.Rotate(bullet_angle / 180.0f);
int bullet_uniid = 0; {
if (c->room->BattleStarted() || BulletInfo bullet_info;
(c->room->GetGasData().gas_mode == GasJump && bullet_info.c = c->GetWeakPtrRef();
!c->HasBuffEffect(kBET_Jump))) { bullet_info.weapon_meta = weapon_meta;
bullet_uniid = c->room->CreateBullet bullet_info.weapon_upgrade_meta = weapon_upgrade_meta;
(c, bullet_info.bullet_meta = bullet_meta;
c->shot_passenger, bullet_info.bullet_born_pos = bullet_born_pos;
weapon_meta, bullet_info.bullet_dir = bullet_dir;
weapon_upgrade_meta, bullet_info.fly_distance = fly_distance;
bullet_meta, bullet_info.is_tank_skin = is_tank_skin;
bullet_born_pos, bullet_info.weapon_lv = weapon_lv;
bullet_dir, bullet_info.delay_time = std::get<3>(tuple);
fly_distance, InternalCreateBullet(bullet_info);
is_tank_skin);
} }
if (bullet_uniid == 0) {
bullet_uniid = c->room->AllocUniid();
}
c->room->frame_event.AddBullet(bullet_uniid,
c->GetWeakPtrRef(),
weapon_meta,
weapon_lv,
bullet_born_pos,
bullet_dir,
fly_distance);
} }
c->GetTrigger()->Shot(weapon_meta); c->GetTrigger()->Shot(weapon_meta);
if (weapon_meta->i->recoil_force() > 0.000001) { if (weapon_meta->i->recoil_force() > 0.000001) {

View File

@ -189,10 +189,12 @@ namespace MetaData
std::vector<std::string> strings2; std::vector<std::string> strings2;
a8::Split(str, strings2, ':'); a8::Split(str, strings2, ':');
assert(strings2.size() >= 2); assert(strings2.size() >= 2);
bullet_born_offset.push_back(std::make_tuple( bullet_born_offset.push_back
(std::make_tuple(
a8::XValue(strings2[0]).GetDouble(), a8::XValue(strings2[0]).GetDouble(),
a8::XValue(strings2[1]).GetDouble(), a8::XValue(strings2[1]).GetDouble(),
strings2.size() > 2 ? a8::XValue(strings2[2]).GetDouble() : 0 strings2.size() > 2 ? a8::XValue(strings2[2]).GetDouble() : 0,
strings2.size() > 3 ? a8::XValue(strings2[3]).GetInt() : 0
) )
); );
} }

View File

@ -72,7 +72,7 @@ namespace MetaData
{ {
const metatable::Equip* i = nullptr; const metatable::Equip* i = nullptr;
std::vector<std::tuple<float, float, float>> bullet_born_offset; std::vector<std::tuple<float, float, float, int>> bullet_born_offset;
std::vector<std::tuple<int, a8::Vec2>> shoot_offsets; std::vector<std::tuple<int, a8::Vec2>> shoot_offsets;
std::array<int, IS_END> volume = {}; std::array<int, IS_END> volume = {};
int int_param1 = 0; int int_param1 = 0;