From 116041df451960715eb456cad21ef79a1fd1590c Mon Sep 17 00:00:00 2001 From: Mads Boddum Date: Thu, 26 Nov 2015 20:08:56 +0100 Subject: [PATCH 01/11] SkillMod structure completed. SkillModService is unfinished. --- src/intents/SkillModIntent.java | 39 +++++++++++++++ src/resources/SkillMod.java | 48 +++++++++++++++++++ .../objects/creature/CreatureObject.java | 27 ++++++++++- src/services/commands/SkillModService.java | 23 +++++++++ 4 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 src/intents/SkillModIntent.java create mode 100644 src/resources/SkillMod.java create mode 100644 src/services/commands/SkillModService.java diff --git a/src/intents/SkillModIntent.java b/src/intents/SkillModIntent.java new file mode 100644 index 000000000..5146ad827 --- /dev/null +++ b/src/intents/SkillModIntent.java @@ -0,0 +1,39 @@ +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..7292348ef --- /dev/null +++ b/src/resources/SkillMod.java @@ -0,0 +1,48 @@ +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 d71419b0d..45b40e27a 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; @@ -111,7 +112,7 @@ public class CreatureObject extends TangibleObject { private SWGList equipmentList = new SWGList(BaselineType.CREO, 6, 23); private SWGList appearanceList = new SWGList(BaselineType.CREO, 6, 33); - private SWGMap skillMods = new SWGMap<>(BaselineType.CREO, 4, 3, StringType.ASCII); // TODO: SkillMod structure + private SWGMap skillMods = new SWGMap<>(BaselineType.CREO, 4, 3, StringType.ASCII); private SWGMap missionCriticalObjs = new SWGMap<>(BaselineType.CREO, 4, 13); private SWGMap abilities = new SWGMap<>(BaselineType.CREO, 4, 14, StringType.ASCII); private SWGMap buffs = new SWGMap<>(BaselineType.CREO, 6, 26); // TODO: Buff structure @@ -605,6 +606,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.adjustBase(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/commands/SkillModService.java b/src/services/commands/SkillModService.java new file mode 100644 index 000000000..a4f112c23 --- /dev/null +++ b/src/services/commands/SkillModService.java @@ -0,0 +1,23 @@ +package services.commands; + +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) { + SkillModIntent smi = (SkillModIntent) i; + + for(CreatureObject creature : smi.getAffectedCreatures()) { + creature.adjustSkillmod(smi.getSkillModName(), smi.getAdjustBase(), smi.getAdjustModifier()); + } + } + +} From c6daa925f97739bc5af58a843fee2f5310155e2b Mon Sep 17 00:00:00 2001 From: Mads Boddum Date: Tue, 12 Jan 2016 09:35:30 +0100 Subject: [PATCH 02/11] SkillModIntent can now only affect a single creature --- src/intents/SkillModIntent.java | 10 ++++----- src/services/commands/SkillModService.java | 24 ++++++++++------------ 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/intents/SkillModIntent.java b/src/intents/SkillModIntent.java index 5146ad827..2d7097f7f 100644 --- a/src/intents/SkillModIntent.java +++ b/src/intents/SkillModIntent.java @@ -10,14 +10,14 @@ public class SkillModIntent extends Intent { private final String skillModName; private final int adjustBase; private final int adjustModifier; - private final CreatureObject[] affectedCreatures; + private final CreatureObject creature; - public SkillModIntent(String skillModName, int adjustBase, int adjustModifier, CreatureObject... affectedCreatures) { + public SkillModIntent(String skillModName, int adjustBase, int adjustModifier, CreatureObject creature) { super(TYPE); this.skillModName = skillModName; this.adjustBase = adjustBase; this.adjustModifier = adjustModifier; - this.affectedCreatures = affectedCreatures; + this.creature = creature; } public int getAdjustModifier() { @@ -32,8 +32,8 @@ public class SkillModIntent extends Intent { return skillModName; } - public CreatureObject[] getAffectedCreatures() { - return affectedCreatures; + public CreatureObject getCreature() { + return creature; } } diff --git a/src/services/commands/SkillModService.java b/src/services/commands/SkillModService.java index a4f112c23..97c03638d 100644 --- a/src/services/commands/SkillModService.java +++ b/src/services/commands/SkillModService.java @@ -7,17 +7,15 @@ import resources.objects.creature.CreatureObject; public class SkillModService extends Service { - public SkillModService() { - registerForIntent(SkillModIntent.TYPE); - } - - @Override - public void onIntentReceived(Intent i) { - SkillModIntent smi = (SkillModIntent) i; - - for(CreatureObject creature : smi.getAffectedCreatures()) { - creature.adjustSkillmod(smi.getSkillModName(), smi.getAdjustBase(), smi.getAdjustModifier()); - } - } - + public SkillModService() { + registerForIntent(SkillModIntent.TYPE); + } + + @Override + public void onIntentReceived(Intent i) { + SkillModIntent smi = (SkillModIntent) i; + CreatureObject creature = smi.getCreature(); + creature.adjustSkillmod(smi.getSkillModName(), smi.getAdjustBase(), smi.getAdjustModifier()); + } + } From 2892f63dabc00607fb9b951f5f82cfeeaf046346 Mon Sep 17 00:00:00 2001 From: Mads Boddum Date: Tue, 12 Jan 2016 09:36:44 +0100 Subject: [PATCH 03/11] Revert "SkillModIntent can now only affect a single creature" This reverts commit c6daa925f97739bc5af58a843fee2f5310155e2b. --- src/intents/SkillModIntent.java | 10 ++++----- src/services/commands/SkillModService.java | 24 ++++++++++++---------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/intents/SkillModIntent.java b/src/intents/SkillModIntent.java index 2d7097f7f..5146ad827 100644 --- a/src/intents/SkillModIntent.java +++ b/src/intents/SkillModIntent.java @@ -10,14 +10,14 @@ public class SkillModIntent extends Intent { private final String skillModName; private final int adjustBase; private final int adjustModifier; - private final CreatureObject creature; + private final CreatureObject[] affectedCreatures; - public SkillModIntent(String skillModName, int adjustBase, int adjustModifier, CreatureObject creature) { + public SkillModIntent(String skillModName, int adjustBase, int adjustModifier, CreatureObject... affectedCreatures) { super(TYPE); this.skillModName = skillModName; this.adjustBase = adjustBase; this.adjustModifier = adjustModifier; - this.creature = creature; + this.affectedCreatures = affectedCreatures; } public int getAdjustModifier() { @@ -32,8 +32,8 @@ public class SkillModIntent extends Intent { return skillModName; } - public CreatureObject getCreature() { - return creature; + public CreatureObject[] getAffectedCreatures() { + return affectedCreatures; } } diff --git a/src/services/commands/SkillModService.java b/src/services/commands/SkillModService.java index 97c03638d..a4f112c23 100644 --- a/src/services/commands/SkillModService.java +++ b/src/services/commands/SkillModService.java @@ -7,15 +7,17 @@ import resources.objects.creature.CreatureObject; public class SkillModService extends Service { - public SkillModService() { - registerForIntent(SkillModIntent.TYPE); - } - - @Override - public void onIntentReceived(Intent i) { - SkillModIntent smi = (SkillModIntent) i; - CreatureObject creature = smi.getCreature(); - creature.adjustSkillmod(smi.getSkillModName(), smi.getAdjustBase(), smi.getAdjustModifier()); - } - + public SkillModService() { + registerForIntent(SkillModIntent.TYPE); + } + + @Override + public void onIntentReceived(Intent i) { + SkillModIntent smi = (SkillModIntent) i; + + for(CreatureObject creature : smi.getAffectedCreatures()) { + creature.adjustSkillmod(smi.getSkillModName(), smi.getAdjustBase(), smi.getAdjustModifier()); + } + } + } From d384041ffcc7e1814289b64a2a655d279d1658ef Mon Sep 17 00:00:00 2001 From: Mads Boddum Date: Tue, 12 Jan 2016 10:16:30 +0100 Subject: [PATCH 04/11] Added SkillModService to GameManager --- src/services/galaxy/GameManager.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/services/galaxy/GameManager.java b/src/services/galaxy/GameManager.java index a863e3d04..24fde7d2a 100644 --- a/src/services/galaxy/GameManager.java +++ b/src/services/galaxy/GameManager.java @@ -29,6 +29,7 @@ package services.galaxy; import resources.control.Manager; import services.commands.CommandService; +import services.commands.SkillModService; import services.faction.FactionService; import services.galaxy.terminals.TerminalService; import services.sui.SuiService; @@ -44,6 +45,7 @@ public class GameManager extends Manager { private final TerminalService terminalManager; private final FactionService factionService; // private final GroupService groupService; + private final SkillModService skillModService; public GameManager() { traderManager = new TraderManager(); @@ -54,6 +56,7 @@ public class GameManager extends Manager { terminalManager = new TerminalService(); factionService = new FactionService(); // groupService = new GroupService(); + skillModService = new SkillModService(); addChildService(traderManager); addChildService(commandService); @@ -63,5 +66,6 @@ public class GameManager extends Manager { addChildService(terminalManager); addChildService(factionService); // addChildService(groupService); + addChildService(skillModService); } } From c41a052b7e886f3e613bc805e10bb38d48b9602e Mon Sep 17 00:00:00 2001 From: Mads Boddum Date: Tue, 12 Jan 2016 11:55:24 +0100 Subject: [PATCH 05/11] Moved SkillModService into services.galaxy package --- src/services/commands/SkillModService.java | 23 --------- src/services/galaxy/GameManager.java | 1 - src/services/galaxy/SkillModService.java | 54 ++++++++++++++++++++++ 3 files changed, 54 insertions(+), 24 deletions(-) delete mode 100644 src/services/commands/SkillModService.java create mode 100644 src/services/galaxy/SkillModService.java diff --git a/src/services/commands/SkillModService.java b/src/services/commands/SkillModService.java deleted file mode 100644 index a4f112c23..000000000 --- a/src/services/commands/SkillModService.java +++ /dev/null @@ -1,23 +0,0 @@ -package services.commands; - -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) { - SkillModIntent smi = (SkillModIntent) i; - - for(CreatureObject creature : smi.getAffectedCreatures()) { - creature.adjustSkillmod(smi.getSkillModName(), smi.getAdjustBase(), smi.getAdjustModifier()); - } - } - -} diff --git a/src/services/galaxy/GameManager.java b/src/services/galaxy/GameManager.java index 24fde7d2a..5be007ec6 100644 --- a/src/services/galaxy/GameManager.java +++ b/src/services/galaxy/GameManager.java @@ -29,7 +29,6 @@ package services.galaxy; import resources.control.Manager; import services.commands.CommandService; -import services.commands.SkillModService; import services.faction.FactionService; import services.galaxy.terminals.TerminalService; import services.sui.SuiService; diff --git a/src/services/galaxy/SkillModService.java b/src/services/galaxy/SkillModService.java new file mode 100644 index 000000000..b476a486e --- /dev/null +++ b/src/services/galaxy/SkillModService.java @@ -0,0 +1,54 @@ +/*********************************************************************************** +* 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) { + SkillModIntent smi = (SkillModIntent) i; + + for (CreatureObject creature : smi.getAffectedCreatures()) { + int adjustBase = smi.getAdjustBase(); + int adjustModifier = smi.getAdjustModifier(); + String skillModName = smi.getSkillModName(); + + creature.adjustSkillmod(skillModName, adjustBase, adjustModifier); + } + } + +} From a47e1cf59e852f0bc07478f165da6bfb3e77d3ab Mon Sep 17 00:00:00 2001 From: Mads Boddum Date: Tue, 12 Jan 2016 12:03:19 +0100 Subject: [PATCH 06/11] Fixed an issue where skillmod adjustments were always made to the base --- src/resources/objects/creature/CreatureObject.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resources/objects/creature/CreatureObject.java b/src/resources/objects/creature/CreatureObject.java index b74f74f77..c5eb01fed 100644 --- a/src/resources/objects/creature/CreatureObject.java +++ b/src/resources/objects/creature/CreatureObject.java @@ -643,7 +643,7 @@ public class CreatureObject extends TangibleObject { // 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.adjustBase(modifier); + skillMod.adjustModifier(modifier); skillMods.update(skillModName, this); } } From dd5af2d3942a6ff4eb36e4bad4c838e7cabb0e6f Mon Sep 17 00:00:00 2001 From: Mads Boddum Date: Tue, 12 Jan 2016 12:05:47 +0100 Subject: [PATCH 07/11] Added missing license header to SkillModIntent --- src/intents/SkillModIntent.java | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/intents/SkillModIntent.java b/src/intents/SkillModIntent.java index 5146ad827..f8b147df9 100644 --- a/src/intents/SkillModIntent.java +++ b/src/intents/SkillModIntent.java @@ -1,3 +1,30 @@ +/*********************************************************************************** +* 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; From c8f4c9bbd3d9e89ddac92f9c0bd1fd7eaa7d94e5 Mon Sep 17 00:00:00 2001 From: Mads Boddum Date: Wed, 20 Jan 2016 11:39:04 +0100 Subject: [PATCH 08/11] Added missing license to resources.SkillMod --- src/resources/SkillMod.java | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/resources/SkillMod.java b/src/resources/SkillMod.java index 7292348ef..f9bf50920 100644 --- a/src/resources/SkillMod.java +++ b/src/resources/SkillMod.java @@ -1,3 +1,30 @@ +/*********************************************************************************** +* 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; From dd47e22ee20c2a2e3165aa44b4eab3f3f1201238 Mon Sep 17 00:00:00 2001 From: Mads Boddum Date: Wed, 20 Jan 2016 11:42:38 +0100 Subject: [PATCH 09/11] Added instance check for SkillModIntent in SkillModService --- src/services/galaxy/SkillModService.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/services/galaxy/SkillModService.java b/src/services/galaxy/SkillModService.java index b476a486e..0e570cab5 100644 --- a/src/services/galaxy/SkillModService.java +++ b/src/services/galaxy/SkillModService.java @@ -40,8 +40,12 @@ public class SkillModService extends Service { @Override public void onIntentReceived(Intent i) { - SkillModIntent smi = (SkillModIntent) i; + switch(i.getType()) { + case SkillModIntent.TYPE: handleSkillModIntent((SkillModIntent) i); break; + } + } + private void handleSkillModIntent(SkillModIntent smi) { for (CreatureObject creature : smi.getAffectedCreatures()) { int adjustBase = smi.getAdjustBase(); int adjustModifier = smi.getAdjustModifier(); From 158f4dd15727406de7ae589950ca42868196b23f Mon Sep 17 00:00:00 2001 From: Mads Boddum Date: Wed, 20 Jan 2016 17:43:38 +0100 Subject: [PATCH 10/11] Fixed spacing vs tabs in GameManager --- src/services/galaxy/GameManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/galaxy/GameManager.java b/src/services/galaxy/GameManager.java index 5e2e0b052..a189d7b9a 100644 --- a/src/services/galaxy/GameManager.java +++ b/src/services/galaxy/GameManager.java @@ -52,7 +52,7 @@ public class GameManager extends Manager { terminalManager = new TerminalService(); factionService = new FactionService(); // groupService = new GroupService(); - skillModService = new SkillModService(); + skillModService = new SkillModService(); addChildService(commandService); addChildService(connectionService); @@ -61,6 +61,6 @@ public class GameManager extends Manager { addChildService(terminalManager); addChildService(factionService); // addChildService(groupService); - addChildService(skillModService); + addChildService(skillModService); } } From efe58bd1e3a1616b6c468f07eb90b6d34c778c6b Mon Sep 17 00:00:00 2001 From: Mads Boddum Date: Sat, 23 Jan 2016 15:37:13 +0100 Subject: [PATCH 11/11] Added instance check to SkillModService and fixed indentation --- src/services/galaxy/SkillModService.java | 40 +++++++++++++----------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/services/galaxy/SkillModService.java b/src/services/galaxy/SkillModService.java index 0e570cab5..e7fece6f4 100644 --- a/src/services/galaxy/SkillModService.java +++ b/src/services/galaxy/SkillModService.java @@ -34,25 +34,29 @@ import resources.objects.creature.CreatureObject; public class SkillModService extends Service { - public SkillModService() { - registerForIntent(SkillModIntent.TYPE); - } + public SkillModService() { + registerForIntent(SkillModIntent.TYPE); + } - @Override - public void onIntentReceived(Intent i) { - switch(i.getType()) { - case SkillModIntent.TYPE: handleSkillModIntent((SkillModIntent) i); break; - } - } + @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); - } - } + 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); + } + } }