Skip to content

Commit

Permalink
punish players for using knockback bows
Browse files Browse the repository at this point in the history
attempt to fix issue where knockback bows mess with dergon's pathfinding
  • Loading branch information
DeveloperDeborah committed Jan 23, 2024
1 parent 0cf7800 commit 6c49008
Showing 1 changed file with 46 additions and 5 deletions.
51 changes: 46 additions & 5 deletions src/no/runsafe/dergons/Dergon.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
import no.runsafe.framework.api.IWorld;
import no.runsafe.framework.api.player.IPlayer;
import no.runsafe.framework.internal.wrapper.ObjectUnwrapper;
import no.runsafe.framework.internal.wrapper.ObjectWrapper;
import no.runsafe.framework.minecraft.Buff;
import no.runsafe.framework.minecraft.Item;
import no.runsafe.framework.minecraft.Sound;
import no.runsafe.framework.minecraft.WorldEffect;
import no.runsafe.framework.minecraft.enchantment.RunsafeEnchantment;
import no.runsafe.framework.minecraft.entity.RunsafeFallingBlock;
import no.runsafe.framework.minecraft.entity.ProjectileEntity;
import no.runsafe.framework.minecraft.item.meta.RunsafeMeta;
import org.bukkit.util.Vector;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;

import static java.lang.Math.*;
Expand Down Expand Up @@ -441,11 +445,49 @@ else if (targetEntity == null)
* @param bodyPart Part of the dergon hit.
* @param damager Source of the damage.
* @param damageValue Amount of damage.
* @return true
* @return True if damage is dealt.
*/
@Override
public boolean a(EntityComplexPart bodyPart, DamageSource damager, float damageValue)
{
Entity bukkitAttacker = damager.getEntity();
IPlayer attacker = null;
if (bukkitAttacker instanceof EntityHuman)
attacker = ObjectWrapper.convert(((EntityHuman) bukkitAttacker).getBukkitEntity());

// Check if the player is attacking with a punch bow
if (attacker != null)
{
RunsafeMeta checkItem = attacker.getItemInMainHand();
if (checkItem != null && checkItem.is(Item.Combat.Bow))
{
for (Map.Entry<RunsafeEnchantment, Integer> enchantment : checkItem.getEnchantments().entrySet())
{
if (!enchantment.getKey().getName().equals("ARROW_KNOCKBACK"))
continue;

attacker.setVelocity(new Vector(4, 4, 4));
attacker.addBuff(Buff.Combat.Blindness.duration(15));
attacker.sendColouredMessage("&4The dergon punches you back instead.");
return false;
}
}
checkItem = attacker.getItemInOffHand();
if (checkItem != null && checkItem.is(Item.Combat.Bow))
{
for (Map.Entry<RunsafeEnchantment, Integer> enchantment : checkItem.getEnchantments().entrySet())
{
if (!enchantment.getKey().getName().equals("ARROW_KNOCKBACK"))
continue;

attacker.setVelocity(new Vector(4, 4, 4));
attacker.addBuff(Buff.Combat.Blindness.duration(15));
attacker.sendColouredMessage("&4The dergon punches you back instead.");
return false;
}
}
}

// Recalculate target location
double yawRadian = toRadians(yaw);
double xDirection = sin(yawRadian);
Expand All @@ -456,8 +498,7 @@ public boolean a(EntityComplexPart bodyPart, DamageSource damager, float damageV
targetEntity = null;

// Only apply damage if the source is a player or an explosion.
Entity attacker = damager.getEntity();
if (attacker instanceof EntityHuman || damager.isExplosion())
if (attacker != null || damager.isExplosion())
{
// Do more damage for head shots
if(bodyPart != dergonHead)
Expand All @@ -466,9 +507,9 @@ public boolean a(EntityComplexPart bodyPart, DamageSource damager, float damageV
}

// Spawn in some creatures to help defend the dergon
if (attacker instanceof EntityHuman && random.nextFloat() < (Config.getVexChance() / 100))
if (attacker != null && random.nextFloat() < (Config.getVexChance() / 100))
{
ILocation attackerLocation = dergonWorld.getLocation(attacker.locX, attacker.locY + 1, attacker.locZ);
ILocation attackerLocation = attacker.getLocation();
if (attackerLocation == null)
return true;

Expand Down

0 comments on commit 6c49008

Please sign in to comment.