actionskinning.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. /*
  2. Example of skinning config which should be inside animal's base class:
  3. class 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. // Make sure to have only 1 of the following quantity paramenter
  12. quantity = 100; // Optional: Set item's quantity
  13. quantityCoef = 1; // Optional: Set item's quantity (in coefficient)
  14. quantityMinMax[] = {100, 200}; // Optional: Set item's quantity within min/max values
  15. quantityMinMaxCoef[] = {0, 1}; // Optional: Set item's quantity (in coefficient) within min/max values
  16. };
  17. };
  18. */
  19. class ActionSkinningCB : ActionContinuousBaseCB
  20. {
  21. override void CreateActionComponent()
  22. {
  23. m_ActionData.m_ActionComponent = new CAContinuousTime(UATimeSpent.SKIN);
  24. }
  25. }
  26. class ActionSkinning: ActionContinuousBase
  27. {
  28. void ActionSkinning()
  29. {
  30. m_CallbackClass = ActionSkinningCB;
  31. m_SpecialtyWeight = UASoftSkillsWeight.PRECISE_MEDIUM;
  32. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_ANIMALSKINNING;
  33. m_StanceMask = DayZPlayerConstants.STANCEMASK_CROUCH;
  34. m_FullBody = true;
  35. m_Text = "#skin";
  36. }
  37. override void CreateConditionComponents()
  38. {
  39. m_ConditionItem = new CCINonRuined();
  40. m_ConditionTarget = new CCTCursorNoRuinCheck();
  41. }
  42. override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
  43. {
  44. Object targetObject = target.GetObject();
  45. if (targetObject.CanBeSkinned() && !targetObject.IsAlive())
  46. {
  47. EntityAI target_EAI;
  48. if (Class.CastTo(target_EAI, targetObject) && target_EAI.CanBeSkinnedWith(item))
  49. return true;
  50. }
  51. return false;
  52. }
  53. // Spawns the loot according to the Skinning class in the dead agent's config
  54. override void OnFinishProgressServer(ActionData action_data)
  55. {
  56. super.OnFinishProgressServer(action_data);
  57. Object targetObject = action_data.m_Target.GetObject();
  58. // Mark the body as skinned to forbid another skinning action on it
  59. EntityAI body = EntityAI.Cast(targetObject);
  60. body.SetAsSkinned();
  61. MiscGameplayFunctions.RemoveAllAttachedChildrenByTypename(body, {Bolt_Base});
  62. HandlePlayerBody(action_data);
  63. SpawnItems(action_data);
  64. if (body)
  65. {
  66. GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Call(GetGame().ObjectDelete, body);
  67. }
  68. MiscGameplayFunctions.DealAbsoluteDmg(action_data.m_MainItem, UADamageApplied.SKINNING);
  69. PluginLifespan moduleLifespan = PluginLifespan.Cast(GetPlugin(PluginLifespan));
  70. moduleLifespan.UpdateBloodyHandsVisibility(action_data.m_Player, true);
  71. action_data.m_Player.SetBloodyHandsPenaltyChancePerAgent(eAgents.SALMONELLA, body.GetSkinningBloodInfectionChance(eAgents.SALMONELLA));
  72. }
  73. // Spawns an organ defined in the given config
  74. ItemBase CreateOrgan(PlayerBase player, vector body_pos, string item_to_spawn, string cfg_skinning_organ_class, ItemBase tool)
  75. {
  76. // Create item from config
  77. ItemBase added_item;
  78. vector posHead;
  79. MiscGameplayFunctions.GetHeadBonePos(player,posHead);
  80. vector posRandom = MiscGameplayFunctions.GetRandomizedPositionVerified(posHead,body_pos,UAItemsSpreadRadius.NARROW,player);
  81. Class.CastTo(added_item, GetGame().CreateObjectEx(item_to_spawn, posRandom, ECE_PLACE_ON_SURFACE));
  82. // Check if skinning is configured for this body
  83. if (!added_item)
  84. return null;
  85. // Set item's quantity from config, if it's defined there.
  86. float item_quantity = 0;
  87. array<float> quant_min_max = new array<float>;
  88. array<float> quant_min_max_coef = new array<float>;
  89. GetGame().ConfigGetFloatArray(cfg_skinning_organ_class + "quantityMinMax", quant_min_max);
  90. GetGame().ConfigGetFloatArray(cfg_skinning_organ_class + "quantityMinMaxCoef", quant_min_max_coef);
  91. // Read config for quantity value
  92. if (quant_min_max.Count() > 0)
  93. {
  94. float soft_skill_manipulated_value = (quant_min_max.Get(0)+ quant_min_max.Get(1)) / 2;
  95. item_quantity = Math.RandomFloat(soft_skill_manipulated_value, quant_min_max.Get(1));
  96. }
  97. if (quant_min_max_coef.Count() > 0)
  98. {
  99. float coef = Math.RandomFloat(quant_min_max_coef.Get(0), quant_min_max_coef.Get(1));
  100. item_quantity = added_item.GetQuantityMax() * coef;
  101. }
  102. if (GetGame().ConfigGetFloat(cfg_skinning_organ_class + "quantity") > 0)
  103. item_quantity = g_Game.ConfigGetFloat(cfg_skinning_organ_class + "quantity");
  104. if (GetGame().ConfigGetFloat(cfg_skinning_organ_class + "quantityCoef") > 0)
  105. {
  106. float coef2 = g_Game.ConfigGetFloat(cfg_skinning_organ_class + "quantityCoef");
  107. item_quantity = added_item.GetQuantityMax() * coef2;
  108. }
  109. if (item_quantity > 0)
  110. {
  111. item_quantity = Math.Round(item_quantity);
  112. added_item.SetQuantity(item_quantity, false);
  113. }
  114. // Transfer tool's damage to the item's condition
  115. float item_apply_tool_damage_coef = GetGame().ConfigGetFloat(cfg_skinning_organ_class + "transferToolDamageCoef");
  116. if (item_apply_tool_damage_coef > 0)
  117. {
  118. float tool_dmg_coef = 1 - tool.GetHealth01();
  119. float organ_dmg_coef = tool_dmg_coef * item_apply_tool_damage_coef;
  120. added_item.DecreaseHealthCoef(organ_dmg_coef);
  121. }
  122. added_item.InsertAgent(eAgents.SALMONELLA, 1);
  123. return added_item;
  124. }
  125. override void OnFinishProgressClient(ActionData action_data)
  126. {
  127. super.OnFinishProgressClient(action_data);
  128. if (action_data.m_Target)
  129. {
  130. Object target_obj = action_data.m_Target.GetObject();
  131. if (target_obj.IsKindOf("Animal_CapreolusCapreolus") || target_obj.IsKindOf("Animal_CapreolusCapreolusF") || target_obj.IsKindOf("Animal_CervusElaphus") || target_obj.IsKindOf("Animal_CervusElaphusF"))
  132. {
  133. GetGame().GetAnalyticsClient().OnActionFinishedGutDeer();
  134. }
  135. }
  136. }
  137. //! This section drops all clothes (and attachments) from the dead player before deleting their body
  138. void HandlePlayerBody(ActionData action_data)
  139. {
  140. PlayerBase body;
  141. if (Class.CastTo(body,action_data.m_Target.GetObject()))
  142. {
  143. if (body.IsRestrained() && body.GetHumanInventory().GetEntityInHands())
  144. MiscGameplayFunctions.TransformRestrainItem(body.GetHumanInventory().GetEntityInHands(), null, action_data.m_Player, body);
  145. //Remove splint if target is wearing one
  146. if (body.IsWearingSplint())
  147. {
  148. EntityAI entity = action_data.m_Player.SpawnEntityOnGroundOnCursorDir("Splint", 0.5);
  149. ItemBase newItem = ItemBase.Cast(entity);
  150. EntityAI attachment = body.GetItemOnSlot("Splint_Right");
  151. if (attachment && attachment.GetType() == "Splint_Applied")
  152. {
  153. if (newItem)
  154. {
  155. MiscGameplayFunctions.TransferItemProperties(attachment, newItem);
  156. //Lower health level of splint after use
  157. if (newItem.GetHealthLevel() < 4)
  158. {
  159. int newDmgLevel = newItem.GetHealthLevel() + 1;
  160. float max = newItem.GetMaxHealth("", "");
  161. switch (newDmgLevel)
  162. {
  163. case GameConstants.STATE_BADLY_DAMAGED:
  164. newItem.SetHealth("", "", max * GameConstants.DAMAGE_BADLY_DAMAGED_VALUE);
  165. break;
  166. case GameConstants.STATE_DAMAGED:
  167. newItem.SetHealth("", "", max * GameConstants.DAMAGE_DAMAGED_VALUE);
  168. break;
  169. case GameConstants.STATE_WORN:
  170. newItem.SetHealth("", "", max * GameConstants.DAMAGE_WORN_VALUE);
  171. break;
  172. case GameConstants.STATE_RUINED:
  173. newItem.SetHealth("", "", max * GameConstants.DAMAGE_RUINED_VALUE);
  174. break;
  175. default:
  176. break;
  177. }
  178. }
  179. }
  180. attachment.Delete();
  181. }
  182. }
  183. int deadBodyLifetime;
  184. if (GetCEApi())
  185. {
  186. deadBodyLifetime = GetCEApi().GetCEGlobalInt("CleanupLifetimeDeadPlayer");
  187. if (deadBodyLifetime <= 0)
  188. deadBodyLifetime = 3600;
  189. }
  190. DropInventoryItems(body,deadBodyLifetime);
  191. }
  192. }
  193. void DropInventoryItems(PlayerBase body, float newLifetime)
  194. {
  195. array<EntityAI> children = new array<EntityAI>;
  196. body.GetInventory().EnumerateInventory(InventoryTraversalType.LEVELORDER, children);
  197. foreach (EntityAI child : children)
  198. {
  199. if (child)
  200. {
  201. child.SetLifetime(newLifetime);
  202. body.GetInventory().DropEntity(InventoryMode.SERVER, body, child);
  203. }
  204. }
  205. }
  206. void SpawnItems(ActionData action_data)
  207. {
  208. EntityAI body = EntityAI.Cast(action_data.m_Target.GetObject());
  209. // Get config path to the animal
  210. string cfg_animal_class_path = "cfgVehicles " + body.GetType() + " " + "Skinning ";
  211. vector bodyPosition = body.GetPosition();
  212. if (!g_Game.ConfigIsExisting(cfg_animal_class_path))
  213. {
  214. Debug.Log("Failed to find class 'Skinning' in the config of: " + body.GetType());
  215. return;
  216. }
  217. // Getting item type from the config
  218. int child_count = g_Game.ConfigGetChildrenCount(cfg_animal_class_path);
  219. string item_to_spawn;
  220. string cfg_skinning_organ_class;
  221. // Parsing of the 'Skinning' class in the config of the dead body
  222. for (int i1 = 0; i1 < child_count; i1++)
  223. {
  224. // To make configuration as convenient as possible, all classes are parsed and parameters are read
  225. g_Game.ConfigGetChildName(cfg_animal_class_path, i1, cfg_skinning_organ_class); // out cfg_skinning_organ_class
  226. cfg_skinning_organ_class = cfg_animal_class_path + cfg_skinning_organ_class + " ";
  227. g_Game.ConfigGetText(cfg_skinning_organ_class + "item", item_to_spawn); // out item_to_spawn
  228. if (item_to_spawn != "") // Makes sure to ignore incompatible parameters in the Skinning class of the agent
  229. {
  230. // Spawning items in action_data.m_Player's inventory
  231. int item_count = g_Game.ConfigGetInt(cfg_skinning_organ_class + "count");
  232. array<string> itemZones = new array<string>;
  233. array<float> itemCount = new array<float>;
  234. float zoneDmg = 0;
  235. GetGame().ConfigGetTextArray(cfg_skinning_organ_class + "itemZones", itemZones);
  236. GetGame().ConfigGetFloatArray(cfg_skinning_organ_class + "countByZone", itemCount);
  237. if (itemCount.Count() > 0)
  238. {
  239. item_count = 0;
  240. for (int z = 0; z < itemZones.Count(); z++)
  241. {
  242. zoneDmg = body.GetHealth01(itemZones[z], "Health");
  243. zoneDmg *= itemCount[z]; //just re-using variable
  244. item_count += Math.Floor(zoneDmg);
  245. }
  246. }
  247. for (int i2 = 0; i2 < item_count; i2++)
  248. {
  249. ItemBase spawn_result = CreateOrgan(action_data.m_Player, bodyPosition, item_to_spawn, cfg_skinning_organ_class, action_data.m_MainItem);
  250. //Damage pelts based on the average values on itemZones
  251. //It only works if the "quantityCoef" in the config is more than 0
  252. float qtCoeff = GetGame().ConfigGetFloat(cfg_skinning_organ_class + "quantityCoef");
  253. if (qtCoeff > 0)
  254. {
  255. float avgDmgZones = 0;
  256. for (int c2 = 0; c2 < itemZones.Count(); c2++)
  257. {
  258. avgDmgZones += body.GetHealth01(itemZones[c2], "Health");
  259. }
  260. avgDmgZones = avgDmgZones/itemZones.Count(); // Evaluate the average Health
  261. if (spawn_result)
  262. spawn_result.SetHealth01("","", avgDmgZones);
  263. }
  264. // inherit temperature
  265. if (body.CanHaveTemperature() && spawn_result.CanHaveTemperature())
  266. {
  267. spawn_result.SetTemperatureDirect(body.GetTemperature());
  268. spawn_result.SetFrozen(body.GetIsFrozen());
  269. }
  270. // handle fat/guts from human bodies
  271. if ((item_to_spawn == "Lard") || (item_to_spawn == "Guts"))
  272. {
  273. if (body.IsKindOf("SurvivorBase"))
  274. {
  275. spawn_result.InsertAgent(eAgents.BRAIN, 1);
  276. }
  277. }
  278. }
  279. }
  280. }
  281. }
  282. //DEPRECATED
  283. vector GetRandomPos(vector body_pos)
  284. {
  285. return body_pos + Vector(Math.RandomFloat01() - 0.5, 0, Math.RandomFloat01() - 0.5);
  286. }
  287. }