Initial ent XP work

This commit is contained in:
Mads Boddum
2016-09-08 21:11:08 +02:00
parent 633675c3b6
commit fc3eb8f6c4
+93 -13
View File
@@ -57,8 +57,8 @@ public class EntertainmentService extends Service {
// TODO: when performing, make NPCs in a radius of x look towards the player (?) and clap. When they stop, turn back (?) and stop clapping
private static final byte XP_CYCLE_RATE = 10;
private final Map<String, Integer> danceMap; // dance performanceNames mapped to danceId
private final Map<CreatureObject, Future<?>> performerMap;
private final Map<String, PerformanceData> danceMap; // dance performanceNames mapped to danceId
private final Map<CreatureObject, Performance> performerMap;
private final ScheduledExecutorService executorService;
public EntertainmentService() {
@@ -79,7 +79,11 @@ public class EntertainmentService extends Service {
// Load the dances only. Music is currently unsupported.
if (!requiredDance.isEmpty()) {
danceMap.put((String) performanceTable.getCell(i, 0), (int) performanceTable.getCell(i, 5)); // performanceName, danceVisualId
PerformanceData performanceData = new PerformanceData(
String.valueOf(performanceTable.getCell(i, 5)), // danceVisualId
(int) performanceTable.getCell(i, 10)); // flourishXpMod
danceMap.put((String) performanceTable.getCell(i, 0), performanceData); // Map the name to the performance data
}
}
@@ -117,7 +121,7 @@ public class EntertainmentService extends Service {
} else if (danceMap.containsKey(danceName)) {
// The dance name is valid.
if (dancer.hasAbility("startDance+" + danceName)) {
startDancing(dancer, "dance_" + danceMap.get(danceName));
startDancing(dancer, danceMap.get(danceName).getPerformanceId());
} else {
// This creature doesn't have the ability to perform this dance.
new ChatBroadcastIntent(dancer.getOwner(), "@performance:dance_lack_skill_self").broadcast();
@@ -150,7 +154,7 @@ public class EntertainmentService extends Service {
case PE_ZONE_IN_SERVER:
// We need to check if they're dancing in order to start giving them XP
if(creature.getPosture().equals(Posture.SKILL_ANIMATING)) {
scheduleExperienceTask(creature);
scheduleExperienceTask(creature, );
}
break;
@@ -161,6 +165,9 @@ public class EntertainmentService extends Service {
Player performer = i.getPerformer();
CreatureObject performerObject = performer.getCreatureObject();
// TODO performance counter check
performerObject.setPerformanceCounter(performerObject.getPerformanceCounter() + 1);
// Send the flourish animation to the owner of the creature and owners of creatures observing
performerObject.sendObserversAndSelf(new Animation(performerObject.getObjectId(), i.getFlourishName()));
new ChatBroadcastIntent(performer, "@performance:flourish_perform").broadcast();
@@ -175,17 +182,27 @@ public class EntertainmentService extends Service {
return performer.hasSkill("class_entertainer_phase1_novice"); // First entertainer skillbox
}
private void scheduleExperienceTask(CreatureObject performer) {
private void scheduleExperienceTask(CreatureObject performer, String performanceName) {
Log.d(this, "Scheduled %s to receive XP every %d seconds", performer, XP_CYCLE_RATE);
synchronized(performerMap) {
performerMap.put(performer, executorService.scheduleAtFixedRate(new EntertainerExperience(performer), XP_CYCLE_RATE, XP_CYCLE_RATE, TimeUnit.SECONDS));
Future<?> future = executorService.scheduleAtFixedRate(new EntertainerExperience(performer), XP_CYCLE_RATE, XP_CYCLE_RATE, TimeUnit.SECONDS);
Performance performance = new Performance(future, performanceName);
performerMap.put(performer, performance);
}
}
private void cancelExperienceTask(CreatureObject performer) {
Log.d(this, "%s no longer receives XP every %d seconds", performer, XP_CYCLE_RATE);
synchronized (performerMap) {
Future<?> future = performerMap.remove(performer);
Performance performance = performerMap.remove(performer);
if(performance == null) {
Log.e(this, "Couldn't cancel experience task for %s because they weren't found in performerMap", performer);
return;
}
Future<?> future = performance.getFuture();
// TODO null check?
// TODO use return result?
@@ -193,15 +210,15 @@ public class EntertainmentService extends Service {
}
}
private void startDancing(CreatureObject dancer, String danceId) {
dancer.setAnimation(danceId);
private void startDancing(CreatureObject dancer, String performanceName) {
dancer.setAnimation("dance_" + performanceName);
dancer.setPerformanceId(0); // 0 - anything else will make it look like we're playing music
dancer.setPerforming(true);
dancer.setPosture(Posture.SKILL_ANIMATING);
// Only entertainers get XP
if(isEntertainer(dancer))
scheduleExperienceTask(dancer);
scheduleExperienceTask(dancer, performanceName);
new ChatBroadcastIntent(dancer.getOwner(), "@performance:dance_start_self").broadcast();
}
@@ -223,6 +240,47 @@ public class EntertainmentService extends Service {
}
}
private class Performance {
private final Future<?> future;
private final String performanceName;
public Performance(Future<?> future, String performanceName) {
this.future = future;
this.performanceName = performanceName;
}
public Future<?> getFuture() {
return future;
}
public String getPerformanceName() {
return performanceName;
}
}
/**
* Data pulled from the performance.iff table
*/
private class PerformanceData {
private final String performanceId;
private final int flourishXpMod;
public PerformanceData(String performanceId, int flourishXpMod) {
this.performanceId = performanceId;
this.flourishXpMod = flourishXpMod;
}
public String getPerformanceId() {
return performanceId;
}
public int getFlourishXpMod() {
return flourishXpMod;
}
}
private class EntertainerExperience implements Runnable {
private final CreatureObject performer;
@@ -233,8 +291,30 @@ public class EntertainmentService extends Service {
@Override
public void run() {
int xpGained = 123; // TODO: This depends on the performance!
new ExperienceIntent(performer, "entertainer", xpGained).broadcast();
int performanceCounter = performer.getPerformanceCounter();
System.out.println("perf counter: " + performanceCounter);
Performance performance = performerMap.get(performer);
if(performance == null) {
Log.e("EntertainerExperience", "Performer %s wasn't in performermap", performer);
return;
}
String performanceName = performance.getPerformanceName();
System.out.println(performanceName);
PerformanceData performanceData = danceMap.get(performanceName);
System.out.println(performanceData);
int flourishXpMod = performanceData.getFlourishXpMod();
System.out.println("flourish xp mod: " + flourishXpMod);
int xpGained = (int) (performanceCounter * (flourishXpMod * 3.8));
System.out.println("xpGained: " + xpGained);
if(xpGained > 0) {
new ExperienceIntent(performer, "entertainer", xpGained).broadcast();
performer.setPerformanceCounter(performanceCounter - 1);
}
}
}