74 lines
2.1 KiB
Java
74 lines
2.1 KiB
Java
package shootergame.tiles;
|
|
|
|
import java.util.Random;
|
|
|
|
import shootergame.Main;
|
|
import shootergame.entity.Entity;
|
|
import shootergame.entity.EntityItem;
|
|
import shootergame.init.Items;
|
|
import shootergame.init.Textures;
|
|
import shootergame.util.math.ItemStack;
|
|
import shootergame.util.math.TileState;
|
|
import shootergame.util.math.random.RandomHelpers;
|
|
import shootergame.util.math.vec.Vec2d;
|
|
import shootergame.util.math.vec.Vec2i;
|
|
import shootergame.world.chunk.Chunk;
|
|
import shootergame.world.layer.Layer;
|
|
|
|
public class TileChest extends TileVertical
|
|
{
|
|
public static final short CHEST_CAVES = 0;
|
|
|
|
public TileChest(String id) {
|
|
super(id, Textures.TILE_CHEST, new Vec2d(1, 1));
|
|
|
|
this.tileSolid = true;
|
|
this.opaqueTile = true;
|
|
this.tileHitbox = 0.4;
|
|
|
|
}
|
|
|
|
private void spawnItem(Chunk chunk, Vec2i pos, ItemStack stack) {
|
|
chunk.spawnEntity(new EntityItem(new Vec2d(pos.x+0.5, pos.y+0.5), stack));
|
|
}
|
|
|
|
@Override
|
|
public void onActivated(Layer layer, Vec2i tpos, Entity entity, TileState state) {
|
|
super.onActivated(layer, tpos, entity, state);
|
|
|
|
Chunk chunk = layer.getChunk(tpos);
|
|
Random rand = Main.rand;
|
|
|
|
if(state.meta == CHEST_CAVES)
|
|
{
|
|
// Ammo
|
|
spawnItem(chunk, tpos, new ItemStack(Items.AMMO, RandomHelpers.randrange(rand, 100), (short)1));
|
|
|
|
// Tnt
|
|
spawnItem(chunk, tpos, new ItemStack(Items.TNT, RandomHelpers.randrange(rand, 2), (short)10));
|
|
|
|
// Health potions
|
|
spawnItem(chunk, tpos, new ItemStack(Items.HEALTH_POTION, RandomHelpers.randrange(rand, 4), (short)50));
|
|
|
|
// Gun upgrade
|
|
if(RandomHelpers.randrange(rand, 5) == 0) {
|
|
spawnItem(chunk, tpos, new ItemStack(Items.GUN_UPGRADE, 1, (short)1));
|
|
}
|
|
if(RandomHelpers.randrange(rand, 20) == 0) {
|
|
spawnItem(chunk, tpos, new ItemStack(Items.GUN_UPGRADE, 1, (short)2));
|
|
}
|
|
|
|
// Defence upgrade
|
|
if(RandomHelpers.randrange(rand, 20) == 0) {
|
|
spawnItem(chunk, tpos, new ItemStack(Items.DEFENCE_UPGRADE, 1, (short)2));
|
|
}
|
|
if(RandomHelpers.randrange(rand, 5) == 0) {
|
|
spawnItem(chunk, tpos, new ItemStack(Items.DEFENCE_UPGRADE, 1, (short)1));
|
|
}
|
|
}
|
|
|
|
layer.breakFrontTile(tpos);
|
|
}
|
|
|
|
}
|