Exemplo n.º 1
0
  private void onDamage(Person shooter, int damage, Person person, Room room) {
    int life = person.getLife();
    int armor = person.getArmor();
    if (armor > 0) {
      int armorDamage = damage * 2 / 3;
      person.setArmor(armor - armorDamage);
      damage = damage - armorDamage;
      if (person.getArmor() < 0) {
        damage -= person.getArmor();
        person.setArmor(0);
      }
    }
    person.setLife(life - damage);

    if (person.getLife() <= 0) {
      personService.kill(person, room);
      personService.reward(shooter, person);
    }
  }
Exemplo n.º 2
0
 public void onGetItem(AbstractItem item, Person player) {
   if (!item.isAvailable()) {
     return;
   }
   switch (item.getType()) {
       // weapons
     case "assault":
       handleWeaponPick(player, new AssaultRifle());
       break;
     case "sniper":
       handleWeaponPick(player, new SniperRifle());
       break;
     case "minigun":
       handleWeaponPick(player, new Minigun());
       break;
     case "rocket":
       handleWeaponPick(player, new RocketLauncher());
       break;
     case "flame":
       handleWeaponPick(player, new Flamethrower());
       break;
     case "shotgun":
       handleWeaponPick(player, new Shotgun());
       break;
       // items
     case "medkit":
       int life = player.getLife();
       if (life < 100) {
         life += 25;
         if (life > 100) {
           life = 100;
         }
       } else {
         return;
       }
       player.setLife(life);
       break;
     case "armor":
       int armor = player.getArmor();
       if (armor < 100) {
         armor += 100;
         if (armor > 100) {
           armor = 100;
         }
       } else {
         return;
       }
       player.setArmor(armor);
       break;
     case "helm":
       int armor1 = player.getArmor();
       if (armor1 < 150) {
         armor1 += 50;
         if (armor1 > 150) {
           armor1 = 150;
         }
       } else {
         return;
       }
       player.setArmor(armor1);
       break;
     default:
       throw new RuntimeException("Unknonwn weapon name - " + item.getType());
   }
   item.setAvailable(false);
   item.setTimeout(System.currentTimeMillis() + item.getTime());
 }