mirror of
https://github.com/ProjectSWGCore/NGECore2.git
synced 2026-07-31 01:15:57 -04:00
Added leveling/roadmap, skillService
This commit is contained in:
@@ -36,10 +36,13 @@ import org.apache.mina.core.buffer.IoBuffer;
|
||||
import org.apache.mina.core.session.IoSession;
|
||||
|
||||
import protocol.swg.ClientIdMsg;
|
||||
import protocol.swg.ClientMfdStatusUpdateMessage;
|
||||
import protocol.swg.ExpertiseRequestMessage;
|
||||
import protocol.swg.ServerTimeMessage;
|
||||
import protocol.swg.objectControllerObjects.ShowFlyText;
|
||||
import resources.common.FileUtilities;
|
||||
import resources.common.Opcodes;
|
||||
import resources.common.RGB;
|
||||
import resources.common.SpawnPoint;
|
||||
import resources.objects.Buff;
|
||||
import resources.objects.building.BuildingObject;
|
||||
@@ -53,7 +56,12 @@ import services.sui.SUIWindow.SUICallback;
|
||||
|
||||
import main.NGECore;
|
||||
|
||||
import engine.clientdata.ClientFileManager;
|
||||
import engine.clientdata.visitors.CrcStringTableVisitor;
|
||||
import engine.clientdata.visitors.DatatableVisitor;
|
||||
import engine.clients.Client;
|
||||
import engine.resources.common.CRC;
|
||||
import engine.resources.objects.DraftSchematic;
|
||||
import engine.resources.objects.SWGObject;
|
||||
import engine.resources.scene.Point3D;
|
||||
import engine.resources.service.INetworkDispatch;
|
||||
@@ -65,7 +73,9 @@ public class PlayerService implements INetworkDispatch {
|
||||
|
||||
private NGECore core;
|
||||
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
|
||||
|
||||
protected final Object objectMutex = new Object();
|
||||
|
||||
public PlayerService(final NGECore core) {
|
||||
this.core = core;
|
||||
scheduler.scheduleAtFixedRate(new Runnable() {
|
||||
@@ -293,7 +303,189 @@ public class PlayerService implements INetworkDispatch {
|
||||
core.buffService.addBuffToCreature(creature, "cloning_sickness");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Gives experience. If they have enough experience, it auto-levels them up.
|
||||
*
|
||||
* First, it adds the experience.
|
||||
* Second, it sees if they need to level up.
|
||||
* Third, if they do, it adds the relevant stat/health/action increases & expertise points.
|
||||
* Fourth, if their roadmap increased, it adds the relevant roadmap update, roadmap items, skillmods, abilities, and profession quests.
|
||||
* ALL of this info is contained in the client files, so we don't need to bother with scripts.
|
||||
*/
|
||||
public void giveExperience(CreatureObject creature, int experience) {
|
||||
DatatableVisitor experienceTable;
|
||||
PlayerObject player = (PlayerObject) creature.getSlottedObject("ghost");
|
||||
|
||||
synchronized(objectMutex) {
|
||||
try {
|
||||
experienceTable = ClientFileManager.loadFile("datatables/player/player_level.iff", DatatableVisitor.class);
|
||||
|
||||
// Cannot gain more than half of the XP needed for the next level in one go
|
||||
// Do check
|
||||
|
||||
// 1. Add the experience.
|
||||
if (experience > 0) {
|
||||
creature.showFlyText("base_player", "prose_flytext_xp", experience, (float) 2.5, new RGB(180, 60, 240), 1);
|
||||
}
|
||||
|
||||
String xpType = ((player.getProfession().contains("entertainer")) ? "entertainer" : ((player.getProfession().contains("trader")) ? "crafting" : "combat_general"));
|
||||
|
||||
if (player.getXpList().containsKey(xpType)) {
|
||||
experience += player.getXp(xpType);
|
||||
}
|
||||
|
||||
player.setXp(xpType, experience);
|
||||
|
||||
// 2. See if they need to level up.
|
||||
for (int i = 0; i < experienceTable.getRowCount(); i++) {
|
||||
if (experienceTable.getObject(i, 0) != null) {
|
||||
if (experience >= ((Integer) experienceTable.getObject(i, 1))) {
|
||||
if (creature.getLevel() < (Integer) experienceTable.getObject(i, 0)) {
|
||||
creature.playEffectObject("clienteffect/level_granted.cef", "");
|
||||
creature.getClient().getSession().write((new ClientMfdStatusUpdateMessage((float) ((creature.getLevel() == 90) ? 90 : (creature.getLevel() + 1)), "/GroundHUD.MFDStatus.vsp.role.targetLevel")).serialize());
|
||||
creature.setLevel(((Integer) experienceTable.getObject(i, 0)).shortValue());
|
||||
|
||||
// 3. Add the relevant health/action and expertise points.
|
||||
float luck = (((((float) (core.scriptService.getMethod("scripts/roadmap/", player.getProfession(), "getLuck").__call__().asInt()) + (core.scriptService.getMethod("scripts/roadmap/", creature.getStfName(), "getLuck").__call__().asInt())) / ((float) 90)) * ((float) creature.getLevel())) - ((float) creature.getSkillModBase("luck")));
|
||||
float precision = (((((float) (core.scriptService.getMethod("scripts/roadmap/", player.getProfession(), "getPrecision").__call__().asInt()) + (core.scriptService.getMethod("scripts/roadmap/", creature.getStfName(), "getPrecision").__call__().asInt())) / ((float) 90)) * ((float) creature.getLevel())) - ((float) creature.getSkillModBase("precision")));
|
||||
float strength = (((((float) (core.scriptService.getMethod("scripts/roadmap/", player.getProfession(), "getStrength").__call__().asInt()) + (core.scriptService.getMethod("scripts/roadmap/", creature.getStfName(), "getStrength").__call__().asInt())) / ((float) 90)) * ((float) creature.getLevel())) - ((float) creature.getSkillModBase("strength")));
|
||||
float constitution = (((((float) (core.scriptService.getMethod("scripts/roadmap/", player.getProfession(), "getConstitution").__call__().asInt()) + (core.scriptService.getMethod("scripts/roadmap/", creature.getStfName(), "getConstitution").__call__().asInt())) / ((float) 90)) * ((float) creature.getLevel())) - ((float) creature.getSkillModBase("constitution")));
|
||||
float stamina = (((((float) (core.scriptService.getMethod("scripts/roadmap/", player.getProfession(), "getStamina").__call__().asInt()) + (core.scriptService.getMethod("scripts/roadmap/", creature.getStfName(), "getStamina").__call__().asInt())) / ((float) 90)) * ((float) creature.getLevel())) - ((float) creature.getSkillModBase("stamina")));
|
||||
float agility = (((((float) (core.scriptService.getMethod("scripts/roadmap/", player.getProfession(), "getAgility").__call__().asInt()) + (core.scriptService.getMethod("scripts/roadmap/", creature.getStfName(), "getAgility").__call__().asInt())) / ((float) 90)) * ((float) creature.getLevel())) - ((float) creature.getSkillModBase("agility")));
|
||||
float health = 100;
|
||||
float action = 75;
|
||||
|
||||
int healthGranted = ((Integer) experienceTable.getObject(i, 4));
|
||||
|
||||
if (luck >= 1) {
|
||||
core.skillModService.addSkillMod(creature, "luck", (int) luck);
|
||||
creature.sendSystemMessage("spam", "level_up_stat_gain_0", (int) luck, 0);
|
||||
}
|
||||
|
||||
if (precision >= 1) {
|
||||
core.skillModService.addSkillMod(creature, "precision", (int) precision);
|
||||
creature.sendSystemMessage("spam", "level_up_stat_gain_1", (int) precision, 0);
|
||||
}
|
||||
|
||||
if (strength >= 1) {
|
||||
core.skillModService.addSkillMod(creature, "strength", (int) strength);
|
||||
creature.sendSystemMessage("spam", "level_up_stat_gain_2", (int) strength, 0);
|
||||
}
|
||||
|
||||
if (constitution >= 1) {
|
||||
core.skillModService.addSkillMod(creature, "constitution", (int) constitution);
|
||||
creature.sendSystemMessage("spam", "level_up_stat_gain_3", (int) constitution, 0);
|
||||
}
|
||||
|
||||
if (stamina >= 1) {
|
||||
core.skillModService.addSkillMod(creature, "stamina", (int) stamina);
|
||||
creature.sendSystemMessage("spam", "level_up_stat_gain_4", (int) stamina, 0);
|
||||
}
|
||||
|
||||
if (agility >= 1) {
|
||||
core.skillModService.addSkillMod(creature, "agility", (int) agility);
|
||||
creature.sendSystemMessage("spam", "level_up_stat_gain_5", (int) agility, 0);
|
||||
}
|
||||
|
||||
if (health >= 1) {
|
||||
creature.setMaxHealth((creature.getMaxHealth() + (int) health + (healthGranted - creature.getGrantedHealth())));
|
||||
creature.setHealth(creature.getMaxHealth());
|
||||
creature.sendSystemMessage("spam", "level_up_stat_gain_6", (((int) health) + (((int) constitution) * 8) + (((int) stamina) * 2)), 0);
|
||||
}
|
||||
|
||||
if (action >= 1) {
|
||||
creature.setMaxAction((creature.getMaxAction() + (int) action));
|
||||
creature.setAction(creature.getMaxAction());
|
||||
creature.sendSystemMessage("spam", "level_up_stat_gain_7", (((int) action) + (((int) stamina) * 8) + (((int) constitution) * 2)), 0);
|
||||
}
|
||||
|
||||
creature.setGrantedHealth(((Integer) experienceTable.getObject(i, 4)));
|
||||
// -> Expertise point added automatically by client
|
||||
creature.showFlyText("cbt_spam", "level_up", (float) 2.5, new RGB(100, 149, 237), 0);
|
||||
|
||||
// 4. Adds roadmap rewards
|
||||
int level = creature.getLevel();
|
||||
|
||||
if ((level == 4 || level == 7 || level == 10) || ((level > 10) && (((creature.getLevel() - 10) % 4) == 0))) {
|
||||
int skill = ((level <= 10) ? ((level - 1) / 3) : ((((level - 10) / 4)) + 3));
|
||||
String roadmapSkillName = "";
|
||||
DatatableVisitor skillTemplate, roadmap;
|
||||
|
||||
try {
|
||||
skillTemplate = ClientFileManager.loadFile("datatables/skill_template/skill_template.iff", DatatableVisitor.class);
|
||||
|
||||
for (int s = 0; s < skillTemplate.getRowCount(); s++) {
|
||||
if (skillTemplate.getObject(s, 0) != null) {
|
||||
if (((String) skillTemplate.getObject(s, 0)).equals(player.getProfession())) {
|
||||
String[] skillArray = ((String) skillTemplate.getObject(s, 4)).split(",");
|
||||
roadmapSkillName = skillArray[skill];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
creature.showFlyText("cbt_spam", "skill_up", (float) 2.5, new RGB(154, 205, 50), 0);
|
||||
creature.playEffectObject("clienteffect/skill_granted.cef", "");
|
||||
creature.playMusic("sound/music_acq_bountyhunter.snd");
|
||||
core.skillService.addSkill(creature, roadmapSkillName);
|
||||
player.setProfessionWheelPosition(roadmapSkillName);
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
roadmap = ClientFileManager.loadFile("datatables/roadmap/item_rewards.iff", DatatableVisitor.class);
|
||||
|
||||
for (int s = 0; s < roadmap.getRowCount(); s++) {
|
||||
if (roadmap.getObject(s, 0) != null) {
|
||||
if (((String) roadmap.getObject(s, 1)).equals(roadmapSkillName)) {
|
||||
String[] apts = ((String) roadmap.getObject(s, 2)).split(",");
|
||||
String[] items = ((String) roadmap.getObject(s, 4)).split(",");
|
||||
String[] wookieeItems = ((String) roadmap.getObject(s, 5)).split(",");
|
||||
String[] ithorianItems = ((String) roadmap.getObject(s, 6)).split(",");
|
||||
|
||||
for (int n = 0; n < items.length; n++) {
|
||||
String item = items[n];
|
||||
|
||||
if (wookieeItems.length > 0 && creature.getStfName().contains("wookiee")) {
|
||||
item = wookieeItems[n];
|
||||
} else if (ithorianItems.length > 0 && creature.getStfName().contains("ithorian")) {
|
||||
item = ithorianItems[n];
|
||||
}
|
||||
|
||||
try {
|
||||
if (!item.contains("/")) {
|
||||
item = core.scriptService.callScript("scripts/roadmap/", "roadmap_rewards", "get", item).asString();
|
||||
}
|
||||
|
||||
if (item != null && item != "") {
|
||||
creature.getSlottedObject("inventory").add(core.objectService.createObject(item, creature.getPlanet()));
|
||||
} else {
|
||||
//System.out.println("Can't find template: " + item);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
Reference in New Issue
Block a user