Add CV auto calculator
parent
6fab2976cf
commit
95264be64d
|
@ -15,10 +15,62 @@ function readSpecimens(collection, v) {
|
|||
for (let s of v.specimens) {
|
||||
// Assign file family to specimen type just for sorting simplicity.
|
||||
s.type = v.family
|
||||
s.combatvalue = calculateCV(s)
|
||||
collection.insert(s)
|
||||
}
|
||||
}
|
||||
|
||||
function calculateCV(t) {
|
||||
if (!t) return 0
|
||||
if (t.combatvalue) return t.combatvalue
|
||||
let v = 0
|
||||
if (t.health) {
|
||||
v += 1 + t.health/2
|
||||
}
|
||||
if(t.move) {
|
||||
v += t.move
|
||||
}
|
||||
if (t.attack) {
|
||||
v += t.attack
|
||||
}
|
||||
if (Array.isArray(t.attacks) && t.attacks.length > 0) {
|
||||
let avgDmg = 0
|
||||
let avgAtk = 0
|
||||
let hasOpportunity = 0
|
||||
for (let a of t.attacks) {
|
||||
let aDmg = 0
|
||||
for (let d of a.damage) {
|
||||
aDmg += d.value
|
||||
}
|
||||
avgDmg += aDmg / a.damage.length
|
||||
avgAtk += a.attack
|
||||
if (a.opportunistic) {
|
||||
hasOpportunity = 1
|
||||
}
|
||||
}
|
||||
avgDmg /= t.attacks.length
|
||||
avgAtk /= t.attacks.length
|
||||
v += avgDmg / avgAtk + hasOpportunity
|
||||
}
|
||||
if (Array.isArray(t.defenses)) {
|
||||
let maxDef = 0
|
||||
let defs = t.defenses.length
|
||||
let perfects = 0
|
||||
for (let d of t.defenses) {
|
||||
if (d.perfect) {
|
||||
perfects++
|
||||
}
|
||||
maxDef = Math.max(maxDef, d.value)
|
||||
}
|
||||
v += maxDef + defs + perfects
|
||||
}
|
||||
if (Array.isArray(t.specials)) {
|
||||
v += t.specials.length
|
||||
}
|
||||
|
||||
return Math.round(v)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
readSpecimens,
|
||||
}
|
||||
|
|
|
@ -343,3 +343,7 @@ td:last-child {
|
|||
cursor: copy;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
small {
|
||||
font-size: 70%;
|
||||
}
|
|
@ -159,11 +159,12 @@ Sort: <a href="?sort-by=name">Name</a> <a href="?sort-by=worth">Worth</a>
|
|||
#}}
|
||||
|
||||
{{##def.specimens_table_entry:item:
|
||||
<h2><a href="/db/specimens/{{=item.type||''}}/{{=item.name || ''}}">{{=item.name || ''}}</a> <span data-json='{{=JSON.stringify(item)}}'></span> </h2>
|
||||
<h2><a href="/db/specimens/{{=item.type||''}}/{{=item.name || ''}}">{{=item.name || ''}}</a><span data-json='{{=JSON.stringify(item)}}'></span> </h2>
|
||||
<p>{{=item.description || ''}}</p>
|
||||
<strong>Move</strong> {{=item.move || ''}};
|
||||
<strong>Attack</strong> {{=item.attack || ''}};
|
||||
<strong>Health</strong> {{=item.health || ''}} (<a href="#" data-flip="+{{=item.health}}"></a>)
|
||||
<strong>Health</strong> {{=item.health || ''}} (<a href="#" data-flip="+{{=item.health}}"></a>);
|
||||
<strong>CV</strong> {{=item.combatvalue || ''}}
|
||||
<h3>Attacks</h3>
|
||||
{{~item.attacks :attack}}
|
||||
<h4> {{=attack.name || 'unknown'}} ({{=attack.attacktype || 'melee' }}) </h4>
|
||||
|
|
Loading…
Reference in New Issue