添加每科子弹后坐力和子弹消耗类型处理

This commit is contained in:
aozhiwei 2021-10-20 11:43:01 +08:00
parent 0c39aff642
commit 4b9e532e87
7 changed files with 71 additions and 11 deletions

View File

@ -429,6 +429,21 @@ enum KillTextFieldIdx
kFieldIdxWeaponTextIcon, kFieldIdxWeaponTextIcon,
}; };
enum BulletConsumeType_e
{
kBulletConsumeOne = 0,
kBulletConsumeMulti = 1,
};
enum BulletBornOffsetIdx_e
{
kBulletBornOffsetX = 0,
kBulletBornOffsetY = 1,
kBulletBornOffsetAngle = 2,
kBulletBornOffsetDelayTime = 3,
kBulletBornOffsetRecoilForce = 4,
};
const char* const PROJ_NAME_FMT = "game%d_gameserver"; const char* const PROJ_NAME_FMT = "game%d_gameserver";
const char* const PROJ_ROOT_FMT = "/data/logs/%s"; const char* const PROJ_ROOT_FMT = "/data/logs/%s";

View File

@ -25,6 +25,7 @@ struct BulletInfo
bool is_tank_skin = false; bool is_tank_skin = false;
int weapon_lv = 0; int weapon_lv = 0;
int delay_time = 0; int delay_time = 0;
int recoil_force = 0;
int invincible_buff_uniid = 0; int invincible_buff_uniid = 0;
}; };
@ -40,10 +41,24 @@ static void InternalCreateBullet(BulletInfo& bullet_info)
if (c->downed) { if (c->downed) {
return; return;
} }
if (c->GetCurrWeapon()->weapon_idx == 0) {
return;
}
if (c->GetCurrWeapon()->meta->i->bullet_consume_type() == kBulletConsumeMulti) {
if (c->GetCurrWeapon()->ammo <= 0) {
return;
}
--c->GetCurrWeapon()->ammo;
}
if (bullet_info.delay_time <= 0) { if (bullet_info.delay_time <= 0) {
int bullet_uniid = 0; int bullet_uniid = 0;
if (MetaMgr::Instance()->prebattle_can_use_skill || if (MetaMgr::Instance()->prebattle_can_use_skill ||
!(c->HasBuffEffect(kBET_Jump) || c->HasBuffEffect(kBET_Fly))) { !(c->HasBuffEffect(kBET_Jump) || c->HasBuffEffect(kBET_Fly))) {
if (bullet_info.recoil_force > 0) {
c->DoRecoilForce(bullet_info.recoil_force);
bullet_info.bullet_born_pos = bullet_info.bullet_born_pos -
(bullet_info.bullet_dir * bullet_info.recoil_force);
}
bullet_uniid = c->room->CreateBullet bullet_uniid = c->room->CreateBullet
(c, (c,
c->shot_passenger, c->shot_passenger,
@ -192,17 +207,14 @@ void InternalShot(Creature* c,
bullet_info.is_tank_skin = is_tank_skin; bullet_info.is_tank_skin = is_tank_skin;
bullet_info.weapon_lv = weapon_lv; bullet_info.weapon_lv = weapon_lv;
bullet_info.delay_time = std::get<3>(tuple); bullet_info.delay_time = std::get<3>(tuple);
bullet_info.recoil_force = std::get<4>(tuple);
bullet_info.invincible_buff_uniid = invincible_buff_uniid; bullet_info.invincible_buff_uniid = invincible_buff_uniid;
InternalCreateBullet(bullet_info); InternalCreateBullet(bullet_info);
} }
} }
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) {
a8::Vec2 old_move_dir = c->GetMoveDir(); c->DoRecoilForce(weapon_meta->i->recoil_force());
c->MustBeAddBuff(c, kRecoilBuffId);
c->SetMoveDir(c->GetAttackDir() * -1);
c->_UpdateMove(weapon_meta->i->recoil_force());
c->SetMoveDir(old_move_dir);
} }
if (c->HasBuffEffect(kBET_Hide)) { if (c->HasBuffEffect(kBET_Hide)) {
c->RemoveBuffByEffectId(kBET_Hide); c->RemoveBuffByEffectId(kBET_Hide);
@ -1674,7 +1686,8 @@ void Creature::Shot(a8::Vec2& target_dir, bool& shot_ok, float fly_distance)
abort(); abort();
} }
if (GetCurrWeapon()->weapon_idx != 0) { if (GetCurrWeapon()->weapon_idx != 0 &&
GetCurrWeapon()->meta->i->bullet_consume_type() == kBulletConsumeOne) {
--GetCurrWeapon()->ammo; --GetCurrWeapon()->ammo;
} }
int slot_id = GetCurrWeapon()->meta->i->_inventory_slot(); int slot_id = GetCurrWeapon()->meta->i->_inventory_slot();
@ -2889,3 +2902,14 @@ void Creature::FollowToTarget()
} }
} }
} }
void Creature::DoRecoilForce(int distance)
{
if (distance > 0) {
a8::Vec2 old_move_dir = GetMoveDir();
MustBeAddBuff(this, kRecoilBuffId);
SetMoveDir(GetAttackDir() * -1);
_UpdateMove(distance);
SetMoveDir(old_move_dir);
}
}

View File

@ -248,6 +248,7 @@ class Creature : public MoveableEntity
void DecDisableMoveDirTimes() { --disable_move_dir_times_ ; }; void DecDisableMoveDirTimes() { --disable_move_dir_times_ ; };
int GetDisableMoveDirTimes() { return disable_move_dir_times_ ; }; int GetDisableMoveDirTimes() { return disable_move_dir_times_ ; };
void SetDisableMoveDirTimes(int times) { disable_move_dir_times_ = times; }; void SetDisableMoveDirTimes(int times) { disable_move_dir_times_ = times; };
void DoRecoilForce(int distance);
protected: protected:
virtual void OnBuffRemove(Buff& buff); virtual void OnBuffRemove(Buff& buff);

View File

@ -256,7 +256,8 @@ namespace MetaData
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 strings2.size() > 3 ? a8::XValue(strings2[3]).GetInt() : 0,
strings2.size() > 4 ? a8::XValue(strings2[4]).GetInt() : 0
) )
); );
lock_time += strings2.size() > 3 ? a8::XValue(strings2[3]).GetInt() : 0; lock_time += strings2.size() > 3 ? a8::XValue(strings2[3]).GetInt() : 0;

View File

@ -86,7 +86,8 @@ namespace MetaData
const metatable::Equip* i = nullptr; const metatable::Equip* i = nullptr;
int lock_time = 0; int lock_time = 0;
std::vector<std::tuple<float, float, float, int>> bullet_born_offset; //0,0,0,0,后座力
std::vector<std::tuple<float, float, float, int, 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;

View File

@ -493,9 +493,18 @@ void RoomObstacle::ActiveAirDrop()
[] (const a8::XParams& param) [] (const a8::XParams& param)
{ {
RoomObstacle* obstacle = (RoomObstacle*)param.sender.GetUserData(); RoomObstacle* obstacle = (RoomObstacle*)param.sender.GetUserData();
a8::Vec2 born_pos = obstacle->GetPos();
{
MetaData::MapThing* thing_meta = MetaMgr::Instance()->GetMapThing(obstacle->meta->int_param1);
if (thing_meta && thing_meta->i->summon_born_rad() > 0) {
a8::Vec2 born_dir = a8::Vec2::UP;
born_dir.Rotate(obstacle->GetUniId());
born_pos = born_pos + born_dir * thing_meta->i->summon_born_rad();
}
}
obstacle->room->frame_event.AddAirDrop(param.param2, obstacle->room->frame_event.AddAirDrop(param.param2,
param.param3, param.param3,
obstacle->GetPos()); born_pos);
}, },
&xtimer_attacher.timer_list_ &xtimer_attacher.timer_list_
); );
@ -511,11 +520,18 @@ bool RoomObstacle::DoInteraction(Human* sender)
void RoomObstacle::SummonAirDropBox(int box_id) void RoomObstacle::SummonAirDropBox(int box_id)
{ {
a8::Vec2 born_pos = GetPos();
MetaData::MapThing* thing_meta = MetaMgr::Instance()->GetMapThing(box_id);
if (thing_meta && thing_meta->i->summon_born_rad() > 0) {
a8::Vec2 born_dir = a8::Vec2::UP;
born_dir.Rotate(GetUniId());
born_pos = born_pos + born_dir * thing_meta->i->summon_born_rad();
}
RoomObstacle* obstacle = room->CreateObstacle RoomObstacle* obstacle = room->CreateObstacle
( (
box_id, box_id,
GetPos().x, born_pos.x,
GetPos().y born_pos.y
); );
if (obstacle) { if (obstacle) {
obstacle->PushCollisionObjects(); obstacle->PushCollisionObjects();

View File

@ -74,6 +74,7 @@ message MapThing
optional string sweep_tags = 31; optional string sweep_tags = 31;
optional int32 prebattle_hide = 32; optional int32 prebattle_hide = 32;
optional int32 life_time = 33; optional int32 life_time = 33;
optional int32 summon_born_rad = 34;
} }
message SafeArea message SafeArea
@ -172,6 +173,7 @@ message Equip
optional int32 auto_switch_weapon_time = 65; optional int32 auto_switch_weapon_time = 65;
optional int32 quality = 66; optional int32 quality = 66;
optional int32 explosion_damage_delay = 67; optional int32 explosion_damage_delay = 67;
optional int32 bullet_consume_type = 68;
optional string inventory_slot = 31; // optional string inventory_slot = 31; //
optional int32 _inventory_slot = 32; // optional int32 _inventory_slot = 32; //