Advertisement
Vulajin

input handler

Dec 19th, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.15 KB | None | 0 0
  1. // GSGE.Code.Things.PlayerUnit
  2. public void handleInput(InputHandler input)
  3. {
  4. if (base.isAlive())
  5. {
  6. if (input.isDown(Controls.Heal))
  7. {
  8. if (this.m_map.isHub())
  9. {
  10. if (input.wasPressed(Controls.Heal) && World.isTimePast(this.m_lastZoomSwitch + 0.25f + 0.1f))
  11. {
  12. float zoomRequestValue = Camera.getZoomRequestValue("TOWN_VIEW");
  13. if (zoomRequestValue >= 1f)
  14. {
  15. Camera.requestZoom("TOWN_VIEW", 0.5f, 0.25f, 3.40282347E+38f);
  16. }
  17. else if (zoomRequestValue <= 0.5f)
  18. {
  19. Camera.requestZoom("TOWN_VIEW", 1f, 0.25f, 3.40282347E+38f);
  20. }
  21. this.m_lastZoomSwitch = World.getElapsedTime();
  22. AudioManager.PlayCue("CameraZoom");
  23. }
  24. }
  25. else if (!base.InBottomlessPit && !base.isPassedOutOrGettingUp())
  26. {
  27. Weapon weapon = base.fireWeapon(Weapon.SlotType.CONSUMABLE);
  28. InGameUI.onAttackInput(weapon);
  29. }
  30. }
  31. if (this.m_map.isHub() && (input.wasPressed(Controls.PrimaryAttack) || input.wasPressed(Controls.SecondaryAttack) || input.wasPressed(Controls.Shield) || input.wasPressed(Controls.SpecialAttack)))
  32. {
  33. InGameUI.showHud();
  34. }
  35. if (input.wasPressed(Controls.Inventory))
  36. {
  37. InGameUI.showMoneyImmediately();
  38. App.getScreenManager().AddScreen(new SeedInventoryScreen(App.getScreenManager(), null));
  39. return;
  40. }
  41. if (ConfigOptions.UseMouse && !ConfigOptions.UseWASD && input.isDown(Controls.Move))
  42. {
  43. Vector2 screenLocation = input.getCursorLocation();
  44. screenLocation = Functions.convertScreenToWorldLocation(screenLocation);
  45. }
  46. Weapon weapon2 = this.handleUseAndWeaponInput(input);
  47. if (!this.m_player.AllowInput && !ConfigOptions.GodMode)
  48. {
  49. return;
  50. }
  51. if (weapon2 != null && !weapon2.getData().FullyAutomatic && weapon2.getFramesTriggerHeldFor() > 1)
  52. {
  53. weapon2 = null;
  54. }
  55. Vector2 vector = Vector2.Zero;
  56. Vector2 vector2 = Vector2.Zero;
  57. if (!ConfigOptions.UseMouse)
  58. {
  59. vector2 += input.getLeftStickLocation();
  60. }
  61. if (!ConfigOptions.UseMouse || ConfigOptions.UseWASD)
  62. {
  63. vector2 += input.getDirection();
  64. vector = Functions.rotateInput(vector2);
  65. if (ConfigOptions.UseMouse && ConfigOptions.UseWASD && !this.m_strafe && vector != Vector2.Zero)
  66. {
  67. double angle = Functions.getAngle(Vector2.Zero, vector);
  68. double num = Functions.arcDistance(this.m_angle, angle);
  69. if (num < 1.727875996925089 && num > 0.3490658503988659)
  70. {
  71. Vector2 vector3 = Vector2.Subtract(vector, this.m_direction);
  72. vector3.Normalize();
  73. vector3 = Vector2.Multiply(vector3, 0.2f);
  74. vector = Vector2.Add(this.m_direction, vector3);
  75. }
  76. }
  77. }
  78. else
  79. {
  80. if (input.wasPressed(Controls.Stop))
  81. {
  82. this.stopMoving();
  83. }
  84. else if (input.isDown(Controls.Move) && base.canMove() && !this.m_somethingUsed)
  85. {
  86. Vector2 vector4 = input.getCursorLocation();
  87. vector4 = Functions.convertScreenToWorldLocation(vector4);
  88. if (Vector2.Subtract(vector4, this.m_location).LengthSquared() > 256f)
  89. {
  90. this.m_moveTarget = vector4;
  91. AnimationManager.create("MoveMarker", this.m_moveTarget, 0.0);
  92. }
  93. }
  94. if (this.m_moveTarget != Vector2.Zero)
  95. {
  96. vector = this.m_moveTarget - this.m_location;
  97. }
  98. }
  99. double num2 = 0.0;
  100. if (vector != Vector2.Zero)
  101. {
  102. if (this.m_passedOut)
  103. {
  104. this.getUp();
  105. return;
  106. }
  107. if (this.m_hardLandPassedOut)
  108. {
  109. this.hardLandGetUp();
  110. return;
  111. }
  112. num2 = Functions.getAngle(Vector2.Zero, vector);
  113. this.m_lastMoveInputTime = World.getElapsedTime();
  114. base.cancelAnimation(base.m_thingData.FidgetGraphic);
  115. this.setNextFidgetTime();
  116. }
  117. bool flag = false;
  118. float num3 = vector.Length();
  119. if (num3 > 0f)
  120. {
  121. num3 = 1f;
  122. }
  123. if ((weapon2 == null || !weapon2.getData().AutoLockWithMouse) && ConfigOptions.UseMouse && !input.isDown(Controls.Shield))
  124. {
  125. Vector2 vector5 = input.getCursorLocation();
  126. vector5 = Functions.convertScreenToWorldLocation(vector5);
  127. if (!World.isTimePast(this.m_lockUntilTime) || (weapon2 != null && weapon2.getData().SlotType != Weapon.SlotType.MOVE))
  128. {
  129. if (weapon2 != null)
  130. {
  131. this.m_lockUntilTime = World.getElapsedTime() + weapon2.getAutoLockDuration();
  132. }
  133. if (vector5 != Vector2.Zero)
  134. {
  135. flag = true;
  136. double angle2 = Functions.getAngle(base.getLocation(), vector5);
  137. base.setGoalAngle(angle2);
  138. float amount = (float)(Functions.arcDistance(angle2, num2) / 3.1415926535897931);
  139. float num4 = MathHelper.Lerp(1f, this.m_data.BackpedalSpeedModifier, amount);
  140. num3 *= num4;
  141. Weapon weapon3 = weapon2;
  142. if (weapon3 == null)
  143. {
  144. weapon3 = base.LastWeaponFired;
  145. }
  146. if (weapon3 == null || weapon3.getData().ShowLockLine)
  147. {
  148. InGameUI.getPlayerUI(this.m_player.Index).showLockOnLine(this, vector5, 150f);
  149. }
  150. }
  151. }
  152. this.m_lockTarget = null;
  153. }
  154. else
  155. {
  156. Vector2 vector6 = input.getRightStickLocation();
  157. vector6 = Functions.rotateInput(vector6);
  158. Weapon defaultWeapon = this.m_weaponArsenal.getDefaultWeapon(Weapon.SlotType.DEFENSE);
  159. if (!ConfigOptions.UseMouse && vector6.LengthSquared() > 0.0225f && defaultWeapon != null && base.isWeaponAllowed(defaultWeapon.getName()))
  160. {
  161. double angle3 = Functions.getAngle(Vector2.Zero, vector6);
  162. this.m_lockTarget = null;
  163. this.m_incomingProjectiles.Clear();
  164. base.setGoalAngle(angle3);
  165. if (vector2 != Vector2.Zero)
  166. {
  167. flag = true;
  168. }
  169. }
  170. else
  171. {
  172. this.updateLock(input, weapon2);
  173. }
  174. if (this.m_lockTarget != null && this.m_lockTarget.isAlive())
  175. {
  176. flag = true;
  177. double angle4 = Functions.getAngle(this, this.m_lockTarget);
  178. float amount2 = (float)(Functions.arcDistance(angle4, num2) / 3.1415926535897931);
  179. float num5 = MathHelper.Lerp(1f, this.m_data.BackpedalSpeedModifier, amount2);
  180. num3 *= num5;
  181. }
  182. else if (ConfigOptions.UseMouse && ((weapon2 != null && weapon2.getData().AutoLockWithMouse) || (!ConfigOptions.UseWASD && input.isDown(Controls.Shield))))
  183. {
  184. Vector2 vector7 = input.getCursorLocation();
  185. vector7 = Functions.convertScreenToWorldLocation(vector7);
  186. if (vector7 != Vector2.Zero)
  187. {
  188. flag = true;
  189. double angle5 = Functions.getAngle(base.getLocation(), vector7);
  190. base.setGoalAngle(angle5);
  191. if (weapon2 != null && weapon2.getData().ShowLockLine)
  192. {
  193. InGameUI.getPlayerUI(this.m_player.Index).showLockOnLine(this, vector7, 150f);
  194. }
  195. }
  196. }
  197. }
  198. if (this.m_legAnimation != null && this.m_legAnimation.Data.OwnerMoveFractionPlaySpeed > 0f)
  199. {
  200. this.m_legAnimation.PlaySpeed = num3 * this.m_legAnimation.Data.OwnerMoveFractionPlaySpeed;
  201. }
  202. if (this.m_animation.Data.OwnerMoveFractionPlaySpeed > 0f)
  203. {
  204. this.m_animation.PlaySpeed = Math.Min(1f, num3 * this.m_animation.Data.OwnerMoveFractionPlaySpeed);
  205. }
  206. if (num3 > 0f)
  207. {
  208. double num6 = this.m_angle;
  209. if (this.m_animation.shouldMirror())
  210. {
  211. num6 -= (double)this.m_animation.Data.RotateLegs;
  212. }
  213. else
  214. {
  215. num6 += (double)this.m_animation.Data.RotateLegs;
  216. }
  217. this.setMoveStyle(flag, num6, num2);
  218. }
  219. if (this.m_allowInput)
  220. {
  221. if (ConfigOptions.UseMouse && !ConfigOptions.UseWASD)
  222. {
  223. if (this.m_moveTarget != Vector2.Zero && this.m_moveTarget != this.m_location)
  224. {
  225. if (flag)
  226. {
  227. base.moveInput(this.m_moveTarget, num3, flag);
  228. }
  229. else
  230. {
  231. base.moveInput(this.m_moveTarget, num3);
  232. }
  233. }
  234. else
  235. {
  236. base.moveInput(this.m_angle, 0f, flag);
  237. this.m_moveTarget = Vector2.Zero;
  238. }
  239. }
  240. else
  241. {
  242. base.moveInput(num2, num3, flag);
  243. }
  244. }
  245. else
  246. {
  247. this.m_strafe = false;
  248. }
  249. Weapon primaryWeapon = base.getPrimaryWeapon();
  250. if (primaryWeapon != null)
  251. {
  252. primaryWeapon.setAngle(base.getAngle());
  253. }
  254. if (!this.m_allowInput)
  255. {
  256. return;
  257. }
  258. }
  259. if (this.m_animation.getName() == this.m_data.m_thingData.Graphic && World.isTimePast(this.m_nextFidgetTime))
  260. {
  261. base.setAnimation(base.m_thingData.FidgetGraphic);
  262. this.setNextFidgetTime();
  263. }
  264. }
  265.  
  266.  
  267.  
  268.  
  269. // GSGE.Code.Things.PlayerUnit
  270. private Weapon handleUseAndWeaponInput(InputHandler input)
  271. {
  272. if (base.InBottomlessPit)
  273. {
  274. this.m_somethingUsed = false;
  275. return null;
  276. }
  277. if (base.isPassedOutOrGettingUp())
  278. {
  279. this.m_somethingUsed = false;
  280. return null;
  281. }
  282. if (base.TriggerLockedWeapon != null)
  283. {
  284. if (!base.InBottomlessPit && this.getZLocation() <= 0f && !base.TriggerLockedWeapon.isClipEmpty() && base.TriggerLockedWeapon.isEquipped() && (base.TriggerLockedWeapon.hasAmmo() || base.TriggerLockedWeapon.ClipShotNum != 1))
  285. {
  286. this.m_somethingUsed = false;
  287. return base.fireWeapon(base.TriggerLockedWeapon.getData().SlotType);
  288. }
  289. base.TriggerLockedWeapon = null;
  290. }
  291. Weapon weapon = null;
  292. bool flag = true;
  293. Thing useTarget = this.m_player.getUseTarget();
  294. if (useTarget != null && (input.wasPressed(Controls.Use) || (ConfigOptions.UseMouse && input.wasMouseButtonPressed(Controls.MouseButtons.Left) && InGameUI.getPlayerUI(ProfileManager.PlayerIndex).isNearUseIcon(input.getCursorLocationWithHeight(), 70f))))
  295. {
  296. this.m_player.useThing();
  297. this.m_somethingUsed = true;
  298. flag = false;
  299. }
  300. if (this.m_somethingUsed)
  301. {
  302. if (input.isDown(Controls.Use))
  303. {
  304. flag = false;
  305. }
  306. else
  307. {
  308. this.m_somethingUsed = false;
  309. }
  310. }
  311. if (flag)
  312. {
  313. bool flag2 = false;
  314. if (input.wasPressed(Controls.Reload))
  315. {
  316. flag2 = this.manualReload();
  317. }
  318. if (!flag2)
  319. {
  320. if (input.isDown(Controls.SpecialAttack))
  321. {
  322. weapon = base.fireWeapon(Weapon.SlotType.SPECIAL);
  323. InGameUI.onAttackInput(weapon);
  324. if (ConfigOptions.UseMouse && !ConfigOptions.UseWASD && input.wasPressed(Controls.SpecialAttack))
  325. {
  326. this.stopMoving();
  327. }
  328. }
  329. else if ((!ConfigOptions.UseMouse || input.isShiftDown()) && input.isDown(Controls.PrimaryAttack))
  330. {
  331. weapon = base.fireWeapon(Weapon.SlotType.PRIMARY);
  332. InGameUI.onAttackInput(weapon);
  333. if (ConfigOptions.UseMouse && !ConfigOptions.UseWASD && input.wasPressed(Controls.PrimaryAttack))
  334. {
  335. this.stopMoving();
  336. }
  337. }
  338. else if (input.isDown(Controls.PrimaryAttack))
  339. {
  340. weapon = base.fireWeapon(Weapon.SlotType.PRIMARY);
  341. InGameUI.onAttackInput(weapon);
  342. if (ConfigOptions.UseMouse && !ConfigOptions.UseWASD && input.wasPressed(Controls.PrimaryAttack))
  343. {
  344. this.stopMoving();
  345. }
  346. }
  347. else if (this.shouldFireSecondary(input))
  348. {
  349. weapon = base.fireWeapon(Weapon.SlotType.SECONDARY);
  350. InGameUI.onAttackInput(weapon);
  351. if (ConfigOptions.UseMouse && !ConfigOptions.UseWASD && input.wasPressed(Controls.SecondaryAttack))
  352. {
  353. this.stopMoving();
  354. }
  355. }
  356. else if ((!ConfigOptions.UseMouse && input.getRightStickLocation().LengthSquared() > 0.0225f) || input.isDown(Controls.Shield))
  357. {
  358. weapon = base.fireWeapon(Weapon.SlotType.DEFENSE);
  359. InGameUI.onAttackInput(weapon);
  360. if (ConfigOptions.UseMouse && !ConfigOptions.UseWASD && input.wasPressed(Controls.Shield))
  361. {
  362. this.stopMoving();
  363. }
  364. }
  365. else if (input.wasPressed(Controls.Dodge))
  366. {
  367. weapon = base.fireWeapon(Weapon.SlotType.MOVE);
  368. }
  369. }
  370. }
  371. return weapon;
  372. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement