Compare commits

..

2 Commits

Author SHA1 Message Date
Preston b944847b8a Added fear mechanic. 2025-08-17 17:14:17 -05:00
Preston cdf6465f60 Add initial workspace configuration file. Add fear mechanic. 2025-08-17 17:06:10 -05:00
16 changed files with 199 additions and 60 deletions
+2 -5
View File
@@ -24,8 +24,5 @@
hs_err_pid*
replay_pid*
*.idea/
Server.iml
*.gitignore
prestonbane.iml
qodana.yaml
*.code-workspace
+1
View File
@@ -1196,6 +1196,7 @@ public class Enum {
Durability,
ExclusiveDamageCap,
Fade,
Fear,
Fly,
Health,
HealthFull,
@@ -280,6 +280,9 @@ public class dbEffectsBaseHandler extends dbHandlerBase {
case Stunned:
abstractEffectModifier = new StunnedEffectModifier(rs);
break;
case Fear:
abstractEffectModifier = new FearEffectModifier(rs);
break;
case Value:
abstractEffectModifier = new ValueEffectModifier(rs);
if (effectBase != null) {
@@ -433,6 +433,11 @@ public enum CombatManager {
if (bonus != null && bonus.getBool(ModType.Stunned, SourceType.None))
attackFailure = true;
//see if attacker is feared. If so, stop here
if (bonus != null && bonus.getBool(ModType.Fear, SourceType.None))
attackFailure = true;
//Get Range of weapon
float range;
+10 -11
View File
@@ -79,6 +79,11 @@ public enum MovementManager {
return;
}
// Will this prevent movement at all or only player input for movement?
if (toMove.getBonuses().getBool(ModType.Fear, SourceType.None)) {
return;
}
if (msg.getEndLat() > MBServerStatics.MAX_WORLD_WIDTH)
msg.setEndLat((float) MBServerStatics.MAX_WORLD_WIDTH);
@@ -88,7 +93,7 @@ public enum MovementManager {
// if (msg.getEndLat() < 0)
// msg.setEndLat(0);
//
//
// if (msg.getEndLon() > 0)
// msg.setEndLon(0);
@@ -216,16 +221,6 @@ 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;
@@ -417,6 +412,10 @@ public enum MovementManager {
PlayerBonuses bonus = member.getBonuses();
if (bonus.getBool(ModType.Stunned, SourceType.None) || bonus.getBool(ModType.CannotMove, SourceType.None))
continue;
//don't move if player is feared
if (bonus.getBool(ModType.Fear, SourceType.None))
continue;
member.update();
+18
View File
@@ -313,6 +313,9 @@ public enum PowersManager {
if (bonus != null && (bonus.getBool(ModType.Stunned, SourceType.None) || bonus.getBool(ModType.CannotCast, SourceType.None) || bonus.getBool(ModType.BlockedPowerType, sourceType)))
return true;
if (bonus != null && bonus.getBool(ModType.Fear, SourceType.None))
return true;
// if moving make sure spell valid for movement
Vector3fImmutable endLoc = playerCharacter.getEndLoc();
@@ -595,6 +598,9 @@ public enum PowersManager {
SourceType sourceType = SourceType.GetSourceType(pb.getCategory());
if (bonus != null && (bonus.getBool(ModType.Stunned, SourceType.None) || bonus.getBool(ModType.CannotCast, SourceType.None) || bonus.getBool(ModType.BlockedPowerType, sourceType)))
return true;
if (bonus != null && bonus.getBool(ModType.Fear, SourceType.None))
return true;
// if moving make sure spell valid for movement
// if flying, make sure spell valid for flying.
@@ -761,6 +767,11 @@ public enum PowersManager {
finishRecycleTime(msg.getPowerUsedID(), playerCharacter, true);
return;
}
if (bonus.getBool(ModType.Fear, SourceType.None)) {
finishRecycleTime(msg.getPowerUsedID(), playerCharacter, true);
return;
}
}
// get target loc
@@ -1042,6 +1053,9 @@ public enum PowersManager {
return;
}
if (bonus != null && bonus.getBool(ModType.Fear, SourceType.None))
return;
msg.setNumTrains(9999);
msg.setUnknown04(2);
DispatchMessage.sendToAllInRange(caster, msg);
@@ -2565,6 +2579,10 @@ public enum PowersManager {
}
public static void cancelOnFear(AbstractCharacter ac) {
}
private static PowersBase getLastPower(AbstractCharacter ac) {
if (ac == null)
return null;
+42
View File
@@ -0,0 +1,42 @@
package engine.jobs;
import engine.job.AbstractJob;
import engine.objects.AbstractCharacter;
import engine.math.Vector3fImmutable;
import engine.server.MBServerStatics;
import java.util.Random;
public class FearWanderJob extends AbstractJob {
private final AbstractCharacter target;
private final Random rand = new Random();
public FearWanderJob(AbstractCharacter target) {
super();
this.target = target;
}
@Override
public void doJob() {
// Only wander if still feared
if (target == null || !target.getBonuses().getBool(engine.Enum.ModType.Fear, engine.Enum.SourceType.None))
return;
// Pick a random direction and distance
float angle = rand.nextFloat() * (float)Math.PI * 2f;
float distance = 5f + rand.nextFloat() * 10f; // 5-15 units
Vector3fImmutable current = target.getLoc();
float newX = current.x + (float)Math.cos(angle) * distance;
float newZ = current.z + (float)Math.sin(angle) * distance;
// Clamp to world bounds if needed
newX = (float) Math.max(0, Math.min(newX, MBServerStatics.MAX_WORLD_WIDTH));
newZ = (float) Math.max(0, Math.min(newZ, MBServerStatics.MAX_WORLD_HEIGHT));
Vector3fImmutable dest = new Vector3fImmutable(newX, current.y, newZ);
// Issue movement (implement setEndLoc or similar in your AbstractCharacter)
target.setEndLoc(dest);
}
}
+1 -40
View File
@@ -81,7 +81,7 @@ public class Bounds {
Bounds identityBounds = Bounds.borrow();
identityBounds.setBounds(location);
collisionState = collide(targetBounds, identityBounds, 0.1f);
collisionState = collide(targetBounds, identityBounds, 0.0f);
identityBounds.release();
return collisionState;
}
@@ -267,45 +267,6 @@ 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));
@@ -124,7 +124,7 @@ public class CombatUtilities {
}
public static boolean canSwing(Mob agent) {
return (agent.isAlive() && !agent.getBonuses().getBool(ModType.Stunned, SourceType.None));
return (agent.isAlive() && !agent.getBonuses().getBool(ModType.Stunned, SourceType.None) && !agent.getBonuses().getBool(ModType.Fear, SourceType.None));
}
public static void swingIsMiss(Mob agent, AbstractWorldObject target, int animation) {
@@ -169,7 +169,7 @@ public class MovementUtilities {
if (agent.getMobBase() != null && Enum.MobFlagType.SENTINEL.elementOf(agent.getMobBase().getFlags()))
return false;
return (agent.isAlive() && !agent.getBonuses().getBool(ModType.Stunned, SourceType.None) && !agent.getBonuses().getBool(ModType.CannotMove, SourceType.None));
return (agent.isAlive() && !agent.getBonuses().getBool(ModType.Stunned, SourceType.None) && !agent.getBonuses().getBool(ModType.Fear, SourceType.None) && !agent.getBonuses().getBool(ModType.CannotMove, SourceType.None));
}
public static Vector3fImmutable randomPatrolLocation(Mob agent, Vector3fImmutable center, float radius) {
+24
View File
@@ -1653,6 +1653,30 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
PowersManager.cancelOnStun(this);
}
public final void cancelOnFear() {
boolean changed = false;
for (String s : this.effects.keySet()) {
Effect eff = this.effects.get(s);
if (eff == null)
continue;
if (eff.cancelOnFear() && eff.cancel()) {
eff.cancelJob();
this.effects.remove(s);
changed = true;
}
}
JobContainer wanderJob = this.getTimers().get("FearWander");
if (wanderJob != null) {
wanderJob.cancelJob();
this.getTimers().remove("FearWander");
}
if (changed) {
applyBonuses();
}
PowersManager.cancelOnFear(this);
}
//Call to apply any new effects to player
public synchronized void applyBonuses() {
PlayerCharacter player;
+9
View File
@@ -48,6 +48,7 @@ public class Effect {
private boolean cancelOnTerritoryClaim;
private boolean cancelOnUnEquip;
private boolean cancelOnStun;
private boolean cancelOnFear;
private boolean bakedInStat = false;
private boolean isStatic = false;
private int effectSourceType = 0;
@@ -80,6 +81,7 @@ public class Effect {
this.cancelOnTerritoryClaim = false;
this.cancelOnUnEquip = false;
this.cancelOnStun = false;
this.cancelOnFear = false;
this.eb = eb;
this.trains = trains;
}
@@ -99,6 +101,7 @@ public class Effect {
this.cancelOnTerritoryClaim = false;
this.cancelOnUnEquip = false;
this.cancelOnStun = false;
this.cancelOnFear = false;
this.eb = eb;
this.trains = trains;
this.isStatic = isStatic;
@@ -581,6 +584,12 @@ public class Effect {
return this.cancelOnStun;
}
public boolean cancelOnFear() {
if (this.eb == null)
return true;
return this.cancelOnFear;
}
public boolean cancelOnTakeDamage() {
if (this.eb == null)
return true;
+1 -1
View File
@@ -1249,7 +1249,7 @@ public class Mob extends AbstractIntelligenceAgent {
if (!this.isMoving())
return;
if (this.isAlive() == false || this.getBonuses().getBool(ModType.Stunned, SourceType.None) || this.getBonuses().getBool(ModType.CannotMove, SourceType.None)) {
if (this.isAlive() == false || this.getBonuses().getBool(ModType.Stunned, SourceType.None) || this.getBonuses().getBool(ModType.Fear, SourceType.None) || this.getBonuses().getBool(ModType.CannotMove, SourceType.None)) {
//Target is stunned or rooted. Don't move
this.stopMovement(this.getMovementLoc());
+21 -1
View File
@@ -26,6 +26,7 @@ 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;
@@ -268,6 +269,9 @@ public class PlayerCharacter extends AbstractCharacter {
this.hash = rs.getString("hash");
// For debugging skills
// CharacterSkill.printSkills(this);
}
public static Building getUpdatedBindBuilding(PlayerCharacter player) {
@@ -4403,6 +4407,10 @@ public class PlayerCharacter extends AbstractCharacter {
if (this.bonuses.getBool(ModType.Stunned, SourceType.None))
return 0f;
if (this.bonuses.getBool(
ModType.Fear, SourceType.None))
return 0f;
// Get base skill amount
CharacterSkill sk = this.skills.get(type);
float amount;
@@ -4432,6 +4440,10 @@ public class PlayerCharacter extends AbstractCharacter {
// must not be stunned
if (this.bonuses.getBool(ModType.Stunned, SourceType.None))
return 0f;
if (this.bonuses.getBool(ModType.Fear, SourceType.None))
return 0f;
// Get base skill amount
CharacterSkill sk = this.skills.get(sourceType.name());
@@ -4561,6 +4573,9 @@ public class PlayerCharacter extends AbstractCharacter {
this.charItemManager = new CharacterItemManager(this);
Bounds playerBounds = Bounds.borrow();
playerBounds.setBounds(this.getLoc());
this.setBounds(playerBounds);
}
@Override
@@ -4890,6 +4905,12 @@ public class PlayerCharacter extends AbstractCharacter {
this.region = AbstractWorldObject.GetRegionByWorldObject(this);
return;
}
if (this.isAlive() == false || this.getBonuses().getBool(ModType.Fear, SourceType.None)) {
//Target is feared. Don't move
this.stopMovement(newLoc);
this.region = AbstractWorldObject.GetRegionByWorldObject(this);
return;
}
if (newLoc.equals(this.getEndLoc())) {
this.stopMovement(newLoc);
this.region = AbstractWorldObject.GetRegionByWorldObject(this);
@@ -5356,7 +5377,6 @@ 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);
+2
View File
@@ -247,6 +247,8 @@ public class ActionsBase {
//TODO make this more efficient then testing strings
if (this.stackType.equals("Stun") && bonus.getBool(ModType.ImmuneTo, SourceType.Stun))
return true; //Currently stun immune. Skip stun
else if (this.stackType.equals("Fear") && bonus.getBool(ModType.ImmuneTo, SourceType.Fear))
return true; //Currently fear immune. Skip fear
else if (this.stackType.equals("Snare") && bonus.getBool(ModType.ImmuneTo, SourceType.Snare))
return true; //Currently snare immune. Skip snare
else if (this.stackType.equals("Blindness") && bonus.getBool(ModType.ImmuneTo, SourceType.Blind))
@@ -0,0 +1,58 @@
// ·. · · · · .
// · ·
// · ·
//
// · · ·
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.powers.effectmodifiers;
import engine.Enum.GameObjectType;
import engine.Enum.ModType;
import engine.Enum.SourceType;
import engine.jobs.FearWanderJob;
import engine.job.JobContainer;
import engine.job.JobScheduler;
import engine.jobs.AbstractEffectJob;
import engine.objects.*;
import java.sql.ResultSet;
import java.sql.SQLException;
public class FearEffectModifier extends AbstractEffectModifier {
public FearEffectModifier(ResultSet rs) throws SQLException {
super(rs);
}
@Override
protected void _applyEffectModifier(AbstractCharacter source, AbstractWorldObject awo, int trains, AbstractEffectJob effect) {
// Optional: custom logic when fear is applied
}
@Override
public void applyBonus(AbstractCharacter ac, int trains) {
PlayerBonuses bonus = ac.getBonuses();
bonus.setBool(this.modType, this.sourceType, true);
ac.cancelOnFear();
ac.setIsCasting(false);
ac.stopMovement(ac.getLoc());
// Schedule the wander job if not already scheduled
if (ac.getTimers().get("FearWander") == null) {
JobContainer wanderJob = JobScheduler.getInstance().scheduleJob(
new FearWanderJob(ac), 2000
);
ac.getTimers().put("FearWander", wanderJob);
}
}
@Override
public void applyBonus(Item item, int trains) {}
@Override
public void applyBonus(Building building, int trains) {}
}