health.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. // Inventory items. These objects rely on the item & inventory support
  23. // system defined in item.cs and inventory.cs
  24. //-----------------------------------------------------------------------------
  25. // Health Patches cannot be picked up and are not meant to be added to inventory.
  26. // Health is applied automatically when an objects collides with a patch.
  27. //-----------------------------------------------------------------------------
  28. function HealthPatch::onCollision(%this, %obj, %col)
  29. {
  30. // Apply health to colliding object if it needs it.
  31. // Works for all shapebase objects.
  32. if (%col.getDamageLevel() != 0 && %col.getState() !$= "Dead")
  33. {
  34. %col.applyRepair(%this.repairAmount);
  35. %obj.respawn();
  36. if (%col.client)
  37. messageClient(%col.client, 'MsgHealthPatchUsed', '\c2Health Patch Applied');
  38. serverPlay3D(HealthUseSound, %obj.getTransform());
  39. }
  40. }
  41. function ShapeBase::tossPatch(%this)
  42. {
  43. //error("ShapeBase::tossPatch(" SPC %this.client.nameBase SPC ")");
  44. if(!isObject(%this))
  45. return;
  46. %item = ItemData::createItem(HealthKitPatch);
  47. %item.sourceObject = %this;
  48. %item.static = false;
  49. MissionCleanup.add(%item);
  50. %vec = (-1.0 + getRandom() * 2.0) SPC (-1.0 + getRandom() * 2.0) SPC getRandom();
  51. %vec = vectorScale(%vec, 10);
  52. %eye = %this.getEyeVector();
  53. %dot = vectorDot("0 0 1", %eye);
  54. if (%dot < 0)
  55. %dot = -%dot;
  56. %vec = vectorAdd(%vec, vectorScale("0 0 8", 1 - %dot));
  57. %vec = vectorAdd(%vec, %this.getVelocity());
  58. %pos = getBoxCenter(%this.getWorldBox());
  59. %item.setTransform(%pos);
  60. %item.applyImpulse(%pos, %vec);
  61. %item.setCollisionTimeout(%this);
  62. //serverPlay3D(%item.getDataBlock().throwSound, %item.getTransform());
  63. %item.schedulePop();
  64. return %item;
  65. }