diff --git a/server/gameserver/constant.h b/server/gameserver/constant.h index cb20929..60d3fda 100755 --- a/server/gameserver/constant.h +++ b/server/gameserver/constant.h @@ -184,7 +184,10 @@ enum EquipAttr_e enum EquipType_e { + EQUIP_TYPE_WEAPON = 1, + EQUIP_TYPE_OLDSKIN = 8, EQUIP_TYPE_CAR = 9, + EQUIP_TYPE_SKIN = 10, EQUIP_TYPE_End }; @@ -232,6 +235,12 @@ enum MapObjectType_e kMOT_SpawnPoint = 2 }; +enum SkinSlot_e +{ + kSkinSlot_CLOTH = 1, + kSkinSlot_HAT = 2, +}; + const char* const PROJ_NAME_FMT = "game%d_gameserver"; const char* const PROJ_ROOT_FMT = "/data/logs/%s"; diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index 970c517..466f0ef 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -27,6 +27,7 @@ #include "framework/cpp/httpclientpool.h" const int kReviveTimeAdd = 12; +const int kSkinNum = 4; Human::Human():Entity() { @@ -44,6 +45,11 @@ Human::Human():Entity() weapon.weapon_lv = 0; weapon.ammo = 0; } + for (int i = 0; i < kSkinNum; ++i) { + Skin& skin = a8::FastAppend(skins); + skin.skin_id = 0; + skin.skin_lv = 1; + } weapons[0] = default_weapon; curr_weapon = &weapons[0]; inventory_[IS_1XSCOPE] = 1; @@ -86,7 +92,7 @@ float Human::GetSpeed() } } } else if (aiming) { - return meta->i->aiming_speed(); + return std::max(1, meta->i->aiming_speed()); } float speed = meta->i->move_speed(); speed = (speed + buff_attr_abs_[kHAT_Speed]) * (1 + buff_attr_rate_[kHAT_Speed]); @@ -2173,7 +2179,7 @@ void Human::SendBattleReport() delete params; } -void Human::ProcLootSkin(Loot* entity, MetaData::Equip* item_meta) +void Human::ProcLootOldSkin(Loot* entity, MetaData::Equip* item_meta) { auto oil_sync_func = [] (const a8::XParams& param) @@ -2254,6 +2260,44 @@ void Human::ProcLootSkin(Loot* entity, MetaData::Equip* item_meta) } } +void Human::ProcLootSkin(Loot* entity, MetaData::Equip* item_meta) +{ + switch (item_meta->i->equip_subtype()) { + case 11: + { + //装饰 + Skin* old_skin = GetSkinByIdx(kSkinSlot_HAT); + if (old_skin) { + a8::Vec2 dir = a8::Vec2::UP; + dir.Rotate(a8::RandAngle()); + room->CreateLoot(old_skin->skin_id, GetPos() + dir * (40 + rand() % 50), 1, 1); + + *old_skin = Skin(); + old_skin->skin_id = item_meta->i->id(); + old_skin->skin_lv = 1; + SyncAroundPlayers(__FILE__, __LINE__, __func__); + } + } + break; + case 12: + { + //衣服 + Skin* old_skin = GetSkinByIdx(kSkinSlot_CLOTH); + if (old_skin) { + a8::Vec2 dir = a8::Vec2::UP; + dir.Rotate(a8::RandAngle()); + room->CreateLoot(old_skin->skin_id, GetPos() + dir * (40 + rand() % 50), 1, 1); + + *old_skin = Skin(); + old_skin->skin_id = item_meta->i->id(); + old_skin->skin_lv = 1; + SyncAroundPlayers(__FILE__, __LINE__, __func__); + } + } + break; + } +} + void Human::ProcLootCar(Loot* entity, MetaData::Equip* item_meta) { if (downed) { @@ -2413,24 +2457,42 @@ void Human::FreeReviveTimer() void Human::RandSkin() { std::vector ids = {1, 2, 3, 4, 5, 6}; - for (int i = 0; i < 4; ++i) { + for (int i = 0; i < kSkinNum; ++i) { int rand_idx = rand() % ids.size(); - Skin& skin = a8::FastAppend(skins); + int skin_id = ids[rand_idx]; + if (skin_id == 2) { + skin_id = 13001 + rand(6); + } else if (skin_id == 3) { + skin_id = 15001 + rand(6); + } + Skin& skin = skins[i]; skin.skin_id = ids[rand_idx]; skin.skin_lv = 1; ids.erase(ids.begin() + rand_idx); } } -void Human::AddSkin(int skin_id) +void Human::SetSkin(int idx, int skin_id) { - if (skins.size() < 4) { - Skin& skin = a8::FastAppend(skins); + if (idx < kSkinNum) { + Skin& skin = skins[idx]; skin.skin_id = skin_id; skin.skin_lv = 1; } } +Skin* Human::GetSkinByIdx(int idx) +{ + int i = 0; + for (auto& skin : skins) { + if (i == idx) { + return &skin; + } + ++i; + } + return nullptr; +} + MetaData::Skill* Human::CurrentSkillMeta() { return skill_meta_; diff --git a/server/gameserver/human.h b/server/gameserver/human.h index cdbb046..e103685 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -219,7 +219,8 @@ class Human : public Entity void FreeDownedTimer(); void FreeReviveTimer(); void RandSkin(); - void AddSkin(int skin_id); + void SetSkin(int idx, int skin_id); + Skin* GetSkinByIdx(int idx); MetaData::Skill* CurrentSkillMeta(); int GetSkillLeftTime(); int GetSkillCd(); @@ -241,6 +242,7 @@ class Human : public Entity protected: void _UpdateMove(int speed); + void ProcLootOldSkin(Loot* entity, MetaData::Equip* item_meta); void ProcLootSkin(Loot* entity, MetaData::Equip* item_meta); void ProcLootCar(Loot* entity, MetaData::Equip* item_meta); void ResetTankSkin(); @@ -311,7 +313,7 @@ private: bool sent_battlereport_ = false; bool sent_game_end_ = false; - std::list skins; + std::vector skins; friend class FrameMaker; friend class FrameEvent; diff --git a/server/gameserver/player.cc b/server/gameserver/player.cc index e6dfa1f..5e15fb7 100644 --- a/server/gameserver/player.cc +++ b/server/gameserver/player.cc @@ -513,7 +513,7 @@ void Player::LootInteraction(Loot* entity) return; } switch (item_meta->i->equip_type()) { - case 1: + case EQUIP_TYPE_WEAPON: { //装备 if (item_meta->i->equip_subtype() == 1) { @@ -569,7 +569,12 @@ void Player::LootInteraction(Loot* entity) } } break; - case 8: + case EQUIP_TYPE_OLDSKIN: + { + ProcLootOldSkin(entity, item_meta); + } + break; + case EQUIP_TYPE_SKIN: { ProcLootSkin(entity, item_meta); } diff --git a/server/gameserver/playermgr.cc b/server/gameserver/playermgr.cc index 7111bb4..44010d9 100644 --- a/server/gameserver/playermgr.cc +++ b/server/gameserver/playermgr.cc @@ -73,8 +73,12 @@ Player* PlayerMgr::CreatePlayerByCMJoin(long ip_saddr, int socket, const cs::CMJ } } #if 1 - for (int skin_id : msg.baseskin()) { - hum->AddSkin(skin_id); + { + int idx = 0; + for (int skin_id : msg.baseskin()) { + hum->SetSkin(idx, skin_id); + ++idx; + } } #else hum->SetSkinInfo(msg.baseskin());