1.0.0-SNAPSHOT-U59

+ Finalised the Skill system
This commit is contained in:
AMinecraftDev 2018-11-18 16:56:06 +08:00
parent 11baa56327
commit 861705f717
5 changed files with 75 additions and 47 deletions

View File

@ -1,6 +1,8 @@
package com.songoda.epicbosses.events;
import com.songoda.epicbosses.holder.ActiveBossHolder;
import com.songoda.epicbosses.skills.ISkillHandler;
import com.songoda.epicbosses.skills.Skill;
import lombok.Getter;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
@ -15,9 +17,21 @@ public class BossSkillEvent extends Event {
private static final HandlerList handlers = new HandlerList();
@Getter private ActiveBossHolder activeBossHolder;
@Getter private ISkillHandler skillHandler;
@Getter private Skill skill;
public BossSkillEvent(ActiveBossHolder activeBossHolder, ISkillHandler skillHandler, Skill skill) {
this.activeBossHolder = activeBossHolder;
this.skillHandler = skillHandler;
this.skill = skill;
}
@Override
public HandlerList getHandlers() {
return null;
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -3,17 +3,20 @@ package com.songoda.epicbosses.listeners.during;
import com.songoda.epicbosses.CustomBosses;
import com.songoda.epicbosses.api.BossAPI;
import com.songoda.epicbosses.entity.BossEntity;
import com.songoda.epicbosses.events.BossSkillEvent;
import com.songoda.epicbosses.events.PreBossSkillEvent;
import com.songoda.epicbosses.holder.ActiveBossHolder;
import com.songoda.epicbosses.managers.BossEntityManager;
import com.songoda.epicbosses.managers.BossSkillManager;
import com.songoda.epicbosses.managers.files.SkillsFileManager;
import com.songoda.epicbosses.skills.ISkillHandler;
import com.songoda.epicbosses.skills.Skill;
import com.songoda.epicbosses.skills.types.CommandSkillElement;
import com.songoda.epicbosses.skills.types.CustomSkillElement;
import com.songoda.epicbosses.skills.types.GroupSkillElement;
import com.songoda.epicbosses.skills.types.PotionSkillElement;
import com.songoda.epicbosses.utils.Debug;
import com.songoda.epicbosses.utils.MessageUtils;
import com.songoda.epicbosses.utils.RandomUtils;
import com.songoda.epicbosses.utils.ServerUtils;
import org.bukkit.Bukkit;
@ -26,10 +29,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.*;
/**
* @author Charles Cullen
@ -65,11 +65,11 @@ public class BossSkillListener implements Listener {
if(bossEntity.getSkills() == null || bossEntity.getSkills().getOverallChance() == null) return;
// if(RandomUtils.get().canPreformAction(bossEntity.getSkills().getOverallChance())) {
if(RandomUtils.get().canPreformAction(bossEntity.getSkills().getOverallChance())) {
PreBossSkillEvent preBossSkillEvent = new PreBossSkillEvent(activeBossHolder, livingEntity, (LivingEntity) entityDamaging);
ServerUtils.get().callEvent(preBossSkillEvent);
// }
}
}
@EventHandler
@ -95,56 +95,39 @@ public class BossSkillListener implements Listener {
return;
}
List<LivingEntity> targettedEntities = getTargetedEntities(activeBossHolder, skill, activeBossHolder.getLivingEntity().getLocation(), damagingEntity);
List<LivingEntity> targettedEntities = this.bossSkillManager.getTargetedEntities(activeBossHolder, skill, activeBossHolder.getLivingEntity().getLocation(), damagingEntity);
String bossDisplayName = activeBossHolder.getName();
String skillDisplayName = skill.getDisplayName();
ISkillHandler<?> skillHandler;
if(skill.getType().equalsIgnoreCase("POTION")) {
PotionSkillElement potionSkillElement = this.bossSkillManager.getPotionSkillElement(skill);
potionSkillElement.castSkill(skill, potionSkillElement, activeBossHolder, targettedEntities);
System.out.println("#1");
skillHandler = potionSkillElement;
} else if(skill.getType().equalsIgnoreCase("COMMAND")) {
CommandSkillElement commandSkillElement = this.bossSkillManager.getCommandSkillElement(skill);
commandSkillElement.castSkill(skill, commandSkillElement, activeBossHolder, targettedEntities);
System.out.println("#2");
skillHandler = commandSkillElement;
} else if(skill.getType().equalsIgnoreCase("GROUP")) {
GroupSkillElement groupSkillElement = this.bossSkillManager.getGroupSkillElement(skill);
groupSkillElement.castSkill(skill, groupSkillElement, activeBossHolder, targettedEntities);
System.out.println("#3");
skillHandler = groupSkillElement;
} else if(skill.getType().equalsIgnoreCase("CUSTOM")) {
CustomSkillElement customSkillElement = this.bossSkillManager.getCustomSkillElement(skill);
this.bossSkillManager.handleCustomSkillCasting(skill, customSkillElement, activeBossHolder, targettedEntities);
System.out.println("#4");
}
}
private List<LivingEntity> getTargetedEntities(ActiveBossHolder activeBossHolder, Skill skill, Location center, LivingEntity damager) {
double radiusSqr = skill.getRadius() * skill.getRadius();
List<LivingEntity> targetedList = new ArrayList<>();
String mode = skill.getMode();
if(mode.equalsIgnoreCase("ONE")) {
return Arrays.asList(damager);
} else if(mode.equalsIgnoreCase("BOSS")) {
targetedList.addAll(activeBossHolder.getLivingEntityMap().values());
skillHandler = this.bossSkillManager.handleCustomSkillCasting(skill, customSkillElement, activeBossHolder, targettedEntities);
} else {
for(Player player : Bukkit.getOnlinePlayers()) {
if(!player.getWorld().equals(center.getWorld())) continue;
if(center.distanceSquared(player.getLocation()) > radiusSqr) continue;
if(mode.equalsIgnoreCase("ALL")) {
targetedList.add(player);
} else if(mode.equalsIgnoreCase("RANDOM")) {
if(RandomUtils.get().preformRandomAction()) {
targetedList.add(player);
}
}
}
return;
}
return targetedList;
masterMessage.replaceAll(s -> s.replace("{boss}", bossDisplayName).replace("{skill}", skillDisplayName));
targettedEntities.forEach(livingEntity -> MessageUtils.get().sendMessage(livingEntity, masterMessage));
BossSkillEvent bossSkillEvent = new BossSkillEvent(activeBossHolder, skillHandler, skill);
ServerUtils.get().callEvent(bossSkillEvent);
}
}

View File

@ -11,11 +11,13 @@ import com.songoda.epicbosses.skills.types.PotionSkillElement;
import com.songoda.epicbosses.utils.BossesGson;
import com.songoda.epicbosses.utils.Debug;
import com.songoda.epicbosses.utils.ILoadable;
import com.songoda.epicbosses.utils.RandomUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
/**
* @author Charles Cullen
@ -40,16 +42,17 @@ public class BossSkillManager implements ILoadable {
registerCustomSkill(new Warp());
}
public void handleCustomSkillCasting(Skill skill, CustomSkillElement customSkillElement, ActiveBossHolder activeBossHolder, List<LivingEntity> nearbyEntities) {
public CustomSkillHandler handleCustomSkillCasting(Skill skill, CustomSkillElement customSkillElement, ActiveBossHolder activeBossHolder, List<LivingEntity> nearbyEntities) {
String type = customSkillElement.getCustom().getType();
CustomSkillHandler customSkillHandler = getCustomSkillHandler(type);
if(customSkillHandler == null) {
Debug.FAILED_TO_OBTAIN_THE_SKILL_HANDLER.debug(type);
return;
return null;
}
customSkillHandler.castSkill(skill, customSkillElement, activeBossHolder, nearbyEntities);
return customSkillHandler;
}
public PotionSkillElement getPotionSkillElement(Skill skill) {
@ -97,7 +100,34 @@ public class BossSkillManager implements ILoadable {
SKILLS.remove(customSkillHandler);
}
public CustomSkillHandler getCustomSkillHandler(String name) {
public List<LivingEntity> getTargetedEntities(ActiveBossHolder activeBossHolder, Skill skill, Location center, LivingEntity damager) {
double radiusSqr = skill.getRadius() * skill.getRadius();
List<LivingEntity> targetedList = new ArrayList<>();
String mode = skill.getMode();
if(mode.equalsIgnoreCase("ONE")) {
return Arrays.asList(damager);
} else if(mode.equalsIgnoreCase("BOSS")) {
targetedList.addAll(activeBossHolder.getLivingEntityMap().values());
} else {
for(Player player : Bukkit.getOnlinePlayers()) {
if(!player.getWorld().equals(center.getWorld())) continue;
if(center.distanceSquared(player.getLocation()) > radiusSqr) continue;
if(mode.equalsIgnoreCase("ALL")) {
targetedList.add(player);
} else if(mode.equalsIgnoreCase("RANDOM")) {
if(RandomUtils.get().preformRandomAction()) {
targetedList.add(player);
}
}
}
}
return targetedList;
}
private CustomSkillHandler getCustomSkillHandler(String name) {
for(CustomSkillHandler customSkillHandler : new HashSet<>(SKILLS)) {
String skillName = customSkillHandler.getClass().getSimpleName();

View File

@ -2,6 +2,7 @@ package com.songoda.epicbosses.utils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import java.util.Arrays;
@ -16,11 +17,11 @@ public class MessageUtils {
private static MessageUtils INSTANCE = new MessageUtils();
public void sendMessage(Player player, String... messages) {
public void sendMessage(LivingEntity player, String... messages) {
sendMessage(player, Arrays.asList(messages));
}
public void sendMessage(Player player, List<String> messages) {
public void sendMessage(LivingEntity player, List<String> messages) {
for(String s : messages) {
player.sendMessage(StringUtils.get().translateColor(s));
}

View File

@ -19,7 +19,7 @@
</modules>
<properties>
<plugin.version>1.0.0-SNAPSHOT-U58</plugin.version>
<plugin.version>1.0.0-SNAPSHOT-U59</plugin.version>
<plugin.name>EpicBosses</plugin.name>
<plugin.main>com.songoda.epicbosses.CustomBosses</plugin.main>
<plugin.author>AMinecraftDev</plugin.author>