Priest Example Script - lordachoo/adventureland GitHub Wiki

Priest Example Code Description

  • Has attack_mode default crap, move_mode, curseMode and partyHealMode
    • Move mode will force bot to be stationary so they don't go wandering off
    • curseMode enables cursing or not to consume mana - May need to turn this off if group is taking more damage than we can heal and we need more mana
    • partyHealMode enables partyheal spell casting on or off
    • debug toggles console.log messages
  • Basic potion function use_potions() - set potionHealAmount and potionManaAmount so extra potion capacity isn't wasted.
  • Basic functionality: set healAmount for how much hp a (partied) character should be missing before bothering to heal them - Every tick the priest will search party members for heal targets and heal
  • The curseMode, partyHealMode` functions can be toggled to fit the encounters needs.
  • Has the party code for LordAchoo, LordAsneeze, LordApriest to always create/maintain group

Code

var attack_mode=true
var move_mode=false
var partyHealMode=false
var curseMode=true
var debug=true

async function use_potions() {
	var potionHealAmount=200
	var potionManaAmount=300
if (character.hp < character.max_hp - potionHealAmount || character.mp < character.max_mp - potionManaAmount) {
				set_message("Using Potion");
                use_hp_or_mp();
            }   
}

/*
* Priest Heal Party Code
*/
function ms_to_next_skill(skill) {
    const next_skill = parent.next_skill[skill]
    if (next_skill == undefined) return 0
    const ms = parent.next_skill[skill].getTime() - Date.now() - Math.min(...parent.pings) + 15
    return ms < 0 ? 0 : ms
}

async function healParty() {
	var healAmount=400 // Threshold for how low character.hp is before healing
	if (character.party) {
		set_message("Init HP");
        for (let char_name in get_party()) {
            let party_member = get_entity(char_name); // changed parent.entities
            if(party_member == null) {
                if(debug) console.log(char_name + " is out of render distance");
                continue;
            }
            if (party_member.hp < party_member.max_hp - healAmount) {
		    if(debug) {
            console.log("HEALING: "+char_name+","+party_member.hp+","+party_member.max_hp);
            }
                set_message("Healing");
                await heal(party_member);
                delay = ms_to_next_skill('attack');
                break;
            } else {
			set_message("No Heal Tgt");
			}
		}
	}
}

//////////////////

setInterval(function(){

	use_potions();
	loot();

	// Try to search party for 'attack heals' every iteration
	healParty();
	
	if(!attack_mode || character.rip || is_moving(character)) return;

	var target=get_targeted_monster();
	if(!target)
	{
		target=get_nearest_monster({min_xp:100,max_att:120});
		if(target) change_target(target);
		else
		{
			set_message("No Monsters");
			return;
		}
	}
	
	if(!is_in_range(target))
	{
		if(move_mode) {
			set_message("MOVING...");
		move(
			character.x+(target.x-character.x)/2,
			character.y+(target.y-character.y)/2
			);
		}
		// Walk half the distance - IF move_mode == true
	}
	else if(can_attack(target))
	{
		set_message("Attacking!");
		use_skill("curse")
		attack(target);
	}
	if(partyHealMode) {
		if(!is_on_cooldown("partyheal") && character.mp >= 400)
		{
		set_message("Party Heal!");
		use_skill("partyheal");
		}
	}
	if(curseMode) {
		if(!is_on_cooldown("curse") && character.mp >= 400)
		{
		set_message("Curse Tgt!");
		use_skill("curse");
		}
	}
},1000/4); // Loops every 1/4 seconds.

/*
* PARTY CODE
*/

var group = ["LordAchoo", "LordAsneeze", "LordApriest"];

setInterval(function () {
	if(parent.party_list.length < 3 ){
    if (character.name == group[0]) {
        for (let i = 1; i < group.length; i++) {
            let name = group[i];
            send_party_invite(name);
        }
    } else {
        if (character.party) {
            if (character.party != group[0]) {
                parent.socket.emit("party", {event: "leave"})
            }
        } else {
            send_party_request(group[0]);
            }  
        }
    }
}, 1000 * 10);

function on_party_request(name) {
    console.log("Party Request");
    if (group.indexOf(name) != -1) {
        accept_party_request(name);
    }
}
function on_party_invite(name) {
    console.log("Party Invite");
    if (group.indexOf(name) != -1) {
        accept_party_invite(name);
    }
}