Give players who switch teams worse bread

This commit is contained in:
BuildTools 2017-06-15 00:11:38 -07:00
parent 5eca38b5a4
commit d3dd613b7e
1 changed files with 24 additions and 1 deletions

View File

@ -14,8 +14,10 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import tc.oc.commons.bukkit.item.ItemBuilder;
import tc.oc.commons.core.collection.WeakHashSet;
import tc.oc.commons.core.random.ImmutableWeightedRandomChooser;
import tc.oc.commons.core.random.WeightedRandomChooser;
import tc.oc.pgm.events.PlayerChangePartyEvent;
import tc.oc.pgm.kits.FreeItemKit;
import tc.oc.pgm.kits.Kit;
import tc.oc.pgm.match.Match;
@ -23,6 +25,7 @@ import tc.oc.pgm.match.MatchPlayer;
import tc.oc.pgm.mutation.types.KitMutation;
import java.util.List;
import java.util.Set;
public class BreadMutation extends KitMutation {
@ -45,11 +48,19 @@ public class BreadMutation extends KitMutation {
.put(new FreeItemKit(new ItemBuilder(item(Material.BREAD)).enchant(Enchantment.FIRE_ASPECT, 100).name("Insanely Hot Bread").get()), 1)
.build();
final static ImmutableMap<FreeItemKit, Integer> BAD_BREADS_MAP = new ImmutableMap.Builder<FreeItemKit, Integer>()
.put(new FreeItemKit(new ItemBuilder(item(Material.BREAD)).enchant(Enchantment.FIRE_ASPECT, 1).name("Hot Bread").get()), 20)
.put(new FreeItemKit(new ItemBuilder(item(Material.BREAD)).enchant(Enchantment.DAMAGE_ALL, 5).name("Sharp Bread").get()), 20)
.put(new FreeItemKit(new ItemBuilder(item(Material.BREAD)).enchant(Enchantment.KNOCKBACK, 2).name("Bouncy Bread").get()), 20)
.build();
final static WeightedRandomChooser<PotionEffectType, Integer> POTIONS = new ImmutableWeightedRandomChooser<>(PotionMutation.BAD_MAP);
final static WeightedRandomChooser<FreeItemKit, Integer> BREADS = new ImmutableWeightedRandomChooser<>(BREADS_MAP);
final static WeightedRandomChooser<FreeItemKit, Integer> BAD_BREADS = new ImmutableWeightedRandomChooser<>(BAD_BREADS_MAP);
final static Range<Integer> AMPLIFIER_RANGE = Range.closed(0, 3);
final static Range<Integer> DURATION_RANGE = Range.closed(3, 10);
final static Set<MatchPlayer> playersForBadBread = new WeakHashSet<>();
public BreadMutation(Match match) {
super(match, false);
@ -58,7 +69,12 @@ public class BreadMutation extends KitMutation {
@Override
public void kits(MatchPlayer player, List<Kit> kits) {
super.kits(player, kits);
kits.add(BREADS.choose(entropy()));
if (playersForBadBread.contains(player)) {
kits.add(BAD_BREADS.choose(entropy()));
playersForBadBread.remove(player);
} else {
kits.add(BREADS.choose(entropy()));
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@ -69,6 +85,13 @@ public class BreadMutation extends KitMutation {
((LivingEntity)event.getEntity()).addPotionEffect(new PotionEffect(POTIONS.choose(entropy()), 20 * entropy().randomInt(DURATION_RANGE), entropy().randomInt(AMPLIFIER_RANGE)));
}
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPartyChange(PlayerChangePartyEvent event) {
playersForBadBread.add(event.getPlayer());
}
}