All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mmb.engine.chance.ListChance Maven / Gradle / Ivy

Go to download

Dependency for the MultiMachineBuilder, a voxel game about building an industrial empire in a finite world. THIS RELEASE IS NOT PLAYABLE. To play the game, donwload from >ITCH.IO LINK HERE< or >GH releases link here<

There is a newer version: 0.6
Show newest version
/**
 * 
 */
package mmb.engine.chance;

import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;

import org.ainslec.picocog.PicoWriter;

import mmb.engine.inv.io.InventoryWriter;
import mmb.engine.item.ItemEntry;
import mmb.engine.worlds.world.World;

/**
 * @author oskar
 *
 */
public class ListChance implements Chance {
	private final Chance[] chances;
	public ListChance(Chance... chances) {
		super();
		this.chances = chances;
	}

	@Override
	public boolean drop(InventoryWriter inv, World map, int x, int y) {
		boolean result = false;
		for(Chance chance: chances) {
			result |= chance.drop(inv, map, x, y);
		}
		return result;
	}

	@Override
	public void produceResults(InventoryWriter tgt, int amount) {
		for(Chance chance: chances) {
			chance.produceResults(tgt, amount);
		}
	}

	@Override
	public void represent(PicoWriter out) {
		out.write("{");
		out.indentRight();
		out.writeln("");
		for(Chance chance: chances) {
			chance.represent(out);
			out.writeln("");
		}
		out.indentLeft();
		out.write("}");
	}

	@Override
	public boolean contains(ItemEntry item) {
		for(Chance chance: chances) {
			if(chance.contains(item)) return true;
		}
		return false;
	}

	private Set items;
	@Override
	public Set items() {
		if(items == null) items = Arrays.stream(chances).flatMap(chance -> chance.items().stream()).collect(Collectors.toSet());
		return items;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy