DayZ 1.30
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено

◆ SpawnItems()

void SpawnItems ( ActionData action_data)

We only use the first dmg zone to get and set the result item health based of zone health

См. определение в файле ActionSkinning.c строка 249

250 {
251 EntityAI body = EntityAI.Cast(action_data.m_Target.GetObject());
252
253 // Get config path to the animal
254 string cfgAnimalClassPath = "cfgVehicles " + body.GetType() + " " + "Skinning ";
255 vector bodyPosition = body.GetPosition();
256
257 if (!g_Game.ConfigIsExisting(cfgAnimalClassPath))
258 {
259 Debug.Log("Failed to find class 'Skinning' in the config of: " + body.GetType());
260 return;
261 }
262
263 // Getting item type from the config
264 int childCount = g_Game.ConfigGetChildrenCount(cfgAnimalClassPath);
265
266 string itemToSpawn;
267 string cfgSkinningOrganClass;
268 // Parsing of the 'Skinning' class in the config of the dead body
269 for (int i1 = 0; i1 < childCount; i1++)
270 {
271 // To make configuration as convenient as possible, all classes are parsed and parameters are read
272 g_Game.ConfigGetChildName(cfgAnimalClassPath, i1, cfgSkinningOrganClass); // out cfgSkinningOrganClass
273 cfgSkinningOrganClass = cfgAnimalClassPath + cfgSkinningOrganClass + " ";
274 g_Game.ConfigGetText(cfgSkinningOrganClass + "item", itemToSpawn); // out itemToSpawn
275
276 if (itemToSpawn != "") // Makes sure to ignore incompatible parameters in the Skinning class of the agent
277 {
278 // Spawning items in action_data.m_Player's inventory
279 int itemSpawnCount = g_Game.ConfigGetInt(cfgSkinningOrganClass + "count");
280
281 array<string> itemZones = new array<string>;
282 array<float> itemCount = new array<float>;
283 float zoneDmg = 0;
284
285 g_Game.ConfigGetTextArray(cfgSkinningOrganClass + "itemZones", itemZones);
286 g_Game.ConfigGetFloatArray(cfgSkinningOrganClass + "countByZone", itemCount);
287
288 if (itemCount.Count() > 0)
289 {
290 itemSpawnCount = 0;
291 for (int z = 0; z < itemZones.Count(); z++)
292 {
293 zoneDmg = body.GetHealth01(itemZones[z], "Health");
294 zoneDmg *= itemCount[z]; //just re-using variable
295 itemSpawnCount += Math.Floor(zoneDmg);
296 }
297 }
298
299 float transferedPartDmgCoef = g_Game.ConfigGetFloat(cfgSkinningOrganClass + "transferPartDamageCoef");
300 if (transferedPartDmgCoef > 0 && itemSpawnCount <= 0) // Special behavior for headdresses
301 itemSpawnCount = 1;
302
303 for (int i2 = 0; i2 < itemSpawnCount; i2++)
304 {
305 ItemBase spawnResult = CreateOrgan(action_data.m_Player, bodyPosition, itemToSpawn, cfgSkinningOrganClass, action_data.m_MainItem);
306 if (!spawnResult)
307 continue;
308
309 // Damage spawned result item based on the average health value of the body part
310 // It only works if the "transferPartDamageCoef" value in the config is higher than 0
311 if (transferedPartDmgCoef > 0)
312 {
313 float partHealth = 0;
314 float partMaxHealth = 0;
315
317 for (int z2 = 0; z2 < itemZones.Count(); z2++)
318 {
319 partHealth = body.GetHealth(itemZones[z2], "Health");
320 partMaxHealth = body.GetMaxHealth(itemZones[z2], "Health");
321 break;
322 }
323
324 if (partMaxHealth > 0)
325 {
326 float itemMaxHealth = spawnResult.GetMaxHealth("", "Health");
327 float partHealthPercent = (partHealth / partMaxHealth) * 100;
328 float itemHealth = (itemMaxHealth / 100) * partHealthPercent;
329
330 if (transferedPartDmgCoef > 1) // Makes sure to adjust incompatible parameter in the Skinning class of the agent
331 transferedPartDmgCoef = 1;
332
333 float itemHealthCoef = itemHealth * transferedPartDmgCoef;
334 spawnResult.SetHealth("", "Health", itemHealthCoef);
335 }
336 }
337
338 //Damage pelts based on the average values on itemZones
339 //It only works if the "quantityCoef" in the config is more than 0
340 float qtCoeff = g_Game.ConfigGetFloat(cfgSkinningOrganClass + "quantityCoef");
341 if (qtCoeff > 0)
342 {
343 float avgDmgZones = 0;
344 for (int c2 = 0; c2 < itemZones.Count(); c2++)
345 {
346 avgDmgZones += body.GetHealth01(itemZones[c2], "Health");
347 }
348
349 avgDmgZones = avgDmgZones/itemZones.Count(); // Evaluate the average Health
350 spawnResult.SetHealth01("","", avgDmgZones);
351 }
352
353 // inherit temperature
354 if (body.CanHaveTemperature() && spawnResult.CanHaveTemperature())
355 {
356 spawnResult.SetTemperatureDirect(body.GetTemperature());
357 spawnResult.SetFrozen(body.GetIsFrozen());
358 }
359
360 // handle fat/guts from human bodies
361 if ((itemToSpawn == "Lard") || (itemToSpawn == "Guts"))
362 {
363 if (body.IsKindOf("SurvivorBase"))
364 {
365 spawnResult.InsertAgent(eAgents.BRAIN, 1);
366 }
367 }
368 }
369 }
370 }
371 }
ItemBase CreateOrgan(PlayerBase player, vector body_pos, string item_to_spawn, string cfg_skinning_organ_class, ItemBase tool)
Определения ActionSkinning.c:91
DayZGame g_Game
Определения DayZGame.c:4074
eAgents
Определения EAgents.c:3
PlayerBase m_Player
Определения ActionBase.c:40
ref ActionTarget m_Target
Определения ActionBase.c:39
ItemBase m_MainItem
Определения ActionBase.c:35
static void Log(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Prints debug message with normal prio.
Определения 3_Game/DayZ/tools/Debug.c:183
Определения 3_Game/DayZ/tools/Debug.c:2
Определения EnMath.c:7
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Определения EnConvert.c:119
static proto float Floor(float f)
Returns floor of value.

Перекрестные ссылки CreateOrgan(), Math::Floor(), g_Game, Debug::Log(), ActionData::m_MainItem, ActionData::m_Player и ActionData::m_Target.