Index: core3/trunk/MMOCoreORB/src/server/zone/objects/creature/AiAgent.idl =================================================================== diff -u -N -r3295 -r5449 --- core3/trunk/MMOCoreORB/src/server/zone/objects/creature/AiAgent.idl (.../AiAgent.idl) (revision 3295) +++ core3/trunk/MMOCoreORB/src/server/zone/objects/creature/AiAgent.idl (.../AiAgent.idl) (revision 5449) @@ -66,13 +66,18 @@ import server.zone.objects.tangible.weapon.WeaponObject; import server.zone.templates.SharedObjectTemplate; import server.zone.templates.mobile.CreatureTemplate; -include server.zone.objects.tangible.DamageMap; import server.zone.objects.creature.events.DespawnCreatureOnPlayerDissappear; include server.zone.objects.creature.variables.CreatureAttackMap; import engine.util.u3d.Coordinate; import server.zone.objects.creature.commands.QueueCommand; import engine.util.Observable; -import server.zone.objects.creature.AiObserver; +import server.zone.objects.player.PlayerObject; +include server.zone.objects.player.FactionStatus; +include system.thread.Mutex; +include server.zone.managers.loot.lootgroup.LootGroupCollection; +include server.zone.objects.scene.components.AiInterfaceComponent; +include server.zone.objects.creature.variables.CreatureTemplateReference; +include system.thread.ReadWriteLock; class AiAgent extends CreatureObject { protected transient AiThinkEvent thinkEvent; @@ -84,6 +89,12 @@ protected transient AiAwarenessEvent awarenessEvent; @dereferenced + protected transient ReadWriteLock despawnMutex; + + @dereferenced + protected transient Vector aiInterfaceComponents; + + @dereferenced protected Vector skillCommands; @dereferenced @@ -94,42 +105,50 @@ @dereferenced protected PatrolPoint nextStepPosition; - + @dereferenced - protected DamageMap damageMap; + protected Vector weapons; - @dereferenced - protected SortedVector aiObserverMap; + @dereferenced + protected Vector camouflagedObjects; @dereferenced - protected Vector weapons; + protected CreatureTemplateReference npcTemplate; - protected transient CreatureTemplate npcTemplate; - protected transient SharedObjectTemplate objectTemplate; - - protected transient CreatureObject lootOwner; - protected boolean baby; + //DEBUG + protected boolean showNextMovementPosition; + @dereferenced + protected Vector movementMarkers; + protected boolean despawnOnNoPlayerInRange; - @weakReference + //@weakReference protected SceneObject followObject; protected unsigned int followState; + @dereferenced + protected transient Mutex targetMutex; protected boolean fleeing; + @dereferenced + protected transient Time lastDamageReceived; + protected float respawnTimer; protected int numberOfPlayersInRange; + protected boolean loadedOutfit; + protected transient DespawnCreatureOnPlayerDissappear despawnEvent; - public static final int UPDATEMOVEMENTINTERVAL = 1000; // msec + public static final int UPDATEMOVEMENTINTERVAL = 500; // msec public static final unsigned int OBLIVIOUS = 0; public static final unsigned int WATCHING = 1; public static final unsigned int STALKING = 2; public static final unsigned int FOLLOWING = 3; + public static final unsigned int PATROLING = 4; public AiAgent() { baby = false; @@ -138,16 +157,19 @@ respawnTimer = 0; + showNextMovementPosition = true; + despawnOnNoPlayerInRange = true; numberOfPlayersInRange = 0; - - objectTemplate = null; - npcTemplate = null; - lootOwner = null; + loadedOutfit = false; + Logger.setLoggingName("AiAgent"); Logger.setLogging(false); Logger.setGlobalLogging(true); + + fleeing = false; + baby = false; } /** @@ -158,7 +180,7 @@ public native void initializeTransientMembers(); public void finalize() { - Logger.info("deleting from ram", true); + //Logger.info("deleting from ram", true); } public abstract native void activateRecovery(); @@ -173,29 +195,65 @@ public native void doRecovery(); + public native void doAttack(); + public native void doMovement(); + public native void setLevel(int lvl); + + /** + * Sends the CREO baseline messages of this object to the specified player + * @pre { this object is locked } + * @post { this object is locked, player received the baseline messages } + * @param player SceneObject that will receive the baselines + */ + public native void sendBaselinesTo(SceneObject player); + + public native int calculateAttackMinDamage(int level); + public native int calculateAttackMaxDamage(int level); + public native float calculateAttackSpeed(int level); + + public abstract native boolean isCamouflaged(CreatureObject target) { + return false; + } + + public native boolean isScentMasked(CreatureObject target); + + public native boolean isConcealed(CreatureObject target); + protected native boolean findNextPosition(float maxDistance, WorldCoordinates nextPosition); @local - public abstract void doAwarenessCheck(@dereferenced Coordinate start, unsigned long time, CreatureObject target) { + public native void doAwarenessCheck(@dereferenced Coordinate start, unsigned long time, CreatureObject target); + + /** + * Handles the radial selection sent by the client, must be overriden by inherited objects + * @pre { this object is locked, player is locked } + * @post { this object is locked, player is locked } + * @param player CreatureObject that selected the option + * @param selectedID selected menu id + * @returns 0 if successfull + */ + public native int handleObjectMenuSelect(CreatureObject player, byte selectedID); - } - public native void checkNewAngle(); public native void fillAttributeList(AttributeListMessage msg, CreatureObject object); public native void setNextPosition(float x, float z, float y, SceneObject cell = null); + public native void notifyPositionUpdate(QuadTreeEntry entry); + @local public native void updateCurrentPosition(PatrolPoint point); @local public native void broadcastNextPositionUpdate(PatrolPoint point); public void clearPatrolPoints() { - patrolPoints.removeAll(); + synchronized (targetMutex) { + patrolPoints.removeAll(); + } } @local @@ -222,7 +280,8 @@ * @post { this object is locked } * @return unused for now */ - public native int inflictDamage(TangibleObject attacker, int damageType, int damage, boolean destroy, boolean notifyClient = true); + public native int inflictDamage(TangibleObject attacker, int damageType, float damage, boolean destroy, boolean notifyClient = true); + public native int inflictDamage(TangibleObject attacker, int damageType, float damage, boolean destroy, final string xp, boolean notifyClient = true); /** * sends the conversation notification @@ -262,8 +321,19 @@ public native int notifyAttack(Observable observable); public native int notifyCallForHelp(Observable observable, ManagedObject arg1); + public void destroyObjectFromWorld(boolean sendSelfDestroy) { + super.destroyObjectFromWorld(sendSelfDestroy); + + if (moveEvent != null) { + moveEvent.clearCreatureObject(); + moveEvent = null; + } + } + public native void activatePostureRecovery(); + public native void queueDizzyFallEvent(); + /** * Cleares the combat state * @pre { this object is locked } @@ -301,18 +371,29 @@ /** * Gets called when the creature was despawned */ - public native void notifyDespawn(Zone zone); + public abstract native void notifyDespawn(Zone zone); - public abstract native void scheduleDespawn(); + public abstract void scheduleDespawn() { + //Despawn in 45 seconds. + scheduleDespawn(45); + } /** + * Schedules despawn of the AiAgent. + * @param timeToDespawn the time to despawn the AiAgent in seconds. + */ + public abstract native void scheduleDespawn(int timeToDespawn); + + /** * Respawns creature to specified zone with home location position */ public native void respawn(Zone zone, int level); @local public void addPatrolPoint(@dereferenced PatrolPoint point) { - patrolPoints.add(point); + synchronized (targetMutex) { + patrolPoints.add(point); + } } public void setHomeLocation(float x, float z, float y, SceneObject cell = null) { @@ -338,12 +419,28 @@ if (super.pvpStatusBitmask == 0) return false; - if (this.isRetreating()) + if (isRetreating()) return false; - if (this.isDead()) + if (isDead()) return false; + if (object.isAiAgent()) + return false; + + unsigned int targetFaction = object.getFaction(); + + if (targetFaction != 0 && super.getFaction() != 0) { + PlayerObject ghost = object.getPlayerObject(); + + if (targetFaction == getFaction()) + return false; + + if (ghost != null && (targetFaction != super.getFaction()) && ghost.getFactionStatus() == FactionStatus.ONLEAVE) + return false; + } else if (targetFaction == 0 && super.getFaction() != 0) + return false; + return true; } @@ -353,15 +450,7 @@ * @post { } * @return returns true if its aggressive */ - public boolean isAggressiveTo(CreatureObject object) { - if (!isAttackableBy(object)) - return false; - - if (super.pvpStatusBitmask & CreatureFlag.AGGRESSIVE) - return true; - - return false; - } + public native boolean isAggressiveTo(CreatureObject object); public void setOblivious() { followState = OBLIVIOUS; @@ -370,43 +459,55 @@ } public void setWatchObject(SceneObject obj) { - if (this.isRetreating()) - return; - - followState = WATCHING; - - setTargetObject(obj); - activateMovementEvent(); + synchronized (targetMutex) { + if (this.isRetreating()) + return; + + followState = WATCHING; + + setTargetObject(obj); + activateMovementEvent(); + } } public void setStalkObject(SceneObject obj) { - if (this.isRetreating()) - return; - - followState = STALKING; - - setTargetObject(obj); - activateMovementEvent(); + synchronized (targetMutex) { + if (this.isRetreating()) + return; + + followState = STALKING; + + setTargetObject(obj); + activateMovementEvent(); + } } public void setFollowObject(SceneObject obj) { - if (this.isRetreating()) - return; - - followState = FOLLOWING; - - setTargetObject(obj); - activateMovementEvent(); + synchronized (targetMutex) { + if (this.isRetreating()) + return; + + followState = FOLLOWING; + + setTargetObject(obj); + activateMovementEvent(); + } } public void setTargetObject(SceneObject obj) { - if (followObject != obj) { - clearPatrolPoints(); + synchronized (targetMutex) { + if (followObject != obj) { + clearPatrolPoints(); - followObject = obj; + followObject = obj; + } } } + public SceneObject getFollowObject() { + return followObject; + } + public native void selectWeapon(); public native boolean validateStateAttack(CreatureObject target, string args); @@ -421,94 +522,94 @@ public native void clearDespawnEvent(); public float getKinetic() { - if (npcTemplate == null) + if (npcTemplate.get() == null) return 0; - return npcTemplate.getKinetic(); + return npcTemplate.get().getKinetic(); } public float getEnergy() { - if (npcTemplate == null) + if (npcTemplate.get() == null) return 0; - return npcTemplate.getEnergy(); + return npcTemplate.get().getEnergy(); } public float getElectricity() { - if (npcTemplate == null) + if (npcTemplate.get() == null) return 0; - return npcTemplate.getElectricity(); + return npcTemplate.get().getElectricity(); } public float getStun() { - if (npcTemplate == null) + if (npcTemplate.get() == null) return 0; - return npcTemplate.getStun(); + return npcTemplate.get().getStun(); } public float getBlast() { - if (npcTemplate == null) + if (npcTemplate.get() == null) return 0; - return npcTemplate.getBlast(); + return npcTemplate.get().getBlast(); } public float getHeat() { - if (npcTemplate == null) + if (npcTemplate.get() == null) return 0; - return npcTemplate.getHeat(); + return npcTemplate.get().getHeat(); } public float getCold() { - if (npcTemplate == null) + if (npcTemplate.get() == null) return 0; - return npcTemplate.getCold(); + return npcTemplate.get().getCold(); } public float getAcid() { - if (npcTemplate == null) + if (npcTemplate.get() == null) return 0; - return npcTemplate.getAcid(); + return npcTemplate.get().getAcid(); } public float getLightSaber() { - if (npcTemplate == null) + if (npcTemplate.get() == null) return 0; - return npcTemplate.getLightSaber(); + return npcTemplate.get().getLightSaber(); } public boolean isStalker() { - if (npcTemplate == null) + if (npcTemplate.get() == null) return false; - return npcTemplate.isStalker(); + return npcTemplate.get().isStalker(); } public boolean isKiller() { - if (npcTemplate == null) + if (npcTemplate.get() == null) return false; - return npcTemplate.isKiller(); + return npcTemplate.get().isKiller(); } public unsigned int getFerocity() { - if (npcTemplate == null) + if (npcTemplate.get() == null) return 0; - return npcTemplate.getFerocity(); + return npcTemplate.get().getFerocity(); } public unsigned int getArmor() { - if (npcTemplate == null) + if (npcTemplate.get() == null) return 0; - return npcTemplate.getArmor(); + return npcTemplate.get().getArmor(); } public boolean getDespawnOnNoPlayerInRange() { @@ -519,68 +620,81 @@ return numberOfPlayersInRange; } - @local - public DamageMap getDamageMap() { - return damageMap; - } - public string getFactionString() { - if (npcTemplate == null) + if (npcTemplate.get() == null) return ""; - return npcTemplate.getFaction(); + return npcTemplate.get().getFaction(); } public string getSocialGroup() { - if (npcTemplate == null) + if (npcTemplate.get() == null) return ""; - return npcTemplate.getSocialGroup(); + return npcTemplate.get().getSocialGroup(); } public float getChanceHit() { - if (npcTemplate == null) + if (npcTemplate.get() == null) return false; - return npcTemplate.getChanceHit(); + return npcTemplate.get().getChanceHit(); } public int getDamageMin() { - if (npcTemplate == null) + if (npcTemplate.get() == null) return 0; - return npcTemplate.getDamageMin(); + if (getWeapon() == null) + return 0; + + return getWeapon().getMinDamage(); + + //return npcTemplate.get().getDamageMin(); + //return calculateAttackMinDamage(super.getLevel()); } public int getDamageMax() { - if (npcTemplate == null) + if (npcTemplate.get() == null) return 0; - return npcTemplate.getDamageMax(); + if (getWeapon() == null) + return 0; + + //return npcTemplate.get().getDamageMax(); + return getWeapon().getMaxDamage(); } public int getBaseXp() { - if (npcTemplate == null) + if (npcTemplate.get() == null) return 0; - return npcTemplate.getBaseXp(); + return npcTemplate.get().getBaseXp(); } public unsigned int getDiet() { - if (npcTemplate == null) + if (npcTemplate.get() == null) return 0; - return npcTemplate.getDiet(); + return npcTemplate.get().getDiet(); } @local public CreatureAttackMap getAttackMap() { - if (npcTemplate == null) + if (npcTemplate.get() == null) return null; - return npcTemplate.getAttacks(); + return npcTemplate.get().getAttacks(); } + @local + public LootGroupCollection getLootGroups() { + if (npcTemplate.get() == null) + return null; + + return npcTemplate.get().getLootGroups(); + } + public float getRespawnTimer() { return respawnTimer; } @@ -594,18 +708,19 @@ return true; } - public void setLootOwner(CreatureObject owner) { - lootOwner = owner; + @local + public CreatureTemplate getCreatureTemplate() { + return npcTemplate.get(); } - public CreatureObject getLootOwner() { - return lootOwner; - } - /* * Place holder for when loot is implemented */ public boolean hasLoot() { return false; } + + public void setShowNextPosition(boolean val) { + showNextMovementPosition = val; + } }