Created
November 3, 2016 12:27
-
-
Save Kattoor/c8a4bd6f5cc19c9094adedd1984c2124 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
function getTarget() { | |
let entityValues = Object.values(parent.entities); | |
let greenWorms = entityValues.filter(entity => entity.mtype === 'worm'); | |
let redWorms = entityValues.filter(entity => entity.mtype === 'osnake'); | |
let target; | |
if (redWorms.length > 0) | |
target = findClosest(redWorms); | |
else | |
target = findClosest(greenWorms); | |
return target; | |
} | |
function findClosest(entities) { | |
let closestEntity, closestEntityDistance | |
entities.forEach(entity => { | |
let distance = Math.sqrt( | |
Math.abs(entity.real_x - character.real_x) + | |
Math.abs(entity.real_y - character.real_y) | |
); | |
if (!closestEntity || distance < closestEntityDistance) { | |
closestEntity = entity; | |
closestEntityDistance = distance; | |
} | |
}); | |
game_log(closestEntityDistance); | |
return closestEntity; | |
} | |
setInterval(() => { | |
loot(); | |
let hPots1 = character.items.filter(item => item && item.name === 'hpot0')[0]; | |
let hPots2 = character.items.filter(item => item && item.name === 'hpot1')[0]; | |
let mPots1 = character.items.filter(item => item && item.name === 'mpot0')[0]; | |
let mPots2 = character.items.filter(item => item && item.name === 'mpot1')[0]; | |
if ((!hPots1 && !hPots2) || ((hPots1 ? hPots1.q : 0) + (hPots2 ? hPots2.q : 0) < 25)) | |
parent.socket.emit("buy", {name:"hpot1", quantity: 25}); | |
if ((!mPots1 && !mPots2) || ((mPots1 ? mPots1.q : 0) + (mPots2 ? mPots2.q : 0) < 25)) | |
parent.socket.emit("buy", {name:"mpot1", quantity: 25}); | |
if (charater.hp <= 800) | |
parent.use('hp'); | |
if (character.mp <= 250) | |
parent.use('mp'); | |
let target = get_targeted_monster(); | |
if (!target) { | |
target = getTarget(); | |
if (!target) return; | |
change_target(target); | |
} | |
if (!in_attack_range(target)) | |
move(character.real_x + (target.real_x - character.real_x) / 2, character.real_y + (target.real_y - character.real_y) / 2); | |
if (can_attack(target)) | |
attack(target); | |
}, 50); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment