From 12b963ec796342d42689cec85d72c7df1a2f5f8f Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 2 Apr 2019 14:19:40 +0800 Subject: [PATCH] 1 --- server/gameserver/android.cc | 3 ++- server/gameserver/constant.h | 3 +++ server/gameserver/human.cc | 11 ++++++----- server/gameserver/human.h | 2 -- server/gameserver/player.cc | 23 +++++++++++++---------- server/gameserver/types.h | 2 ++ server/tools/protobuild/cs_proto.proto | 6 +++--- 7 files changed, 29 insertions(+), 21 deletions(-) diff --git a/server/gameserver/android.cc b/server/gameserver/android.cc index 45c62f6..e6bd985 100644 --- a/server/gameserver/android.cc +++ b/server/gameserver/android.cc @@ -24,10 +24,11 @@ void Android::Initialize() health = meta->i->health(); helmet = DEF_HELMET_ID; chest = DEF_CHEST_ID; + #if 0 weapon = DEF_WEAPON_ID; + #endif helmet_meta = MetaMgr::Instance()->GetEquip(helmet); chest_meta = MetaMgr::Instance()->GetEquip(chest); - weapon_meta = MetaMgr::Instance()->GetEquip(weapon); RecalcSelfCollider(); } diff --git a/server/gameserver/constant.h b/server/gameserver/constant.h index b26d5c1..e37e4f6 100755 --- a/server/gameserver/constant.h +++ b/server/gameserver/constant.h @@ -74,3 +74,6 @@ const int SYNC_FRAME_RATE = 10; const int MAX_INVENTORY_NUM = 14; const int MAX_WEAPON_NUM = 5; + +const int GUN_SLOT1 = 1; +const int GUN_SLOT2 = 2; diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index 136fcf8..a82c66e 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -15,6 +15,7 @@ Human::Human() default_weapon.weapon_idx = 0; default_weapon.weapon_id = 12102; default_weapon.weapon_lv = 1; + default_weapon.meta = MetaMgr::Instance()->GetEquip(default_weapon.weapon_id); weapons.reserve(MAX_WEAPON_NUM); for (size_t i = 0; i < MAX_WEAPON_NUM; ++i) { auto& weapon = a8::FastAppend(weapons); @@ -78,7 +79,7 @@ void Human::FillMFObjectFull(cs::MFObjectFull* full_data) void Human::Shot(Vector2D& target_dir) { - if (!weapon_meta) { + if (!curr_weapon->meta) { return; } @@ -92,18 +93,18 @@ void Human::Shot(Vector2D& target_dir) { cs::MFBullet* bullet = room->frame_data.bullets.Add(); bullet->set_player_id(entity_uniid); - bullet->set_bullet_id(weapon_meta->i->use_bullet()); + 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(weapon_meta->i->id()); + bullet->set_gun_id(curr_weapon->meta->i->id()); } { Bullet* bullet = new Bullet(); bullet->player = this; bullet->room = room; - bullet->gun_meta = weapon_meta; - bullet->meta = MetaMgr::Instance()->GetEquip(weapon_meta->i->use_bullet()); + bullet->gun_meta = curr_weapon->meta; + bullet->meta = MetaMgr::Instance()->GetEquip(curr_weapon->meta->i->use_bullet()); bullet->pos = pos; bullet->dir = target_dir; bullet->born_pos = pos; diff --git a/server/gameserver/human.h b/server/gameserver/human.h index 98b4b99..8391bb9 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -23,7 +23,6 @@ class Human : public Entity MetaData::Player* meta = nullptr; MetaData::Equip* helmet_meta = nullptr; MetaData::Equip* chest_meta = nullptr; - MetaData::Equip* weapon_meta = nullptr; Vector2D move_dir; Vector2D attack_dir; @@ -39,7 +38,6 @@ class Human : public Entity int skin = 0; int helmet = 0; int chest = 0; - int weapon = 0; int energy_shield = 0; int vip = 0; int sdmg = 0; diff --git a/server/gameserver/player.cc b/server/gameserver/player.cc index fa317df..1b272ae 100644 --- a/server/gameserver/player.cc +++ b/server/gameserver/player.cc @@ -47,10 +47,15 @@ void Player::Initialize() health = meta->i->health(); helmet = DEF_HELMET_ID; chest = DEF_CHEST_ID; - weapon = DEF_WEAPON_ID; + #if 1 + weapons[GUN_SLOT1].weapon_idx = GUN_SLOT1; + weapons[GUN_SLOT1].weapon_id = DEF_WEAPON_ID; + weapons[GUN_SLOT1].weapon_lv = 1; + weapons[GUN_SLOT1].meta = MetaMgr::Instance()->GetEquip(DEF_WEAPON_ID);; + curr_weapon = &weapons[GUN_SLOT1]; + #endif helmet_meta = MetaMgr::Instance()->GetEquip(helmet); chest_meta = MetaMgr::Instance()->GetEquip(chest); - weapon_meta = MetaMgr::Instance()->GetEquip(weapon); RecalcSelfCollider(); inventory.reserve(MAX_INVENTORY_NUM); for (size_t i = 0; i < inventory.size(); ++i) { @@ -131,34 +136,32 @@ void Player::UpdateShot() void Player::Shot() { - if (!weapon_meta) { + if (!curr_weapon->meta) { return; } { cs::MFShot* shot = room->frame_data.shots.Add(); shot->set_player_id(entity_uniid); - #if 0 - shot->set_weapon_id(weapon_meta->i->id()); - #endif + curr_weapon->ToPB(shot->mutable_weapon()); shot->set_offhand(true); shot->set_bullskin(10001); } { cs::MFBullet* bullet = room->frame_data.bullets.Add(); bullet->set_player_id(entity_uniid); - bullet->set_bullet_id(weapon_meta->i->use_bullet()); + bullet->set_bullet_id(curr_weapon->meta->i->use_bullet()); pos.ToPB(bullet->mutable_pos()); attack_dir.ToPB(bullet->mutable_dir()); bullet->set_bulletskin(10001); - bullet->set_gun_id(weapon_meta->i->id()); + bullet->set_gun_id(curr_weapon->meta->i->id()); } { Bullet* bullet = new Bullet(); bullet->player = this; bullet->room = room; - bullet->gun_meta = weapon_meta; - bullet->meta = MetaMgr::Instance()->GetEquip(weapon_meta->i->use_bullet()); + bullet->gun_meta = curr_weapon->meta; + bullet->meta = MetaMgr::Instance()->GetEquip(curr_weapon->meta->i->use_bullet()); bullet->pos = pos; bullet->dir = attack_dir; bullet->born_pos = pos; diff --git a/server/gameserver/types.h b/server/gameserver/types.h index c0f3a6c..ec22fcd 100755 --- a/server/gameserver/types.h +++ b/server/gameserver/types.h @@ -45,6 +45,7 @@ struct Vector2D namespace MetaData { struct SafeArea; + struct Equip; } struct GasData @@ -69,6 +70,7 @@ struct Weapon int weapon_id = 0; int weapon_lv = 0; int num = 0; + MetaData::Equip* meta = nullptr; void ToPB(cs::MFWeapon* pb_obj); }; diff --git a/server/tools/protobuild/cs_proto.proto b/server/tools/protobuild/cs_proto.proto index 41c70aa..54288b3 100755 --- a/server/tools/protobuild/cs_proto.proto +++ b/server/tools/protobuild/cs_proto.proto @@ -653,9 +653,9 @@ message SMGameOver //拾取 message SMPickup { - optional int32 type = 1; - optional int32 item_id = 2; - optional int32 count = 3; + optional int32 error_code = 1; //0:没有错误 1:背包空间不足 2:物品已拥有 3:物品已装备 + optional int32 item_id = 2; //道具id + optional int32 count = 3; //获得数量 } //断线通知