add dummyentity.h
This commit is contained in:
parent
707729778e
commit
2a688b5906
@ -94,6 +94,7 @@ enum EntityType_e
|
|||||||
ET_Bullet = 20,
|
ET_Bullet = 20,
|
||||||
|
|
||||||
//ET_Android = 30,
|
//ET_Android = 30,
|
||||||
|
ET_Dummy = 29,
|
||||||
ET_Unuse = 30,
|
ET_Unuse = 30,
|
||||||
ET_MAX
|
ET_MAX
|
||||||
};
|
};
|
||||||
|
@ -2039,6 +2039,11 @@ void Creature::FindLocation()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case ET_Dummy:
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
46
server/gameserver/dummyentity.cc
Normal file
46
server/gameserver/dummyentity.cc
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#include "precompile.h"
|
||||||
|
|
||||||
|
#include "dummyentity.h"
|
||||||
|
|
||||||
|
#include "metatable.pb.h"
|
||||||
|
#include "collider.h"
|
||||||
|
#include "mapservice.h"
|
||||||
|
|
||||||
|
void DummyEntity::Initialize()
|
||||||
|
{
|
||||||
|
Entity::Initialize();
|
||||||
|
std::vector<AabbCollider*> collider_list;
|
||||||
|
if (blocks) {
|
||||||
|
for (auto& obj : *blocks) {
|
||||||
|
switch (obj.shape()) {
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
AabbCollider* collider = new AabbCollider();
|
||||||
|
collider->owner = this;
|
||||||
|
collider->_min = a8::Vec2(obj.x() - obj.width()/10,
|
||||||
|
obj.y() - obj.height()/1.0);
|
||||||
|
collider->_max = a8::Vec2(obj.x() + obj.width()/1.0,
|
||||||
|
obj.y() + obj.height()/1.0);
|
||||||
|
AddEntityCollider(collider);
|
||||||
|
collider_list.push_back(collider);
|
||||||
|
permanent_map_service->AddCollider(collider);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
CircleCollider* collider = new CircleCollider();
|
||||||
|
collider->owner = this;
|
||||||
|
collider->pos = a8::Vec2(obj.x(), obj.y());
|
||||||
|
collider->rad = obj.rad();
|
||||||
|
AddEntityCollider(collider);
|
||||||
|
permanent_map_service->AddCollider(collider);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
17
server/gameserver/dummyentity.h
Normal file
17
server/gameserver/dummyentity.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "entity.h"
|
||||||
|
|
||||||
|
namespace metatable
|
||||||
|
{
|
||||||
|
class MapBlockJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
class DummyEntity : public Entity
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MapService* permanent_map_service = nullptr;
|
||||||
|
std::list<metatable::MapBlockJson>* blocks = nullptr;
|
||||||
|
|
||||||
|
virtual void Initialize() override;
|
||||||
|
};
|
@ -10,6 +10,7 @@
|
|||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "car.h"
|
#include "car.h"
|
||||||
#include "hero.h"
|
#include "hero.h"
|
||||||
|
#include "dummyentity.h"
|
||||||
|
|
||||||
void EntityFactory::Init()
|
void EntityFactory::Init()
|
||||||
{
|
{
|
||||||
@ -96,3 +97,11 @@ Hero* EntityFactory::MakeHero(int entity_uniid)
|
|||||||
hum->entity_type_ = ET_Hero;
|
hum->entity_type_ = ET_Hero;
|
||||||
return hum;
|
return hum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DummyEntity* EntityFactory::MakeDummy(int entity_uniid)
|
||||||
|
{
|
||||||
|
DummyEntity* dummy = new DummyEntity();
|
||||||
|
dummy->uniid_ = entity_uniid;
|
||||||
|
dummy->entity_type_ = ET_Dummy;
|
||||||
|
return dummy;
|
||||||
|
}
|
||||||
|
@ -9,6 +9,7 @@ class Android;
|
|||||||
class Player;
|
class Player;
|
||||||
class Car;
|
class Car;
|
||||||
class Hero;
|
class Hero;
|
||||||
|
class DummyEntity;
|
||||||
class EntityFactory : public a8::Singleton<EntityFactory>
|
class EntityFactory : public a8::Singleton<EntityFactory>
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@ -28,6 +29,7 @@ class EntityFactory : public a8::Singleton<EntityFactory>
|
|||||||
Player* MakePlayer(int entity_uniid);
|
Player* MakePlayer(int entity_uniid);
|
||||||
Car* MakeCar(int entity_uniid);
|
Car* MakeCar(int entity_uniid);
|
||||||
Hero* MakeHero(int entity_uniid);
|
Hero* MakeHero(int entity_uniid);
|
||||||
|
DummyEntity* MakeDummy(int entity_uniid);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "metamgr.h"
|
#include "metamgr.h"
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
#include "entityfactory.h"
|
#include "entityfactory.h"
|
||||||
|
#include "dummyentity.h"
|
||||||
|
|
||||||
const int MAP_GRID_WIDTH = 64;
|
const int MAP_GRID_WIDTH = 64;
|
||||||
|
|
||||||
@ -35,6 +36,7 @@ void MapInstance::Init()
|
|||||||
MAP_GRID_WIDTH);
|
MAP_GRID_WIDTH);
|
||||||
CreateThings();
|
CreateThings();
|
||||||
CreateTerrain();
|
CreateTerrain();
|
||||||
|
CreateBlock();
|
||||||
a8::UdpLog::Instance()->Info
|
a8::UdpLog::Instance()->Info
|
||||||
("map_id:%d current_uniid:%d loots:%d mini_room_spawn_points:%d normal_room_spawn_points:%d "
|
("map_id:%d current_uniid:%d loots:%d mini_room_spawn_points:%d normal_room_spawn_points:%d "
|
||||||
"building_num:%d obstalce_num:%d obstacle0_num:%d "
|
"building_num:%d obstalce_num:%d obstacle0_num:%d "
|
||||||
@ -261,6 +263,18 @@ void MapInstance::CreateTerrain()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MapInstance::CreateBlock()
|
||||||
|
{
|
||||||
|
std::list<metatable::MapBlockJson>* blocks = MetaMgr::Instance()->GetMapBlock(map_meta_->i->map_pic());
|
||||||
|
DummyEntity* dummy = EntityFactory::Instance()->MakeDummy(AllocUniid());
|
||||||
|
dummy->SetPos(a8::Vec2());
|
||||||
|
dummy->permanent_map_service = map_service_;
|
||||||
|
dummy->blocks = blocks;
|
||||||
|
dummy->Initialize();
|
||||||
|
uniid_hash_[dummy->GetUniId()] = dummy;
|
||||||
|
grid_service_->AddPermanentEntity(dummy);
|
||||||
|
}
|
||||||
|
|
||||||
void MapInstance::CreateMapObject(MetaData::MapTplThing& thing_tpl)
|
void MapInstance::CreateMapObject(MetaData::MapTplThing& thing_tpl)
|
||||||
{
|
{
|
||||||
int thing_id = thing_tpl.RandThing();
|
int thing_id = thing_tpl.RandThing();
|
||||||
|
@ -27,6 +27,7 @@ class MapInstance
|
|||||||
private:
|
private:
|
||||||
void CreateThings();
|
void CreateThings();
|
||||||
void CreateTerrain();
|
void CreateTerrain();
|
||||||
|
void CreateBlock();
|
||||||
void CreateMapObject(MetaData::MapTplThing& thing_tpl);
|
void CreateMapObject(MetaData::MapTplThing& thing_tpl);
|
||||||
void CreateBuilding(int thing_id, float building_x, float building_y);
|
void CreateBuilding(int thing_id, float building_x, float building_y);
|
||||||
Obstacle* InternalCreateObstacle(int id, float x, float y, int collider_tag,
|
Obstacle* InternalCreateObstacle(int id, float x, float y, int collider_tag,
|
||||||
|
@ -84,6 +84,7 @@ public:
|
|||||||
std::map<int, MetaData::Drop*> drop_hash;
|
std::map<int, MetaData::Drop*> drop_hash;
|
||||||
std::map<std::string, std::list<metatable::MapTplThingJson>> maptpl_meta_hash;
|
std::map<std::string, std::list<metatable::MapTplThingJson>> maptpl_meta_hash;
|
||||||
std::map<std::string, std::list<metatable::MapLayerJson>> layer_meta_hash;
|
std::map<std::string, std::list<metatable::MapLayerJson>> layer_meta_hash;
|
||||||
|
std::map<std::string, std::list<metatable::MapBlockJson>> block_meta_hash;
|
||||||
std::map<std::string, std::vector<MetaData::MapTplThing>> maptpl_hash;
|
std::map<std::string, std::vector<MetaData::MapTplThing>> maptpl_hash;
|
||||||
std::map<int, MetaData::Dress*> dress_hash;
|
std::map<int, MetaData::Dress*> dress_hash;
|
||||||
std::vector<MetaData::Dress*> dress_vec;
|
std::vector<MetaData::Dress*> dress_vec;
|
||||||
@ -488,6 +489,19 @@ private:
|
|||||||
f8::ReadJsonMetaFile(filename, itr->second);
|
f8::ReadJsonMetaFile(filename, itr->second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
auto itr = block_meta_hash.find(meta.map_pic());
|
||||||
|
if (itr == block_meta_hash.end()) {
|
||||||
|
block_meta_hash[meta.map_pic()] = std::list<metatable::MapBlockJson>();
|
||||||
|
itr = block_meta_hash.find(meta.map_pic());
|
||||||
|
} else {
|
||||||
|
itr->second.clear();
|
||||||
|
}
|
||||||
|
std::string filename = res_path + "map" + meta.map_pic() + ".block.json";
|
||||||
|
if (access(filename.c_str(), F_OK) != -1) {
|
||||||
|
f8::ReadJsonMetaFile(filename, itr->second);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -801,6 +815,12 @@ std::list<metatable::MapLayerJson>* MetaMgr::GetMapLayer(const std::string& map_
|
|||||||
return itr != loader_->layer_meta_hash.end() ? &itr->second : nullptr;
|
return itr != loader_->layer_meta_hash.end() ? &itr->second : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::list<metatable::MapBlockJson>* MetaMgr::GetMapBlock(const std::string& map_name)
|
||||||
|
{
|
||||||
|
auto itr = loader_->block_meta_hash.find(map_name);
|
||||||
|
return itr != loader_->block_meta_hash.end() ? &itr->second : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
std::list<MetaData::AirDrop>& MetaMgr::GetAirDrops()
|
std::list<MetaData::AirDrop>& MetaMgr::GetAirDrops()
|
||||||
{
|
{
|
||||||
return loader_->airdrop_list;
|
return loader_->airdrop_list;
|
||||||
|
@ -34,6 +34,7 @@ class MetaMgr : public a8::Singleton<MetaMgr>
|
|||||||
std::vector<MetaData::MapTplThing>* GetMapTplThing(const std::string& map_name);
|
std::vector<MetaData::MapTplThing>* GetMapTplThing(const std::string& map_name);
|
||||||
metatable::TerrainJson* GetTerrainJson(int map_id);
|
metatable::TerrainJson* GetTerrainJson(int map_id);
|
||||||
std::list<metatable::MapLayerJson>* GetMapLayer(const std::string& map_name);
|
std::list<metatable::MapLayerJson>* GetMapLayer(const std::string& map_name);
|
||||||
|
std::list<metatable::MapBlockJson>* GetMapBlock(const std::string& map_name);
|
||||||
std::list<MetaData::AirDrop>& GetAirDrops();
|
std::list<MetaData::AirDrop>& GetAirDrops();
|
||||||
MetaData::AirDrop* GetAirDrop(int airdrop_id);
|
MetaData::AirDrop* GetAirDrop(int airdrop_id);
|
||||||
std::list<MetaData::AirRaid>& GetAirRaids();
|
std::list<MetaData::AirRaid>& GetAirRaids();
|
||||||
|
@ -428,3 +428,13 @@ message MapLayerJson
|
|||||||
optional int32 height = 3;
|
optional int32 height = 3;
|
||||||
repeated int32 grids = 4;
|
repeated int32 grids = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message MapBlockJson
|
||||||
|
{
|
||||||
|
optional int32 shape = 1;
|
||||||
|
optional float x = 5;
|
||||||
|
optional float y = 6;
|
||||||
|
optional float height = 7;
|
||||||
|
optional float width = 8;
|
||||||
|
optional float rad = 9;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user