diff --git a/scripts/commands/setgodmode.py b/scripts/commands/setgodmode.py index 8eda4fd4..54f1b2bb 100644 --- a/scripts/commands/setgodmode.py +++ b/scripts/commands/setgodmode.py @@ -3,6 +3,8 @@ from engine.resources.scene import Point3D from protocol.swg import CommPlayerMessage from protocol.swg.objectControllerObjects import ShowLootBox from protocol.swg import ObjControllerMessage +from engine.resources.objects import SWGObject +from jarray import array def setup(): return @@ -62,12 +64,11 @@ def run(core, actor, target, commandString): testObject = core.objectService.createObject('object/weapon/ranged/rifle/shared_rifle_t21.iff', actor.getPlanet()) testObject.setCustomName('Crush4r') testObject.setStringAttribute('crafter', 'Wavescrub') - actor.getSlottedObject('inventory').add(testObject) - listedRewards = [testObject] - rewards = ShowLootBox(actor.getObjectId(), listedRewards) - objMessage = ObjControllerMessage(11, rewards) - actor.getClient().getSession().write(objMessage.serialize()) - + dGun = core.objectService.createObject('object/weapon/ranged/rifle/shared_rifle_tc22_blaster.iff', actor.getPlanet()) + dGun.setCustomName('Supertoms Gun') + dGun.setStringAttribute('crafter', 'Wavescrub') + a = array([dGun], SWGObject) + core.playerService.giveItems(actor, a) return elif command == 'comm': diff --git a/src/protocol/swg/objectControllerObjects/ShowLootBox.java b/src/protocol/swg/objectControllerObjects/ShowLootBox.java index 656b17be..e295fc2d 100644 --- a/src/protocol/swg/objectControllerObjects/ShowLootBox.java +++ b/src/protocol/swg/objectControllerObjects/ShowLootBox.java @@ -33,9 +33,9 @@ import resources.common.StringUtilities; public class ShowLootBox extends ObjControllerObject { private long playerId; - private List rewards; + private SWGObject[] rewards; - public ShowLootBox(long playerId, List rewards) { + public ShowLootBox(long playerId, SWGObject[] rewards) { this.playerId = playerId; this.rewards = rewards; } @@ -48,18 +48,22 @@ public class ShowLootBox extends ObjControllerObject { @Override public IoBuffer serialize() { // Controller Type = 11 - IoBuffer buffer = IoBuffer.allocate(20 + (rewards.size() * 8)).order(ByteOrder.LITTLE_ENDIAN); + IoBuffer buffer = IoBuffer.allocate(20 + (rewards.length * 8)).order(ByteOrder.LITTLE_ENDIAN); buffer.putInt(ObjControllerMessage.SHOW_LOOT_BOX); buffer.putLong(playerId); - buffer.putInt(1); // 0 for a black background on icon, 1 for transparent (default) + buffer.putInt(0); // 1 for a black background on icon, 0 or 2 for transparent (default) - buffer.putInt(rewards.size()); - for(SWGObject obj : rewards) { - buffer.putLong(obj.getObjectID()); + if (rewards.length == 1) { + buffer.putInt(1); + buffer.putLong(rewards[0].getObjectId()); + } else { + buffer.putInt(rewards.length); + for(SWGObject obj : rewards) { + buffer.putLong(obj.getObjectID()); + } } - return buffer.flip(); } diff --git a/src/services/PlayerService.java b/src/services/PlayerService.java index 55e3d8f7..7065eb96 100644 --- a/src/services/PlayerService.java +++ b/src/services/PlayerService.java @@ -43,11 +43,13 @@ import protocol.swg.CreateClientPathMessage; import protocol.swg.ExpertiseRequestMessage; import protocol.swg.GuildRequestMessage; import protocol.swg.GuildResponseMessage; +import protocol.swg.ObjControllerMessage; import protocol.swg.PlayerMoneyResponse; import protocol.swg.ServerTimeMessage; import protocol.swg.SetWaypointColor; import protocol.swg.objectControllerObjects.ChangeRoleIconChoice; import protocol.swg.objectControllerObjects.ShowFlyText; +import protocol.swg.objectControllerObjects.ShowLootBox; import resources.common.Console; import resources.common.FileUtilities; import resources.common.ObjControllerOpcodes; @@ -734,6 +736,7 @@ public class PlayerService implements INetworkDispatch { player.getTitleList().remove(title); } + /** * Creates a blue path to the destination point. * @param actor Player that will be seeing the blue path. @@ -755,6 +758,34 @@ public class PlayerService implements INetworkDispatch { actor.getClient().getSession().write(path.serialize()); } + /** + * Gives a player items and shows the "New Items" message. + * @param reciever Player receiving the items + * @param items The object(s) to be given. + */ + public void giveItems(CreatureObject reciever, SWGObject[] items) { + if (reciever == null || items == null) + return; + + if (reciever.getClient() == null) + return; + Client client = reciever.getClient(); + + if (client.getSession() == null) + return; + SWGObject inventory = reciever.getSlottedObject("inventory"); + + if (inventory == null) + return; + + for (SWGObject obj : items) { + inventory.add(obj); + } + + ObjControllerMessage objController = new ObjControllerMessage(11, new ShowLootBox(reciever.getObjectID(), items)); + client.getSession().write(objController.serialize()); + } + @Override public void shutdown() { // TODO Auto-generated method stub