diff --git a/src/intents/DanceIntent.java b/src/intents/DanceIntent.java
new file mode 100644
index 000000000..f1c778613
--- /dev/null
+++ b/src/intents/DanceIntent.java
@@ -0,0 +1,34 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package intents;
+
+import resources.control.Intent;
+import resources.objects.creature.CreatureObject;
+
+/**
+ *
+ * @author Mads
+ */
+public class DanceIntent extends Intent {
+ public static final String TYPE = "DanceIntent";
+ private final String danceName;
+ private final CreatureObject creatureObject;
+
+ public DanceIntent(String danceName, CreatureObject creatureObject) {
+ super(TYPE);
+ this.danceName = danceName;
+ this.creatureObject = creatureObject;
+ }
+
+ public String getDanceName() {
+ return danceName;
+ }
+
+ public CreatureObject getCreatureObject() {
+ return creatureObject;
+ }
+
+}
diff --git a/src/resources/commands/callbacks/StartDanceCallback.java b/src/resources/commands/callbacks/StartDanceCallback.java
new file mode 100644
index 000000000..d34b041d6
--- /dev/null
+++ b/src/resources/commands/callbacks/StartDanceCallback.java
@@ -0,0 +1,79 @@
+/**
+ * *********************************************************************************
+ * Copyright (c) 2015 /// Project SWG /// www.projectswg.com *
+ * *
+ * ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
+ * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
+ * Our goal is to create an emulator which will provide a server for players to *
+ * continue playing a game similar to the one they used to play. We are basing *
+ * it on the final publish of the game prior to end-game events. *
+ * *
+ * This file is part of Holocore. *
+ * *
+ * -------------------------------------------------------------------------------- *
+ * *
+ * Holocore is free software: you can redistribute it and/or modify *
+ * it under the terms of the GNU Affero General Public License as *
+ * published by the Free Software Foundation, either version 3 of the *
+ * License, or (at your option) any later version. *
+ * *
+ * Holocore is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU Affero General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Affero General Public License *
+ * along with Holocore. If not, see . * *
+ * *********************************************************************************
+ */
+package resources.commands.callbacks;
+
+import java.util.Map;
+import java.util.Set;
+import resources.commands.ICmdCallback;
+import resources.objects.SWGObject;
+import resources.objects.creature.CreatureObject;
+import resources.player.Player;
+import resources.sui.SuiButtons;
+import resources.sui.SuiEvent;
+import resources.sui.SuiListBox;
+import services.galaxy.GalacticManager;
+
+public class StartDanceCallback implements ICmdCallback {
+
+ private static final String ABILITY_NAME_PREFIX = "startDance+";
+
+ @Override
+ public void execute(GalacticManager galacticManager, Player player, SWGObject target, String args) {
+ CreatureObject creatureObject = player.getCreatureObject();
+
+ // Not sure if args can ever actually be null. Better safe than sorry.
+ if (args == null || args.isEmpty()) {
+ // If no args are given, then bring up the SUI window for dance selection.
+ SuiListBox listBox = new SuiListBox(SuiButtons.OK_CANCEL, "@performance:select_dance", "@performance:available_dances");
+ Set abilityNames = creatureObject.getAbilityNames();
+
+ for(String abilityName : abilityNames) {
+ if(abilityName.startsWith(ABILITY_NAME_PREFIX)) {
+ listBox.addListItem(abilityName.replace(ABILITY_NAME_PREFIX, ""));
+ }
+ }
+
+ listBox.addOkButtonCallback("handleSelectedItem", new resources.sui.ISuiCallback() {
+ @Override
+ public void handleEvent(Player player, SWGObject actor, SuiEvent event, Map parameters) {
+ int selection = SuiListBox.getSelectedRow(parameters);
+ String selectedDanceName = listBox.getListItem(selection).getName();
+
+ new intents.DanceIntent(selectedDanceName, player.getCreatureObject()).broadcast();
+ }
+ });
+
+ listBox.display(player);
+ } else {
+ new intents.DanceIntent(args, player.getCreatureObject()).broadcast();
+ }
+
+ }
+
+}
diff --git a/src/resources/objects/creature/CreatureObject.java b/src/resources/objects/creature/CreatureObject.java
index 177d4b083..74d152fec 100644
--- a/src/resources/objects/creature/CreatureObject.java
+++ b/src/resources/objects/creature/CreatureObject.java
@@ -719,6 +719,8 @@ public class CreatureObject extends TangibleObject {
public boolean hasAbility(String abilityName) { return abilities.get(abilityName) != null; }
+ public Set getAbilityNames() { return abilities.keySet(); };
+
public void setHealth(int health) {
synchronized(attributes) {
attributes.set(0, health);
diff --git a/src/services/commands/CommandService.java b/src/services/commands/CommandService.java
index 9db5f0bc7..4a02af2c3 100644
--- a/src/services/commands/CommandService.java
+++ b/src/services/commands/CommandService.java
@@ -226,6 +226,7 @@ public class CommandService extends Service {
registerCallback("revertPlayerAppearance", RevertAppearanceCallback.class);
registerCallback("qatool", QaToolCmdCallback.class);
registerCallback("goto", GotoCmdCallback.class);
+ registerCallback("startDance", StartDanceCallback.class);
}
private void clearCommands() {
diff --git a/src/services/commands/EntertainmentService.java b/src/services/commands/EntertainmentService.java
new file mode 100644
index 000000000..25ee6f858
--- /dev/null
+++ b/src/services/commands/EntertainmentService.java
@@ -0,0 +1,69 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package services.commands;
+
+import intents.DanceIntent;
+import intents.chat.ChatBroadcastIntent;
+import java.util.HashMap;
+import java.util.Map;
+import resources.Posture;
+import resources.control.Intent;
+import resources.control.Service;
+import resources.objects.creature.CreatureObject;
+
+/**
+ *
+ * @author Mads
+ */
+public class EntertainmentService extends Service {
+
+ private final Map danceMap;
+
+ public EntertainmentService() {
+ danceMap = new HashMap<>();
+ registerForIntent(DanceIntent.TYPE);
+ }
+
+ @Override
+ public boolean initialize() {
+ danceMap.put("basic", 1); // TODO load data from datatables/performance/performance.iff
+
+ return super.initialize();
+ }
+
+ @Override
+ public void onIntentReceived(Intent i) {
+ switch(i.getType()) {
+ case DanceIntent.TYPE: handleDanceIntent((DanceIntent) i); break;
+ }
+ }
+
+ private void handleDanceIntent(DanceIntent i) {
+ CreatureObject dancer = i.getCreatureObject();
+ String danceName = i.getDanceName();
+
+ if(danceMap.containsKey(danceName)) {
+ // The dance name is valid.
+ // TODO check if the dancer is allowed to perform this dance.
+ startDancing(dancer, "dance_" + danceMap.get(danceName));
+ } else {
+ // This dance name is invalid
+ new ChatBroadcastIntent(dancer.getOwner(), "@performance:dance_unknown_self").broadcast();
+ System.out.println("dance " + danceName + " is an invalid dance"); // DEBUG
+ }
+ }
+
+ private void startDancing(CreatureObject dancer, String danceId) {
+ System.out.println(dancer + " is now performing dance id: " + danceId);
+ dancer.setAnimation(danceId);
+ dancer.setPerformanceId(0); // 0 - anything else will make it look like we're playing music
+ dancer.setPerformanceCounter(dancer.getPerformanceCounter() + 1); // TODO is this correct?
+ dancer.setPerforming(true);
+ dancer.setPosture(Posture.SKILL_ANIMATING);
+ new ChatBroadcastIntent(dancer.getOwner(), "@performance:dance_start_self").broadcast();
+ }
+
+}
diff --git a/src/services/galaxy/GameManager.java b/src/services/galaxy/GameManager.java
index 21605db1c..792ecb043 100644
--- a/src/services/galaxy/GameManager.java
+++ b/src/services/galaxy/GameManager.java
@@ -30,6 +30,7 @@ package services.galaxy;
import resources.control.Manager;
import services.collections.CollectionBadgeManager;
import services.commands.CommandService;
+import services.commands.EntertainmentService;
import services.faction.FactionService;
import services.galaxy.terminals.TerminalService;
import services.sui.SuiService;
@@ -45,7 +46,7 @@ public class GameManager extends Manager {
private final FactionService factionService;
//private final GroupService groupService;
private final SkillModService skillModService;
-
+ private final EntertainmentService entertainmentService;
public GameManager() {
commandService = new CommandService();
@@ -57,6 +58,7 @@ public class GameManager extends Manager {
factionService = new FactionService();
// groupService = new GroupService();
skillModService = new SkillModService();
+ entertainmentService = new EntertainmentService();
addChildService(commandService);
addChildService(connectionService);
@@ -67,5 +69,6 @@ public class GameManager extends Manager {
addChildService(factionService);
// addChildService(groupService);
addChildService(skillModService);
+ addChildService(entertainmentService);
}
}