DayZ 1.30
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
ActionSkinning.c
См. документацию.
1/*
2Example of skinning config which should be inside animal's base class:
3class Skinning
4{
5 // All classes in this scope are parsed, so they can have any name.
6 class ObtainedSteaks
7 {
8 item = "DeerSteakMeat"; // item to spawn
9 count = 10; // How many items to spawn
10 transferToolDamageCoef = 1; // Optional: How much tool's damage is transfered to item's damage.
11
12 // Make sure to have only 1 of the following quantity paramenter
13 quantity = 100; // Optional: Set item's quantity
14 quantityCoef = 1; // Optional: Set item's quantity (in coefficient)
15 quantityMinMax[] = {100, 200}; // Optional: Set item's quantity within min/max values
16 quantityMinMaxCoef[] = {0, 1}; // Optional: Set item's quantity (in coefficient) within min/max values
17 };
18};
19*/
20
22{
23 override void CreateActionComponent()
24 {
25 m_ActionData.m_ActionComponent = new CAContinuousTime(UATimeSpent.SKIN);
26 }
27}
28
30{
31 void ActionSkinning()
32 {
33 m_CallbackClass = ActionSkinningCB;
34 m_SpecialtyWeight = UASoftSkillsWeight.PRECISE_MEDIUM;
35
36 m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_ANIMALSKINNING;
37 m_StanceMask = DayZPlayerConstants.STANCEMASK_CROUCH;
38 m_FullBody = true;
39 m_Text = "#skin";
40 }
41
47
48 override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
49 {
50 Object targetObject = target.GetObject();
51
52 if (targetObject.CanBeSkinned() && !targetObject.IsAlive())
53 {
54 EntityAI target_EAI;
55 if (Class.CastTo(target_EAI, targetObject) && target_EAI.CanBeSkinnedWith(item))
56 return true;
57 }
58
59 return false;
60 }
61
62 // Spawns the loot according to the Skinning class in the dead agent's config
63 override void OnFinishProgressServer(ActionData action_data)
64 {
65 super.OnFinishProgressServer(action_data);
66
67 Object targetObject = action_data.m_Target.GetObject();
68
69 // Mark the body as skinned to forbid another skinning action on it
70 EntityAI body = EntityAI.Cast(targetObject);
71 body.SetAsSkinned();
72
73 MiscGameplayFunctions.RemoveAllAttachedChildrenByTypename(body, {Bolt_Base});
74
75 HandlePlayerBody(action_data);
76 SpawnItems(action_data);
77
78 if (body)
79 {
80 g_Game.GetCallQueue(CALL_CATEGORY_SYSTEM).Call(g_Game.ObjectDelete, body);
81 }
82
83 MiscGameplayFunctions.DealAbsoluteDmg(action_data.m_MainItem, UADamageApplied.SKINNING);
84
86 moduleLifespan.UpdateBloodyHandsVisibility(action_data.m_Player, true);
87 action_data.m_Player.SetBloodyHandsPenaltyChancePerAgent(eAgents.SALMONELLA, body.GetSkinningBloodInfectionChance(eAgents.SALMONELLA));
88 }
89
90 // Spawns an organ defined in the given config
91 ItemBase CreateOrgan(PlayerBase player, vector body_pos, string item_to_spawn, string cfg_skinning_organ_class, ItemBase tool)
92 {
93 // Create item from config
94 ItemBase added_item;
95 vector posHead = MiscGameplayFunctions.GetPlayerHeadPosition(player);
96 vector posRandom = MiscGameplayFunctions.GetRandomizedPositionVerified(posHead,body_pos,UAItemsSpreadRadius.NARROW,player);
97 Class.CastTo(added_item, g_Game.CreateObjectEx(item_to_spawn, posRandom, ECE_PLACE_ON_SURFACE));
98
99 // Check if skinning is configured for this body
100 if (!added_item)
101 return null;
102
103 // Set item's quantity from config, if it's defined there.
104 float item_quantity = 0;
105 array<float> quant_min_max = new array<float>;
106 array<float> quant_min_max_coef = new array<float>;
107
108 g_Game.ConfigGetFloatArray(cfg_skinning_organ_class + "quantityMinMax", quant_min_max);
109 g_Game.ConfigGetFloatArray(cfg_skinning_organ_class + "quantityMinMaxCoef", quant_min_max_coef);
110
111 // Read config for quantity value
112 if (quant_min_max.Count() > 0)
113 {
114 float soft_skill_manipulated_value = (quant_min_max.Get(0)+ quant_min_max.Get(1)) / 2;
115 item_quantity = Math.RandomFloat(soft_skill_manipulated_value, quant_min_max.Get(1));
116 }
117
118 if (quant_min_max_coef.Count() > 0)
119 {
120 float coef = Math.RandomFloat(quant_min_max_coef.Get(0), quant_min_max_coef.Get(1));
121 item_quantity = added_item.GetQuantityMax() * coef;
122 }
123
124 if (g_Game.ConfigGetFloat(cfg_skinning_organ_class + "quantity") > 0)
125 item_quantity = g_Game.ConfigGetFloat(cfg_skinning_organ_class + "quantity");
126
127 if (g_Game.ConfigGetFloat(cfg_skinning_organ_class + "quantityCoef") > 0)
128 {
129 float coef2 = g_Game.ConfigGetFloat(cfg_skinning_organ_class + "quantityCoef");
130 item_quantity = added_item.GetQuantityMax() * coef2;
131 }
132
133 if (item_quantity > 0)
134 {
135 item_quantity = Math.Round(item_quantity);
136 added_item.SetQuantity(item_quantity, false);
137 }
138
139 // Transfer tool's damage to the item's condition
140 float item_apply_tool_damage_coef = g_Game.ConfigGetFloat(cfg_skinning_organ_class + "transferToolDamageCoef");
141
142 if (item_apply_tool_damage_coef > 0)
143 {
144 float tool_dmg_coef = 1 - tool.GetHealth01();
145 float organ_dmg_coef = tool_dmg_coef * item_apply_tool_damage_coef;
146 added_item.DecreaseHealthCoef(organ_dmg_coef);
147 }
148
149 added_item.InsertAgent(eAgents.SALMONELLA, 1);
150 return added_item;
151 }
152
153 override void OnFinishProgressClient(ActionData action_data)
154 {
155 super.OnFinishProgressClient(action_data);
156
157 if (action_data.m_Target)
158 {
159 Object targetObj = action_data.m_Target.GetObject();
160
161 AnimalBase skinnedAnimal;
162 if (AnimalBase.CastTo(skinnedAnimal, targetObj) && skinnedAnimal.TrackNaturalInstinctsAchievement())
163 {
164 g_Game.GetAnalyticsClient().OnActionFinishedGutDeer();
165 }
166 }
167 }
168
170 void HandlePlayerBody(ActionData action_data)
171 {
172 PlayerBase body;
173 if (Class.CastTo(body,action_data.m_Target.GetObject()))
174 {
175 if (body.IsRestrained() && body.GetEntityInHands())
176 MiscGameplayFunctions.TransformRestrainItem(body.GetEntityInHands(), null, action_data.m_Player, body);
177
178 //Remove splint if target is wearing one
179 if (body.IsWearingSplint())
180 {
181 EntityAI entity = action_data.m_Player.SpawnEntityOnGroundOnCursorDir("Splint", 0.5);
182 ItemBase newItem = ItemBase.Cast(entity);
183 EntityAI attachment = body.GetItemOnSlot("Splint_Right");
184 if (attachment && attachment.GetType() == "Splint_Applied")
185 {
186 if (newItem)
187 {
188 MiscGameplayFunctions.TransferItemProperties(attachment, newItem);
189 //Lower health level of splint after use
190 if (newItem.GetHealthLevel() < 4)
191 {
192 int newDmgLevel = newItem.GetHealthLevel() + 1;
193 float max = newItem.GetMaxHealth("", "");
194
195 switch (newDmgLevel)
196 {
198 newItem.SetHealth("", "", max * GameConstants.DAMAGE_BADLY_DAMAGED_VALUE);
199 break;
200
202 newItem.SetHealth("", "", max * GameConstants.DAMAGE_DAMAGED_VALUE);
203 break;
204
206 newItem.SetHealth("", "", max * GameConstants.DAMAGE_WORN_VALUE);
207 break;
208
210 newItem.SetHealth("", "", max * GameConstants.DAMAGE_RUINED_VALUE);
211 break;
212
213 default:
214 break;
215 }
216 }
217 }
218
219 attachment.Delete();
220 }
221 }
222
223 int deadBodyLifetime;
224 if (GetCEApi())
225 {
226 deadBodyLifetime = GetCEApi().GetCEGlobalInt("CleanupLifetimeDeadPlayer");
227 if (deadBodyLifetime <= 0)
228 deadBodyLifetime = 3600;
229 }
230
231 DropInventoryItems(body,deadBodyLifetime);
232 }
233 }
234
235 void DropInventoryItems(PlayerBase body, float newLifetime)
236 {
237 array<EntityAI> children = new array<EntityAI>;
238 body.GetInventory().EnumerateInventory(InventoryTraversalType.LEVELORDER, children);
239 foreach (EntityAI child : children)
240 {
241 if (child)
242 {
243 child.SetLifetime(newLifetime);
244 body.GetInventory().DropEntity(InventoryMode.SERVER, body, child);
245 }
246 }
247 }
248
249 void SpawnItems(ActionData action_data)
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 }
372
373 //DEPRECATED
375 {
376 return body_pos + Vector(Math.RandomFloat01() - 0.5, 0, Math.RandomFloat01() - 0.5);
377 }
378}
InventoryMode
NOTE: PREDICTIVE is not to be used at all in multiplayer.
bool m_FullBody
Определения ActionBase.c:60
string m_Text
Определения ActionBase.c:57
void CreateConditionComponents()
Определения ActionBase.c:245
ref CCIBase m_ConditionItem
Определения ActionBase.c:63
float m_SpecialtyWeight
Определения ActionBase.c:77
ref CCTBase m_ConditionTarget
Определения ActionBase.c:64
int m_StanceMask
Определения ActionBase.c:61
void DropInventoryItems(PlayerBase body, float newLifetime)
Определения ActionSkinning.c:235
vector GetRandomPos(vector body_pos)
Определения ActionSkinning.c:374
void HandlePlayerBody(ActionData action_data)
This section drops all clothes (and attachments) from the dead player before deleting their body.
Определения ActionSkinning.c:170
ActionSkinningCB ActionContinuousBaseCB ActionSkinning()
Определения ActionSkinning.c:31
ItemBase CreateOrgan(PlayerBase player, vector body_pos, string item_to_spawn, string cfg_skinning_organ_class, ItemBase tool)
Определения ActionSkinning.c:91
void ActionTarget(Object object, Object parent, int componentIndex, vector cursorHitPos, float utility, string surfaceName="")
Определения ActionTargets.c:125
proto native CEApi GetCEApi()
Get the CE API.
const int ECE_PLACE_ON_SURFACE
Определения CentralEconomy.c:38
void SpawnItems()
Определения ContaminatedArea_Dynamic.c:170
DayZGame g_Game
Определения DayZGame.c:4074
eAgents
Определения EAgents.c:3
void PluginLifespan()
Определения PluginLifespan.c:45
PluginBase GetPlugin(typename plugin_type)
Определения PluginManager.c:326
ActionData m_ActionData
Определения AnimatedActionBase.c:3
void OnFinishProgressClient(ActionData action_data)
Определения ActionContinuousBase.c:293
void OnFinishProgressServer(ActionData action_data)
Определения ActionContinuousBase.c:289
PlayerBase m_Player
Определения ActionBase.c:40
ref ActionTarget m_Target
Определения ActionBase.c:39
ItemBase m_MainItem
Определения ActionBase.c:35
Определения ActionBase.c:22
override void CreateActionComponent()
Определения ActionSkinning.c:23
override bool TrackNaturalInstinctsAchievement()
Определения AnimalBase.c:202
Определения AnimalBase.c:113
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
Определения AnimatedActionBase.c:244
Определения AmmunitionPiles.c:84
Определения CCINonRuined.c:2
Super root of all classes in Enforce script.
Определения EnScript.c:11
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
override bool SetQuantity(float value, bool destroy_config=true, bool destroy_forced=false, bool allow_client=false, bool clamp_to_stack_max=true)
Определения PileOfBricks.c:64
Определения EnMath.c:7
Определения ObjectTyped.c:2
Определения PlayerBaseClient.c:2
const float SKINNING
Определения ActionConstants.c:156
const float NARROW
Определения ActionConstants.c:130
const float SKIN
Определения ActionConstants.c:59
Определения ActionConstants.c:28
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Определения EnConvert.c:119
DayZPlayerConstants
defined in C++
Определения dayzplayer.c:602
InventoryTraversalType
tree traversal type, for more see http://en.wikipedia.org/wiki/Tree_traversal
Определения gameplay.c:6
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
const float DAMAGE_BADLY_DAMAGED_VALUE
Определения 3_Game/DayZ/constants.c:924
const float DAMAGE_RUINED_VALUE
Определения 3_Game/DayZ/constants.c:925
const float DAMAGE_DAMAGED_VALUE
Определения 3_Game/DayZ/constants.c:923
const float DAMAGE_WORN_VALUE
Определения 3_Game/DayZ/constants.c:922
const int STATE_RUINED
Определения 3_Game/DayZ/constants.c:909
const int STATE_WORN
Определения 3_Game/DayZ/constants.c:912
const int STATE_DAMAGED
Определения 3_Game/DayZ/constants.c:911
const int STATE_BADLY_DAMAGED
Определения 3_Game/DayZ/constants.c:910
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static float RandomFloat01()
Returns a random float number between and min [inclusive] and max [inclusive].
Определения EnMath.c:126
static proto float Floor(float f)
Returns floor of value.
static proto float Round(float f)
Returns mathematical round of value.
static proto float RandomFloat(float min, float max)
Returns a random float number between and min[inclusive] and max[exclusive].
const int CALL_CATEGORY_SYSTEM
Определения 3_Game/DayZ/tools/tools.c:8