选择武器Ok
This commit is contained in:
parent
12b963ec79
commit
08ce0b619a
@ -82,6 +82,9 @@ void Player::Update(int delta_time)
|
|||||||
if (poisoning) {
|
if (poisoning) {
|
||||||
UpdatePoisoning();
|
UpdatePoisoning();
|
||||||
}
|
}
|
||||||
|
if (select_weapon) {
|
||||||
|
UpdateSelectWeapon();
|
||||||
|
}
|
||||||
MakeUpdateMsg();
|
MakeUpdateMsg();
|
||||||
SendNotifyMsg(*update_msg);
|
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()
|
void Player::Shot()
|
||||||
{
|
{
|
||||||
if (!curr_weapon->meta) {
|
if (!curr_weapon->meta) {
|
||||||
@ -227,6 +245,50 @@ void Player::LootInteraction(Loot* entity)
|
|||||||
if (entity->pickuped) {
|
if (entity->pickuped) {
|
||||||
return;
|
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;
|
entity->pickuped = true;
|
||||||
room->AddDeletedObject(entity->entity_uniid);
|
room->AddDeletedObject(entity->entity_uniid);
|
||||||
}
|
}
|
||||||
@ -268,6 +330,10 @@ void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
|
|||||||
interaction_objids = msg.interaction_objids();
|
interaction_objids = msg.interaction_objids();
|
||||||
}
|
}
|
||||||
last_seq_id = msg.seq();
|
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)
|
void Player::_CMDropItem(f8::MsgHdr& hdr, const cs::CMDropItem& msg)
|
||||||
|
@ -38,6 +38,12 @@ class Player : public Human
|
|||||||
bool shot_start = false;
|
bool shot_start = false;
|
||||||
bool shot_hold = false;
|
bool shot_hold = false;
|
||||||
int series_shot_frames = 0;
|
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;
|
::google::protobuf::RepeatedField< ::google::protobuf::int32 > interaction_objids;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -52,6 +58,7 @@ class Player : public Human
|
|||||||
virtual void Update(int delta_time) override;
|
virtual void Update(int delta_time) override;
|
||||||
void UpdateMove();
|
void UpdateMove();
|
||||||
void UpdateShot();
|
void UpdateShot();
|
||||||
|
void UpdateSelectWeapon();
|
||||||
void Shot();
|
void Shot();
|
||||||
void ProcInteraction();
|
void ProcInteraction();
|
||||||
void ObstacleInteraction(Obstacle* entity);
|
void ObstacleInteraction(Obstacle* entity);
|
||||||
|
@ -517,11 +517,7 @@ message CMMove
|
|||||||
optional bool shot_hold = 7; //射击-一直按着
|
optional bool shot_hold = 7; //射击-一直按着
|
||||||
optional bool reload = 8; //装弹
|
optional bool reload = 8; //装弹
|
||||||
|
|
||||||
optional bool equip_primary = 10; //装备1
|
optional int32 select_weapon = 10; //切换武器(没切换是不用发)
|
||||||
optional bool equip_secondary = 11; //装备2
|
|
||||||
optional bool equip_throwable = 12; //装备3
|
|
||||||
optional bool equip_melee = 13; //装备
|
|
||||||
optional bool equip_last = 14; //最后使用的装备
|
|
||||||
|
|
||||||
optional bool cancel_action = 15; //zz
|
optional bool cancel_action = 15; //zz
|
||||||
//optional bool edit_mode = 16; //没用到
|
//optional bool edit_mode = 16; //没用到
|
||||||
@ -539,8 +535,8 @@ message CMMove
|
|||||||
//丢弃道具
|
//丢弃道具
|
||||||
message CMDropItem
|
message CMDropItem
|
||||||
{
|
{
|
||||||
optional int32 item_id = 1;
|
optional int32 item_id = 1; //道具id
|
||||||
optional int32 weapon_idx = 2;
|
optional int32 weapon_idx = 2; //武器索引 0-4
|
||||||
}
|
}
|
||||||
|
|
||||||
//发送表情
|
//发送表情
|
||||||
|
Loading…
x
Reference in New Issue
Block a user