Advertisement
twiliteblue

Marine Jump Experiment v1.1

Feb 12th, 2015
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 29.87 KB | None | 0 0
  1. // ======= Copyright (c) 2003-2012, Unknown Worlds Entertainment, Inc. All rights reserved. =======
  2. //
  3. // lua\Marine.lua
  4. //
  5. //    Created by:   Charlie Cleveland (charlie@unknownworlds.com) and
  6. //                  Max McGuire (max@unknownworlds.com)
  7. //
  8. // ========= For more information, visit us at http://www.unknownworlds.com =====================
  9.  
  10. Script.Load("lua/Player.lua")
  11. Script.Load("lua/Mixins/BaseMoveMixin.lua")
  12. Script.Load("lua/Mixins/GroundMoveMixin.lua")
  13. Script.Load("lua/Mixins/JumpMoveMixin.lua")
  14. Script.Load("lua/Mixins/CrouchMoveMixin.lua")
  15. Script.Load("lua/Mixins/LadderMoveMixin.lua")
  16. Script.Load("lua/Mixins/CameraHolderMixin.lua")
  17. Script.Load("lua/OrderSelfMixin.lua")
  18. Script.Load("lua/MarineActionFinderMixin.lua")
  19. Script.Load("lua/StunMixin.lua")
  20. Script.Load("lua/NanoShieldMixin.lua")
  21. Script.Load("lua/SprintMixin.lua")
  22. Script.Load("lua/InfestationTrackerMixin.lua")
  23. Script.Load("lua/WeldableMixin.lua")
  24. Script.Load("lua/ScoringMixin.lua")
  25. Script.Load("lua/UnitStatusMixin.lua")
  26. Script.Load("lua/DissolveMixin.lua")
  27. Script.Load("lua/MapBlipMixin.lua")
  28. Script.Load("lua/VortexAbleMixin.lua")
  29. Script.Load("lua/HiveVisionMixin.lua")
  30. Script.Load("lua/DisorientableMixin.lua")
  31. Script.Load("lua/LOSMixin.lua")
  32. Script.Load("lua/CombatMixin.lua")
  33. Script.Load("lua/SelectableMixin.lua")
  34. Script.Load("lua/ParasiteMixin.lua")
  35. Script.Load("lua/OrdersMixin.lua")
  36. Script.Load("lua/RagdollMixin.lua")
  37. Script.Load("lua/WebableMixin.lua")
  38. Script.Load("lua/CorrodeMixin.lua")
  39. Script.Load("lua/TunnelUserMixin.lua")
  40. Script.Load("lua/PhaseGateUserMixin.lua")
  41. Script.Load("lua/Weapons/PredictedProjectile.lua")
  42. Script.Load("lua/MarineVariantMixin.lua")
  43. Script.Load("lua/MarineOutlineMixin.lua")
  44.  
  45. if Client then
  46.     Script.Load("lua/TeamMessageMixin.lua")
  47. end
  48.  
  49. class 'Marine' (Player)
  50.  
  51. Marine.kMapName = "marine"
  52.  
  53. if Server then
  54.     Script.Load("lua/Marine_Server.lua")
  55. elseif Client then
  56.     Script.Load("lua/Marine_Client.lua")
  57. end
  58.  
  59. PrecacheAsset("models/marine/marine.surface_shader")
  60. PrecacheAsset("models/marine/marine_noemissive.surface_shader")
  61.  
  62. Marine.kFlashlightSoundName = PrecacheAsset("sound/NS2.fev/common/light")
  63. Marine.kGunPickupSound = PrecacheAsset("sound/NS2.fev/marine/common/pickup_gun")
  64. Marine.kSpendResourcesSoundName = PrecacheAsset("sound/NS2.fev/marine/common/player_spend_nanites")
  65. Marine.kChatSound = PrecacheAsset("sound/NS2.fev/marine/common/chat")
  66. Marine.kSoldierLostAlertSound = PrecacheAsset("sound/NS2.fev/marine/voiceovers/soldier_lost")
  67.  
  68. Marine.kFlinchEffect = PrecacheAsset("cinematics/marine/hit.cinematic")
  69. Marine.kFlinchBigEffect = PrecacheAsset("cinematics/marine/hit_big.cinematic")
  70.  
  71. Marine.kHitGroundStunnedSound = PrecacheAsset("sound/NS2.fev/marine/common/jump")
  72. Marine.kSprintStart = PrecacheAsset("sound/NS2.fev/marine/common/sprint_start")
  73. Marine.kSprintTiredEnd = PrecacheAsset("sound/NS2.fev/marine/common/sprint_tired")
  74. //The longer running sound, sprint_start, would be ideally the sprint_end soudn instead. That is what is done here
  75. Marine.kSprintStartFemale = PrecacheAsset("sound/NS2.fev/marine/common/sprint_tired_female")                                                                      
  76. Marine.kSprintTiredEndFemale = PrecacheAsset("sound/NS2.fev/marine/common/sprint_start_female")
  77.  
  78. Marine.kEffectNode = "fxnode_playereffect"
  79. Marine.kHealth = kMarineHealth
  80. Marine.kBaseArmor = kMarineArmor
  81. Marine.kArmorPerUpgradeLevel = kArmorPerUpgradeLevel
  82. Marine.kMaxSprintFov = 95
  83. // Player phase delay - players can only teleport this often
  84. Marine.kPlayerPhaseDelay = 2
  85.  
  86. Marine.kWalkMaxSpeed = 5                // Four miles an hour = 6,437 meters/hour = 1.8 meters/second (increase for FPS tastes)
  87. Marine.kRunMaxSpeed = 6.0               // 10 miles an hour = 16,093 meters/hour = 4.4 meters/second (increase for FPS tastes)
  88. Marine.kRunInfestationMaxSpeed = 5.2    // 10 miles an hour = 16,093 meters/hour = 4.4 meters/second (increase for FPS tastes)
  89.  
  90. // Used to make marine jump vertical speed change less sudden.
  91. kJumpHeightFactor = 0.76
  92. // How fast does our armor get repaired by welders
  93. Marine.kArmorWeldRate = kMarineArmorWeldRate
  94. Marine.kWeldedEffectsInterval = .5
  95.  
  96. Marine.kSpitSlowDuration = 3
  97.  
  98. Marine.kWalkBackwardSpeedScalar = 0.4
  99.  
  100. // start the get up animation after stun before giving back control
  101. Marine.kGetUpAnimationLength = 0
  102.  
  103. // tracked per techId
  104. Marine.kMarineAlertTimeout = 4
  105.  
  106. local kDropWeaponTimeLimit = 1
  107. local kPickupWeaponTimeLimit = 1
  108.  
  109. Marine.kAcceleration = 100
  110. Marine.kSprintAcceleration = 120 // 70
  111. Marine.kSprintInfestationAcceleration = 60
  112.  
  113. Marine.kGroundFrictionForce = 16
  114.  
  115. Marine.kAirStrafeWeight = 2
  116.  
  117. PrecacheAsset("models/marine/rifle/rifle_shell_01.dds")
  118. PrecacheAsset("models/marine/rifle/rifle_shell_01_normal.dds")
  119. PrecacheAsset("models/marine/rifle/rifle_shell_01_spec.dds")
  120. PrecacheAsset("models/marine/rifle/rifle_view_shell.model")
  121. PrecacheAsset("models/marine/rifle/rifle_shell.model")
  122. PrecacheAsset("models/marine/arms_lab/arms_lab_holo.model")
  123. PrecacheAsset("models/effects/frag_metal_01.model")
  124. PrecacheAsset("cinematics/vfx_materials/vfx_circuit_01.dds")
  125. PrecacheAsset("materials/effects/nanoclone.dds")
  126. PrecacheAsset("cinematics/vfx_materials/bugs.dds")
  127. PrecacheAsset("cinematics/vfx_materials/refract_water_01_normal.dds")
  128.  
  129. local networkVars =
  130. {      
  131.     flashlightOn = "boolean",
  132.    
  133.     timeOfLastDrop = "private time",
  134.     timeOfLastPickUpWeapon = "private time",
  135.    
  136.     flashlightLastFrame = "private boolean",
  137.    
  138.     timeLastSpitHit = "private time",
  139.     lastSpitDirection = "private vector",
  140.    
  141.     ruptured = "boolean",
  142.     interruptAim = "private boolean",
  143.     poisoned = "boolean",
  144.     catpackboost = "boolean",
  145.     timeCatpackboost = "private time",
  146.     weaponUpgradeLevel = "integer (0 to 3)",
  147.    
  148.     unitStatusPercentage = "private integer (0 to 100)",
  149.    
  150.     strafeJumped = "private compensated boolean",
  151.    
  152.     timeLastBeacon = "private time",
  153.    
  154. }
  155.  
  156. AddMixinNetworkVars(OrdersMixin, networkVars)
  157. AddMixinNetworkVars(BaseMoveMixin, networkVars)
  158. AddMixinNetworkVars(GroundMoveMixin, networkVars)
  159. AddMixinNetworkVars(JumpMoveMixin, networkVars)
  160. AddMixinNetworkVars(CrouchMoveMixin, networkVars)
  161. AddMixinNetworkVars(LadderMoveMixin, networkVars)
  162. AddMixinNetworkVars(CameraHolderMixin, networkVars)
  163. AddMixinNetworkVars(SelectableMixin, networkVars)
  164. AddMixinNetworkVars(StunMixin, networkVars)
  165. AddMixinNetworkVars(NanoShieldMixin, networkVars)
  166. AddMixinNetworkVars(SprintMixin, networkVars)
  167. AddMixinNetworkVars(OrderSelfMixin, networkVars)
  168. AddMixinNetworkVars(DissolveMixin, networkVars)
  169. AddMixinNetworkVars(VortexAbleMixin, networkVars)
  170. AddMixinNetworkVars(LOSMixin, networkVars)
  171. AddMixinNetworkVars(CombatMixin, networkVars)
  172. AddMixinNetworkVars(ParasiteMixin, networkVars)
  173. AddMixinNetworkVars(WebableMixin, networkVars)
  174. AddMixinNetworkVars(CorrodeMixin, networkVars)
  175. AddMixinNetworkVars(TunnelUserMixin, networkVars)
  176. AddMixinNetworkVars(PhaseGateUserMixin, networkVars)
  177. AddMixinNetworkVars(MarineVariantMixin, networkVars)
  178. AddMixinNetworkVars(ScoringMixin, networkVars)
  179.  
  180. function Marine:OnCreate()
  181.  
  182.     InitMixin(self, BaseMoveMixin, { kGravity = Player.kGravity })
  183.     InitMixin(self, GroundMoveMixin)
  184.     InitMixin(self, JumpMoveMixin)
  185.     InitMixin(self, CrouchMoveMixin)
  186.     InitMixin(self, LadderMoveMixin)
  187.     InitMixin(self, CameraHolderMixin, { kFov = kDefaultFov })
  188.     InitMixin(self, MarineActionFinderMixin)
  189.     InitMixin(self, ScoringMixin, { kMaxScore = kMaxScore })
  190.     InitMixin(self, VortexAbleMixin)
  191.     InitMixin(self, CombatMixin)
  192.     InitMixin(self, SelectableMixin)
  193.    
  194.     Player.OnCreate(self)
  195.    
  196.     InitMixin(self, DissolveMixin)
  197.     InitMixin(self, LOSMixin)
  198.     InitMixin(self, ParasiteMixin)
  199.     InitMixin(self, RagdollMixin)
  200.     InitMixin(self, WebableMixin)
  201.     InitMixin(self, CorrodeMixin)
  202.     InitMixin(self, TunnelUserMixin)
  203.     InitMixin(self, PhaseGateUserMixin)
  204.     InitMixin(self, PredictedProjectileShooterMixin)
  205.     InitMixin(self, MarineVariantMixin)
  206.    
  207.     if Server then
  208.    
  209.         self.timePoisoned = 0
  210.         self.poisoned = false
  211.        
  212.         // stores welder / builder progress
  213.         self.unitStatusPercentage = 0
  214.         self.timeLastUnitPercentageUpdate = 0
  215.        
  216.     elseif Client then
  217.    
  218.         self.flashlight = Client.CreateRenderLight()
  219.        
  220.         self.flashlight:SetType( RenderLight.Type_Spot )
  221.         self.flashlight:SetColor( Color(.8, .8, 1) )
  222.         self.flashlight:SetInnerCone( math.rad(30) )
  223.         self.flashlight:SetOuterCone( math.rad(35) )
  224.         self.flashlight:SetIntensity( 10 )
  225.         self.flashlight:SetRadius( 15 )
  226.         self.flashlight:SetGoboTexture("models/marine/male/flashlight.dds")
  227.        
  228.         self.flashlight:SetIsVisible(false)
  229.        
  230.         InitMixin(self, TeamMessageMixin, { kGUIScriptName = "GUIMarineTeamMessage" })
  231.  
  232.         InitMixin(self, DisorientableMixin)
  233.        
  234.     end
  235.  
  236. end
  237.  
  238. local function UpdateNanoArmor(self)
  239.     self.hasNanoArmor = false // self:GetWeapon(Welder.kMapName)
  240.     return true
  241. end
  242.  
  243. function Marine:GetCanJump()
  244.     return not self:GetIsWebbed() and ( self:GetIsOnGround() or self:GetIsOnLadder() )
  245. end
  246.  
  247. function Marine:OnInitialized()
  248.  
  249.     // work around to prevent the spin effect at the infantry portal spawned from
  250.     // local player should not see the holo marine model
  251.     if Client and Client.GetIsControllingPlayer() then
  252.    
  253.         local ips = GetEntitiesForTeamWithinRange("InfantryPortal", self:GetTeamNumber(), self:GetOrigin(), 1)
  254.         if #ips > 0 then
  255.             Shared.SortEntitiesByDistance(self:GetOrigin(), ips)
  256.             ips[1]:PreventSpinEffect(0.2)
  257.         end
  258.        
  259.     end
  260.    
  261.     // These mixins must be called before SetModel because SetModel eventually
  262.     // calls into OnUpdatePoseParameters() which calls into these mixins.
  263.     // Yay for convoluted class hierarchies!!!
  264.     InitMixin(self, OrdersMixin, { kMoveOrderCompleteDistance = kPlayerMoveOrderCompleteDistance })
  265.     InitMixin(self, OrderSelfMixin, { kPriorityAttackTargets = { "Harvester" } })
  266.     InitMixin(self, StunMixin)
  267.     InitMixin(self, NanoShieldMixin)
  268.     InitMixin(self, SprintMixin)
  269.     InitMixin(self, WeldableMixin)
  270.    
  271.     // SetModel must be called before Player.OnInitialized is called so the attach points in
  272.     // the Marine are valid to attach weapons to. This is far too subtle...
  273.     self:SetModel(self:GetVariantModel(), MarineVariantMixin.kMarineAnimationGraph)
  274.    
  275.     Player.OnInitialized(self)
  276.    
  277.     // Calculate max and starting armor differently
  278.     self.armor = 0
  279.    
  280.     if Server then
  281.    
  282.         self.armor = self:GetArmorAmount()
  283.         self.maxArmor = self.armor
  284.        
  285.         // This Mixin must be inited inside this OnInitialized() function.
  286.         if not HasMixin(self, "MapBlip") then
  287.             InitMixin(self, MapBlipMixin)
  288.         end
  289.        
  290.         InitMixin(self, InfestationTrackerMixin)
  291.         self.timeRuptured = 0
  292.         self.interruptStartTime = 0
  293.         self.timeLastPoisonDamage = 0
  294.        
  295.         self.lastPoisonAttackerId = Entity.invalidId
  296.        
  297.         self:AddTimedCallback(UpdateNanoArmor, 1)
  298.        
  299.     elseif Client then
  300.    
  301.         InitMixin(self, HiveVisionMixin)
  302.         InitMixin(self, MarineOutlineMixin)
  303.        
  304.         self:AddHelpWidget("GUIMarineHealthRequestHelp", 2)
  305.         self:AddHelpWidget("GUIMarineFlashlightHelp", 2)
  306.         self:AddHelpWidget("GUIBuyShotgunHelp", 2)
  307.         // No more auto weld orders.
  308.         //self:AddHelpWidget("GUIMarineWeldHelp", 2)
  309.         self:AddHelpWidget("GUIMapHelp", 1)
  310.         self:AddHelpWidget("GUITunnelEntranceHelp", 1)
  311.        
  312.         self.notifications = { }
  313.         self.timeLastSpitHitEffect = 0
  314.        
  315.     end
  316.    
  317.     self.weaponDropTime = 0
  318.    
  319.     local viewAngles = self:GetViewAngles()
  320.     self.lastYaw = viewAngles.yaw
  321.     self.lastPitch = viewAngles.pitch
  322.    
  323.     // -1 = leftmost, +1 = right-most
  324.     self.horizontalSwing = 0
  325.     // -1 = up, +1 = down
  326.    
  327.     self.timeLastSpitHit = 0
  328.     self.lastSpitDirection = Vector(0, 0, 0)
  329.     self.timeOfLastDrop = 0
  330.     self.timeOfLastPickUpWeapon = 0
  331.     self.ruptured = false
  332.     self.interruptAim = false
  333.     self.catpackboost = false
  334.     self.timeCatpackboost = 0
  335.    
  336.     self.flashlightLastFrame = false
  337.    
  338. end
  339.  
  340. local blockBlackArmor = false
  341. if Server then
  342.     Event.Hook("Console_blockblackarmor", function() if Shared.GetCheatsEnabled() then blockBlackArmor = not blockBlackArmor end end)
  343. end
  344.  
  345. function Marine:GetArmorLevel()
  346.  
  347.     local armorLevel = 0
  348.     local techTree = self:GetTechTree()
  349.  
  350.     if techTree then
  351.    
  352.         local armor3Node = techTree:GetTechNode(kTechId.Armor3)
  353.         local armor2Node = techTree:GetTechNode(kTechId.Armor2)
  354.         local armor1Node = techTree:GetTechNode(kTechId.Armor1)
  355.    
  356.         if armor3Node and armor3Node:GetResearched() then
  357.             armorLevel = 3
  358.         elseif armor2Node and armor2Node:GetResearched()  then
  359.             armorLevel = 2
  360.         elseif armor1Node and armor1Node:GetResearched()  then
  361.             armorLevel = 1
  362.         end
  363.        
  364.     end
  365.  
  366.     return armorLevel
  367.  
  368. end
  369.  
  370. function Marine:GetWeaponLevel()
  371.  
  372.     local weaponLevel = 0
  373.     local techTree = self:GetTechTree()
  374.  
  375.     if techTree then
  376.        
  377.             local weapon3Node = techTree:GetTechNode(kTechId.Weapons3)
  378.             local weapon2Node = techTree:GetTechNode(kTechId.Weapons2)
  379.             local weapon1Node = techTree:GetTechNode(kTechId.Weapons1)
  380.        
  381.             if weapon3Node and weapon3Node:GetResearched() then
  382.                 weaponLevel = 3
  383.             elseif weapon2Node and weapon2Node:GetResearched()  then
  384.                 weaponLevel = 2
  385.             elseif weapon1Node and weapon1Node:GetResearched()  then
  386.                 weaponLevel = 1
  387.             end
  388.            
  389.     end
  390.  
  391.     return weaponLevel
  392.  
  393. end
  394.  
  395. function Marine:GetCanRepairOverride(target)
  396.     return self:GetWeapon(Welder.kMapName) and HasMixin(target, "Weldable") and ( (target:isa("Marine") and target:GetArmor() < target:GetMaxArmor()) or (not target:isa("Marine") and target:GetHealthScalar() < 0.9) )
  397. end
  398.  
  399. function Marine:GetSlowOnLand()
  400.     return true
  401. end
  402.  
  403. function Marine:GetArmorAmount(armorLevels)
  404.  
  405.     if not armorLevels then
  406.    
  407.         armorLevels = 0
  408.    
  409.         if GetHasTech(self, kTechId.Armor3, true) then
  410.             armorLevels = 3
  411.         elseif GetHasTech(self, kTechId.Armor2, true) then
  412.             armorLevels = 2
  413.         elseif GetHasTech(self, kTechId.Armor1, true) then
  414.             armorLevels = 1
  415.         end
  416.    
  417.     end
  418.    
  419.     return Marine.kBaseArmor + armorLevels * Marine.kArmorPerUpgradeLevel
  420.    
  421. end
  422.  
  423. function Marine:GetNanoShieldOffset()
  424.     return Vector(0, -0.1, 0)
  425. end
  426.  
  427. function Marine:OnDestroy()
  428.  
  429.     Player.OnDestroy(self)
  430.    
  431.     if Client then
  432.  
  433.         if self.ruptureMaterial then
  434.        
  435.             Client.DestroyRenderMaterial(self.ruptureMaterial)
  436.             self.ruptureMaterial = nil
  437.            
  438.         end
  439.        
  440.         if self.flashlight ~= nil then
  441.             Client.DestroyRenderLight(self.flashlight)
  442.         end
  443.  
  444.     end
  445.    
  446. end
  447.  
  448. function Marine:HandleButtons(input)
  449.  
  450.     PROFILE("Marine:HandleButtons")
  451.    
  452.     Player.HandleButtons(self, input)
  453.    
  454.     if self:GetCanControl() then
  455.    
  456.         // Update sprinting state
  457.         self:UpdateSprintingState(input)
  458.        
  459.         local flashlightPressed = bit.band(input.commands, Move.ToggleFlashlight) ~= 0
  460.         if not self.flashlightLastFrame and flashlightPressed then
  461.        
  462.             self:SetFlashlightOn(not self:GetFlashlightOn())
  463.             StartSoundEffectOnEntity(Marine.kFlashlightSoundName, self, 1, self)
  464.            
  465.         end
  466.         self.flashlightLastFrame = flashlightPressed
  467.        
  468.         if bit.band(input.commands, Move.Drop) ~= 0 and not self:GetIsVortexed() then
  469.        
  470.             if Server then
  471.            
  472.                 // First check for a nearby weapon to pickup.
  473.                 local nearbyDroppedWeapon = self:GetNearbyPickupableWeapon()
  474.                 if nearbyDroppedWeapon then
  475.                
  476.                     if Shared.GetTime() > self.timeOfLastPickUpWeapon + kPickupWeaponTimeLimit then
  477.                    
  478.                         if nearbyDroppedWeapon.GetReplacementWeaponMapName then
  479.                        
  480.                             local replacement = nearbyDroppedWeapon:GetReplacementWeaponMapName()
  481.                             local toReplace = self:GetWeapon(replacement)
  482.                             if toReplace then
  483.                            
  484.                                 self:RemoveWeapon(toReplace)
  485.                                 DestroyEntity(toReplace)
  486.                                
  487.                             end
  488.                            
  489.                         end
  490.                        
  491.                         self:AddWeapon(nearbyDroppedWeapon, true)
  492.                         StartSoundEffectAtOrigin(Marine.kGunPickupSound, self:GetOrigin())
  493.                        
  494.                         self.timeOfLastPickUpWeapon = Shared.GetTime()
  495.                        
  496.                     end
  497.                    
  498.                 else
  499.                
  500.                     // No nearby weapon, drop our current weapon.
  501.                     self:Drop()
  502.                    
  503.                 end
  504.                
  505.             end
  506.            
  507.         end
  508.        
  509.     end
  510.    
  511. end
  512.  
  513. function Marine:SetFlashlightOn(state)
  514.     self.flashlightOn = state
  515. end
  516.  
  517. function Marine:GetFlashlightOn()
  518.     return self.flashlightOn
  519. end
  520.  
  521. function Marine:GetInventorySpeedScalar()
  522.     return 1 - self:GetWeaponsWeight()
  523. end
  524.  
  525. function Marine:GetCrouchSpeedScalar()
  526.     return Player.kCrouchSpeedScalar
  527. end
  528.  
  529. function Marine:ModifyGroundFraction(groundFraction)
  530.     return groundFraction > 0 and 1 or 0
  531. end
  532.  
  533. function Marine:GetMaxSpeed(possible)
  534.  
  535.     if possible then
  536.         return Marine.kRunMaxSpeed
  537.     end
  538.  
  539.     local sprintingScalar = self:GetSprintingScalar()
  540.     local maxSprintSpeed = Marine.kWalkMaxSpeed + (Marine.kRunMaxSpeed - Marine.kWalkMaxSpeed)*sprintingScalar
  541.     local maxSpeed = ConditionalValue(self:GetIsSprinting(), maxSprintSpeed, Marine.kWalkMaxSpeed)
  542.    
  543.     // Take into account our weapon inventory and current weapon. Assumes a vanilla marine has a scalar of around .8.
  544.     local inventorySpeedScalar = self:GetInventorySpeedScalar() + .17    
  545.     local useModifier = self.isUsing and 0.5 or 1
  546.    
  547.     if self.catpackboost then
  548.         maxSpeed = maxSpeed + kCatPackMoveAddSpeed
  549.     end
  550.    
  551.     return maxSpeed * self:GetSlowSpeedModifier() * inventorySpeedScalar  * useModifier
  552.    
  553. end
  554.  
  555. function Marine:GetFootstepSpeedScalar()
  556.     return Clamp(self:GetVelocityLength() / (Marine.kRunMaxSpeed * self:GetCatalystMoveSpeedModifier() * self:GetSlowSpeedModifier()), 0, 1)
  557. end
  558.  
  559. // Maximum speed a player can move backwards
  560. function Marine:GetMaxBackwardSpeedScalar()
  561.     return Marine.kWalkBackwardSpeedScalar
  562. end
  563.  
  564. function Marine:GetControllerPhysicsGroup()
  565.     return PhysicsGroup.BigPlayerControllersGroup
  566. end
  567.  
  568. function Marine:GetJumpHeight()
  569.     return Player.kJumpHeight - Player.kJumpHeight * self.slowAmount * 0.8
  570. end
  571.  
  572. function Marine:GetCanBeWeldedOverride()
  573.     return not self:GetIsVortexed() and self:GetArmor() < self:GetMaxArmor(), false
  574. end
  575.  
  576. // Returns -1 to 1
  577. function Marine:GetWeaponSwing()
  578.     return self.horizontalSwing
  579. end
  580.  
  581. function Marine:GetWeaponDropTime()
  582.     return self.weaponDropTime
  583. end
  584.  
  585. local marineTechButtons = { kTechId.Attack, kTechId.Move, kTechId.Defend, kTechId.Construct }
  586. function Marine:GetTechButtons(techId)
  587.  
  588.     local techButtons = nil
  589.    
  590.     if techId == kTechId.RootMenu then
  591.         techButtons = marineTechButtons
  592.     end
  593.    
  594.     return techButtons
  595.  
  596. end
  597.  
  598. function Marine:GetChatSound()
  599.     return Marine.kChatSound
  600. end
  601.  
  602. function Marine:GetDeathMapName()
  603.     return MarineSpectator.kMapName
  604. end
  605.  
  606. // Returns the name of the primary weapon
  607. function Marine:GetPlayerStatusDesc()
  608.  
  609.     local status = kPlayerStatus.Void
  610.    
  611.     if (self:GetIsAlive() == false) then
  612.         return kPlayerStatus.Dead
  613.     end
  614.    
  615.     local weapon = self:GetWeaponInHUDSlot(1)
  616.     if (weapon) then
  617.         if (weapon:isa("GrenadeLauncher")) then
  618.             return kPlayerStatus.GrenadeLauncher
  619.         elseif (weapon:isa("Rifle")) then
  620.             return kPlayerStatus.Rifle
  621.         elseif (weapon:isa("Shotgun")) then
  622.             return kPlayerStatus.Shotgun
  623.         elseif (weapon:isa("Flamethrower")) then
  624.             return kPlayerStatus.Flamethrower
  625.         end
  626.     end
  627.    
  628.     return status
  629. end
  630.  
  631. function Marine:GetCanDropWeapon(weapon, ignoreDropTimeLimit)
  632.  
  633.     if not weapon then
  634.         weapon = self:GetActiveWeapon()
  635.     end
  636.    
  637.     if weapon ~= nil and weapon.GetIsDroppable and weapon:GetIsDroppable() then
  638.    
  639.         // Don't drop weapons too fast.
  640.        if ignoreDropTimeLimit or (Shared.GetTime() > (self.timeOfLastDrop + kDropWeaponTimeLimit)) then
  641.            return true
  642.        end
  643.        
  644.    end
  645.    
  646.    return false
  647.    
  648. end
  649.  
  650. function Marine:GetCanUseCatPack()
  651.  
  652.    local enoughTimePassed = self.timeCatpackboost + 6 < Shared.GetTime()
  653.    return not self.catpackboost or enoughTimePassed
  654.    
  655. end
  656.  
  657. // Do basic prediction of the weapon drop on the client so that any client
  658. // effects for the weapon can be dealt with.
  659. function Marine:Drop(weapon, ignoreDropTimeLimit, ignoreReplacementWeapon)
  660.  
  661.    local activeWeapon = self:GetActiveWeapon()
  662.    
  663.    if not weapon then
  664.        weapon = activeWeapon
  665.    end
  666.    
  667.    if self:GetCanDropWeapon(weapon, ignoreDropTimeLimit) then
  668.    
  669.        if weapon == activeWeapon then
  670.            self:SelectNextWeapon()
  671.        end
  672.        
  673.        weapon:OnPrimaryAttackEnd(self)
  674.        
  675.        if Server then
  676.        
  677.            self:RemoveWeapon(weapon)
  678.            
  679.            local weaponSpawnCoords = self:GetAttachPointCoords(Weapon.kHumanAttachPoint)
  680.            weapon:SetCoords(weaponSpawnCoords)
  681.            
  682.        end
  683.        
  684.        // Tell weapon not to be picked up again for a bit
  685.        weapon:Dropped(self)
  686.        
  687.        // Set activity end so we can't drop like crazy
  688.         self.timeOfLastDrop = Shared.GetTime()
  689.        
  690.         if Server then
  691.        
  692.             if ignoreReplacementWeapon ~= true and weapon.GetReplacementWeaponMapName then
  693.            
  694.                 self:GiveItem(weapon:GetReplacementWeaponMapName(), false)
  695.                 // the client expects the next weapon is going to be selected (does not know about the replacement).
  696.                 self:SelectNextWeaponInDirection(1)
  697.                
  698.             end
  699.            
  700.         end
  701.        
  702.         return true
  703.        
  704.     end
  705.    
  706.     return false
  707.    
  708. end
  709.  
  710. function Marine:OnStun()
  711.  
  712.     local activeWeapon = self:GetActiveWeapon()
  713.    
  714.     if activeWeapon then
  715.         activeWeapon:OnHolster(self)
  716.     end
  717.    
  718. end
  719.  
  720. function Marine:OnStunEnd()
  721.  
  722.     local activeWeapon = self:GetActiveWeapon()
  723.    
  724.     if activeWeapon then
  725.         activeWeapon:OnDraw(self)
  726.     end
  727.    
  728. end
  729.  
  730. function Marine:OnHitGroundStunned()
  731.  
  732.     if Server then
  733.         StartSoundEffectOnEntity(Marine.kHitGroundStunnedSound, self)
  734.     end
  735.    
  736. end
  737.  
  738. function Marine:GetWeldPercentageOverride()
  739.     return self:GetArmor() / self:GetMaxArmor()
  740. end
  741.  
  742. function Marine:OnSpitHit(direction)
  743.  
  744.     if Server then
  745.         self.timeLastSpitHit = Shared.GetTime()
  746.         self.lastSpitDirection = direction  
  747.     end
  748.  
  749. end
  750.  
  751. function Marine:GetCanChangeViewAngles()
  752.     return not self:GetIsStunned()
  753. end    
  754.  
  755. function Marine:OnUseTarget(target)
  756.  
  757.     local activeWeapon = self:GetActiveWeapon()
  758.  
  759.     if target and HasMixin(target, "Construct") and ( target:GetCanConstruct(self) or (target.CanBeWeldedByBuilder and target:CanBeWeldedByBuilder()) ) then
  760.    
  761.         if activeWeapon and activeWeapon:GetMapName() ~= Builder.kMapName then
  762.             self:SetActiveWeapon(Builder.kMapName, true)
  763.             self.weaponBeforeUse = activeWeapon:GetMapName()
  764.         end
  765.        
  766.     else
  767.         if activeWeapon and activeWeapon:GetMapName() == Builder.kMapName and self.weaponBeforeUse then
  768.             self:SetActiveWeapon(self.weaponBeforeUse, true)
  769.         end    
  770.     end
  771.  
  772. end
  773.  
  774. function Marine:OnUseEnd()
  775.  
  776.     local activeWeapon = self:GetActiveWeapon()
  777.  
  778.     if activeWeapon and activeWeapon:GetMapName() == Builder.kMapName and self.weaponBeforeUse then
  779.         self:SetActiveWeapon(self.weaponBeforeUse)
  780.     end
  781.  
  782. end
  783.  
  784. function Marine:OnUpdateAnimationInput(modelMixin)
  785.  
  786.     PROFILE("Marine:OnUpdateAnimationInput")
  787.    
  788.     Player.OnUpdateAnimationInput(self, modelMixin)
  789.    
  790.     local animationLength = modelMixin:isa("ViewModel") and 0 or 0.5
  791.    
  792.     if not self:GetIsJumping() and self:GetIsSprinting() then
  793.         modelMixin:SetAnimationInput("move", "sprint")
  794.     end
  795.  
  796.     if self:GetIsStunned() and self:GetRemainingStunTime() > animationLength then
  797.         modelMixin:SetAnimationInput("move", "stun")
  798.     end
  799.    
  800.     local activeWeapon = self:GetActiveWeapon()
  801.     local catalystSpeed = 1
  802.    
  803.     if activeWeapon and activeWeapon.GetCatalystSpeedBase then
  804.         catalystSpeed = activeWeapon:GetCatalystSpeedBase()
  805.     end
  806.    
  807.     if self.catpackboost then
  808.         catalystSpeed = kCatPackWeaponSpeed * catalystSpeed
  809.     end
  810.  
  811.     modelMixin:SetAnimationInput("catalyst_speed", catalystSpeed)
  812.    
  813. end
  814.  
  815. function Marine:GetDeflectMove()
  816.     return true
  817. end    
  818.  
  819. function Marine:ModifyJumpLandSlowDown(slowdownScalar)
  820.  
  821.     if self.strafeJumped then
  822.         slowdownScalar = 0.2 + slowdownScalar
  823.     end
  824.    
  825.     return slowdownScalar
  826.  
  827. end
  828.  
  829. local kStrafeJumpForce = 1
  830. local kStrafeJumpDelay = 0.7
  831. function Marine:ModifyJump(input, velocity, jumpVelocity)
  832.  
  833.     jumpVelocity.y = jumpVelocity.y * kJumpHeightFactor
  834.    
  835.     /*
  836.     local isStrafeJump = input.move.z == 0 and input.move.x ~= 0
  837.     if isStrafeJump and self:GetTimeGroundTouched() + kStrafeJumpDelay < Shared.GetTime() then
  838.    
  839.         local strafeJumpDirection = GetNormalizedVector(self:GetViewCoords():TransformVector(input.move))
  840.         jumpVelocity:Add(strafeJumpDirection * kStrafeJumpForce)
  841.         jumpVelocity.y = jumpVelocity.y * 0.8
  842.         self.strafeJumped = true
  843.        
  844.     else
  845.         self.strafeJumped = false
  846.     end
  847.    
  848.     jumpVelocity:Scale(self:GetSlowSpeedModifier())
  849.     */
  850.    
  851. end
  852.  
  853. function Marine:OnJump()
  854.  
  855.     if self.strafeJumped then
  856.         self:TriggerEffects("strafe_jump", {surface = self:GetMaterialBelowPlayer()})          
  857.     end
  858.  
  859.     self:TriggerEffects("jump", {surface = self:GetMaterialBelowPlayer()})
  860.    
  861. end    
  862.  
  863. function Marine:OnProcessMove(input)
  864.  
  865.     if self.catpackboost then
  866.         self.catpackboost = Shared.GetTime() - self.timeCatpackboost < kCatPackDuration
  867.     end
  868.  
  869.     if Server then
  870.    
  871.         self.ruptured = Shared.GetTime() - self.timeRuptured < Rupture.kDuration
  872.         self.interruptAim  = Shared.GetTime() - self.interruptStartTime < Gore.kAimInterruptDuration
  873.        
  874.         if self.unitStatusPercentage ~= 0 and self.timeLastUnitPercentageUpdate + 2 < Shared.GetTime() then
  875.             self.unitStatusPercentage = 0
  876.         end    
  877.        
  878.         if self.poisoned then
  879.        
  880.             if self:GetIsAlive() and self.timeLastPoisonDamage + 1 < Shared.GetTime() then
  881.            
  882.                 local attacker = Shared.GetEntity(self.lastPoisonAttackerId)
  883.            
  884.                 local currentHealth = self:GetHealth()
  885.                 local poisonDamage = kBitePoisonDamage
  886.                
  887.                 // never kill the marine with poison only
  888.                 if currentHealth - poisonDamage < kPoisonDamageThreshhold then
  889.                     poisonDamage = math.max(0, currentHealth - kPoisonDamageThreshhold)
  890.                 end
  891.                
  892.                 local killedFromDamage, damageDone = self:DeductHealth(poisonDamage, attacker, nil, true)
  893.  
  894.                 if attacker then
  895.                
  896.                     SendDamageMessage( attacker, self, damageDone, self:GetOrigin(), damageDone )
  897.                
  898.                 end
  899.            
  900.                 self.timeLastPoisonDamage = Shared.GetTime()  
  901.                
  902.             end
  903.            
  904.             if self.timePoisoned + kPoisonBiteDuration < Shared.GetTime() then
  905.            
  906.                 self.timePoisoned = 0
  907.                 self.poisoned = false
  908.                
  909.             end
  910.            
  911.         end
  912.        
  913.         // check nano armor
  914.         if not self:GetIsInCombat() and self.hasNanoArmor then            
  915.             self:SetArmor(self:GetArmor() + input.time * kNanoArmorHealPerSecond, true)            
  916.         end
  917.        
  918.     end
  919.    
  920.     Player.OnProcessMove(self, input)
  921.    
  922. end
  923.  
  924. function Marine:GetCanSeeDamagedIcon(ofEntity)
  925.     return HasMixin(ofEntity, "Weldable")
  926. end
  927.  
  928. function Marine:GetIsInterrupted()
  929.     return self.interruptAim
  930. end
  931.  
  932. function Marine:OnPostUpdateCamera(deltaTime)
  933.  
  934.     if self:GetIsStunned() then
  935.         self:SetDesiredCameraYOffset(-1.3)
  936.     end
  937.    
  938. end
  939.  
  940. function Marine:GetHasCatpackBoost()
  941.     return self.catpackboost
  942. end
  943.  
  944. // dont allow marines to me chain stomped. this gives them breathing time and the onos needs to time the stomps instead of spamming
  945. // and being able to permanently disable the marine
  946. function Marine:GetIsStunAllowed()
  947.     return not self.timeLastStun or self.timeLastStun + kDisruptMarineTimeout < Shared.GetTime() and not self:GetIsVortexed()
  948. end
  949.  
  950. function Marine:ModifyGravityForce(gravityTable)
  951.     // Apply no gravity for the first 0.1 second after a jump. This allows marine to have reduced jumping impulse while keeping the same jump height!
  952.     if self:GetIsOnGround() or self:GetRecentlyJumped() then
  953.         gravityTable.gravity = 0
  954.     end
  955. end
  956.  
  957. Shared.LinkClassToMap("Marine", Marine.kMapName, networkVars, true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement