예제 #1
0
  @EventHandler(priority = EventPriority.NORMAL)
  public void onEntityTarget(EntityTargetEvent event) {
    if (event.isCancelled()) return;

    // If a player is targeted...
    if (!(event.getTarget() instanceof Player)) return;

    // ... by creature that cares about the truce with vampires ...
    if (!(Conf.creatureTypeTruceMonsters.contains(
        EntityUtil.creatureTypeFromEntity(event.getEntity())))) return;

    VPlayer vplayer = VPlayers.i.get((Player) event.getTarget());

    // ... and that player is a vampire ...
    if (!vplayer.isVampire()) return;

    // ... that has not recently done something to break the truce...
    if (vplayer.truceIsBroken()) return;

    // Then the creature will not attack.
    event.setCancelled(true);
  }
예제 #2
0
  /**
   * In this entity-damage-listener we will obtain blood, risk infections and break truce. Those
   * things does never cancel or alter an event so they belong at monitor level.
   */
  @EventHandler(priority = EventPriority.MONITOR)
  public void onEntityDamageMonitor(EntityDamageEvent event) {
    if (event.isCancelled()) return;

    // For further interest this must be a close combat attack by another entity
    if (event.getCause() != DamageCause.ENTITY_ATTACK && event.getCause() != DamageCause.PROJECTILE)
      return;
    if (!(event instanceof EntityDamageByEntityEvent)) return;

    // Define local fields
    Entity damagee = event.getEntity();
    Creature cDamagee;
    Player pDamagee;
    VPlayer vpDamagee;

    EntityDamageByEntityEvent edbeEvent = (EntityDamageByEntityEvent) event;

    Entity damager = edbeEvent.getDamager();
    Player pDamager;
    VPlayer vpDamager;

    // Consider the damager to be the shooter if this is a projectile
    if (damager instanceof Projectile) {
      damager = ((Projectile) damager).getShooter();
    }

    // For further interest that attacker must be a player.
    if (!(damager instanceof Player)) return;

    pDamager = (Player) damager;
    vpDamager = VPlayers.i.get(pDamager);

    if (vpDamager.isVampire()) {
      if (damagee instanceof Player) {
        // A True Blood vampire attacked a normal player. There is risk for infection.
        pDamagee = (Player) damagee;
        vpDamagee = VPlayers.i.get(pDamagee);

        vpDamagee.infectionContractRisk(vpDamager);

        // There will also be blood!
        if (pDamagee.getHealth() > 0) {
          int damage = event.getDamage();
          if (pDamagee.getHealth() < damage) {
            damage = pDamagee.getHealth();
          }
          vpDamager.foodAdd(damage * Conf.foodPerDamageFromPlayer);
          vpDamager.healthAdd(damage * Conf.healthPerDamageFromPlayer);
        }
      } else if (damagee instanceof Creature) {
        // A vampire attacked a creature
        cDamagee = (Creature) damagee;
        CreatureType creatureType = EntityUtil.creatureTypeFromEntity(damagee);

        // Obtain blood?
        if (Conf.foodPerDamageFromCreature.containsKey(creatureType) && cDamagee.getHealth() > 0) {
          int damage = event.getDamage();
          if (cDamagee.getHealth() < damage) {
            damage = cDamagee.getHealth();
          }
          vpDamager.foodAdd(damage * Conf.foodPerDamageFromCreature.get(creatureType));
          vpDamager.healthAdd(damage * Conf.healthPerDamageFromCreature.get(creatureType));
        }

        // Break truce
        if (Conf.creatureTypeTruceMonsters.contains(creatureType)) {
          vpDamager.truceBreak();
        }
      }
    } else if (damagee instanceof Player) {
      pDamagee = (Player) damagee;
      vpDamagee = VPlayers.i.get(pDamagee);

      if (vpDamagee.isVampire()) {
        vpDamager.infectionContractRisk(vpDamager);
      }
    }
  }