Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. package org.espeon.game.model.content.combat;
  2.  
  3. import org.espeon.game.event.Event;
  4. import org.espeon.game.model.Animation;
  5. import org.espeon.game.model.Damage.HitType;
  6. import org.espeon.game.model.Entity;
  7. import org.espeon.game.model.World;
  8.  
  9. /**
  10. *
  11. * @author Encouragin
  12. *
  13. * Represents the actual combat.
  14. *
  15. * @param <T> The entity this combat system is for.
  16. */
  17.  
  18. public final class Combat<T extends Entity> {
  19. /**
  20. * The attacker.
  21. */
  22. private T attacker;
  23.  
  24. /**
  25. * Assign a new combat system for a single entity.
  26. * @param attacker The attacker.
  27. */
  28. public Combat(final T attacker) {
  29. this.attacker = attacker;
  30. }
  31.  
  32. /**
  33. * Check if we're ready to attack.
  34. * @param victim The selected victim of the attacker.
  35. */
  36. public boolean isAvailableToAttack(final Entity victim) {
  37. /**
  38. * Check if either the attacker or victim are
  39. * returned dead in-game.
  40. */
  41. if (attacker.isDead() || victim.isDead()) {
  42. return false;
  43. }
  44. return true;
  45. }
  46.  
  47. /**
  48. * Attack the attacker's victim with a melee attack.
  49. * @param victim The selected victim of the attacker.
  50. */
  51. public void attackWithMelee(final Entity victim) {
  52. /**
  53. * Let the attacker perform a combat animation.
  54. */
  55. attacker.playAnimation(Animation.create(422, 0));
  56. /**
  57. * Submit a damage delaying event. This event is for
  58. * in-game combat perfection. We submit a event within
  59. * the played animation and the appearance of the damage
  60. * hit.
  61. */
  62. World.getWorld().submit(new Event(900) {
  63. @Override
  64. public void execute() {
  65. /**
  66. * Let a damage hit appear on the victim's
  67. * virtual body.
  68. */
  69. victim.inflictDamage(10, HitType.NORMAL_DAMAGE);
  70. /**
  71. * Stop the event.
  72. */
  73. this.stop();
  74. }
  75. });
  76. }
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement