diff --git a/src/intents/SkillModIntent.java b/src/intents/SkillModIntent.java new file mode 100644 index 000000000..f8b147df9 --- /dev/null +++ b/src/intents/SkillModIntent.java @@ -0,0 +1,66 @@ +/*********************************************************************************** +* 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 intents; + +import resources.control.Intent; +import resources.objects.creature.CreatureObject; + +public class SkillModIntent extends Intent { + + public static final String TYPE = "SkillModIntent"; + + private final String skillModName; + private final int adjustBase; + private final int adjustModifier; + private final CreatureObject[] affectedCreatures; + + public SkillModIntent(String skillModName, int adjustBase, int adjustModifier, CreatureObject... affectedCreatures) { + super(TYPE); + this.skillModName = skillModName; + this.adjustBase = adjustBase; + this.adjustModifier = adjustModifier; + this.affectedCreatures = affectedCreatures; + } + + public int getAdjustModifier() { + return adjustModifier; + } + + public int getAdjustBase() { + return adjustBase; + } + + public String getSkillModName() { + return skillModName; + } + + public CreatureObject[] getAffectedCreatures() { + return affectedCreatures; + } + +} diff --git a/src/resources/SkillMod.java b/src/resources/SkillMod.java new file mode 100644 index 000000000..f9bf50920 --- /dev/null +++ b/src/resources/SkillMod.java @@ -0,0 +1,75 @@ +/*********************************************************************************** +* 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; + +import java.io.Serializable; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +import resources.encodables.Encodable; + +public class SkillMod implements Encodable, Serializable { + + private static final long serialVersionUID = 1L; + + private int base, modifier; + + public SkillMod(int base, int modifier) { + this.base = base; + this.modifier = modifier; + } + + @Override + public byte[] encode() { + ByteBuffer buffer = ByteBuffer.allocate(Integer.BYTES * 2).order(ByteOrder.LITTLE_ENDIAN); + + buffer.putInt(base); + buffer.putInt(modifier); + + return buffer.array(); + } + + @Override + public void decode(ByteBuffer data) { + base = data.getInt(); + modifier = data.getInt(); + } + + public void adjustBase(int adjustment) { + base += adjustment; + } + + public void adjustModifier(int adjustment) { + modifier += adjustment; + } + + public int getValue() { + return base + modifier; + } + +} diff --git a/src/resources/objects/creature/CreatureObject.java b/src/resources/objects/creature/CreatureObject.java index dbb731e8a..53454e714 100644 --- a/src/resources/objects/creature/CreatureObject.java +++ b/src/resources/objects/creature/CreatureObject.java @@ -40,6 +40,7 @@ import resources.HologramColour; import resources.Posture; import resources.PvpFlag; import resources.Race; +import resources.SkillMod; import resources.collections.SWGList; import resources.collections.SWGMap; import resources.encodables.player.Equipment; @@ -55,7 +56,7 @@ import utilities.Encoder.StringType; public class CreatureObject extends TangibleObject { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 2L; private transient GroupInviterData inviterData = new GroupInviterData(0, null, "", 0); private transient long lastReserveOperation = 0; @@ -112,12 +113,11 @@ public class CreatureObject extends TangibleObject { private SWGList equipmentList = new SWGList(6, 23); private SWGList appearanceList = new SWGList(6, 33); - private SWGMap skillMods = new SWGMap<>(4, 3, StringType.ASCII); // TODO: SkillMod structure + private SWGMap skillMods = new SWGMap<>(4, 3, StringType.ASCII); // TODO: SkillMod structure private SWGMap missionCriticalObjs = new SWGMap<>(4, 13); private SWGMap abilities = new SWGMap<>(4, 14, StringType.ASCII); private SWGMap buffs = new SWGMap<>(6, 26); // TODO: Buff structure - public CreatureObject(long objectId) { super(objectId, BaselineType.CREO); initMaxAttributes(); @@ -630,6 +630,28 @@ public class CreatureObject extends TangibleObject { sendDelta(3, 18, statesBitmask); } + public void adjustSkillmod(String skillModName, int base, int modifier) { + SkillMod skillMod = skillMods.get(skillModName); + + if(skillMod == null) { + // They didn't have this SkillMod already. + // Therefore, we send a full delta. + skillMods.put(skillModName, new SkillMod(base, modifier)); + skillMods.sendDeltaMessage(this); + } else { + // They already had this skillmod. + // All we need to do is adjust the base and the modifier and send an update from the SWGMap + skillMod.adjustBase(base); + skillMod.adjustModifier(modifier); + skillMods.update(skillModName, this); + } + } + + public int getSkillModValue(String skillModName) { + SkillMod skillMod = skillMods.get(skillModName); + return skillMod != null ? skillMod.getValue() : 0; + } + public boolean isVisible() { return visible; } diff --git a/src/services/galaxy/GameManager.java b/src/services/galaxy/GameManager.java index 05109b13d..a189d7b9a 100644 --- a/src/services/galaxy/GameManager.java +++ b/src/services/galaxy/GameManager.java @@ -42,6 +42,7 @@ public class GameManager extends Manager { private final TerminalService terminalManager; private final FactionService factionService; // private final GroupService groupService; + private final SkillModService skillModService; public GameManager() { commandService = new CommandService(); @@ -51,6 +52,7 @@ public class GameManager extends Manager { terminalManager = new TerminalService(); factionService = new FactionService(); // groupService = new GroupService(); + skillModService = new SkillModService(); addChildService(commandService); addChildService(connectionService); @@ -59,5 +61,6 @@ public class GameManager extends Manager { addChildService(terminalManager); addChildService(factionService); // addChildService(groupService); + addChildService(skillModService); } } diff --git a/src/services/galaxy/SkillModService.java b/src/services/galaxy/SkillModService.java new file mode 100644 index 000000000..e7fece6f4 --- /dev/null +++ b/src/services/galaxy/SkillModService.java @@ -0,0 +1,62 @@ +/*********************************************************************************** +* 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 services.galaxy; + +import intents.SkillModIntent; +import resources.control.Intent; +import resources.control.Service; +import resources.objects.creature.CreatureObject; + +public class SkillModService extends Service { + + public SkillModService() { + registerForIntent(SkillModIntent.TYPE); + } + + @Override + public void onIntentReceived(Intent i) { + switch (i.getType()) { + case SkillModIntent.TYPE: + if (i instanceof SkillModIntent) { + handleSkillModIntent((SkillModIntent) i); + } + break; + } + } + + private void handleSkillModIntent(SkillModIntent smi) { + for (CreatureObject creature : smi.getAffectedCreatures()) { + int adjustBase = smi.getAdjustBase(); + int adjustModifier = smi.getAdjustModifier(); + String skillModName = smi.getSkillModName(); + + creature.adjustSkillmod(skillModName, adjustBase, adjustModifier); + } + } + +}