选择武器Ok

This commit is contained in:
aozhiwei 2019-04-02 15:08:21 +08:00
parent 12b963ec79
commit 08ce0b619a
3 changed files with 76 additions and 7 deletions

View File

@ -82,6 +82,9 @@ void Player::Update(int delta_time)
if (poisoning) {
UpdatePoisoning();
}
if (select_weapon) {
UpdateSelectWeapon();
}
MakeUpdateMsg();
SendNotifyMsg(*update_msg);
{
@ -134,6 +137,21 @@ void Player::UpdateShot()
}
}
void Player::UpdateSelectWeapon()
{
if (selected_weapon_idx >= 0 && selected_weapon_idx < weapons.size()) {
Weapon* weapon = &weapons[selected_weapon_idx];
if (weapon->weapon_id != 0) {
curr_weapon = weapon;
for (auto& pair : room->human_hash_) {
pair.second->new_objects.insert(this);
}
}
}
select_weapon = false;
selected_weapon_idx = 0;
}
void Player::Shot()
{
if (!curr_weapon->meta) {
@ -227,6 +245,50 @@ void Player::LootInteraction(Loot* entity)
if (entity->pickuped) {
return;
}
MetaData::Equip* item_meta = MetaMgr::Instance()->GetEquip(entity->item_id);
if (!item_meta) {
return;
}
switch (item_meta->i->equip_type()) {
case 1:
{
//装备
if (item_meta->i->equip_subtype() == 1) {
//近战
if (default_weapon.weapon_id != weapons[0].weapon_id) {
cs::SMPickup notifymsg;
notifymsg.set_error_code(2);
SendNotifyMsg(notifymsg);
return;
} else {
weapons[0].weapon_idx = 0;
weapons[0].weapon_id = entity->item_id;
weapons[0].weapon_lv = 1;
weapons[0].num = 0;
need_sync_active_player = true;
}
} else {
Weapon* weapon = nullptr;
if (weapons[GUN_SLOT1].weapon_id == 0) {
weapon = &weapons[GUN_SLOT1];
} else if (weapons[GUN_SLOT2].weapon_id == 0) {
weapon = &weapons[GUN_SLOT2];
}
if (!weapon) {
cs::SMPickup notifymsg;
notifymsg.set_error_code(2);
SendNotifyMsg(notifymsg);
return;
}
weapons[0].weapon_idx = 0;
weapons[0].weapon_id = entity->item_id;
weapons[0].weapon_lv = 1;
weapons[0].num = 0;
need_sync_active_player = true;
}
}
break;
}
entity->pickuped = true;
room->AddDeletedObject(entity->entity_uniid);
}
@ -268,6 +330,10 @@ void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
interaction_objids = msg.interaction_objids();
}
last_seq_id = msg.seq();
if (msg.has_select_weapon()) {
select_weapon = true;
selected_weapon_idx = msg.select_weapon();
}
}
void Player::_CMDropItem(f8::MsgHdr& hdr, const cs::CMDropItem& msg)

View File

@ -38,6 +38,12 @@ class Player : public Human
bool shot_start = false;
bool shot_hold = false;
int series_shot_frames = 0;
bool select_weapon = false;
int selected_weapon_idx = 0;
bool need_sync_active_player = false;
::google::protobuf::RepeatedField< ::google::protobuf::int32 > interaction_objids;
template <typename T>
@ -52,6 +58,7 @@ class Player : public Human
virtual void Update(int delta_time) override;
void UpdateMove();
void UpdateShot();
void UpdateSelectWeapon();
void Shot();
void ProcInteraction();
void ObstacleInteraction(Obstacle* entity);

View File

@ -517,11 +517,7 @@ message CMMove
optional bool shot_hold = 7; //-
optional bool reload = 8; //
optional bool equip_primary = 10; //1
optional bool equip_secondary = 11; //2
optional bool equip_throwable = 12; //3
optional bool equip_melee = 13; //
optional bool equip_last = 14; //使
optional int32 select_weapon = 10; //()
optional bool cancel_action = 15; //zz
//optional bool edit_mode = 16; //
@ -539,8 +535,8 @@ message CMMove
//
message CMDropItem
{
optional int32 item_id = 1;
optional int32 weapon_idx = 2;
optional int32 item_id = 1; //id
optional int32 weapon_idx = 2; // 0-4
}
//