package org.pfaa.chemica.model;

import java.util.List;

import net.minecraft.potion.PotionEffect;

public class Hazard {
	public enum SpecialCode {
		NONE, OXIDIZER, WATER_REACTIVE, SIMPLE_ASPHYXIANT, CORROSIVE, BIOHAZARD, POISONOUS, RADIOACTIVE, CRYOGENIC
	}
	
	public final int health;
	public final int flammability;
	public final int instability;
	public final SpecialCode special;
	
	public Hazard(int health, int flammability, int instability, SpecialCode special) {
		if (health < 0 || health > 4)
			throw new IllegalArgumentException("'health' must be in [0,4]");
		if (flammability < 0 || flammability  > 4)
			throw new IllegalArgumentException("'flammability' must be in [0,4]");
		if (instability < 0 || instability > 4)
			throw new IllegalArgumentException("'instability' must be in [0,4]");
		this.health = health;
		this.flammability = flammability;
		this.instability = instability;
		this.special = special;
	}
	
	public Hazard(int health, int flammability, int instability) {
		this(health, flammability, instability, SpecialCode.NONE);
	}

	public Hazard() {
		this(1, 0, 0);
	}

	private static final double[] IGNITION_TEMP_LIMITS = new double[] { 
		Double.POSITIVE_INFINITY, 500, 400, Constants.STANDARD_TEMPERATURE, 200
	};

	public boolean isFlammable(Condition condition) {
		return condition.temperature >= IGNITION_TEMP_LIMITS[this.flammability];
	}
	
	private static final double[] EXPLOSION_TEMP_LIMITS = new double[] { 
		Double.POSITIVE_INFINITY, 500, 400, 300, Constants.STANDARD_TEMPERATURE
	};
	
	public int getExplosionRadius(Condition condition) {
		if (condition.temperature >= EXPLOSION_TEMP_LIMITS[this.instability]) {
			return this.instability; 
		} else {
			return 0;
		}
	}
	
	public List<PotionEffect> getHealthEffects() {
		switch(this.health) {
		case 0:
		case 1:
		case 2:
		case 3:
		case 4:
		default:
			throw new IllegalStateException("Invalid health value");
		}
	}
	
}

@@ -47,14 +47,78 @@
 til.
+Array
 List;%0A
+import java.util.List;%0A%0Aimport net.minecraft.potion.Potion;
 %0Aimp
@@ -1776,24 +1776,230 @@
 0;%0A%09%09%7D%0A%09%7D%0A%09%0A
+%09private PotionEffect createPotionEffect(Potion potion, int durationAmplifier) %7B%0A%09%09return new PotionEffect(potion.id, 20 * 2 %5E (this.health + durationAmplifier));%0A%09%7D%0A%09%0A%09// happens when inside a fluid block%0A
 %09public List
@@ -2020,14 +2020,15 @@
  get
-Health
+Contact
 Effe
@@ -2041,14 +2041,73 @@
 %7B%0A%09%09
-switch
+List%3CPotionEffect%3E effects = new ArrayList%3CPotionEffect%3E();%0A%09%09if 
 (thi
@@ -2118,140 +2118,460 @@
 alth
+ %3E= 2
 ) %7B%0A%09%09
-case 0:%0A%09%09case 1:%0A%09%09case 2:%0A%09%09case 3:%0A%09%09case 4:%0A%09%09default:%0A%09%09%09throw new IllegalStateException(%22Invalid health value%22);%0A%09%09%7D%0A%09%7D
+%09effects.add(this.createPotionEffect(Potion.poison, 0));%0A%09%09%7D%0A%09%09return effects;%0A%09%7D%0A%09%0A%09// happens when drinking a liquid (potion)%0A%09public List%3CPotionEffect%3E getIngestionEffects() %7B%0A%09%09List%3CPotionEffect%3E effects = new ArrayList%3CPotionEffect%3E();%0A%09%09if (this.health %3E= 1) %7B%0A%09%09%09effects.add(this.createPotionEffect(Potion.confusion, 1));%0A%09%09%7D%0A%09%09if (this.health %3E= 2) %7B%0A%09%09%09effects.add(this.createPotionEffect(Potion.poison, 1));%0A%09%09%7D%0A%09%09return effects;
 %0A%09
+%7D
 %0A%7D%0A

implement potion effects from health hazards