Skip to content

Instantly share code, notes, and snippets.

@tehsausage
Last active March 28, 2022 09:00
Show Gist options
  • Save tehsausage/bd5c74e7e01f3ef3c14a8f9f1477cd19 to your computer and use it in GitHub Desktop.
Save tehsausage/bd5c74e7e01f3ef3c14a8f9f1477cd19 to your computer and use it in GitHub Desktop.
diff --git a/src/map.cpp b/src/map.cpp
index 6b05380..7cff42f 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -1495,18 +1495,67 @@ void Map::Attack(Character *from, Direction direction)
break;
}
+ // 0 = 1x1
+ // 1 = 3x3
+ // 2 = 5x5
+ // etc...
+ int aoe_range = 1;
+
+ auto in_aoe_range = [&](int x, int y)
+ {
+ int tx = target_x;
+ int ty = target_y;
+
+ // Calculate melee AoEs around the player instead of in front of the player
+ if (range == 1 && aoe_range > 0)
+ {
+ tx = from->x;
+ ty = from->y;
+ }
+
+ // Diamond / cross-shaped AoE patterns
+ //return util::path_length(npc->x, npc->y, ty, ty) <= aoe_range;
+
+ // Square shaped AoE patterns
+ return std::abs(x - tx) <= aoe_range && std::abs(y - ty) <= aoe_range;
+ };
+
+ std::list<NPC*> targets;
+
UTIL_FOREACH(this->npcs, npc)
{
if ((npc->ENF().type == ENF::Passive || npc->ENF().type == ENF::Aggressive || from->SourceDutyAccess() >= static_cast<int>(this->world->admin_config["killnpc"]))
- && npc->alive && npc->x == target_x && npc->y == target_y)
+ && npc->alive && in_aoe_range(npc->x, npc->y))
+ {
+ targets.push_back(npc);
+ }
+ }
+
+ if (!targets.empty())
+ {
+ UTIL_FOREACH(targets, npc)
{
int amount = util::rand(from->mindam, from->maxdam);
double rand = util::rand(0.0, 1.0);
// Checks if target is facing you
- bool critical = std::abs(int(npc->direction) - from->direction) != 2 || rand < static_cast<double>(this->world->config["CriticalRate"]);
+ bool critical = false;
+
+ bool primary_target = (npc->x == target_x && npc->y == target_y);
+
+ // Limit positional critical damage to primary target
+ if (primary_target)
+ {
+ if (std::abs(int(npc->direction) - from->direction) != 2)
+ critical = true;
+
+ if (this->world->config["CriticalFirstHit"] && npc->hp == npc->ENF().hp)
+ critical = true;
+ }
- if (this->world->config["CriticalFirstHit"] && npc->hp == npc->ENF().hp)
+ if (rand < static_cast<double>(this->world->config["CriticalRate"]))
+ {
critical = true;
+ }
std::unordered_map<std::string, double> formula_vars;
@@ -1535,9 +1584,10 @@ void Map::Attack(Character *from, Direction direction)
npc->Damage(from, amount);
// *npc may not be valid here
-
- return;
}
+
+ // Skip this return and ranged weapons will laser through monsters
+ return;
}
if (!this->Walkable(target_x, target_y, true))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment