proximityMine.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 ProximityMineData::onThrow( %this, %user, %amount )
  23. {
  24. // Remove the object from the inventory
  25. %user.decInventory( %this, 1 );
  26. // Construct the actual object in the world, and add it to
  27. // the mission group so its cleaned up when the mission is
  28. // done. The object is given a random z rotation.
  29. %obj = new ProximityMine()
  30. {
  31. datablock = %this;
  32. sourceObject = %user;
  33. rotation = "0 0 1 "@ (getRandom() * 360);
  34. static = false;
  35. client = %user.client;
  36. };
  37. MissionCleanup.add(%obj);
  38. return %obj;
  39. }
  40. function ProximityMineData::onTriggered( %this, %obj, %target )
  41. {
  42. //echo(%this.name SPC "triggered by " @ %target.getClassName());
  43. }
  44. function ProximityMineData::onExplode( %this, %obj, %position )
  45. {
  46. // Damage objects within the mine's damage radius
  47. if ( %this.damageRadius > 0 )
  48. radiusDamage( %obj, %position, %this.damageRadius, %this.radiusDamage, %this.damageType, %this.areaImpulse );
  49. }
  50. function ProximityMineData::damage( %this, %obj, %position, %source, %amount, %damageType )
  51. {
  52. // Explode if any damage is applied to the mine
  53. %obj.schedule(50 + getRandom(50), explode);
  54. }
  55. // Customized kill message for deaths caused by proximity mines
  56. function sendMsgClientKilled_MineDamage( %msgType, %client, %sourceClient, %damLoc )
  57. {
  58. if ( %sourceClient $= "" ) // editor placed mine
  59. messageAll( %msgType, '%1 was blown up!', %client.playerName );
  60. else if ( %sourceClient == %client ) // own mine
  61. messageAll( %msgType, '%1 stepped on his own mine!', %client.playerName );
  62. else // enemy placed mine
  63. messageAll( %msgType, '%1 was blown up by %2!', %client.playerName, %sourceClient.playerName );
  64. }
  65. // ----------------------------------------------------------------------------
  66. // Player deployable proximity mine
  67. // ----------------------------------------------------------------------------
  68. // Cannot use the Weapon class for ProximityMineData datablocks as it is already tied
  69. // to ItemData.
  70. function ProxMine::onUse(%this, %obj)
  71. {
  72. // Act like a weapon on use
  73. Weapon::onUse( %this, %obj );
  74. }
  75. function ProxMine::onPickup( %this, %obj, %shape, %amount )
  76. {
  77. // Act like a weapon on pickup
  78. Weapon::onPickup( %this, %obj, %shape, %amount );
  79. }
  80. function ProxMine::onInventory( %this, %obj, %amount )
  81. {
  82. %obj.client.setAmmoAmountHud( 1, %amount );
  83. // Cycle weapons if we are out of ammo
  84. if ( !%amount && ( %slot = %obj.getMountSlot( %this.image ) ) != -1 )
  85. %obj.cycleWeapon( "prev" );
  86. }
  87. function ProxMineImage::onMount( %this, %obj, %slot )
  88. {
  89. // The mine doesn't use ammo from a player's perspective.
  90. %obj.setImageAmmo( %slot, true );
  91. %numMines = %obj.getInventory(%this.item);
  92. %obj.client.RefreshWeaponHud( 1, %this.item.previewImage, %this.item.reticle, %this.item.zoomReticle, %numMines );
  93. }
  94. function ProxMineImage::onUnmount( %this, %obj, %slot )
  95. {
  96. %obj.client.RefreshWeaponHud( 0, "", "" );
  97. }
  98. function ProxMineImage::onFire( %this, %obj, %slot )
  99. {
  100. // To fire a deployable mine is to throw it
  101. %obj.throw( %this.item );
  102. }