Ok, this should work for you: on('ready',function(){
"use strict";
const requiredMoveDistance = 2,
attributeName = 'jumpBonus',
valueSuccess = '2',
valueFailure = '1';
let getPageScale = (function(){
let cache = {};
const pageScale = function( pageid ){
if(!_.has(cache,pageid)){
let page = getObj('page',pageid);
if(page){
cache[pageid]={
scale: page.get('scale_number'),
units: page.get('scale_units'),
diagonal: page.get('diagonaltype')
};
} else {
cache[pageid]={
scale: 5,
units: 'ft',
diagonal: 'pythagorean'
};
}
}
return cache[pageid];
};
on('change:page',(p)=>(delete cache[p.id],pageScale(p.id)));
on('destroy:page',(p)=>delete cache[p.id]);
return pageScale;
}()),
getLastMoveDistance = function(obj){
let x = obj.get('left'),
y = obj.get('top'),
p = _.chain(obj.get('lastmove').split(/,/))
.map((n)=>parseInt(n,10))
.last(2)
.value(),
x1 = p[0]||x,
y1 = p[1]||y,
scale = getPageScale(obj.get('pageid')),
dist
;
switch(scale.diagonal){
case 'foure':
dist = Math.max(Math.abs(x-x1), Math.abs(y-y1));
dist = (dist/70)*scale.scale;
break;
case 'manhattan':
dist = Math.abs(x-x1) + Math.abs(y-y1);
dist = (dist/70)*scale.scale;
break;
case 'threefive':
// best guess... no way to REALLY do this right easily
let xd = Math.abs(x-x1)/70,
yd = Math.abs(y-y1)/70;
dist = Math.max(xd,yd)*scale.scale;
if(Math.floor(xd) && Math.floor(yd)){
dist = Math.floor(Math.ceil(dist/5)*1.5)*5;
}
break;
default:
case 'pythagorean':
dist = Math.sqrt( Math.pow(Math.abs(x-x1),2) + Math.pow(Math.abs(y-y1),2));
dist = (dist/70)*scale.scale;
break;
}
return dist;
};
on('change:graphic',function(obj,prev){
if(Campaign().get('initiativepage') !== false && obj.get('represents')){
let toRaw=Campaign().get('turnorder'),
to = JSON.parse(toRaw)||[];
if( to[0] && obj.id === to[0].id){
let lastMoveDist=getLastMoveDistance(obj),
attr = findObjs({
type: 'attribute',
name: attributeName,
characterid: obj.get('represents')
})[0];
if(!attr){
attr=createObj('attribute',{
characterid: obj.get('represents'),
name: attributeName,
current: valueFailure
});
}
if(lastMoveDist >= requiredMoveDistance){
attr.set('current',valueSuccess);
} else {
attr.set('current',valueFailure);
}
}
}
});
on('change:campaign:initiativepage',function(c,prev){
_.each(findObjs({
type: 'attribute',
name: attributeName
}),(a)=>a.set('current',valueFailure));
});
on('change:campaign:turnorder',function(c,prev){
let toRaw=c.get('turnorder'),
to = JSON.parse(toRaw)||[],
t = getObj('graphic',to[0] && to[0].id),
cid = t && t.get('represents');
_.each(findObjs({
type: 'attribute',
name: attributeName
}),(a)=>{
if(a.get('characterid') !== cid ){
a.set('current',valueFailure);
}
});
});
});
It will now respect the page settings regarding diagonal movement type (though 3.5 setting is a bit weird, but I don't figure you use that so didn't spend too much time on it. =D).