This commit is contained in:
aozhiwei 2019-04-12 11:26:48 +08:00
parent e658c5018d
commit c7a15819a9
5 changed files with 86 additions and 18 deletions

View File

@ -117,6 +117,16 @@ void Human::Shot(Vector2D& target_dir)
if (!curr_weapon->meta) {
return;
}
if (curr_weapon->weapon_idx != 0 &&
curr_weapon->ammo <= 0) {
AutoLoadingBullet();
return;
}
#if 1
float fly_distance = 5;
#endif
{
::google::protobuf::RepeatedPtrField<::cs::MFShot>* shots = nullptr;
{
@ -136,27 +146,81 @@ void Human::Shot(Vector2D& target_dir)
shot->set_offhand(true);
shot->set_bullskin(10001);
}
::google::protobuf::RepeatedPtrField<::cs::MFBullet>* bullets = nullptr;
{
for (auto& tuple : curr_weapon->meta->bullet_born_offset) {
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;
::google::protobuf::RepeatedPtrField<::cs::MFBullet>* bullets = nullptr;
{
auto itr = room->frame_data.bullets_hash.find(room->frame_no);
if (itr == room->frame_data.bullets_hash.end()) {
room->frame_data.bullets_hash[room->frame_no] = ::google::protobuf::RepeatedPtrField<::cs::MFBullet>();
itr = room->frame_data.bullets_hash.find(room->frame_no);
{
auto itr = room->frame_data.bullets_hash.find(room->frame_no);
if (itr == room->frame_data.bullets_hash.end()) {
room->frame_data.bullets_hash[room->frame_no] = ::google::protobuf::RepeatedPtrField<::cs::MFBullet>();
itr = room->frame_data.bullets_hash.find(room->frame_no);
}
bullets = &itr->second;
}
bullets = &itr->second;
}
{
cs::MFBullet* bullet = bullets->Add();
bullet->set_player_id(entity_uniid);
bullet->set_bullet_id(curr_weapon->meta->i->use_bullet());
bullet_born_pos.ToPB(bullet->mutable_pos());
attack_dir.ToPB(bullet->mutable_dir());
bullet->set_bulletskin(10001);
bullet->set_gun_id(curr_weapon->meta->i->id());
bullet->set_fly_distance(fly_distance);
}
room->CreateBullet(this, curr_weapon->meta, bullet_born_pos, attack_dir, fly_distance);
}
{
cs::MFBullet* bullet = bullets->Add();
bullet->set_player_id(entity_uniid);
bullet->set_bullet_id(curr_weapon->meta->i->use_bullet());
pos.ToPB(bullet->mutable_pos());
target_dir.ToPB(bullet->mutable_dir());
bullet->set_bulletskin(10001);
bullet->set_gun_id(curr_weapon->meta->i->id());
--curr_weapon->ammo;
int slot_id = curr_weapon->meta->i->_inventory_slot();
switch (slot_id) {
case 5:
{
//手雷
if (inventory[slot_id] > 0) {
--inventory[slot_id];
++curr_weapon->ammo;
} else {
int weapon_idx = curr_weapon->weapon_idx;
*curr_weapon = Weapon();
curr_weapon->weapon_idx = weapon_idx;
if (weapons[SMOKE_SLOT].weapon_id != 0) {
curr_weapon = &weapons[SMOKE_SLOT];
} else {
curr_weapon = &weapons[0];
}
AutoLoadingBullet();
}
need_sync_active_player = true;
SyncAroundPlayers();
}
break;
case 6:
{
//烟雾弹
if (inventory[slot_id] > 0) {
--inventory[slot_id];
++curr_weapon->ammo;
} else {
int weapon_idx = curr_weapon->weapon_idx;
*curr_weapon = Weapon();
curr_weapon->weapon_idx = weapon_idx;
if (weapons[FRAG_SLOT].weapon_id != 0) {
curr_weapon = &weapons[FRAG_SLOT];
} else {
curr_weapon = &weapons[0];
}
AutoLoadingBullet();
}
need_sync_active_player = true;
SyncAroundPlayers();
}
break;
}
room->CreateBullet(this, curr_weapon->meta, pos, target_dir, 0);
last_shot_frameno_ = room->frame_no;
need_sync_active_player = true;
}
void Human::RecalcSelfCollider()
@ -413,5 +477,5 @@ void Human::DecHP(float dec_hp, int killer_id, const std::string& killer_name)
if (health <= 0.0001f) {
BeKill(killer_id, killer_name);
}
need_sync_active_player = true;
SyncAroundPlayers();
}

View File

@ -92,6 +92,8 @@ class Human : public Entity
void BeKill(int killer_id, const std::string& killer_name);
void DecHP(float dec_hp, int killer_id, const std::string& killer_name);
protected:
long long last_shot_frameno_ = 0;
private:
CircleCollider* self_collider_ = nullptr;

View File

@ -799,6 +799,7 @@ void Player::FillMFActivePlayerData(cs::MFActivePlayerData* player_data)
player_data->set_backpack(backpack);
player_data->set_helmet(helmet);
player_data->set_chest(chest);
player_data->set_health(health);
player_data->set_cur_weapon_idx(curr_weapon->weapon_idx);
player_data->set_cur_scope(curr_scope_idx);
for (auto& weapon : weapons) {

View File

@ -97,7 +97,6 @@ class Player : public Human
private:
int send_update_msg_times = 0;
long long last_shot_frameno_ = 0;
cs::SMUpdate* update_msg = nullptr;
long long last_sync_gas_frameno = 0;
void MakeUpdateMsg();

View File

@ -354,6 +354,8 @@ message MFActivePlayerData
optional int32 helmet = 32; //
optional int32 chest = 33; //
optional float health = 34; //
optional int32 cur_scope = 10; // 1 2 4 8 15
/*
0: 9mm