库存重构Ok

This commit is contained in:
aozhiwei 2021-06-09 15:15:26 +08:00
parent c23b6dc681
commit 9a6370b894
5 changed files with 31 additions and 17 deletions

View File

@ -101,6 +101,7 @@ enum InventorySlot_e
IS_TRAP = 19, //陷井
IS_MINE = 20, //地雷
IS_MAX = 30,
IS_END
};

View File

@ -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()

View File

@ -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<int, IS_END>& GetInventoryData() { return inventory_; };
std::array<Inventory, IS_END>& GetInventoryData() { return inventory_; };
virtual void _UpdateMove(int speed) {};
void CheckSpecObject();
@ -226,7 +226,7 @@ private:
float skill_distance_ = 0.0f;
std::map<int, Skill*> skill_hash_;
std::map<int, Skill*> passive_skill_hash_;
std::array<int, IS_END> inventory_ = {};
std::array<Inventory, IS_END> inventory_ = {};
friend class Skill;
};

View File

@ -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);
}
}
}

View File

@ -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
{