mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-24 00:15:16 +01:00
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 {
|
||||
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) {
|
||||
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);
|
||||
|
||||
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)
|
||||
abort(CancelReason.OTHER);
|
||||
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 {
|
||||
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) {
|
||||
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);
|
||||
|
||||
if (isSuccessful()) {
|
||||
MMORayTraceResult result = MMOLib.plugin.getVersion().getWrapper().rayTrace(data.getPlayer(), range,
|
||||
entity -> MMOCoreUtils.canTarget(data, entity));
|
||||
entity -> MMOCoreUtils.canTarget(data, entity, buff));
|
||||
if (!result.hasHit())
|
||||
abort();
|
||||
else
|
||||
|
@ -42,7 +42,8 @@ public class MMOCoreUtils {
|
||||
if (isLastSpace && ch >= 'a' && ch <= 'z') {
|
||||
builder.setCharAt(item, (char) (ch + ('A' - 'a')));
|
||||
isLastSpace = false;
|
||||
} else isLastSpace = ch == ' ';
|
||||
} else
|
||||
isLastSpace = ch == ' ';
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
@ -145,16 +146,37 @@ public class MMOCoreUtils {
|
||||
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) {
|
||||
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
|
||||
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;
|
||||
|
||||
// party check
|
||||
if (target instanceof Player) {
|
||||
if (!buff && target instanceof Player) {
|
||||
PlayerData targetData = PlayerData.get((Player) target);
|
||||
return !targetData.hasParty() || !targetData.getParty().getMembers().has(player);
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ public class Greater_Healings extends Skill {
|
||||
|
||||
@Override
|
||||
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())
|
||||
return cast;
|
||||
|
||||
|
@ -35,7 +35,7 @@ public class Human_Shield extends Skill {
|
||||
|
||||
@Override
|
||||
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())
|
||||
return cast;
|
||||
|
||||
|
@ -26,7 +26,7 @@ public class Minor_Healings extends Skill {
|
||||
|
||||
@Override
|
||||
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())
|
||||
return cast;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user