From a7f08b469f8d9377e9ed2b0a4e6205fbca1c7b3a Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 7 Mar 2023 13:22:44 +0800 Subject: [PATCH] 1 --- server/gameserver/constant.h | 1 + server/gameserver/creature.h | 2 +- server/gameserver/mt/Map.cc | 41 ++++++++++++++++++++++++++++++++++++ server/gameserver/mt/Map.h | 3 +++ 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/server/gameserver/constant.h b/server/gameserver/constant.h index 7d9896f0..cc2b11a2 100644 --- a/server/gameserver/constant.h +++ b/server/gameserver/constant.h @@ -235,6 +235,7 @@ enum EquipType_e EQUIP_TYPE_SPOILS = 12, EQUIP_TYPE_SINGAL_EMITTER = 13, EQUIP_TYPE_GIFT_PACKAGE = 14, + EQUIP_TYPE_GEMSTONE = 15, EQUIP_TYPE_End }; diff --git a/server/gameserver/creature.h b/server/gameserver/creature.h index 297fb2f9..1b9173cb 100644 --- a/server/gameserver/creature.h +++ b/server/gameserver/creature.h @@ -109,7 +109,7 @@ class Creature : public MoveableEntity int shield_hp_ = 0; int shield_max_hp_ = 0; - int gemstone = 666; + int gemstone = 0; Creature(); virtual ~Creature() override; diff --git a/server/gameserver/mt/Map.cc b/server/gameserver/mt/Map.cc index 5bb24729..a9f76705 100644 --- a/server/gameserver/mt/Map.cc +++ b/server/gameserver/mt/Map.cc @@ -3,6 +3,7 @@ #include "mt/Map.h" #include "mt/MapCollider.h" #include "mt/SafeArea.h" +#include "mt/MetaMgr.h" IMPL_TABLE(mt::Map) @@ -119,6 +120,7 @@ namespace mt A8_ABORT(); } collider_info = MapCollider::GetByName(map_collider()); + LoadWorldObjects(); } void Map::Init2() @@ -174,4 +176,43 @@ namespace mt return map_id() >= 1002 && map_id() <= 1003; } + void Map::LoadWorldObjects() + { + auto parse_func = + [] (std::shared_ptr node, WorldObject* obj) + { + obj->object_id = node->At("id")->AsXValue(); + auto bounds = node->At("bounds"); + auto center = bounds->At("center"); + auto size = bounds->At("size"); + obj->pos.x = center->At("x")->AsXValue().GetDouble(); + obj->pos.y = center->At("y")->AsXValue().GetDouble(); + obj->pos.z = center->At("z")->AsXValue().GetDouble(); + + obj->size.x = size->At("x")->AsXValue().GetDouble(); + obj->size.y = size->At("y")->AsXValue().GetDouble(); + obj->size.z = size->At("z")->AsXValue().GetDouble(); + }; + + a8::XObject root; + if (root.ReadFromFile(MetaMgr::Instance()->GetResDir() + world_object_file())) { + { + auto thing = root.At("thing"); + for (int i = 0; i < thing->Size(); ++i) { + auto& obj = a8::FastAppend(_world_objects); + obj.object_type = WorldObjectType_e::kBoxType; + parse_func(thing->At(i), &obj); + } + } + { + auto thing = root.At("loot"); + for (int i = 0; i < thing->Size(); ++i) { + auto& obj = a8::FastAppend(_world_objects); + obj.object_type = WorldObjectType_e::kLootType; + parse_func(thing->At(i), &obj); + } + } + } + } + } diff --git a/server/gameserver/mt/Map.h b/server/gameserver/mt/Map.h index 85341698..900a96a5 100644 --- a/server/gameserver/mt/Map.h +++ b/server/gameserver/mt/Map.h @@ -13,6 +13,7 @@ namespace mt int object_id = 0; int object_type = 0; glm::vec3 pos; + glm::vec3 size; float rotation = 0.0f; }; @@ -44,6 +45,8 @@ namespace mt void Init1(); void Init2(); + private: + void LoadWorldObjects(); }; }