diff --git a/scripts/commands/bandflourish.py b/scripts/commands/bandflourish.py new file mode 100644 index 00000000..75c17b32 --- /dev/null +++ b/scripts/commands/bandflourish.py @@ -0,0 +1,57 @@ +import sys + +def setup(): + return + +def run(core, actor, target, commandString): + + if len(commandString) <= 0: + actor.sendSystemMessage('@performance:flourish_not_valid', 0) + return + + if commandString == 'on': + actor.setAcceptBandflourishes(1) + actor.sendSystemMessage('@performance:band_flourish_status_on', 0) + return + if commandString == 'off': + actor.setAcceptBandflourishes(0) + actor.sendSystemMessage('@performance:band_flourish_status_off', 0) + return + + try: + flourish = int(commandString) + except ValueError: + actor.sendSystemMessage('@performance:flourish_not_valid', 0) + return + + if flourish < 1 or flourish > 9: + actor.sendSystemMessage('@performance:flourish_not_valid', 0) + return + + if actor.getPerformanceId() <= 0: + actor.sendSystemMessage('@performance:flourish_not_performing', 0) + return + + animation = 'skill_action_' + str(flourish) + if flourish == 9: + animation = 'mistake' + + group = core.objectService.getObject(actor.getGroupId()) + if not group: + if actor.getAcceptBandflourishes(): + actor.sendSystemMessage('@performance:flourish_perform_band_self', 0) + actor.sendSystemMessage('@performance:flourish_perform', 0) + actor.doSkillAnimation(animation) + return + + for creature in group.getMemberList(): + if creature.getAcceptBandflourishes(): + if actor == creature: + creature.sendSystemMessage('@performance:flourish_perform_band_self', 0) + else: + creature.sendSystemMessage('@performance:flourish_perform_band_member', 0) + creature.sendSystemMessage('@performance:flourish_perform', 0) + creature.doSkillAnimation(animation) + return + + diff --git a/scripts/commands/flourish.py b/scripts/commands/flourish.py new file mode 100644 index 00000000..0bb6cb93 --- /dev/null +++ b/scripts/commands/flourish.py @@ -0,0 +1,31 @@ +import sys + +def setup(): + return + +def run(core, actor, target, commandString): + + if len(commandString) <= 0: + actor.sendSystemMessage('@performance:flourish_not_valid', 0) + return + + try: + flourish = int(commandString) + except ValueError: + actor.sendSystemMessage('@performance:flourish_not_valid', 0) + return + + if flourish < 1 or flourish > 9: + actor.sendSystemMessage('@performance:flourish_not_valid', 0) + return + + if actor.getPerformanceId() <= 0: + actor.sendSystemMessage('@performance:flourish_not_performing', 0) + return + + actor.sendSystemMessage('@performance:flourish_perform', 0) + animation = 'skill_action_' + str(flourish) + if flourish == 9: + animation = 'mistake' + + actor.doSkillAnimation(animation) diff --git a/scripts/commands/startdance.py b/scripts/commands/startdance.py index a8d78ed7..18aa211c 100644 --- a/scripts/commands/startdance.py +++ b/scripts/commands/startdance.py @@ -12,23 +12,28 @@ def setup(): def run(core, actor, target, commandString): entSvc = core.entertainmentService + global actorObject + global coreObject + global availableDances + global suiWindow + actorObject = actor + coreObject = core if len(commandString) > 0: params = commandString.split(" ") - startDance(core, actor, params[0]) + startDance(core, actor, params[0], 0) return else: - available_dances = entSvc.getAvailableDances(actor) + availableDances = entSvc.getAvailableDances(actor) + print availableDances suiSvc = core.suiService - suiWindow = suiSvc.createListBox(ListBoxType.LIST_BOX_OK_CANCEL, "@performance:select_dance", "@performance:available_dances", available_dances, actor, actor, 10) + suiWindow = suiSvc.createListBox(ListBoxType.LIST_BOX_OK_CANCEL, "@performance:select_dance", "@performance:available_dances", availableDances, actor, None, 10) - returnParams = Vector() - returnParams.add('btnOk:Text') - returnParams.add('btnCancel:Text') - suiWindow.addHandler(0, '', Trigger.TRIGGER_OK, returnParams, handleStartdance) - suiWindow.addHandler(1, '', Trigger.TRIGGER_CANCEL, returnParams, handleStartdance) + returnList = Vector() + returnList.add("List.lstList:SelectedRow") + suiWindow.addHandler(0, '', Trigger.TRIGGER_OK, returnList, handleStartdance) suiSvc.openSUIWindow(suiWindow) return @@ -36,40 +41,56 @@ def run(core, actor, target, commandString): def handleStartdance(core, owner, eventType, returnList): + + item = suiWindow.getMenuItems().get(int(returnList.get(0))) + + if not item: + return + + #if eventType == 0: + startDance(coreObject, actorObject, '', int(item.getObjectId())) return -def startDance(core, actor, danceName): +def startDance(core, actor, danceName, visual): entSvc = core.entertainmentService - if not entSvc.isDance(danceName): + if visual <= 0: + visual = entSvc.getDanceVisualId(danceName) + + if visual <= 0: + return + + if not entSvc.isDance(visual): actor.sendSystemMessage('@performance:dance_unknown_self',0) return - if not entSvc.canDance(actor, danceName): + if not entSvc.canDance(actor, visual): actor.sendSystemMessage('@performance:dance_lack_skill_self',0) return - return if actor.getPerformanceId() > 0: actor.sendSystemMessage('@performance:already_performing_self',0) return - performance = entSvc.getPerformance(danceName) - #TODO: check costume, posture, etc + #TODO: check costume, posture, etc? - actor.sendSystemMessage('@performance:dance_start_self'); + actor.sendSystemMessage('@performance:dance_start_self',0); actor.notifyAudience('@performance:dance_start_other'); + danceVisual = 'dance_' + str(visual) + if not actor.getPerformanceWatchee(): - #this also needs to notify the client with a delta4 + #this also notifies the client with a delta4 actor.setPerformanceWatchee(actor) - + #this should send a CREO3 actor.setPosture(0x09); + + dance = entSvc.getDance(visual) + # send CREO6 here # second param is some sort of counter or start tick - actor.startPerformance(performance.getLineNumber(), 0xCDCC4C3C, 'dance_' . performance.getVisualId true) - - + actor.startPerformance(dance.getLineNumber(), -842249156 , danceVisual, 1) + return diff --git a/scripts/commands/stopdance.py b/scripts/commands/stopdance.py new file mode 100644 index 00000000..0f2d4763 --- /dev/null +++ b/scripts/commands/stopdance.py @@ -0,0 +1,19 @@ +import sys + +def setup(): + return + +def run(core, actor, target, commandString): + entSvc = core.entertainmentService + + if (actor.getPerformanceId() <= 0): + actor.sendSystemMessage('@performance:dance_not_performing', 0) + return + + #since we need to stop performance for any posture change, + # all packets are triggered in setPosture. + # this may not be very consistent, but it prevents + # duplicate code. + actor.setPosture(0x00) + + return diff --git a/src/resources/objects/creature/CreatureMessageBuilder.java b/src/resources/objects/creature/CreatureMessageBuilder.java index 042f12eb..39f35820 100644 --- a/src/resources/objects/creature/CreatureMessageBuilder.java +++ b/src/resources/objects/creature/CreatureMessageBuilder.java @@ -1000,7 +1000,7 @@ public class CreatureMessageBuilder extends ObjectMessageBuilder { buffer.putInt(performanceId); int size = buffer.position(); buffer.flip(); - buffer = createDelta("CREO", (byte) 6, (short) 1, (short) 2, buffer, size + 4); + buffer = createDelta("CREO", (byte) 6, (short) 1, (short) 0x14, buffer, size + 4); return buffer; } @@ -1009,15 +1009,7 @@ public class CreatureMessageBuilder extends ObjectMessageBuilder { buffer.putInt(performanceCounter); int size = buffer.position(); buffer.flip(); - buffer = createDelta("CREO", (byte) 6, (short) 1, (short) 2, buffer, size + 4); - return buffer; - } - - public IoBuffer buildSkillName(String skillName) { - IoBuffer buffer = bufferPool.allocate(getUnicodeString(skillName).length, false).order(ByteOrder.LITTLE_ENDIAN); - int size = buffer.position(); - buffer.flip(); - buffer = createDelta("CREO", (byte) 6, (short) 1, (short) 2, buffer, size + 4); + buffer = createDelta("CREO", (byte) 6, (short) 1, (short) 0x13, buffer, size + 4); return buffer; } @@ -1026,7 +1018,7 @@ public class CreatureMessageBuilder extends ObjectMessageBuilder { buffer.put((byte) ((doStart) ? 1 : 0)); int size = buffer.position(); buffer.flip(); - buffer = createDelta("CREO", (byte) 6, (short) 1, (short) 2, buffer, size + 4); + buffer = createDelta("CREO", (byte) 6, (short) 1, (short) 0x1B, buffer, size + 4); return buffer; } diff --git a/src/resources/objects/creature/CreatureObject.java b/src/resources/objects/creature/CreatureObject.java index b1787033..c2ce6fff 100644 --- a/src/resources/objects/creature/CreatureObject.java +++ b/src/resources/objects/creature/CreatureObject.java @@ -57,7 +57,7 @@ import resources.objects.tangible.TangibleObject; import resources.objects.weapon.WeaponObject; -@Entity(version=4) +@Entity(version=5) public class CreatureObject extends TangibleObject implements IPersistent { @NotPersistent @@ -117,6 +117,11 @@ public class CreatureObject extends TangibleObject implements IPersistent { private byte moodId = 0; private int performanceCounter = 0; private int performanceId = 0; + //FIXME: this is a bit of a hack. + private boolean performanceType = false; + //FIXME: hmm.. or persistent? + @NotPersistent + private boolean acceptBandflourishes = true; private CreatureObject performanceWatchee; private CreatureObject performanceListenee; private int health = 1000; @@ -296,15 +301,25 @@ public class CreatureObject extends TangibleObject implements IPersistent { } public void setPosture(byte posture) { + boolean needsStopPerformance = false; synchronized(objectMutex) { + if (this.posture == 0x09) { + needsStopPerformance = true; + } this.posture = posture; } + IoBuffer postureDelta = messageBuilder.buildPostureDelta(posture); Posture postureUpdate = new Posture(getObjectID(), posture); ObjControllerMessage objController = new ObjControllerMessage(0x1B, postureUpdate); notifyObservers(postureDelta, true); notifyObservers(objController, true); + + if (needsStopPerformance) { + stopPerformance(); + } + } @Override @@ -738,6 +753,14 @@ public class CreatureObject extends TangibleObject implements IPersistent { notifyObservers(messageBuilder.buildCurrentAnimationDelta(currentAnimation), true); } + + public void doSkillAnimation(String skillAnimation) { + Animation animation = new Animation(getObjectId(), skillAnimation); + ObjControllerMessage objController = new ObjControllerMessage(0x1B, animation); + + notifyObservers(objController, true); + + } public String getMoodAnimation() { synchronized(objectMutex) { @@ -885,6 +908,14 @@ public class CreatureObject extends TangibleObject implements IPersistent { } } + public boolean getAcceptBandflourishes() { + return acceptBandflourishes; + } + + public void setAcceptBandflourishes(boolean acceptBandflourishes) { + this.acceptBandflourishes = acceptBandflourishes; + } + public SWGList getEquipmentList() { return equipmentList; } @@ -1324,26 +1355,41 @@ public class CreatureObject extends TangibleObject implements IPersistent { } } - public void startPerformance(int performanceId, int performanceCounter, String skillName, boolean doStart) { + 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; } - if (doStart) { getClient().getSession().write(messageBuilder.buildPerformanceId(performanceId)); } - if (doStart) { getClient().getSession().write(messageBuilder.buildPerformanceCounter(performanceCounter)); } - if (doStart) { getClient().getSession().write(messageBuilder.buildSkillName(skillName)); } - getClient().getSession().write(messageBuilder.buildStartPerformance(doStart)); + 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 notifyAudience() { + 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); + notifyAudience("@performance:" + type + "_stop_other"); + + getClient().getSession().write(messageBuilder.buildStartPerformance(false)); + } + + public void notifyAudience(String message) { //TODO: stub } - - - + @Override public void setPvPBitmask(int pvpBitmask) { super.setPvPBitmask(pvpBitmask); diff --git a/src/services/EntertainmentService.java b/src/services/EntertainmentService.java index 2d262da6..6882c8a8 100644 --- a/src/services/EntertainmentService.java +++ b/src/services/EntertainmentService.java @@ -216,6 +216,9 @@ public class EntertainmentService implements INetworkDispatch { private void registerCommands() { core.commandService.registerCommand("startdance"); + core.commandService.registerCommand("stopdance"); + core.commandService.registerCommand("flourish"); + core.commandService.registerCommand("bandflourish"); } public void giveInspirationBuff(SWGObject reciever, Vector buffVector) { @@ -242,20 +245,27 @@ public class EntertainmentService implements INetworkDispatch { } + public int getDanceVisualId(String danceName) { + Performance p = performances.get(danceName); + + //if 0 , then it's no dance. need to handle that in the script. + return p.getDanceVisualId(); + } + public Map getAvailableDances(CreatureObject actor) { Map dances = new HashMap(); for (int index : danceMap.keySet()) { if (!canDance(actor, danceMap.get(index) )) { continue; } - dances.put( new Long(index), danceMap.get(index).getPerformanceName() ); + dances.put( new Long( danceMap.get(index).getDanceVisualId() ), danceMap.get(index).getPerformanceName() ); } return dances; } - public boolean isDance(String danceName) { - return ( performances.get(danceName) != null && performances.get(danceName).getType() == -1788534963); + public boolean isDance(int visualId) { + return ( danceMap.get(visualId) != null ) ; } public boolean canDance(CreatureObject actor, Performance dance) { @@ -265,9 +275,13 @@ public class EntertainmentService implements INetworkDispatch { return false; } - public boolean canDance(CreatureObject actor, String danceName) { - if (!isDance(danceName)) { return false; } - return canDance(actor, performances.get(danceName)); + public boolean canDance(CreatureObject actor, int visualId) { + if (!isDance(visualId)) { return false; } + return canDance(actor, danceMap.get(visualId)); + } + + public Performance getDance(int visualId) { + return danceMap.get(visualId); } public Performance getPerformance(String name) {