-
-
Save Rouby/8e7953cbbf6c6094f915 to your computer and use it in GitHub Desktop.
This file contains 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
///////////////////////////////////////////////// | |
/***********************************************/ | |
var GIM = { | |
alias: "Graphic Inventory Manager", | |
author: { | |
name: "John C." || "Echo" || "SplenectomY", | |
company: "Team Asshat" || "The Alehounds", | |
contact: "echo@TeamAsshat.com", | |
}, | |
version: "0.2", | |
gist: "https://gist.github.com/SplenectomY/9d1ef745f23927edc930", | |
forum: "", | |
/***********************************************/ | |
///////////////////////////////////////////////// | |
/////////BEGIN USER CONFIG///////// | |
playerList: [ | |
"-JeTLkLt_UFt7Boc1DsQ", /* 1: Coille Flitterleaf */ | |
"-JeT529rL-wvu8yT8Q9N", /* 2: Tanion of House Victaria */ | |
"-JeXs7g5ADZiaVjYOdIg", /* 3: Oldstuff McTuggins */ | |
"-Jebn59AIWLWOxW3WMS9", /* 4: Xanneiros Lothammer */ | |
//"-JeIO7XaKP76ZS22z0x3", /* 5: Sampleton Testificate */ | |
], | |
logPlayerIds: true, | |
invImg: "https://s3.amazonaws.com/files.d20.io/images/6927416/y5kI_BBCDJrxGCU8FttwEg/thumb.png?1420069394", | |
coin: { | |
wgt: 0.02, /* in lbs. Default is per 5e rules */ | |
vol: 0.0002 /* in cubic feet. (5,000 per ft3) */ | |
}, | |
temperatureUnit: "F", /* Change to C if Celsius is desired */ | |
storageItems: [ | |
backpack = { | |
name: "backpack", | |
max_wgt: 30, | |
max_vol: 1, | |
}, | |
quiver = { | |
name: "quiver", | |
max_wgt: "", | |
max_vol: 0.1, | |
}, | |
boltCase = { | |
name: "boltcase", | |
max_wgt: "", | |
max_vol: 0.15, | |
}, | |
pouch = { | |
name: "pouch", | |
max_wgt: 6, | |
max_vol: .2, | |
}, | |
bagHolding = { | |
name: "bagofholding", | |
max_wgt: 500, | |
max_vol: 64, | |
}, | |
handyHaversackSide1 = { | |
name: "hhhside1", | |
max_wgt: 20, | |
max_vol: 2, | |
}, | |
handyHaversackSide2 = { | |
name: "hhhside2", | |
max_wgt: 20, | |
max_vol: 2, | |
}, | |
handyHaversack = { | |
name: "hhh", | |
max_wgt: 80, | |
max_vol: 8, | |
}, | |
// I have 6 pockets, because thats the max | |
// I would give my characters on any item. | |
// Add more if you wish. | |
pocket1 = { | |
name: "pocket1", | |
max_wgt: 3, | |
max_vol: .1, | |
}, | |
pocket2 = { | |
name: "pocket2", | |
max_wgt: 3, | |
max_vol: .1, | |
}, | |
pocket3 = { | |
name: "pocket3", | |
max_wgt: 3, | |
max_vol: .1, | |
}, | |
pocket4 = { | |
name: "pocket4", | |
max_wgt: 3, | |
max_vol: .1, | |
}, | |
pocket5 = { | |
name: "pocket5", | |
max_wgt: 3, | |
max_vol: .1, | |
}, | |
pocket6 = { | |
name: "pocket6", | |
max_wgt: 3, | |
max_vol: .1, | |
}, | |
], | |
//////////END USER CONFIG////////// | |
runTimeout: 0, | |
isNewGraphic: false, | |
extraRun: false, | |
objsToBeCreated: [], | |
runMe: function forGreatJustice() { | |
if (GIM.runTimeout > 0) { | |
GIM.runTimeout--; | |
} else { | |
processGIM() | |
for(i1 = 0; i1 < GIM.objsToBeCreated.length; i1++) { | |
create_inv( | |
GIM.objsToBeCreated[i1][0], | |
GIM.objsToBeCreated[i1][1], | |
GIM.objsToBeCreated[i1][2], | |
GIM.objsToBeCreated[i1][3], | |
GIM.objsToBeCreated[i1][4], | |
GIM.objsToBeCreated[i1][5], | |
GIM.objsToBeCreated[i1][6] | |
); | |
} | |
GIM.objsToBeCreated = []; | |
// This handles any extra runs | |
if (GIM.extraRun == true && GIM.objsToBeCreated.length == 0) { | |
processGIM(); | |
processGIM(); | |
GIM.extraRun = false; | |
} | |
GIM.runTimeout--; | |
} | |
}, | |
isObj: function runFlagChecks(obj,type) { | |
s = obj.get("gmnotes"); | |
var isObjResult, | |
invFlags = [ | |
"main", | |
"inv", | |
"worn", | |
"drop", | |
"ignore" | |
], | |
statusTokenFlags = [ | |
"status", | |
"status2" | |
]; | |
if (type == "item") { | |
isObjResult = true; | |
for (i2 = 0; i2 < invFlags.length; i2++) { | |
if (s.indexOf(invFlags[i2]) !== -1) { | |
isObjResult = false; | |
} | |
} | |
for (i3 = 0; i3 < statusTokenFlags.length; i3++) { | |
if (s.indexOf(statusTokenFlags[i3]) !== -1) { | |
isObjResult = false; | |
} | |
} | |
} | |
if (type == "inv") { | |
isObjResult = false; | |
for (i4 = 0; i4 < invFlags.length; i4++) { | |
if (s.indexOf(invFlags[i4]) !== -1) { | |
isObjResult = true; | |
} | |
} | |
} | |
if (type == "status") { | |
isObjResult = false; | |
for (i4 = 0; i4 < statusTokenFlags.length; i4++) { | |
if (s.indexOf(statusTokenFlags[i4]) !== -1) { | |
isObjResult = true; | |
} | |
} | |
} | |
return isObjResult; | |
}, | |
isInside: function allYourBase(x,y) { | |
if (x.get("left") > y.left && x.get("top") > y.top && x.get("left") < y.right && x.get("top") < y.bottom) return true; | |
else return false; | |
} | |
}; | |
fixedCreateObj = (function () { | |
return function () { | |
var obj = createObj.apply(this, arguments); | |
if (obj && !obj.fbpath) { | |
obj.fbpath = obj.changed._fbpath.replace(/([^\/]*\/){4}/, "/"); | |
} | |
return obj; | |
}; | |
}()); | |
function processGIM() { | |
var warmth = [], | |
hosp = [], | |
hosp_average = 0, | |
equipped = [], | |
inv = [], | |
items = [], | |
items_stacked = [], | |
objInvs = filterObjs(function(obj) { | |
if(obj.get("type") == "graphic") { | |
return GIM.isObj(obj,"inv"); | |
} | |
else return false; | |
}), | |
objItems = filterObjs(function(obj) { | |
if(obj.get("type") == "graphic") { | |
return GIM.isObj(obj,"item"); | |
} | |
else return false; | |
}), | |
objStatus = filterObjs(function(obj) { | |
if(obj.get("type") == "graphic") { | |
return GIM.isObj(obj,"status"); | |
} | |
else return false; | |
}), | |
objects = objInvs.concat(objItems,objStatus); | |
for (i5 = 0; i5 < GIM.playerList.length; i5++) { | |
warmth[i5] = 0; | |
hosp[i5] = 0; | |
equipped[i5] = []; | |
} | |
/***************************/ | |
/***** STEP 1 out of 4 *****/ | |
/***************************/ | |
_.each(objInvs, function(obj) { | |
s = obj.get("gmnotes"); | |
if (s.indexOf("main") !== -1) { | |
if (!obj.get("bar1_value")) {obj.set("bar1_value", 0)} | |
inv[inv.length] = { | |
type: "main", | |
id: obj.get("_id"), | |
owner: obj.get("bar3_value"), | |
weight: 0, | |
volume: 0, | |
inv_gmnotes: obj.get("gmnotes"), | |
left: Math.floor(obj.get("left") - Math.floor(obj.get("width") / 2)), | |
top: Math.floor(obj.get("top") - Math.floor(obj.get("height") / 2)), | |
right: Math.floor(obj.get("left") + Math.floor(obj.get("width") / 2)), | |
bottom: Math.floor(obj.get("top") + Math.floor(obj.get("height") / 2)) | |
}; | |
} | |
}); | |
/***************************/ | |
/***** STEP 2 out of 4 *****/ | |
/***************************/ | |
_.each(objInvs, function(obj) { | |
s = obj.get("gmnotes"); | |
for(i6 = 0; i6 < inv.length; i6++) { | |
if (inv[i6].type == "main" && s.indexOf("main") == -1 && GIM.isInside(obj, inv[i6]) == true) { | |
inv[inv.length] = { | |
type: "sub", | |
id: obj.get("_id"), | |
owner: inv[i6].owner, | |
weight: 0, | |
volume: 0, | |
layer: obj.get("layer"), | |
inv_gmnotes: obj.get("gmnotes"), | |
left: Math.floor(obj.get("left") - Math.floor(obj.get("width") / 2)), | |
top: Math.floor(obj.get("top") - Math.floor(obj.get("height") / 2)), | |
right: Math.floor(obj.get("left") + Math.floor(obj.get("width") / 2)), | |
bottom: Math.floor(obj.get("top") + Math.floor(obj.get("height") / 2)) | |
}; | |
} | |
} | |
}); | |
/***************************/ | |
/***** STEP 3 out of 4 *****/ | |
/***************************/ | |
_.each(objItems, function(obj) { | |
s = obj.get("gmnotes"); | |
// ... log it into the item array | |
items[items.length] = { | |
id: obj.get("_id"), | |
left: obj.get("left"), | |
top: obj.get("top") | |
}; | |
// ... make sure the item has wgt/vol values | |
if(!obj.get("bar1_value")) {obj.set("bar1_value",0)} | |
if(!obj.get("bar2_value")) {obj.set("bar2_value",0)} | |
// If it's an empty potion, remove the name and tint | |
if (s.indexOf("liquid") !== -1 && obj.get("bar1_value") == 0) { | |
obj.set("name",""); | |
obj.set("tint_color","transparent"); | |
} | |
// Settings for newly added items | |
if(GIM.isNewGraphic == true) { | |
obj.set("showplayers_name",true); | |
obj.set("showname",true); | |
obj.set("playersedit_bar2",false); | |
obj.set("playersedit_bar3",false); | |
obj.set("showplayers_bar3",false); | |
obj.set("showplayers_bar2",false); | |
if (s.indexOf("liquid") !== -1) { | |
obj.set("playersedit_bar1",true); | |
obj.set("showplayers_bar1",true); | |
} else { | |
obj.set("playersedit_bar1",false); | |
obj.set("showplayers_bar1",false); | |
} | |
} | |
// For each inventory ... | |
for(i7 = 0; i7 < inv.length; i7++) { | |
var q = inv[i7].owner - 1, r = inv[i7].inv_gmnotes; | |
// ... that contains this item object ... | |
if (GIM.isInside(obj, inv[i7]) == true && r.indexOf("ignore") == -1) { | |
// ... do these things: | |
// If the item's containing inventory is hidden, hide the item ... | |
if(inv[i7].layer == "gmlayer" && obj.get("layer") != "gmlayer") { | |
obj.set("layer","gmlayer") | |
// ... or unhide it otherwise. | |
} else if (inv[i7].type == "sub" && inv[i7].inv_gmnotes != "drop" && inv[i7].layer == "objects" && obj.get("layer") != "objects" || inv[i7].layer == "map") { | |
obj.set("layer","objects"); | |
} | |
// If item is on a drop inventory, put it on the map layer | |
if(inv[i7].inv_gmnotes == "drop") { | |
obj.set("layer","map"); | |
} | |
// If item is not stowable, prevent stowing as such | |
if (r.indexOf("inv") !== -1 && r.indexOf("worn") == -1 && s.indexOf("unstowable") !== -1) { | |
obj.set("top",inv[i7].bottom + 35); | |
} else { | |
// This will exclude items that are hidden or dropped. | |
if(obj.get("layer") == "objects") { | |
// If the item is a pile of coins ... | |
if(s.indexOf("coins") !== -1) { | |
// ... adjust the weight and volume ... | |
obj.set("bar1_value",Math.round(parseFloat(obj.get("bar3_value")) * GIM.coin.wgt * 100000) / 100000); | |
obj.set("bar2_value",Math.round(parseFloat(obj.get("bar3_value")) * GIM.coin.vol * 100000) / 100000); | |
// ... and let its name show the total | |
if(s.indexOf("copper") !== -1) { | |
obj.set("name","Cp: " + obj.get("bar3_value")); | |
} | |
if(s.indexOf("silver") !== -1) { | |
obj.set("name","Sp: " + obj.get("bar3_value")); | |
} | |
if(s.indexOf("gold") !== -1) { | |
obj.set("name","Gp: " + obj.get("bar3_value")); | |
} | |
if(s.indexOf("electrum") !== -1) { | |
obj.set("name","Ep: " + obj.get("bar3_value")); | |
} | |
if(s.indexOf("platinum") !== -1) { | |
obj.set("name","Pp: " + obj.get("bar3_value")); | |
} | |
} | |
// If the item has a non-changing base weight (empty bottles) ... | |
if (s.indexOf("weight") !== -1) { | |
var weight_array = s.split("%20"), weight_loc = weight_array.indexOf("weight") + 1; | |
// ... add the weight to its containing inventories | |
inv[i7].weight += parseFloat(weight_array[weight_loc]); | |
} | |
// Add weights and volumes of each item to its containing inventories | |
inv[i7].weight += parseFloat(obj.get("bar1_value")); | |
inv[i7].volume += parseFloat(obj.get("bar2_value")); | |
// Calculate how warm a player is based on what he or she is wearing | |
if (inv[i7].inv_gmnotes == 'worn') { | |
if (s.indexOf("warmth") !== -1) { | |
warmth_array = s.split("%20"); | |
warmth_loc = warmth_array.indexOf("warmth") + 1; | |
warmth[q] += parseInt(warmth_array[warmth_loc]); | |
} | |
// Create new inventory boxes if an inv item is equipped for the first time | |
for (k = 0; k < GIM.storageItems.length; k++) { | |
if (s.indexOf(GIM.storageItems[k].name) !== -1) { | |
GIM.objsToBeCreated[GIM.objsToBeCreated.length] = [ | |
obj.get("_pageid"), | |
GIM.storageItems[k].name, | |
obj.get("left"), | |
obj.get("top"), | |
obj.get("_id"), | |
GIM.storageItems[k].max_wgt, | |
GIM.storageItems[k].max_vol, | |
]; | |
obj.set("gmnotes", s.replace(GIM.storageItems[k].name,"storage_" + obj.get("_id"))); | |
} | |
} | |
// Log any worn "storage_" items into an array. | |
if (s.indexOf("storage_" + obj.get("_id")) !== -1) { | |
equipped[q][(equipped[q]).length] = "rep_" + obj.get("_id"); | |
} | |
} | |
// Give the proper player control of that item | |
if(inv[i7].type == "main") { | |
for(j = 1; j < GIM.playerList.length + 1; j++) { | |
if (inv[i7].owner == j) { | |
obj.set("controlledby",GIM.playerList[j - 1]) | |
} | |
} | |
// If the item gives hospitality, reflect as such | |
if (s.indexOf("hosp") !== -1) { | |
hosp[q]++; | |
} | |
} | |
} | |
} | |
} | |
} | |
}); | |
// Calculate average hospitality | |
for(i8 = 0; i8 < hosp.length; i8++) { | |
hosp_average += hosp[i8]; | |
} | |
Math.floor(hosp_average /= GIM.playerList.length); | |
/***************************/ | |
/***** STEP 4 out of 4 *****/ | |
/***************************/ | |
_.each(objects, function(obj) { | |
s = obj.get("gmnotes"); | |
stacks = 1; | |
for (i9 = 0; i9 < items.length; i9++) { | |
if (obj.get("left") == items[i9].left && obj.get("top") == items[i9].top && obj.get("_id") != items[i9].id && GIM.isObj(obj,"item") == true) { | |
stacks++; | |
} | |
} | |
if (stacks == 1) { | |
obj.set({ | |
status_blue: false, | |
status_red: false | |
}); | |
} else if (stacks < 10) { | |
obj.set({ | |
status_red: false, | |
status_blue: stacks | |
}); | |
} else if (stacks < 100) { | |
var tens = Math.floor(stacks / 10); | |
obj.set({ | |
status_blue: stacks - (tens * 10), | |
status_red: tens | |
}); | |
} | |
// Make sure "unequipped" inventories are hidden. | |
for (i10 = 0; i10 < inv.length; i10++) { | |
var q = inv[i10].owner - 1; | |
is_it_equipped = false; | |
if (inv[i10].id == obj.get("_id")) { | |
if (s.indexOf("rep") !== -1) { | |
item_owner = inv[i10].owner - 1; | |
for (j = 0; j < equipped[item_owner].length; j++){ | |
if (s.indexOf(equipped[item_owner][j]) !== -1) { | |
is_it_equipped = true; | |
} | |
} | |
if (is_it_equipped == true) { | |
if (s.indexOf("ignore") !== -1) { | |
obj.set("layer","map"); | |
} else { | |
obj.set("layer","objects"); | |
} | |
if (GIM.extraRun == true) { | |
} else { | |
GIM.extraRun = true; | |
} | |
} else if (is_it_equipped == false) { | |
obj.set("layer","gmlayer"); | |
if (GIM.extraRun == true) { | |
} else { | |
GIM.extraRun = true; | |
} | |
} | |
} | |
// Now we apply values to bar1 and bar2 of each inventory. | |
obj.set("bar1_value", Math.round(inv[i10].weight * 1000) / 1000); | |
obj.set("bar2_value", Math.round(inv[i10].volume * 1000) / 1000); | |
if (obj.get("bar1_value") > obj.get("bar1_max") && obj.get("bar1_max") > 0) { | |
obj.set({ | |
status_dead: true | |
}); | |
} else if (obj.get("bar2_value") > obj.get("bar2_max") && obj.get("bar2_max") > 0) { | |
obj.set({ | |
status_dead: true | |
}); | |
} else { | |
obj.set({ | |
status_dead: false | |
}); | |
} | |
} | |
// Set status token values | |
if (inv[i10].type == 'main' && obj.get("bar3_value") == inv[i10].owner) { | |
if (obj.get("gmnotes") == "status") { | |
obj.set("bar1_value", Math.round(inv[i10].weight * 10) / 10); | |
obj.set("bar2_value", Math.round(inv[i10].volume * 10) / 10); | |
obj.set("name",'Weight: ' + obj.get("bar1_value") + " | Profile: " + obj.get("bar2_value")); | |
} else if (obj.get("gmnotes") == "status2") { | |
// Temperature values are changed per user preference | |
if (GIM.temperatureUnit == "F") { | |
obj.set("bar1_value", warmth[q] * 10); | |
} else if (GIM.temperatureUnit == "C") { | |
obj.set("bar1_value", Math.floor(((warmth[q] * 10 - 32) * (5 / 9)))); | |
} | |
obj.set("bar2_value", hosp[q]); | |
obj.set("name",'Warmth: ' + obj.get("bar1_value") + "°" + GIM.temperatureUnit + " | Hosp: " + obj.get("bar2_value") + " (" + hosp_average + ")"); | |
} | |
} | |
} | |
}); | |
GIM.runTimeout = GIM.runTimeout + 3; | |
}; | |
function create_inv(g_page_id, g_name, g_left, g_top, g_id, g_wgt, g_vol) { | |
setTimeout(function(){ | |
toBack(fixedCreateObj("graphic",{ | |
name: g_name, | |
imgsrc: GIM.invImg, | |
pageid: g_page_id, | |
left: g_left + 350, | |
top: g_top, | |
width: 70, | |
height: 70, | |
bar1_value: 0, | |
bar1_max: g_wgt, | |
bar2_value: 0, | |
bar2_max: g_vol, | |
layer: "objects", | |
gmnotes: "inv rep_" + g_id | |
})); | |
},5); | |
} | |
on("ready",function(){ | |
if (GIM.logPlayerIds == true) { | |
var players = filterObjs(function(obj) { | |
if (obj.get("type") == "player") return true; | |
else return false; | |
}); | |
log('************* PLAYER IDs *************'); | |
_.each(players, function(obj) { | |
log(obj.get("_displayname") + ": " + obj.get("_id")); | |
}); | |
log('**************************************'); | |
} | |
setInterval(function(){GIM.runMe()},500); | |
on("change:graphic:lastmove",function(obj){ | |
GIM.runTimeout = 2; | |
obj.set({ | |
statusmarkers: "!" | |
}); | |
}); | |
on("add:graphic",function(obj){ | |
GIM.isNewGraphic = true; | |
obj.set("width",70); | |
obj.set("height",70); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment