Fix tag master and achievement progress

This commit is contained in:
Thanos Paravantis 2016-04-27 13:14:20 +03:00
parent ccebeb75f1
commit ba5d06db88
18 changed files with 178 additions and 93 deletions

View File

@ -174,8 +174,6 @@ public class BawkBawkBattles extends TeamGame implements IThrown
* - Fix item rendering exception (kangaroo jump http://i.imgur.com/CPYIogC.jpg)
* - Pinata Master
* - http://prnt.sc/ax86n8 typos
* - Tag master only adds 1
* - Bouncing block don't make completed players jump high
*
* Medium Priority
* - Make spawn distance equal from a target
@ -200,8 +198,8 @@ public class BawkBawkBattles extends TeamGame implements IThrown
new String[] {
"Follow Bawk Bawk's instructions in chat.",
"Complete a task first or be the last one to stay alive.",
"If you fail a challenge, you loose one life.",
"If you ran out of lives, chickens will attack you.",
"If you fail a challenge, you lose one life.",
"If you run out of lives, chickens will attack you.",
"Last player with lives wins.",
});

View File

@ -25,6 +25,7 @@ import mineplex.core.common.util.C;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.common.util.UtilTime;
import mineplex.core.hologram.Hologram;
@ -318,6 +319,7 @@ public abstract class Challenge implements Listener
}
Data.addCompletedPlayer(player);
UtilPlayer.clearPotionEffects(player);
UtilInv.Clear(player);
}

View File

@ -0,0 +1,8 @@
package nautilus.game.arcade.game.games.mineware.challenge;
import org.bukkit.entity.Player;
public interface LogicTracker
{
public boolean hasData(Player player);
}

View File

@ -2,7 +2,7 @@ package nautilus.game.arcade.game.games.mineware.challenge;
import org.bukkit.entity.Player;
public interface DataTracker
public interface NumberTracker
{
public Number getData(Player player);

View File

@ -29,14 +29,14 @@ import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.game.games.mineware.BawkBawkBattles;
import nautilus.game.arcade.game.games.mineware.challenge.Challenge;
import nautilus.game.arcade.game.games.mineware.challenge.ChallengeType;
import nautilus.game.arcade.game.games.mineware.challenge.LogicTracker;
public class ChallengeBouncingBlock extends Challenge
public class ChallengeBouncingBlock extends Challenge implements LogicTracker
{
private ArrayList<Player> _stepTracker = new ArrayList<Player>();
private ArrayList<Block> _blocks = new ArrayList<Block>();
private HashMap<Player, Integer> _score = new HashMap<Player, Integer>();
// TODO: Separate functionality to different methods.
private static int _goal = 10;
public ChallengeBouncingBlock(BawkBawkBattles host)
{
@ -46,7 +46,7 @@ public class ChallengeBouncingBlock extends Challenge
"Bouncing Block",
"Jump and punch floating wool blocks.",
"Avoid landing on red wool.",
"First to 10 wins!");
"First to " + _goal + " wins!");
Settings.setUseMapHeight();
}
@ -74,9 +74,8 @@ public class ChallengeBouncingBlock extends Challenge
Block block = location.getBlock();
block.setType(Material.WOOL);
if (Math.random() * 100 < 20.0)
if (Math.random() < 0.2)
block.setData((byte) 14);
else
block.setData((byte) 0);
@ -89,27 +88,23 @@ public class ChallengeBouncingBlock extends Challenge
@Override
public void onStart()
{
Host.StrictAntiHack = false;
addEffect(PotionEffectType.JUMP, 6);
for (Player player : getPlayersAlive())
{
_score.put(player, 0);
}
Host.StrictAntiHack = false;
}
@Override
public void onEnd()
{
Host.StrictAntiHack = true;
for (Block woolBlocks : _blocks)
woolBlocks.setType(Material.AIR);
_blocks.clear();
_score.clear();
// _antiHackFix.clear();
Host.StrictAntiHack = true;
}
@EventHandler
@ -131,17 +126,8 @@ public class ChallengeBouncingBlock extends Challenge
if (!_blocks.contains(block))
return;
increment(player, 1);
player.playSound(player.getLocation(), Sound.SUCCESSFUL_HIT, 0.2f, 0.2f);
block.setType(Material.AIR);
spawnRandomWool(getArenaSize(9), (UtilMath.r(6) + 5));
if (_score.get(player) >= 10)
{
setCompleted(player);
UtilTextBottom.display(C.cGreen + C.Bold + "Completed!", player);
}
hitBlock(player, block);
checkCompleted(player);
}
@EventHandler
@ -153,11 +139,8 @@ public class ChallengeBouncingBlock extends Challenge
if (event.getType() != UpdateType.TICK)
return;
for (Player player : getPlayersAlive())
for (Player player : getPlayersIn(true))
{
if (Data.isDone(player))
continue;
UtilTextBottom.display(C.Bold + "Score: " + C.Reset + C.cYellow + C.Bold + _score.get(player), player);
}
}
@ -173,35 +156,21 @@ public class ChallengeBouncingBlock extends Challenge
if (!isPlayerValid(player))
return;
if (event.getFrom().getX() == event.getTo().getX() && event.getFrom().getZ() == event.getTo().getZ())
if (isLooking(event.getFrom(), event.getTo()))
return;
Location loc = player.getLocation();
Block blockBelow = loc.getBlock().getRelative(BlockFace.DOWN);
if (Recharge.Instance.use(player, "Movement", 300, false, false) && _score.get(player) > 0)
if (canLooseScore(player) && blockBelow.getType() == Material.WOOL)
{
if (blockBelow.getType() == Material.WOOL)
Wool woolBelow = (Wool) blockBelow.getState().getData();
if (woolBelow.getColor() == DyeColor.RED)
{
Wool woolBelow = (Wool) blockBelow.getState().getData();
if (woolBelow.getColor() == DyeColor.RED)
{
int subtract = 2;
if (_score.get(player) == 1)
subtract = 1;
subtract(player, subtract);
UtilTextMiddle.display(null, "Score decreased by " + C.cRed + subtract + C.Reset + "!", 5, 40, 5, player);
player.playSound(player.getLocation(), Sound.NOTE_BASS, 1.0F, 1.0F);
if (!_stepTracker.contains(player))
{
_stepTracker.add(player);
}
}
int amount = subtractFromScore(player);
showSubtractMessage(player, amount);
trackStep(player);
}
}
}
@ -212,13 +181,71 @@ public class ChallengeBouncingBlock extends Challenge
if (!isChallengeValid())
return;
_stepTracker.remove(event.getPlayer());
Player player = event.getPlayer();
_stepTracker.remove(player);
_score.remove(player);
}
private void hitBlock(Player player, Block block)
{
increment(player, 1);
player.playSound(player.getLocation(), Sound.SUCCESSFUL_HIT, 0.2f, 0.2f);
block.setType(Material.AIR);
spawnRandomWool(getArenaSize(9), (UtilMath.r(6) + 5));
}
private void checkCompleted(Player player)
{
if (_score.get(player) >= _goal)
{
setCompleted(player);
UtilTextBottom.display(C.cGreen + C.Bold + "Completed!", player);
}
}
private boolean isLooking(Location from, Location to)
{
return from.getX() == to.getX() && from.getZ() == to.getZ();
}
private boolean canLooseScore(Player player)
{
return Recharge.Instance.use(player, "Movement", 300, false, false) && _score.get(player) > 0;
}
private int subtractFromScore(Player player)
{
int amount = 2;
if (_score.get(player) == 1)
{
amount = 1;
}
subtract(player, amount);
return amount;
}
private void showSubtractMessage(Player player, int amount)
{
UtilTextMiddle.display(null, "Score decreased by " + C.cRed + amount + C.Reset + "!", 5, 40, 5, player);
player.playSound(player.getLocation(), Sound.NOTE_BASS, 1.0F, 1.0F);
}
private void trackStep(Player player)
{
if (!_stepTracker.contains(player))
{
_stepTracker.add(player);
}
}
@SuppressWarnings("deprecation")
private void spawnStartingWool()
{
whileLoop: while (_blocks.size() <= Math.ceil(getPlayersAlive().size() / 2) + 1)
whileLoop: while (_blocks.size() <= Math.ceil(Host.getPlayersWithRemainingLives() / 2) + 1)
{
for (int x = -getArenaSize(); x <= getArenaSize(); x++)
{
@ -226,9 +253,9 @@ public class ChallengeBouncingBlock extends Challenge
{
for (int y = 5; y <= 11; y++)
{
Block b = getCenter().getBlock().getRelative(x, y, z);
Block block = getCenter().getBlock().getRelative(x, y, z);
if (b.getType() == Material.AIR || b.getType() == null)
if (block.isEmpty() || block.getType() == null)
{
if (UtilMath.r(50) == 0)
{
@ -239,11 +266,11 @@ public class ChallengeBouncingBlock extends Challenge
color = (byte) UtilMath.r(16);
}
b.setType(Material.WOOL);
b.setData((byte) UtilMath.r(16));
_blocks.add(b);
block.setType(Material.WOOL);
block.setData((byte) UtilMath.r(16));
_blocks.add(block);
if (_blocks.size() >= Math.ceil(Host.GetPlayers(true).size() / 2) + 1)
if (_blocks.size() >= Math.ceil(Host.getPlayersWithRemainingLives() / 2) + 1)
{
break whileLoop;
}
@ -266,7 +293,7 @@ public class ChallengeBouncingBlock extends Challenge
Block b = getCenter().getBlock().getRelative(x, y, z);
Byte color = (byte) UtilMath.r(16);
while (color == 14) // prevent RED
while (color == 14)
{
color = (byte) UtilMath.r(16);
}
@ -299,8 +326,9 @@ public class ChallengeBouncingBlock extends Challenge
_score.put(player, 0);
}
public boolean hasSteppedOnWool(Player player)
@Override
public boolean hasData(Player player)
{
return _stepTracker.contains(player);
return !_stepTracker.contains(player);
}
}

View File

@ -32,9 +32,9 @@ import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.game.games.mineware.BawkBawkBattles;
import nautilus.game.arcade.game.games.mineware.challenge.Challenge;
import nautilus.game.arcade.game.games.mineware.challenge.ChallengeType;
import nautilus.game.arcade.game.games.mineware.challenge.DataTracker;
import nautilus.game.arcade.game.games.mineware.challenge.NumberTracker;
public class ChallengeChickenShooting extends Challenge implements DataTracker
public class ChallengeChickenShooting extends Challenge implements NumberTracker
{
private ArrayList<Chicken> _chickens = new ArrayList<Chicken>();
private HashMap<Player, Integer> _score = new HashMap<Player, Integer>();

View File

@ -22,9 +22,9 @@ import mineplex.core.itemstack.ItemBuilder;
import nautilus.game.arcade.game.games.mineware.BawkBawkBattles;
import nautilus.game.arcade.game.games.mineware.challenge.Challenge;
import nautilus.game.arcade.game.games.mineware.challenge.ChallengeType;
import nautilus.game.arcade.game.games.mineware.challenge.DataTracker;
import nautilus.game.arcade.game.games.mineware.challenge.NumberTracker;
public class ChallengeEggSmash extends Challenge implements DataTracker
public class ChallengeEggSmash extends Challenge implements NumberTracker
{
private static int _smashedEggsGoal = 10;
private HashMap<Player, Integer> _score = new HashMap<Player, Integer>();

View File

@ -32,9 +32,9 @@ import mineplex.core.projectile.ProjectileUser;
import nautilus.game.arcade.game.games.mineware.BawkBawkBattles;
import nautilus.game.arcade.game.games.mineware.challenge.Challenge;
import nautilus.game.arcade.game.games.mineware.challenge.ChallengeType;
import nautilus.game.arcade.game.games.mineware.challenge.DataTracker;
import nautilus.game.arcade.game.games.mineware.challenge.NumberTracker;
public class ChallengeFallingBlocks extends Challenge implements DataTracker
public class ChallengeFallingBlocks extends Challenge implements NumberTracker
{
// The spawn chances of a falling block.
private double _spawnChance = 20.0;

View File

@ -21,9 +21,9 @@ import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.game.games.mineware.BawkBawkBattles;
import nautilus.game.arcade.game.games.mineware.challenge.Challenge;
import nautilus.game.arcade.game.games.mineware.challenge.ChallengeType;
import nautilus.game.arcade.game.games.mineware.challenge.DataTracker;
import nautilus.game.arcade.game.games.mineware.challenge.NumberTracker;
public class ChallengeKangarooJump extends Challenge implements DataTracker
public class ChallengeKangarooJump extends Challenge implements NumberTracker
{
private HashMap<Player, Integer> _heightData = new HashMap<Player, Integer>();
private long _gameTime = System.currentTimeMillis() + ((UtilMath.r(5) + 20) * 1000);

View File

@ -24,8 +24,9 @@ import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.game.games.mineware.BawkBawkBattles;
import nautilus.game.arcade.game.games.mineware.challenge.Challenge;
import nautilus.game.arcade.game.games.mineware.challenge.ChallengeType;
import nautilus.game.arcade.game.games.mineware.challenge.LogicTracker;
public class ChallengeKingOfTheLadder extends Challenge
public class ChallengeKingOfTheLadder extends Challenge implements LogicTracker
{
private ArrayList<Player> _hitTracker = new ArrayList<Player>();
private Location _winCornerA;
@ -236,8 +237,9 @@ public class ChallengeKingOfTheLadder extends Challenge
_hitTracker.remove(event.getPlayer());
}
public boolean hasBeenHit(Player player)
@Override
public boolean hasData(Player player)
{
return _hitTracker.contains(player);
return !_hitTracker.contains(player);
}
}

View File

@ -31,9 +31,9 @@ import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.game.games.mineware.BawkBawkBattles;
import nautilus.game.arcade.game.games.mineware.challenge.Challenge;
import nautilus.game.arcade.game.games.mineware.challenge.ChallengeType;
import nautilus.game.arcade.game.games.mineware.challenge.DataTracker;
import nautilus.game.arcade.game.games.mineware.challenge.NumberTracker;
public class ChallengeMilkACow extends Challenge implements DataTracker
public class ChallengeMilkACow extends Challenge implements NumberTracker
{
private Villager _villager;
private HashMap<Entity, ArrayList<String>> _milked = new HashMap<Entity, ArrayList<String>>();

View File

@ -28,9 +28,9 @@ import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.game.games.mineware.BawkBawkBattles;
import nautilus.game.arcade.game.games.mineware.challenge.Challenge;
import nautilus.game.arcade.game.games.mineware.challenge.ChallengeType;
import nautilus.game.arcade.game.games.mineware.challenge.DataTracker;
import nautilus.game.arcade.game.games.mineware.challenge.NumberTracker;
public class ChallengeMiniOneInTheQuiver extends Challenge implements DataTracker
public class ChallengeMiniOneInTheQuiver extends Challenge implements NumberTracker
{
private HashMap<Player, Integer> _killTracker = new HashMap<Player, Integer>();

View File

@ -15,9 +15,9 @@ import org.bukkit.event.player.PlayerQuitEvent;
import nautilus.game.arcade.game.games.mineware.BawkBawkBattles;
import nautilus.game.arcade.game.games.mineware.challenge.Challenge;
import nautilus.game.arcade.game.games.mineware.challenge.ChallengeType;
import nautilus.game.arcade.game.games.mineware.challenge.DataTracker;
import nautilus.game.arcade.game.games.mineware.challenge.NumberTracker;
public class ChallengeNavigationMaze extends Challenge implements DataTracker
public class ChallengeNavigationMaze extends Challenge implements NumberTracker
{
private HashMap<Player, Long> _completionTime = new HashMap<Player, Long>();

View File

@ -1,6 +1,7 @@
package nautilus.game.arcade.game.games.mineware.challenge.type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import org.bukkit.Color;
@ -25,12 +26,14 @@ import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.game.games.mineware.BawkBawkBattles;
import nautilus.game.arcade.game.games.mineware.challenge.ChallengeType;
import nautilus.game.arcade.game.games.mineware.challenge.LogicTracker;
import nautilus.game.arcade.game.games.mineware.challenge.TeamChallenge;
public class ChallengeReverseTag extends TeamChallenge
public class ChallengeReverseTag extends TeamChallenge implements LogicTracker
{
private int _cooldown = 2; // Seconds
private HashSet<Player> _cooldowns = new HashSet<Player>();
private HashMap<Player, Boolean> _tagTracker = new HashMap<Player, Boolean>();
public ChallengeReverseTag(BawkBawkBattles host)
{
@ -97,6 +100,7 @@ public class ChallengeReverseTag extends TeamChallenge
for (Player tagged : getFirstTeam().getPlayers())
{
tagEffect(tagged);
_tagTracker.put(tagged, true);
}
}
@ -191,18 +195,32 @@ public class ChallengeReverseTag extends TeamChallenge
return;
_cooldowns.remove(player);
_tagTracker.remove(player);
}
private void clear(Player player)
{
if (getFirstTeam().isMember(player))
{
trackClear(player);
clearEffect(player);
getFirstTeam().remove(player);
getSecondTeam().add(player);
}
}
private void trackClear(Player player)
{
if (_tagTracker.containsKey(player))
{
if (_tagTracker.get(player))
{
_tagTracker.put(player, false);
}
}
}
private void clearEffect(Player player)
{
UtilTextMiddle.display(null, C.cRed + "You are no longer tagged.", 5, 40, 5, player);
@ -218,6 +236,7 @@ public class ChallengeReverseTag extends TeamChallenge
{
if (getSecondTeam().isMember(player))
{
trackTag(player);
tagEffect(player);
getSecondTeam().remove(player);
@ -231,6 +250,21 @@ public class ChallengeReverseTag extends TeamChallenge
}
}
private void trackTag(Player player)
{
if (_tagTracker.containsKey(player))
{
if (_tagTracker.get(player))
{
_tagTracker.put(player, true);
}
}
else
{
_tagTracker.put(player, true);
}
}
private void tagEffect(Player player)
{
UtilTextMiddle.display(null, C.cGreen + "You are now tagged, keep it up.", 5, 40, 5, player);
@ -253,4 +287,17 @@ public class ChallengeReverseTag extends TeamChallenge
}
}.runTaskLater(Host.Manager.getPlugin(), 20 * _cooldown);
}
@Override
public boolean hasData(Player player)
{
if (_tagTracker.containsKey(player))
{
return _tagTracker.get(player);
}
else
{
return false;
}
}
}

View File

@ -21,9 +21,9 @@ import mineplex.core.projectile.ProjectileUser;
import nautilus.game.arcade.game.games.mineware.BawkBawkBattles;
import nautilus.game.arcade.game.games.mineware.challenge.Challenge;
import nautilus.game.arcade.game.games.mineware.challenge.ChallengeType;
import nautilus.game.arcade.game.games.mineware.challenge.DataTracker;
import nautilus.game.arcade.game.games.mineware.challenge.NumberTracker;
public class ChallengeWaveCrush extends Challenge implements DataTracker
public class ChallengeWaveCrush extends Challenge implements NumberTracker
{
// The amount of waves that started.
private int _waveAmount = 0;

View File

@ -22,10 +22,10 @@ public class BouncingShadowTracker extends ChallengeStatTracker
for (Player player : getGame().GetPlayers(true))
{
if (!bouncingBlock.hasSteppedOnWool(player) && bouncingBlock.getData().isDone(player))
if (bouncingBlock.hasData(player) && bouncingBlock.getData().isDone(player))
{
System.out.println("Bouncing Shadow: " + player.getName());
addStat(player, "BouncingShadow", 1, true, false);
addStat(player, "BouncingShadow", 1, false, false);
}
}
}

View File

@ -22,10 +22,10 @@ public class QuickClimberTracker extends ChallengeStatTracker
for (Player player : getGame().GetPlayers(true))
{
if (!kotl.hasBeenHit(player) && kotl.getData().isDone(player))
if (kotl.hasData(player) && kotl.getData().isDone(player))
{
System.out.println("Quick Climber: " + player.getName());
addStat(player, "QuickClimber", 1, true, false);
addStat(player, "QuickClimber", 1, false, false);
}
}
}

View File

@ -22,10 +22,10 @@ public class TagMasterTracker extends ChallengeStatTracker
for (Player player : reverseTag.getFirstTeam().getPlayers())
{
if (reverseTag.getData().isCompleted(player))
if (reverseTag.hasData(player))
{
System.out.println("Tag Master: " + player.getName());
addStat(player, "TagMaster", 1, true, false);
addStat(player, "TagMaster", 1, false, false);
}
}
}