使用 道具ok
This commit is contained in:
parent
abe56517d1
commit
71c0da24ac
@ -65,6 +65,24 @@ enum ActionType_e
|
||||
AT_Relive = 3,
|
||||
};
|
||||
|
||||
enum InventorySlot_e
|
||||
{
|
||||
IS_9MM = 0,
|
||||
IS_556MM = 1,
|
||||
IS_762MM = 2,
|
||||
IS_12GAUGE = 3,
|
||||
IS_RPG = 4,
|
||||
IS_FRAG = 5,
|
||||
IS_SMOKE = 6,
|
||||
IS_HEALTHKIT = 7,
|
||||
|
||||
IS_1XSCOPE = 12,
|
||||
IS_2XSCOPE = 13,
|
||||
IS_4XSCOPE = 14,
|
||||
IS_8XSCOPE = 15,
|
||||
IS_15XSCOPE = 16,
|
||||
};
|
||||
|
||||
const char* const PROJ_NAME_FMT = "game%d_gameserver";
|
||||
const char* const PROJ_ROOT_FMT = "/data/logs/%s";
|
||||
|
||||
|
@ -34,6 +34,7 @@ public:
|
||||
std::map<int, MetaData::SafeArea*> safearea_hash;
|
||||
std::map<int, MetaData::Item*> item_hash;
|
||||
std::map<int, MetaData::Equip*> equip_hash;
|
||||
std::map<int, MetaData::Equip*> equip_slot_hash;
|
||||
std::map<int, MetaData::Player*> player_hash;
|
||||
std::map<int, MetaData::MapThing*> mapthing_hash;
|
||||
std::map<int, MetaData::Building*> building_hash;
|
||||
@ -99,6 +100,9 @@ private:
|
||||
MetaData::Equip& item = a8::FastAppend(equip_list);
|
||||
item.i = &meta;
|
||||
equip_hash[item.i->id()] = &item;
|
||||
if (meta._inventory_slot() > -1) {
|
||||
equip_slot_hash[meta._inventory_slot()] = &item;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& meta : player_meta_list) {
|
||||
@ -186,6 +190,12 @@ MetaData::Equip* MetaMgr::GetEquip(int id)
|
||||
return itr != loader_->equip_hash.end() ? itr->second : nullptr;
|
||||
}
|
||||
|
||||
MetaData::Equip* MetaMgr::GetEquipBySlotId(int slot_id)
|
||||
{
|
||||
auto itr = loader_->equip_slot_hash.find(slot_id);
|
||||
return itr != loader_->equip_slot_hash.end() ? itr->second : nullptr;
|
||||
}
|
||||
|
||||
MetaData::Building* MetaMgr::GetBuilding(int building_id)
|
||||
{
|
||||
auto itr = loader_->building_hash.find(building_id);
|
||||
|
@ -21,6 +21,7 @@ class MetaMgr : public a8::Singleton<MetaMgr>
|
||||
MetaData::MapThing* GetMapThing(int mapthing_id);
|
||||
MetaData::Player* GetPlayer(int id);
|
||||
MetaData::Equip* GetEquip(int id);
|
||||
MetaData::Equip* GetEquipBySlotId(int slot_id);
|
||||
MetaData::Building* GetBuilding(int building_id);
|
||||
MetaData::Drop* GetDrop(int drop_id);
|
||||
MetaData::SafeArea* GetSafeArea(int area_id);
|
||||
|
@ -63,6 +63,12 @@ void Player::Update(int delta_time)
|
||||
if (reload) {
|
||||
UpdateReload();
|
||||
}
|
||||
if (cancel_action) {
|
||||
UpdateCancelAction();
|
||||
}
|
||||
if (use_item) {
|
||||
UpdateUseItemIdx();
|
||||
}
|
||||
if (action_type != AT_None) {
|
||||
UpdateAction();
|
||||
}
|
||||
@ -174,6 +180,29 @@ void Player::UpdateAction()
|
||||
}
|
||||
}
|
||||
break;
|
||||
case AT_UseItem:
|
||||
{
|
||||
switch (action_item_id) {
|
||||
case IS_HEALTHKIT:
|
||||
{
|
||||
MetaData::Equip* item_meta = MetaMgr::Instance()->GetEquipBySlotId(action_item_id);
|
||||
if (item_meta){
|
||||
if (inventory[item_meta->i->_inventory_slot()] > 0) {
|
||||
health += item_meta->i->heal();
|
||||
health = std::max(100.0f, health);
|
||||
++inventory[item_meta->i->_inventory_slot()];
|
||||
need_sync_active_player = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
ResetAction();
|
||||
}
|
||||
@ -185,6 +214,40 @@ void Player::UpdateReload()
|
||||
reload = false;
|
||||
}
|
||||
|
||||
void Player::UpdateCancelAction()
|
||||
{
|
||||
CancelAction();
|
||||
cancel_action = false;
|
||||
}
|
||||
|
||||
void Player::UpdateUseItemIdx()
|
||||
{
|
||||
if (use_item_idx >= 0 && use_item_idx < MAX_INVENTORY_NUM) {
|
||||
switch (use_item_idx) {
|
||||
case IS_HEALTHKIT:
|
||||
{
|
||||
MetaData::Equip* item_meta = MetaMgr::Instance()->GetEquipBySlotId(use_item_idx);
|
||||
if (item_meta) {
|
||||
StartAction(
|
||||
AT_UseItem,
|
||||
item_meta->i->use_time(),
|
||||
use_item_idx,
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
use_item_idx = 0;
|
||||
use_item = false;
|
||||
}
|
||||
|
||||
void Player::Shot()
|
||||
{
|
||||
if (!curr_weapon->meta) {
|
||||
@ -519,6 +582,13 @@ void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
|
||||
if (msg.has_reload()) {
|
||||
reload = msg.reload();
|
||||
}
|
||||
if (msg.has_cancel_action()) {
|
||||
cancel_action = msg.cancel_action();
|
||||
}
|
||||
if (msg.has_use_item_idx()) {
|
||||
use_item = true;
|
||||
use_item_idx = msg.use_item_idx();
|
||||
}
|
||||
}
|
||||
|
||||
void Player::UpdateDropWeapon()
|
||||
|
@ -46,6 +46,11 @@ class Player : public Human
|
||||
bool drop_weapon = false;
|
||||
int drop_weapon_idx = 0;
|
||||
|
||||
bool cancel_action = false;
|
||||
|
||||
bool use_item = false;
|
||||
int use_item_idx = 0;
|
||||
|
||||
bool use_scope = false;
|
||||
int use_scope_idx = 0;
|
||||
|
||||
@ -70,6 +75,8 @@ class Player : public Human
|
||||
void UpdateUseScope();
|
||||
void UpdateAction();
|
||||
void UpdateReload();
|
||||
void UpdateCancelAction();
|
||||
void UpdateUseItemIdx();
|
||||
void Shot();
|
||||
void ProcInteraction();
|
||||
void ObstacleInteraction(Obstacle* entity);
|
||||
|
@ -536,7 +536,8 @@ message CMMove
|
||||
optional int32 select_weapon = 10; //切换武器(没切换是不用发)
|
||||
optional int32 drop_weapon = 11; //丢弃武器
|
||||
|
||||
//use_item使用道具
|
||||
optional bool cancel_action = 26; //取消当前操作(比如取消使用道具装弹等)
|
||||
optional int32 use_item_idx = 22; //使用道具(对应库存索引0-16)
|
||||
optional int32 use_scope = 25; //使用倍镜 0-4
|
||||
|
||||
optional bool interaction = 9; //是否有交互
|
||||
|
Loading…
x
Reference in New Issue
Block a user