seedpackbase.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. class SeedPackBase extends Inventory_Base
  2. {
  3. private static const float PACK_DAMAGE_TOLERANCE = 0.5;
  4. void SeedPackBase()
  5. {
  6. }
  7. void EmptySeedPack(PlayerBase player)
  8. {
  9. string pack_type = GetType();
  10. string seeds_type = "";
  11. GetGame().ConfigGetText("cfgVehicles " + pack_type + " Horticulture ContainsSeedsType", seeds_type);
  12. int seeds_quantity_max = GetGame().ConfigGetInt("cfgVehicles " + pack_type + " Horticulture ContainsSeedsQuantity");
  13. int seeds_quantity = seeds_quantity_max;
  14. seeds_quantity = Math.Round(seeds_quantity_max * GetHealth01("",""));
  15. if (seeds_quantity < 1)
  16. {
  17. seeds_quantity = 1;
  18. }
  19. if (player)
  20. {
  21. EmptySeedsPackLambda lambda = new EmptySeedsPackLambda(this, seeds_type, player, seeds_quantity);
  22. player.ServerReplaceItemInHandsWithNew(lambda);
  23. }
  24. else
  25. {
  26. vector pos = GetPosition();
  27. GetGame().CreateObjectEx(seeds_type, pos, ECE_PLACE_ON_SURFACE);
  28. GetGame().ObjectDelete(this);
  29. }
  30. }
  31. override void SetActions()
  32. {
  33. super.SetActions();
  34. AddAction(ActionEmptySeedsPack);
  35. }
  36. }
  37. class EmptySeedsPackLambda : ReplaceItemWithNewLambdaBase
  38. {
  39. int m_ItemCount;
  40. PlayerBase m_Player;
  41. void EmptySeedsPackLambda(EntityAI old_item, string new_item_type, PlayerBase player, int count)
  42. {
  43. m_ItemCount = count;
  44. m_Player = player;
  45. }
  46. override void CopyOldPropertiesToNew(notnull EntityAI old_item, EntityAI new_item)
  47. {
  48. super.CopyOldPropertiesToNew(old_item, new_item);
  49. ItemBase unboxed;
  50. Class.CastTo(unboxed, new_item);
  51. unboxed.SetQuantity(m_ItemCount);
  52. }
  53. override void OnSuccess(EntityAI new_item)
  54. {
  55. super.OnSuccess(new_item);
  56. //spawns wrapping Paper
  57. if (m_Player)
  58. {
  59. m_Player.SpawnEntityOnGroundRaycastDispersed("Paper",DEFAULT_SPAWN_DISTANCE,UAItemsSpreadRadius.NARROW);
  60. }
  61. else
  62. {
  63. GetGame().CreateObjectEx("Paper", new_item.GetHierarchyRoot().GetPosition(), ECE_PLACE_ON_SURFACE);
  64. }
  65. }
  66. };