Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function schedulePartyBuff() {
- var habId = "id";
- var habToken = "token";
- var threshold = 200; // when your mana is more than this number, it will buff your party until this number is reached again
- var sleepTime = 30000; // pause in the loop for 30000 milliseconds (30 seconds); this is to avoid the servers being overloaded
- var paramsTemplateGet = {
- "method" : "get",
- "headers" : {
- "x-api-user" : habId,
- "x-api-key" : habToken
- }
- }
- // get class and type of buff
- var response = UrlFetchApp.fetch("https://habitica.com/api/v3/user?userFields=flags.classSelected,stats", paramsTemplateGet);
- response = JSON.parse(response);
- if (response.data.flags.classSelected && response.data.stats.mp > threshold) {
- var skillId;
- var cost;
- switch(response.data.stats.class) {
- case "warrior":
- skillId = "valorousPresence"; // STR option
- cost = 20;
- // skillId = "intimidate"; // CON option
- // cost = 15;
- break;
- case "rogue":
- skillId = "toolsOfTrade" // PER
- cost = 25;
- break;
- case "wizard":
- skillId = "earth";
- cost = 35;
- break;
- case "healer":
- if (response.data.stats.hp < 20) {
- skillId = "healAll";
- } else {
- skillId = "protectAura"; // CON
- }
- cost = 30;
- }
- // a Google script may not take more time than 6 minutes (360000 milliseconds), so we need to limit the maximum amount of buffs, or else you'll get errors
- var maxBuffs = (360000 / sleepTime) - 1;
- var buffs = Math.trunc((response.data.stats.mp - threshold) / cost);
- if (buffs > maxBuffs) {
- buffs = maxBuffs;
- }
- var url = "https://habitica.com/api/v3/user/class/cast/" + skillId
- var paramsTemplate = {
- "method" : "post",
- "headers" : {
- "x-api-user" : habId,
- "x-api-key" : habToken
- }
- }
- var params = paramsTemplate;
- for (var i = 0; i < buffs; i++) {
- UrlFetchApp.fetch(url, params)
- Utilities.sleep(sleepTime);
- // for healers: switch from healing to buffing after a few heals (default: set to 3 for 4 heals)
- if (skillId == "healAll" && i == 3) { skillId = "protectAura"; }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement