forked from Upstream/mmocore
Buff based skills can now be cast on party members
This commit is contained in:
parent
e9eed241e0
commit
f8b7ac20b3
@ -12,19 +12,34 @@ import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
|||||||
public class LocationSkillResult extends SkillResult {
|
public class LocationSkillResult extends SkillResult {
|
||||||
private Location loc;
|
private Location loc;
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* this SkillResult is only available for 1.13+ users.
|
* @param data Player casting the skill
|
||||||
|
* @param skill Skill being cast
|
||||||
|
* @param range Skill raycast range
|
||||||
*/
|
*/
|
||||||
public LocationSkillResult(PlayerData data, SkillInfo skill, double range) {
|
public LocationSkillResult(PlayerData data, SkillInfo skill, double range) {
|
||||||
|
this(data, skill, range, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param data Player casting the skill
|
||||||
|
* @param skill Skill being cast
|
||||||
|
* @param range Skill raycast range
|
||||||
|
* @param buff If the skill is a buff ie if it can be cast on party members
|
||||||
|
*/
|
||||||
|
public LocationSkillResult(PlayerData data, SkillInfo skill, double range, boolean buff) {
|
||||||
super(data, skill);
|
super(data, skill);
|
||||||
|
|
||||||
if (isSuccessful()) {
|
if (isSuccessful()) {
|
||||||
|
|
||||||
RayTraceResult result = data.getPlayer().getWorld().rayTrace(data.getPlayer().getEyeLocation(), data.getPlayer().getEyeLocation().getDirection(), range, FluidCollisionMode.ALWAYS, true, 1.0D, entity -> MMOCoreUtils.canTarget(data, entity));
|
RayTraceResult result = data.getPlayer().getWorld().rayTrace(data.getPlayer().getEyeLocation(),
|
||||||
|
data.getPlayer().getEyeLocation().getDirection(), range, FluidCollisionMode.ALWAYS, true, 1.0D,
|
||||||
|
entity -> MMOCoreUtils.canTarget(data, entity, buff));
|
||||||
if (result == null)
|
if (result == null)
|
||||||
abort(CancelReason.OTHER);
|
abort(CancelReason.OTHER);
|
||||||
else
|
else
|
||||||
loc = result.getHitBlock() != null ? result.getHitBlock().getLocation() : result.getHitEntity() != null ? result.getHitEntity().getLocation() : null;
|
loc = result.getHitBlock() != null ? result.getHitBlock().getLocation()
|
||||||
|
: result.getHitEntity() != null ? result.getHitEntity().getLocation() : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,12 +12,27 @@ import net.mmogroup.mmolib.api.MMORayTraceResult;
|
|||||||
public class TargetSkillResult extends SkillResult {
|
public class TargetSkillResult extends SkillResult {
|
||||||
private LivingEntity target;
|
private LivingEntity target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param data Player casting the skill
|
||||||
|
* @param skill Skill being cast
|
||||||
|
* @param range Skill raycast range
|
||||||
|
*/
|
||||||
public TargetSkillResult(PlayerData data, SkillInfo skill, double range) {
|
public TargetSkillResult(PlayerData data, SkillInfo skill, double range) {
|
||||||
|
this(data, skill, range, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param data Player casting the skill
|
||||||
|
* @param skill Skill being cast
|
||||||
|
* @param range Skill raycast range
|
||||||
|
* @param buff If the skill is a buff ie if it can be cast on party members
|
||||||
|
*/
|
||||||
|
public TargetSkillResult(PlayerData data, SkillInfo skill, double range, boolean buff) {
|
||||||
super(data, skill);
|
super(data, skill);
|
||||||
|
|
||||||
if (isSuccessful()) {
|
if (isSuccessful()) {
|
||||||
MMORayTraceResult result = MMOLib.plugin.getVersion().getWrapper().rayTrace(data.getPlayer(), range,
|
MMORayTraceResult result = MMOLib.plugin.getVersion().getWrapper().rayTrace(data.getPlayer(), range,
|
||||||
entity -> MMOCoreUtils.canTarget(data, entity));
|
entity -> MMOCoreUtils.canTarget(data, entity, buff));
|
||||||
if (!result.hasHit())
|
if (!result.hasHit())
|
||||||
abort();
|
abort();
|
||||||
else
|
else
|
||||||
|
@ -42,7 +42,8 @@ public class MMOCoreUtils {
|
|||||||
if (isLastSpace && ch >= 'a' && ch <= 'z') {
|
if (isLastSpace && ch >= 'a' && ch <= 'z') {
|
||||||
builder.setCharAt(item, (char) (ch + ('A' - 'a')));
|
builder.setCharAt(item, (char) (ch + ('A' - 'a')));
|
||||||
isLastSpace = false;
|
isLastSpace = false;
|
||||||
} else isLastSpace = ch == ' ';
|
} else
|
||||||
|
isLastSpace = ch == ' ';
|
||||||
}
|
}
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
@ -145,16 +146,37 @@ public class MMOCoreUtils {
|
|||||||
return entities;
|
return entities;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO worldguard flags support for no target
|
/**
|
||||||
|
* @param player Player casting a spell/basic attack
|
||||||
|
* @param target The target entity
|
||||||
|
* @return If the player can target the entity given the attack type
|
||||||
|
* (buff or attack)
|
||||||
|
*/
|
||||||
public static boolean canTarget(PlayerData player, Entity target) {
|
public static boolean canTarget(PlayerData player, Entity target) {
|
||||||
if(!player.isOnline()) return false;
|
return canTarget(player, target, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param player Player casting a spell/basic attack
|
||||||
|
* @param target The target entity
|
||||||
|
* @param buff Used when the attack is not an attack but a positive buff.
|
||||||
|
* Buffs or heals can be applied on party members, whereas
|
||||||
|
* attacks can't target party members.
|
||||||
|
* @return If the player can target the entity given the attack type
|
||||||
|
* (buff or attack)
|
||||||
|
*/
|
||||||
|
// TODO worldguard flags support for no target
|
||||||
|
public static boolean canTarget(PlayerData player, Entity target, boolean buff) {
|
||||||
|
if (!player.isOnline())
|
||||||
|
return false;
|
||||||
|
|
||||||
// basic checks
|
// basic checks
|
||||||
if (!(target instanceof LivingEntity) || player.getPlayer().equals(target) || target.isDead() || MMOLib.plugin.getEntities().findCustom(target))
|
if (!(target instanceof LivingEntity) || player.getPlayer().equals(target) || target.isDead()
|
||||||
|
|| MMOLib.plugin.getEntities().findCustom(target))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// party check
|
// party check
|
||||||
if (target instanceof Player) {
|
if (!buff && target instanceof Player) {
|
||||||
PlayerData targetData = PlayerData.get((Player) target);
|
PlayerData targetData = PlayerData.get((Player) target);
|
||||||
return !targetData.hasParty() || !targetData.getParty().getMembers().has(player);
|
return !targetData.hasParty() || !targetData.getParty().getMembers().has(player);
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ public class Greater_Healings extends Skill {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SkillResult whenCast(PlayerData data, SkillInfo skill) {
|
public SkillResult whenCast(PlayerData data, SkillInfo skill) {
|
||||||
SkillResult cast = data.getPlayer().isSneaking() ? new SkillResult(data, skill) : new TargetSkillResult(data, skill, 50);
|
SkillResult cast = data.getPlayer().isSneaking() ? new SkillResult(data, skill) : new TargetSkillResult(data, skill, 50, true);
|
||||||
if (!cast.isSuccessful())
|
if (!cast.isSuccessful())
|
||||||
return cast;
|
return cast;
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ public class Human_Shield extends Skill {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SkillResult whenCast(PlayerData data, SkillInfo skill) {
|
public SkillResult whenCast(PlayerData data, SkillInfo skill) {
|
||||||
TargetSkillResult cast = new TargetSkillResult(data, skill, 7);
|
TargetSkillResult cast = new TargetSkillResult(data, skill, 7, true);
|
||||||
if (!cast.isSuccessful())
|
if (!cast.isSuccessful())
|
||||||
return cast;
|
return cast;
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ public class Minor_Healings extends Skill {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SkillResult whenCast(PlayerData data, SkillInfo skill) {
|
public SkillResult whenCast(PlayerData data, SkillInfo skill) {
|
||||||
SkillResult cast = data.getPlayer().isSneaking() ? new SkillResult(data, skill) : new TargetSkillResult(data, skill, 50);
|
SkillResult cast = data.getPlayer().isSneaking() ? new SkillResult(data, skill) : new TargetSkillResult(data, skill, 50, true);
|
||||||
if (!cast.isSuccessful())
|
if (!cast.isSuccessful())
|
||||||
return cast;
|
return cast;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user