mirror of
https://github.com/ProjectSWGCore/NGECore2.git
synced 2026-09-11 21:45:43 -04:00
Fixed client crash when buffs clear on corpse
Corpse despawn now Patrolling NPCs dont despawn, still fixing it
This commit is contained in:
@@ -146,20 +146,43 @@ public class Buff extends Delta {
|
||||
|
||||
public byte[] getBytes() {
|
||||
// If getObject ever returns null here, it means there's a major bug with objects being in quadtree but not in objectList.
|
||||
PlayerObject player = (PlayerObject) NGECore.getInstance().objectService.getObject(buffeeId).getSlottedObject("ghost");
|
||||
long lastPlayTimeUpdate = ((player == null) ? 0L : player.getLastPlayTimeUpdate());
|
||||
int remainingDuration = getRemainingDuration();
|
||||
|
||||
synchronized(objectMutex) {
|
||||
totalPlayTime = ((player == null) ? 0 : (int) (totalPlayTime + (System.currentTimeMillis() - lastPlayTimeUpdate) / 1000));
|
||||
IoBuffer buffer = createBuffer(24);
|
||||
buffer.putInt((int) ((duration > 0) ? (totalPlayTime + remainingDuration) : -1));
|
||||
buffer.putInt(0);
|
||||
buffer.putInt((int) duration);
|
||||
buffer.putLong(bufferId);
|
||||
buffer.putInt(stacks);
|
||||
buffer.flip();
|
||||
return buffer.array();
|
||||
|
||||
if (NGECore.getInstance().objectService.getObject(buffeeId)==null){
|
||||
System.err.println("FATAL ERROR BUFFED CREATURE NOT IN OBJECTLIST");
|
||||
return new byte[]{};
|
||||
}
|
||||
|
||||
CreatureObject cre = (CreatureObject)NGECore.getInstance().objectService.getObject(buffeeId);
|
||||
// NPCs should be considered here to
|
||||
if (cre.isPlayer()){
|
||||
PlayerObject player = (PlayerObject) NGECore.getInstance().objectService.getObject(buffeeId).getSlottedObject("ghost");
|
||||
long lastPlayTimeUpdate = ((player == null) ? 0L : player.getLastPlayTimeUpdate());
|
||||
int remainingDuration = getRemainingDuration();
|
||||
|
||||
synchronized(objectMutex) {
|
||||
totalPlayTime = ((player == null) ? 0 : (int) (totalPlayTime + (System.currentTimeMillis() - lastPlayTimeUpdate) / 1000));
|
||||
IoBuffer buffer = createBuffer(24);
|
||||
buffer.putInt((int) ((duration > 0) ? (totalPlayTime + remainingDuration) : -1));
|
||||
buffer.putInt(0);
|
||||
buffer.putInt((int) duration);
|
||||
buffer.putLong(bufferId);
|
||||
buffer.putInt(stacks);
|
||||
buffer.flip();
|
||||
return buffer.array();
|
||||
}
|
||||
} else {
|
||||
int remainingDuration = getRemainingDuration();
|
||||
synchronized(objectMutex) {
|
||||
totalPlayTime = 0;
|
||||
IoBuffer buffer = createBuffer(24);
|
||||
buffer.putInt((int) ((duration > 0) ? (totalPlayTime + remainingDuration) : -1));
|
||||
buffer.putInt(0);
|
||||
buffer.putInt((int) duration);
|
||||
buffer.putLong(bufferId);
|
||||
buffer.putInt(stacks);
|
||||
buffer.flip();
|
||||
return buffer.array();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -564,7 +587,8 @@ public class Buff extends Delta {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
core.buffService.removeBuffFromCreature(creature, Buff.this);
|
||||
if (creature!=null)
|
||||
core.buffService.removeBuffFromCreature(creature, Buff.this);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -224,7 +224,8 @@ public class BuffService implements INetworkDispatch {
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
removeBuffFromCreature(target, buff);
|
||||
if (target!=null && buff != null)
|
||||
removeBuffFromCreature(target, buff);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -243,10 +244,12 @@ public class BuffService implements INetworkDispatch {
|
||||
public void run() {
|
||||
try {
|
||||
if (buffer == null || buffer.getClient() == null)
|
||||
removeBuffFromCreature(target, buff);
|
||||
if (target!=null && buff != null)
|
||||
removeBuffFromCreature(target, buff);
|
||||
|
||||
if (target.getWorldPosition().getDistance2D(buffer.getWorldPosition()) > 80) {
|
||||
removeBuffFromCreature(target, buff);
|
||||
if (target!=null && buff != null)
|
||||
removeBuffFromCreature(target, buff);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -388,7 +391,8 @@ public class BuffService implements INetworkDispatch {
|
||||
if(buff.getRemainingDuration() > 0 && buff.getDuration() > 0) {
|
||||
ScheduledFuture<?> task = scheduler.schedule(() -> {
|
||||
try {
|
||||
removeBuffFromCreature(creature, buff);
|
||||
if (creature!=null && buff != null)
|
||||
removeBuffFromCreature(creature, buff);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -507,46 +507,32 @@ public class AIActor {
|
||||
}
|
||||
|
||||
public void scheduleDespawn() {
|
||||
// Sometimes these tasks are null?
|
||||
|
||||
try {
|
||||
if (aggroCheckTask!=null)
|
||||
aggroCheckTask.cancel(true);
|
||||
if (factionCheckTask!=null)
|
||||
factionCheckTask.cancel(true);
|
||||
} catch(Exception e) {
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
regenTask.cancel(true);
|
||||
} catch(Exception e) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
despawnFuture = scheduler.schedule(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
damageMap.clear();
|
||||
followObject = null;
|
||||
NGECore.getInstance().objectService.destroyObject(creature);
|
||||
NGECore.getInstance().objectService.destroyObject(creature);
|
||||
destroyActor();
|
||||
} catch (Exception e) {
|
||||
System.err.println("Exception3 in scheduleDespawn");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
//}, 2, TimeUnit.MINUTES);
|
||||
}, 10, TimeUnit.SECONDS);
|
||||
//}, 2, TimeUnit.MINUTES);
|
||||
}, 15, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public void destroyActor(){
|
||||
creature.getEventBus().unsubscribe(this);
|
||||
if (creature!=null){
|
||||
if (despawnFuture!=null){
|
||||
despawnFuture.cancel(true);
|
||||
despawnFuture = null;
|
||||
}
|
||||
}
|
||||
// if (creature!=null){
|
||||
// if (despawnFuture!=null){
|
||||
// despawnFuture.cancel(true);
|
||||
// despawnFuture = null;
|
||||
// }
|
||||
// }
|
||||
|
||||
// Make sure to kill all AI helper threads
|
||||
if (aggroCheckTask!=null)
|
||||
@@ -559,7 +545,26 @@ public class AIActor {
|
||||
movementFuture.cancel(true);
|
||||
movementFuture = null;
|
||||
}
|
||||
if (recoveryFuture!=null){
|
||||
recoveryFuture.cancel(true);
|
||||
recoveryFuture = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void endMovement(){
|
||||
|
||||
// Make sure to kill all AI helper threads
|
||||
if (aggroCheckTask!=null)
|
||||
aggroCheckTask.cancel(true);
|
||||
if (factionCheckTask!=null)
|
||||
factionCheckTask.cancel(true);
|
||||
if (regenTask!=null)
|
||||
regenTask.cancel(true);
|
||||
if (movementFuture!=null){
|
||||
movementFuture.cancel(true);
|
||||
movementFuture = null;
|
||||
}
|
||||
if (recoveryFuture!=null){
|
||||
recoveryFuture.cancel(true);
|
||||
recoveryFuture = null;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,9 @@ public class DeathState extends AIState {
|
||||
|
||||
@Override
|
||||
public byte onEnter(AIActor actor) {
|
||||
if (!actor.isActorAlive())
|
||||
return 0;
|
||||
actor.setActorAlive(false);
|
||||
NGECore.getInstance().buffService.clearBuffs(actor.getCreature());
|
||||
NGECore.getInstance().aiService.awardExperience(actor);
|
||||
NGECore.getInstance().aiService.awardGcw(actor);
|
||||
|
||||
@@ -604,18 +604,19 @@ public class ObjectService implements INetworkDispatch {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
// Commented for now until found where the respawn is always set to 60 for any NPC
|
||||
// try {
|
||||
// // Commented for now until found where the respawn is always set to 60 for any NPC
|
||||
// CreatureObject newObject = NGECore.getInstance().spawnService.spawnCreature(Template, 0, planet.getName(), cellId, spawnPosition.x, spawnPosition.y, spawnPosition.z, orientation.w, orientation.x, orientation.y, orientation.z, level);
|
||||
// AIActor newAIActor = (AIActor)newObject.getAttachment("AI");
|
||||
// newAIActor.cloneActor(((AIActor) object.getAttachment("AI")));
|
||||
//object.setAttachment("AI", null);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// //object.setAttachment("AI", null);
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
}
|
||||
|
||||
}, ((AIActor) object.getAttachment("AI")).getMobileTemplate().getRespawnTime(), TimeUnit.SECONDS);
|
||||
//}, ((AIActor) object.getAttachment("AI")).getMobileTemplate().getRespawnTime(), TimeUnit.SECONDS);
|
||||
}, 20, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
String filePath = "scripts/" + object.getTemplate().split("shared_" , 2)[0].replace("shared_", "") + object.getTemplate().split("shared_" , 2)[1].replace(".iff", "") + ".py";
|
||||
|
||||
Reference in New Issue
Block a user