Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify and clarify calculate_monster_score calculations #151

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 37 additions & 44 deletions node/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2297,59 +2297,52 @@ function monster_hunt_logic(player, monster) {
}
}

function calculate_monster_score(player, monster, share) {
var score = min(1, monster.mult * 2.2);
var divider = 1;
if (!share) {
share = 0;
}
if (monster.cooperative) {
divider = 2;
}
for (var id in players) {
var current = players[id];
if (current.id == player.id) {
continue;
function calculate_monster_score(player, monster, coopShare = 0) {
// NOTE: `.mult` is usually 1, but will be set on server shutdown to the ratio of remaining HP.
// See: shutdown_routine()
let score = Math.min(1, monster.mult * 2.2);
const divisor = monster.cooperative ? 2 : 1;

for (const id in players) {
const p = players[id];
if (p.id === player.id) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could skip the get call on id of p and just use id directly given by the for loop

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continue; // Skip ourself
}
if (current.owner == player.owner && current.type == "merchant" && simple_distance(current, player) < 600) {
score -= 0.2 / divider;

const sameOwner = p.owner === player.owner;
const sameParty = p.party && p.party === player.party;
if (!sameOwner && !sameParty) {
continue; // Not our character, and in a different party
}

const isMerchant = p.type === "merchant";
if (sameOwner && sameParty && !isMerchant) {
score += 0.3 / divisor; // +0.3 points for each additional non-merchant character of ours in our party (even if they are far away)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old lines 2330 & 2337

}

if (isMerchant && simple_distance(p, player) <= 600) {
// Nearby merchants reduce the points
if (sameOwner) {
score -= 0.2 / divisor; // Deduct points if our merchant is nearby
}
if (sameParty) {
score -= 0.1 / divisor; // Deduct points if a merchant in our party is nearby
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old line 2323

}
}
if (
current.party &&
current.party == player.party &&
current.type == "merchant" &&
simple_distance(current, player) < 600
) {
score -= 0.1 / divider;
} else if (
current.owner == player.owner &&
current.party == player.party &&
simple_distance(current, player) < 600 &&
current.type != "merchant"
) {
score += 0.3 / divider;
} else if (
current.owner == player.owner &&
current.party &&
current.party == player.party &&
current.type != "merchant"
) {
score += 0.3 / divider;
} // originally 0.25
}
if (simple_distance(player, monster) > 600 && share < 0.01) {
score -= 0.3 / divider;

if (simple_distance(player, monster) > 600 && coopShare < 0.01) {
score -= 0.3 / divisor; // Deduct points if we were far away from the kill, unless it was a coop monster and we contributed
}
if (player.type == "merchant" && player.party) {
score /= 2;
}
if (score < 0) {
score = 0;
// TODO: What if the merchant killed the monster with a golden gun? Should it not get full points then?
score /= 2; // Half points if we're a merchant in a party
}
if (gameplay == "hardcore") {
score *= 10000;
}
return score;

return Math.max(0, score);
}

function issue_monster_awards(monster) {
Expand Down