コード例 #1
0
  public void attackPlayerDefender(
      RpgPlayer rpgDefender,
      RpgPlayer rpgAttacker,
      RpgMonster rpgMobAttacker,
      double damage,
      int damageType,
      String typeString) {
    EntityDamageByEntityEvent edbe;
    Player playerDefender = rpgDefender.getPlayer();
    String guildName = "";
    HealthConverter hc = null;
    boolean ignoreArmor = false;
    int guildMemberCount = 0;

    // Get party and member count.
    if (FC_Rpg.guildConfig.getGuildByMember(playerDefender.getName()) != null) {
      guildName = FC_Rpg.guildConfig.getGuildByMember(playerDefender.getName());
      guildMemberCount = FC_Rpg.guildConfig.getOnlineGuildPlayerList(guildName).size();
    } else guildMemberCount = 1;

    // Check to see if the player was recently attacked to make sure he isn't attacked too much.
    if (canAttack(rpgDefender.getLastDamagedLong(), guildMemberCount) == false) return;

    // Refresh player enchants.
    rpgDefender.refreshItemEnchants();

    // Handle immortality effect first.
    if (rpgDefender.playerConfig.getStatusActiveRpgPlayer(SpellEffect.IMMORTAL.getID())) {
      rpgDefender.attemptDamageAvoidNotification(true);
      return;
    }

    // Check if the player has dodge status on them.
    if (rpgDefender.playerConfig.getStatusActiveRpgPlayer(SpellEffect.DODGE.getID())) {
      Random rand = new Random();

      if (rand.nextInt(100)
          < rpgDefender.playerConfig.getStatusMagnitude(SpellEffect.DODGE.getID())) {
        rpgDefender.attemptDamageAvoidNotification(false);
        return;
      }
    }

    if (rpgDefender.playerConfig.getStatusActiveRpgPlayer(SpellEffect.HEAL_CHANCE.getID()))
      rpgDefender.healHealth(
          rpgDefender.playerConfig.maxHealth
              * rpgDefender.playerConfig.getStatusMagnitude(SpellEffect.HEAL_CHANCE.getID()));

    // Set the last damage cause for players.
    if (rpgAttacker != null) {
      // Refresh player enchants.
      rpgAttacker.refreshItemEnchants();

      // Update durability of weapons.
      updateSwordDurabilities(rpgAttacker.getPlayer());

      // Apply false EDBEE
      edbe =
          new EntityDamageByEntityEvent(
              rpgAttacker.getPlayer(), playerDefender, DamageCause.ENTITY_ATTACK, 0);
      playerDefender.setLastDamageCause(edbe);

      // Calculate potions.
      damage *= FC_Rpg.battleCalculations.getPotionOffenseBonus(playerDefender);

      // True gets returned, we ignore armor.
      ignoreArmor =
          rpgAttacker.playerConfig.getStatusActiveRpgPlayer(SpellEffect.IGNORE_ARMOR.getID());
    } else if (rpgMobAttacker != null) {
      // Apply false EDBEE
      edbe =
          new EntityDamageByEntityEvent(
              rpgMobAttacker.getEntity(), rpgDefender.getPlayer(), DamageCause.ENTITY_ATTACK, 0);
      playerDefender.setLastDamageCause(edbe);

      // Handle enchantments for mobs.
      if (damageType == 0)
        damage *=
            FC_Rpg.battleCalculations.getEntityEnchantmentBonus(
                rpgMobAttacker.getEntity(), Enchantment.DAMAGE_ARTHROPODS);

      if (damageType == 1)
        damage *=
            FC_Rpg.battleCalculations.getEntityEnchantmentBonus(
                rpgMobAttacker.getEntity(), Enchantment.ARROW_DAMAGE);

      // Calculate potions.
      damage *= FC_Rpg.battleCalculations.getPotionOffenseBonus(rpgMobAttacker.getEntity());
    }

    // Deal thorns damage before anything is calculated.
    if (rpgDefender.playerConfig.getStatusActiveRpgPlayer(SpellEffect.THORNS.getID())) {
      double thornsDamage =
          damage * rpgDefender.playerConfig.getStatusMagnitude(SpellEffect.THORNS.getID());

      // Attempt a dodge notification
      rpgDefender.attemptThornsNotification(thornsDamage);

      if (rpgAttacker != null) rpgAttacker.dealDamage(thornsDamage);
      else if (rpgMobAttacker != null) rpgMobAttacker.dealDamage(thornsDamage);
    }

    // If the attacker doesn't have the ignore defense status, then...
    if (!ignoreArmor) {
      // Calculate damage based on players armor.
      damage *= FC_Rpg.battleCalculations.getArmorBonus(rpgDefender);

      // Add in enchantment bonuses.
      damage *=
          FC_Rpg.battleCalculations.getArmorEnchantmentBonus(
              playerDefender, Enchantment.PROTECTION_ENVIRONMENTAL);

      if (damageType == 1)
        damage *=
            FC_Rpg.battleCalculations.getArmorEnchantmentBonus(
                playerDefender, Enchantment.PROTECTION_PROJECTILE);
    }

    damage *= FC_Rpg.battleCalculations.getPotionDefenseBonus(playerDefender);

    // Handle block.
    if (playerDefender.isBlocking() == true) {
      // Variable Declaration.
      RpgClass rpgClass = rpgDefender.playerConfig.getRpgClass();

      if (rpgClass != null) {
        if (rpgClass.getPassiveID() == BalanceConfig.passive_StrongerParry)
          damage *=
              FC_Rpg.balanceConfig
                  .getPassivesStrongerParry(); // 25% damage reduction for blocking as defender.
        else damage *= .9; // 10% damage reduction for blocking.
      } else damage *= .9; // 10% damage reduction for blocking.
    }

    // If taunt status is active, then...
    if (rpgDefender.playerConfig.getStatusActiveRpgPlayer(SpellEffect.TAUNT.getID()) == true) {
      // Apply taunt damage reduction.
      damage *= rpgDefender.playerConfig.getStatusMagnitude(SpellEffect.TAUNT.getID());
    }

    // Deal damage greater than 0.
    if (damage < 0.1) damage = 0.1;

    // Deal the damage to the player
    rpgDefender.dealDamage(damage);

    // Perform damage effect.
    playerDefender.playEffect(EntityEffect.HURT);

    if (rpgAttacker != null) {
      handle_Post_Offense_Buffs(rpgAttacker, playerDefender, damage);

      if (playerDefender != null) handle_Post_Offense_Buffs(rpgAttacker, playerDefender, damage);

      rpgAttacker.attemptAttackNotification(
          rpgDefender.getPlayer().getName(),
          rpgDefender.playerConfig.getClassLevel(),
          rpgDefender.playerConfig.curHealth,
          rpgDefender.playerConfig.maxHealth,
          damage);
      applyKnockback(rpgAttacker.getPlayer(), playerDefender, damageType);
    }

    // Set the players health based current health out of maximum health.
    hc =
        new HealthConverter(rpgDefender.playerConfig.maxHealth, rpgDefender.playerConfig.curHealth);

    playerDefender.setHealth(hc.getPlayerHearts());

    // Check armor durabilities for the player defender.
    increaseArmorDurabilities(playerDefender);

    // If the players has 0 health, kill minecraft body and set to dead.
    if (rpgDefender.playerConfig.curHealth < 1) {
      // Damage the player defender.
      playerDefender.damage(10000);

      // Set the player to alive.
      rpgDefender.setIsAlive(false);
    } else {
      if (rpgAttacker != null) {
        rpgDefender.attemptDefenseNotification(
            damage, rpgAttacker.getPlayer().getName(), rpgAttacker.playerConfig.getClassLevel());
        handle_Defense_Passives(damage, rpgDefender, rpgAttacker.getPlayer());
      } else if (rpgMobAttacker != null) {
        rpgDefender.attemptDefenseNotification(
            damage, rpgMobAttacker.getEntity().getType().toString(), rpgMobAttacker.getLevel());
        handle_Defense_Passives(damage, rpgDefender, rpgMobAttacker.getEntity());
      } else {
        rpgDefender.attemptDefenseNotification(damage, typeString, -1);
      }
    }
  }
コード例 #2
0
  // Mob combat
  public void attackMobDefender(
      RpgMonster rpgMobDefender, RpgPlayer rpgAttacker, double damage, int damageType) {
    // Variable Declarations.
    Player playerAttacker = rpgAttacker.getPlayer();
    LivingEntity entityDefender = rpgMobDefender.getEntity();
    String guild = null;
    int partyMemberCount = 1;

    // Make sure that the mob wasn't attacked too recently.
    if (FC_Rpg.guildConfig.getGuildByMember(playerAttacker.getName()) != null) {
      guild = FC_Rpg.guildConfig.getGuildByMember(playerAttacker.getName());
      partyMemberCount = FC_Rpg.guildConfig.getOnlineGuildPlayerList(guild).size();

      if (canAttack(rpgMobDefender.getLastDamagedLong(), partyMemberCount) == false) return;
    }

    // Check to see if the player was recently attacked to make sure he isn't attacked too much.
    if (canAttack(rpgMobDefender.getLastDamagedLong(), partyMemberCount) == false) return;

    // Refresh player enchants.
    rpgAttacker.refreshItemEnchants();

    // If the player has the fire arrow status, then...
    if (rpgAttacker.playerConfig.getStatusActiveRpgPlayer(SpellEffect.FIRE_STRIKE.getID())) {
      // If the mob is alive and not a boss.
      if (rpgMobDefender.getIsBoss() == false && rpgMobDefender.getIsAlive() == true) {
        // Put mob on fire
        ((LivingEntity) entityDefender).setFireTicks(20); // set the mob on fire!

        // Then return
        return;
      }
    }

    // Update sword durabilities.
    updateSwordDurabilities(playerAttacker);

    if (rpgAttacker.playerConfig.getStatusActiveRpgPlayer(
        SpellEffect.CRITICAL_DAMAGE_DOUBLE.getID())) {
      Random rand = new Random();

      // Increase attack damage by its magnitude.
      if (rand.nextInt(100)
          > rpgAttacker.playerConfig.getStatusMagnitude(SpellEffect.CRITICAL_DAMAGE_DOUBLE.getID()))
        damage *= 2;
    }

    // Handle the passives for attacking players.
    damage = handle_Offense_Passives(damage, rpgAttacker, playerAttacker);

    // If the attacker doesn't have the ignore defense status, then...
    if (rpgAttacker.playerConfig.getStatusActiveRpgPlayer(SpellEffect.IGNORE_ARMOR.getID())
        == false) {
      damage *= FC_Rpg.battleCalculations.getArmorBonus(rpgMobDefender);

      // Add in enchantment bonuses.
      damage *=
          FC_Rpg.battleCalculations.getArmorEnchantmentBonus(
              rpgMobDefender.getEntity(), Enchantment.PROTECTION_ENVIRONMENTAL);

      if (damageType == 1)
        damage *=
            FC_Rpg.battleCalculations.getArmorEnchantmentBonus(
                rpgMobDefender.getEntity(), Enchantment.PROTECTION_PROJECTILE);
    }

    // Account for potions.
    damage *= FC_Rpg.battleCalculations.getPotionOffenseBonus(playerAttacker);
    damage *= FC_Rpg.battleCalculations.getPotionDefenseBonus(rpgMobDefender.getEntity());

    // Damage must always be 1 or 0. If it is negative it will heal the creature (not good).
    if (damage < 0.1) damage = 0.1;

    // Find the attacker and deal damage from the attacker to the defender.
    rpgMobDefender.dealDamage(damage);

    // Perform damage effect.
    entityDefender.playEffect(EntityEffect.HURT);

    // Update health for ender dragon and wither bosses.
    if (entityDefender.getType() == EntityType.ENDER_DRAGON) {
      HealthConverter hc =
          new HealthConverter(rpgMobDefender.getMaxHealth(), rpgMobDefender.getCurHealth());
      entityDefender.setHealth(hc.getEnderDragonHearts());
    } else if (entityDefender.getType() == EntityType.WITHER) {
      HealthConverter hc =
          new HealthConverter(rpgMobDefender.getMaxHealth(), rpgMobDefender.getCurHealth());
      entityDefender.setHealth(hc.getWitherHearts());
    }

    // Attempt to send an attack notification.
    rpgAttacker.attemptAttackNotification(
        rpgMobDefender.getEntity().getType().toString(),
        rpgMobDefender.getLevel(),
        rpgMobDefender.getCurHealth(),
        rpgMobDefender.getMaxHealth(),
        damage);

    // Handle berserker class spells
    handle_Post_Offense_Buffs(rpgAttacker, entityDefender, damage);

    if (playerAttacker != null) applyKnockback(playerAttacker, entityDefender, damageType);

    // Put entity damage by entity event on both attacker and defender.
    EntityDamageByEntityEvent edbe =
        new EntityDamageByEntityEvent(playerAttacker, entityDefender, DamageCause.ENTITY_ATTACK, 0);
    playerAttacker.setLastDamageCause(edbe);
    entityDefender.setLastDamageCause(edbe);

    // If the mob has 0 health handle it's death processes AND drop loot.
    if (rpgMobDefender.getCurHealth() <= 0) {
      if (rpgMobDefender.getIsAlive() == false) return;

      rpgMobDefender.setIsAlive(false);

      if (rpgMobDefender.getMobAggressionCheck()) {
        // Give the attacker a mob kill
        rpgAttacker.playerConfig.setLifetimeMobKills(
            rpgAttacker.playerConfig.getLifetimeMobKills() + 1);

        // If the player is in a party, then...
        if (guild != null) FC_Rpg.guildConfig.addMobKill(guild); // Add a mob kill for that party.

        // Give battle winnings
        attemptGiveBattleWinnings(guild, playerAttacker, rpgMobDefender);

        // Don't drop loot if the monster level is too high/low.
        if ((rpgMobDefender.getLevel() - rpgAttacker.playerConfig.getClassLevel())
            > FC_Rpg.balanceConfig.getPowerLevelPrevention() * -1)
          rpgMobDefender.handleHostileMobDrops(
              entityDefender.getLocation()); // Drop rpg items for hostile mobs.
      } else {
        // Drop items for non-hostile mobs.
        if (FC_Rpg.balanceConfig.getDefaultItemDrops() == false)
          rpgMobDefender.handlePassiveMobDrops(entityDefender.getLocation());
      }

      // Drop experience
      rpgMobDefender.dropExperience();

      // Remove the mob
      removeMob(entityDefender);
    }
  }