BloodMagic/1.7.2/main/java/WayofTime/alchemicalWizardry/api/rituals/Rituals.java

334 lines
8 KiB
Java
Raw Normal View History

2014-05-04 22:11:09 +00:00
package WayofTime.alchemicalWizardry.api.rituals;
2014-06-02 19:16:36 +00:00
import java.util.HashMap;
import java.util.LinkedList;
2014-05-04 22:11:09 +00:00
import java.util.List;
2014-06-02 19:16:36 +00:00
import java.util.Map;
2014-05-04 22:11:09 +00:00
2014-06-02 19:16:36 +00:00
import scala.reflect.internal.Trees.This;
2014-05-04 22:11:09 +00:00
import net.minecraft.block.Block;
import net.minecraft.world.World;
public class Rituals
{
private int crystalLevel;
private int actCost;
private RitualEffect effect;
private String name;
2014-06-02 19:16:36 +00:00
public static Map<String,Rituals> ritualMap = new HashMap();
@Deprecated
public static List<Rituals> ritualList = new LinkedList();
public static List<String> keyList = new LinkedList();
2014-05-04 22:11:09 +00:00
public Rituals(int crystalLevel, int actCost, RitualEffect effect, String name)
{
this.crystalLevel = crystalLevel; //For a test commit
2014-05-04 22:11:09 +00:00
this.actCost = actCost;
this.effect = effect;
this.name = name;
2014-06-02 19:16:36 +00:00
keyList.add(name);
ritualMap.put(name, this);
2014-05-04 22:11:09 +00:00
}
2014-06-02 19:16:36 +00:00
/**
* Static method to register a ritual to the Ritual Registry
* @param key Unique identification key - must be different from all others to properly register
* @param crystalLevel Crystal level required to activate
* @param actCost LP amount required to activate
* @param effect The effect that will be ticked
* @param name The name of the ritual
* @return Returns true if properly registered, or false if the key is already used
*/
public static boolean registerRitual(String key, int crystalLevel, int actCost, RitualEffect effect, String name)
2014-05-04 22:11:09 +00:00
{
2014-06-02 19:16:36 +00:00
if(ritualMap.containsKey(key))
{
return false;
}
else
{
Rituals ritual = new Rituals(crystalLevel, actCost, effect, name);
ritual.removeRitualFromList();
ritualMap.put(key, ritual);
keyList.add(key);
return true;
}
}
public void removeRitualFromList()
{
if(ritualMap.containsValue(this))
{
ritualMap.remove(ritualMap.remove(this.name));
}
if(keyList.contains(this.name))
{
keyList.remove(this.name);
}
}
2014-05-04 22:11:09 +00:00
2014-06-02 19:16:36 +00:00
public static String checkValidRitual(World world, int x, int y, int z)
{
for(String key : ritualMap.keySet())
{
if(checkRitualIsValid(world,x,y,z,key))
{
return key;
}
}
return "";
2014-05-04 22:11:09 +00:00
}
2014-06-02 19:16:36 +00:00
public static boolean canCrystalActivate(String ritualID, int crystalLevel)
2014-05-04 22:11:09 +00:00
{
2014-06-02 19:16:36 +00:00
if(ritualMap.containsKey(ritualID))
{
Rituals ritual = ritualMap.get(ritualID);
if(ritual != null)
{
return ritual.getCrystalLevel() <= crystalLevel;
}
}
return false;
2014-05-04 22:11:09 +00:00
}
2014-06-02 19:16:36 +00:00
public static boolean checkRitualIsValid(World world, int x, int y, int z, String ritualID)
2014-05-04 22:11:09 +00:00
{
int direction = Rituals.getDirectionOfRitual(world, x, y, z, ritualID);
if (direction != -1)
{
return true;
}
return false;
}
/**
* 1 - NORTH
* 2 - EAST
* 3 - SOUTH
* 4 - WEST
*/
2014-06-02 19:16:36 +00:00
public static boolean checkDirectionOfRitualValid(World world, int x, int y, int z, String ritualID, int direction)
2014-05-04 22:11:09 +00:00
{
List<RitualComponent> ritual = Rituals.getRitualList(ritualID);
if (ritual == null)
{
return false;
}
Block test = null;
switch (direction)
{
case 1:
for (RitualComponent rc : ritual)
{
test = world.getBlock(x + rc.getX(), y + rc.getY(), z + rc.getZ());
if (!(test instanceof IRitualStone))
{
return false;
}
if (world.getBlockMetadata(x + rc.getX(), y + rc.getY(), z + rc.getZ()) != rc.getStoneType())
{
return false;
}
}
return true;
case 2:
for (RitualComponent rc : ritual)
{
test = world.getBlock(x - rc.getZ(), y + rc.getY(), z + rc.getX());
if (!(test instanceof IRitualStone))
{
return false;
}
if (world.getBlockMetadata(x - rc.getZ(), y + rc.getY(), z + rc.getX()) != rc.getStoneType())
{
return false;
}
}
return true;
case 3:
for (RitualComponent rc : ritual)
{
test = world.getBlock(x - rc.getX(), y + rc.getY(), z - rc.getZ());
if (!(test instanceof IRitualStone))
{
return false;
}
if (world.getBlockMetadata(x - rc.getX(), y + rc.getY(), z - rc.getZ()) != rc.getStoneType())
{
return false;
}
}
return true;
case 4:
for (RitualComponent rc : ritual)
{
test = world.getBlock(x + rc.getZ(), y + rc.getY(), z - rc.getX());
if (!(test instanceof IRitualStone))
{
return false;
}
if (world.getBlockMetadata(x + rc.getZ(), y + rc.getY(), z - rc.getX()) != rc.getStoneType())
{
return false;
}
}
return true;
}
return false;
}
2014-06-02 19:16:36 +00:00
public static int getDirectionOfRitual(World world, int x, int y, int z, String ritualID)
2014-05-04 22:11:09 +00:00
{
for (int i = 1; i <= 4; i++)
{
if (Rituals.checkDirectionOfRitualValid(world, x, y, z, ritualID, i))
{
return i;
}
}
return -1;
}
2014-06-02 19:16:36 +00:00
public static int getCostForActivation(String ritualID)
2014-05-04 22:11:09 +00:00
{
2014-06-02 19:16:36 +00:00
if(ritualMap.containsKey(ritualID))
{
Rituals ritual = ritualMap.get(ritualID);
if(ritual != null)
{
return ritual.actCost;
}
}
return 0;
2014-05-04 22:11:09 +00:00
}
2014-06-02 19:16:36 +00:00
public static int getInitialCooldown(String ritualID)
2014-05-04 22:11:09 +00:00
{
2014-06-02 19:16:36 +00:00
if(ritualMap.containsKey(ritualID))
{
Rituals ritual = ritualMap.get(ritualID);
if(ritual != null && ritual.effect != null)
{
return ritual.effect.getInitialCooldown();
}
}
return 0;
2014-05-04 22:11:09 +00:00
}
2014-06-02 19:16:36 +00:00
public static List<RitualComponent> getRitualList(String ritualID)
2014-05-04 22:11:09 +00:00
{
2014-06-02 19:16:36 +00:00
if(ritualMap.containsKey(ritualID))
{
Rituals ritual = ritualMap.get(ritualID);
if(ritual != null)
{
return ritual.obtainComponents();
}else
{
return null;
}
}else
{
return null;
}
2014-05-04 22:11:09 +00:00
}
private List<RitualComponent> obtainComponents()
{
return this.effect.getRitualComponentList();
}
private int getCrystalLevel()
{
return this.crystalLevel;
}
2014-06-02 19:16:36 +00:00
public static void performEffect(IMasterRitualStone ritualStone, String ritualID)
2014-05-04 22:11:09 +00:00
{
2014-06-02 19:16:36 +00:00
if(ritualMap.containsKey(ritualID))
{
Rituals ritual = ritualMap.get(ritualID);
if(ritual != null && ritual.effect != null)
{
ritual.effect.performEffect(ritualStone);
}
}
2014-05-04 22:11:09 +00:00
}
public static int getNumberOfRituals()
{
2014-06-02 19:16:36 +00:00
return ritualMap.size();
2014-05-04 22:11:09 +00:00
}
public String getRitualName()
{
return this.name;
}
2014-06-02 19:16:36 +00:00
public static String getNameOfRitual(String id)
2014-05-04 22:11:09 +00:00
{
2014-06-02 19:16:36 +00:00
if(ritualMap.containsKey(id))
{
Rituals ritual = ritualMap.get(id);
if(ritual != null)
{
return ritual.getRitualName();
}
}
return "";
}
public static String getNextRitualKey(String key)
{
boolean hasSpotted = false;
String firstKey = "";
for(String str : keyList)
{
if(firstKey.equals(""))
{
firstKey = str;
}
if(hasSpotted)
{
return str;
}
if(str.equals(key))
{
hasSpotted = true;
}
}
return firstKey;
2014-05-04 22:11:09 +00:00
}
}