From bfc1653d686187e82fcc8834d70d7a2b8d9046cd Mon Sep 17 00:00:00 2001 From: wallaceg09 Date: Tue, 4 Nov 2014 22:22:05 -0600 Subject: [PATCH] Refactored EntertainmentService to to allow music to function properly Modified startdance script to work with the refactored EntertainmentService --- scripts/commands/startdance.py | 4 +- src/services/EntertainmentService.java | 81 ++++++++++++++++++++++++-- 2 files changed, 79 insertions(+), 6 deletions(-) diff --git a/scripts/commands/startdance.py b/scripts/commands/startdance.py index ce557827..aec96252 100644 --- a/scripts/commands/startdance.py +++ b/scripts/commands/startdance.py @@ -56,7 +56,9 @@ def startDance(core, actor, danceName, visual): entSvc = core.entertainmentService if visual <= 0: - visual = entSvc.getDanceVisualId(danceName) + print("[PYTHON] startdance.visual = " , visual) + visual = entSvc.getDanceVisualId(danceName) + print("[PYTHON] startdance.visual = " , visual) if visual <= 0: actor.sendSystemMessage('@performance:dance_unknown_self',0) diff --git a/src/services/EntertainmentService.java b/src/services/EntertainmentService.java index 68907056..7af4ba9b 100644 --- a/src/services/EntertainmentService.java +++ b/src/services/EntertainmentService.java @@ -4,6 +4,7 @@ import java.nio.ByteOrder; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import java.util.Vector; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executors; @@ -13,6 +14,7 @@ import java.util.concurrent.TimeUnit; import main.NGECore; +import org.apache.commons.collections.iterators.EntrySetMapIterator; import org.apache.mina.core.buffer.IoBuffer; import org.apache.mina.core.session.IoSession; @@ -52,7 +54,7 @@ public class EntertainmentService implements INetworkDispatch { private Vector buffBuilderSkills = new Vector(); //FIXME: create a wrapper class for double key lookup maps - private ConcurrentHashMap performances = new ConcurrentHashMap(); + private ConcurrentHashMap performances = new ConcurrentHashMap(); private ConcurrentHashMap performancesByIndex = new ConcurrentHashMap(); private ConcurrentHashMap danceMap = new ConcurrentHashMap(); @@ -68,6 +70,9 @@ public class EntertainmentService implements INetworkDispatch { this.core = core; populateSkillCaps(); populatePerformanceTable(); + + System.out.printf("[DEBUG] number_of_performances: %d\n", performances.size()); + populatePerformanceEffects(); registerCommands(); loadCharacterCustomizationData(); @@ -437,13 +442,21 @@ public class EntertainmentService implements INetworkDispatch { if (p.getType() == -1788534963) { danceMap.put(new Integer(p.getDanceVisualId()), p); } - performances.put(p.getPerformanceName(), p); + performances.put(new PerformanceUID(p.getPerformanceName(), p.getInstrumentAudioId()), p); performancesByIndex.put(r, p); } } catch (InstantiationException | IllegalAccessException e) { e.printStackTrace(); } + + //TODO: Remove + Set debugSet = performances.keySet(); + for(PerformanceUID uid : debugSet) + { + System.out.println(uid.toString()); + } + } private void populateSkillCaps() { @@ -608,13 +621,15 @@ public class EntertainmentService implements INetworkDispatch { }*/ } + //FIXME: Refactor using new map --Complete-- public int getDanceVisualId(String danceName) { - Performance p = performances.get(danceName); + Performance p = getPerformance(danceName, 0); //if 0 , then it's no dance. need to handle that in the script. return ((p == null) ? 0 : p.getDanceVisualId()); } + //FIXME: Refactor using new map ?? Perhaps not ?? public Map getAvailableDances(CreatureObject actor) { Map dances = new HashMap(); @@ -627,6 +642,7 @@ public class EntertainmentService implements INetworkDispatch { } + //FIXME: if visualId > 0 then it is a dance... public boolean isDance(int visualId) { return ( danceMap.get(visualId) != null ) ; } @@ -647,8 +663,10 @@ public class EntertainmentService implements INetworkDispatch { return danceMap.get(visualId); } - public Performance getPerformance(String name) { - return performances.get(name); + //FIXME: Refactor using new map -COMPLETE- + //FIXME: Returning null for known combination... + public Performance getPerformance(String name, int instrumentAudioId) { + return performances.get(new PerformanceUID(name, instrumentAudioId)); } public Performance getPerformanceByIndex(int index) { @@ -757,6 +775,7 @@ public class EntertainmentService implements INetworkDispatch { performer.sendSystemMessage("@performance:flourish_wait_self", (byte) 0); return; } + //FIXME: I don't think this will work. Performance performance = getPerformanceByIndex(performer.getPerformanceId()); if(performance == null) @@ -991,5 +1010,57 @@ public class EntertainmentService implements INetworkDispatch { public void shutdown() { } + + /** + * @author Glen + * This class serves as a unique id for performances. + * The performance.iff file is structured very similar to a database, and with that idea in mind + * this helper-class will serve as essentially the primary key of each performance. + */ + private class PerformanceUID + { + private final String performanceName; + private final int instrumentAudioId; + + public PerformanceUID(String performanceName, int instrumentAudioId) + { + this.performanceName = performanceName; + this.instrumentAudioId = instrumentAudioId; + } + + public boolean equals(PerformanceUID other) { + if(other != null) + { + if(this.performanceName == other.performanceName && this.instrumentAudioId == other.instrumentAudioId) + { + return true; + } + } + return false; + } + + @Override + public boolean equals(Object obj) { + if(obj != null && this.getClass() == obj.getClass() && this.performanceName.equals(((PerformanceUID)obj).performanceName) && this.instrumentAudioId == ((PerformanceUID)obj).instrumentAudioId) + { + return true; + } + return false; + } + + @Override + public int hashCode() { + return this.performanceName != null ? performanceName.hashCode() * 37 + instrumentAudioId: instrumentAudioId; +// int hash = performanceName.hashCode() ^ instrumentAudioId; +// return hash; + } + + @Override + public String toString() { + return "PerformanceUID [performanceName=" + performanceName + + ", instrumentAudioId=" + instrumentAudioId + ", hashCode = " + hashCode() + "]"; + } + + } }