public double prepareAttacker(EntityDamageByEntityEvent e) { // Variable Declarations/Initializations Arrow arrow = null; List<Spell> spellBook = null; double damage = 0; rpgMobAttacker = null; // Determine what the source of damage was. if (e.getDamager() instanceof Egg) { cancelRpgDamage = true; return 0; } else if (e.getDamager() instanceof Fish) { cancelRpgDamage = true; return 0; } else if (e.getDamager() instanceof Snowball) { cancelRpgDamage = true; return 0; } else if (e.getDamager() instanceof Fireball) { boolean success = false; Fireball fb = (Fireball) (e.getDamager()); if (fb.getShooter() == e.getEntity()) { cancelRpgDamage = true; return 0; } if (e.getEntity() instanceof Fireball || e.getEntity() instanceof LargeFireball) { cancelRpgDamage = true; return 0; } for (RpgPlayer rpgPlayer : FC_Rpg.rpgEntityManager.getOnlineRpgPlayers()) { if (rpgPlayer.summon_Owns(e.getDamager())) { // Variable Initializations rpgAttacker = rpgPlayer; spellBook = rpgAttacker.playerConfig.getRpgClass().getSpellBook(); damageType = 2; for (int i = 0; i < spellBook.size(); i++) { if (spellBook.get(i).effectID == SpellEffect.FIREBALL.getID()) { SpellCaster sc = new SpellCaster(); damage = sc.updatefinalSpellMagnitude( rpgAttacker, spellBook.get(i), (rpgAttacker.playerConfig.getSpellLevels().get(i) - 1)); break; } } success = true; break; } } if (success == false) { cancelRpgDamage = true; return 0; } } else if (e.getDamager() instanceof Arrow) { // Set damage type to arrow damageType = 1; // Store the arrow. arrow = (Arrow) e.getDamager(); // If the player shot the arrow, set damage to player stuff. if (arrow.getShooter() instanceof Player) { // Store the attacker playerAttacker = (Player) arrow.getShooter(); rpgAttacker = FC_Rpg.rpgEntityManager.getRpgPlayer(playerAttacker); } else { // Set the creature attacker. creatureAttacker = arrow.getShooter(); // Get the shooter entity monster and store. rpgMobAttacker = FC_Rpg.rpgEntityManager.getRpgMonster(arrow.getShooter()); // Set the damage to the monsters strength. if (rpgMobAttacker != null) damage = rpgMobAttacker.getAttack() * FC_Rpg.balanceConfig.getPlayerStatMagnitudeAttack(); } // Remove all arrows. arrow.remove(); } else if (e.getDamager() instanceof LightningStrike) { // Initialize rpgMobAttacker; rpgMobAttacker = new RpgMonster(); damage = rpgMobAttacker.getAttack() * FC_Rpg.balanceConfig.getPlayerStatMagnitudeAttack(); } // Melee player attacks else if (e.getDamager() instanceof Player) { // Store the attacker playerAttacker = (Player) e.getDamager(); rpgAttacker = FC_Rpg.rpgEntityManager.getRpgPlayer(playerAttacker); } // If the entity is a living entity we want to store it. else if (e.getDamager() instanceof LivingEntity) { // Set creature attacker. creatureAttacker = (LivingEntity) e.getDamager(); // Initialize rpgMobAttacker; rpgMobAttacker = FC_Rpg.rpgEntityManager.getRpgMonster(creatureAttacker); damage = rpgMobAttacker.getAttack() * FC_Rpg.balanceConfig.getPlayerStatMagnitudeAttack(); if (creatureAttacker.getEquipment().getItemInHand() != null) damage = damage * FC_Rpg.battleCalculations.getWeaponModifier( creatureAttacker.getEquipment().getItemInHand(), 999999); } // Else if not it's an error and return the monster strength. else { FC_Rpg.plugin .getLogger() .info("Error: PrepareAttacker(), undefined entity type: " + e.getDamager().toString()); // Initialize rpgMobAttacker; rpgMobAttacker = new RpgMonster(); damage = rpgMobAttacker.getAttack() * FC_Rpg.balanceConfig.getPlayerStatMagnitudeAttack(); } // Cancel damage for stunned stuff. if (rpgAttacker != null) { // If disabled cancel attack if (rpgAttacker.playerConfig.getStatusActiveRpgPlayer(SpellEffect.DISABLED.getID())) { cancelRpgDamage = true; return 0; } // Set damage of arrows. damage = rpgAttacker.getTotalAttack() * FC_Rpg.balanceConfig.getPlayerStatMagnitudeAttack(); // Add weapon Bonus damage *= FC_Rpg.battleCalculations.getWeaponModifier( playerAttacker.getItemInHand(), rpgAttacker.getTotalAttack()); // If the player has the attack buff, then... if (rpgAttacker.playerConfig.getStatusActiveRpgPlayer(SpellEffect.DAMAGE_BONUS.getID())) damage *= rpgAttacker.playerConfig.getStatusMagnitude(SpellEffect.DAMAGE_BONUS.getID()); } else if (rpgMobAttacker != null) { if (rpgMobAttacker.getStatusActiveEntity(rpgMobAttacker.getStatusDisabled())) { cancelRpgDamage = true; return 0; } } else if (rpgAttacker == null) { MessageLib msgLib = new MessageLib(playerAttacker); msgLib.standardMessage("You need to pick a class before you can fight."); cancelRpgDamage = true; return 0; } return damage; }
// -1, false, false are defaults, attackmob and attack player are only processed when damage = -1. public void entityAttack(EntityDamageByEntityEvent ed, double customDamage) { double damage = 0; event = ed; // Reset all globals. setGlobalDefaults(); // Set event damage to 0. ed.setDamage(0); LivingEntity entity; Entity eEntity = ed.getEntity(); if (eEntity instanceof Arrow) { Arrow ca = (Arrow) eEntity; entity = ca.getShooter(); } else if (eEntity instanceof LargeFireball) { LargeFireball cf = (LargeFireball) eEntity; entity = cf.getShooter(); } else if (eEntity instanceof ExperienceOrb) { return; } else if (eEntity instanceof Item) { return; } else { // Set entity equal to the entity that got hit. try { entity = (LivingEntity) ed.getEntity(); } catch (ClassCastException e) { FC_Rpg.plugin .getLogger() .info( "Failed to cast an entity to living entity, damage cancelled -> " + eEntity.toString() + " <- report to a FC_Rpg developer via a ticket please."); return; } } // Prepare the defender and attacker variables. prepareDefender(entity); // If a damage was passed in, then we don't want to set damage. Else, store new damage damage = prepareAttacker(ed); // When two players are fighting, then... boolean isPvp = false; // set whether in pvp or not. if (playerAttacker != null && playerDefender != null) isPvp = true; if (isPvp == true && cancelRpgDamage == true) { MessageLib msgLib = new MessageLib(playerAttacker); msgLib.standardMessage("This player can't be attacked currently."); return; } // Check player tiers. if (isPvp == true) { int attackerTier = getTier(rpgAttacker.playerConfig.getClassLevel()); int defenderTier = getTier(rpgDefender.playerConfig.getClassLevel()); if (attackerTier != defenderTier) { MessageLib msgLib = new MessageLib(playerAttacker); msgLib.infiniteMessage( "You can't fight this target because they are in tier ", defenderTier + "", " and you are in tier ", attackerTier + "", "!"); return; } } // If we are cancelling rpg damage, then return. if (cancelRpgDamage == true) return; if (customDamage > -1) damage = customDamage; /** * ********************************************************* * * <p>SET THE BASE DAMAGE BASED ON IF A PLAYER, MOB, OR ENVIROMENT CAUSED DAMAGE * * <p>********************************************************* */ // We do a sword check for atttackers. if (rpgAttacker != null) { // Check the attackers sword. rpgAttacker.swordAttackRequirementCheck(); // We handle spells on non-fireball player attacks. if (damageType != 2) { if (rpgAttacker.playerConfig.getAutoCast() == true) rpgAttacker.prepareSpell(false); double spellDamage = -1; // Attempt to cast a spell. if (rpgMobDefender != null) spellDamage = rpgAttacker.castSpell(rpgMobDefender.getEntity(), damage, damageType); else spellDamage = rpgAttacker.castSpell(rpgDefender.getPlayer(), damage, damageType); // If the spell failed to cast, then we want to do spells/enchantment stuff. if (spellDamage == -1) { // Cast auto spells/enchantment stuff. if (rpgMobDefender != null) spellDamage = rpgAttacker.autocastOffense(rpgMobDefender.getEntity(), damage); else spellDamage = rpgAttacker.autocastOffense(rpgDefender.getPlayer(), damage); } // If the spell damage isn't -1, then we want to store the spell damage. if (spellDamage != -1) damage = spellDamage; } } // Apply randomization to damage. damage = getRandomDamageModifier(damage); // We do a armor check for defenders. if (rpgDefender != null) { rpgDefender.fullArmorCheck(); // Cast armor enchantment stuff. rpgDefender.autocastDefense(); } if (rpgMobDefender != null) { // Prevent mobs from damaging friendly mobs. if (rpgMobAttacker != null) return; // If no player attacked, then we want to nuke the mob (enviromental damage). if (rpgAttacker == null) { edm.nukeMob(rpgMobDefender.getEntity()); return; } // Attack the mob defender if (edm.attackMobDefender(rpgMobDefender, rpgAttacker, damage, damageType) == false) { MessageLib msgLib = new MessageLib(playerAttacker); msgLib.standardMessage("Attack Missed."); } // Make creatures forcibly attack attacker. if (playerAttacker != null && mobDefender != null) { // Set wolves to angry. if (mobDefender instanceof Wolf) ((Wolf) mobDefender).setAngry(true); if (mobDefender instanceof Creature) { // Change aggro ((Creature) mobDefender).setTarget(playerAttacker); } } } else if (rpgDefender != null) { // Attack the player Defender. if (rpgAttacker != null) { if (edm.attackPlayerDefender( rpgDefender, rpgAttacker, null, damage, damageType, rpgAttacker.getPlayer().getName().substring(0, nameTrimEnd)) == false) { MessageLib msgLib = new MessageLib(playerAttacker); msgLib.standardMessage("Attack Missed."); } } else if (rpgMobAttacker != null) edm.attackPlayerDefender( rpgDefender, null, rpgMobAttacker, damage, damageType, rpgMobAttacker.getEntity().getType().toString()); } }