From 8c0f7fcb52bb5ee5514a2ff388105efd77308f0f Mon Sep 17 00:00:00 2001 From: CharonInferar Date: Sun, 24 Aug 2014 03:13:08 +0200 Subject: [PATCH 1/2] Fixed Incap weaken immortality bug --- scripts/static_spawns/tatooine/mos_eisley.py | 27 ++++++++++++++++++++ src/services/SimulationService.java | 21 +++++++++++++++ src/services/ai/AIService.java | 11 ++++++++ src/services/combat/CombatService.java | 18 ++++++------- 4 files changed, 67 insertions(+), 10 deletions(-) diff --git a/scripts/static_spawns/tatooine/mos_eisley.py b/scripts/static_spawns/tatooine/mos_eisley.py index e1429082..f6ab63b5 100644 --- a/scripts/static_spawns/tatooine/mos_eisley.py +++ b/scripts/static_spawns/tatooine/mos_eisley.py @@ -157,4 +157,31 @@ def addPlanetSpawns(core, planet): aiSvc.setLoiter(r3m6, float(1), float(3)) aiSvc.setLoiter(eg1, float(1), float(3)) aiSvc.setLoiter(r3j7, float(1), float(3)) + + # Looped Patrol must end in same cell like the start point!!! + #building id: 1105845 Buildingid + cell ! + trehla = stcSvc.spawnObject('trehla', 'tatooine', long(1105845 + 8), float(24.21), float(2.12), float(73.49), float(0.92), float(0), float(-0.38), float(0)) + patrolpointsCells = Vector() # Vector Building reference Patrolpoint CellID + aiSvc.addPatrolPointCell(patrolpointsCells, trehla.getGrandparent(), Point3D(float(25.11), float(2.10), float(50.22)), 7) + aiSvc.addPatrolPointCell(patrolpointsCells, trehla.getGrandparent(), Point3D(float(21.25), float(0.6), float(45.51)), 6) + aiSvc.addPatrolPointCell(patrolpointsCells, trehla.getGrandparent(), Point3D(float(-11.78), float(0.59), float(45.78)), 6) + aiSvc.addPatrolPointCell(patrolpointsCells, trehla.getGrandparent(), Point3D(float(-13.67), float(2.6), float(18.27)), 6) + aiSvc.addPatrolPointCell(patrolpointsCells, trehla.getGrandparent(), Point3D(float(-6.63), float(2.6), float(17.87)), 6) + aiSvc.addPatrolPointCell(patrolpointsCells, trehla.getGrandparent(), Point3D(float(-6.74), float(2.6), float(1.60)), 6) + aiSvc.addPatrolPointCell(patrolpointsCells, trehla.getGrandparent(), Point3D(float(-17.92), float(0.6), float(1.88)), 5) + aiSvc.addPatrolPointCell(patrolpointsCells, trehla.getGrandparent(), Point3D(float(-18.21), float(0.6), float(9.40)), 5) + aiSvc.addPatrolPointCell(patrolpointsCells, trehla.getGrandparent(), Point3D(float(-24.18), float(0.6), float(9.40)), 5) + + aiSvc.addPatrolPointCell(patrolpointsCells, trehla.getGrandparent(), Point3D(float(-24.50), float(0.6), float(-4.08)), 2) + aiSvc.addPatrolPointCell(patrolpointsCells, trehla.getGrandparent(), Point3D(float(0.03), float(0.6), float(-4.36)), 1) + aiSvc.addPatrolPointCell(patrolpointsCells, trehla.getGrandparent(), Point3D(float(25.03), float(0.6), float(-4.10)), 3) + aiSvc.addPatrolPointCell(patrolpointsCells, trehla.getGrandparent(), Point3D(float(24.38), float(0.6), float(9.42)), 3) + aiSvc.addPatrolPointCell(patrolpointsCells, trehla.getGrandparent(), Point3D(float(17.98), float(0.6), float(9.14)), 4) + aiSvc.addPatrolPointCell(patrolpointsCells, trehla.getGrandparent(), Point3D(float(5.44), float(2.6), float(2.33)), 6) + aiSvc.addPatrolPointCell(patrolpointsCells, trehla.getGrandparent(), Point3D(float(9.3), float(2.6), float(18.64)), 6) + aiSvc.addPatrolPointCell(patrolpointsCells, trehla.getGrandparent(), Point3D(float(14.65), float(0.92), float(40.72)), 6) + aiSvc.addPatrolPointCell(patrolpointsCells, trehla.getGrandparent(), Point3D(float(23.9), float(0.93), float(48.22)), 7) + aiSvc.addPatrolPointCell(patrolpointsCells, trehla.getGrandparent(), Point3D(float(26.64), float(2.12), float(57.42)), 7) + aiSvc.addPatrolPointCell(patrolpointsCells, trehla.getGrandparent(), Point3D(float(27.64), float(2.12), float(70.07)), 8) + aiSvc.setPatrol(trehla, patrolpointsCells) return \ No newline at end of file diff --git a/src/services/SimulationService.java b/src/services/SimulationService.java index 0d3366fe..9b23cec5 100644 --- a/src/services/SimulationService.java +++ b/src/services/SimulationService.java @@ -1067,6 +1067,27 @@ public class SimulationService implements INetworkDispatch { } + public Point3D convertModelSpaceToPoint(Point3D point, SWGObject object) { + + Point3D position = object.getPosition(); + WB_M44 translateMatrix = new WB_M44(1, 0, 0, position.x, 0, 1, 0, position.y, 0, 0, 1, position.z, 0, 0, 0, 1); + + float radians = object.getRadians(); + float sin = (float) Math.sin(radians); + float cos = (float) Math.cos(radians); + + WB_M44 rotationMatrix = new WB_M44(cos, 0, sin, 0, 0, 1, 0, 0, -sin, 0, cos, 0, 0, 0, 0, 1); //non-inverse matrix + + WB_M44 modelSpace = translateMatrix.mult(rotationMatrix); + + float x = (float) (modelSpace.m11 * point.x + modelSpace.m12 * point.y + modelSpace.m13 * point.z + modelSpace.m14); + float y = (float) (modelSpace.m21 * point.x + modelSpace.m22 * point.y + modelSpace.m23 * point.z + modelSpace.m24); + float z = (float) (modelSpace.m31 * point.x + modelSpace.m32 * point.y + modelSpace.m33 * point.z + modelSpace.m34); + + return new Point3D(x, y, z); + + } + /* * Moved this to ConnectionService which will disconnect them * from the server if they don't send packets for 5 minutes or more diff --git a/src/services/ai/AIService.java b/src/services/ai/AIService.java index 162b09b1..6371202b 100644 --- a/src/services/ai/AIService.java +++ b/src/services/ai/AIService.java @@ -35,6 +35,8 @@ import resources.common.SpawnPoint; import resources.datatables.Difficulty; import resources.datatables.FactionStatus; import resources.datatables.GcwType; +import resources.objects.building.BuildingObject; +import resources.objects.cell.CellObject; import resources.objects.creature.CreatureObject; import resources.objects.group.GroupObject; import resources.objects.player.PlayerObject; @@ -213,6 +215,15 @@ public class AIService { actor.setCurrentState(new IdleState()); } + public void addPatrolPointCell(Vector patrolpoints, BuildingObject building, Point3D position, int cellID){ + if (building==null) + return; + CellObject cellObj = building.getCellByCellNumber(cellID); + if (cellObj!=null) + position.setCell(cellObj); + patrolpoints.add(position); + } + public void setLoiter(CreatureObject creature, float minDist, float maxDist){ AIActor actor = (AIActor) creature.getAttachment("AI"); if (actor==null) diff --git a/src/services/combat/CombatService.java b/src/services/combat/CombatService.java index fbd5fedf..f979170d 100644 --- a/src/services/combat/CombatService.java +++ b/src/services/combat/CombatService.java @@ -1238,21 +1238,19 @@ public class CombatService implements INetworkDispatch { if(target.hasBuff("incapWeaken")) { if (!attacker.isPlayer()){ - AIActor aiActor = (AIActor)attacker.getAttachment("AI"); - if (aiActor.getMobileTemplate().isDeathblow()) - deathblowPlayer(attacker, target); + deathblowPlayer(attacker, target); } else { deathblowPlayer(attacker, target); } return; - } - - if (!attacker.isPlayer()){ - AIActor aiActor = (AIActor)attacker.getAttachment("AI"); - if (aiActor.getMobileTemplate().isDeathblow()){ - deathblowPlayer(attacker, target); - return; + } else { + if (!attacker.isPlayer()){ + AIActor aiActor = (AIActor)attacker.getAttachment("AI"); + if (aiActor.getMobileTemplate().isDeathblow()){ + deathblowPlayer(attacker, target); + return; + } } } From 7ff3c5a0d8e7038805bb0e6962da956f11ace085 Mon Sep 17 00:00:00 2001 From: CharonInferar Date: Sun, 24 Aug 2014 03:14:09 +0200 Subject: [PATCH 2/2] Added cell-relative AI patrol motion - Replaced unnecessarily complex algebraic matrix expression --- src/services/ai/states/AIState.java | 154 ++++++++++++++++++---------- 1 file changed, 99 insertions(+), 55 deletions(-) diff --git a/src/services/ai/states/AIState.java b/src/services/ai/states/AIState.java index b1f4a93c..021cdbb9 100644 --- a/src/services/ai/states/AIState.java +++ b/src/services/ai/states/AIState.java @@ -76,6 +76,15 @@ public abstract class AIState { NGECore core = NGECore.getInstance(); Point3D currentPosition = creature.getPosition(); Point3D targetPosition = null; + // Cell management + if (creature.getContainer()!=null && creature.getContainer() instanceof CellObject){ + CellObject cellObj1 = (CellObject)creature.getContainer(); + if (cellObj1!=null){ + currentPosition.setCell(cellObj1); + } + } + + float maxDistance = stopDistance; boolean finished = false; float dx, dz, newX = 0, newY = 0, newZ = 0; @@ -85,6 +94,8 @@ public abstract class AIState { //while(!finished && movementPoints.size() != 0) { if ((!(actor.getCurrentState() instanceof FollowState)) && movementPoints.size() == 0 && patrolPoints.size() == 0) { + if (creature.getTemplate().contains("shared_dressed_tutorial_mentor.iff")) + System.out.println("findNewPosition targetPosition null "); DevLog.debugoutai(actor, "Charon", "AI State findnewpos", "Breakout1"); return false; } @@ -107,16 +118,31 @@ public abstract class AIState { if (actor.getCurrentState().getClass().equals(FollowState.class)){ targetPosition = actor.getFollowObject().getWorldPosition(); + if (actor.getFollowObject().getContainer()!=null && actor.getFollowObject().getContainer() instanceof CellObject){ + CellObject cellObj1 = (CellObject)actor.getFollowObject().getContainer(); + if (cell!=null) + targetPosition.setCell(cellObj1); + } } Vector path = core.aiService.findPath(creature.getPlanetId(), currentPosition, targetPosition); if (targetPosition==null){ + if (creature.getTemplate().contains("shared_dressed_tutorial_mentor.iff")) + System.out.println("findNewPosition targetPosition null "); DevLog.debugoutai(actor, "Charon", "AI State findnewpos", "Breakout2"); return false; } + float distanceToTarget = targetPosition.getWorldPosition().getDistance(creature.getWorldPosition()); + if (targetPosition.getCell()!=null){ + //Point3D targetWorldPosition = core.simulationService.convertModelSpaceToPoint(targetPosition, creature.getGrandparent()); + Point3D targetWorldPosition = targetPosition.getWorldPosition(); + distanceToTarget = targetWorldPosition.getDistance(creature.getWorldPosition()); + } + + if(distanceToTarget > stopDistance) { maxDistance = Math.min(speed, distanceToTarget - stopDistance); } else { @@ -139,9 +165,7 @@ public abstract class AIState { Point3D oldPosition = null; float pathDistance = 0; - - - + for(int i = 1; i < path.size() && !finished; i++) { Point3D currentPathPosition = path.get(i); @@ -153,7 +177,7 @@ public abstract class AIState { pathDistance += oldWorldPos.getDistance(currentPathPosition.getWorldPosition()); if(pathDistance >= maxDistance || i == path.size() - 1 || currentPathPosition.getCell() != creature.getContainer()) { - + finished = true; if(movementPoints.size() != 0 && currentPosition.getWorldPosition().getDistance(currentPathPosition.getWorldPosition()) <= stopDistance && cell == creature.getContainer()) { @@ -177,6 +201,7 @@ public abstract class AIState { //float distance = oldWorldPos.getDistance(currentPathPosition.getWorldPosition()); float distance = NGECore.getInstance().aiService.distanceSquared(oldWorldPos, currentPathPosition.getWorldPosition()); // Ok to use, as distance is not directly used later float travelDistance = distance - (pathDistance - maxDistance); + // temp fix for melee npcs travelDistance *= 1.3; if(travelDistance <= 0) { @@ -203,7 +228,7 @@ public abstract class AIState { fullong = (int)(tempdz*100); halfshort = ((int)(tempdx*100)) >> 1; } - float deltaDist = (fullong + halfshort)/100; + float deltaDist = (fullong + halfshort)/100; // end of approximation newX = (float) (oldPosition.x + (speed * (dx / deltaDist))); newZ = (float) (oldPosition.z + (speed * (dz / deltaDist))); @@ -226,6 +251,10 @@ public abstract class AIState { } } else { + + if (creature.getTemplate().contains("shared_dressed_tutorial_mentor.iff")) + System.out.println("ELSE CASE"); + newX = currentPathPosition.x; newZ = currentPathPosition.z; newY = core.terrainService.getHeight(creature.getPlanetId(), newX, newZ); @@ -742,8 +771,7 @@ public abstract class AIState { if (creature.isInCombat()){ return; } - - + TangibleObject target = actor.getFollowObject(); float speed = (float) creature.getWalkSpeed(); float maxDistance = 6; @@ -763,82 +791,98 @@ public abstract class AIState { // Manage Patrol points maxDistance = 1; - if (actor.getPatrolPoints().size()==0) + if (actor.getPatrolPoints().size()==0){ return; + } + + + Point3D currentDestination = actor.getPatrolPoints().get(actor.getPatrolPointIndex()); - //System.out.println("currentPosition.getDistance2D(currentDestination) " + currentPosition.getDistance2D(currentDestination)); - if (NGECore.getInstance().aiService.distanceSquared2D(currentPosition, currentDestination)<4){ - //if (currentPosition.getDistance2D(currentDestination)<4){ + + float relDistance = NGECore.getInstance().aiService.distanceSquared2D(currentPosition, currentDestination); + + if (currentDestination.getCell()!=null){ + //Point3D curdestWS = core.simulationService.convertModelSpaceToPoint(currentDestination, creature.getGrandparent()); + Point3D curdestWS = currentDestination.getWorldPosition(); + relDistance = NGECore.getInstance().aiService.distanceSquared2D(currentPosition, curdestWS); + } + + if (relDistance<4){ + if (actor.getPatrolPointIndex()=4 && NGECore.getInstance().invasionService.getInvasionPhase()!=3){ - actor.setAIactive(false); // switch off auto-target-recognition to counter lag - actor.setCurrentState(new IdleState()); - //System.out.println("AI switched off!"); - return; - } - - //actor.setCurrentState(new IdleState()); - // Wait state() Since this state does not require move,recover and all that its simple task + if (isInvader!=null){ - //NGECore.getInstance().aiService.waitForEvent(actor, NGECore.getInstance().invasionService, "isDefendingGeneralAlive", false, WithdrawalState.class); - - return; // Last Patrol point reached and no loop + // If invader check for in weapon range general + if (core.invasionService.getDefensiveGeneral()!=null){ + if (core.invasionService.getInvasionPhase()==3 && core.invasionService.getDefensiveGeneral().getPosture()!=13 && core.invasionService.getDefensiveGeneral().getPosture()!=14 && core.invasionService.getDistanceToDefensiveGeneral(creature)<2500){ + actor.addDefender(core.invasionService.getDefensiveGeneral()); + return; + } + } + + // Check if there are more than 5 invaders at same spot + if (NGECore.getInstance().simulationService.getAllNearSameFactionNPCs(7, creature).size()>=4 && NGECore.getInstance().invasionService.getInvasionPhase()!=3){ + actor.setAIactive(false); // switch off auto-target-recognition to counter lag + actor.setCurrentState(new IdleState()); + //System.out.println("AI switched off!"); + return; + } + + //actor.setCurrentState(new IdleState()); + // Wait state() Since this state does not require move,recover and all that its simple task + + //NGECore.getInstance().aiService.waitForEvent(actor, NGECore.getInstance().invasionService, "isDefendingGeneralAlive", false, WithdrawalState.class); + + return; // Last Patrol point reached and no loop + } } } - } + } else {} Point3D newPosition = new Point3D(); boolean foundNewPos = findNewPosition(actor, speed, maxDistance, newPosition); - - - - + if(!foundNewPos || (newPosition.x == 0 && newPosition.z == 0)) return; + + //Point3D newWorldPos = newPosition.getWorldPosition(); + Point3D newWorldPos = newPosition; + if (newPosition.getCell()==null) + newWorldPos = newPosition.getWorldPosition(); + + currentPosition = creature.getPosition(); - Point3D newWorldPos = newPosition.getWorldPosition(); - float direction = (float) Math.atan2(newWorldPos.x - currentPosition.x, newWorldPos.z - currentPosition.z); + float direction = (float) Math.atan2(newWorldPos.x - currentPosition.x, newWorldPos.z - currentPosition.z); // +0.973F if(direction < 0) - direction = (float) (2 * Math.PI + direction); + direction = (float) (2 * Math.PI + direction); // +0.973F + Quaternion quaternion = new Quaternion((float) Math.cos(direction / 2), 0, (float) Math.sin(direction / 2), 0); if (quaternion.y < 0.0f && quaternion.w > 0.0f) { quaternion.y *= -1; quaternion.w *= -1; } -// if (newPosition.getCell()==null) -// System.out.println("newPosition.getCell() is NULL"); try{ core.simulationService.moveObject(creature, newPosition, quaternion, creature.getMovementCounter(), speed, newPosition.getCell()); } catch (NullPointerException e) { // Just to identify what exactly is null here -// if (creature==null) -// System.out.print("creature==null" ); -// if (newPosition==null) -// System.out.print("newPosition==null" ); -// if (quaternion==null) -// System.out.print("quaternion==null" ); -// if (newPosition.getCell()==null) -// System.out.print("newPosition.getCell()==null" ); -// -// System.out.print("creature.getMovementCounter() " + creature.getMovementCounter()); + // if (creature==null) + // System.out.print("creature==null" ); + // if (newPosition==null) + // System.out.print("newPosition==null" ); + // if (quaternion==null) + // System.out.print("quaternion==null" ); + // if (newPosition.getCell()==null) + // System.out.print("newPosition.getCell()==null" ); + // } }