physicsShape.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. function PhysicsShapeData::damage(%this, %obj, %sourceObject, %position, %amount, %damageType)
  23. {
  24. // Order of operations is extremely important here!
  25. // Verify that any changes will not cause this method to overflow the stack
  26. // recursively calling itself.
  27. // Note that invulerable, damageRadius, areaImpulse, radiusDamage, and damageType
  28. // are only dynamic fields... This is fine so long as you are only calling
  29. // this method server-side, just keep in mind these fields are NOT networked.
  30. if ( %this.invulnerable ||
  31. %amount < 0 ||
  32. ( %this.minDamageAmount != 0 && %amount < %this.minDamageAmount ) )
  33. return;
  34. // We cannot destroy things twice.
  35. if ( %obj.isDestroyed() )
  36. return;
  37. // This sets a maskbit on the server PhysicsShape which will cause the
  38. // client object to destroy ( spawn debris ) during the next ghost update.
  39. %obj.destroy();
  40. // Single-player hack...
  41. // In a single-player situation the radial impulse NetEvent will
  42. // be applied client-side immediately when we call it, which means it will
  43. // happen before the next ghost update and the debris won't even exist yet!
  44. //
  45. // So we are explicitly calling destroy on the client-side object first,
  46. // before sending the event.
  47. //
  48. if ( %obj.getClientObject() )
  49. %obj.getClientObject().destroy();
  50. if ( %this.damageRadius > 0 )
  51. {
  52. // Send impulse event to affect objects from the explosion of this object.
  53. // Happens server-side and client-side.
  54. if ( %this.areaImpulse > 0 )
  55. RadialImpulseEvent::send( %position, %this.damageRadius, %this.areaImpulse );
  56. // Apply damage to objects from the explosion of this object.
  57. if ( %this.radiusDamage > 0 )
  58. radiusDamage( %obj, %position, %this.damageRadius, %this.radiusDamage, %this.damageType );
  59. }
  60. }