Skip to content

Instantly share code, notes, and snippets.

@jacobparis
Created October 9, 2017 21:38
Show Gist options
  • Save jacobparis/c0f74c416ceb93eca449ff55fd4e78f6 to your computer and use it in GitHub Desktop.
Save jacobparis/c0f74c416ceb93eca449ff55fd4e78f6 to your computer and use it in GitHub Desktop.
class Worker {
public var miningExperience:Float = 0;
public var walkingExperience:Float = 0;
public var carryExperience:Float = 0;
public var attackExperience:Float = 0;
public function new() {}
/** A worker is likely to accept any task that surpasses its threshold.
* A skilled miner will thus have a very low mining threshold **/
public function mineThreshold():Float {
return 1 / this.miningSpeed();
}
inline function miningSpeed():Float {
return 1.0 + this.miningExperience;
}
public function carryThreshold():Float {
return 1 / walkingSpeed() + carryLimit() / 5.0;
}
inline function walkingSpeed():Float {
return 1.0 + this.walkingExperience;
}
inline function carryLimit():Float {
return 1.0 + this.carryExperience;
}
/**
* Train a skill. Should be called every time a task is completed
* @param skill - The skill to train
*/
public function train(skill:Skills):Void {
var x = 1.01;
switch(skill) {
case MINE: {
buff(this.miningExperience, x, 3);
debuff(this.walkingExperience, x, 2);
debuff(this.carryExperience, x, 1);
}
case WALK: {
buff(this.walkingExperience, x, 1);
}
case CARRY: {
buff(this.carryExperience, x, 4);
debuff(this.miningExperience, x, 1);
}
case ATTACK: {
buff(this.attackExperience, x, 4);
debuff(this.miningExperience, x, 2);
debuff(this.walkingExperience, x, 2);
debuff(this.carryExperience, x, 2);
}
}
}
inline function buff(value:Float, amount:Float, times:Int):Float {
return value * Math.pow(amount, times);
}
inline function debuff(value:Float, amount:Float, times:Int):Float {
return value / Math.pow(amount, times);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment