Created
July 9, 2021 00:34
-
-
Save KinoAR/7ed6467154b9b349156bdc8aa806f890 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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