Compare commits

...

15 Commits

Author SHA1 Message Date
Preston 962bebab6c Adjusted the distance check for players in player's path, effectively making the collision area of players larger. This can be changed in Bounds PlayerCollisionPoint method by increasing or decreasing the minDistance var. 2024-09-24 21:36:12 -05:00
Preston a67fee76c3 Redone player collision by removing all refrences and usage of Bounds in PlayerCharacter.java. Added a new method PlayerCollisionPoint in Bounds.java mirroring PlayerBuildingCollisionPoint for other players instead of buildings. Added a new check in movement mirrioring the check for buildings but for players to ensure that PlayerCollisionPoint is called in each movement. 2024-09-23 23:43:48 -05:00
Preston Driver d22ff916bf Merge branch 'playercollision-1' of http://repo.magicbane.com/Preston/prestonbane into playercollision-1 2024-09-20 12:39:25 -05:00
Preston Driver 2d1da7679e Added functionality to handlePlayerCollision method in PlayerCharacter.java to actively prevent players from standing in each other. 2024-09-20 12:38:37 -05:00
Preston Driver 549a381174 Updated .gitignore. 2024-09-18 22:55:36 -05:00
Preston Driver 43563aeb14 Updated dependencies since it appears that old build failed to. 2024-09-18 22:50:18 -05:00
Preston Driver 7a4c2fe72a Attempt to push to docker container. 2024-09-17 20:52:47 -05:00
Preston Driver 24cc6af147 Added player collision with other players in PlayerCharacter class. 2024-09-16 23:06:07 -05:00
MagicBot 3649c629b7 Revert "DamageType defined as in JSON"
This reverts commit 1c31070fc8.
2024-04-01 12:04:12 -04:00
MagicBot 1c31070fc8 DamageType defined as in JSON 2024-04-01 12:01:59 -04:00
MagicBot bff41967db Revert "Out of combat mode when patrolling."
This reverts commit d3692d0fb7.
2023-09-08 13:07:15 -04:00
MagicBot d3692d0fb7 Out of combat mode when patrolling. 2023-09-08 13:04:29 -04:00
FatBoy 074a799d01 added health recovery to mobs 2023-08-22 20:58:52 -05:00
FatBoy 36ffd08a72 guard minions logic work 2023-08-22 20:52:45 -05:00
FatBoy 58f828b3cd items removed properly from inventory, NPCs nop longer stock base items 2023-08-22 20:52:26 -05:00
5 changed files with 82 additions and 45 deletions
+5
View File
@@ -24,3 +24,8 @@
hs_err_pid*
replay_pid*
*.idea/
Server.iml
*.gitignore
prestonbane.iml
qodana.yaml
+11 -1
View File
@@ -88,7 +88,7 @@ public enum MovementManager {
// if (msg.getEndLat() < 0)
// msg.setEndLat(0);
//
//
// if (msg.getEndLon() > 0)
// msg.setEndLon(0);
@@ -216,6 +216,16 @@ public enum MovementManager {
}
if (toMove.getObjectType().equals(GameObjectType.PlayerCharacter)) {
Vector3fImmutable playerCollidePoint = Bounds.PlayerCollisionPoint((PlayerCharacter) toMove, toMove.getLoc(), endLocation);
if (playerCollidePoint != null) {
msg.setEndCoord(playerCollidePoint);
endLocation = playerCollidePoint;
collide = true;
}
}
if (toMove.getObjectType() == GameObjectType.PlayerCharacter && ((PlayerCharacter) toMove).isTeleportMode()) {
toMove.teleport(endLocation);
return;
+40 -1
View File
@@ -81,7 +81,7 @@ public class Bounds {
Bounds identityBounds = Bounds.borrow();
identityBounds.setBounds(location);
collisionState = collide(targetBounds, identityBounds, 0.0f);
collisionState = collide(targetBounds, identityBounds, 0.1f);
identityBounds.release();
return collisionState;
}
@@ -267,6 +267,45 @@ public class Bounds {
return collidePoint;
}
public static Vector3fImmutable PlayerCollisionPoint(PlayerCharacter player, Vector3fImmutable start, Vector3fImmutable end) {
Vector3fImmutable collidePoint = null;
float distance = player.getLoc().distance2D(end);
// Check for building collisions first
collidePoint = PlayerBuildingCollisionPoint(player, start, end);
if (collidePoint != null) {
return collidePoint;
}
// Now check for player collisions
HashSet<AbstractWorldObject> nearbyPlayers = WorldGrid.getObjectsInRangePartial(player, distance + 2, MBServerStatics.MASK_PLAYER);
float minDistance = 5.0f; // Minimum distance between players
for (AbstractWorldObject awo : nearbyPlayers) {
PlayerCharacter otherPlayer = (PlayerCharacter) awo;
if (otherPlayer == player) continue;
Vector3fImmutable otherLoc = otherPlayer.getLoc();
Vector3fImmutable closestPoint = getClosestPointOnLine(start, end, otherLoc);
if (closestPoint.distance2D(otherLoc) < minDistance) {
// Collision detected, adjust end point
Vector3fImmutable pushVector = closestPoint.subtract(otherLoc).normalize();
collidePoint = closestPoint.add(pushVector.scaleAdd(minDistance, Vector3fImmutable.ZERO));
break;
}
}
return collidePoint != null ? collidePoint : end;
}
private static Vector3fImmutable getClosestPointOnLine(Vector3fImmutable lineStart, Vector3fImmutable lineEnd, Vector3fImmutable point) {
Vector3fImmutable line = lineEnd.subtract(lineStart);
float t = point.subtract(lineStart).dot(line) / line.dot(line);
t = Math.max(0, Math.min(1, t));
return lineStart.add(line.scaleAdd(t, Vector3fImmutable.ZERO));
}
public static boolean linesTouching(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) {
float denominator = ((x2 - x1) * (y4 - y3)) - ((y2 - y1) * (x4 - x3));
float numerator1 = ((y1 - y3) * (x4 - x3)) - ((x1 - x3) * (y4 - y3));
+25 -36
View File
@@ -693,6 +693,8 @@ public class MobAI {
DefaultLogic(mob);
break;
}
if(mob.isAlive())
RecoverHealth(mob);
} catch (Exception e) {
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: DetermineAction" + " " + e.getMessage());
}
@@ -808,7 +810,7 @@ public class MobAI {
chaseTarget(mob);
break;
case GuardMinion:
if (!mob.npcOwner.isAlive() || ((Mob) mob.npcOwner).despawned)
if (!mob.npcOwner.isAlive() && mob.getCombatTarget() == null)
randomGuardPatrolPoint(mob);
else {
if (mob.getCombatTarget() != null) {
@@ -827,6 +829,7 @@ public class MobAI {
chaseTarget(mob);
}
break;
}
} catch (Exception e) {
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: CheckMobMovement" + " " + e.getMessage());
@@ -1043,7 +1046,6 @@ public class MobAI {
mob.setCombatTarget(newTarget);
}
CheckMobMovement(mob);
CheckForAttack(mob);
} catch (Exception e) {
@@ -1054,24 +1056,9 @@ public class MobAI {
public static void GuardMinionLogic(Mob mob) {
try {
if (!mob.npcOwner.isAlive()) {
if (mob.getCombatTarget() == null) {
CheckForPlayerGuardAggro(mob);
} else {
AbstractWorldObject newTarget = ChangeTargetFromHateValue(mob);
if (newTarget != null) {
if (newTarget.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) {
if (GuardCanAggro(mob, (PlayerCharacter) newTarget))
mob.setCombatTarget(newTarget);
} else
mob.setCombatTarget(newTarget);
}
}
boolean isComanded = mob.npcOwner.isAlive();
if (!isComanded) {
GuardCaptainLogic(mob);
}else {
if (mob.npcOwner.getCombatTarget() != null)
mob.setCombatTarget(mob.npcOwner.getCombatTarget());
@@ -1110,22 +1097,6 @@ public class MobAI {
CheckMobMovement(mob);
CheckForAttack(mob);
//recover health
if (mob.getTimestamps().containsKey("HEALTHRECOVERED") == false)
mob.getTimestamps().put("HEALTHRECOVERED", System.currentTimeMillis());
if (mob.isSit() && mob.getTimeStamp("HEALTHRECOVERED") < System.currentTimeMillis() + 3000)
if (mob.getHealth() < mob.getHealthMax()) {
float recoveredHealth = mob.getHealthMax() * ((1 + mob.getBonuses().getFloatPercentAll(Enum.ModType.HealthRecoverRate, Enum.SourceType.None)) * 0.01f);
mob.setHealth(mob.getHealth() + recoveredHealth);
mob.getTimestamps().put("HEALTHRECOVERED", System.currentTimeMillis());
if (mob.getHealth() > mob.getHealthMax())
mob.setHealth(mob.getHealthMax());
}
} catch (Exception e) {
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: PetLogic" + " " + e.getMessage());
}
@@ -1379,4 +1350,22 @@ public class MobAI {
}
return null;
}
public static void RecoverHealth(Mob mob){
//recover health
if (mob.getTimestamps().containsKey("HEALTHRECOVERED") == false)
mob.getTimestamps().put("HEALTHRECOVERED", System.currentTimeMillis());
if (mob.isSit() && mob.getTimeStamp("HEALTHRECOVERED") < System.currentTimeMillis() + 3000)
if (mob.getHealth() < mob.getHealthMax()) {
float recoveredHealth = mob.getHealthMax() * ((1 + mob.getBonuses().getFloatPercentAll(Enum.ModType.HealthRecoverRate, Enum.SourceType.None)) * 0.01f);
mob.setHealth(mob.getHealth() + recoveredHealth);
mob.getTimestamps().put("HEALTHRECOVERED", System.currentTimeMillis());
if (mob.getHealth() > mob.getHealthMax())
mob.setHealth(mob.getHealthMax());
}
}
}
+1 -7
View File
@@ -26,7 +26,6 @@ import engine.job.JobScheduler;
import engine.jobs.DeferredPowerJob;
import engine.jobs.FinishSpireEffectJob;
import engine.jobs.NoTimeJob;
import engine.math.Bounds;
import engine.math.FastMath;
import engine.math.Vector3fImmutable;
import engine.net.ByteBufferWriter;
@@ -269,9 +268,6 @@ public class PlayerCharacter extends AbstractCharacter {
this.hash = rs.getString("hash");
// For debugging skills
// CharacterSkill.printSkills(this);
}
public static Building getUpdatedBindBuilding(PlayerCharacter player) {
@@ -4565,9 +4561,6 @@ public class PlayerCharacter extends AbstractCharacter {
this.charItemManager = new CharacterItemManager(this);
Bounds playerBounds = Bounds.borrow();
playerBounds.setBounds(this.getLoc());
this.setBounds(playerBounds);
}
@Override
@@ -5363,6 +5356,7 @@ public class PlayerCharacter extends AbstractCharacter {
moveToMsg.setSourceType(GameObjectType.PlayerCharacter.ordinal());
moveToMsg.setSourceID(this.getObjectUUID());
Dispatch dispatch = Dispatch.borrow(this, moveToMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);