diff --git a/server/gameserver/constant.h b/server/gameserver/constant.h index d4d17ed..df009c7 100755 --- a/server/gameserver/constant.h +++ b/server/gameserver/constant.h @@ -101,6 +101,7 @@ enum InventorySlot_e IS_TRAP = 19, //陷井 IS_MINE = 20, //地雷 + IS_MAX = 30, IS_END }; diff --git a/server/gameserver/creature.cc b/server/gameserver/creature.cc index 92fd0b5..8345f27 100644 --- a/server/gameserver/creature.cc +++ b/server/gameserver/creature.cc @@ -107,15 +107,21 @@ Creature::Creature():MoveableEntity() weapon.ammo = 0; } + for (size_t i = 0; i < inventory_.size(); ++i) { + inventory_[i].slot = i; + inventory_[i].itemid = 0; + inventory_[i].num = 0; + } + weak_ptr_chunk_.Set(this); - inventory_[IS_1XSCOPE] = 1; + inventory_[IS_1XSCOPE].num = 1; if (MetaMgr::Instance()->fighting_mode) { - inventory_[IS_9MM] = FIGHTING_MODE_BULLET_NUM; - inventory_[IS_556MM] = FIGHTING_MODE_BULLET_NUM; - inventory_[IS_762MM] = FIGHTING_MODE_BULLET_NUM; - inventory_[IS_12GAUGE] = FIGHTING_MODE_BULLET_NUM; - inventory_[IS_RPG] = FIGHTING_MODE_BULLET_NUM; + inventory_[IS_9MM].num = FIGHTING_MODE_BULLET_NUM; + inventory_[IS_556MM].num = FIGHTING_MODE_BULLET_NUM; + inventory_[IS_762MM].num = FIGHTING_MODE_BULLET_NUM; + inventory_[IS_12GAUGE].num = FIGHTING_MODE_BULLET_NUM; + inventory_[IS_RPG].num = FIGHTING_MODE_BULLET_NUM; } } @@ -1382,7 +1388,7 @@ int Creature::GetInventory(int slot_id) if (!IsValidSlotId(slot_id)) { abort(); } - return inventory_[slot_id]; + return inventory_[slot_id].num; } void Creature::AddInventory(int slot_id, int num) @@ -1391,7 +1397,7 @@ void Creature::AddInventory(int slot_id, int num) if (!IsValidSlotId(slot_id)) { abort(); } - inventory_[slot_id] += num; + inventory_[slot_id].num += num; } void Creature::DecInventory(int slot_id, int num) @@ -1400,7 +1406,7 @@ void Creature::DecInventory(int slot_id, int num) if (!IsValidSlotId(slot_id)) { abort(); } - inventory_[slot_id] -= num; + inventory_[slot_id].num -= num; } void Creature::CheckSpecObject() diff --git a/server/gameserver/creature.h b/server/gameserver/creature.h index fabe67e..1ec03ab 100644 --- a/server/gameserver/creature.h +++ b/server/gameserver/creature.h @@ -152,7 +152,7 @@ class Creature : public MoveableEntity int GetInventory(int slot_id); void AddInventory(int slot_id, int num); void DecInventory(int slot_id, int num); - std::array& GetInventoryData() { return inventory_; }; + std::array& GetInventoryData() { return inventory_; }; virtual void _UpdateMove(int speed) {}; void CheckSpecObject(); @@ -226,7 +226,7 @@ private: float skill_distance_ = 0.0f; std::map skill_hash_; std::map passive_skill_hash_; - std::array inventory_ = {}; + std::array inventory_ = {}; friend class Skill; }; diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index fab0a84..1aa316f 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -1381,8 +1381,8 @@ void Human::FillMFActivePlayerData(cs::MFActivePlayerData* player_data) auto p = player_data->add_weapons(); weapon.ToPB(p); } - for (auto& num : GetInventoryData()) { - player_data->add_inventory(num); + for (auto& inv : GetInventoryData()) { + player_data->add_inventory(inv.num); } player_data->set_energy_shield(energy_shield); #if 1 @@ -2337,7 +2337,7 @@ void Human::DeadDrop() } } for (size_t slot = 0; slot < GetInventoryData().size(); ++slot) { - if (GetInventoryData()[slot] > 0) { + if (GetInventory(slot) > 0) { MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquipBySlotId(slot); if (equip_meta) { if (equip_meta->i->equip_type() == EQUIP_TYPE_BULLET) { @@ -2350,8 +2350,8 @@ void Human::DeadDrop() case IS_MINE: { a8::Vec2 drop_pos = GetPos(); - room->DropItem(drop_pos, equip_meta->i->id(), GetInventoryData()[slot], 1); - DecInventory(slot, GetInventoryData()[slot]); + room->DropItem(drop_pos, equip_meta->i->id(), GetInventory(slot), 1); + DecInventory(slot, GetInventory(slot)); } break; default: @@ -2359,7 +2359,7 @@ void Human::DeadDrop() } } else { a8::Vec2 drop_pos = GetPos(); - room->DropItem(drop_pos, equip_meta->i->id(), GetInventoryData()[slot], 1); + room->DropItem(drop_pos, equip_meta->i->id(), GetInventory(slot), 1); } } } diff --git a/server/gameserver/types.h b/server/gameserver/types.h index 4441696..0afb07f 100755 --- a/server/gameserver/types.h +++ b/server/gameserver/types.h @@ -161,6 +161,13 @@ struct KillInfo std::string msg; }; +struct Inventory +{ + int slot = 0; + int num = 0; + int itemid = 0; +}; + #pragma pack(1) struct ObjectSyncFlags {