Skip to content

Commit

Permalink
Add optional requirement to shops. Also limit distance between pylons to
Browse files Browse the repository at this point in the history
avoid massive server lag from trolls
  • Loading branch information
Dove-Bren committed Jul 21, 2016
1 parent 9c531a1 commit fb91b18
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public static enum PluginConfigurationKey {
HOLDERNAME("interface.magic.holderName", Category.PLAYER, "Spellholder Name", "What name should spellholders have to be considered valid spellholders?", "Spell Vessel"),
ALLOWWEAVING("spellweaving.enabled", Category.FEATURE, "Enable Spellweaving", "Should spellweaving be enabled?", true),
USEINVOKER("spellweaving.useInvoker", Category.FEATURE, "Use Invoker", "Can players use an item invoker to invoke their spellweaving spells?", true),
PYLONMAXDISTANCE("spellweaving.maxDistance", Category.FEATURE, "Max Pylon Distance", "Maximum distance between pylons allowed. Limits cast load", 20.0),
INVOKERNAME("interface.spellweaving.invokerName", Category.PLAYER, "Invoker Name", "What name should an invoker have to be considered valid", "Spell Invoker"),
INVOKERTYPE("interface.spellweaving.invokerType", Category.PLAYER, "Invoker Type", "What material type is the spell invoker?", "CARROT_STICK"),
RECALLERTYPE("interface.recall.recallerType", Category.PLAYER, "Recaller Type", "What material is used as the recaller object? If the player can't get the item, they can only recall if you set up a recall spell", "BOOK"),
Expand Down Expand Up @@ -571,6 +572,10 @@ public Map<Sound, Double> getMusicDurations() {
return map;
}

public Double getMaxPylonDistance() {
return config.getDouble(PluginConfigurationKey.PYLONMAXDISTANCE.key, (Double) PluginConfigurationKey.PYLONMAXDISTANCE.def);
}

public Object getBaseValue(PluginConfigurationKey key) {
return config.get(key.key, key.def);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,28 @@
package com.skyisland.questmanager.magic.spell.effect;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;

import com.skyisland.questmanager.QuestManagerPlugin;
import com.skyisland.questmanager.magic.MagicUser;
import com.skyisland.questmanager.magic.SpellPylon;
import com.skyisland.questmanager.player.QuestPlayer;

/**
* Creates in the world a pylon ties to the given player of a certain type
*
*/
public class CastPylonEffect extends SpellEffect {

public static final String DISTANCE_ERROR_MESSAGE = ChatColor.RED + "The pylon would be too far from the others, and was not set!";

/**
* Registers this class as configuration serializable with all defined
* {@link aliases aliases}
Expand Down Expand Up @@ -97,14 +103,32 @@ public CastPylonEffect(String name, ItemStack icon) {
@Override
public void apply(Entity e, MagicUser cause) {
//cast it at location of entity?
SpellPylon pylon = new SpellPylon(type, icon, e.getLocation());

cause.addSpellPylon(pylon);
apply(e.getLocation(), cause);
// SpellPylon pylon = new SpellPylon(type, icon, e.getLocation());
//
// cause.addSpellPylon(pylon);

}

@Override
public void apply(Location loc, MagicUser cause) {
List<SpellPylon> active = cause.getSpellPylons();
double maxDistance = QuestManagerPlugin.questManagerPlugin.getPluginConfiguration().getMaxPylonDistance();
if (active != null && !active.isEmpty()) {
for (SpellPylon pylon : active) {

if (pylon.getLocation().distance(loc) > maxDistance) {
if (cause instanceof QuestPlayer) {
QuestPlayer qp = (QuestPlayer) cause;
if (qp.getPlayer().isOnline())
qp.getPlayer().getPlayer().sendMessage(DISTANCE_ERROR_MESSAGE);
}
return; //cancel everything. just stop, cause it's gonna be too big.
}
}
}


SpellPylon pylon = new SpellPylon(type, icon, loc);

cause.addSpellPylon(pylon);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ public static List<String> getEffectTooltip(PotionEffect effect, String displayN
list.add(ChatColor.WHITE + "Grants temporary health that cannot be");
list.add(ChatColor.WHITE + "regenerated, but will be deducted from");
list.add(ChatColor.WHITE + "first");
list.add(ChatColor.GOLD + " Bonus Health: " + ChatColor.GREEN + (4 * effect.getAmplifier())
list.add(ChatColor.GOLD + " Bonus Health: " + ChatColor.GREEN + (4 * (effect.getAmplifier() + 1))
+ ChatColor.RESET);
} else if (effect.getType().equals(PotionEffectType.DAMAGE_RESISTANCE)) {
list.add(ChatColor.WHITE + "Reduces damage taken from all sources");
list.add(ChatColor.GOLD + " Damage Reduction: " + ChatColor.GREEN + (20 * effect.getAmplifier())
list.add(ChatColor.GOLD + " Damage Reduction: " + ChatColor.GREEN + (20 * (effect.getAmplifier() + 1))
+ "%" + ChatColor.RESET);
} else if (effect.getType().equals(PotionEffectType.FAST_DIGGING)) {
list.add(ChatColor.WHITE + "Improves attack speed and digging speed");
Expand All @@ -185,16 +185,16 @@ public static List<String> getEffectTooltip(PotionEffect effect, String displayN
} else if (effect.getType().equals(PotionEffectType.HEALTH_BOOST)) {
list.add(ChatColor.WHITE + "Grants a boost to maximum health for");
list.add(ChatColor.WHITE + "the duration of the effect");
list.add(ChatColor.GOLD + " Bonus Health: " + ChatColor.GREEN + (4 * effect.getAmplifier())
list.add(ChatColor.GOLD + " Bonus Health: " + ChatColor.GREEN + (4 * (effect.getAmplifier() + 1))
+ ChatColor.RESET);
} else if (effect.getType().equals(PotionEffectType.INCREASE_DAMAGE)) {
list.add(ChatColor.WHITE + "Increases melee damage dealt");
list.add(ChatColor.GOLD + " Damage Increase: " + ChatColor.GREEN + (3 * effect.getAmplifier())
list.add(ChatColor.GOLD + " Damage Increase: " + ChatColor.GREEN + (3 * (effect.getAmplifier() + 1))
+ ChatColor.RESET);
} else if (effect.getType().equals(PotionEffectType.LUCK)) {
list.add(ChatColor.WHITE + "Increases the chance of getting better");
list.add(ChatColor.WHITE + "loot from monsters and chests");
list.add(ChatColor.GOLD + " Luck Bonus: " + ChatColor.GREEN + effect.getAmplifier()
list.add(ChatColor.GOLD + " Luck Bonus: " + ChatColor.GREEN + (effect.getAmplifier() + 1)
+ ChatColor.RESET);
} else if (effect.getType().equals(PotionEffectType.POISON)) {
list.add(ChatColor.WHITE + "Deals damage over time until cured");
Expand Down Expand Up @@ -225,19 +225,19 @@ public static List<String> getEffectTooltip(PotionEffect effect, String displayN
(float) effect.getDuration() / 20));
} else if (effect.getType().equals(PotionEffectType.SLOW)) {
list.add(ChatColor.WHITE + "Reduces all movement speed");
list.add(ChatColor.GOLD + " Reduction: " + ChatColor.RED + (15 * effect.getAmplifier())
list.add(ChatColor.GOLD + " Reduction: " + ChatColor.RED + (15 * (effect.getAmplifier() + 1))
+ "%" + ChatColor.RESET);
} else if (effect.getType().equals(PotionEffectType.SLOW_DIGGING)) {
list.add(ChatColor.WHITE + "Reduces swing and mining speed");
list.add(ChatColor.GOLD + " Swing Speed: " + ChatColor.RED + "-"
+ (10 * effect.getAmplifier()) + "%");
} else if (effect.getType().equals(PotionEffectType.SPEED)) {
list.add(ChatColor.WHITE + "Increases movement speed");
list.add(ChatColor.GOLD + " Reduction: " + ChatColor.GREEN + (20 * effect.getAmplifier())
list.add(ChatColor.GOLD + " Reduction: " + ChatColor.GREEN + (20 * (effect.getAmplifier() + 1))
+ "%" + ChatColor.RESET);
} else if (effect.getType().equals(PotionEffectType.WEAKNESS)) {
list.add(ChatColor.WHITE + "Decreases melee damage dealt");
list.add(ChatColor.GOLD + " Damage Penalty: " + ChatColor.RED + (4 * effect.getAmplifier())
list.add(ChatColor.GOLD + " Damage Penalty: " + ChatColor.RED + (4 * (effect.getAmplifier() + 1))
+ ChatColor.RESET);
} else if (effect.getType().equals(PotionEffectType.WITHER)) {
list.add(ChatColor.WHITE + "Deals damage over time until cured");
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/com/skyisland/questmanager/npc/ShopNPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.skyisland.questmanager.npc;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.bukkit.Location;
Expand All @@ -37,9 +38,11 @@
import com.skyisland.questmanager.player.QuestPlayer;
import com.skyisland.questmanager.ui.ChatMenu;
import com.skyisland.questmanager.ui.menu.BioptionChatMenu;
import com.skyisland.questmanager.ui.menu.SimpleChatMenu;
import com.skyisland.questmanager.ui.menu.action.OpenInventoryGuiAction;
import com.skyisland.questmanager.ui.menu.inventory.ShopInventory;
import com.skyisland.questmanager.ui.menu.message.BioptionMessage;
import com.skyisland.questmanager.ui.menu.message.Message;

/**
* NPC which offers to and repairs a players equipment, for a fee
Expand Down Expand Up @@ -84,6 +87,8 @@ public String getAlias() {

private ShopNPC(Location startingLoc) {
super(startingLoc);
altMessage = null;
requirements = null;
}

@Override
Expand Down Expand Up @@ -113,6 +118,7 @@ public Map<String, Object> serialize() {
return map;
}

@SuppressWarnings("unchecked")
public static ShopNPC valueOf(Map<String, Object> map) {
if (map == null || !map.containsKey("name") || !map.containsKey("type")
|| !map.containsKey("location") || !map.containsKey("equipment")
Expand Down Expand Up @@ -167,17 +173,53 @@ public static ShopNPC valueOf(Map<String, Object> map) {
npc.chat.setSourceLabel(label);
}

//update code 3
if (map.containsKey("badrequirementmessage"))
npc.altMessage = (Message) map.get("badrequirementmessage");
if (map.containsKey("requiredquests"))
npc.requirements = (List<String>) map.get("requiredquests");

return npc;
}

private ShopInventory inventory;

private Message altMessage;

private List<String> requirements;

@Override
protected void interact(Player player) {

QuestPlayer qp = QuestManagerPlugin.questManagerPlugin.getPlayerManager()
.getPlayer(player.getUniqueId());

boolean meetreqs = true;

if (requirements != null && !requirements.isEmpty()) {
//go through reqs, see if the player has those quests completed
for (String req : requirements) {
//check for optionals/sets
if (!QuestPlayer.meetsRequirement(qp, req)) {
meetreqs = false;
break;
}
}
}

if (!meetreqs) {
//doesn't have all the required quests done yet!
ChatMenu messageChat;

if (altMessage == null) {
messageChat = new SimpleChatMenu(new FancyMessage("Hail, adventurer."));
} else {
messageChat = ChatMenu.getDefaultMenu(altMessage);
}
messageChat.show(player);
return;
}


ChatMenu messageChat = new BioptionChatMenu(chat,
new OpenInventoryGuiAction(qp, inventory)
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/com/skyisland/questmanager/player/QuestPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public static boolean meetsRequirement(QuestPlayer player, String requirement) {

return true;
}

//"Driven.a" 6
if (requirement.contains(".")) {
int pos = requirement.indexOf(".");
String name = requirement.substring(0, pos);
Expand All @@ -244,6 +244,9 @@ public static boolean meetsRequirement(QuestPlayer player, String requirement) {
}

public static boolean hasKey(QuestPlayer player, String questName, String key) {
if (questName.startsWith("*"))
questName = questName.substring(1);
System.out.println("check haskey. Quest: [" + questName + "] key: [" + key + "]");
if (player.questKeys.containsKey(questName)) {
String keys = player.questKeys.get(questName);
if (key.length() > 1) {
Expand Down Expand Up @@ -2232,6 +2235,20 @@ public void castSpellWeavingSpell() {
private List<Entity> getEntitiesInBound(List<Location> points) {
List<Entity> list = new LinkedList<>();

//prelim area check. Can't be over config values
Location last = null;
double maxDistance = QuestManagerPlugin.questManagerPlugin.getPluginConfiguration().getMaxPylonDistance();
for (Location l : points) {
if (last == null) {
last = l;
continue;
}

if (l.distance(last) > maxDistance) {
return list; //cancel everything. just stop, cause it's gonna be too big.
}
}

if (points == null || points.isEmpty()) {
return list;
}
Expand Down

0 comments on commit fb91b18

Please sign in to comment.