From 08ce0b619a2ff3747b21c55092630ae534a228cb Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 2 Apr 2019 15:08:21 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=89=E6=8B=A9=E6=AD=A6=E5=99=A8Ok?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/gameserver/player.cc | 66 ++++++++++++++++++++++++++ server/gameserver/player.h | 7 +++ server/tools/protobuild/cs_proto.proto | 10 ++-- 3 files changed, 76 insertions(+), 7 deletions(-) diff --git a/server/gameserver/player.cc b/server/gameserver/player.cc index 1b272ae..e21460d 100644 --- a/server/gameserver/player.cc +++ b/server/gameserver/player.cc @@ -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) diff --git a/server/gameserver/player.h b/server/gameserver/player.h index abcb0c0..e96c671 100644 --- a/server/gameserver/player.h +++ b/server/gameserver/player.h @@ -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 @@ -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); diff --git a/server/tools/protobuild/cs_proto.proto b/server/tools/protobuild/cs_proto.proto index 54288b3..cd9bed9 100755 --- a/server/tools/protobuild/cs_proto.proto +++ b/server/tools/protobuild/cs_proto.proto @@ -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 } //发送表情