Skip to content

Commit

Permalink
Merge pull request #104 from earthiverse/range-fix
Browse files Browse the repository at this point in the history
Fix infinite range for `curse`, `cburst`, and `3shot`/`5shot`
  • Loading branch information
kaansoral authored Feb 21, 2024
2 parents 4930cd0 + 4d99e3e commit 7b19a9f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 52 deletions.
9 changes: 9 additions & 0 deletions design/skills.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@
"cooldown":60000,
"target":"monster",
"hostile":True,
"use_range":True,
},
"tangle":{
"type":"skill",
Expand All @@ -232,6 +233,8 @@
"cooldown":60000,
"target":True,
"hostile":True,
"use_range":True,
"range_multiplier":2,
},
"rspeed":{
"type":"skill",
Expand Down Expand Up @@ -606,6 +609,9 @@
"cooldown":10000,
"target":True,
"hostile":True,
"range_multiplier":3,
"range_bonus":20,
"use_range": True
},
"pcoat":{
"type":"skill",
Expand Down Expand Up @@ -644,6 +650,7 @@
"warning":"Highly unbalanced skill, could get nerfed or modified",
"hostile":True,
"projectile":"mentalburst",
"use_range":True,
},
"quickpunch":{
"type":"skill",
Expand Down Expand Up @@ -748,6 +755,7 @@
"pierces_immunity":True,
"damage_type":"physical",
"procs":True,
"use_range":True,
},
"3shot":{
"type":"skill",
Expand Down Expand Up @@ -810,6 +818,7 @@
"name":"Curse",
"explanation":"Cursed opponents receive 20% more damage, deal 20% less damage and they slow down by 20.",
"mp":400,
"range":200,
"duration":5000,
"cooldown":5000,
"condition":"cursed",
Expand Down
99 changes: 47 additions & 52 deletions node/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2886,9 +2886,6 @@ function commence_attack(attacker, target, atype) {
} else if (atype == "cburst") {
var mp_cutoff = attacker.next_mp;
var mp = attacker.next_mp;
if (atype == "cburst") {
mp = mp_cutoff = attacker.next_mp;
}
if (attacker.mp < mp_cutoff) {
attacker.socket.emit("game_response", { response: "no_mp" });
return { failed: true, reason: "no_mp", place: atype, id: target.id };
Expand Down Expand Up @@ -8259,7 +8256,8 @@ function init_io() {
}

// Range check
if (target && (gSkill.range || gSkill.use_range)) {
const isTargetTooFar = (target) => {
// Use the range of the skill, falling back to the player range if it isn't set
let range = gSkill.range || player.range;
if (gSkill.range_multiplier) {
range *= gSkill.range_multiplier;
Expand All @@ -8274,12 +8272,16 @@ function init_io() {

const dist = distance(player, target);
if (dist > range + player.xrange) {
return fail_response("too_far", data.name, { dist: dist, id: target.id });
return true;
}
if (dist > range) {
// xrange was used, reduce it by however much we used
player.xrange -= dist - range;
}
return false;
};
if (target && isTargetTooFar(target)) {
return fail_response("too_far", data.name, { dist: dist, id: target.id });
}

// Consume item check
Expand Down Expand Up @@ -8573,37 +8575,41 @@ function init_io() {
resend(target, "u+cid");
}
} else if (data.name == "cburst") {
var hit = {};
var times = 0;
var targeted = {};
var attack = null;
var c_resolve = null;
consume_mp(player, gSkill.mp);
player.first_burst = true;
player.halt = true;
if (is_array(data.targets)) {
data.targets.forEach(function (t) {
// console.log(id);
var id = t[0];
var mp = max(0, parseInt(t[1]) || 0);
if (player.mp < 20 || times > 16 || !mp) {
return;
// Only look at the first 16 targets in the array if more are provided
for (const t of data.targets.slice(0, 16)) {
const id = t[0];

// Prevent attacking the same entity twice
if (targeted[id]) {
continue;
}
times += 1;
var target = instances[player.in].monsters[id];
targeted[id] = true;

const mp = max(0, parseInt(t[1]) || 0);
if (mp <= 0) {
continue;
}
let target = instances[player.in].monsters[id];
if (!target) {
target = instances[player.in].players[id];
}
if (!target || is_invinc(target) || target.name == player.name) {
return;
continue;
}
if (hit[id]) {
return;
if (isTargetTooFar(target)) {
continue;
}
hit[id] = true;
player.next_mp = mp;
attack = commence_attack(player, target, "cburst");
if (!attack || !attack.projectile) {
return;
continue;
}
if (!c_resolve) {
c_resolve = attack;
Expand All @@ -8613,14 +8619,12 @@ function init_io() {
c_resolve.pids.push(attack.pid);
c_resolve.targets.push(attack.target);
}
});
}
}
player.halt = false;
player.to_resend = "u+cid";
if (!c_resolve) {
if (attack) {
reject = attack;
}
reject = { failed: true, place: data.name, reason: "no_target" };
disappearing_text(player.socket, player, "NO HITS");
} else {
resolve = c_resolve;
Expand Down Expand Up @@ -8662,57 +8666,48 @@ function init_io() {
xy_emit(player, "ui", { type: data.name });
} else if (data.name == "3shot" || data.name == "5shot") {
player.halt = true;
var times = 0;
var hit = {};
var reftarget = null;
var targets = 3;
var attack = null;
var c_resolve = null;
if (data.name == "5shot") {
targets = 5;
}
const targeted = {};
let c_resolve = null;
//console.log(data.ids);
if (is_array(data.ids)) {
data.ids.forEach(function (id) {
if (times >= targets) {
return;
// Only look at the first Xshot targets in the array if more are provided
for (const id of data.ids.slice(0, data.name === "5shot" ? 5 : 3)) {
// Prevent attacking the same entity twice
if (targeted[id]) {
continue;
}
times += 1;
var target = instances[player.in].monsters[id];
targeted[id] = true;

target = instances[player.in].monsters[id];
if (!target) {
target = instances[player.in].players[id];
}

if (!target || is_invinc(target) || target.name == player.name) {
attack = { failed: true, place: data.name, reason: "no_target" };
return;
continue;
}
if (hit[id]) {
return;
if (isTargetTooFar(target)) {
continue;
}
hit[id] = true;
attack = commence_attack(player, target, data.name);
const attack = commence_attack(player, target, data.name);
if (!attack || !attack.projectile) {
return;
continue;
}
if (!c_resolve) {
reftarget = target;
c_resolve = attack;
attack.pids = [attack.pid];
attack.targets = [attack.target];
} else {
c_resolve.pids.push(attack.pid);
c_resolve.targets.push(attack.target);
}
// if(times==1 && attack==null) times=40;
});
}
}
consume_mp(player, gSkill.mp, reftarget);
player.halt = false;
player.to_resend = "u+cid";
consume_mp(player, gSkill.mp, target);
if (!c_resolve) {
if (attack) {
reject = attack;
}
reject = { failed: true, place: data.name, reason: "no_target" };
disappearing_text(player.socket, player, "NO HITS");
} else {
resolve = c_resolve;
Expand Down

0 comments on commit 7b19a9f

Please sign in to comment.