Created
January 8, 2013 16:44
-
-
Save unstoppablecarl/4485355 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
/** | |
* all values in percentages | |
*/ | |
Attack = ig.Class.extend({ | |
/** | |
* unit this attack belongs to | |
*/ | |
unit: null, | |
init: function(unit){ | |
this.unit = unit; | |
}, | |
name: 'rifle_burst', | |
displayName: 'Rifle Burst', | |
cost: { | |
AP: 5, | |
MP: 0, | |
health: 0, | |
stress: 0 | |
}, | |
// number of times this attack is applied per usage | |
rateOfFire: 1, | |
range: { | |
min: 0, | |
max: 30 | |
}, | |
damageApplied: [ | |
{ | |
type: 'balistic', | |
ammount: 3 | |
} | |
], | |
accuracy: 50, | |
// target type can be 'unit' | |
getTargetDistance: function(target){ | |
if(this.targetType == 'unit'){ | |
var target = this.targetUnit.hex; | |
} | |
this.unit.hex.getDistanceToHex(target.hex); | |
}, | |
targetUnitIsValid: function(unit){ | |
return this.targetHexIsValid(unit.hex); | |
}, | |
targetHexIsValid: function(hex){ | |
// check unit has line of sight to target | |
if(!unit.hex.groups.LOSVisible){ | |
return false; | |
} | |
// check max range to target | |
if(this.range.max < this.unit.hex.getDistanceToHex(hex)){ | |
return false; | |
}; | |
return true; | |
}, | |
getAccuracyRangePenalty: function(range){ | |
if(range <= 5){ | |
return 0; | |
} | |
// -2% for every hex after 5 | |
return 2 * (range - 5); | |
}, | |
getTargetStealthTerrainBonus: function(target){ | |
// get all obstacles overlaping with the field of view between this.unit (attacker) and target, then select the one with highest stealth bonus | |
return 0; | |
}, | |
getTargetDefenseTerrainBonus: function(target){ | |
// get all obstacles overlaping with the field of view between this.unit (attacker) and target, then select the one with highest defense bonus | |
return 0; | |
}, | |
getTargetDetectionChance: function(target){ | |
// calculate chance of detection of target based on distance, cover, stealth stat, etc. | |
return | |
this.unit.stats.detection | |
+ this.unit.getDetectionRangePenalty(this.getTargetDistance(target)) | |
- this.getTargetStealthTerrainBonus(target) | |
- target.stats.stealth; | |
}, | |
getTargetHitChance: function(target){ | |
// calculate chance of detection of target based on distance, cover, stealth stat, etc. | |
return | |
this.accuracy | |
- target.stats.defense | |
- this.getTargetDefenseTerrainBonus(target); | |
}, | |
getTotalDamage: function(target){ | |
var total = 0; | |
for(var i = 0, len = this.damageApplied; i < len; i++){ | |
var dmg = this.damageApplied[i]; | |
if(dmg.type in target.stats.armor){ | |
var armorResistanceToType = target.stats.armor[dmg.type], | |
damageDealt = dmg.ammount - armorResistanceToType; | |
if (damageDealt < 0) damageDealt = 0; | |
total += damageDealt; | |
} | |
} | |
return total; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment