MCPcopy Create free account
hub / github.com/OpenArkStudio/ARK / CreateEntity

Method CreateEntity

src/plugin/kernel/src/AFCKernelModule.cpp:130–218  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128}
129
130std::shared_ptr<AFIEntity> AFCKernelModule::CreateEntity(const AFGUID& self, const int map_id,
131 const int map_instance_id, const std::string& class_name, const ID_TYPE config_id, const AFIDataList& args)
132{
133 AFGUID object_id = self;
134
135 auto pMapInfo = m_pMapModule->GetMapInfo(map_id);
136 if (pMapInfo == nullptr)
137 {
138 ARK_LOG_ERROR("There is no scene, scene = {}", map_id);
139 return nullptr;
140 }
141
142 if (!pMapInfo->ExistInstance(map_instance_id))
143 {
144 ARK_LOG_ERROR("There is no group, scene = {} group = {}", map_id, map_instance_id);
145 return nullptr;
146 }
147
148 auto pClassMeta = m_pClassModule->FindMeta(class_name);
149 if (nullptr == pClassMeta)
150 {
151 ARK_LOG_ERROR("There is no class meta, name = {}", class_name);
152 return nullptr;
153 }
154
155 std::shared_ptr<AFIStaticEntity> pStaticEntity = nullptr;
156 if (config_id > 0)
157 {
158 auto pStaticEntity = GetStaticEntity(config_id);
159 if (nullptr == pStaticEntity)
160 {
161 ARK_LOG_ERROR("There is no config, config_id = {}", config_id);
162 return nullptr;
163 }
164
165 if (pStaticEntity->GetClassName() != class_name)
166 {
167 ARK_LOG_ERROR("Config class does not match entity class, config_id = {}", config_id);
168 return nullptr;
169 }
170 }
171
172 // check args num
173 size_t arg_count = args.GetCount();
174 if (arg_count % 2 != 0)
175 {
176 ARK_LOG_ERROR("Args count is wrong, count = {}", arg_count);
177 return nullptr;
178 }
179
180 if (object_id == NULL_GUID)
181 {
182 object_id = m_pGUIDModule->CreateGUID();
183 }
184
185 // Check if the entity exists
186 if (GetEntity(object_id) != nullptr)
187 {

Callers 1

CreateAnPlayerAndInitMethod · 0.80

Calls 10

GetMapInfoMethod · 0.80
ExistInstanceMethod · 0.80
CreateGUIDMethod · 0.80
AddEntityToInstanceMethod · 0.80
FindMetaMethod · 0.45
GetCountMethod · 0.45
insertMethod · 0.45
dataMethod · 0.45
GetNodeManagerMethod · 0.45
GetTableManagerMethod · 0.45

Tested by

no test coverage detected