HaniiPuppy

damage spell effect definition source

Mar 5th, 2016
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.06 KB | None | 0 0
  1.     /**
  2.      * Causes the specified damage to affected entities.
  3.      *
  4.      * possible arguments:
  5.      *
  6.      * The amount of damage to deal is the numeric argument or the modifier value of the spell effect.
  7.      *
  8.      * ignore armour: Makes the damage from this spell ignore any armour.
  9.      *
  10.      * ignore buffs/absolute: Makes the damage from this spell ignore any potion effects, armour enchantments, etc.
  11.      *
  12.      * ignore spell strength: Makes the damage from this spell not be affected by the spell strength.
  13.      *
  14.      * fire: Makes the damage from this spell effect fire damage.
  15.      *
  16.      * explosion: Makes the damage from this spell effect explosion damage.
  17.      *
  18.      * not magic: Makes the damage from this spell effect not magic damage. (it is magic damage by default)
  19.      *
  20.      * projectile: Makes the damage from this spell effect projectile damage. (It is by default only if the spell is
  21.      *             cast as a projectile spell)
  22.      *
  23.      * not projectile: Makes the damage from this spell effect not projectile damage. (It is by default only if the
  24.      *                 spell is cast as a projectile spell)
  25.      *
  26.      * ignore non living: non-living entities are unaffected. (e.g. paintings, armour stands, minecarts, etc.)
  27.      *
  28.      * distance multiplier: As a percentage (where 0 is 0%, 1.0 is 100%) of the specified amount of damage, how much
  29.      *                      damage those at the very edge of the spell's affected area take. This progresses from 1.0 to
  30.      *                      the value passed to this argument linearly depending on how close to the centre the affected
  31.      *                      entity is.
  32.      *
  33.      *                      e.g. where a value of 0.3 is used, and the damage specified is 5, the actual entity hit
  34.      *                      would take 5 (1.0 * 5) damage, an entity at the edge of the affected area would
  35.      *                      take 1.5 (0.3 * 5) damage, and an entity halfway between the two would take 3.25 (0.65 * 5)
  36.      *                      damage.
  37.      */
  38.     static final SpellEffectDefinition damage = new SpellEffectDefinition("Damage")
  39.     {
  40.         @Override
  41.         public void PerformEffect(SpellArgs spellArgs, List<SpellEffectDefinitionModifier> defModifiers)
  42.         {
  43.             double damage = 1;
  44.             double percentOfDamageAtEdge = 1; // i.e. as a percent, how much damage is taken by those at the max distance.
  45.            
  46.             boolean ignoreArmour = false;
  47.             boolean ignoreBuffs = false;
  48.             boolean ignoreSpellStrength = false;
  49.            
  50.             boolean isFireDamage = false;
  51.             boolean isMagicDamage = true;
  52.             boolean isExplosionDamage = false;
  53.             boolean isProjectile = spellArgs.getSpellTarget() == SpellTarget.projectile;
  54.            
  55.             boolean ignoreNonLivingEntities = false;
  56.            
  57.             DamageSource dmgSrc = spellArgs.getCaster() instanceof SpellCasterEntity
  58.                     ? new ArcaneSpellEntityDamageSource(spellArgs)
  59.                     : new ArcaneSpellGeneralDamageSource(spellArgs);
  60.            
  61.             for(SpellEffectDefinitionModifier modifier : defModifiers)
  62.             {
  63.                 if(defModifiers instanceof NumericDefinitionModifier)
  64.                     damage = ((NumericDefinitionModifier)modifier).asDouble();
  65.                 else if(modifier instanceof ModifierValueDefinitionModifier)
  66.                 {
  67.                     Double newDamage = Doubles.tryParse(modifier.getName());
  68.                    
  69.                     if(newDamage != null)
  70.                         damage = newDamage;
  71.                 }
  72.                 else if(modifier instanceof BasicDefinitionModifier)
  73.                 {
  74.                     // TO DO: Change this to a switch/case statement once I drop support for Java 1.6
  75.                    
  76.                     if(modifier.getName().equalsIgnoreCase("ignorearmour")
  77.                     || modifier.getName().equalsIgnoreCase("ignore armour"))
  78.                     { ignoreArmour = true; }
  79.                     else if(modifier.getName().equalsIgnoreCase("ignorebuffs")
  80.                          || modifier.getName().equalsIgnoreCase("ignore buffs")
  81.                          || modifier.getName().equalsIgnoreCase("absolute"))
  82.                     { ignoreBuffs = true; }
  83.                     else if(modifier.getName().equalsIgnoreCase("ignorespellstrength")
  84.                          || modifier.getName().equalsIgnoreCase("ignore spell strength")
  85.                          || modifier.getName().equalsIgnoreCase("ignorestrength")
  86.                          || modifier.getName().equalsIgnoreCase("ignore strength"))
  87.                     { ignoreSpellStrength = true; }
  88.                     else if(modifier.getName().equalsIgnoreCase("fire"))
  89.                     { isFireDamage = true; }
  90.                     else if(modifier.getName().equalsIgnoreCase("explosion"))
  91.                     { isExplosionDamage = true; }
  92.                     else if(modifier.getName().equalsIgnoreCase("notmagic")
  93.                          || modifier.getName().equalsIgnoreCase("not magic"))
  94.                     { isMagicDamage = false; }
  95.                     else if(modifier.getName().equalsIgnoreCase("projectile"))
  96.                     { isProjectile = true; }
  97.                     else if(modifier.getName().equalsIgnoreCase("notprojectile")
  98.                          || modifier.getName().equalsIgnoreCase("not projectile"))
  99.                     { isProjectile = false; }
  100.                     else if(modifier.getName().equalsIgnoreCase("ignorenonliving")
  101.                          || modifier.getName().equalsIgnoreCase("ignore non living")
  102.                          || modifier.getName().equalsIgnoreCase("ignore nonliving"))
  103.                     { ignoreNonLivingEntities = true; }
  104.                     else if(modifier.getName().equalsIgnoreCase("distancemultiplier")
  105.                          || modifier.getName().equalsIgnoreCase("distance multiplier"))
  106.                     {
  107.                         Double newMultiplier = Doubles.tryParse(modifier.getValue());
  108.                        
  109.                         if(newMultiplier != null)
  110.                             percentOfDamageAtEdge = newMultiplier;
  111.                     }
  112.                 }
  113.             }
  114.            
  115.             if(ignoreArmour)      dmgSrc.setDamageBypassesArmor();
  116.             if(ignoreBuffs)       dmgSrc.setDamageIsAbsolute();
  117.             if(isFireDamage)      dmgSrc.setFireDamage();
  118.             if(isMagicDamage)     dmgSrc.setMagicDamage();
  119.             if(isExplosionDamage) dmgSrc.setExplosion();
  120.             if(isProjectile)      dmgSrc.setProjectile();
  121.            
  122.             if(!ignoreSpellStrength)
  123.                 damage = damage * spellArgs.getSpellStrength().getStrengthModifier();
  124.            
  125.             for(Entity entity : spellArgs.getEntitiesAffected())
  126.             {
  127.                 if(ignoreNonLivingEntities && !(entity instanceof EntityLivingBase))
  128.                     continue;
  129.                
  130.                 double damageToTake;
  131.                
  132.                 // The below if statement shouldn't actually be necessary - it'll work fine without it, it just saves
  133.                 // having to process the below chunk of code where percentageOfDamageToTake will always be 1.
  134.                 if(percentOfDamageAtEdge == 1 || entity == spellArgs.getEntityHit())
  135.                     damageToTake = damage;
  136.                 else
  137.                 {
  138.                     double actualDistance = spellArgs.getBurstLocation().DistanceFrom(new Location(entity.posX, entity.posY, entity.posZ));
  139.                     double distanceAsPercentOfMax = actualDistance / spellArgs.getAOESize().getDistance();
  140.                     double percentageOfDamageToTake = percentOfDamageAtEdge + ((1.0 - distanceAsPercentOfMax) * (1.0 - percentOfDamageAtEdge));
  141.                     damageToTake = damage * percentageOfDamageToTake;
  142.                 }
  143.                
  144.                 entity.attackEntityFrom(dmgSrc, (float)damageToTake);
  145.             }
  146.         }
  147.     };
Advertisement
Add Comment
Please, Sign In to add comment