use of com.solinia.solinia.Exceptions.CoreStateInitException in project solinia3-core by mixxit.
the class SoliniaNPC method processChatInteractionEvent.
@Override
public void processChatInteractionEvent(SoliniaLivingEntity solentity, LivingEntity triggerentity, String data) {
String[] words = data.split(" ");
// Merchant special commands
if (words.length > 0) {
// Check player has sufficient faction
if (triggerentity instanceof Player)
if (solentity.getNpcid() > 0) {
try {
ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(solentity.getNpcid());
if (npc.getFactionid() > 0) {
ISoliniaPlayer solPlayer = SoliniaPlayerAdapter.Adapt((Player) triggerentity);
PlayerFactionEntry factionEntry = solPlayer.getFactionEntry(npc.getFactionid());
if (factionEntry != null) {
switch(Utils.getFactionStandingType(factionEntry.getFactionId(), factionEntry.getValue())) {
case FACTION_THREATENLY:
case FACTION_SCOWLS:
solentity.emote("* " + npc.getName() + " scowls angrily at " + solPlayer.getFullName());
return;
default:
break;
}
}
}
} catch (CoreStateInitException e) {
}
}
switch(words[0].toUpperCase()) {
case "SHOP":
if (triggerentity instanceof Player)
if (getMerchantid() > 0) {
if (words.length == 1) {
sendMerchantItemListToPlayer((Player) triggerentity, 1);
return;
}
int page = 1;
try {
page = Integer.parseInt(words[1]);
} catch (Exception e) {
}
if (page < 1)
page = 1;
sendMerchantItemListToPlayer((Player) triggerentity, page);
}
return;
case "LISTEFFECTS":
if (triggerentity instanceof Player) {
if (((Player) triggerentity).isOp()) {
Player player = (Player) triggerentity;
try {
for (SoliniaActiveSpell spell : StateManager.getInstance().getEntityManager().getActiveEntitySpells(solentity.getBukkitLivingEntity()).getActiveSpells()) {
player.sendMessage(spell.getSpell().getName());
for (ActiveSpellEffect effect : spell.getActiveSpellEffects()) {
player.sendMessage(" - " + effect.getSpellEffectType().name() + " " + effect.getBase());
}
}
} catch (CoreStateInitException e) {
//
}
}
}
return;
default:
break;
}
}
// Normal text matching
for (ISoliniaNPCEventHandler handler : getEventHandlers()) {
if (!handler.getInteractiontype().equals(InteractionType.CHAT))
continue;
if (!data.toUpperCase().contains(handler.getTriggerdata().toUpperCase()))
continue;
if (handler.getChatresponse() != null && !handler.getChatresponse().equals("")) {
if ((triggerentity instanceof Player)) {
if (!handler.playerMeetsRequirements((Player) triggerentity))
return;
}
String response = handler.getChatresponse();
solentity.say(replaceChatWordsWithHints(response), triggerentity);
if (triggerentity instanceof Player)
handler.awardPlayer((Player) triggerentity);
if (handler.getTeleportResponse() != null && !handler.getTeleportResponse().equals("")) {
if (triggerentity instanceof Player) {
String[] zonedata = handler.getTeleportResponse().split(",");
// Dissasemble the value to ensure it is correct
String world = zonedata[0];
double x = Double.parseDouble(zonedata[1]);
double y = Double.parseDouble(zonedata[2]);
double z = Double.parseDouble(zonedata[3]);
Location loc = new Location(Bukkit.getWorld(world), x, y, z);
((Player) triggerentity).teleport(loc);
}
}
}
}
return;
}
use of com.solinia.solinia.Exceptions.CoreStateInitException in project solinia3-core by mixxit.
the class SoliniaNPC method disableAllSpawners.
@Override
public void disableAllSpawners(boolean parseBoolean) {
try {
for (ISoliniaSpawnGroup group : StateManager.getInstance().getConfigurationManager().getSpawnGroups()) {
if (group.getNpcid() == this.getId()) {
System.out.println("Set Spawner Disabled Status: " + group.getId() + ":" + group.getName() + " - " + parseBoolean);
group.setDisabled(parseBoolean);
StateManager.getInstance().getEntityManager().getNPCEntityProvider().removeSpawnGroup(group);
}
}
} catch (CoreStateInitException e) {
}
}
use of com.solinia.solinia.Exceptions.CoreStateInitException in project solinia3-core by mixxit.
the class SoliniaNPCEventHandler method editTriggerEventSetting.
@Override
public void editTriggerEventSetting(String setting, String value) throws InvalidNPCEventSettingException {
switch(setting.toLowerCase()) {
case "randomisedgearsuffix":
setRandomisedGearSuffix(value);
break;
case "title":
setTitle(value);
break;
case "awardstitle":
setAwardsTitle(Boolean.parseBoolean(value));
break;
case "triggerdata":
if (value.equals(""))
throw new InvalidNPCEventSettingException("Triggerdata is empty");
if (value.contains(" "))
throw new InvalidNPCEventSettingException("Triggerdata can only be one value");
setTriggerdata(value.toUpperCase());
break;
case "chatresponse":
if (value.equals(""))
throw new InvalidNPCEventSettingException("Chatresponse is empty");
setChatresponse(value);
break;
case "requiresquest":
int questid = Integer.parseInt(value);
if (questid < 1)
throw new InvalidNPCEventSettingException("Invalid quest id");
try {
ISoliniaQuest quest = StateManager.getInstance().getConfigurationManager().getQuest(questid);
if (quest == null)
throw new InvalidNPCEventSettingException("Invalid quest id");
} catch (CoreStateInitException e) {
throw new InvalidNPCEventSettingException("State not initialised");
}
setRequiresQuest(questid);
break;
case "awardsquest":
int aquestid = Integer.parseInt(value);
if (aquestid < 1)
throw new InvalidNPCEventSettingException("Invalid quest id");
try {
ISoliniaQuest quest = StateManager.getInstance().getConfigurationManager().getQuest(aquestid);
if (quest == null)
throw new InvalidNPCEventSettingException("Invalid quest id");
} catch (CoreStateInitException e) {
throw new InvalidNPCEventSettingException("State not initialised");
}
setAwardsQuest(aquestid);
break;
case "requiresquestflag":
setRequiresQuestFlag(value);
break;
case "awardsquestflag":
setAwardsQuestFlag(value);
break;
case "teleportresponse":
try {
String[] zonedata = value.split(",");
// Dissasemble the value to ensure it is correct
String world = zonedata[0];
double x = Double.parseDouble(zonedata[1]);
double y = Double.parseDouble(zonedata[2]);
double z = Double.parseDouble(zonedata[3]);
setTeleportResponse(world + "," + x + "," + y + "," + z);
break;
} catch (Exception e) {
throw new InvalidNPCEventSettingException("Teleport zone value must be in format: world,x,y,z");
}
case "awardsrandomisedgear":
setAwardsRandomisedGear(Boolean.parseBoolean(value));
break;
case "awardsitem":
int itemId = Integer.parseInt(value);
if (itemId < 1)
throw new InvalidNPCEventSettingException("Invalid item ID");
if (getAwardsQuestFlag() == null || getAwardsQuestFlag().equals(""))
throw new InvalidNPCEventSettingException("You cannot set an awardsitem to a npc event handler unless the npc awards a quest flag - this is to prevent duplicated awards");
try {
ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemId);
if (item == null)
throw new InvalidNPCEventSettingException("Invalid item id");
} catch (CoreStateInitException e) {
throw new InvalidNPCEventSettingException("State not initialised");
}
setAwardsItem(itemId);
break;
default:
throw new InvalidNPCEventSettingException("Invalid NPC Event setting. Valid Options are: triggerdata,chatresponse,interactiontype,requiresquest,awardsquest,requiresquestflag,awardsquestflag,awardsitem");
}
}
use of com.solinia.solinia.Exceptions.CoreStateInitException in project solinia3-core by mixxit.
the class SoliniaLivingEntity method doRandomChat.
@Override
public void doRandomChat() {
if (isPlayer())
return;
if (this.getNpcid() < 1)
return;
try {
ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(this.getNpcid());
if (npc.getRandomchatTriggerText() == null || npc.getRandomchatTriggerText().equals(""))
return;
// 2% chance of saying something
int random = Utils.RandomBetween(1, 100);
if (random < 2) {
this.say(npc.getRandomchatTriggerText());
}
} catch (CoreStateInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of com.solinia.solinia.Exceptions.CoreStateInitException in project solinia3-core by mixxit.
the class SoliniaLivingEntity method checkHitChance.
@Override
public boolean checkHitChance(SoliniaLivingEntity attacker, DamageHitInfo hit) {
ISoliniaLivingEntity defender = this;
if (defender.isPlayer()) {
try {
ISoliniaPlayer player = SoliniaPlayerAdapter.Adapt((Player) defender.getBukkitLivingEntity());
if (player.isMeditating()) {
return true;
}
} catch (CoreStateInitException e) {
// ignore it
}
}
int avoidance = defender.getTotalDefense();
int accuracy = hit.tohit;
// if (accuracy == -1)
// return true;
double hitRoll = Utils.RandomBetween(0, (int) Math.floor(accuracy));
double avoidRoll = Utils.RandomBetween(0, (int) Math.floor(avoidance));
// tie breaker? Don't want to be biased any one way
return hitRoll > avoidRoll;
}
Aggregations