diff --git a/scripts/character_builder_terminal.py b/scripts/character_builder_terminal.py index 7fb5ec0b..7346b8bc 100644 --- a/scripts/character_builder_terminal.py +++ b/scripts/character_builder_terminal.py @@ -628,12 +628,12 @@ def lightsaberColorCrystals(owner, inventory): return def jediBelt(owner, inventory): - inventory.add(core.objectService.createObject("object/tangible/wearables/backpack/shared_fannypack_s01.iff", owner.getPlanet())) + # inventory.add(core.objectService.createObject("object/tangible/wearables/backpack/shared_fannypack_s01.iff", owner.getPlanet())) screenOne(core, owner) return def backpack(owner, inventory): - inventory.add(core.objectService.createObject("object/tangible/wearables/backpack/shared_backpack_s01.iff", owner.getPlanet())) + # inventory.add(core.objectService.createObject("object/tangible/wearables/backpack/shared_backpack_s01.iff", owner.getPlanet())) screenOne(core, owner) return diff --git a/scripts/commands/acceptquest.py b/scripts/commands/acceptquest.py index be3231f3..ca7d6dd8 100644 --- a/scripts/commands/acceptquest.py +++ b/scripts/commands/acceptquest.py @@ -4,5 +4,11 @@ def setup(): return def run(core, actor, target, commandString): - print ('acceptQuest: ' + commandString) + player = actor.getPlayerObject() + + if player is None: + return + + questName = core.questService.getQuestStringByCrc(int(commandString)) + core.questService.immediatlyActivateQuest(actor, questName) return diff --git a/scripts/commands/transferitemarmor.py b/scripts/commands/transferitemarmor.py index c78c862c..46a741f3 100644 --- a/scripts/commands/transferitemarmor.py +++ b/scripts/commands/transferitemarmor.py @@ -2,51 +2,26 @@ import sys def setup(): return - -def run(core, actor, target, commandString): +def run(core, actor, target, commandString): parsedMsg = commandString.split(' ', 3) objService = core.objectService containerID = long(parsedMsg[1]) container = objService.getObject(containerID) - canEquip = core.equipmentService.canEquip(actor, target) - if target and container and target.getContainer(): oldContainer = target.getContainer() if container == oldContainer: print 'Error: New container is same as old container.' - return; + return; - if canEquip[0] is False and container == actor: - actor.sendSystemMessage(canEquip[1], 0) - return - - replacedObject = None - slotName = None - replacedObjects = [] - slotNames = None - - if actor == container: - slotNames = container.getSlotNamesForObject(target) - - for slotName in slotNames: - object = container.getSlottedObject(slotName) - - if not object in replacedObjects and not object == None: - replacedObjects.append(object) - - if object != None: - actor.transferTo(actor, oldContainer, object) + if oldContainer == actor.getSlottedObject('appearance_inventory'): + core.equipmentService.unequipAppearance(actor, target) oldContainer.transferTo(actor, container, target) - if oldContainer == actor.getSlottedObject('appearance_inventory'): - actor.removeObjectFromAppearanceEquipList(target) - if container == actor.getSlottedObject('appearance_inventory'): - actor.addObjectToAppearanceEquipList(target) - + core.equipmentService.equipAppearance(actor, target) + return - \ No newline at end of file diff --git a/scripts/commands/transferitemmisc.py b/scripts/commands/transferitemmisc.py index d1dee497..c0708738 100644 --- a/scripts/commands/transferitemmisc.py +++ b/scripts/commands/transferitemmisc.py @@ -5,14 +5,14 @@ def setup(): return def run(core, actor, target, commandString): - parsedMsg = commandString.split(' ', 3) objService = core.objectService containerID = long(parsedMsg[1]) container = objService.getObject(containerID) actorContainer = actor.getContainer() - if container == None: return + if container == None: + return if not 'cell' in container.getTemplate() and container.isFull(): actor.sendSystemMessage('@container_error_message:container03', 0) @@ -24,15 +24,19 @@ def run(core, actor, target, commandString): if target.getTemplate() == 'object/tangible/item/shared_loot_cash.iff': core.lootService.handleCreditPickUp(actor,target) - if target.getGrandparent().getInventoryItemCount()==1: + + if target.getGrandparent().getInventoryItemCount() == 1: core.lootService.setLooted(actor,target.getGrandparent()) + core.objectService.destroyObject(target) + return if target.isLootItem(): target.setLootItem(0) actor.sendSystemMessage('You looted ' + target.getObjectName().getStfValue() + ' from corpse.', 0) #actor.sendSystemMessage('container.getInventoryItemCount() %s' % target.getGrandparent().getInventoryItemCount(), 0) + if target.getGrandparent().getInventoryItemCount()==1: core.lootService.setLooted(actor,target.getGrandparent()) @@ -40,20 +44,12 @@ def run(core, actor, target, commandString): target.getContainer().transferTo(actor, container, target) core.simulationService.teleport(target, actor.getPosition(), Quaternion(1,0,0,0), containerID) return - elif target.getContainer().getTemplate() == "object/cell/shared_cell.iff" and core.housingService.getPermissions(actor, target.getContainer()): target.getContainer().transferTo(actor, container, target) return - elif actorContainer != None and container.getTemplate() == "object/cell/shared_cell.iff": actor.sendSystemMessage("You do not have permission to access that container!", 0) return - - canEquip = core.equipmentService.canEquip(actor, target) - - if canEquip[0] is False and container == actor: - actor.sendSystemMessage(canEquip[1], 0) - return if target and container and target.getContainer(): oldContainer = target.getContainer() @@ -62,29 +58,12 @@ def run(core, actor, target, commandString): print 'Error: New container is same as old container.' return; - replacedObject = None - slotName = None - replacedObjects = [] - slotNames = None + if oldContainer == actor.getSlottedObject('appearance_inventory'): + core.equipmentService.unequipAppearance(actor, target) - if actor == container: - slotNames = container.getSlotNamesForObject(target) - - for slotName in slotNames: - object = container.getSlottedObject(slotName) - - if not object in replacedObjects and not object == None: - replacedObjects.append(object) - - if object != None: - container.transferTo(actor, container, object) - oldContainer.transferTo(actor, container, target) - if oldContainer == actor.getSlottedObject('appearance_inventory'): - actor.removeObjectFromAppearanceEquipList(target) - if container == actor.getSlottedObject('appearance_inventory'): - actor.addObjectToAppearanceEquipList(target) - + core.equipmentService.equipAppearance(actor, target) + return diff --git a/scripts/commands/transferitemweapon.py b/scripts/commands/transferitemweapon.py index c2586049..25b9378b 100644 --- a/scripts/commands/transferitemweapon.py +++ b/scripts/commands/transferitemweapon.py @@ -4,41 +4,19 @@ def setup(): return def run(core, actor, target, commandString): - parsedMsg = commandString.split(' ', 3) objService = core.objectService containerID = long(parsedMsg[1]) container = objService.getObject(containerID) + if target and container and target.getContainer(): oldContainer = target.getContainer() + if container == oldContainer: - print 'Error: New container is same as old container.' - return; - - canEquip = core.equipmentService.canEquip(actor, target) - - if canEquip[0] is False and container == actor: - actor.sendSystemMessage(canEquip[1], 0) - return - - replacedObject = None - slotName = None - replacedObjects = [] - slotNames = None - - if actor == container: - slotNames = container.getSlotNamesForObject(target) - - for slotName in slotNames: - object = container.getSlottedObject(slotName) - - if not object in replacedObjects and not object == None: - replacedObjects.append(object) - - if object != None: - container.transferTo(actor, container, object) + print 'Error: New container is same as old container.' + return; oldContainer.transferTo(actor, container, target) return - \ No newline at end of file + diff --git a/scripts/conversation/quests/tatooine/vourk.py b/scripts/conversation/quests/tatooine/vourk.py index 32e8c846..c9426d57 100644 --- a/scripts/conversation/quests/tatooine/vourk.py +++ b/scripts/conversation/quests/tatooine/vourk.py @@ -119,19 +119,10 @@ def handleOptionsSix(core, actor, npc, selection): return def handleOptionsSeven(core, actor, npc, selection): - print ('selection 7: ' + str(selection)) if (selection == 0): # Ok, I'll do what he says. quest = actor.getPlayerObject().getQuest('tatooine_eisley_legacy') - - if (actor.getLevel() >= 10): - core.questService.activateQuest(actor, 'quest/tatooine_eisley_gotoniko') - return - else: - core.questService.activateQuest(actor, 'quest/tatooine_eisley_gotomayor') - return - core.questService.handleActivateSignal(actor, npc, quest, 2) - core.conversationService.sendStopConversation(actor, npc, '@conversation/c_newbie_secondchance', 's_136') + core.conversationService.sendStopConversation(actor, npc, 'conversation/c_newbie_secondchance', 's_136') return elif (selection == 1): # But I don't know anything about Mos Eisley! quest = actor.getPlayerObject().getQuest('tatooine_eisley_legacy') @@ -142,7 +133,7 @@ def handleOptionsSeven(core, actor, npc, selection): return def endConversation(core, actor, npc): - core.conversationService.sendStopConversation(actor, npc, '@conversation/c_newbie_secondchance', 's_200') + core.conversationService.sendStopConversation(actor, npc, 'conversation/c_newbie_secondchance', 's_200') return def hasActiveTrehlaQuest(core, actor, npc, player): diff --git a/scripts/quests/events/signals/tat_eisley_legacy_e2.py b/scripts/quests/events/signals/tat_eisley_legacy_e2.py index 2c219af1..0520e50a 100644 --- a/scripts/quests/events/signals/tat_eisley_legacy_e2.py +++ b/scripts/quests/events/signals/tat_eisley_legacy_e2.py @@ -6,4 +6,9 @@ def wait(core, actor): def activate(core, actor, quest): core.questService.completeActiveTask(actor, quest) + + if (actor.getLevel() >= 10): + core.questService.sendQuestAcceptWindow(actor, 'quest/tatooine_eisley_gotoniko') + else: + core.questService.sendQuestAcceptWindow(actor, 'quest/tatooine_eisley_gotomayor') return \ No newline at end of file diff --git a/scripts/radial/terminal/travel_terminal.py b/scripts/radial/terminal/travel_terminal.py index a579af12..de72aa58 100644 --- a/scripts/radial/terminal/travel_terminal.py +++ b/scripts/radial/terminal/travel_terminal.py @@ -13,7 +13,7 @@ def handleSelection(core, owner, target, option): if owner.getCombatFlag() == 1: owner.sendSystemMessage('You can\'t use that while in combat.', 0) return - tpm = EnterTicketPurchaseModeMessage(owner.getPlanet().getName(), core.mapService.getClosestCityName(owner), owner) + tpm = EnterTicketPurchaseModeMessage(owner.getPlanet().getName(), core.mapService.getClosestCityName(owner), False) owner.getClient().getSession().write(tpm.serialize()) return return diff --git a/scripts/radial/terminal/travel_terminal_itv.py b/scripts/radial/terminal/travel_terminal_itv.py index b9356f38..47955905 100644 --- a/scripts/radial/terminal/travel_terminal_itv.py +++ b/scripts/radial/terminal/travel_terminal_itv.py @@ -14,7 +14,7 @@ def handleSelection(core, owner, target, option): if owner.getCombatFlag() == 1: owner.sendSystemMessage('You can\'t use that while in combat.', 0) return - tpm = EnterTicketPurchaseModeMessage(owner.getPlanet().getName(), core.mapService.getClosestCityName(owner), owner, True) + tpm = EnterTicketPurchaseModeMessage(owner.getPlanet().getName(), core.mapService.getClosestCityName(owner), True) owner.getClient().getSession().write(tpm.serialize()) return return diff --git a/src/protocol/swg/CmdStartScene.java b/src/protocol/swg/CmdStartScene.java index 918b0f4f..5b6815a7 100644 --- a/src/protocol/swg/CmdStartScene.java +++ b/src/protocol/swg/CmdStartScene.java @@ -73,7 +73,7 @@ public class CmdStartScene extends SWGMessage { result.put(getAsciiString(sharedRaceTemplate)); result.putLong(time); - result.put(new byte[] { (byte)0x8E, (byte)0xB5, (byte)0xEA, (byte)0x4E }); + result.putInt((int) (System.currentTimeMillis() / 1000)); return result.flip(); } diff --git a/src/protocol/swg/EnterTicketPurchaseModeMessage.java b/src/protocol/swg/EnterTicketPurchaseModeMessage.java index 0287c55c..3080d43e 100644 --- a/src/protocol/swg/EnterTicketPurchaseModeMessage.java +++ b/src/protocol/swg/EnterTicketPurchaseModeMessage.java @@ -23,32 +23,21 @@ package protocol.swg; import java.nio.ByteOrder; -import main.NGECore; - import org.apache.mina.core.buffer.IoBuffer; -import services.travel.TravelPoint; -import engine.resources.objects.SWGObject; +import resources.common.Opcodes; +import engine.resources.common.StringUtilities; -@SuppressWarnings("unused") public class EnterTicketPurchaseModeMessage extends SWGMessage { private String planetName; - private String cityName; - private SWGObject player; - private boolean isItv = false; + private String nearestPointName; + private boolean isInstant = false; - public EnterTicketPurchaseModeMessage(String planetName, String cityName, SWGObject player, boolean isItv) { + public EnterTicketPurchaseModeMessage(String planetName, String nearestPointName, boolean isInstant) { this.planetName = planetName; - this.cityName = cityName; - this.player = player; - this.isItv = true; - } - - public EnterTicketPurchaseModeMessage(String planetName, String cityName, SWGObject player) { - this.planetName = planetName; - this.cityName = cityName; - this.player = player; + this.nearestPointName = nearestPointName; + this.isInstant = isInstant; } @Override @@ -58,22 +47,13 @@ public class EnterTicketPurchaseModeMessage extends SWGMessage { @Override public IoBuffer serialize() { - final NGECore core = NGECore.getInstance(); - - TravelPoint nearestPoint = null; - if (!isItv) nearestPoint = core.travelService.getNearestTravelPoint(player); - else nearestPoint = core.travelService.getNearestTravelPoint(player, 5120); - - IoBuffer result = IoBuffer.allocate(11 + planetName.length() + nearestPoint.getName().length()).order(ByteOrder.LITTLE_ENDIAN); + IoBuffer result = IoBuffer.allocate(11 + planetName.length() + nearestPointName.length()).order(ByteOrder.LITTLE_ENDIAN); result.putShort((short) 3); - result.putInt(0x904DAE1A); - - result.put(getAsciiString(planetName)); - result.put(getAsciiString(nearestPoint.getName())); - - - result.put((byte) 0); + result.putInt(Opcodes.EnterTicketPurchaseModeMessage); + result.put(StringUtilities.getAsciiString(planetName)); + result.put(StringUtilities.getAsciiString(nearestPointName)); + result.put(isInstant ? (byte) 1 : (byte) 0); return result.flip(); } diff --git a/src/protocol/swg/PlayClientEffectLocMessage.java b/src/protocol/swg/PlayClientEffectLocMessage.java index fd71b8a7..6f0b391d 100644 --- a/src/protocol/swg/PlayClientEffectLocMessage.java +++ b/src/protocol/swg/PlayClientEffectLocMessage.java @@ -28,24 +28,32 @@ import org.apache.mina.core.buffer.IoBuffer; import engine.resources.scene.Point3D; public class PlayClientEffectLocMessage extends SWGMessage { - + private String effectFile; private String planet; private Point3D position; + private String commandString; + private long cellId; public PlayClientEffectLocMessage(String effectFile, String planet, Point3D position) { - this.effectFile = effectFile; this.planet = planet; this.position = position; - + this.cellId = 0; + this.commandString = ""; + } + + public PlayClientEffectLocMessage(String effectFile, String planet, Point3D position, long cellId, String commandString) { + this.effectFile = effectFile; + this.planet = planet; + this.position = position; + this.cellId = cellId; + this.commandString = commandString; } @Override public IoBuffer serialize() { - - IoBuffer result = IoBuffer.allocate(36 + effectFile.length() + planet.length()).order(ByteOrder.LITTLE_ENDIAN); - + IoBuffer result = IoBuffer.allocate(36 + effectFile.length() + planet.length() + commandString.length()).order(ByteOrder.LITTLE_ENDIAN); result.putShort((short) 9); result.putInt(0x02949E74); result.put(getAsciiString(effectFile)); @@ -53,18 +61,16 @@ public class PlayClientEffectLocMessage extends SWGMessage { result.putFloat(position.x); result.putFloat(position.y); result.putFloat(position.z); - result.putLong(0); - result.putInt(0); // unks seem to be always 0 - result.putShort((short) 0); - + result.putLong(cellId); + result.putFloat(0); // Sometimes 1 (aka 0x0000803A) for tie fighters + result.put(getAsciiString(commandString)); return result.flip(); - } - + @Override public void deserialize(IoBuffer data) { // TODO Auto-generated method stub } - + } diff --git a/src/protocol/swg/PlayClientEffectObjectMessage.java b/src/protocol/swg/PlayClientEffectObjectMessage.java index ad94129f..435acb73 100644 --- a/src/protocol/swg/PlayClientEffectObjectMessage.java +++ b/src/protocol/swg/PlayClientEffectObjectMessage.java @@ -26,13 +26,12 @@ import java.nio.ByteOrder; import org.apache.mina.core.buffer.IoBuffer; public class PlayClientEffectObjectMessage extends SWGMessage { - + private long objectId; private String effectFile; private String commandString; - + public PlayClientEffectObjectMessage(String effectFile, long objectId, String commandString) { - this.effectFile = effectFile; this.objectId = objectId; this.commandString = commandString; @@ -40,33 +39,21 @@ public class PlayClientEffectObjectMessage extends SWGMessage { @Override public IoBuffer serialize() { - - IoBuffer result = IoBuffer.allocate(20 + effectFile.length() + commandString.length()).order(ByteOrder.LITTLE_ENDIAN); - + int size = 20 + effectFile.length() + commandString.length() + ((effectFile.startsWith("clienteffect/holoemote_") ? commandString.length() : 0)); + IoBuffer result = IoBuffer.allocate(size).order(ByteOrder.LITTLE_ENDIAN); result.putShort((short) 5); result.putInt(0x8855434A); result.put(getAsciiString(effectFile)); - - if(!effectFile.startsWith("clienteffect/holoemote_")) - { - result.putShort((short) 0); // Because waverunner is a dweeb - result.putLong(objectId); - result.put(getAsciiString(commandString)); - } - else - { - result.put(getAsciiString(commandString)); - result.putLong(objectId); - } - + result.put(getAsciiString(effectFile.startsWith("clienteffect/holoemote_") ? commandString : "")); + result.putLong(objectId); + result.put(getAsciiString(commandString)); return result.flip(); - } - + @Override public void deserialize(IoBuffer data) { // TODO Auto-generated method stub } - + } diff --git a/src/protocol/swg/PlayClientEffectObjectTransformMessage.java b/src/protocol/swg/PlayClientEffectObjectTransformMessage.java index e5a0e7d4..f23af7a1 100644 --- a/src/protocol/swg/PlayClientEffectObjectTransformMessage.java +++ b/src/protocol/swg/PlayClientEffectObjectTransformMessage.java @@ -24,22 +24,19 @@ package protocol.swg; import java.nio.ByteOrder; import org.apache.mina.core.buffer.IoBuffer; -import org.apache.mina.core.buffer.SimpleBufferAllocator; import engine.resources.scene.Point3D; import engine.resources.scene.Quaternion; public class PlayClientEffectObjectTransformMessage extends SWGMessage { - + private long objectId; private String effectFile; private String commandString; private Point3D effectorPosition; private Quaternion effectorOrientation; - public SimpleBufferAllocator bufferPool = new SimpleBufferAllocator(); - + public PlayClientEffectObjectTransformMessage(String effectFile, long objectId, String commandString, Point3D effectorPosition, Quaternion effectorOrientation) { - this.effectFile = effectFile; this.objectId = objectId; this.commandString = commandString; @@ -49,42 +46,26 @@ public class PlayClientEffectObjectTransformMessage extends SWGMessage { @Override public IoBuffer serialize() { - - IoBuffer result = bufferPool.allocate(100, false).order(ByteOrder.LITTLE_ENDIAN); - result.setAutoExpand(true); + IoBuffer result = IoBuffer.allocate(46 + effectFile.length() + commandString.length(), false).order(ByteOrder.LITTLE_ENDIAN); result.putShort((short) 5); result.putInt(0x4F5E09B6); result.put(getAsciiString(effectFile)); - result.putFloat(effectorOrientation.w); // qw - result.putFloat(effectorOrientation.x); // qx - result.putFloat(effectorOrientation.y); // qy - result.putFloat(effectorOrientation.z); // qz - result.putFloat(effectorPosition.x); // pos.x - result.putFloat(effectorPosition.y); // pos.y - result.putFloat(effectorPosition.z); // pos.z + result.putFloat(effectorOrientation.w); + result.putFloat(effectorOrientation.x); + result.putFloat(effectorOrientation.y); + result.putFloat(effectorOrientation.z); + result.putFloat(effectorPosition.x); + result.putFloat(effectorPosition.y); + result.putFloat(effectorPosition.z); result.putLong(objectId); result.put(getAsciiString(commandString)); - - int size = result.position(); - result.flip(); - result = bufferPool.allocate(size, false).put(result.array(), 0, size); - - return IoBuffer.allocate(size).put(result.array(), 0, size).flip(); + return result.flip(); } - /* - 00 09 54 6C 05 00 B6 09-5E 4F 1B 00 61 70 70 65 - 61 72 61 6E 63 65 2F 70-74 5F 6C 6F 6F 74 5F 64 - 69 73 63 2E 70 72 74 00-00 00 00 00 00 00 00 00 - 00 00 00 00 00 80 3F 00-00 00 00 24 F8 AA 3F 00 - 00 00 00 3B 54 E1 3E 33-00 00 00 06 00 6C 6F 6F - 74 4D 65 01 EB 3C - */ - @Override public void deserialize(IoBuffer data) { // TODO Auto-generated method stub } - + } diff --git a/src/protocol/swg/SUICreatePageMessage.java b/src/protocol/swg/SUICreatePageMessage.java index 33046ada..6ed71340 100644 --- a/src/protocol/swg/SUICreatePageMessage.java +++ b/src/protocol/swg/SUICreatePageMessage.java @@ -36,27 +36,19 @@ public class SUICreatePageMessage extends SWGMessage{ private long rangeObjectId; private float range; - public SUICreatePageMessage(String script, int windowId, Vector components, long rangeObjectId, float range) { - this.script = script; this.windowId = windowId; this.components = components; this.rangeObjectId = rangeObjectId; this.range = range; - } - - - - public void deserialize(IoBuffer data) { } public IoBuffer serialize() { - IoBuffer result = IoBuffer.allocate(100).order(ByteOrder.LITTLE_ENDIAN); result.setAutoExpand(true); @@ -65,6 +57,7 @@ public class SUICreatePageMessage extends SWGMessage{ result.putInt(windowId); result.put(getAsciiString(script)); + result.putInt(components.size()); for(SUIWindowComponent component : components) { @@ -85,13 +78,12 @@ public class SUICreatePageMessage extends SWGMessage{ } result.putLong(rangeObjectId); + result.put(new byte[] { (byte) 0xFF, (byte) 0xFF, 0x7F, 0x7F, (byte) 0xFF, (byte) 0xFF, 0x7F, 0x7F, (byte) 0xFF, (byte) 0xFF, 0x7F, 0x7F}); result.putFloat(range); - result.putLong(0); - result.putInt(0); - + int size = result.position(); result = IoBuffer.allocate(size).put(result.array(), 0, size); - + return result.flip(); } } diff --git a/src/protocol/swg/SUICreateTimerBar.java b/src/protocol/swg/SUICreateTimerBar.java index 456f18ab..3e67f614 100644 --- a/src/protocol/swg/SUICreateTimerBar.java +++ b/src/protocol/swg/SUICreateTimerBar.java @@ -27,7 +27,7 @@ import java.util.List; import org.apache.mina.core.buffer.IoBuffer; -@SuppressWarnings("unused") +@Deprecated public class SUICreateTimerBar extends SWGMessage{ private String script; @@ -35,7 +35,7 @@ public class SUICreateTimerBar extends SWGMessage{ private int startCount; private int digitCount; private List digits = new ArrayList(); - String prompt; + private String prompt; public SUICreateTimerBar(String script, int windowId, String prompt, int startCount) { @@ -134,4 +134,30 @@ public class SUICreateTimerBar extends SWGMessage{ return result.flip(); } + + /* + This is just a simple SUICreatePageMessage and can be achieved through the proper system: + + 02 00 F6 42 33 5F 61 EF 00 00 18 00 53 63 72 69 ...B3_a.....Scri + 70 74 2E 43 6F 75 6E 74 64 6F 77 6E 54 69 6D 65 pt.CountdownTime + 72 42 61 72 03 00 00 00 03 01 00 00 00 28 00 00 rBar.........(.. + 00 40 00 73 00 61 00 67 00 61 00 5F 00 73 00 79 .@.s.a.g.a._.s.y + 00 73 00 74 00 65 00 6D 00 3A 00 68 00 6F 00 6C .s.t.e.m.:.h.o.l + 00 6F 00 63 00 72 00 6F 00 6E 00 5F 00 63 00 72 .o.c.r.o.n._.c.r + 00 65 00 61 00 74 00 69 00 6F 00 6E 00 5F 00 63 .e.a.t.i.o.n._.c + 00 6F 00 75 00 6E 00 74 00 64 00 6F 00 77 00 6E .o.u.n.t.d.o.w.n + 00 02 00 00 00 09 00 63 6F 6D 70 2E 74 65 78 74 .......comp.text + 04 00 54 65 78 74 03 01 00 00 00 15 00 00 00 70 ..Text.........p + 00 67 00 63 00 5F 00 68 00 6F 00 6C 00 6F 00 63 .g.c._.h.o.l.o.c + 00 72 00 6F 00 6E 00 5F 00 63 00 72 00 65 00 61 .r.o.n._.c.r.e.a + 00 74 00 69 00 6F 00 6E 00 02 00 00 00 13 00 62 .t.i.o.n.......b + 67 2E 63 61 70 74 69 6F 6E 2E 6C 62 6C 54 69 74 g.caption.lblTit + 6C 65 04 00 54 65 78 74 03 01 00 00 00 03 00 00 le..Text........ + 00 30 00 2C 00 33 00 02 00 00 00 04 00 74 68 69 .0.,.3.......thi + 73 17 00 63 6F 75 6E 74 64 6F 77 6E 54 69 6D 65 s..countdownTime + 72 54 69 6D 65 56 61 6C 75 65 00 00 00 00 00 00 rTimeValue...... + 00 00 E2 CE 48 C5 5D BF C7 40 A9 33 FC 44 00 00 ....H.]..@.3.D.. + 40 40 @@ + */ + } diff --git a/src/protocol/swg/SUIUpdatePageMessage.java b/src/protocol/swg/SUIUpdatePageMessage.java index af733a2c..06d6f571 100644 --- a/src/protocol/swg/SUIUpdatePageMessage.java +++ b/src/protocol/swg/SUIUpdatePageMessage.java @@ -29,30 +29,26 @@ import org.apache.mina.core.buffer.IoBuffer; import services.sui.SUIWindowComponent; public class SUIUpdatePageMessage extends SWGMessage { - + private String script; private int windowId; private Vector components; private long rangeObjectId; private float range; - public SUIUpdatePageMessage(String script, int windowId, Vector components, long rangeObjectId, float range) { - this.script = script; this.windowId = windowId; this.components = components; this.rangeObjectId = rangeObjectId; this.range = range; - } - + public void deserialize(IoBuffer data) { } public IoBuffer serialize() { - IoBuffer result = IoBuffer.allocate(100).order(ByteOrder.LITTLE_ENDIAN); result.setAutoExpand(true); @@ -67,28 +63,26 @@ public class SUIUpdatePageMessage extends SWGMessage { result.put(component.getType()); result.putInt(component.getWideParams().size()); - + for(String param : component.getWideParams()) { result.put(getUnicodeString(param)); } result.putInt(component.getNarrowParams().size()); - + for(String param : component.getNarrowParams()) { result.put(getAsciiString(param)); } - } result.putLong(rangeObjectId); + result.put(new byte[] { (byte) 0xFF, (byte) 0xFF, 0x7F, 0x7F, (byte) 0xFF, (byte) 0xFF, 0x7F, 0x7F, (byte) 0xFF, (byte) 0xFF, 0x7F, 0x7F}); result.putFloat(range); - result.putLong(0); - result.putInt(0); - + int size = result.position(); result = IoBuffer.allocate(size).put(result.array(), 0, size); - + return result.flip(); } - + } diff --git a/src/protocol/swg/auctionManagerClientListener/AuctionQueryHeadersMessage.java b/src/protocol/swg/auctionManagerClientListener/AuctionQueryHeadersMessage.java index b92f96c3..9247f215 100644 --- a/src/protocol/swg/auctionManagerClientListener/AuctionQueryHeadersMessage.java +++ b/src/protocol/swg/auctionManagerClientListener/AuctionQueryHeadersMessage.java @@ -21,8 +21,8 @@ ******************************************************************************/ package protocol.swg.auctionManagerClientListener; -import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import org.apache.mina.core.buffer.IoBuffer; @@ -35,6 +35,7 @@ public class AuctionQueryHeadersMessage extends SWGMessage { private int screen; private int category; private int itemTypeCRC; + private byte unk; private String searchString; private int unkInt; private int minPrice; @@ -47,28 +48,26 @@ public class AuctionQueryHeadersMessage extends SWGMessage { @Override public void deserialize(IoBuffer data) { data.skip(6); - setRange(data.getInt()); - setCounter(data.getInt()); - setScreen(data.getInt()); - setCategory(data.getInt()); - setItemTypeCRC(data.getInt()); - data.get(); // unk + this.range = data.getInt(); + this.counter = data.getInt(); + this.screen = data.getInt(); + this.category = data.getInt(); + this.itemTypeCRC = data.getInt(); + this.unk = data.get(); int size = data.getInt(); - try { - setSearchString(new String(ByteBuffer.allocate(size * 2).put(data.array(), data.position(), size * 2).array(), "UTF-16LE")); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } + + this.searchString = new String(ByteBuffer.allocate(size * 2).put(data.array(), data.position(), size * 2).array(), StandardCharsets.UTF_16LE); + data.position(data.position() + size * 2); - setUnkInt(data.getInt()); - setMinPrice(data.getInt()); - setMaxPrice(data.getInt()); - setIncludeEntranceFee(data.get()); + this.unkInt = data.getInt(); + this.minPrice = data.getInt(); + this.maxPrice = data.getInt(); + this.includeEntranceFee = data.get(); // Ziggy - boolean? data.skip(5); // unk - setVendorId(data.getLong()); - setVendorFlag(data.get()); - setOffset(data.getShort()); + this.vendorId = data.getLong(); + this.vendorFlag = data.get(); + this.offset = data.getShort(); } @@ -82,104 +81,56 @@ public class AuctionQueryHeadersMessage extends SWGMessage { return range; } - public void setRange(int range) { - this.range = range; - } - public int getCounter() { return counter; } - - public void setCounter(int counter) { - this.counter = counter; - } - + public int getScreen() { return screen; } - public void setScreen(int screen) { - this.screen = screen; - } - public int getCategory() { return category; } - - public void setCategory(int category) { - this.category = category; - } - + public int getItemTypeCRC() { return itemTypeCRC; } - public void setItemTypeCRC(int itemTypeCRC) { - this.itemTypeCRC = itemTypeCRC; - } - public String getSearchString() { return searchString; } - public void setSearchString(String searchString) { - this.searchString = searchString; - } - public int getUnkInt() { return unkInt; } - public void setUnkInt(int unkInt) { - this.unkInt = unkInt; - } - public int getMinPrice() { return minPrice; } - public void setMinPrice(int minPrice) { - this.minPrice = minPrice; - } - public int getMaxPrice() { return maxPrice; } - public void setMaxPrice(int maxPrice) { - this.maxPrice = maxPrice; - } - public byte getIncludeEntranceFee() { return includeEntranceFee; } - public void setIncludeEntranceFee(byte includeEntranceFee) { - this.includeEntranceFee = includeEntranceFee; - } - public long getVendorId() { return vendorId; } - public void setVendorId(long vendorId) { - this.vendorId = vendorId; - } - public byte getVendorFlag() { return vendorFlag; } - public void setVendorFlag(byte vendorFlag) { - this.vendorFlag = vendorFlag; - } - public short getOffset() { return offset; } - public void setOffset(short offset) { - this.offset = offset; + public byte getUnk() { + return unk; } } diff --git a/src/protocol/swg/auctionManagerClientListener/CreateAuctionMessage.java b/src/protocol/swg/auctionManagerClientListener/CreateAuctionMessage.java index 33a57339..72e19e7c 100644 --- a/src/protocol/swg/auctionManagerClientListener/CreateAuctionMessage.java +++ b/src/protocol/swg/auctionManagerClientListener/CreateAuctionMessage.java @@ -21,8 +21,8 @@ ******************************************************************************/ package protocol.swg.auctionManagerClientListener; -import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import org.apache.mina.core.buffer.IoBuffer; @@ -35,24 +35,21 @@ public class CreateAuctionMessage extends SWGMessage { private int price; private int duration; private String description; - private byte premium; + private boolean isPremium; @Override public void deserialize(IoBuffer data) { data.skip(6); - setObjectId(data.getLong()); + this.objectId = data.getLong(); int size = data.getInt(); - try { - setDescription(new String(ByteBuffer.allocate(size * 2).put(data.array(), data.position(), size * 2).array(), "UTF-16LE")); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - data.position(data.position() + size * 2); + this.description = new String(ByteBuffer.allocate(size * 2).put(data.array(), data.position(), size * 2).array(), StandardCharsets.UTF_16LE); - setVendorId(data.getLong()); - setPrice(data.getInt()); - setDuration(data.getInt()); // in minutes - setPremium(data.get()); + data.position(data.position() + size * 2); + + this.vendorId = data.getLong(); + this.price = data.getInt(); + this.duration = data.getInt(); // in minutes + this.isPremium = (data.get() == 0 ? false : true); } @Override @@ -65,50 +62,24 @@ public class CreateAuctionMessage extends SWGMessage { return objectId; } - public void setObjectId(long objectId) { - this.objectId = objectId; - } - public long getVendorId() { return vendorId; } - public void setVendorId(long vendorId) { - this.vendorId = vendorId; - } - public int getPrice() { return price; } - public void setPrice(int price) { - this.price = price; - } - public int getDuration() { return duration; } - public void setDuration(int duration) { - this.duration = duration; - } - public String getDescription() { return description; } - public void setDescription(String description) { - this.description = description; - } - - public boolean getPremium() { - if(premium == 1) - return true; - return false; - } - - public void setPremium(byte premium) { - this.premium = premium; + public boolean isPremium() { + return isPremium; } } diff --git a/src/protocol/swg/auctionManagerClientListener/CreateImmediateAuctionMessage.java b/src/protocol/swg/auctionManagerClientListener/CreateImmediateAuctionMessage.java index 0546f41e..bf638873 100644 --- a/src/protocol/swg/auctionManagerClientListener/CreateImmediateAuctionMessage.java +++ b/src/protocol/swg/auctionManagerClientListener/CreateImmediateAuctionMessage.java @@ -21,8 +21,8 @@ ******************************************************************************/ package protocol.swg.auctionManagerClientListener; -import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import org.apache.mina.core.buffer.IoBuffer; @@ -35,23 +35,21 @@ public class CreateImmediateAuctionMessage extends SWGMessage { private int price; private int duration; private String description; - private byte premium; + private boolean isPremium; @Override public void deserialize(IoBuffer data) { data.skip(6); - setObjectId(data.getLong()); - setVendorId(data.getLong()); - setPrice(data.getInt()); - setDuration(data.getInt()); // in minutes + this.objectId = data.getLong(); + this.vendorId = data.getLong(); + this.price = data.getInt(); + this.duration = data.getInt(); + int size = data.getInt(); - try { - setDescription(new String(ByteBuffer.allocate(size * 2).put(data.array(), data.position(), size * 2).array(), "UTF-16LE")); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } + + this.description = new String(ByteBuffer.allocate(size * 2).put(data.array(), data.position(), size * 2).array(), StandardCharsets.UTF_16LE); data.position(data.position() + size * 2); - setPremium(data.get()); + this.isPremium = (data.get() == 0 ? false : true); } @Override @@ -64,50 +62,27 @@ public class CreateImmediateAuctionMessage extends SWGMessage { return objectId; } - public void setObjectId(long objectId) { - this.objectId = objectId; - } - public long getVendorId() { return vendorId; } - public void setVendorId(long vendorId) { - this.vendorId = vendorId; - } - public int getPrice() { return price; } - public void setPrice(int price) { - this.price = price; - } - +/* + * @return Duration in minutes + */ public int getDuration() { return duration; } - public void setDuration(int duration) { - this.duration = duration; - } - public String getDescription() { return description; } - public void setDescription(String description) { - this.description = description; - } - - public boolean getPremium() { - if(premium == 1) - return true; - return false; - } - - public void setPremium(byte premium) { - this.premium = premium; + public boolean isPremium() { + return isPremium; } } diff --git a/src/protocol/swg/chat/ChatInstantMessageToCharacter.java b/src/protocol/swg/chat/ChatInstantMessageToCharacter.java index c4e746f3..3547220a 100644 --- a/src/protocol/swg/chat/ChatInstantMessageToCharacter.java +++ b/src/protocol/swg/chat/ChatInstantMessageToCharacter.java @@ -21,7 +21,6 @@ ******************************************************************************/ package protocol.swg.chat; -import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; diff --git a/src/protocol/swg/objectControllerObjects/CommandEnqueue.java b/src/protocol/swg/objectControllerObjects/CommandEnqueue.java index bb1705a4..5e4278ca 100644 --- a/src/protocol/swg/objectControllerObjects/CommandEnqueue.java +++ b/src/protocol/swg/objectControllerObjects/CommandEnqueue.java @@ -21,13 +21,11 @@ ******************************************************************************/ package protocol.swg.objectControllerObjects; -import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import org.apache.mina.core.buffer.IoBuffer; -@SuppressWarnings("unused") - public class CommandEnqueue extends ObjControllerObject { public static final int SOCIAL_INTERNAL = 0x32CF1BEE; @@ -48,7 +46,7 @@ public class CommandEnqueue extends ObjControllerObject { public static final int FLO = 0x3B159B76; public static final int BANDFLOURISH = 0xF4C60EC3; public static final int BANDFLO = 0xDD3FB008; - + private int actionCounter; private int commandCRC; private long targetId; @@ -56,31 +54,22 @@ public class CommandEnqueue extends ObjControllerObject { private final int commandObjectIndex = 20; private long objectId; private String commandArguments; - + public CommandEnqueue() { } - public CommandEnqueue(int actionCounter, ObjControllerObject commandObject) { - this.actionCounter = actionCounter; - this.commandObject = commandObject; - } - + public void deserialize(IoBuffer buffer) { - objectId = buffer.getLong(); - buffer.getInt(); - actionCounter = buffer.getInt(); + int size; + + this.objectId = buffer.getLong(); + buffer.getInt(); // Ziggy - related to commandObjectIndex? + this.actionCounter = buffer.getInt(); + this.commandCRC = buffer.getInt(); + this.targetId = buffer.getLong(); + size = buffer.getInt(); - commandCRC = buffer.getInt(); - targetId = buffer.getLong(); - int size = buffer.getInt(); - try { - commandArguments = new String(ByteBuffer.allocate(size * 2).put(buffer.array(), buffer.position(), size * 2).array(), "UTF-16LE"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - - //commandArguments = getNextUnicodeString(buffer); - //commandObject = getCommandObject(commandCRC); + commandArguments = new String(ByteBuffer.allocate(size * 2).put(buffer.array(), buffer.position(), size * 2).array(), StandardCharsets.UTF_16LE); } public IoBuffer serialize() { diff --git a/src/protocol/swg/objectControllerObjects/ObjController_448.java b/src/protocol/swg/objectControllerObjects/ObjController_448.java index f6324a5e..9aa15ae3 100644 --- a/src/protocol/swg/objectControllerObjects/ObjController_448.java +++ b/src/protocol/swg/objectControllerObjects/ObjController_448.java @@ -27,6 +27,7 @@ import org.apache.mina.core.buffer.IoBuffer; import protocol.swg.ObjControllerMessage; +@Deprecated public class ObjController_448 extends ObjControllerObject { private long objectId; diff --git a/src/protocol/swg/objectControllerObjects/QuestTaskCounterMessage.java b/src/protocol/swg/objectControllerObjects/QuestTaskCounterMessage.java index 421f9748..757d798c 100644 --- a/src/protocol/swg/objectControllerObjects/QuestTaskCounterMessage.java +++ b/src/protocol/swg/objectControllerObjects/QuestTaskCounterMessage.java @@ -26,16 +26,17 @@ import java.nio.ByteOrder; import org.apache.mina.core.buffer.IoBuffer; import protocol.swg.ObjControllerMessage; +import resources.quest.Quest; public class QuestTaskCounterMessage extends ObjControllerObject { private long objectId; - private String questName; + private Quest quest; private String stf; - public QuestTaskCounterMessage(long objectId, String questName, String stf) { + public QuestTaskCounterMessage(long objectId, Quest quest, String stf) { this.objectId = objectId; - this.questName = questName; + this.quest = quest; this.stf = stf; } @@ -47,7 +48,7 @@ public class QuestTaskCounterMessage extends ObjControllerObject { @Override public IoBuffer serialize() { - byte[] questNameBytes = getAsciiString(questName); + byte[] questNameBytes = getAsciiString(quest.getCrcName()); byte[] stfBytes = getUnicodeString(stf); IoBuffer buffer = IoBuffer.allocate(38 + questNameBytes.length + stfBytes.length).order(ByteOrder.LITTLE_ENDIAN); @@ -57,10 +58,10 @@ public class QuestTaskCounterMessage extends ObjControllerObject { buffer.putInt(0); buffer.put(questNameBytes); - buffer.putInt(1); // ?? + buffer.putInt(quest.getCounterMax()); // Max count buffer.put(stfBytes); - buffer.putInt(0); // ?? - buffer.putInt(1); // ?? + buffer.putInt(0); // spacer? + buffer.putInt(quest.getCounterValue()); // Current count return buffer.flip(); } diff --git a/src/protocol/swg/objectControllerObjects/ShowQuestAcceptWindow.java b/src/protocol/swg/objectControllerObjects/ShowQuestAcceptWindow.java index 9fb2d7dc..125155a4 100644 --- a/src/protocol/swg/objectControllerObjects/ShowQuestAcceptWindow.java +++ b/src/protocol/swg/objectControllerObjects/ShowQuestAcceptWindow.java @@ -24,16 +24,17 @@ package protocol.swg.objectControllerObjects; import org.apache.mina.core.buffer.IoBuffer; import protocol.swg.ObjControllerMessage; +import engine.resources.common.CRC; import engine.resources.objects.Baseline; public class ShowQuestAcceptWindow extends ObjControllerObject { private long objectId; - private int questCrc; + private String questName; - public ShowQuestAcceptWindow(long objectId, int questCrc) { + public ShowQuestAcceptWindow(long objectId, String questName) { this.objectId = objectId; - this.questCrc = questCrc; + this.questName = questName; } @Override @@ -44,11 +45,11 @@ public class ShowQuestAcceptWindow extends ObjControllerObject { public IoBuffer serialize() { IoBuffer buffer = Baseline.createBuffer(20); - buffer.putInt(ObjControllerMessage.SHOW_QUEST_COMPLETION_WINDOW); + buffer.putInt(ObjControllerMessage.SHOW_QUEST_ACCEPT_WINDOW); buffer.putLong(objectId); buffer.putInt(0); - buffer.putInt(questCrc); + buffer.putInt(CRC.StringtoCRC(questName)); return buffer.flip(); } diff --git a/src/protocol/swg/objectControllerObjects/ShowQuestCompletionWindow.java b/src/protocol/swg/objectControllerObjects/ShowQuestCompletionWindow.java index 6078f56d..4a5070b5 100644 --- a/src/protocol/swg/objectControllerObjects/ShowQuestCompletionWindow.java +++ b/src/protocol/swg/objectControllerObjects/ShowQuestCompletionWindow.java @@ -24,16 +24,17 @@ package protocol.swg.objectControllerObjects; import org.apache.mina.core.buffer.IoBuffer; import protocol.swg.ObjControllerMessage; +import engine.resources.common.CRC; import engine.resources.objects.Baseline; public class ShowQuestCompletionWindow extends ObjControllerObject { private long objectId; - private int questCrc; + private String questName; - public ShowQuestCompletionWindow(long objectId, int questCrc) { + public ShowQuestCompletionWindow(long objectId, String questName) { this.objectId = objectId; - this.questCrc = questCrc; + this.questName = questName; } @Override @@ -48,7 +49,7 @@ public class ShowQuestCompletionWindow extends ObjControllerObject { buffer.putLong(objectId); buffer.putInt(0); - buffer.putInt(questCrc); + buffer.putInt(CRC.StringtoCRC(questName)); return buffer.flip(); } diff --git a/src/resources/common/Opcodes.java b/src/resources/common/Opcodes.java index 245aa8a6..666ccb0a 100644 --- a/src/resources/common/Opcodes.java +++ b/src/resources/common/Opcodes.java @@ -100,5 +100,7 @@ public class Opcodes { public static final int CreateCharacterSuccess = 0x1DB575CC; public static final int PlayerMoneyResponse = 0x367E737E; public static final int CmdStartScene = 0x3AE6DFAE; + public static final int IncubatorStartMessage = CRC.StringtoCRC("IncubatorStartMessage"); + public static final int EnterTicketPurchaseModeMessage = 0x904DAE1A; } diff --git a/src/resources/objects/SWGList.java b/src/resources/objects/SWGList.java index 790232f2..383394cf 100644 --- a/src/resources/objects/SWGList.java +++ b/src/resources/objects/SWGList.java @@ -233,7 +233,7 @@ public class SWGList extends Delta implements List { int index = list.indexOf(o); if (list.remove(o)) { - queue(item(1, index, null, true, false)); + queue(item(0, index, null, true, false)); return true; } else { return false; @@ -245,7 +245,7 @@ public class SWGList extends Delta implements List { synchronized(objectMutex) { E element = list.remove(index); - queue(item(1, index, null, true, false)); + queue(item(0, index, null, true, false)); return (E) element; } diff --git a/src/resources/objects/creature/CreatureObject.java b/src/resources/objects/creature/CreatureObject.java index 0d4fc028..32521beb 100644 --- a/src/resources/objects/creature/CreatureObject.java +++ b/src/resources/objects/creature/CreatureObject.java @@ -190,7 +190,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { baseline.put("visibleOnRadar", true); baseline.put("isPet", false); baseline.put("32", (byte) 0); - baseline.put("appearanceEquipmentList", new SWGList(this, 6, 31, false)); + baseline.put("appearanceEquipmentList", new SWGList(this, 6, 33, false)); baseline.put("34", (long) 0); return baseline; } @@ -220,9 +220,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { } public void setBankCredits(int bankCredits) { - if (getClient() != null && getClient().getSession() != null) { - getClient().getSession().write(getBaseline(1).set("bankCredits", bankCredits)); - } + notifySelf(getBaseline(1).set("bankCredits", bankCredits)); } public void addBankCredits(int bankCredits) { @@ -242,9 +240,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { } public void setCashCredits(int cashCredits) { - if (getClient() != null && getClient().getSession() != null) { - getClient().getSession().write(getBaseline(1).set("cashCredits", cashCredits)); - } + notifySelf(getBaseline(1).set("cashCredits", cashCredits)); } public void addCashCredits(int cashCredits) { @@ -434,9 +430,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { } public void setAccelerationMultiplierBase(float accelerationMultiplierBase) { - if (getClient() != null && getClient().getSession() != null) { - getClient().getSession().write(getBaseline(4).set("accelerationMultiplierBase", accelerationMultiplierBase)); - } + notifySelf(getBaseline(4).set("accelerationMultiplierBase", accelerationMultiplierBase)); } public float getAccelerationMultiplierMod() { @@ -444,9 +438,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { } public void setAccelerationMultiplierMod(float accelerationMultiplierMod) { - if (getClient() != null && getClient().getSession() != null) { - getClient().getSession().write(getBaseline(4).set("accelerationMultiplierMod", accelerationMultiplierMod)); - } + notifySelf(getBaseline(4).set("accelerationMultiplierMod", accelerationMultiplierMod)); } @SuppressWarnings("unchecked") @@ -539,9 +531,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { } public void setSpeedMultiplierBase(float speedMultiplierBase) { - if (getClient() != null && getClient().getSession() != null) { - getClient().getSession().write(getBaseline(4).set("speedMultiplierBase", speedMultiplierBase)); - } + notifySelf(getBaseline(4).set("speedMultiplierBase", speedMultiplierBase)); } public float getSpeedMultiplierMod() { @@ -549,9 +539,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { } public void setSpeedMultiplierMod(float speedMultiplierMod) { - if (getClient() != null && getClient().getSession() != null) { - getClient().getSession().write(getBaseline(4).set("speedMultiplierMod", speedMultiplierMod)); - } + notifySelf(getBaseline(4).set("speedMultiplierMod", speedMultiplierMod)); } public long getListenToId() { @@ -559,9 +547,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { } public void setListenToId(long listenToId) { - if (getClient() != null && getClient().getSession() != null) { - getClient().getSession().write(getBaseline(4).set("listenToId", listenToId)); - } + notifySelf(getBaseline(4).set("listenToId", listenToId)); } public float getRunSpeed() { @@ -569,9 +555,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { } public void setRunSpeed(float runSpeed) { - if (getClient() != null && getClient().getSession() != null) { - getClient().getSession().write(getBaseline(4).set("runSpeed", runSpeed)); - } + notifySelf(getBaseline(4).set("runSpeed", runSpeed)); } public float getSlopeModAngle() { @@ -579,9 +563,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { } public void setSlopeModAngle(float slopeModAngle) { - if (getClient() != null && getClient().getSession() != null) { - getClient().getSession().write(getBaseline(4).set("slopeModAngle", slopeModAngle)); - } + notifySelf(getBaseline(4).set("slopeModAngle", slopeModAngle)); } public float getSlopeModPercent() { @@ -589,9 +571,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { } public void setSlopeModPercent(float slopeModPercent) { - if (getClient() != null && getClient().getSession() != null) { - getClient().getSession().write(getBaseline(4).set("slopeModPercent", slopeModPercent)); - } + notifySelf(getBaseline(4).set("slopeModPercent", slopeModPercent)); } public float getTurnRadius() { @@ -599,9 +579,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { } public void setTurnRadius(float turnRadius) { - if (getClient() != null && getClient().getSession() != null) { - getClient().getSession().write(getBaseline(4).set("turnRadius", turnRadius)); - } + notifySelf(getBaseline(4).set("turnRadius", turnRadius)); } public float getWalkSpeed() { @@ -609,9 +587,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { } public void setWalkSpeed(float walkSpeed) { - if (getClient() != null && getClient().getSession() != null) { - getClient().getSession().write(getBaseline(4).set("walkSpeed", walkSpeed)); - } + notifySelf(getBaseline(4).set("walkSpeed", walkSpeed)); } public float getWaterModPercent() { @@ -619,9 +595,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { } public void setWaterModPercent(float waterModPercent) { - if (getClient() != null && getClient().getSession() != null) { - getClient().getSession().write(getBaseline(4).set("waterModPercent", waterModPercent)); - } + notifySelf(getBaseline(4).set("waterModPercent", waterModPercent)); } @SuppressWarnings("unchecked") @@ -661,9 +635,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { } public void setDisplayXp(int displayXp) { - if (getClient() != null && getClient().getSession() != null) { - getClient().getSession().write(getBaseline(4).set("displayXp", displayXp)); - } + notifySelf(getBaseline(4).set("displayXp", displayXp)); } public short getLevel() { @@ -748,9 +720,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { } public void updateGroupInviteInfo() { - if (getClient() != null && getClient().getSession() != null) { - getClient().getSession().write(getBaseline(6).set("groupInviteInfo", getGroupInviteInfo())); - } + notifySelf(getBaseline(6).set("groupInviteInfo", getGroupInviteInfo())); } public int getGuildId() { @@ -927,12 +897,13 @@ public class CreatureObject extends TangibleObject implements IPersistent { } } - public boolean isWearing(SWGObject object) - { - for (Equipment equipment : getEquipmentList()) - { - if (equipment.getObjectId() == object.getObjectId()) return true; + public boolean isWearing(SWGObject object) { + for (Equipment equipment : getEquipmentList()) { + if (equipment.getObjectId() == object.getObjectId()) { + return true; + } } + return false; } @@ -1158,6 +1129,16 @@ public class CreatureObject extends TangibleObject implements IPersistent { } } + public boolean isWearingAppearance(SWGObject object) { + for (Equipment equipment : getAppearanceEquipmentList()) { + if (equipment.getObjectId() == object.getObjectId()) { + return true; + } + } + + return false; + } + public void removeObjectFromAppearanceEquipList(SWGObject object) { if (object instanceof TangibleObject) { for (Equipment equipment : getAppearanceEquipmentList()) { @@ -1370,9 +1351,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { } public void sendSystemMessage(String message, OutOfBand outOfBand, byte displayType) { - if (getClient() != null && getClient().getSession() != null) { - getClient().getSession().write((new ChatSystemMessage(message, outOfBand, displayType)).serialize()); - } + notifySelf((new ChatSystemMessage(message, outOfBand, displayType)).serialize()); } public void playMusic(String sndFile) { @@ -1392,13 +1371,19 @@ public class CreatureObject extends TangibleObject implements IPersistent { } public void playMusic(String sndFile, long targetId, int repetitions, boolean flag) { - getClient().getSession().write(new PlayMusicMessage(sndFile, targetId, 1, false)); + notifySelf((new PlayMusicMessage(sndFile, targetId, 1, false)).serialize()); } public TangibleObject getInventory() { return (TangibleObject) getSlottedObject("inventory"); } + public void notifySelf(IoBuffer buffer) { + if (getClient() != null && getClient().getSession() != null) { + getClient().getSession().write(buffer); + } + } + public void notifyClients(IoBuffer buffer, boolean notifySelf) { notifyObservers(buffer, notifySelf); } diff --git a/src/resources/objects/player/PlayerObject.java b/src/resources/objects/player/PlayerObject.java index f0729a04..94b2881d 100644 --- a/src/resources/objects/player/PlayerObject.java +++ b/src/resources/objects/player/PlayerObject.java @@ -567,9 +567,7 @@ public class PlayerObject extends IntangibleObject implements Serializable { } public void setCurrentForcePower(int currentForcePower) { - if (getClient() != null) { - getClient().getSession().write(getBaseline(8).set("currentForcePower", currentForcePower)); - } + notifySelf(getBaseline(8).set("currentForcePower", currentForcePower)); } public int getMaxForcePower() { @@ -577,9 +575,7 @@ public class PlayerObject extends IntangibleObject implements Serializable { } public void setMaxForcePower(int maxForcePower) { - if (getClient() != null) { - getClient().getSession().write(getBaseline(8).set("maxForcePower", maxForcePower)); - } + notifySelf(getBaseline(8).set("maxForcePower", maxForcePower)); } @SuppressWarnings("unchecked") @@ -632,9 +628,7 @@ public class PlayerObject extends IntangibleObject implements Serializable { } public void setProfessionWheelPosition(String professionWheelPosition) { - if (getClient() != null) { - getClient().getSession().write(getBaseline(8).set("professionWheelPosition", professionWheelPosition)); - } + notifySelf(getBaseline(8).set("professionWheelPosition", professionWheelPosition)); } public int getExperimentationFlag() { @@ -642,9 +636,7 @@ public class PlayerObject extends IntangibleObject implements Serializable { } public void setExperimentationFlag(int experimentationFlag) { - if (getClient() != null) { - getClient().getSession().write(getBaseline(9).set("experimentationFlag", experimentationFlag)); - } + notifySelf(getBaseline(9).set("experimentationFlag", experimentationFlag)); } public int getCraftingStage() { @@ -652,9 +644,7 @@ public class PlayerObject extends IntangibleObject implements Serializable { } public void setCraftingStage(int craftingStage) { - if (getClient() != null) { - getClient().getSession().write(getBaseline(9).set("craftingStage", craftingStage)); - } + notifySelf(getBaseline(9).set("craftingStage", craftingStage)); } public long getNearestCraftingStation() { @@ -662,9 +652,7 @@ public class PlayerObject extends IntangibleObject implements Serializable { } public void setNearestCraftingStation(long nearestCraftingStation) { - if (getClient() != null) { - getClient().getSession().write(getBaseline(9).set("nearestCraftingStation", nearestCraftingStation)); - } + notifySelf(getBaseline(9).set("nearestCraftingStation", nearestCraftingStation)); } @SuppressWarnings("unchecked") @@ -677,9 +665,7 @@ public class PlayerObject extends IntangibleObject implements Serializable { } public void setExperimentationPoints(int experimentationPoints) { - if (getClient() != null) { - getClient().getSession().write(getBaseline(9).set("experimentationPoints", experimentationPoints)); - } + notifySelf(getBaseline(9).set("experimentationPoints", experimentationPoints)); } public int getAccomplishmentCounter() { @@ -687,9 +673,7 @@ public class PlayerObject extends IntangibleObject implements Serializable { } public void setAccomplishmentCounter(int accomplishmentCounter) { - if (getClient() != null) { - getClient().getSession().write(getBaseline(9).set("accomplishmentCounter", accomplishmentCounter)); - } + notifySelf(getBaseline(9).set("accomplishmentCounter", accomplishmentCounter)); } @SuppressWarnings("unchecked") @@ -723,9 +707,7 @@ public class PlayerObject extends IntangibleObject implements Serializable { } public void setLanguageId(int languageId) { - if (getClient() != null) { - getClient().getSession().write(getBaseline(9).set("languageId", languageId)); - } + notifySelf(getBaseline(9).set("languageId", languageId)); } public int getCurrentStomach() { @@ -733,9 +715,7 @@ public class PlayerObject extends IntangibleObject implements Serializable { } public void setCurrentStomach(int currentStomach) { - if (getClient() != null) { - getClient().getSession().write(getBaseline(9).set("currentStomach", currentStomach)); - } + notifySelf(getBaseline(9).set("currentStomach", currentStomach)); } public int getMaxStomach() { @@ -743,9 +723,7 @@ public class PlayerObject extends IntangibleObject implements Serializable { } public void setMaxStomach(int maxStomach) { - if (getClient() != null) { - getClient().getSession().write(getBaseline(9).set("maxStomach", maxStomach)); - } + notifySelf(getBaseline(9).set("maxStomach", maxStomach)); } public int getCurrentDrink() { @@ -753,9 +731,7 @@ public class PlayerObject extends IntangibleObject implements Serializable { } public void setCurrentDrink(int currentDrink) { - if (getClient() != null) { - getClient().getSession().write(getBaseline(9).set("currentDrink", currentDrink)); - } + notifySelf(getBaseline(9).set("currentDrink", currentDrink)); } public int getMaxDrink() { @@ -763,9 +739,7 @@ public class PlayerObject extends IntangibleObject implements Serializable { } public void setMaxDrink(int maxDrink) { - if (getClient() != null) { - getClient().getSession().write(getBaseline(9).set("maxDrink", maxDrink)); - } + notifySelf(getBaseline(9).set("maxDrink", maxDrink)); } public int getCurrentConsumable() { @@ -773,9 +747,7 @@ public class PlayerObject extends IntangibleObject implements Serializable { } public void setCurrentConsumable(int currentConsumable) { - if (getClient() != null) { - getClient().getSession().write(getBaseline(9).set("currentConsumable", currentConsumable)); - } + notifySelf(getBaseline(9).set("currentConsumable", currentConsumable)); } public int getMaxConsumable() { @@ -783,9 +755,7 @@ public class PlayerObject extends IntangibleObject implements Serializable { } public void setMaxConsumable(int maxConsumable) { - if (getClient() != null) { - getClient().getSession().write(getBaseline(9).set("maxConsumable", maxConsumable)); - } + notifySelf(getBaseline(9).set("maxConsumable", maxConsumable)); } @SuppressWarnings("unchecked") @@ -798,9 +768,7 @@ public class PlayerObject extends IntangibleObject implements Serializable { } public void setKillMeterPoints(int points) { - if (getClient() != null) { - getClient().getSession().write(getBaseline(9).set("killMeterPoints", points)); - } + notifySelf(getBaseline(9).set("killMeterPoints", points)); } public long getPet() { @@ -808,9 +776,7 @@ public class PlayerObject extends IntangibleObject implements Serializable { } public void setPet(long pet) { - if (getClient() != null) { - getClient().getSession().write(getBaseline(9).set("pet", pet)); - } + notifySelf(getBaseline(9).set("pet", pet)); } @SuppressWarnings("unchecked") @@ -1018,6 +984,12 @@ public class PlayerObject extends IntangibleObject implements Serializable { return getOwnedVendors().size(); } + public void notifySelf(IoBuffer buffer) { + if (getContainer() != null && getContainer().getClient() != null && getContainer().getClient().getSession() != null) { + getContainer().getClient().getSession().write(buffer); + } + } + @Override public void notifyClients(IoBuffer buffer, boolean notifySelf) { if (getContainer() != null) { diff --git a/src/resources/objects/tangible/TangibleObject.java b/src/resources/objects/tangible/TangibleObject.java index bede3913..1b84582f 100644 --- a/src/resources/objects/tangible/TangibleObject.java +++ b/src/resources/objects/tangible/TangibleObject.java @@ -104,6 +104,7 @@ public class TangibleObject extends SWGObject implements Serializable { public void initAfterDBLoad() { super.init(); defendersList = new Vector(); + cooldowns = new ConcurrentHashMap(); } public Baseline getOtherVariables() { diff --git a/src/resources/quest/Quest.java b/src/resources/quest/Quest.java index bfd13ba2..99189609 100644 --- a/src/resources/quest/Quest.java +++ b/src/resources/quest/Quest.java @@ -47,6 +47,9 @@ public class Quest extends Delta implements Serializable { private ScheduledFuture timer; private long waypointId; + private int counterMax; + private int counterCurrent; + public Quest() {} public Quest(String name, long ownerId) { @@ -145,6 +148,30 @@ public class Quest extends Delta implements Serializable { this.timer = timer; } + public int getCounterMax() { + return counterMax; + } + + public void setCounterMax(int counterMax) { + this.counterMax = counterMax; + } + + public void incrementCounter() { + counterCurrent++; + } + + public void decrementCounter() { + counterCurrent--; + } + + public int getCounterValue() { + return counterCurrent; + } + + public void setCounterValue(int value) { + this.counterCurrent = value; + } + public byte[] getBytes() { byte[] activeStepBytes = activeStepBitmask.toByteArray(); byte[] completedStepBytes = completedStepBitmask.toByteArray(); diff --git a/src/services/WeatherService.java b/src/services/WeatherService.java index 78baca9b..6dd11f18 100644 --- a/src/services/WeatherService.java +++ b/src/services/WeatherService.java @@ -70,7 +70,7 @@ public class WeatherService { } catch (Exception e) { e.printStackTrace(); } - }, 30, 30, TimeUnit.MINUTES); + }, 15, 15, TimeUnit.MINUTES); } diff --git a/src/services/bazaar/BazaarService.java b/src/services/bazaar/BazaarService.java index 0613155e..52ca9588 100644 --- a/src/services/bazaar/BazaarService.java +++ b/src/services/bazaar/BazaarService.java @@ -331,7 +331,7 @@ public class BazaarService implements INetworkDispatch { if(vendor == null || item == null || item instanceof CreatureObject || item instanceof BuildingObject) return; - addAuction((CreatureObject) player, item, vendor, createAuction.getPrice(), createAuction.getDuration(), createAuction.getDescription(), true, createAuction.getPremium()); + addAuction((CreatureObject) player, item, vendor, createAuction.getPrice(), createAuction.getDuration(), createAuction.getDescription(), true, createAuction.isPremium()); }); @@ -359,7 +359,7 @@ public class BazaarService implements INetworkDispatch { if(vendor == null || item == null || item instanceof CreatureObject || item instanceof BuildingObject) return; - addAuction((CreatureObject) player, item, vendor, createAuction.getPrice(), createAuction.getDuration(), createAuction.getDescription(), false, createAuction.getPremium()); + addAuction((CreatureObject) player, item, vendor, createAuction.getPrice(), createAuction.getDuration(), createAuction.getDescription(), false, createAuction.isPremium()); }); diff --git a/src/services/command/CommandService.java b/src/services/command/CommandService.java index c7e47a7e..daf99bbc 100644 --- a/src/services/command/CommandService.java +++ b/src/services/command/CommandService.java @@ -693,7 +693,8 @@ public class CommandService implements INetworkDispatch { public void processCommand(CreatureObject actor, SWGObject target, BaseSWGCommand command, int actionCounter, String commandArgs) { if (command.getGodLevel() > 0 || command.getCommandName().equals("setgodmode") || command.getCommandName().equals("server") || command.getCommandName().equals("teleport") - || command.getCommandName().equals("teleportto") || command.getCommandName().equals("teleporttarget") || command.getCommandName().equals("createcreature") || command.getCommandName().equals("giveitem") ) { + || command.getCommandName().equals("teleportto") || command.getCommandName().equals("teleporttarget") || command.getCommandName().equals("createcreature") || command.getCommandName().equals("giveitem") ) { + String accessLevel = core.adminService.getAccessLevelFromDB(actor.getClient().getAccountId()); String filePath = "accesslevels/" + accessLevel + ".txt"; System.out.println(command.getCommandName() + " was just used by an admin with accessLevel: " + accessLevel + "."); diff --git a/src/services/equipment/EquipmentService.java b/src/services/equipment/EquipmentService.java index be0b6729..45196f96 100644 --- a/src/services/equipment/EquipmentService.java +++ b/src/services/equipment/EquipmentService.java @@ -39,6 +39,7 @@ import org.python.core.Py; import org.python.core.PyObject; import resources.datatables.FactionStatus; +import resources.datatables.DisplayType; import resources.equipment.Equipment; import resources.objects.creature.CreatureObject; import main.NGECore; @@ -58,20 +59,155 @@ public class EquipmentService implements INetworkDispatch { public EquipmentService(NGECore core) { this.core = core; } - - @Override - public void insertOpcodes(Map arg0, Map arg1) { + + public void equip(CreatureObject actor, SWGObject item) { + SWGObject container = actor; - } - - @Override - public void shutdown() { - + if (canWear(actor, container, item)) { + String template = ((item.getAttachment("customServerTemplate") == null) ? item.getTemplate() : (item.getTemplate().split("shared_")[0] + "shared_" + ((String) item.getAttachment("customServerTemplate")) + ".iff")); + String serverTemplate = template.replace(".iff", ""); + + PyObject func = core.scriptService.getMethod("scripts/" + serverTemplate.split("shared_" , 2)[0].replace("shared_", ""), serverTemplate.split("shared_" , 2)[1], "equip"); + + if (func != null) { + func.__call__(Py.java2py(core), Py.java2py(actor), Py.java2py(item)); + } + + for (String slotName : container.getSlotNamesForObject(item)) { + if (container.getSlottedObject(slotName) != null && !container.getSlotNamesForObject(item).iterator().hasNext()) { + container.transferTo(actor, actor.getSlottedObject("inventory"), item); + break; + } + } + + actor.addObjectToEquipList(item); + processItemAtrributes(actor, item, true); + + if (item instanceof WeaponObject) { + actor.setWeaponId(item.getObjectID()); + } + } } + public void unequip(CreatureObject actor, SWGObject item) { + if (actor.isWearing(item)) { + String template = ((item.getAttachment("customServerTemplate") == null) ? item.getTemplate() : (item.getTemplate().split("shared_")[0] + "shared_" + ((String) item.getAttachment("customServerTemplate")) + ".iff")); + String serverTemplate = template.replace(".iff", ""); + + PyObject func = core.scriptService.getMethod("scripts/" + serverTemplate.split("shared_" , 2)[0].replace("shared_", ""), serverTemplate.split("shared_" , 2)[1], "unequip"); + + if (func != null) { + func.__call__(Py.java2py(core), Py.java2py(actor), Py.java2py(item)); + } + + if (item instanceof WeaponObject) { + actor.setWeaponId(actor.getSlottedObject("default_weapon").getObjectID()); + } + + actor.removeObjectFromEquipList(item); + processItemAtrributes(actor, item, false); + } + } + + public void equipAppearance(CreatureObject actor, SWGObject item) { + SWGObject container = actor.getSlottedObject("appearance_inventory"); + + if (canWear(actor, container, item)) { + for (String slotName : container.getSlotNamesForObject(item)) { + if (container.getSlottedObject(slotName) != null && !container.getSlotNamesForObject(item).iterator().hasNext()) { + unequipAppearance(actor, item); + container.transferTo(actor, actor.getSlottedObject("inventory"), item); + break; + } + } + + actor.addObjectToAppearanceEquipList(item); + } + } + + public void unequipAppearance(CreatureObject actor, SWGObject item) { + if (actor.isWearingAppearance(item) ) { + actor.removeObjectFromAppearanceEquipList(item); + } + } /* - Returns an array; + * @returns True if can wear. + */ + public boolean canWear(CreatureObject actor, SWGObject container, SWGObject item) { + // TODO: Species restrictions + // TODO: Gender restrictions + + if (item == null) { + return false; + } + + if (actor.isWearing(item) || actor.isWearingAppearance(item)) { + return false; + } + + if (container.getSlotNamesForObject(item) == null || container.getSlotNamesForObject(item).size() == 0) { + return false; + } + + if (item.getAttributes().toString().contains("cat_armor")) { + if (actor.hasAbility("wear_all_armor")) { + return true; + } else { + actor.sendSystemMessage("@error_message:insufficient_skill", DisplayType.Broadcast); // I am unsure if this is the right message + return false; + } + } + + if (item.getStringAttribute("class_required") != null) { + String classRequired = item.getStringAttribute("class_required"); + String profession = ((PlayerObject) actor.getSlottedObject("ghost")).getProfession(); + + if (classRequired.contains(core.playerService.getFormalProfessionName(profession)) || classRequired.equals("None")) { + return true; + } else { + actor.sendSystemMessage("@error_message:insufficient_skill", DisplayType.Broadcast); // I am unsure if this is the right message + return false; + } + } + + if (item.getStringAttribute("faction_restriction") != null) { + if (item.getStringAttribute("faction_restriction").toLowerCase().contentEquals(actor.getFaction()) && actor.getFactionStatus() >= FactionStatus.Combatant) { + return true; + } else { + actor.sendSystemMessage("@faction_recruiter:must_be_faction_member_use", DisplayType.Broadcast); // will have to somehow manage prose %TO for faction name + return false; + } + } + + if (item.getAttributes().containsKey("required_combat_level")) { + if (actor.getLevel() >= item.getIntAttribute("required_combat_level")) { + return true; + } else { + actor.sendSystemMessage("@error_message:insufficient_skill", DisplayType.Broadcast); // I am unsure if this is the right message + return false; + } + } + + if (item.getAttachment("unity") != null) { + actor.sendSystemMessage("@unity:cannot_remove_ring", DisplayType.Broadcast); + return false; + } + + if (item.getTemplate().startsWith("object/weapon/") && item.getTemplate().contains("lightsaber") && item.getAttachment("hasColorCrystal") == null) { + item.setAttachment("hasColorCrystal", false); + } + + if (item.getAttachment("hasColorCrystal") != null && (Boolean) item.getAttachment("hasColorCrystal") == false) { + actor.sendSystemMessage("@jedi_spam:lightsaber_no_color", DisplayType.Broadcast); + return false; + } + + return true; + } + + /* + @returns an array; [0] = boolean, whether or not the item may be equipped; [1] = string, in case of failure, why */ @@ -82,71 +218,66 @@ public class EquipmentService implements INetworkDispatch { boolean result = true; String message = ""; - if (item == null) - { + if (item == null) { result = false; message = "null_item"; return new Object[] { result, message }; } - if (item.getAttributes().toString().contains("cat_armor")) - { - if (actor.hasAbility("wear_all_armor")) result = true; - else - { - result = false; - message = "@error_message:insufficient_skill"; // I am unsure if this is the right message - return new Object[] { result, message }; - } - } - - if (item.getStringAttribute("class_required") != null) - { - String classRequired = item.getStringAttribute("class_required"); - String profession = ((PlayerObject) actor.getSlottedObject("ghost")).getProfession(); - - if (classRequired.contains(core.playerService.getFormalProfessionName(profession)) || classRequired.equals("None")) result = true; - else - { + if (item.getAttributes().toString().contains("cat_armor")) { + if (actor.hasAbility("wear_all_armor")) { + result = true; + } else { result = false; message = "@error_message:insufficient_skill"; // I am unsure if this is the right message return new Object[] { result, message }; } } - if (item.getStringAttribute("faction_restriction") != null) - { - if (item.getStringAttribute("faction_restriction").toLowerCase().contentEquals(actor.getFaction()) && actor.getFactionStatus() >= FactionStatus.Combatant) result = true; - else - { + if (item.getStringAttribute("class_required") != null) { + String classRequired = item.getStringAttribute("class_required"); + String profession = ((PlayerObject) actor.getSlottedObject("ghost")).getProfession(); + + if (classRequired.contains(core.playerService.getFormalProfessionName(profession)) || classRequired.equals("None")) { + result = true; + } else { + result = false; + message = "@error_message:insufficient_skill"; // I am unsure if this is the right message + return new Object[] { result, message }; + } + } + + if (item.getStringAttribute("faction_restriction") != null) { + if (item.getStringAttribute("faction_restriction").toLowerCase().contentEquals(actor.getFaction()) && actor.getFactionStatus() >= FactionStatus.Combatant) { + result = true; + } else { result = false; message = "@faction_recruiter:must_be_faction_member_use"; // will have to somehow manage prose %TO for faction name return new Object[] { result, message }; } } - if (item.getAttributes().containsKey("required_combat_level")) - { - if (actor.getLevel() >= item.getIntAttribute("required_combat_level")) result = true; - else - { + if (item.getAttributes().containsKey("required_combat_level")) { + if (actor.getLevel() >= item.getIntAttribute("required_combat_level")) { + result = true; + } else { result = false; message = "@error_message:insufficient_skill"; // I am unsure if this is the right message return new Object[] { result, message }; } } - if(item.getAttachment("unity") != null) - { + if (item.getAttachment("unity") != null) { result = false; message = "@unity:cannot_remove_ring"; return new Object[] { result, message }; } - if(item.getTemplate().startsWith("object/weapon/") && item.getTemplate().contains("lightsaber") && item.getAttachment("hasColorCrystal") == null) item.setAttachment("hasColorCrystal", false); + if (item.getTemplate().startsWith("object/weapon/") && item.getTemplate().contains("lightsaber") && item.getAttachment("hasColorCrystal") == null) { + item.setAttachment("hasColorCrystal", false); + } - if(item.getAttachment("hasColorCrystal") != null && (Boolean) item.getAttachment("hasColorCrystal") == false) - { + if (item.getAttachment("hasColorCrystal") != null && (Boolean) item.getAttachment("hasColorCrystal") == false) { result = false; message = "@jedi_spam:lightsaber_no_color"; return new Object[] { result, message }; @@ -157,60 +288,23 @@ public class EquipmentService implements INetworkDispatch { return new Object[] { result, message }; } - public void equip(CreatureObject actor, SWGObject item) - { - String template = ((item.getAttachment("customServerTemplate") == null) ? item.getTemplate() : (item.getTemplate().split("shared_")[0] + "shared_" + ((String) item.getAttachment("customServerTemplate")) + ".iff")); - String serverTemplate = template.replace(".iff", ""); - - PyObject func = core.scriptService.getMethod("scripts/" + serverTemplate.split("shared_" , 2)[0].replace("shared_", ""), serverTemplate.split("shared_" , 2)[1], "equip"); - if(func != null) func.__call__(Py.java2py(core), Py.java2py(actor), Py.java2py(item)); - - if(!actor.isWearing(item)) - { - //if(item instanceof WeaponObject){ - //A rifle is not identified as a true WeaponObject ?!?!?!?! - if (item.getTemplate().startsWith("object/weapon/")) actor.setWeaponId(item.getObjectID()); - - actor.addObjectToEquipList(item); - processItemAtrributes(actor, item, true); - } -} - - public void unequip(CreatureObject actor, SWGObject item) - { - String template = ((item.getAttachment("customServerTemplate") == null) ? item.getTemplate() : (item.getTemplate().split("shared_")[0] + "shared_" + ((String) item.getAttachment("customServerTemplate")) + ".iff")); - String serverTemplate = template.replace(".iff", ""); - - PyObject func = core.scriptService.getMethod("scripts/" + serverTemplate.split("shared_" , 2)[0].replace("shared_", ""), serverTemplate.split("shared_" , 2)[1], "unequip"); - if(func != null) func.__call__(Py.java2py(core), Py.java2py(actor), Py.java2py(item)); - - if(actor.isWearing(item)) - { - // This should be changed to instanceof WeaponObject eventually... see comment in equip() - if (item.getTemplate().startsWith("object/weapon/")) actor.setWeaponId(actor.getSlottedObject("default_weapon").getObjectID()); - - actor.removeObjectFromEquipList(item); - processItemAtrributes(actor, item, false); - } - } - - public void processItemAtrributes(CreatureObject creature, SWGObject item, boolean equipping) - { + public void processItemAtrributes(CreatureObject creature, SWGObject item, boolean equipping) { // TODO: crit enhancement from crafted weapons // TODO: check for armor category in order to add resistance to certain DoT types Map attributes = new TreeMap(item.getAttributes()); - if(equipping) - { - if(item.getStringAttribute("cat_wpn_damage.wpn_category") != null) { + if (equipping) { + if (item.getStringAttribute("cat_wpn_damage.wpn_category") != null) { core.skillModService.addSkillMod(creature, "display_only_critical", getWeaponCriticalChance(creature, item)); creature.setAttachment("EquippedWeapon", item.getObjectID()); + // Check if weapon has power up active - if (item.getAttachment("PUPEndTime")!=null){ + if (item.getAttachment("PUPEndTime") != null) { long pupEndTime = (long)item.getAttachment("PUPEndTime"); - if (pupEndTime>System.currentTimeMillis()){ + + if (pupEndTime > System.currentTimeMillis()) { // do nothing let the rest add the mods } else { // Make sure pup buff icons are cleared @@ -218,27 +312,14 @@ public class EquipmentService implements INetworkDispatch { } } - if(item.getTemplate().contains("shirt")) { - + if (item.getTemplate().contains("shirt")) { creature.setAttachment("EquippedShirt", item.getObjectID()); - // Check if shirt has power up active - if (item.getAttachment("PUPEndTime")!=null){ - long pupEndTime = (long)item.getAttachment("PUPEndTime"); - if (pupEndTime>System.currentTimeMillis()){ - // do nothing let the rest add the mods - } else { - // Make sure pup buff icons are cleared - } - } - } - - if(item.getTemplate().contains("chest")) { - creature.setAttachment("EquippedChest", item.getObjectID()); - // Check if chest has power up active - if (item.getAttachment("PUPEndTime")!=null){ + // Check if shirt has power up active + if (item.getAttachment("PUPEndTime") != null){ long pupEndTime = (long)item.getAttachment("PUPEndTime"); - if (pupEndTime>System.currentTimeMillis()){ + + if (pupEndTime > System.currentTimeMillis()) { // do nothing let the rest add the mods } else { // Make sure pup buff icons are cleared @@ -246,65 +327,74 @@ public class EquipmentService implements INetworkDispatch { } } - if(item.getStringAttribute("proc_name") != null) core.buffService.addBuffToCreature(creature, item.getStringAttribute("proc_name").replace("@ui_buff:", ""), creature); + if (item.getTemplate().contains("chest")) { + creature.setAttachment("EquippedChest", item.getObjectID()); + + // Check if chest has power up active + if (item.getAttachment("PUPEndTime") != null){ + long pupEndTime = (long)item.getAttachment("PUPEndTime"); + + if (pupEndTime>System.currentTimeMillis()) { + // do nothing let the rest add the mods + } else { + // Make sure pup buff icons are cleared + } + } + } - for(Entry e : attributes.entrySet()) - { - if(e.getKey().startsWith("cat_skill_mod_bonus.@stat_n:")) - { + if (item.getStringAttribute("proc_name") != null) { + core.buffService.addBuffToCreature(creature, item.getStringAttribute("proc_name").replace("@ui_buff:", ""), creature); + } + + for (Entry e : attributes.entrySet()) { + if (e.getKey().startsWith("cat_skill_mod_bonus.@stat_n:")) { core.skillModService.addSkillMod(creature, e.getKey().replace("cat_skill_mod_bonus.@stat_n:", ""), Integer.parseInt((String) e.getValue())); } - if(e.getKey().startsWith("cat_stat_mod_bonus.@stat_n:")) - { + if (e.getKey().startsWith("cat_stat_mod_bonus.@stat_n:")) { core.skillModService.addSkillMod(creature, e.getKey().replace("cat_stat_mod_bonus.@stat_n:", ""), Integer.parseInt((String) e.getValue())); } - if(e.getKey().startsWith("cat_attrib_mod_bonus.attr_health")) - { + if (e.getKey().startsWith("cat_attrib_mod_bonus.attr_health")) { creature.setMaxHealth(creature.getMaxHealth() + Integer.parseInt((String) e.getValue())); } - if(e.getKey().startsWith("cat_attrib_mod_bonus.attr_action")) - { + if (e.getKey().startsWith("cat_attrib_mod_bonus.attr_action")) { creature.setMaxAction(creature.getMaxAction() + Integer.parseInt((String) e.getValue())); } } - } - else - { - if(item.getStringAttribute("cat_wpn_damage.wpn_category") != null){ + } else { + if (item.getStringAttribute("cat_wpn_damage.wpn_category") != null) { core.skillModService.deductSkillMod(creature, "display_only_critical", getWeaponCriticalChance(creature, item)); creature.setAttachment("EquippedWeapon", null); } - if(item.getTemplate().contains("shirt")) { + if (item.getTemplate().contains("shirt")) { creature.setAttachment("EquippedShirt", null); } - if(item.getTemplate().contains("chest")) { + if (item.getTemplate().contains("chest")) { creature.setAttachment("EquippedChest", null); } - if(item.getStringAttribute("proc_name") != null) core.buffService.removeBuffFromCreatureByName(creature, item.getStringAttribute("proc_name").replace("@ui_buff:", "")); + if (item.getStringAttribute("proc_name") != null) { + core.buffService.removeBuffFromCreatureByName(creature, item.getStringAttribute("proc_name").replace("@ui_buff:", "")); + } - for(Entry e : attributes.entrySet()) - { - if(e.getKey().startsWith("cat_skill_mod_bonus.@stat_n:")) - { + for (Entry e : attributes.entrySet()) { + if (e.getKey().startsWith("cat_skill_mod_bonus.@stat_n:")) { core.skillModService.deductSkillMod(creature, e.getKey().replace("cat_skill_mod_bonus.@stat_n:", ""), Integer.parseInt((String) e.getValue())); - } - if(e.getKey().startsWith("cat_stat_mod_bonus.@stat_n:")) - { + } + + if (e.getKey().startsWith("cat_stat_mod_bonus.@stat_n:")) { core.skillModService.deductSkillMod(creature, e.getKey().replace("cat_stat_mod_bonus.@stat_n:", ""), Integer.parseInt((String) e.getValue())); } - if(e.getKey().startsWith("cat_attrib_mod_bonus.attr_health")) - { + if (e.getKey().startsWith("cat_attrib_mod_bonus.attr_health")) { creature.setMaxHealth(creature.getMaxHealth() - Integer.parseInt((String) e.getValue())); - } - if(e.getKey().startsWith("cat_attrib_mod_bonus.attr_action")) - { + } + + if (e.getKey().startsWith("cat_attrib_mod_bonus.attr_action")) { creature.setMaxAction(creature.getMaxAction() - Integer.parseInt((String) e.getValue())); } } @@ -312,60 +402,65 @@ public class EquipmentService implements INetworkDispatch { calculateArmorProtection(creature, equipping); - if(item.getAttachment("setBonus") != null) - { + if (item.getAttachment("setBonus") != null) { BonusSetTemplate bonus = bonusSetTemplates.get((String)item.getAttachment("setBonus")); bonus.callScript(creature); } } - - private void calculateArmorProtection(CreatureObject creature, boolean equipping) - { + + private void calculateArmorProtection(CreatureObject creature, boolean equipping) { int wornArmourPieces = 0, forceProtection = 0; Map protection = new TreeMap(); - for(Equipment equipment : new ArrayList(creature.getEquipmentList())) - { + for (Equipment equipment : new ArrayList(creature.getEquipmentList())) { SWGObject item = core.objectService.getObject(equipment.getObjectId()); - if(item == null) + + if (item == null) { continue; + } + Map attributes = new TreeMap(item.getAttributes()); boolean incPieceCount = false; - if(item.getStringAttribute("protection_level") != null) - { + if (item.getStringAttribute("protection_level") != null) { forceProtection = getForceProtection(item); break; } - for(Entry e : attributes.entrySet()) - { - if(e.getKey().startsWith("cat_armor_standard_protection")) - { + for (Entry e : attributes.entrySet()) { + if (e.getKey().startsWith("cat_armor_standard_protection")) { String protectionType = e.getKey().replace("cat_armor_standard_protection.armor_eff_", ""); float modifier = Float.parseFloat(core.scriptService.getMethod("scripts/equipment/", "slot_protection", creature.getSlotNameForObject(item)).__call__().asString()) / 100; Float protectionAmount = Float.parseFloat((String) e.getValue()) * modifier; - - if(protection.containsKey(protectionType)) protection.replace(protectionType, protection.get(protectionType) + protectionAmount); - else protection.put(protectionType, protectionAmount); + + if (protection.containsKey(protectionType)) { + protection.replace(protectionType, protection.get(protectionType) + protectionAmount); + } else { + protection.put(protectionType, protectionAmount); + } + incPieceCount = true; - } - else if(e.getKey().startsWith("cat_armor_special_protection")) - { + } else if(e.getKey().startsWith("cat_armor_special_protection")) { String protectionType = e.getKey().replace("cat_armor_special_protection.special_protection_type_", ""); float modifier = Float.parseFloat(core.scriptService.getMethod("scripts/equipment/", "slot_protection", creature.getSlotNameForObject(item)).__call__().asString()) / 100; Float protectionAmount = Float.parseFloat((String) e.getValue()) * modifier; - if(protection.containsKey(protectionType)) protection.replace(protectionType, protection.get(protectionType) + protectionAmount); - else protection.put(protectionType, protectionAmount); + if (protection.containsKey(protectionType)) { + protection.replace(protectionType, protection.get(protectionType) + protectionAmount); + } else { + protection.put(protectionType, protectionAmount); + } + incPieceCount = true; } } - if(incPieceCount) wornArmourPieces++; + + if (incPieceCount) { + wornArmourPieces++; + } } - if(protection.size() == 0) - { + if (protection.size() == 0) { protection.put("kinetic", (float) 0); protection.put("energy", (float) 0); protection.put("heat", (float) 0); @@ -374,73 +469,90 @@ public class EquipmentService implements INetworkDispatch { protection.put("electricity", (float) 0); } - for(Entry e : protection.entrySet()) - { + for (Entry e : protection.entrySet()) { core.skillModService.deductSkillMod(creature, e.getKey(), creature.getSkillModBase(e.getKey())); core.skillModService.addSkillMod(creature, e.getKey(), forceProtection); - if(wornArmourPieces >= 3) core.skillModService.addSkillMod(creature, e.getKey(), (int) e.getValue().floatValue()); + + if (wornArmourPieces >= 3) { + core.skillModService.addSkillMod(creature, e.getKey(), (int) e.getValue().floatValue()); + } } } - public void calculateLightsaberAttributes(CreatureObject actor, TangibleObject item, SWGObject targetContainer) - { + public void calculateLightsaberAttributes(CreatureObject actor, TangibleObject item, SWGObject targetContainer) { WeaponObject lightsaber = null; TangibleObject lightsaberInventory = null; long tunerId = 0; // Get our lightsaber weapon object - if(item.getContainer().getTemplate().startsWith("object/tangible/inventory/shared_lightsaber_inventory")) lightsaber = (WeaponObject) item.getGrandparent(); - else if(targetContainer.getTemplate().startsWith("object/tangible/inventory/shared_lightsaber_inventory")) lightsaber = (WeaponObject) targetContainer.getContainer(); + if (item.getContainer().getTemplate().startsWith("object/tangible/inventory/shared_lightsaber_inventory")) { + lightsaber = (WeaponObject) item.getGrandparent(); + } else if (targetContainer.getTemplate().startsWith("object/tangible/inventory/shared_lightsaber_inventory")) { + lightsaber = (WeaponObject) targetContainer.getContainer(); + } - if(lightsaber == null) return; + if (lightsaber == null) { + return; + } lightsaberInventory = (TangibleObject) lightsaber.getSlottedObject("saber_inv"); - if(lightsaber.getAttachment("weaponBaseDamageMin") == null) lightsaber.setAttachment("weaponBaseDamageMin", lightsaber.getMinDamage()); - if(lightsaber.getAttachment("weaponBaseDamageMax") == null) lightsaber.setAttachment("weaponBaseDamageMax", lightsaber.getMaxDamage()); + if (lightsaber.getAttachment("weaponBaseDamageMin") == null) { + lightsaber.setAttachment("weaponBaseDamageMin", lightsaber.getMinDamage()); + } + + if (lightsaber.getAttachment("weaponBaseDamageMax") == null) { + lightsaber.setAttachment("weaponBaseDamageMax", lightsaber.getMaxDamage()); + } // Check if item is a lightsaber component - if(lightsaberInventory == null) return; - if(lightsaber.getContainer() instanceof CreatureObject) - { + if (lightsaberInventory == null) { + return; + } + + if (lightsaber.getContainer() instanceof CreatureObject) { actor.sendSystemMessage("@jedi_spam:saber_not_while_equpped", (byte) 0); return; } - if(!item.getTemplate().startsWith("object/tangible/component/weapon/lightsaber/")) - { + if (!item.getTemplate().startsWith("object/tangible/component/weapon/lightsaber/")) { actor.sendSystemMessage("@jedi_spam:saber_not_crystal", (byte) 0); return; } - if(lightsaber.getAttachment("hasColorCrystal") == null) lightsaber.setAttachment("hasColorCrystal", false); - if(item.getAttributes().containsKey("@obj_attr_n:color") && (Boolean) lightsaber.getAttachment("hasColorCrystal") && !(targetContainer.getContainer() instanceof CreatureObject)) - { + + if (lightsaber.getAttachment("hasColorCrystal") == null) { + lightsaber.setAttachment("hasColorCrystal", false); + } + + if (item.getAttributes().containsKey("@obj_attr_n:color") && (Boolean) lightsaber.getAttachment("hasColorCrystal") && !(targetContainer.getContainer() instanceof CreatureObject)) { actor.sendSystemMessage("@jedi_spam:saber_already_has_color", (byte) 0); return; } // Find our tuner - if(item.getAttachment("tunerId") == null) item.setAttachment("tunerId", 0); + if (item.getAttachment("tunerId") == null) { + item.setAttachment("tunerId", 0); + } + tunerId = (int) item.getAttachment("tunerId"); // Check if player tuned the crystal - if(tunerId == 0) - { + if (tunerId == 0) { actor.sendSystemMessage("@jedi_spam:saber_crystal_not_tuned", (byte) 0); return; } - if(tunerId != actor.getObjectId()) - { + + if (tunerId != actor.getObjectId()) { actor.sendSystemMessage("@jedi_spam:saber_crystal_not_owner", (byte) 0); return; + } else { + item.getContainer().transferTo(actor, targetContainer, item); } - else item.getContainer().transferTo(actor, targetContainer, item); - + // Calculate attributes lightsaber.setAttachment("hasColorCrystal", false); - lightsaberInventory.viewChildren(lightsaberInventory, false, false, new Traverser() - { + lightsaberInventory.viewChildren(lightsaberInventory, false, false, new Traverser() { WeaponObject saber; @SuppressWarnings("unused") TangibleObject saberInv; @@ -448,13 +560,11 @@ public class EquipmentService implements INetworkDispatch { int maxDamageBonus = 0; Boolean hasColorCrystal = false; - public void process(SWGObject item) - { + public void process(SWGObject item) { saber = (WeaponObject) item.getGrandparent(); saberInv = (TangibleObject) saber.getSlottedObject("saber_inv"); - - if(item.getAttributes().get("@obj_attr_n:color") != null) // "Blade Color Modification" - { + + if (item.getAttributes().get("@obj_attr_n:color") != null) { // "Blade Color Modification" int crystalColorIndex = resources.datatables.LightsaberColors.getByName((String) item.getAttributes().get("@obj_attr_n:color")); byte bladeType = crystalColorIndex > 256 ? (byte) (crystalColorIndex % 256) : 0x00; @@ -469,9 +579,7 @@ public class EquipmentService implements INetworkDispatch { // System.out.println(); hasColorCrystal = true; - } - else - { + } else { minDamageBonus += Integer.parseInt(item.getAttributes().get("@obj_attr_n:mindamage")); // "Minimum Damage" maxDamageBonus += Integer.parseInt(item.getAttributes().get("@obj_attr_n:maxdamage")); // "Maximum Damage" } @@ -490,9 +598,10 @@ public class EquipmentService implements INetworkDispatch { private int getWeaponCriticalChance(CreatureObject actor, SWGObject item) { int weaponCriticalChance = 0; String weaponCriticalSkillMod = (core.scriptService.getMethod("scripts/equipment/", "weapon_critical", "weap_" + item.getStringAttribute("cat_wpn_damage.wpn_category").replace("@obj_attr_n:wpn_category_", "")).__call__().asString()); - - if(actor.getSkillMod(weaponCriticalSkillMod) != null) + + if (actor.getSkillMod(weaponCriticalSkillMod) != null) { weaponCriticalChance = actor.getSkillModBase(weaponCriticalSkillMod); + } return weaponCriticalChance; } @@ -501,26 +610,36 @@ public class EquipmentService implements INetworkDispatch { return core.scriptService.getMethod("scripts/equipment/", "force_protection", item.getAttachment("type") + "_" + item.getStringAttribute("protection_level")).__call__().asInt(); } - public void addBonusSetTemplate(BonusSetTemplate bonusSet) - { + public void addBonusSetTemplate(BonusSetTemplate bonusSet) { bonusSetTemplates.put(bonusSet.getName(), bonusSet); } public void loadBonusSets() { - Path p = Paths.get("scripts/equipment/bonus_sets/"); - FileVisitor fv = new SimpleFileVisitor() - { - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException - { - core.scriptService.callScript("scripts/equipment/bonus_sets/", file.getFileName().toString().replace(".py", ""), "addBonusSet", core); - return FileVisitResult.CONTINUE; - } - }; - try - { + Path p = Paths.get("scripts/equipment/bonus_sets/"); + + FileVisitor fv = new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + core.scriptService.callScript("scripts/equipment/bonus_sets/", file.getFileName().toString().replace(".py", ""), "addBonusSet", core); + return FileVisitResult.CONTINUE; + } + }; + + try { Files.walkFileTree(p, fv); - } - catch (IOException e) { e.printStackTrace(); } + } catch (IOException e) { + e.printStackTrace(); + } } + + @Override + public void insertOpcodes(Map arg0, Map arg1) { + + } + + @Override + public void shutdown() { + + } + } diff --git a/src/services/quest/QuestService.java b/src/services/quest/QuestService.java index 294a8211..900b24f2 100644 --- a/src/services/quest/QuestService.java +++ b/src/services/quest/QuestService.java @@ -31,6 +31,7 @@ import java.nio.file.Paths; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; +import java.util.List; import java.util.Map; import java.util.Random; import java.util.concurrent.ConcurrentHashMap; @@ -57,7 +58,6 @@ import resources.common.OutOfBand; import resources.common.ProsePackage; import resources.common.collidables.QuestCollidable; import resources.datatables.DisplayType; -import resources.objects.SWGMap; import resources.objects.creature.CreatureObject; import resources.objects.player.PlayerObject; import resources.objects.tangible.TangibleObject; @@ -79,9 +79,31 @@ public class QuestService implements INetworkDispatch { private NGECore core; private Map questMap = new ConcurrentHashMap(); private Map questRewardMap = new ConcurrentHashMap(); - + private List forceAcceptQuests = new ArrayList(); + private Map questCrcMap = new ConcurrentHashMap(); + public QuestService(NGECore core) { this.core = core; + + try { + DatatableVisitor forceQuestVisitor = ClientFileManager.loadFile("datatables/quest/force_accept_quests.iff", DatatableVisitor.class); + + for (int r = 0; r > forceQuestVisitor.getRowCount(); r++) { + forceAcceptQuests.add((String) forceQuestVisitor.getObject(r, 0)); + } + + } catch (InstantiationException | IllegalAccessException e) { + e.printStackTrace(); + } + + File quests = Paths.get("clientdata/datatables/questlist/quest").toFile(); + for (File fQuest : quests.listFiles()) { + if (fQuest.isDirectory()) + continue; + + String questName = "quest/" + fQuest.getName().split(".iff")[0]; + questCrcMap.put(CRC.StringtoCRC(questName), questName); + } } @Override @@ -95,49 +117,6 @@ public class QuestService implements INetworkDispatch { }); } - - public boolean doesPlayerHaveQuest(CreatureObject creo, String questName) { - PlayerObject ghost = creo.getPlayerObject(); - - if (ghost == null) { - try { throw new Exception("Ghost is null! Cannot determine if player has quest or not."); } - catch (Exception e) {e.printStackTrace();} - } - - SWGMap questJournal = ghost.getQuestJournal(); - - if (questJournal.size() == 0) - return false; - - return questJournal.containsKey(CRC.StringtoCRC("quest/" + questName)); - } - - public boolean isQuestCompleted(CreatureObject creo, String questName) { - PlayerObject ghost = creo.getPlayerObject(); - - if (ghost == null) { - try { throw new Exception("Ghost is null! Cannot determine if player completed quest or not."); } - catch (Exception e) {e.printStackTrace();} - } - - SWGMap questJournal = ghost.getQuestJournal(); - - if (questJournal.size() == 0) - return false; - - if (!questJournal.containsKey(CRC.StringtoCRC("quest/" + questName))) - return false; - else - return questJournal.get(CRC.StringtoCRC("quest/") + questName).isCompleted(); - } - - public void sendQuestWindow(CreatureObject reciever, String questName) { - if (reciever == null || reciever.getClient() == null || reciever.getClient().getSession() == null) - return; - - ObjControllerMessage objMsg = new ObjControllerMessage(11, new ForceActivateQuest(reciever.getObjectID(), CRC.StringtoCRC("quest/" + questName))); - reciever.getClient().getSession().write(objMsg.serialize()); - } public void activateNextTask(CreatureObject quester, String questName) { @@ -164,7 +143,6 @@ public class QuestService implements INetworkDispatch { QuestTask task = qData.getTasks().get(activeStep); - switch (task.getType()) { // quest.task.ground.go_to_location @@ -184,10 +162,14 @@ public class QuestService implements INetworkDispatch { // quest.task.ground.retrieve_item case "retrieve_item": + if (quest.getCounterMax() != task.getNumRequired()) { + quest.setCounterMax(task.getNumRequired()); + quest.setCounterValue(0); + } + player.getQuestRetrieveItemTemplates().put(task.getServerTemplate(), new QuestItem(quest.getName(), activeStep)); - // TODO: add item count - ObjControllerMessage itemCount = new ObjControllerMessage(11, new QuestTaskCounterMessage(quester.getObjectID(), quest.getCrcName(), "@quest/groundquests:retrieve_item_counter")); + ObjControllerMessage itemCount = new ObjControllerMessage(11, new QuestTaskCounterMessage(quester.getObjectID(), quest, "@quest/groundquests:retrieve_item_counter")); quester.getClient().getSession().write(itemCount.serialize()); WaypointObject wpRetrieve = createWaypoint(task.getWaypointName(), new Point3D(task.getLocationX(), task.getLocationY(), task.getLocationZ()), task.getPlanet()); @@ -232,9 +214,17 @@ public class QuestService implements INetworkDispatch { break; case "complete_quest": - completeQuest(player, quest); - break; + if (quest.getWaypointId() != 0) { + player.getWaypoints().remove(quest.getWaypointId()); + core.objectService.destroyObject(quest.getWaypointId()); + } + if (quest.getTimer() != null) + quest.getTimer().cancel(true); + + completeQuest(player, quest); + return; + case "reward": // TODO: System message? - Also check possibility of "Item" column being used for reward as well TangibleObject reward = (TangibleObject) core.objectService.createObject(getQuestRewardTemplate(task.getLootName()), core.terrainService.getPlanetByName(task.getPlanet())); @@ -278,29 +268,36 @@ public class QuestService implements INetworkDispatch { player.getWaypoints().remove(quest.getWaypointId()); core.objectService.destroyObject(quest.getWaypointId()); } - + if (quest.getTimer() != null) quest.getTimer().cancel(true); + if (task.showSystemMessages() && task.isVisible()) { + ProsePackage prose = new ProsePackage("@quest/ground/system_message:quest_task_completed"); + prose.setToCustomString(task.getJournalEntryTitle()); + quester.sendSystemMessage(new OutOfBand(prose), DisplayType.Quest); + } + if (activeStep + 1 >= qData.getTasks().size()) { //QuestList listItem = questRewardMap.get(quest.getName()); quest.setCompleted(true); - if (!task.isGrantQuestOnCompleteShowSystemMessage()) { - completeQuest(player, quest); // Force complete packet sent if the quest isn't auto completed (window shows up, typical for exclusive reward items) - player.getContainer().getClient().getSession().write(player.getBaseline(8).createDelta(7)); - } else - sendQuestCompleteWindow(quester, quest.getCrc()); - - if (task.getGrantQuestOnComplete() != null && !task.getGrantQuestOnComplete().equals("")) - activateQuest(quester, task.getGrantQuestOnComplete()); - + // TODO: Unable to determine if this is calculated in "Complete Quest" window should pop up or just finish automatically, but it's the best for now + if (task.isVisible()) + sendQuestCompleteWindow(quester, quest.getCrcName()); + else + completeQuest(player, quest); + return; } - if (task.getGrantQuestOnComplete() != null && !task.getGrantQuestOnComplete().equals("")) - activateQuest(quester, task.getGrantQuestOnComplete()); + if (task.getGrantQuestOnComplete() != null && !task.getGrantQuestOnComplete().equals("")) { + if(!task.isVisible()) + immediatlyActivateQuest(quester, task.getGrantQuestOnComplete()); + else + sendQuestAcceptWindow(quester, task.getGrantQuestOnComplete()); + } quest.incrementQuestStep(); @@ -310,7 +307,7 @@ public class QuestService implements INetworkDispatch { } - public void activateQuest(CreatureObject quester, String questString) { + public void immediatlyActivateQuest(CreatureObject quester, String questString) { Quest quest = new Quest(questString, quester.getObjectID()); PlayerObject player = quester.getPlayerObject(); @@ -346,6 +343,7 @@ public class QuestService implements INetworkDispatch { quest.setCompleted(true); QuestList info = getQuestList(quest.getName()); + QuestTask task = getQuestData(quest.getName()).getTasks().get(quest.getActiveTask()); ArrayList recievedItems = new ArrayList(); TangibleObject inventory = (TangibleObject) creo.getSlottedObject("inventory"); @@ -416,18 +414,29 @@ public class QuestService implements INetworkDispatch { core.playerService.giveExperience(creo, info.getRewardExperienceAmount()); } + if (task.getGrantQuestOnComplete() != null && !task.getGrantQuestOnComplete().equals("")) { + if (task.isVisible()) + sendQuestAcceptWindow(creo, task.getGrantQuestOnComplete()); + else + immediatlyActivateQuest(creo, task.getGrantQuestOnComplete()); + } + // Update quest & client quest.setRecievedAward(true); creo.getClient().getSession().write(player.getBaseline(8).createDelta(7)); } - public void sendQuestAcceptWindow(CreatureObject reciever, int questCrc) { - ObjControllerMessage objController = new ObjControllerMessage(0x0B, new ShowQuestAcceptWindow(reciever.getObjectID(), questCrc)); + public void sendQuestWindow(CreatureObject reciever, String questName) { + ObjControllerMessage objMsg = new ObjControllerMessage(0x0B, new ForceActivateQuest(reciever.getObjectID(), CRC.StringtoCRC("quest/" + questName))); + reciever.getClient().getSession().write(objMsg.serialize()); + } + public void sendQuestAcceptWindow(CreatureObject reciever, String questName) { + ObjControllerMessage objController = new ObjControllerMessage(0x0B, new ShowQuestAcceptWindow(reciever.getObjectID(), questName)); reciever.getClient().getSession().write(objController.serialize()); } - public void sendQuestCompleteWindow(CreatureObject reciever, int questCrc) { - ObjControllerMessage objController = new ObjControllerMessage(0x0B, new ShowQuestCompletionWindow(reciever.getObjectID(), questCrc)); + public void sendQuestCompleteWindow(CreatureObject reciever, String questName) { + ObjControllerMessage objController = new ObjControllerMessage(0x0B, new ShowQuestCompletionWindow(reciever.getObjectID(), questName)); reciever.getClient().getSession().write(objController.serialize()); } @@ -477,8 +486,6 @@ public class QuestService implements INetworkDispatch { core.scriptService.callScript("scripts/quests/events/signals/", task.getSignalName(), "activate", core, actor, quest); return; } - - completeActiveTask(actor, quest); } public void handleAddConversationScript(TangibleObject object, String script) { @@ -536,6 +543,10 @@ public class QuestService implements INetworkDispatch { } } + public String getQuestStringByCrc(int crc) { + return questCrcMap.get(crc); + } + public boolean adminActivateQuest(CreatureObject creo, String questName) { PlayerObject ghost = creo.getPlayerObject(); @@ -564,7 +575,7 @@ public class QuestService implements INetworkDispatch { if (questData == null) return false; - activateQuest(creo, questName); + immediatlyActivateQuest(creo, questName); return true; } @@ -639,7 +650,7 @@ public class QuestService implements INetworkDispatch { //if (visitor.getObjectByColumnNameAndIndex("", r)) - if (task.getType().equals("quest.task.ground.go_to_location")) { + if (task.getType().equals("go_to_location")) { QuestCollidable collision = new QuestCollidable(new Point3D(task.getLocationX(), task.getLocationY(), task.getLocationZ()), task.getRadius(), core.terrainService.getPlanetByName(task.getPlanet()), quest, r); collision.setCallback(core.scriptService.getMethod("scripts/quests/events/", "go_to_location", "run")); core.simulationService.addCollidable(collision, task.getLocationX(), task.getLocationZ()); diff --git a/src/services/spawn/SpawnService.java b/src/services/spawn/SpawnService.java index e790004d..feeeb648 100644 --- a/src/services/spawn/SpawnService.java +++ b/src/services/spawn/SpawnService.java @@ -106,8 +106,8 @@ public class SpawnService { /*if(mobileTemplate.getCustomWeapon() != null) { - creature.addObjectToEquipList(mobileTemplate.getCustomWeapon()); creature.add(mobileTemplate.getCustomWeapon()); + creature.addObjectToEquipList(mobileTemplate.getCustomWeapon()); creature.setWeaponId(mobileTemplate.getCustomWeapon().getObjectID()); }*/ @@ -183,12 +183,12 @@ public class SpawnService { defaultWeapon.setMinDamage(creature.getLevel() * 22); } - creature.addObjectToEquipList(defaultWeapon); creature.add(defaultWeapon); + creature.addObjectToEquipList(defaultWeapon); creature.setWeaponId(defaultWeapon.getObjectID()); - creature.addObjectToEquipList(inventory); creature.add(inventory); - + creature.addObjectToEquipList(inventory); + int customHealth = mobileTemplate.getHealth(); if(difficulty > 0 && customHealth == 0) { if(difficulty == 1) { @@ -282,8 +282,8 @@ public class SpawnService { /*if(mobileTemplate.getCustomWeapon() != null) { - creature.addObjectToEquipList(mobileTemplate.getCustomWeapon()); creature.add(mobileTemplate.getCustomWeapon()); + creature.addObjectToEquipList(mobileTemplate.getCustomWeapon()); creature.setWeaponId(mobileTemplate.getCustomWeapon().getObjectID()); }*/ @@ -368,11 +368,11 @@ public class SpawnService { defaultWeapon.setMinDamage(creature.getLevel() * 22); } - creature.addObjectToEquipList(defaultWeapon); creature.add(defaultWeapon); + creature.addObjectToEquipList(defaultWeapon); creature.setWeaponId(defaultWeapon.getObjectID()); - creature.addObjectToEquipList(inventory); creature.add(inventory); + creature.addObjectToEquipList(inventory); int customHealth = mobileTemplate.getHealth(); if(difficulty > 0 && customHealth == 0) {