seedpackbase.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. void EmptySeedsPackLambda (EntityAI old_item, string new_item_type, PlayerBase player, int count)
  41. {
  42. m_ItemCount = count;
  43. }
  44. override void CopyOldPropertiesToNew (notnull EntityAI old_item, EntityAI new_item)
  45. {
  46. super.CopyOldPropertiesToNew(old_item, new_item);
  47. ItemBase unboxed;
  48. Class.CastTo(unboxed, new_item);
  49. unboxed.SetQuantity(m_ItemCount);
  50. }
  51. override void OnSuccess(EntityAI new_item)
  52. {
  53. super.OnSuccess(new_item);
  54. //spawns wrapping Paper
  55. ItemBase paper = ItemBase.Cast( GetGame().CreateObjectEx("Paper", new_item.GetHierarchyRoot().GetPosition(), ECE_PLACE_ON_SURFACE) );
  56. }
  57. };