DayZ 1.27
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
43 {
44 m_ConditionItem = new CCINonRuined();
45 m_ConditionTarget = new CCTCursorNoRuinCheck();
46 }
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 GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Call(GetGame().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;
96 MiscGameplayFunctions.GetHeadBonePos(player,posHead);
97 vector posRandom = MiscGameplayFunctions.GetRandomizedPositionVerified(posHead,body_pos,UAItemsSpreadRadius.NARROW,player);
98 Class.CastTo(added_item, GetGame().CreateObjectEx(item_to_spawn, posRandom, ECE_PLACE_ON_SURFACE));
99
100 // Check if skinning is configured for this body
101 if (!added_item)
102 return null;
103
104 // Set item's quantity from config, if it's defined there.
105 float item_quantity = 0;
106 array<float> quant_min_max = new array<float>;
107 array<float> quant_min_max_coef = new array<float>;
108
109 GetGame().ConfigGetFloatArray(cfg_skinning_organ_class + "quantityMinMax", quant_min_max);
110 GetGame().ConfigGetFloatArray(cfg_skinning_organ_class + "quantityMinMaxCoef", quant_min_max_coef);
111
112 // Read config for quantity value
113 if (quant_min_max.Count() > 0)
114 {
115 float soft_skill_manipulated_value = (quant_min_max.Get(0)+ quant_min_max.Get(1)) / 2;
116 item_quantity = Math.RandomFloat(soft_skill_manipulated_value, quant_min_max.Get(1));
117 }
118
119 if (quant_min_max_coef.Count() > 0)
120 {
121 float coef = Math.RandomFloat(quant_min_max_coef.Get(0), quant_min_max_coef.Get(1));
122 item_quantity = added_item.GetQuantityMax() * coef;
123 }
124
125 if (GetGame().ConfigGetFloat(cfg_skinning_organ_class + "quantity") > 0)
126 item_quantity = g_Game.ConfigGetFloat(cfg_skinning_organ_class + "quantity");
127
128 if (GetGame().ConfigGetFloat(cfg_skinning_organ_class + "quantityCoef") > 0)
129 {
130 float coef2 = g_Game.ConfigGetFloat(cfg_skinning_organ_class + "quantityCoef");
131 item_quantity = added_item.GetQuantityMax() * coef2;
132 }
133
134 if (item_quantity > 0)
135 {
136 item_quantity = Math.Round(item_quantity);
137 added_item.SetQuantity(item_quantity, false);
138 }
139
140 // Transfer tool's damage to the item's condition
141 float item_apply_tool_damage_coef = GetGame().ConfigGetFloat(cfg_skinning_organ_class + "transferToolDamageCoef");
142
143 if (item_apply_tool_damage_coef > 0)
144 {
145 float tool_dmg_coef = 1 - tool.GetHealth01();
146 float organ_dmg_coef = tool_dmg_coef * item_apply_tool_damage_coef;
147 added_item.DecreaseHealthCoef(organ_dmg_coef);
148 }
149
150 added_item.InsertAgent(eAgents.SALMONELLA, 1);
151 return added_item;
152 }
153
154 override void OnFinishProgressClient(ActionData action_data)
155 {
156 super.OnFinishProgressClient(action_data);
157
158 if (action_data.m_Target)
159 {
160 Object target_obj = action_data.m_Target.GetObject();
161
162 if (target_obj.IsKindOf("Animal_CapreolusCapreolus") || target_obj.IsKindOf("Animal_CapreolusCapreolusF") || target_obj.IsKindOf("Animal_CervusElaphus") || target_obj.IsKindOf("Animal_CervusElaphusF"))
163 {
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.GetHumanInventory().GetEntityInHands())
176 MiscGameplayFunctions.TransformRestrainItem(body.GetHumanInventory().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 cfg_animal_class_path = "cfgVehicles " + body.GetType() + " " + "Skinning ";
255 vector bodyPosition = body.GetPosition();
256
257 if (!g_Game.ConfigIsExisting(cfg_animal_class_path))
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 child_count = g_Game.ConfigGetChildrenCount(cfg_animal_class_path);
265
266 string item_to_spawn;
267 string cfg_skinning_organ_class;
268 // Parsing of the 'Skinning' class in the config of the dead body
269 for (int i1 = 0; i1 < child_count; i1++)
270 {
271 // To make configuration as convenient as possible, all classes are parsed and parameters are read
272 g_Game.ConfigGetChildName(cfg_animal_class_path, i1, cfg_skinning_organ_class); // out cfg_skinning_organ_class
273 cfg_skinning_organ_class = cfg_animal_class_path + cfg_skinning_organ_class + " ";
274 g_Game.ConfigGetText(cfg_skinning_organ_class + "item", item_to_spawn); // out item_to_spawn
275
276 if (item_to_spawn != "") // 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 item_count = g_Game.ConfigGetInt(cfg_skinning_organ_class + "count");
280
281 array<string> itemZones = new array<string>;
282 array<float> itemCount = new array<float>;
283 float zoneDmg = 0;
284
285 GetGame().ConfigGetTextArray(cfg_skinning_organ_class + "itemZones", itemZones);
286 GetGame().ConfigGetFloatArray(cfg_skinning_organ_class + "countByZone", itemCount);
287
288 if (itemCount.Count() > 0)
289 {
290 item_count = 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 item_count += Math.Floor(zoneDmg);
296 }
297 }
298
299 for (int i2 = 0; i2 < item_count; i2++)
300 {
301 ItemBase spawn_result = CreateOrgan(action_data.m_Player, bodyPosition, item_to_spawn, cfg_skinning_organ_class, action_data.m_MainItem);
302
303 //Damage pelts based on the average values on itemZones
304 //It only works if the "quantityCoef" in the config is more than 0
305 float qtCoeff = GetGame().ConfigGetFloat(cfg_skinning_organ_class + "quantityCoef");
306 if (qtCoeff > 0)
307 {
308 float avgDmgZones = 0;
309 for (int c2 = 0; c2 < itemZones.Count(); c2++)
310 {
311 avgDmgZones += body.GetHealth01(itemZones[c2], "Health");
312 }
313
314 avgDmgZones = avgDmgZones/itemZones.Count(); // Evaluate the average Health
315
316 if (spawn_result)
317 spawn_result.SetHealth01("","", avgDmgZones);
318 }
319
320 // inherit temperature
321 if (body.CanHaveTemperature() && spawn_result.CanHaveTemperature())
322 {
323 spawn_result.SetTemperatureDirect(body.GetTemperature());
324 spawn_result.SetFrozen(body.GetIsFrozen());
325 }
326
327 // handle fat/guts from human bodies
328 if ((item_to_spawn == "Lard") || (item_to_spawn == "Guts"))
329 {
330 if (body.IsKindOf("SurvivorBase"))
331 {
332 spawn_result.InsertAgent(eAgents.BRAIN, 1);
333 }
334 }
335 }
336 }
337 }
338 }
339
340 //DEPRECATED
342 {
343 return body_pos + Vector(Math.RandomFloat01() - 0.5, 0, Math.RandomFloat01() - 0.5);
344 }
345}
InventoryMode
NOTE: PREDICTIVE is not to be used at all in multiplayer.
Определения Inventory.c:22
int m_CommandUID
Определения ActionBase.c:31
int m_StanceMask
Определения ActionBase.c:33
ActionBase ActionData
Определения ActionBase.c:30
void SpawnItems(ActionData action_data)
Определения ActionSkinning.c:249
void DropInventoryItems(PlayerBase body, float newLifetime)
Определения ActionSkinning.c:235
vector GetRandomPos(vector body_pos)
Определения ActionSkinning.c:341
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
class ActionTargets ActionTarget
proto native CEApi GetCEApi()
Get the CE API.
const int ECE_PLACE_ON_SURFACE
Определения CentralEconomy.c:37
DayZGame g_Game
Определения DayZGame.c:3868
eAgents
Определения EAgents.c:3
void PluginLifespan()
Определения PluginLifespan.c:45
PluginBase GetPlugin(typename plugin_type)
Определения PluginManager.c:316
void CreateConditionComponents()
Определения ActionBase.c:230
ActionData m_ActionData
Определения AnimatedActionBase.c:3
void OnFinishProgressClient(ActionData action_data)
Определения ActionContinuousBase.c:287
void OnFinishProgressServer(ActionData action_data)
Определения ActionContinuousBase.c:283
override void CreateActionComponent()
Определения ActionSkinning.c:23
void OnActionFinishedGutDeer()
Определения AnalyticsManagerClient.c:53
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
Определения AnimatedActionBase.c:240
Определения AmmunitionPiles.c:84
Определения CCINonRuined.c:2
proto native float ConfigGetFloat(string path)
Get float value from config on path.
override ScriptCallQueue GetCallQueue(int call_category)
Определения DayZGame.c:1187
proto native void ConfigGetTextArray(string path, out TStringArray values)
Get array of strings from config on path.
AnalyticsManagerClient GetAnalyticsClient()
Определения Game.c:1513
proto native void ConfigGetFloatArray(string path, out TFloatArray values)
Get array of floats from config on path.
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.
Определения Debug.c:122
Определения Debug.c:2
Определения Building.c:6
Определения constants.c:659
override bool SetQuantity(float value, bool destroy_config=true, bool destroy_forced=false, bool allow_client=false, bool clamp_to_stack_max=true)
Определения PileOfWoodenPlanks.c:88
Определения InventoryItem.c:731
Определения EnMath.c:7
Определения ObjectTyped.c:2
Определения PlayerBaseClient.c:2
proto void Call(func fn, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
adds call into the queue with given parameters and arguments (arguments are held in memory until the ...
const float SKINNING
Определения ActionConstants.c:153
const float NARROW
Определения ActionConstants.c:127
const float SKIN
Определения ActionConstants.c:59
Определения ActionConstants.c:28
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Определения EnConvert.c:106
DayZPlayerConstants
defined in C++
Определения dayzplayer.c:602
InventoryTraversalType
tree traversal type, for more see http://en.wikipedia.org/wiki/Tree_traversal
Определения gameplay.c:6
proto native CGame GetGame()
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
Определения constants.c:861
const float DAMAGE_RUINED_VALUE
Определения constants.c:862
const float DAMAGE_DAMAGED_VALUE
Определения constants.c:860
const float DAMAGE_WORN_VALUE
Определения constants.c:859
const int STATE_RUINED
Определения constants.c:846
const int STATE_WORN
Определения constants.c:849
const int STATE_DAMAGED
Определения constants.c:848
const int STATE_BADLY_DAMAGED
Определения constants.c:847
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
Определения tools.c:8