forked from MagicBane/Server
Compare commits
13 Commits
combat-4
...
d22ff916bf
| Author | SHA1 | Date | |
|---|---|---|---|
| d22ff916bf | |||
| 2d1da7679e | |||
| 549a381174 | |||
| 43563aeb14 | |||
| 7a4c2fe72a | |||
| 24cc6af147 | |||
| 3649c629b7 | |||
| 1c31070fc8 | |||
| bff41967db | |||
| d3692d0fb7 | |||
| 074a799d01 | |||
| 36ffd08a72 | |||
| 58f828b3cd |
@@ -24,3 +24,7 @@
|
||||
hs_err_pid*
|
||||
replay_pid*
|
||||
|
||||
*.idea/
|
||||
Server.iml
|
||||
*.gitignore
|
||||
prestonbane.iml
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -174,6 +174,7 @@ public class PlayerCharacter extends AbstractCharacter {
|
||||
private boolean isTeleporting = false;
|
||||
private boolean dirtyLoad = true;
|
||||
private final ReadWriteLock dirtyLock = new ReentrantReadWriteLock(true);
|
||||
private Bounds playerBounds;
|
||||
|
||||
/**
|
||||
* No Id Constructor
|
||||
@@ -206,6 +207,10 @@ public class PlayerCharacter extends AbstractCharacter {
|
||||
|
||||
this.guildStatus = new AtomicInteger(0);
|
||||
this.bindBuildingID = -1;
|
||||
|
||||
this.playerBounds = Bounds.borrow();
|
||||
playerBounds.setBounds(this.getLoc());
|
||||
this.playerBounds.setBounds(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -269,11 +274,60 @@ public class PlayerCharacter extends AbstractCharacter {
|
||||
|
||||
this.hash = rs.getString("hash");
|
||||
|
||||
this.playerBounds = Bounds.borrow();
|
||||
playerBounds.setBounds(this.getLoc());
|
||||
this.playerBounds.setBounds(this);
|
||||
|
||||
|
||||
// For debugging skills
|
||||
// CharacterSkill.printSkills(this);
|
||||
}
|
||||
|
||||
public void updateBounds() {
|
||||
this.playerBounds.setBounds(this);
|
||||
this.checkCollisionsWithOtherPlayers();
|
||||
}
|
||||
|
||||
public void checkCollisionsWithOtherPlayers() {
|
||||
HashSet<AbstractWorldObject> nearbyObjects = WorldGrid.getObjectsInRangePartial(this, MBServerStatics.CHARACTER_LOAD_RANGE, MBServerStatics.MASK_PLAYER);
|
||||
for (AbstractWorldObject obj : nearbyObjects) {
|
||||
if (obj instanceof PlayerCharacter && obj != this) {
|
||||
PlayerCharacter otherPlayer = (PlayerCharacter) obj;
|
||||
if (Bounds.collide(this.getBounds(), otherPlayer.getBounds(), 0.1f)) {
|
||||
System.out.println("Collision detected with player: " + otherPlayer.getFirstName());
|
||||
ChatManager.chatSystemInfo(otherPlayer, "Has Collided with YOU");
|
||||
// Handle collision with other player
|
||||
handleCollisionWithPlayer(otherPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleCollisionWithPlayer(PlayerCharacter otherPlayer) {
|
||||
Vector3fImmutable myPos = this.getLoc();
|
||||
Vector3fImmutable otherPlayerPos = otherPlayer.getLoc();
|
||||
|
||||
// Calculate direction vector
|
||||
Vector3fImmutable direction = myPos.subtract(otherPlayerPos).normalize();
|
||||
|
||||
// Move players apart
|
||||
float separationDistance = 1.0f; // Adjust this value as needed
|
||||
Vector3fImmutable myNewPos = myPos.add(direction.mult(separationDistance / 2));
|
||||
Vector3fImmutable otherPlayerNewPos = otherPlayerPos.subtract(direction.mult(separationDistance / 2.0f));
|
||||
|
||||
// Update positions
|
||||
this.setLoc(myNewPos);
|
||||
otherPlayer.setLoc(otherPlayerNewPos);
|
||||
|
||||
// Refresh both players in the world
|
||||
WorldGrid.updateObject(this);
|
||||
WorldGrid.updateObject(otherPlayer);
|
||||
|
||||
// Refresh both players in the world
|
||||
WorldGrid.updateObject(this);
|
||||
WorldGrid.updateObject(otherPlayer);
|
||||
}
|
||||
|
||||
public static Building getUpdatedBindBuilding(PlayerCharacter player) {
|
||||
Building returnBuilding = null;
|
||||
|
||||
@@ -4882,6 +4936,7 @@ public class PlayerCharacter extends AbstractCharacter {
|
||||
@Override
|
||||
public void updateLocation() {
|
||||
|
||||
this.updateBounds();
|
||||
|
||||
if (!this.isMoving())
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user