001package fr.aumgn.dac2.arena.regions; 002 003import org.bukkit.World; 004 005import fr.aumgn.bukkitutils.geom.Vector2D; 006import fr.aumgn.bukkitutils.util.Random; 007import fr.aumgn.bukkitutils.util.Util; 008import fr.aumgn.dac2.shape.FlatShape; 009import fr.aumgn.dac2.shape.column.Column; 010import fr.aumgn.dac2.shape.column.ColumnPattern; 011 012public interface PoolFilling { 013 014 /** 015 * Resets the pool. 016 */ 017 public class Reset implements PoolFilling { 018 019 @Override 020 public void fill(World world, Pool pool, ColumnPattern pattern) { 021 for (Column column : pool.getShape()) { 022 column.reset(world); 023 } 024 } 025 } 026 027 /** 028 * Replaces all columns. 029 */ 030 public class Fully implements PoolFilling { 031 032 @Override 033 public void fill(World world, Pool pool, ColumnPattern pattern) { 034 for (Column column : pool.getShape()) { 035 column.set(world, pattern); 036 } 037 } 038 } 039 040 /** 041 * Replaces some columns randomly. 042 */ 043 public class Randomly implements PoolFilling { 044 045 private final double ratio; 046 047 public Randomly(double ratio) { 048 this.ratio = ratio; 049 } 050 051 @Override 052 public void fill(World world, Pool pool, ColumnPattern pattern) { 053 Random rand = Util.getRandom(); 054 for (Column column : pool.getShape()) { 055 if (rand.nextDouble() < ratio) { 056 column.set(world, pattern); 057 } else { 058 column.reset(world); 059 } 060 } 061 } 062 } 063 064 /** 065 * Replaces one column over two. 066 */ 067 public class DeACoudre implements PoolFilling { 068 069 @Override 070 public void fill(World world, Pool pool, ColumnPattern pattern) { 071 boolean sameParity = Util.getRandom().nextBoolean(); 072 073 for (Column column : pool.getShape()) { 074 Vector2D pt = column.getPos(); 075 if (((pt.getBlockX() & 1) == (pt.getBlockZ() & 1)) 076 == sameParity) { 077 column.reset(world); 078 } else { 079 column.set(world, pattern); 080 } 081 } 082 } 083 } 084 085 /** 086 * Replaces all columns (except a random one). 087 */ 088 public static class AllButOne implements PoolFilling { 089 090 @Override 091 public void fill(World world, Pool pool, ColumnPattern pattern) { 092 Random rand = Util.getRandom(); 093 FlatShape shape = pool.getShape(); 094 095 Vector2D except; 096 int minX = shape.getMin2D().getBlockX(); 097 int minZ = shape.getMin2D().getBlockZ(); 098 int maxX = shape.getMax2D().getBlockX(); 099 int maxZ = shape.getMax2D().getBlockZ(); 100 do { 101 except = new Vector2D(rand.nextInt(minX, maxX), 102 rand.nextInt(minZ, maxZ)); 103 } while (!shape.contains2D(except)); 104 105 for (Column column : shape) { 106 if (column.getPos().equals(except)) { 107 column.reset(world); 108 } else { 109 column.set(world, pattern); 110 } 111 } 112 } 113 } 114 115 void fill(World world, Pool pool, ColumnPattern pattern); 116}