drop weapon ok
This commit is contained in:
parent
061a45c188
commit
a72692b860
@ -46,7 +46,6 @@ void HandlerMgr::RegisterNetMsgHandlers()
|
|||||||
RegisterNetMsgHandler(&ggmsghandler, &RoomMgr::_CMJoin);
|
RegisterNetMsgHandler(&ggmsghandler, &RoomMgr::_CMJoin);
|
||||||
|
|
||||||
RegisterNetMsgHandler(&ggmsghandler, &Player::_CMMove);
|
RegisterNetMsgHandler(&ggmsghandler, &Player::_CMMove);
|
||||||
RegisterNetMsgHandler(&ggmsghandler, &Player::_CMDropItem);
|
|
||||||
RegisterNetMsgHandler(&ggmsghandler, &Player::_CMEmote);
|
RegisterNetMsgHandler(&ggmsghandler, &Player::_CMEmote);
|
||||||
RegisterNetMsgHandler(&ggmsghandler, &Player::_CMSpectate);
|
RegisterNetMsgHandler(&ggmsghandler, &Player::_CMSpectate);
|
||||||
RegisterNetMsgHandler(&ggmsghandler, &Player::_CMVoice);
|
RegisterNetMsgHandler(&ggmsghandler, &Player::_CMVoice);
|
||||||
|
@ -50,6 +50,8 @@ class Human : public Entity
|
|||||||
std::vector<Weapon> weapons;
|
std::vector<Weapon> weapons;
|
||||||
Weapon* curr_weapon = nullptr;
|
Weapon* curr_weapon = nullptr;
|
||||||
|
|
||||||
|
std::vector<int> inventory;
|
||||||
|
|
||||||
HumanFrameData frame_data;
|
HumanFrameData frame_data;
|
||||||
|
|
||||||
std::set<Human*> my_seen_players;
|
std::set<Human*> my_seen_players;
|
||||||
|
@ -85,6 +85,9 @@ void Player::Update(int delta_time)
|
|||||||
if (select_weapon) {
|
if (select_weapon) {
|
||||||
UpdateSelectWeapon();
|
UpdateSelectWeapon();
|
||||||
}
|
}
|
||||||
|
if (drop_weapon) {
|
||||||
|
UpdateDropWeapon();
|
||||||
|
}
|
||||||
MakeUpdateMsg();
|
MakeUpdateMsg();
|
||||||
SendNotifyMsg(*update_msg);
|
SendNotifyMsg(*update_msg);
|
||||||
{
|
{
|
||||||
@ -348,76 +351,81 @@ void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
|
|||||||
select_weapon = true;
|
select_weapon = true;
|
||||||
selected_weapon_idx = msg.select_weapon();
|
selected_weapon_idx = msg.select_weapon();
|
||||||
}
|
}
|
||||||
|
if (msg.has_drop_weapon()) {
|
||||||
|
drop_weapon = true;
|
||||||
|
drop_weapon_idx = msg.drop_weapon();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::_CMDropItem(f8::MsgHdr& hdr, const cs::CMDropItem& msg)
|
void Player::UpdateDropWeapon()
|
||||||
{
|
{
|
||||||
if (msg.has_weapon_idx()) {
|
if (drop_weapon_idx >= 0 && drop_weapon_idx < weapons.size()) {
|
||||||
if (msg.weapon_idx() >= 0 && msg.weapon_idx() < weapons.size()) {
|
bool drop_ok = false;
|
||||||
bool drop_ok = false;
|
Weapon* weapon = &weapons[drop_weapon_idx];
|
||||||
Weapon* weapon = &weapons[msg.weapon_idx()];
|
int weapon_id = weapon->weapon_id;
|
||||||
int weapon_id = weapon->weapon_id;
|
if (weapon->weapon_id != 0) {
|
||||||
if (weapon->weapon_id != 0) {
|
if (weapon->weapon_idx == 0) {
|
||||||
if (weapon->weapon_idx == 0) {
|
if (weapon->weapon_id != default_weapon.weapon_id) {
|
||||||
if (weapon->weapon_id != default_weapon.weapon_id) {
|
|
||||||
drop_ok = true;
|
|
||||||
*weapon = default_weapon;
|
|
||||||
}
|
|
||||||
} else if (weapon->weapon_idx == GUN_SLOT1) {
|
|
||||||
drop_ok = true;
|
drop_ok = true;
|
||||||
*weapon = Weapon();
|
*weapon = default_weapon;
|
||||||
weapon->weapon_idx = msg.weapon_idx();
|
}
|
||||||
if (curr_weapon == weapon) {
|
} else if (weapon->weapon_idx == GUN_SLOT1) {
|
||||||
if (weapons[GUN_SLOT2].weapon_id != 0) {
|
drop_ok = true;
|
||||||
curr_weapon = &weapons[GUN_SLOT2];
|
*weapon = Weapon();
|
||||||
} else {
|
weapon->weapon_idx = drop_weapon_idx;
|
||||||
curr_weapon = &weapons[0];
|
if (curr_weapon == weapon) {
|
||||||
|
if (weapons[GUN_SLOT2].weapon_id != 0) {
|
||||||
|
curr_weapon = &weapons[GUN_SLOT2];
|
||||||
|
} else {
|
||||||
|
curr_weapon = &weapons[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (weapon->weapon_idx == GUN_SLOT2) {
|
||||||
|
drop_ok = true;
|
||||||
|
*weapon = Weapon();
|
||||||
|
weapon->weapon_idx = drop_weapon_idx;
|
||||||
|
if (curr_weapon == weapon) {
|
||||||
|
if (weapons[GUN_SLOT1].weapon_id != 0) {
|
||||||
|
curr_weapon = &weapons[GUN_SLOT1];
|
||||||
|
} else {
|
||||||
|
curr_weapon = &weapons[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (drop_ok) {
|
||||||
|
#if 1
|
||||||
|
{
|
||||||
|
MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(weapon_id);
|
||||||
|
if (equip_meta) {
|
||||||
|
Loot* entity = new Loot();
|
||||||
|
entity->room = room;
|
||||||
|
entity->meta = equip_meta;
|
||||||
|
entity->entity_uniid = room->AllocUniid();
|
||||||
|
{
|
||||||
|
Vector2D dir = Vector2D::UP;
|
||||||
|
dir.Rotate(a8::RandAngle());
|
||||||
|
entity->pos = pos + dir * (5 + rand() % 50);
|
||||||
}
|
}
|
||||||
}
|
entity->item_id = weapon_id;
|
||||||
} else if (weapon->weapon_idx == GUN_SLOT2) {
|
entity->count = 1;
|
||||||
drop_ok = true;
|
entity->Initialize();
|
||||||
*weapon = Weapon();
|
room->uniid_hash_[entity->entity_uniid] = entity;
|
||||||
weapon->weapon_idx = msg.weapon_idx();
|
for (auto& pair : room->human_hash_) {
|
||||||
if (curr_weapon == weapon) {
|
pair.second->new_objects.insert(entity);
|
||||||
if (weapons[GUN_SLOT1].weapon_id != 0) {
|
pair.second->part_objects.insert(entity);
|
||||||
curr_weapon = &weapons[GUN_SLOT1];
|
|
||||||
} else {
|
|
||||||
curr_weapon = &weapons[0];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (drop_ok) {
|
#endif
|
||||||
#if 1
|
need_sync_active_player = true;
|
||||||
{
|
for (auto& pair : room->human_hash_) {
|
||||||
MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(weapon_id);
|
pair.second->new_objects.insert(this);
|
||||||
if (equip_meta) {
|
|
||||||
Loot* entity = new Loot();
|
|
||||||
entity->room = room;
|
|
||||||
entity->meta = equip_meta;
|
|
||||||
entity->entity_uniid = room->AllocUniid();
|
|
||||||
{
|
|
||||||
Vector2D dir = Vector2D::UP;
|
|
||||||
dir.Rotate(a8::RandAngle());
|
|
||||||
entity->pos = pos + dir * (5 + rand() % 50);
|
|
||||||
}
|
|
||||||
entity->item_id = weapon_id;
|
|
||||||
entity->count = 1;
|
|
||||||
entity->Initialize();
|
|
||||||
room->uniid_hash_[entity->entity_uniid] = entity;
|
|
||||||
for (auto& pair : room->human_hash_) {
|
|
||||||
pair.second->new_objects.insert(entity);
|
|
||||||
pair.second->part_objects.insert(entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
for (auto& pair : room->human_hash_) {
|
|
||||||
pair.second->new_objects.insert(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
drop_weapon = false;
|
||||||
|
drop_weapon_idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::_CMEmote(f8::MsgHdr& hdr, const cs::CMEmote& msg)
|
void Player::_CMEmote(f8::MsgHdr& hdr, const cs::CMEmote& msg)
|
||||||
@ -454,6 +462,9 @@ void Player::FillMFActivePlayerData(cs::MFActivePlayerData* player_data)
|
|||||||
auto p = player_data->add_weapons();
|
auto p = player_data->add_weapons();
|
||||||
weapon.ToPB(p);
|
weapon.ToPB(p);
|
||||||
}
|
}
|
||||||
|
for (auto& num : inventory) {
|
||||||
|
player_data->add_inventory(num);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::FillMFGasData(cs::MFGasData* gas_data)
|
void Player::FillMFGasData(cs::MFGasData* gas_data)
|
||||||
|
@ -42,6 +42,9 @@ class Player : public Human
|
|||||||
bool select_weapon = false;
|
bool select_weapon = false;
|
||||||
int selected_weapon_idx = 0;
|
int selected_weapon_idx = 0;
|
||||||
|
|
||||||
|
bool drop_weapon = false;
|
||||||
|
int drop_weapon_idx = 0;
|
||||||
|
|
||||||
bool need_sync_active_player = false;
|
bool need_sync_active_player = false;
|
||||||
|
|
||||||
::google::protobuf::RepeatedField< ::google::protobuf::int32 > interaction_objids;
|
::google::protobuf::RepeatedField< ::google::protobuf::int32 > interaction_objids;
|
||||||
@ -59,13 +62,13 @@ class Player : public Human
|
|||||||
void UpdateMove();
|
void UpdateMove();
|
||||||
void UpdateShot();
|
void UpdateShot();
|
||||||
void UpdateSelectWeapon();
|
void UpdateSelectWeapon();
|
||||||
|
void UpdateDropWeapon();
|
||||||
void Shot();
|
void Shot();
|
||||||
void ProcInteraction();
|
void ProcInteraction();
|
||||||
void ObstacleInteraction(Obstacle* entity);
|
void ObstacleInteraction(Obstacle* entity);
|
||||||
void LootInteraction(Loot* entity);
|
void LootInteraction(Loot* entity);
|
||||||
|
|
||||||
void _CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg);
|
void _CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg);
|
||||||
void _CMDropItem(f8::MsgHdr& hdr, const cs::CMDropItem& msg);
|
|
||||||
void _CMEmote(f8::MsgHdr& hdr, const cs::CMEmote& msg);
|
void _CMEmote(f8::MsgHdr& hdr, const cs::CMEmote& msg);
|
||||||
void _CMSpectate(f8::MsgHdr& hdr, const cs::CMSpectate& msg);
|
void _CMSpectate(f8::MsgHdr& hdr, const cs::CMSpectate& msg);
|
||||||
void _CMVoice(f8::MsgHdr& hdr, const cs::CMVoice& msg);
|
void _CMVoice(f8::MsgHdr& hdr, const cs::CMVoice& msg);
|
||||||
@ -76,7 +79,6 @@ class Player : public Human
|
|||||||
private:
|
private:
|
||||||
cs::SMUpdate* update_msg = nullptr;
|
cs::SMUpdate* update_msg = nullptr;
|
||||||
long long last_sync_gas_frameno = 0;
|
long long last_sync_gas_frameno = 0;
|
||||||
std::vector<int> inventory;
|
|
||||||
|
|
||||||
void MakeUpdateMsg();
|
void MakeUpdateMsg();
|
||||||
};
|
};
|
||||||
|
@ -7,7 +7,6 @@ enum CMMessageId_e
|
|||||||
|
|
||||||
_CMJoin = 103;
|
_CMJoin = 103;
|
||||||
_CMMove = 201;
|
_CMMove = 201;
|
||||||
_CMDropItem = 203;
|
|
||||||
_CMEmote = 204;
|
_CMEmote = 204;
|
||||||
_CMSpectate = 205;
|
_CMSpectate = 205;
|
||||||
_CMVoice = 206;
|
_CMVoice = 206;
|
||||||
|
@ -518,6 +518,7 @@ message CMMove
|
|||||||
optional bool reload = 8; //装弹
|
optional bool reload = 8; //装弹
|
||||||
|
|
||||||
optional int32 select_weapon = 10; //切换武器(没切换是不用发)
|
optional int32 select_weapon = 10; //切换武器(没切换是不用发)
|
||||||
|
optional int32 drop_weapon = 11; //丢弃武器
|
||||||
|
|
||||||
optional bool cancel_action = 15; //zz
|
optional bool cancel_action = 15; //zz
|
||||||
//optional bool edit_mode = 16; //没用到
|
//optional bool edit_mode = 16; //没用到
|
||||||
|
Loading…
x
Reference in New Issue
Block a user