From 471fab10d8d775aeb978654604b969cae22ddb9a Mon Sep 17 00:00:00 2001 From: darkk1138 Date: Mon, 9 Dec 2013 17:19:53 +0100 Subject: [PATCH] refactored slightly.. wasted a lot of time with that. :p --- scripts/commands/startdance.py | 6 +- scripts/commands/stopwatching.py | 2 +- .../objects/creature/CreatureObject.java | 112 +++++++++--------- src/services/EntertainmentService.java | 16 ++- 4 files changed, 78 insertions(+), 58 deletions(-) diff --git a/scripts/commands/startdance.py b/scripts/commands/startdance.py index 54433344..768e8e55 100644 --- a/scripts/commands/startdance.py +++ b/scripts/commands/startdance.py @@ -59,6 +59,7 @@ def startDance(core, actor, danceName, visual): visual = entSvc.getDanceVisualId(danceName) if visual <= 0: + actor.sendSystemMessage('@performance:dance_unknown_self',0) return if not entSvc.isDance(visual): @@ -85,7 +86,8 @@ def startDance(core, actor, danceName, visual): if not actor.getPerformanceWatchee(): #this also notifies the client with a delta4 actor.setPerformanceWatchee(actor) - + actor.addAudience(actor) + #this should send a CREO3 actor.setPosture(0x09); @@ -95,6 +97,6 @@ def startDance(core, actor, danceName, visual): # instead of dance.getLineNumber() # send CREO6 here # second param is some sort of counter or start tick - actor.startPerformance(0, -842249156 , danceVisual, 1) + entSvc.startPerformance(actor, 0, -842249156 , danceVisual, 1) return diff --git a/scripts/commands/stopwatching.py b/scripts/commands/stopwatching.py index d40726f6..7dc96fc8 100644 --- a/scripts/commands/stopwatching.py +++ b/scripts/commands/stopwatching.py @@ -8,8 +8,8 @@ def run(core, actor, target, commandString): if not dancer: return - dancer.removeAudience(actor) actor.setPerformanceWatchee(None) + dancer.removeAudience(actor) if not actor.getPerformanceListenee(): actor.setMoodAnimation('') diff --git a/src/resources/objects/creature/CreatureObject.java b/src/resources/objects/creature/CreatureObject.java index 586c81c2..c2d1a7da 100644 --- a/src/resources/objects/creature/CreatureObject.java +++ b/src/resources/objects/creature/CreatureObject.java @@ -343,7 +343,51 @@ public class CreatureObject extends TangibleObject implements IPersistent { } } + + public void startPerformance() { + + getClient().getSession().write(messageBuilder.buildStartPerformance(true)); + + } + + public void stopPerformance() { + String type = ""; + synchronized(objectMutex) { + setPerformanceId(0); + setPerformanceCounter(0); + setCurrentAnimation(""); + type = (performanceType) ? "dance" : "music"; + } + + sendSystemMessage("@performance:" + type + "_stop_self",(byte)0); + stopAudience(); + getClient().getSession().write(messageBuilder.buildStartPerformance(false)); + } + + public void stopAudience() { + String type = ""; + synchronized(objectMutex) { + type = (performanceType) ? "dance" : "music"; + Iterator it = audience.iterator(); + while (it.hasNext()) { + CreatureObject next = it.next(); + if ((performanceType) && (next.getPerformanceWatchee() != this)) { continue; } + if ((!performanceType) && (next.getPerformanceListenee() != this)) { continue; } + if (performanceType) { next.setPerformanceWatchee(null); } + if (!performanceType) { next.setPerformanceListenee(null); } + //this may be a bit dodgy. + boolean isEntertained = next.getPerformanceListenee() != null && next.getPerformanceWatchee() != null; + if (!isEntertained) { + next.setMoodAnimation(""); + } + if (next == this) { continue; } + next.sendSystemMessage("@performance:" + type + "_stop_other",(byte)0); + } + //not sure if this behaviour is correct. might need fixing later. + audience = Collections.synchronizedList(new ArrayList()); + } + } @Override public void setFaction(String faction) { synchronized(objectMutex) { @@ -918,6 +962,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { synchronized(objectMutex) { this.performanceCounter = performanceCounter; } + getClient().getSession().write(messageBuilder.buildPerformanceCounter(performanceCounter)); } public int getPerformanceId() { @@ -930,6 +975,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { synchronized(objectMutex) { this.performanceId = performanceId; } + getClient().getSession().write(messageBuilder.buildPerformanceId(performanceId)); } public boolean getAcceptBandflourishes() { @@ -1424,61 +1470,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { getClient().getSession().write(messageBuilder.buildListenToId(this.listenToId)); } - public void startPerformance(int performanceId, int performanceCounter, String skillName, boolean isDance) { - synchronized(objectMutex) { - this.performanceId = performanceId; - this.performanceCounter = performanceCounter; - this.currentAnimation = skillName; - this.performanceType = isDance; - } - - getClient().getSession().write(messageBuilder.buildPerformanceId(performanceId)); - getClient().getSession().write(messageBuilder.buildPerformanceCounter(performanceCounter)); - getClient().getSession().write(messageBuilder.buildCurrentAnimationDelta(skillName)); - getClient().getSession().write(messageBuilder.buildStartPerformance(true)); - - } - - public void stopPerformance() { - String type = ""; - synchronized(objectMutex) { - this.performanceId = 0; - this.performanceCounter = 0; - this.currentAnimation = null; - type = (performanceType) ? "dance" : "music"; - } - - sendSystemMessage("@performance:" + type + "_stop_self",(byte)0); - stopAudience(); - getClient().getSession().write(messageBuilder.buildPerformanceId(performanceId)); - getClient().getSession().write(messageBuilder.buildPerformanceCounter(performanceCounter)); - getClient().getSession().write(messageBuilder.buildStartPerformance(false)); - } - - public void stopAudience() { - String type = ""; - synchronized(objectMutex) { - type = (performanceType) ? "dance" : "music"; - Iterator it = audience.iterator(); - while (it.hasNext()) { - CreatureObject next = it.next(); - if ((performanceType) && (next.getPerformanceWatchee() != this)) { continue; } - if ((!performanceType) && (next.getPerformanceListenee() != this)) { continue; } - if (performanceType) { next.setPerformanceWatchee(null); } - if (!performanceType) { next.setPerformanceListenee(null); } - //this may be a bit dodgy. - boolean isEntertained = next.getPerformanceListenee() != null && next.getPerformanceWatchee() != null; - if (!isEntertained) { - next.setMoodAnimation(""); - } - if (next == this) { continue; } - next.sendSystemMessage("@performance:" + type + "_stop_other",(byte)0); - } - //not sure if this behaviour is correct. might need fixing later. - audience = Collections.synchronizedList(new ArrayList()); - } - } @Override public void setPvPBitmask(int pvpBitmask) { @@ -1505,5 +1497,17 @@ public class CreatureObject extends TangibleObject implements IPersistent { notifyObservers(messageBuilder.buildDifficultyDelta(difficulty), true); } + + public void setPerformanceType(boolean isDance) { + synchronized(objectMutex) { + this.performanceType = isDance; + } + } + + public boolean getPerformanceType() { + synchronized(objectMutex) { + return this.performanceType; + } + } } diff --git a/src/services/EntertainmentService.java b/src/services/EntertainmentService.java index 60a6d7a0..5236846b 100644 --- a/src/services/EntertainmentService.java +++ b/src/services/EntertainmentService.java @@ -221,6 +221,8 @@ public class EntertainmentService implements INetworkDispatch { core.commandService.registerCommand("groupdance"); core.commandService.registerCommand("startdance"); core.commandService.registerCommand("stopdance"); + core.commandService.registerCommand("watch"); + core.commandService.registerCommand("stopwatching"); } public void giveInspirationBuff(SWGObject reciever, Vector buffVector) { @@ -251,7 +253,7 @@ public class EntertainmentService implements INetworkDispatch { Performance p = performances.get(danceName); //if 0 , then it's no dance. need to handle that in the script. - return p.getDanceVisualId(); + return ((p == null) ? 0 : p.getDanceVisualId()); } public Map getAvailableDances(CreatureObject actor) { @@ -290,6 +292,18 @@ public class EntertainmentService implements INetworkDispatch { return performances.get(name); } + public void startPerformance(CreatureObject actor, int performanceId, int performanceCounter, String skillName, boolean isDance) { + actor.setPerformanceId(performanceId); + actor.setPerformanceCounter(performanceCounter); + actor.setCurrentAnimation(skillName); + actor.setPerformanceType(isDance); + + actor.startPerformance(); + } + + + + @Override public void shutdown() {