Fixed team balancing for ratio based games
This commit is contained in:
parent
166d551fe0
commit
492bf789d8
@ -25,8 +25,6 @@ import org.bukkit.event.block.BlockBurnEvent;
|
||||
import org.bukkit.event.block.BlockFadeEvent;
|
||||
import org.bukkit.event.block.BlockSpreadEvent;
|
||||
import org.bukkit.event.block.LeavesDecayEvent;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
@ -91,7 +89,6 @@ import mineplex.core.inventory.InventoryManager;
|
||||
import mineplex.core.menu.MenuManager;
|
||||
import mineplex.core.mission.MissionManager;
|
||||
import mineplex.core.movement.Movement;
|
||||
import mineplex.core.newnpc.NewNPCManager;
|
||||
import mineplex.core.npc.NpcManager;
|
||||
import mineplex.core.packethandler.PacketHandler;
|
||||
import mineplex.core.party.PartyManager;
|
||||
@ -1057,19 +1054,22 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
||||
@EventHandler
|
||||
public void MessageJoin(PlayerJoinEvent event)
|
||||
{
|
||||
if (event.getJoinMessage() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_incognitoManager.Get(event.getPlayer()).Status)
|
||||
{
|
||||
event.setJoinMessage(null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getJoinMessage() == null)
|
||||
return;
|
||||
|
||||
if (_game != null && _game.AnnounceJoinQuit)
|
||||
if (_game == null || _game.AnnounceJoinQuit)
|
||||
{
|
||||
JoinMessageBroadcastEvent joinMessageBroadcastEvent = new JoinMessageBroadcastEvent(event.getPlayer());
|
||||
UtilServer.CallEvent(joinMessageBroadcastEvent);
|
||||
|
||||
if (joinMessageBroadcastEvent.getUsername() != null)
|
||||
{
|
||||
event.setJoinMessage(F.sys("Join", GetColor(event.getPlayer()) + joinMessageBroadcastEvent.getUsername()));
|
||||
|
@ -17,6 +17,7 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
@ -33,6 +34,7 @@ import mineplex.core.common.util.UtilParticle.ViewDist;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
|
||||
|
||||
import nautilus.game.arcade.game.games.cakewars.CakeWars;
|
||||
import nautilus.game.arcade.game.games.cakewars.item.CakeSpecialItem;
|
||||
@ -142,7 +144,7 @@ public class CakeSheep extends CakeSpecialItem implements Listener
|
||||
switch (block.getType())
|
||||
{
|
||||
case WOOL:
|
||||
chance = 0.8;
|
||||
chance = 1;
|
||||
break;
|
||||
case STAINED_CLAY:
|
||||
chance = 0.7;
|
||||
@ -161,7 +163,7 @@ public class CakeSheep extends CakeSpecialItem implements Listener
|
||||
break;
|
||||
}
|
||||
|
||||
chance *= scale;
|
||||
chance *= scale * 2;
|
||||
|
||||
if (Math.random() < chance)
|
||||
{
|
||||
@ -201,7 +203,7 @@ public class CakeSheep extends CakeSpecialItem implements Listener
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void entityDeath(EntityDeathEvent event)
|
||||
public void sheepDeath(EntityDeathEvent event)
|
||||
{
|
||||
if (event.getEntity() instanceof Sheep)
|
||||
{
|
||||
@ -209,4 +211,22 @@ public class CakeSheep extends CakeSpecialItem implements Listener
|
||||
event.setDroppedExp(0);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void sheepDamage(CustomDamageEvent event)
|
||||
{
|
||||
if (event.GetDamageeEntity() instanceof Sheep && event.GetDamagerPlayer(true) == null)
|
||||
{
|
||||
event.SetCancelled("Sheep World Damage");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void sheepShear(PlayerInteractEntityEvent event)
|
||||
{
|
||||
if (event.getRightClicked() instanceof Sheep)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public enum CakeTeamItem implements CakeItem
|
||||
{
|
||||
for (ItemStack itemStack : player.getInventory().getArmorContents())
|
||||
{
|
||||
if (UtilItem.isArmor(itemStack))
|
||||
if (UtilItem.isArmor(itemStack) && !itemStack.containsEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL))
|
||||
{
|
||||
itemStack.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, level);
|
||||
}
|
||||
@ -66,7 +66,7 @@ public enum CakeTeamItem implements CakeItem
|
||||
{
|
||||
for (ItemStack itemStack : player.getInventory().getContents())
|
||||
{
|
||||
if (UtilItem.isSword(itemStack))
|
||||
if (UtilItem.isSword(itemStack) && !itemStack.containsEnchantment(Enchantment.DAMAGE_ALL))
|
||||
{
|
||||
itemStack.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, level);
|
||||
}
|
||||
@ -86,7 +86,7 @@ public enum CakeTeamItem implements CakeItem
|
||||
{
|
||||
for (ItemStack itemStack : player.getInventory().getContents())
|
||||
{
|
||||
if (itemStack != null && itemStack.getType() == Material.BOW)
|
||||
if (itemStack != null && itemStack.getType() == Material.BOW && !itemStack.containsEnchantment(Enchantment.ARROW_DAMAGE))
|
||||
{
|
||||
itemStack.addUnsafeEnchantment(Enchantment.ARROW_DAMAGE, level);
|
||||
}
|
||||
|
@ -468,7 +468,7 @@ public class HideSeek extends TeamGame
|
||||
_seekers.SetColor(ChatColor.RED);
|
||||
_seekers.SetName("Hunters");
|
||||
|
||||
_teamSelector = new RatioSelector(_seekers, 0.2);
|
||||
_teamSelector = new RatioSelector(_seekers, 0.25);
|
||||
|
||||
getTeamModule().setPrioritisePreferences(true);
|
||||
|
||||
@ -1110,6 +1110,21 @@ public class HideSeek extends TeamGame
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void updateFairTeams(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.FAST || !IsLive())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while (getTeamSelector().canJoinTeam(_seekers, 1, 0, GetPlayers(true).size()) && !_hiders.GetPlayers(true).isEmpty())
|
||||
{
|
||||
Player player = UtilAlg.Random(_hiders.GetPlayers(true));
|
||||
SetSeeker(player, true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void UpdateSeekers(UpdateEvent event)
|
||||
{
|
||||
|
@ -151,7 +151,7 @@ public class MilkCow extends SoloGame
|
||||
_cows = new GameTeam(this, "Cow", ChatColor.RED, _farmers.GetSpawns());
|
||||
GetTeamList().add(_cows);
|
||||
|
||||
_teamSelector = new RatioSelector(_cows, 0.2);
|
||||
_teamSelector = new RatioSelector(_cows, 0.25);
|
||||
|
||||
RestrictKits();
|
||||
}
|
||||
@ -271,37 +271,24 @@ public class MilkCow extends SoloGame
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void CowUpdate(UpdateEvent event)
|
||||
public void updateFairTeams(UpdateEvent event)
|
||||
{
|
||||
if (!IsLive())
|
||||
return;
|
||||
|
||||
if (event.getType() != UpdateType.FAST)
|
||||
return;
|
||||
|
||||
int req = 1;
|
||||
|
||||
while (_cows.GetPlayers(true).size() < req && _farmers.GetPlayers(true).size() > 0)
|
||||
if (event.getType() != UpdateType.FAST || !IsLive())
|
||||
{
|
||||
Player player = _farmers.GetPlayers(true).get(UtilMath.r(_farmers.GetPlayers(true).size()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (_cows.GetPlayers(true).isEmpty() && !_farmers.GetPlayers(true).isEmpty())
|
||||
{
|
||||
Player player = UtilAlg.Random(_farmers.GetPlayers(true));
|
||||
SetCow(player, true);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetCow(Player player, boolean forced)
|
||||
{
|
||||
//Set them as OUT!
|
||||
if (GetTeam(player) != null)
|
||||
GetTeam(player).SetPlacement(player, PlayerState.OUT);
|
||||
|
||||
SetPlayerTeam(player, _cows, true);
|
||||
|
||||
//Kit
|
||||
Kit newKit = GetKits()[3];
|
||||
|
||||
SetKit(player, newKit, false);
|
||||
newKit.ApplyKit(player);
|
||||
|
||||
//Refresh
|
||||
VisibilityManager vm = Managers.require(VisibilityManager.class);
|
||||
Bukkit.getOnlinePlayers().forEach(pl -> vm.refreshVisibility(pl, player));
|
||||
@ -315,7 +302,7 @@ public class MilkCow extends SoloGame
|
||||
AddGems(player, 10, "Forced Cow", false, false);
|
||||
|
||||
Announce(F.main("Game", F.elem(_farmers.GetColor() + player.getName()) + " has become " +
|
||||
F.elem(_cows.GetColor() + newKit.GetName()) + "."));
|
||||
F.elem(_cows.GetColor() + GetKit(player).GetName()) + "."));
|
||||
|
||||
player.getWorld().strikeLightningEffect(player.getLocation());
|
||||
}
|
||||
|
@ -81,7 +81,6 @@ import nautilus.game.arcade.stats.TeamKillsStatTracker;
|
||||
public class WitherGame extends TeamGame implements IBlockRestorer
|
||||
{
|
||||
|
||||
private static final double WITHER_FACTOR = 2.5;
|
||||
private static final long GAME_TIMEOUT = TimeUnit.MINUTES.toMillis(5);
|
||||
|
||||
private GameTeam _runners;
|
||||
@ -336,31 +335,36 @@ public class WitherGame extends TeamGame implements IBlockRestorer
|
||||
}
|
||||
}
|
||||
|
||||
public void setWither(Player player, boolean forced)
|
||||
@EventHandler
|
||||
public void updateFairTeams(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.FAST || !IsLive())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_withers.GetPlayers(true).isEmpty() && !_runners.GetPlayers(true).isEmpty())
|
||||
{
|
||||
Player player = UtilAlg.Random(_runners.GetPlayers(true));
|
||||
setWither(player);
|
||||
}
|
||||
}
|
||||
|
||||
private void setWither(Player player)
|
||||
{
|
||||
SetPlayerTeam(player, _withers, true);
|
||||
|
||||
// Kit
|
||||
Kit newKit = GetKits()[GetKits().length-1];
|
||||
|
||||
SetKit(player, newKit, false);
|
||||
newKit.ApplyKit(player);
|
||||
|
||||
player.teleport(_withers.GetSpawn());
|
||||
|
||||
if (forced)
|
||||
{
|
||||
AddGems(player, 10, "Forced Wither", false, false);
|
||||
AddGems(player, 10, "Forced Wither", false, false);
|
||||
|
||||
Announce(F.main(
|
||||
"Game",
|
||||
F.elem(_withers.GetColor() + player.getName())
|
||||
+ " has become a "
|
||||
+ F.elem(_withers.GetColor() + newKit.GetName())
|
||||
+ "."));
|
||||
Announce(F.main(
|
||||
"Game",
|
||||
F.elem(_withers.GetColor() + player.getName())
|
||||
+ " has become a "
|
||||
+ F.elem(_withers.GetColor() + GetKit(player).GetName())
|
||||
+ "."));
|
||||
|
||||
player.getWorld().strikeLightningEffect(player.getLocation());
|
||||
}
|
||||
player.getWorld().strikeLightningEffect(player.getLocation());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -160,16 +160,18 @@ public class GameTeamModule extends Module
|
||||
friends = new ArrayList<>(friends);
|
||||
// Remove friends that are already on a team
|
||||
friends.removeIf(other -> game.GetTeam(other) != null);
|
||||
// We need to add the player here so that it handles the max team size correctly.
|
||||
// Don't think about it too much, you just need this otherwise you get 3 players in
|
||||
// duo games.
|
||||
friends.add(0, player);
|
||||
|
||||
// Friends operate similarly to parties however we don't need to worry about getting everyone
|
||||
// on a team with at least one friend since these are friends of the current iterating player.
|
||||
if (!friends.isEmpty())
|
||||
if (friends.size() > 1)
|
||||
{
|
||||
int friendSize = Math.min(friends.size(), target) - 1;
|
||||
int friendSize = Math.min(friends.size(), target);
|
||||
GameTeam team = getTeamToJoin(friendSize, target, total);
|
||||
|
||||
game.SetPlayerTeam(player, team, true);
|
||||
|
||||
// Fill the team up as far as it can
|
||||
for (int i = 0; i < friendSize; i++)
|
||||
{
|
||||
|
@ -3,8 +3,6 @@ package nautilus.game.arcade.game.team.selectors;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import nautilus.game.arcade.game.Game;
|
||||
import nautilus.game.arcade.game.GameTeam;
|
||||
|
||||
@ -25,10 +23,6 @@ public class FillToSelector extends EvenTeamSelector
|
||||
.max(Comparator.comparingInt(GameTeam::GetSize))
|
||||
.orElse(null);
|
||||
|
||||
teams.stream()
|
||||
.filter(team -> canJoinTeam(team, desiredAmount, target, total))
|
||||
.forEach(team -> Bukkit.broadcastMessage(team.getDisplayName()));
|
||||
|
||||
if (primaryChoice != null)
|
||||
{
|
||||
return primaryChoice;
|
||||
|
@ -94,10 +94,9 @@ public class VotingManager extends ListenerComponent implements Lifetimed
|
||||
for (Player player : UtilServer.getPlayersCollection())
|
||||
{
|
||||
player.getInventory().remove(remove);
|
||||
player.closeInventory();
|
||||
}
|
||||
|
||||
_shop.onVoteEnd();
|
||||
|
||||
// false when /game set has been used during a vote
|
||||
if (_manager.GetGameCreationManager().getNextGameType() == null)
|
||||
{
|
||||
|
@ -3,7 +3,6 @@ package nautilus.game.arcade.managers.voting.ui;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.shop.ShopBase;
|
||||
import mineplex.core.shop.page.ShopPageBase;
|
||||
@ -23,15 +22,4 @@ public class VotingShop extends ShopBase<ArcadeManager>
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public void onVoteEnd()
|
||||
{
|
||||
for (Player player : UtilServer.getPlayersCollection())
|
||||
{
|
||||
if (isPlayerInShop(player))
|
||||
{
|
||||
removePlayer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,9 +21,10 @@ public class KillMissionTracker extends GameMissionTracker<GameDisplay, Game>
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void playerDeath(PlayerDeathEvent event)
|
||||
{
|
||||
Player killer = event.getEntity().getKiller();
|
||||
Player player = event.getEntity();
|
||||
Player killer = player.getKiller();
|
||||
|
||||
if (killer != null)
|
||||
if (killer != null && !player.equals(killer))
|
||||
{
|
||||
incrementProgress(killer, 1, _game.GetType().getDisplay());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user