use of com.solinia.solinia.Interfaces.ISoliniaLivingEntity in project solinia3-core by mixxit.
the class EntityManager method doNPCCheckForEnemies.
@Override
public void doNPCCheckForEnemies() {
List<Integer> completedNpcsIds = new ArrayList<Integer>();
for (Player player : Bukkit.getOnlinePlayers()) {
for (Entity entity : player.getNearbyEntities(50, 50, 50)) {
if (entity instanceof Player)
continue;
if (!(entity instanceof LivingEntity))
continue;
LivingEntity le = (LivingEntity) entity;
if (!Utils.isLivingEntityNPC(le))
continue;
try {
ISoliniaLivingEntity solle = SoliniaLivingEntityAdapter.Adapt(le);
if (completedNpcsIds.contains(solle.getNpcid()))
continue;
completedNpcsIds.add(solle.getNpcid());
solle.doCheckForEnemies();
} catch (CoreStateInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
use of com.solinia.solinia.Interfaces.ISoliniaLivingEntity in project solinia3-core by mixxit.
the class SoliniaSpell method getSpellEffectiveness.
@Override
public float getSpellEffectiveness(LivingEntity caster, LivingEntity victim) throws CoreStateInitException {
// TODO Auto-generated method stub
int resistmodifier = getResistDiff();
int casterlevel = 1;
int targetresist = 0;
boolean isnpccaster = false;
if (caster instanceof Player) {
casterlevel = SoliniaPlayerAdapter.Adapt((Player) caster).getLevel();
} else {
if (Utils.isLivingEntityNPC(caster)) {
ISoliniaLivingEntity solentity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) caster);
ISoliniaNPC casternpc = StateManager.getInstance().getConfigurationManager().getNPC(solentity.getNpcid());
casterlevel = casternpc.getLevel();
isnpccaster = true;
}
}
boolean isnpcvictim = false;
int victimlevel = 1;
if (victim instanceof Player) {
victimlevel = SoliniaPlayerAdapter.Adapt((Player) victim).getLevel();
targetresist = SoliniaPlayerAdapter.Adapt((Player) victim).getResist(Utils.getSpellResistType(getResisttype()));
} else {
if (Utils.isLivingEntityNPC(victim)) {
ISoliniaLivingEntity solentity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) victim);
ISoliniaNPC victimnpc = StateManager.getInstance().getConfigurationManager().getNPC(solentity.getNpcid());
targetresist = solentity.getResists(Utils.getSpellResistType(getResisttype()));
victimlevel = victimnpc.getLevel();
isnpcvictim = true;
}
}
int resist_chance = 0;
int level_mod = 0;
int temp_level_diff = victimlevel - casterlevel;
if (isnpcvictim == false && victimlevel >= 21 && temp_level_diff > 15) {
temp_level_diff = 15;
}
if (isnpcvictim == true && temp_level_diff < -9) {
temp_level_diff = -9;
}
level_mod = temp_level_diff * temp_level_diff / 2;
if (temp_level_diff < 0) {
level_mod = -level_mod;
}
if (isnpcvictim && (casterlevel - victimlevel < -20)) {
level_mod = 1000;
}
// Even more level stuff this time dealing with damage spells
if (isnpcvictim && isDamageSpell() && victimlevel >= 17) {
int level_diff;
level_diff = victimlevel - casterlevel;
level_mod += (2 * level_diff);
}
resist_chance += level_mod;
resist_chance += resistmodifier;
resist_chance += targetresist;
if (resist_chance > 255) {
resist_chance = 255;
}
if (resist_chance < 0) {
resist_chance = 0;
}
int roll = Utils.RandomBetween(0, 200);
if (roll > resist_chance) {
return 100;
} else {
if (resist_chance < 1) {
resist_chance = 1;
}
int partial_modifier = ((150 * (resist_chance - roll)) / resist_chance);
if (isnpcvictim == true) {
if (victimlevel > casterlevel && victimlevel >= 17 && casterlevel <= 50) {
partial_modifier += 5;
}
if (victimlevel >= 30 && casterlevel < 50) {
partial_modifier += (casterlevel - 25);
}
if (victimlevel < 15) {
partial_modifier -= 5;
}
}
if (isnpccaster) {
if ((victimlevel - casterlevel) >= 20) {
partial_modifier += (victimlevel - casterlevel) * 1.5;
}
}
if (partial_modifier <= 0) {
return 100F;
} else if (partial_modifier >= 100) {
return 0;
}
return (100.0f - partial_modifier);
}
}
use of com.solinia.solinia.Interfaces.ISoliniaLivingEntity in project solinia3-core by mixxit.
the class Solinia3CoreEntityListener method onEntityTargetEvent.
// Needs to occur before anything else
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityTargetEvent(EntityTargetEvent event) {
if (event.isCancelled())
return;
if (!(event.getEntity() instanceof Creature))
return;
try {
Timestamp mzExpiry = StateManager.getInstance().getEntityManager().getMezzed((LivingEntity) event.getEntity());
if (mzExpiry != null) {
if (event.getEntity() instanceof Player) {
event.getEntity().sendMessage("* You are mezzed!");
}
Utils.CancelEvent(event);
;
return;
}
} catch (CoreStateInitException e) {
}
try {
// Me
ISoliniaLivingEntity solEntity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
if (solEntity.isUndead() && !(event.getEntity() instanceof Player) && event.getTarget() instanceof LivingEntity) {
if (StateManager.getInstance().getEntityManager().hasEntityEffectType((LivingEntity) event.getTarget(), SpellEffectType.InvisVsUndead) || StateManager.getInstance().getEntityManager().hasEntityEffectType((LivingEntity) event.getTarget(), SpellEffectType.InvisVsUndead2)) {
((Creature) event.getEntity()).setTarget(null);
Utils.CancelEvent(event);
;
return;
}
}
if (!solEntity.isUndead() && !(event.getEntity() instanceof Player) && !solEntity.isAnimal() && event.getTarget() instanceof LivingEntity) {
if (StateManager.getInstance().getEntityManager().hasEntityEffectType((LivingEntity) event.getTarget(), SpellEffectType.Invisibility) || StateManager.getInstance().getEntityManager().hasEntityEffectType((LivingEntity) event.getTarget(), SpellEffectType.Invisibility2)) {
((Creature) event.getEntity()).setTarget(null);
Utils.CancelEvent(event);
;
return;
}
}
if (solEntity.isAnimal() && !(event.getEntity() instanceof Player) && event.getTarget() instanceof LivingEntity) {
if (StateManager.getInstance().getEntityManager().hasEntityEffectType((LivingEntity) event.getTarget(), SpellEffectType.InvisVsAnimals) || StateManager.getInstance().getEntityManager().hasEntityEffectType((LivingEntity) event.getTarget(), SpellEffectType.ImprovedInvisAnimals)) {
((Creature) event.getEntity()).setTarget(null);
Utils.CancelEvent(event);
;
return;
}
}
// rogue sneak
if (event.getTarget() instanceof Player && !(event.getEntity() instanceof Player)) {
Player targetPlayer = (Player) event.getTarget();
if (targetPlayer.isSneaking()) {
ISoliniaPlayer player = SoliniaPlayerAdapter.Adapt((Player) event.getTarget());
if (player.getClassObj() != null) {
if (player.getClassObj().isSneakFromCrouch()) {
Utils.CancelEvent(event);
;
return;
}
}
}
}
if (event.getEntity() != null && event.getTarget() != null) {
if (!(event.getEntity() instanceof Player)) {
if (event.getEntity() instanceof LivingEntity) {
ISoliniaLivingEntity livingEntity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
}
// Mez cancel target
Timestamp mezExpiry = StateManager.getInstance().getEntityManager().getMezzed((LivingEntity) event.getTarget());
if (mezExpiry != null) {
((Creature) event.getEntity()).setTarget(null);
event.getEntity().sendMessage("The target is mezzed, you cannot hit it");
Utils.CancelEvent(event);
;
return;
}
}
}
} catch (CoreStateInitException e) {
return;
}
}
use of com.solinia.solinia.Interfaces.ISoliniaLivingEntity in project solinia3-core by mixxit.
the class Solinia3CorePlayerChatListener method OnChat.
@EventHandler
public void OnChat(SoliniaAsyncPlayerChatEvent event) {
if (event.isCancelled())
return;
if (!(event.getRawEvent() instanceof AsyncPlayerChatEvent))
return;
// We control all chat!
AsyncPlayerChatEvent rawEvent = (AsyncPlayerChatEvent) event.getRawEvent();
Utils.CancelEvent(rawEvent);
String currentChannel = event.getPlayer().getCurrentChannel();
// always redirect npc interactions to local
if (event.getPlayer().getInteraction() != null) {
currentChannel = "LOCAL";
}
// TODO - Support checking channel modes of player
if (currentChannel.equals("LOCAL")) {
StateManager.getInstance().getChannelManager().sendToLocalChannelDecorated(event.getPlayer(), event.getMessage());
} else {
StateManager.getInstance().getChannelManager().sendToGlobalChannelDecorated(event.getPlayer(), event.getMessage());
}
// NPC responses (if applicable)
if (event.getPlayer().getInteraction() != null) {
Entity entity = Bukkit.getEntity(event.getPlayer().getInteraction());
if (entity != null && entity instanceof LivingEntity) {
LivingEntity livingEntity = (LivingEntity) entity;
ISoliniaLivingEntity solentity;
try {
solentity = StateManager.getInstance().getEntityManager().getLivingEntity(livingEntity);
solentity.processInteractionEvent(event.getPlayer().getBukkitPlayer(), InteractionType.CHAT, event.getMessage());
} catch (CoreStateInitException e) {
// skip
}
}
}
}
use of com.solinia.solinia.Interfaces.ISoliniaLivingEntity in project solinia3-core by mixxit.
the class SoliniaLivingEntity method avoidDamage.
@Override
public DamageHitInfo avoidDamage(SoliniaLivingEntity attacker, DamageHitInfo hit) {
ISoliniaLivingEntity defender = this;
if (getDodgeCheck()) {
hit.damage_done = 0;
hit.avoided = true;
hit.dodged = true;
return hit;
}
if (getRiposteCheck()) {
hit.damage_done = 0;
hit.riposted = true;
hit.avoided = true;
return hit;
}
// TODO Shield Block
// TODO Two Hand Block
hit.avoided = false;
return hit;
}
Aggregations