Treasure stuff from laptop
This commit is contained in:
parent
aa77821c20
commit
6441b110b4
@ -5,7 +5,6 @@ import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@ -16,9 +15,7 @@ import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.common.util.UtilParticle;
|
||||
import mineplex.core.treasure.animation.ChestSpawnAnimation;
|
||||
import mineplex.core.treasure.animation.ChestOpenAnimation;
|
||||
import mineplex.core.treasure.animation.ParticleAnimation;
|
||||
import mineplex.core.treasure.animation.Animation;
|
||||
import mineplex.core.treasure.reward.ExampleReward;
|
||||
import mineplex.core.treasure.reward.ITreasureReward;
|
||||
|
||||
/**
|
||||
@ -32,18 +29,17 @@ public class Treasure
|
||||
private Block _centerBlock;
|
||||
private int _tickCount;
|
||||
private ChestData[] _chestData;
|
||||
private ITreasureReward[] _rewards;
|
||||
|
||||
private LinkedList<Animation> _animations;
|
||||
|
||||
private TreasureStyle _style;
|
||||
|
||||
public Treasure(Player player)
|
||||
public Treasure(Player player, ITreasureReward[] rewards)
|
||||
{
|
||||
this(player, new Random());
|
||||
this(player, new Random(), rewards);
|
||||
}
|
||||
|
||||
public Treasure(Player player, Random seed)
|
||||
public Treasure(Player player, Random seed, ITreasureReward[] rewards)
|
||||
{
|
||||
_player = player;
|
||||
_random = seed;
|
||||
@ -56,10 +52,10 @@ public class Treasure
|
||||
// _animations.add(new ParticleAnimation(this));
|
||||
|
||||
_chestData = new ChestData[4];
|
||||
_chestData[0] = new ChestData(_centerBlock.getRelative(2, 1, 0), new ExampleReward());
|
||||
_chestData[1] = new ChestData(_centerBlock.getRelative(-2, 1, 0), new ExampleReward());
|
||||
_chestData[2] = new ChestData(_centerBlock.getRelative(0, 1, 2), new ExampleReward());
|
||||
_chestData[3] = new ChestData(_centerBlock.getRelative(0, 1, -2), new ExampleReward());
|
||||
_chestData[0] = new ChestData(_centerBlock.getRelative(2, 1, 0), rewards[0]);
|
||||
_chestData[1] = new ChestData(_centerBlock.getRelative(-2, 1, 0), rewards[1]);
|
||||
_chestData[2] = new ChestData(_centerBlock.getRelative(0, 1, 2), rewards[2]);
|
||||
_chestData[3] = new ChestData(_centerBlock.getRelative(0, 1, -2), rewards[3]);
|
||||
}
|
||||
|
||||
private void createCenterClay()
|
||||
@ -219,6 +215,7 @@ public class Treasure
|
||||
if (data != null && !data.isOpened())
|
||||
{
|
||||
data.setOpened(true);
|
||||
data.getReward().giveReward(_player);
|
||||
|
||||
ChestOpenAnimation chestOpenTask = new ChestOpenAnimation(this, data);
|
||||
_animations.add(chestOpenTask);
|
||||
|
@ -30,6 +30,10 @@ import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilBlock;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.treasure.reward.ITreasureReward;
|
||||
import mineplex.core.treasure.reward.RewardManager;
|
||||
import mineplex.core.treasure.reward.rewards.GemReward;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
|
||||
@ -39,12 +43,23 @@ import mineplex.core.updater.event.UpdateEvent;
|
||||
public class TreasureManager extends MiniPlugin
|
||||
{
|
||||
private NautHashMap<Player, Treasure> _playerTreasureMap;
|
||||
private RewardManager _rewardManager;
|
||||
private DonationManager _donationManager;
|
||||
|
||||
public TreasureManager(JavaPlugin plugin)
|
||||
public TreasureManager(JavaPlugin plugin, DonationManager donationManager)
|
||||
{
|
||||
super("Treasure", plugin);
|
||||
|
||||
_donationManager = donationManager;
|
||||
_playerTreasureMap = new NautHashMap<Player, Treasure>();
|
||||
_rewardManager = new RewardManager();
|
||||
|
||||
|
||||
_rewardManager.addReward(new GemReward(_donationManager, 5));
|
||||
_rewardManager.addReward(new GemReward(_donationManager, 50));
|
||||
_rewardManager.addReward(new GemReward(_donationManager, 200));
|
||||
_rewardManager.addReward(new GemReward(_donationManager, 500));
|
||||
_rewardManager.addReward(new GemReward(_donationManager, 5000));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -61,7 +76,14 @@ public class TreasureManager extends MiniPlugin
|
||||
if (!checkNearbyBlocks(player))
|
||||
return;
|
||||
|
||||
Treasure treasure = new Treasure(player);
|
||||
ITreasureReward[] rewards = new ITreasureReward[4];
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
rewards[i] = _rewardManager.nextReward(player);
|
||||
}
|
||||
|
||||
Treasure treasure = new Treasure(player, rewards);
|
||||
_playerTreasureMap.put(player, treasure);
|
||||
|
||||
Location teleportLocation = treasure.getPlayerBlock().getLocation().add(0.5, 0, 0.5);
|
||||
@ -74,6 +96,7 @@ public class TreasureManager extends MiniPlugin
|
||||
|
||||
private boolean checkNearbyBlocks(Player player)
|
||||
{
|
||||
//todo improve this
|
||||
Block centerBlock = player.getLocation().getBlock();
|
||||
|
||||
for (int y = 0; y <= 3; y++)
|
||||
@ -85,7 +108,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 a more open location"));
|
||||
UtilPlayer.message(player, F.main("Treasure", "You can not open a treasure at this spot. Please find an open location"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package mineplex.core.treasure.reward;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
@ -13,4 +14,7 @@ public interface ITreasureReward
|
||||
|
||||
public RewardRarity getRarity();
|
||||
|
||||
public void giveReward(Player player);
|
||||
|
||||
public boolean canGiveReward(Player player);
|
||||
}
|
||||
|
@ -0,0 +1,83 @@
|
||||
package mineplex.core.treasure.reward;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Created by shaun on 2014-09-04.
|
||||
*/
|
||||
public class RewardManager
|
||||
{
|
||||
private HashMap<RewardRarity, List<ITreasureReward>> _treasureMap;
|
||||
private Random _random;
|
||||
|
||||
public RewardManager()
|
||||
{
|
||||
_treasureMap = new HashMap<RewardRarity, List<ITreasureReward>>();
|
||||
_random = new Random();
|
||||
|
||||
for (RewardRarity rarity : RewardRarity.values())
|
||||
{
|
||||
_treasureMap.put(rarity, new ArrayList<ITreasureReward>());
|
||||
}
|
||||
}
|
||||
|
||||
public void addReward(ITreasureReward reward)
|
||||
{
|
||||
RewardRarity rarity = reward.getRarity();
|
||||
|
||||
List<ITreasureReward> treasureList = _treasureMap.get(rarity);
|
||||
|
||||
treasureList.add(reward);
|
||||
}
|
||||
|
||||
public ITreasureReward nextReward(Player player)
|
||||
{
|
||||
/*
|
||||
This is potentially blocking, need to make sure each RewardRarity has at least one reward that
|
||||
players can recieve no matter what. May need to touch on this later.
|
||||
*/
|
||||
//todo
|
||||
|
||||
double rand = _random.nextDouble();
|
||||
RewardRarity rarity;
|
||||
|
||||
if (rand >= 98)
|
||||
{
|
||||
// 2%
|
||||
rarity = RewardRarity.VERY_RARE;
|
||||
}
|
||||
else if (rand >= 90)
|
||||
{
|
||||
// 8%
|
||||
rarity = RewardRarity.RARE;
|
||||
}
|
||||
else if (rand >= 60)
|
||||
{
|
||||
// 30%
|
||||
rarity = RewardRarity.UNCOMMON;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 60%
|
||||
rarity = RewardRarity.COMMON;
|
||||
}
|
||||
|
||||
|
||||
List<ITreasureReward> treasureList = _treasureMap.get(rarity);
|
||||
ITreasureReward reward;
|
||||
|
||||
do
|
||||
{
|
||||
reward = treasureList.get(_random.nextInt(treasureList.size()));
|
||||
}
|
||||
while (!reward.canGiveReward(player));
|
||||
|
||||
return reward;
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +1,12 @@
|
||||
package mineplex.core.treasure.reward;
|
||||
package mineplex.core.treasure.reward.rewards;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.treasure.reward.ITreasureReward;
|
||||
import mineplex.core.treasure.reward.RewardRarity;
|
||||
|
||||
/**
|
||||
* Created by Shaun on 9/2/2014.
|
||||
@ -27,4 +30,16 @@ public class ExampleReward implements ITreasureReward
|
||||
{
|
||||
return RewardRarity.COMMON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void giveReward(Player player)
|
||||
{
|
||||
player.sendMessage("give example reward...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canGiveReward(Player player)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package mineplex.core.treasure.reward.rewards;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.gadget.types.Gadget;
|
||||
import mineplex.core.gadget.types.ParticleGadget;
|
||||
import mineplex.core.treasure.reward.ITreasureReward;
|
||||
import mineplex.core.treasure.reward.RewardRarity;
|
||||
|
||||
/**
|
||||
* Created by shaun on 2014-09-04.
|
||||
*/
|
||||
public class GadgetReward implements ITreasureReward
|
||||
{
|
||||
private Gadget _gadget;
|
||||
private DonationManager _donationManager;
|
||||
|
||||
public GadgetReward(Gadget gadget, DonationManager donationManager)
|
||||
{
|
||||
_gadget = gadget;
|
||||
_donationManager = donationManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText()
|
||||
{
|
||||
return _gadget.GetDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem()
|
||||
{
|
||||
return new ItemStack(_gadget.GetDisplayMaterial());
|
||||
}
|
||||
|
||||
@Override
|
||||
public RewardRarity getRarity()
|
||||
{
|
||||
return RewardRarity.VERY_RARE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void giveReward(Player player)
|
||||
{
|
||||
_donationManager.Get(player.getName()).AddUnknownSalesPackagesOwned(_gadget.GetName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canGiveReward(Player player)
|
||||
{
|
||||
return !(_donationManager.Get(player.getName()).OwnsUnknownPackage(_gadget.GetName()));
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package mineplex.core.treasure.reward.rewards;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.Callback;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.treasure.reward.ITreasureReward;
|
||||
import mineplex.core.treasure.reward.RewardRarity;
|
||||
|
||||
/**
|
||||
* Created by shaun on 2014-09-04.
|
||||
*/
|
||||
public class GemReward implements ITreasureReward
|
||||
{
|
||||
private DonationManager _donationManager;
|
||||
private ItemStack _itemStack;
|
||||
private int _gemAmount;
|
||||
|
||||
public GemReward(DonationManager donationManager, int gemAmount)
|
||||
{
|
||||
_donationManager = donationManager;
|
||||
_gemAmount = gemAmount;
|
||||
|
||||
_itemStack = new ItemStack(Material.EMERALD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText()
|
||||
{
|
||||
return C.cGreen + _gemAmount + " Gems";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem()
|
||||
{
|
||||
return _itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RewardRarity getRarity()
|
||||
{
|
||||
return RewardRarity.COMMON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void giveReward(Player player)
|
||||
{
|
||||
_donationManager.RewardGems(new Callback<Boolean>()
|
||||
{
|
||||
@Override
|
||||
public void run(Boolean data)
|
||||
{
|
||||
|
||||
}
|
||||
}, "Treasure Chest", player.getName(), _gemAmount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canGiveReward(Player player)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user