Fix up spells somewhat

This commit is contained in:
libraryaddict 2015-01-18 21:20:32 +13:00
parent 9b574de541
commit e11e2090ad
3 changed files with 147 additions and 94 deletions

View File

@ -228,7 +228,7 @@ public enum SpellType // ❤
30, // Spell cooldown
0, // Mana cost change per level
0, // Cooldown change per level
500, // Item amount in loot
5, // Item amount in loot
C.cGold + C.Bold + "Launch Height: " + C.Bold + C.cWhite + "Spell Level x 5 blocks",
@ -622,8 +622,9 @@ public enum SpellType // ❤
public ItemStack getSpellBook(WizardBattles wizards)
{
return makeSpell(wizards, new ItemBuilder(Material.ENCHANTED_BOOK).addLore(C.cAqua + "Click on this to learn a spell")
.build());
return makeSpell(wizards, new ItemBuilder(Material.ENCHANTED_BOOK).addLore(C.cAqua + "Click to level up this spell")
.build());
}
public Class<? extends Spell> getSpellClass()

View File

@ -57,7 +57,6 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.event.player.PlayerChatEvent;
@ -77,13 +76,13 @@ import org.bukkit.util.Vector;
public class WizardBattles extends SoloGame
{
private NautHashMap<String, SpellType> _learnedSpellChests = new NautHashMap<String, SpellType>();
private NautHashMap<String, ArrayList<String>> _learnedSpellChests = new NautHashMap<String, ArrayList<String>>();
/**
* The entry is so I can randomize the amounts of the items found
*/
private ArrayList<Entry<ItemStack, Integer>> _randomItems = new ArrayList<Entry<ItemStack, Integer>>();
private NautHashMap<SpellType, Spell> _spells = new NautHashMap<SpellType, Spell>();
private NautHashMap<String, Long> _timeSinceDisplayedMiddle = new NautHashMap<String, Long>();
private WizardSpellMenu _wizard;
private NautHashMap<String, Wizard> _wizards = new NautHashMap<String, Wizard>();
@ -129,6 +128,23 @@ public class WizardBattles extends SoloGame
createLoot();
}
private void addMiddleText(Player p, String message)
{
ArrayList<String> arraylist;
if (_learnedSpellChests.containsKey(p.getName()))
{
arraylist = _learnedSpellChests.get(p.getName());
}
else
{
arraylist = new ArrayList<String>();
_learnedSpellChests.put(p.getName(), arraylist);
}
arraylist.add(message);
}
private void addRandomItem(int amount, Material itemType, int newDurability, int minAmount, int maxAmount)
{
HashMap.SimpleEntry entry = new HashMap.SimpleEntry(new ItemStack(itemType, minAmount, (short) newDurability), maxAmount
@ -441,52 +457,29 @@ public class WizardBattles extends SoloGame
InventoryHolder holder = (InventoryHolder) state;
Inventory inv = holder.getInventory();
boolean addedSpell = false;
boolean containsSpell = false;
for (int i = 0; i < 5; i++)
for (int i = 0; i < 5 || !containsSpell; i++)
{
Entry<ItemStack, Integer> entry = _randomItems.get(UtilMath.r(_randomItems.size()));
ItemStack item = entry.getKey().clone();
// Don't allow 2 books in one chest, else I'd have to do better code to display learned spells after the previous
// expired.
if (item.getType() == Material.ENCHANTED_BOOK)
// Every chest has a spell.
if (i > 5 && item.getType() != Material.ENCHANTED_BOOK)
{
if (addedSpell)
{
i--;
continue;
}
addedSpell = true;
continue;
}
if (!containsSpell)
{
containsSpell = item.getType() == Material.ENCHANTED_BOOK;
}
item.setAmount(item.getAmount() + UtilMath.r(entry.getValue() + 1));
inv.setItem(UtilMath.r(inv.getSize()), item);
}
// Make every chest contain a spellbook
if (!inv.contains(Material.ENCHANTED_BOOK))
{
while (true)
{
Entry<ItemStack, Integer> entry = _randomItems.get(UtilMath.r(_randomItems.size()));
if (entry.getKey().getType() == Material.ENCHANTED_BOOK)
{
ItemStack item = entry.getKey().clone();
item.setAmount(item.getAmount() + UtilMath.r(entry.getValue() + 1));
inv.setItem(UtilMath.r(inv.getSize()), item);
break;
}
}
}
state.update();
}
}
@ -627,7 +620,9 @@ public class WizardBattles extends SoloGame
if (onSpellLearn(p, spell))
{
event.setCurrentItem(new ItemStack(Material.AIR));
_learnedSpellChests.put(p.getName(), spell);
addMiddleText(p, spell.getElement().getColor() + spell.getSpellName() + " leveled to "
+ spell.getElement().getColor() + getWizard(p).getSpellLevel(spell));
}
}
}
@ -647,20 +642,6 @@ public class WizardBattles extends SoloGame
}
}
@EventHandler
public void onClose(InventoryCloseEvent event)
{
Player p = (Player) event.getPlayer();
if (IsAlive(p) && _learnedSpellChests.containsKey(p.getName()))
{
SpellType spell = _learnedSpellChests.remove(p.getName());
Wizard wizard = getWizard(p);
UtilTextMiddle.display("", spell.getElement().getColor() + spell.getSpellName() + " leveled to "
+ spell.getElement().getColor() + wizard.getSpellLevel(spell), 5, 40, 5, p);
}
}
@EventHandler
public void onDamage(EntityDamageByEntityEvent event)
{
@ -800,7 +781,8 @@ public class WizardBattles extends SoloGame
new ItemBuilder(makeUnusedWand()).setTitle(C.cWhite + "Left click to set a spell").build());
p.updateInventory();
UtilTextMiddle.display("", C.cGold + "Gained a wand", p);
addMiddleText(p, C.cGold + "Gained a wand");
return true;
}
return false;
@ -871,8 +853,10 @@ public class WizardBattles extends SoloGame
if (wizard.getSpellLevel(spell) < spell.getMaxLevel())
{
onSpellLearn(player, spell);
UtilTextMiddle.display("", spell.getElement().getColor() + spell.getSpellName() + " leveled to "
+ spell.getElement().getColor() + wizard.getSpellLevel(spell), 5, 40, 5, player);
break;
}
}
@ -918,8 +902,8 @@ public class WizardBattles extends SoloGame
{
Wizard wizard = getWizard(p);
UtilTextMiddle.display("", spell.getElement().getColor() + spell.getSpellName() + " leveled to "
+ spell.getElement().getColor() + wizard.getSpellLevel(spell), 5, 40, 5, p);
addMiddleText(p, spell.getElement().getColor() + spell.getSpellName() + " leveled to "
+ spell.getElement().getColor() + wizard.getSpellLevel(spell));
event.setCancelled(true);
event.getItem().remove();
@ -947,29 +931,47 @@ public class WizardBattles extends SoloGame
@EventHandler
public void onSecond(UpdateEvent event)
{
if ((event.getType() == UpdateType.TICK) && GetState() == GameState.Live)
if (event.getType() == UpdateType.TICK)
{
Iterator<Entry<String, Wizard>> itel = _wizards.entrySet().iterator();
Iterator<Entry<String, ArrayList<String>>> itel = _learnedSpellChests.entrySet().iterator();
while (itel.hasNext())
{
Entry<String, Wizard> entry = itel.next();
Player player = Bukkit.getPlayerExact(entry.getKey());
Wizard wizard = getWizard(player);
float newMana = wizard.getMana();
Entry<String, ArrayList<String>> entry = itel.next();
if (newMana < wizard.getMaxMana())
Player p = Bukkit.getPlayerExact(entry.getKey());
if (p != null && IsAlive(p))
{
newMana = Math.min(newMana + wizard.getManaPerTick(), wizard.getMaxMana());
wizard.setMana(newMana);
// If 40 ticks has passed since last sent the middle text, send another.
if ((!_timeSinceDisplayedMiddle.containsKey(entry.getKey()) || _timeSinceDisplayedMiddle.get(entry.getKey()) <= System
.currentTimeMillis()) && p.getOpenInventory().getType() == InventoryType.PLAYER)
{
UtilTextMiddle.display("", entry.getValue().remove(0), 5, 30, 5, p);
if (entry.getValue().isEmpty())
{
itel.remove();
_timeSinceDisplayedMiddle.remove(entry.getKey());
}
else
{
_timeSinceDisplayedMiddle.put(entry.getKey(), System.currentTimeMillis() + (40 * 1000L));
}
}
}
else
{
itel.remove();
_timeSinceDisplayedMiddle.remove(entry.getKey());
}
UtilTextTop.displayTextBar(player, Math.min(1, wizard.getMana() / wizard.getMaxMana()),
(int) Math.floor(wizard.getMana()) + "/" + (int) wizard.getMaxMana() + " mana "
+ UtilTime.convert((int) (wizard.getManaPerTick() * 20000), 1, TimeUnit.SECONDS) + "mps");
displaySpellWand(player);
}
}
}
@ -1010,6 +1012,39 @@ public class WizardBattles extends SoloGame
}
}
@EventHandler
public void onTick(UpdateEvent event)
{
if ((event.getType() == UpdateType.TICK) && GetState() == GameState.Live)
{
Iterator<Entry<String, Wizard>> itel = _wizards.entrySet().iterator();
while (itel.hasNext())
{
Entry<String, Wizard> entry = itel.next();
Player player = Bukkit.getPlayerExact(entry.getKey());
Wizard wizard = getWizard(player);
float newMana = wizard.getMana();
if (newMana < wizard.getMaxMana())
{
newMana = Math.min(newMana + wizard.getManaPerTick(), wizard.getMaxMana());
wizard.setMana(newMana);
}
float percentage = Math.min(1, wizard.getMana() / wizard.getMaxMana());
String text = (int) Math.floor(wizard.getMana()) + "/" + (int) wizard.getMaxMana() + " mana "
+ UtilTime.convert((int) (wizard.getManaPerTick() * 20000), 1, TimeUnit.SECONDS) + "mps";
UtilTextTop.displayTextBar(player, percentage, text);
displaySpellWand(player);
}
}
}
@EventHandler
public void onUnplaceablePlace(BlockPlaceEvent event)
{

View File

@ -1,51 +1,68 @@
package nautilus.game.arcade.game.games.wizards.spells.subclasses;
import java.util.HashMap;
import java.util.UUID;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilShapes;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.minecraft.game.core.damage.DamageManager;
import mineplex.minecraft.game.core.explosion.CustomExplosion;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
public class LaunchRune
{
private Location _explosiveLocation;
private float _explosiveSize;
private Location _runeLocation;
private float _runeSize;
private int _ticksTillActive = 60;
private float _launchHeight;
private HashMap<UUID, Long> _launchedEntities = new HashMap<UUID, Long>();
public boolean onTick()
{
_ticksTillActive--;
boolean launched = false;
if (_ticksTillActive <= 0)
{
for (LivingEntity entity : _explosiveLocation.getWorld().getEntitiesByClass(LivingEntity.class))
for (LivingEntity entity : _runeLocation.getWorld().getEntitiesByClass(LivingEntity.class))
{
Location loc = entity.getLocation();
if (loc.getY() >= _explosiveLocation.getY() && loc.getY() <= _explosiveLocation.getY() + 1)
UUID uuid = entity.getUniqueId();
if (!_launchedEntities.containsKey(uuid) || _launchedEntities.get(uuid) < System.currentTimeMillis())
{
loc.setY(_explosiveLocation.getY());
if (loc.distance(_explosiveLocation) <= _explosiveSize)
Location loc = entity.getLocation();
if (loc.getY() >= _runeLocation.getY() && loc.getY() <= _runeLocation.getY() + 1)
{
loc.getWorld().playSound(_explosiveLocation, Sound.BAT_TAKEOFF, 1.2F, 1F);
Vector vector = entity.getLocation().getDirection().normalize().multiply(0.1);
vector.setY(_launchHeight);
entity.setVelocity(vector);
entity.setFallDistance(0);
loc.setY(_runeLocation.getY());
displayCircle(5);
if (loc.distance(_runeLocation) <= _runeSize)
{
Vector vector = entity.getLocation().getDirection().normalize().multiply(0.1);
vector.setY(_launchHeight);
entity.setVelocity(vector);
entity.setFallDistance(0);
launched = true;
_launchedEntities.put(uuid, System.currentTimeMillis() + (long) (_runeSize * 2500L));
}
}
}
}
}
if (_ticksTillActive % (_ticksTillActive >= 0 ? 20 : 7) == 0)
if (launched)
{
_runeLocation.getWorld().playSound(_runeLocation, Sound.BAT_TAKEOFF, 1.2F, 1F);
displayCircle(5);
}
else if (_ticksTillActive % (_ticksTillActive >= 0 ? 20 : 7) == 0)
{
displayCircle(1);
}
@ -57,7 +74,7 @@ public class LaunchRune
{
for (double y = 0; y < loops * 0.2D; y += 0.2D)
{
for (Location loc : UtilShapes.getDistancedCircle(_explosiveLocation, 0.3D, _explosiveSize))
for (Location loc : UtilShapes.getDistancedCircle(_runeLocation, 0.3D, _runeSize))
{
UtilParticle.PlayParticle(ParticleType.CLOUD, loc, 0, 0, 0, 0, 1);
}
@ -66,14 +83,14 @@ public class LaunchRune
public LaunchRune(Location loc, float size, int spellLevel)
{
_explosiveLocation = loc;
_explosiveSize = size;
_runeLocation = loc;
_runeSize = size;
_launchHeight = 0.5F + (spellLevel * 0.5F);
displayCircle(1);
}
public Location getLocation()
{
return _explosiveLocation;
return _runeLocation;
}
}