Treasure updates
This commit is contained in:
parent
fc6a2633c9
commit
71f42c6e7b
@ -67,7 +67,7 @@ public class Treasure
|
||||
_chestData[2] = new ChestData(_centerBlock.getRelative(0, 1, 2), rewards[2]);
|
||||
_chestData[3] = new ChestData(_centerBlock.getRelative(0, 1, -2), rewards[3]);
|
||||
|
||||
Bukkit.broadcastMessage(F.main("Treasure", F.name(_player.getName()) + " is opening treasure at " + F.elem(_centerBlock.getX() + ", " + _centerBlock.getZ()) + "!"));
|
||||
Bukkit.broadcastMessage(F.main("Treasure", F.name(_player.getName()) + " is opening a Treasure Chest"));
|
||||
}
|
||||
|
||||
private void createCenterClay()
|
||||
@ -130,19 +130,18 @@ public class Treasure
|
||||
}
|
||||
}
|
||||
|
||||
public int getFinishedTickCount()
|
||||
{
|
||||
return _finishedTickCount;
|
||||
}
|
||||
|
||||
public void update()
|
||||
{
|
||||
if (_finished)
|
||||
{
|
||||
if (_finishedTickCount >= 100)
|
||||
{
|
||||
finish();
|
||||
}
|
||||
|
||||
_finishedTickCount++;
|
||||
}
|
||||
|
||||
|
||||
if (_tickCount == 5)
|
||||
{
|
||||
Block block = _centerBlock;
|
||||
@ -276,6 +275,11 @@ public class Treasure
|
||||
return null;
|
||||
}
|
||||
|
||||
public Player getPlayer()
|
||||
{
|
||||
return _player;
|
||||
}
|
||||
|
||||
public boolean isFinished()
|
||||
{
|
||||
boolean allOpened = true;
|
||||
@ -288,7 +292,7 @@ public class Treasure
|
||||
return allOpened;
|
||||
}
|
||||
|
||||
public void finish()
|
||||
public void cleanup()
|
||||
{
|
||||
for (ChestData chestData : _chestData)
|
||||
{
|
||||
@ -317,9 +321,6 @@ public class Treasure
|
||||
animation.finish();
|
||||
}
|
||||
_animations.clear();
|
||||
|
||||
TreasureFinishEvent event = new TreasureFinishEvent(_player, this);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
}
|
||||
|
||||
public TreasureStyle getStyle()
|
||||
|
@ -1,5 +1,7 @@
|
||||
package mineplex.core.treasure;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -20,6 +22,7 @@ import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.common.util.UtilAction;
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilBlock;
|
||||
import mineplex.core.common.util.UtilEnt;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
@ -119,13 +122,13 @@ public class TreasureManager extends MiniPlugin
|
||||
{
|
||||
for (Treasure treasure : _playerTreasureMap.values())
|
||||
{
|
||||
treasure.finish();
|
||||
treasure.cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
public void attemptOpenTreasure(Player player)
|
||||
{
|
||||
if (!checkNearbyBlocks(player) || checkNearSpawn(player))
|
||||
if (!checkNearbyBlocks(player) || checkNearSpawn(player) || checkInAir(player))
|
||||
return;
|
||||
|
||||
TreasureStartEvent event = new TreasureStartEvent(player);
|
||||
@ -133,7 +136,6 @@ public class TreasureManager extends MiniPlugin
|
||||
|
||||
if (event.isCancelled())
|
||||
{
|
||||
player.sendMessage(F.main("Treasure", "Failed to create a treasure. Unknown reason"));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -163,7 +165,7 @@ public class TreasureManager extends MiniPlugin
|
||||
Block block = centerBlock.getRelative(x, y, z);
|
||||
if (UtilBlock.solid(block))
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Treasure", "You can not open a treasure at this spot. Please find an open location"));
|
||||
UtilPlayer.message(player, F.main("Treasure", "You can't open chests here."));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -172,12 +174,22 @@ public class TreasureManager extends MiniPlugin
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean checkInAir(Player player)
|
||||
{
|
||||
boolean grounded = UtilEnt.isGrounded(player);
|
||||
|
||||
if (!grounded)
|
||||
UtilPlayer.message(player, F.main("Treasure", "You can't open chests while in the air."));
|
||||
|
||||
return !grounded;
|
||||
}
|
||||
|
||||
private boolean checkNearSpawn(Player player)
|
||||
{
|
||||
boolean nearSpawn = UtilMath.offset2d(new Location(player.getWorld(), 0, 0, 0), player.getLocation()) < 10;
|
||||
|
||||
if (nearSpawn)
|
||||
UtilPlayer.message(player, F.main("Treasure", "You are too close to the spawn to open a treasure chest!"));
|
||||
UtilPlayer.message(player, F.main("Treasure", "You can't open chests near spawn."));
|
||||
|
||||
return nearSpawn;
|
||||
}
|
||||
@ -188,9 +200,21 @@ public class TreasureManager extends MiniPlugin
|
||||
if (event.getType() != UpdateType.TICK)
|
||||
return;
|
||||
|
||||
for (Treasure treasure : _playerTreasureMap.values())
|
||||
Iterator<Treasure> iterator = _playerTreasureMap.values().iterator();
|
||||
while(iterator.hasNext())
|
||||
{
|
||||
Treasure treasure = iterator.next();
|
||||
|
||||
treasure.update();
|
||||
|
||||
if (treasure.isFinished() && treasure.getFinishedTickCount() >= 100)
|
||||
{
|
||||
treasure.cleanup();
|
||||
iterator.remove();
|
||||
|
||||
TreasureFinishEvent finishEvent = new TreasureFinishEvent(treasure.getPlayer(), treasure);
|
||||
Bukkit.getPluginManager().callEvent(finishEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -200,7 +224,7 @@ public class TreasureManager extends MiniPlugin
|
||||
if (_playerTreasureMap.containsKey(event.getPlayer()))
|
||||
{
|
||||
Treasure treasure = _playerTreasureMap.remove(event.getPlayer());
|
||||
treasure.finish();
|
||||
treasure.cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,13 +41,13 @@ public class FireworksAnimation extends Animation
|
||||
@Override
|
||||
protected void tick()
|
||||
{
|
||||
if (getTicks() >= 20 * 3)
|
||||
if (getTicks() >= 20)
|
||||
finish();
|
||||
|
||||
if (getTicks() % 10 == 0)
|
||||
{
|
||||
double xDif = _random.nextGaussian() * 2;
|
||||
double zDif = _random.nextGaussian() * 2;
|
||||
double xDif = _random.nextGaussian() * 1;
|
||||
double zDif = _random.nextGaussian() * 1;
|
||||
double yDif = (_random.nextInt(3) * _random.nextDouble()) + 2;
|
||||
|
||||
FireworkEffect effect = FireworkEffect.builder().withColor(Color.fromRGB(_random.nextInt(255), _random.nextInt(255), _random.nextInt(255)))
|
||||
|
@ -39,15 +39,21 @@ public class RewardManager
|
||||
{
|
||||
int currentReward = 0;
|
||||
ITreasureReward[] rewards = new ITreasureReward[4];
|
||||
boolean hasUncommon = false;
|
||||
|
||||
while (currentReward < 4)
|
||||
{
|
||||
ITreasureReward reward = nextReward(player, rewards);
|
||||
ITreasureReward reward = nextReward(player, rewards, currentReward == 3 && !hasUncommon);
|
||||
|
||||
if (reward == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (reward.getRarity().ordinal() >= RewardRarity.UNCOMMON.ordinal())
|
||||
{
|
||||
hasUncommon = true;
|
||||
}
|
||||
rewards[currentReward] = reward;
|
||||
currentReward++;
|
||||
}
|
||||
@ -56,6 +62,11 @@ public class RewardManager
|
||||
}
|
||||
|
||||
private ITreasureReward nextReward(Player player, ITreasureReward[] excludedRewards)
|
||||
{
|
||||
return nextReward(player, excludedRewards, false);
|
||||
}
|
||||
|
||||
private ITreasureReward nextReward(Player player, ITreasureReward[] excludedRewards, boolean requiresUncommon)
|
||||
{
|
||||
double rand = _random.nextDouble();
|
||||
RewardRarity rarity;
|
||||
@ -70,7 +81,7 @@ public class RewardManager
|
||||
// 4%
|
||||
rarity = RewardRarity.RARE;
|
||||
}
|
||||
else if (rand <= 0.30)
|
||||
else if (rand <= 0.30 || requiresUncommon)
|
||||
{
|
||||
// 25%
|
||||
rarity = RewardRarity.UNCOMMON;
|
||||
|
@ -1,17 +1,31 @@
|
||||
package mineplex.core.treasure.reward;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import static mineplex.core.common.util.C.*;
|
||||
|
||||
/**
|
||||
* Created by Shaun on 9/2/2014.
|
||||
*/
|
||||
public enum RewardRarity
|
||||
{
|
||||
|
||||
/**
|
||||
* This will probably be used to figure out what effects are shown when the chest is opened
|
||||
*
|
||||
* (Fireworks, sounds, etc)
|
||||
*/
|
||||
|
||||
COMMON, UNCOMMON, RARE, VERY_RARE;
|
||||
COMMON(cAqua), UNCOMMON(cGreen), RARE(cGold), VERY_RARE(cRed);
|
||||
|
||||
private String _color;
|
||||
|
||||
RewardRarity(String color)
|
||||
{
|
||||
_color = color;
|
||||
}
|
||||
|
||||
public String getColor()
|
||||
{
|
||||
return _color;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ public class CoinReward extends AbstractReward
|
||||
}
|
||||
}, "Treasure Chest", player.getName(), gemsToReward);
|
||||
|
||||
return C.cYellow + gemsToReward + " Coins";
|
||||
return getRarity().getColor() + gemsToReward + " Coins";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -27,7 +27,7 @@ public class GadgetReward extends AbstractReward
|
||||
{
|
||||
_donationManager.Get(player.getName()).AddUnknownSalesPackagesOwned(_gadget.GetName());
|
||||
|
||||
return _gadget.GetDisplayName();
|
||||
return getRarity().getColor() + _gadget.GetDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -47,7 +47,7 @@ public class InventoryReward extends AbstractReward
|
||||
|
||||
_inventoryManager.addItemToInventory(player, "Item", _packageName, amountToGive);
|
||||
|
||||
return C.cAqua + amountToGive + " " + _name;
|
||||
return getRarity().getColor() + amountToGive + " " + _name;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -29,7 +29,7 @@ public class UnknownPackageReward extends AbstractReward
|
||||
{
|
||||
_donationManager.Get(player.getName()).AddUnknownSalesPackagesOwned(_packageName);
|
||||
|
||||
return _name;
|
||||
return getRarity().getColor() + _name;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,6 +39,7 @@ import mineplex.core.gadget.event.GadgetBlockEvent;
|
||||
import mineplex.core.mount.event.MountActivateEvent;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import mineplex.core.task.TaskManager;
|
||||
import mineplex.core.treasure.event.TreasureStartEvent;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.hub.HubManager;
|
||||
@ -356,7 +357,7 @@ public class ParkourManager extends MiniPlugin
|
||||
if (!isParkourMode(player))
|
||||
{
|
||||
//Inform
|
||||
UtilPlayer.message(player, F.main("Parkour", "You must be in " + F.elem("Parkour Mode") + " to finish."));
|
||||
UtilPlayer.message(player, F.main("Parkour", "You must be in " + F.elem("Parkour Mode") + " to cleanup."));
|
||||
UtilPlayer.message(player, F.main("Parkour", "Talk to the " + F.elem("Start NPC") + " to enter Parkour Mode."));
|
||||
return;
|
||||
}
|
||||
@ -418,7 +419,16 @@ public class ParkourManager extends MiniPlugin
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void preventTreasureNearParkour(TreasureStartEvent event)
|
||||
{
|
||||
if (InsideParkour(event.getPlayer().getLocation()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
UtilPlayer.message(event.getPlayer(), F.main("Parkour", "You can't open chests near Parkour."));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void snakeUpdate(UpdateEvent event)
|
||||
|
Loading…
Reference in New Issue
Block a user