添加散弹枪处理

This commit is contained in:
aozhiwei 2019-04-30 16:47:23 +08:00
parent 68d2d372d0
commit 7399c136b8
10 changed files with 30 additions and 9 deletions

View File

@ -106,6 +106,7 @@ void AndroidAI::DoMove()
void AndroidAI::DoAttack()
{
#if 0
Human* hum = (Human*)owner;
if (a8::HasBitFlag(hum->status, HS_Fly) ||
a8::HasBitFlag(hum->status, HS_Jump)) {
@ -123,4 +124,5 @@ void AndroidAI::DoAttack()
sender->Shot(shot_dir);
}
}
#endif
}

View File

@ -55,7 +55,7 @@ void FrameEvent::AddShot(Human* hum)
}
}
void FrameEvent::AddBullet(Human* hum, Vector2D born_pos, float fly_distance)
void FrameEvent::AddBullet(Human* hum, Vector2D born_pos, Vector2D dir, float fly_distance)
{
{
auto& tuple = a8::FastAppend(bullets_);
@ -65,7 +65,7 @@ void FrameEvent::AddBullet(Human* hum, Vector2D born_pos, float fly_distance)
p.set_player_id(hum->entity_uniid);
p.set_bullet_id(hum->curr_weapon->meta->i->use_bullet());
born_pos.ToPB(p.mutable_pos());
hum->attack_dir.ToPB(p.mutable_dir());
dir.ToPB(p.mutable_dir());
p.set_bulletskin(10001);
p.set_gun_id(hum->curr_weapon->meta->i->id());
p.set_fly_distance(fly_distance);

View File

@ -10,7 +10,7 @@ public:
void AddAirDrop(int appear_time, int box_id, Vector2D box_pos);
void AddEmote(Human* hum, int emote_id);
void AddShot(Human* hum);
void AddBullet(Human* hum, Vector2D born_pos, float fly_distance);
void AddBullet(Human* hum, Vector2D born_pos, Vector2D dir, float fly_distance);
void AddExplosion(Bullet* bullet, int item_id, Vector2D bomb_pos);
void AddSmoke(Bullet* bullet, int item_id, Vector2D pos);
void AddExplosionEx(Human* sender, int item_id, Vector2D bomb_pos, int effect);

View File

@ -166,7 +166,7 @@ void Human::Shot(Vector2D& target_dir)
Vector2D bullet_born_offset = Vector2D(std::get<0>(tuple), std::get<1>(tuple));
bullet_born_offset.Rotate(attack_dir.CalcAngle(Vector2D::UP));
Vector2D bullet_born_pos = pos + bullet_born_offset;
room->frame_event.AddBullet(this, bullet_born_pos, fly_distance);
room->frame_event.AddBullet(this, bullet_born_pos, attack_dir, fly_distance);
room->CreateBullet(this, curr_weapon->meta, bullet_born_pos, attack_dir, fly_distance);
}
--curr_weapon->ammo;

View File

@ -52,10 +52,11 @@ namespace MetaData
for (auto& str : strings) {
std::vector<std::string> strings2;
a8::Split(str, strings2, ':');
assert(strings2.size() == 2);
assert(strings2.size() >= 2);
bullet_born_offset.push_back(std::make_tuple(
a8::XValue(strings2[0]).GetDouble(),
a8::XValue(strings2[1]).GetDouble()
a8::XValue(strings2[1]).GetDouble(),
strings2.size() > 2 ? a8::XValue(strings2[2]).GetDouble() : 0
)
);
}

View File

@ -46,7 +46,7 @@ namespace MetaData
{
const metatable::Equip* i = nullptr;
std::vector<std::tuple<float, float>> bullet_born_offset;
std::vector<std::tuple<float, float, float>> bullet_born_offset;
std::array<int, IS_END> volume = {};
void Init();

View File

@ -447,8 +447,14 @@ void Player::Shot()
Vector2D bullet_born_offset = Vector2D(std::get<0>(tuple), std::get<1>(tuple));
bullet_born_offset.Rotate(attack_dir.CalcAngle(Vector2D::UP));
Vector2D bullet_born_pos = pos + bullet_born_offset;
room->frame_event.AddBullet(this, bullet_born_pos, fly_distance);
room->CreateBullet(this, curr_weapon->meta, bullet_born_pos, attack_dir, fly_distance);
Vector2D bullet_dir = attack_dir;
float bullet_angle = std::get<0>(tuple);
if (curr_weapon->meta->i->bullet_angle() >= 1.0f) {
bullet_angle += (rand() % (int)curr_weapon->meta->i->bullet_angle()) * (rand() % 2 == 0 ? 1 : -1);
}
bullet_dir.Rotate(bullet_angle / 180.0f);
room->frame_event.AddBullet(this, bullet_born_pos, bullet_dir, fly_distance);
room->CreateBullet(this, curr_weapon->meta, bullet_born_pos, bullet_dir, fly_distance);
}
}
if (curr_weapon->weapon_idx != 0) {

View File

@ -125,6 +125,16 @@ float Vector2D::CalcAngle(const Vector2D& b)
#endif
}
Vector2D Vector2D::FromAngle(float angle)
{
Vector2D vec2;
float hu = angle * 3.1415926f / 180.0f;
vec2.x = cos(hu);
vec2.y = sin(hu);
vec2.Normalize();
return vec2;
}
Vector2D Vector2D::Perp()
{
return Vector2D(y, -x);

View File

@ -18,6 +18,7 @@ struct Vector2D
void Normalize();
void Rotate(float angle);
float CalcAngle(const Vector2D& b);
static Vector2D FromAngle(float angle);
bool operator == (const Vector2D& b) const;
Vector2D operator + (const Vector2D& b) const;

View File

@ -75,6 +75,7 @@ message Equip
optional int32 bullet_rad = 20; //
optional int32 group_num = 21; //
optional string bullet_born_offset = 30; //
optional float bullet_angle = 34; //
optional string inventory_slot = 31; //
optional int32 _inventory_slot = 32; //