-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(game): Implement /pull command * feat(game): Implement /who command * feat(game): Implement /forgetme command * fix(game): Renamed /pull command to /aggregate * feat(game): Implement /pull command * fix(game): Renamed /guild_create command to /makeguild fix(game): Renamed /guild_delete command to /deleteguild * feat(game): Implement /weak and /weaken command * feat(game): Implement /ipurge command * feat(game): Implement /reset and /r command * fix(game): disconnect would not remove logged in status * fix(single): InMemoryRedis would calculate expiry wrong * feat(game): Implement /dc command * feat(game): Implement stones spawning mobs * fix: build * fix(game): null pointer when group.txt is missing * fix: startup
- Loading branch information
Showing
27 changed files
with
446 additions
and
126 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,51 @@ | ||
namespace QuantumCore.Core.Utils | ||
namespace QuantumCore.Core.Utils; | ||
|
||
public static class MathUtils | ||
{ | ||
public static class MathUtils | ||
public static double Distance(int x1, int y1, int x2, int y2) | ||
{ | ||
var a = x1 - x2; | ||
var b = y1 - y2; | ||
|
||
return Math.Sqrt(a * a + b * b); | ||
} | ||
|
||
/// <summary> | ||
/// Returns the rotation in degrees | ||
/// </summary> | ||
public static double Rotation(double x, double y) | ||
{ | ||
var vectorLength = Math.Sqrt(x * x + y * y); | ||
|
||
var normalizedX = x / vectorLength; | ||
var normalizedY = y / vectorLength; | ||
var upVectorX = 0; | ||
var upVectorY = 1; | ||
|
||
var rotationRadians = -(Math.Atan2(normalizedY, normalizedX) - Math.Atan2(upVectorY, upVectorX)); | ||
|
||
var rotationDegress = rotationRadians * (180 / Math.PI); | ||
if (rotationDegress < 0) rotationDegress += 360; | ||
return rotationDegress; | ||
} | ||
|
||
public static int MinMax(int min, int value, int max) | ||
{ | ||
var temp = (min > value ? min : value); | ||
return (max < temp) ? max : temp; | ||
} | ||
|
||
public static (double X, double Y) GetDeltaByDegree(double degree) | ||
{ | ||
var radian = DegreeToRadian(degree); | ||
|
||
var x = Math.Sin(radian); | ||
var y = Math.Cos(radian); | ||
return (x, y); | ||
} | ||
|
||
public static double DegreeToRadian(double degree) | ||
{ | ||
public static double Distance(int x1, int y1, int x2, int y2) | ||
{ | ||
var a = x1 - x2; | ||
var b = y1 - y2; | ||
|
||
return Math.Sqrt(a * a + b * b); | ||
} | ||
|
||
public static double Rotation(double x, double y) | ||
{ | ||
var vectorLength = Math.Sqrt(x * x + y * y); | ||
|
||
var normalizedX = x / vectorLength; | ||
var normalizedY = y / vectorLength; | ||
var upVectorX = 0; | ||
var upVectorY = 1; | ||
|
||
var rotationRadians = -(Math.Atan2(normalizedY, normalizedX) - Math.Atan2(upVectorY, upVectorX)); | ||
|
||
var rotationDegress = rotationRadians * (180 / Math.PI); | ||
if (rotationDegress < 0) rotationDegress += 360; | ||
return rotationDegress; | ||
} | ||
|
||
public static int MinMax(int min, int value, int max) | ||
{ | ||
var temp = (min > value ? min : value); | ||
return (max < temp) ? max : temp; | ||
} | ||
return degree * Math.PI / 180.0; | ||
} | ||
} |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using QuantumCore.API.Game; | ||
using QuantumCore.Game.World.Entities; | ||
|
||
namespace QuantumCore.Game.Commands; | ||
|
||
[Command("aggregate", "Triggers all monsters around you to be aggro and target you")] | ||
public class AggregateCommand : ICommandHandler | ||
{ | ||
public Task ExecuteAsync(CommandContext context) | ||
{ | ||
context.Player.ForEachNearbyEntity(e => | ||
{ | ||
if (e is not MonsterEntity) return; | ||
e.Target = context.Player; | ||
}); | ||
return Task.CompletedTask; | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using QuantumCore.API.Game; | ||
using QuantumCore.Game.World.Entities; | ||
|
||
namespace QuantumCore.Game.Commands; | ||
|
||
[Command("forgetme", "Clears aggro from all monsters targeting you")] | ||
public class ForgetMeCommand : ICommandHandler | ||
{ | ||
public Task ExecuteAsync(CommandContext context) | ||
{ | ||
context.Player.ForEachNearbyEntity(e => | ||
{ | ||
if (e is MonsterEntity mob && mob.Target == context.Player) | ||
{ | ||
mob.Target = null; | ||
} | ||
}); | ||
return Task.CompletedTask; | ||
} | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Numerics; | ||
using QuantumCore.API.Game; | ||
using QuantumCore.API.Game.World; | ||
using QuantumCore.Core.Utils; | ||
|
||
namespace QuantumCore.Game.Commands; | ||
|
||
[Command("pull", "All monsters in range will quickly move towards you")] | ||
[Command("pull_monster", "All monsters in range will quickly move towards you")] | ||
public class PullCommand : ICommandHandler | ||
{ | ||
public Task ExecuteAsync(CommandContext context) | ||
{ | ||
const int maxDistance = 3000; | ||
const int minDistance = 100; | ||
var p = context.Player; | ||
context.Player.ForEachNearbyEntity(e => | ||
{ | ||
if (e.Type == EEntityType.Monster) | ||
{ | ||
var dist = Vector2.Distance(new Vector2(p.PositionX, p.PositionY), | ||
new Vector2(e.PositionX, e.PositionY)); | ||
if (dist is > maxDistance or < minDistance) | ||
return; | ||
|
||
var degree = MathUtils.Rotation(p.PositionX - e.PositionX, p.PositionY - e.PositionY); | ||
|
||
var pos = MathUtils.GetDeltaByDegree(degree); | ||
var targetX = p.PositionX + pos.X + dist; | ||
var targetY = p.PositionY + pos.Y + dist; | ||
// not correct - moves to the wrong side of the player | ||
// sadly my math skills are too low to implement it correctly | ||
// good enough for now | ||
e.Goto((int)targetX, (int)targetY); | ||
} | ||
}); | ||
return Task.CompletedTask; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using QuantumCore.API.Game; | ||
|
||
namespace QuantumCore.Game.Commands; | ||
|
||
[Command("r", "Resets the players hp + sp to their max")] | ||
[Command("reset", "Resets the players hp + sp to their max")] | ||
public class ResetCommand : ICommandHandler | ||
{ | ||
public Task ExecuteAsync(CommandContext context) | ||
{ | ||
context.Player.Health = context.Player.Player.MaxHp; | ||
context.Player.Mana = context.Player.Player.MaxSp; | ||
context.Player.SendPoints(); | ||
|
||
return Task.CompletedTask; | ||
} | ||
} |
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
Oops, something went wrong.