build vote update

This commit is contained in:
Mini-Chiss 2015-05-09 17:34:07 -05:00
parent 6e2b437e55
commit 41599de06f
3 changed files with 135 additions and 63 deletions

View File

@ -93,6 +93,8 @@ import nautilus.game.arcade.kit.Kit;
public class Build extends SoloGame
{
private NautHashMap<Player, BuildData> _data = new NautHashMap<Player, BuildData>();
private NautHashMap<Player, NautHashMap<Player, Integer>> _votes = new NautHashMap<Player, NautHashMap<Player, Integer>>();
private ArrayList<Entry<Player,Double>> _scoreboardPlaces = new ArrayList<Entry<Player,Double>>();
@ -113,7 +115,7 @@ public class Build extends SoloGame
private MobShop _mobShop;
private ItemStack _shopItem;
private String[] _hintText = new String[]
private String[] _hintText = new String[]
{
"Click Creatures to change their settings!",
"Set the Time/Weather in the Options Menu!",
@ -330,9 +332,24 @@ public class Build extends SoloGame
//Verdict
if (!_viewData.Judged)
{
BuildQuality quality = BuildQuality.getQuality(_viewData.getScore());
if (quality == BuildQuality.Failure)
boolean hasDecentVote = false;
for (Player player : _votes.keySet())
{
NautHashMap<Player, Integer> votes = _votes.get(player);
if (votes.containsKey(_viewData.Player))
{
if (votes.get(_viewData.Player) > 2)
{
hasDecentVote = true;
break;
}
}
}
if (!hasDecentVote)
{
Manager.GetExplosion().BlockExplosion(_viewData.Blocks, _viewData.Spawn, false);
@ -343,7 +360,7 @@ public class Build extends SoloGame
}
//Announce Builder
UtilTextMiddle.display(quality.getText(), "Built by: " + C.Bold + _viewData.Player.getName(), 0, 80, 5);
UtilTextMiddle.display(hasDecentVote ? null : C.cRed + "Failure", "Built by: " + C.Bold + _viewData.Player.getName(), 0, 80, 5);
}
_viewData.Judged = true;
@ -384,12 +401,12 @@ public class Build extends SoloGame
{
UtilInv.Clear(player);
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(160, (byte)14, 1, C.Bold + "+0 " + C.cRed + C.Bold + "MY EYES ARE BLEEDING!"));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(160, (byte)1, 1, C.Bold + "+1 " + C.cGold + C.Bold + "MEH..."));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(160, (byte)4, 1, C.Bold + "+2 " + C.cYellow + C.Bold + "It's okay..."));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(160, (byte)5, 1, C.Bold + "+3 " + C.cGreen + C.Bold + "Good"));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(160, (byte)3, 1, C.Bold + "+4 " + C.cAqua + C.Bold + "Amazing"));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(160, (byte)10, 1, C.Bold + "+5 " + C.cPurple + C.Bold + "WOW! EVERYTHING IS AWESOME!"));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(160, (byte)14, 1, C.cRed + C.Bold + "MY EYES ARE BLEEDING!"));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(160, (byte)1, 1, C.cGold + C.Bold + "MEH..."));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(160, (byte)4, 1, C.cYellow + C.Bold + "It's okay..."));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(160, (byte)5, 1, C.cGreen + C.Bold + "Good"));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(160, (byte)3, 1, C.cAqua + C.Bold + "Amazing"));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(160, (byte)10, 1, C.cPurple + C.Bold + "WOW! EVERYTHING IS AWESOME!"));
UtilTextMiddle.display(null, C.cYellow + "Click to Vote", 0, 60, 5, player);
}
@ -410,6 +427,8 @@ public class Build extends SoloGame
}
else if (_buildGameState == 4)
{
tallyScores();
ArrayList<Player> places = new ArrayList<Player>();
//Calculate Places
@ -417,21 +436,21 @@ public class Build extends SoloGame
while (!_data.isEmpty())
{
Player bestPlayer = null;
double bestScore = 0;
double bestPoints = 0;
for (Player player : _data.keySet())
{
double score = _data.get(player).getScore();
double points = _data.get(player).getPoints();
if (bestPlayer == null || score > bestScore)
if (bestPlayer == null || points > bestPoints)
{
bestPlayer = player;
bestScore = score;
bestPoints = points;
}
}
AddGems(bestPlayer, bestScore, "Build Votes", false, false);
//Average points per player is 1000, so divided by 50 = 20 gems
AddGems(bestPlayer, bestPoints / 50, "Build Votes", false, false);
BuildData data = _data.remove(bestPlayer);
@ -442,11 +461,8 @@ public class Build extends SoloGame
first = false;
}
//Only count if they got above TERRIBLE score
if (BuildQuality.getQuality(bestScore) != BuildQuality.Failure)
places.add(bestPlayer);
_scoreboardPlaces.add(new AbstractMap.SimpleEntry<Player, Double>(bestPlayer, bestScore));
places.add(bestPlayer);
_scoreboardPlaces.add(new AbstractMap.SimpleEntry<Player, Double>(bestPlayer, bestPoints));
}
writeScoreboard();
@ -473,6 +489,66 @@ public class Build extends SoloGame
}
}
private void tallyScores()
{
//Reset, if being re-called
for (BuildData data : _data.values())
{
data.clearPoints();
}
//Each player has 1000 points to give to the other builders.
//They are assigned based on a ratio of points given.
//in a 5 player game, a player who gives everyone +0 will be giving everyone equally 250 Points
for (Player voter : _votes.keySet())
{
//Gather Data
double votesCast = 0;
double voteTotal = 0;
NautHashMap<Player, Integer> votes = _votes.get(voter);
for (int vote : votes.values())
{
votesCast++;
voteTotal += vote;
}
AddGems(voter, (int)(voteTotal / 3), "Voting Fairly", false, false);
double votesNotCast = (GetPlayers(true).size() - 1) - votesCast;
double averageVote = 1;
if (votesCast > 0)
averageVote = voteTotal/votesCast;
//This ensures that only 1000 points will be shared among builds
voteTotal += votesNotCast * averageVote;
//Apply Points to builds
for (Player builder : _data.keySet())
{
if (builder.equals(voter))
continue;
//If the voter didnt vote on this build, it will be given the average of their votes
double vote = averageVote;
if (votes.containsKey(builder))
vote = votes.get(builder);
double points = 1000d * (vote/voteTotal);
_data.get(builder).addPoints(points);
// System.out.println(voter.getName() + " = " + builder.getName() + " " +
// (votes.containsKey(builder) ? vote : "No Vote (" + averageVote + ")") + " ~ " + points);
}
//System.out.println( " " );
}
}
public boolean isBuildTime()
{
return _buildStateTime == 0;
@ -627,30 +703,33 @@ public class Build extends SoloGame
if (!UtilTime.elapsed(_buildStateTime, 1500))
return;
if (!_votes.containsKey(event.getPlayer()))
_votes.put(event.getPlayer(), new NautHashMap<Player, Integer>());
switch (event.getPlayer().getItemInHand().getData().getData())
{
case 14:
_viewData.addScore(event.getPlayer(), 0);
_votes.get(event.getPlayer()).put(_viewData.Player, 1);
UtilTextMiddle.display(null, event.getPlayer().getItemInHand().getItemMeta().getDisplayName(), 0, 40, 5, event.getPlayer());
break;
case 1:
_viewData.addScore(event.getPlayer(), 1);
_votes.get(event.getPlayer()).put(_viewData.Player, 2);
UtilTextMiddle.display(null, event.getPlayer().getItemInHand().getItemMeta().getDisplayName(), 0, 40, 5, event.getPlayer());
break;
case 4:
_viewData.addScore(event.getPlayer(), 2);
_votes.get(event.getPlayer()).put(_viewData.Player, 3);
UtilTextMiddle.display(null, event.getPlayer().getItemInHand().getItemMeta().getDisplayName(), 0, 40, 5, event.getPlayer());
break;
case 5:
_viewData.addScore(event.getPlayer(), 3);
_votes.get(event.getPlayer()).put(_viewData.Player, 4);
UtilTextMiddle.display(null, event.getPlayer().getItemInHand().getItemMeta().getDisplayName(), 0, 40, 5, event.getPlayer());
break;
case 3:
_viewData.addScore(event.getPlayer(), 4);
_votes.get(event.getPlayer()).put(_viewData.Player, 5);
UtilTextMiddle.display(null, event.getPlayer().getItemInHand().getItemMeta().getDisplayName(), 0, 40, 5, event.getPlayer());
break;
case 10:
_viewData.addScore(event.getPlayer(), 5);
_votes.get(event.getPlayer()).put(_viewData.Player, 6);
UtilTextMiddle.display(null, event.getPlayer().getItemInHand().getItemMeta().getDisplayName(), 0, 40, 5, event.getPlayer());
break;
default:
@ -662,9 +741,11 @@ public class Build extends SoloGame
public void playerQuit(PlayerQuitEvent event)
{
_data.remove(event.getPlayer());
for (BuildData data : _data.values())
data.removeScore(event.getPlayer());
for (NautHashMap<Player, Integer> votedFor : _votes.values())
votedFor.remove(event.getPlayer());
_votes.remove(event.getPlayer());
}
@EventHandler
@ -1039,9 +1120,7 @@ public class Build extends SoloGame
{
for (Entry<Player, Double> score : _scoreboardPlaces)
{
int percent = (int)(score.getValue() * 20);
Scoreboard.Write(BuildQuality.getQuality(score.getValue()).getColor() + percent + "% " + ChatColor.RESET + score.getKey().getName());
Scoreboard.Write(BuildQuality.getFinalQuality(score.getValue()).getColor() + (int)(score.getValue().intValue()/10) + " " + ChatColor.RESET + score.getKey().getName());
}
}

View File

@ -57,7 +57,7 @@ public class BuildData
public WeatherType Weather = WeatherType.SUNNY;
public NautHashMap<Player, Integer> Score = new NautHashMap<Player, Integer>();
private double _totalPoints = 0;
public BuildData(Player player, Location spawn, ArrayList<Location> buildBorders)
{
@ -155,29 +155,6 @@ public class BuildData
{
Blocks.add(block);
}
public void addScore(Player player, int i)
{
Score.put(player, i);
}
public void removeScore(Player player)
{
Score.remove(player);
}
public double getScore()
{
if (Score.isEmpty())
return -1;
double score = 0;
for (int i : Score.values())
score += i;
return score/(double)Score.size();
}
public boolean inBuildArea(Block block)
{
@ -327,4 +304,19 @@ public class BuildData
MapUtil.QuickChangeBlockAt(Player.getWorld(), x, y, z, mat, data);
}
}
public void addPoints(double d)
{
_totalPoints += d;
}
public double getPoints()
{
return _totalPoints;
}
public void clearPoints()
{
_totalPoints = 0;
}
}

View File

@ -26,13 +26,14 @@ public enum BuildQuality
return _text;
}
public static BuildQuality getQuality(double avgScore)
//1000 points is average, if everyone votes for everyone equally
public static BuildQuality getFinalQuality(double avgScore)
{
if (avgScore < 0) return NoVotes;
if (avgScore <= 1) return Failure;
if (avgScore <= 2) return Satisfactory;
if (avgScore <= 3) return Good;
if (avgScore <= 4) return Awesome;
if (avgScore <= 500) return Failure;
if (avgScore <= 1000) return Satisfactory;
if (avgScore <= 1500) return Good;
if (avgScore <= 2500) return Awesome;
return Mindblowing;
}