Skip to content

Instantly share code, notes, and snippets.

@KinoAR
Created July 9, 2021 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KinoAR/7ed6467154b9b349156bdc8aa806f890 to your computer and use it in GitHub Desktop.
Save KinoAR/7ed6467154b9b349156bdc8aa806f890 to your computer and use it in GitHub Desktop.
/**
* ADTs take in a parameter as you can see here.
*/
enum ElementalAtk {
FireAtk(?dmg:Int);
WaterAtk(?dmg:Int);
LightningAtk(?dmg:Int);
MagnetoAtk(?dmg:Int);
IceAtk(?dmg:Int);
WindAtk(?dmg:Int);
PhysAtk(?dmg:Int);
}
/**
* Elemental Resistances.
* Elemental resistance of 100 means you will not be affected by the
* status effect, thus making it impossible to be caught on fire.
*
*/
enum ElementalResistances {
FireRes(?res:Float); // question mark means you don't have to enter the elemental resistance Float
WaterRes(?res:Float);
IceRes(?res:Float);
MagneticRes(?res:Float);
LightningRes(?res:Float);
WindRes(?res:Float);
PhysRes(?res:Float);
}
class Monsters {
//We default all the resistances here to 0.5 for all monsters
public var fireRes:Float = 0.5;
public var waterRes:Float = 0.5;
public var iceRes:Float = 0.5;
public var windRes:Float = 0.5;
public var magneticRes:Float = 0.5;
public var lightningRes:Float = 0.5;
public var physRes:Float = 0.5;
public var burnt:Bool;
public function new() {
//Set a specific resistance
this.setRes(FireRes(1.0)); //Sets the monsters Fire resistance to one.
this.setRes(IceRes(1.0)); //Sets the monster Ice resistance to one.
}
/**
* Allows you to set the resistance of an element by passing
* in the enum/ADT value.
* @param res ElementalResistance
*/
public function setRes(res:ElementalResistances) {
switch (res) {
case FireRes(res):
fireRes = res;
case WaterRes(res):
waterRes = res;
case IceRes(res):
iceRes = res;
case WindRes(res):
windRes = res;
case MagneticRes(res):
magneticRes = res;
case LightningRes(res):
lightningRes = res;
case PhysRes(res):
physRes = res;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment