diff --git a/scripts/commands/inspire.py b/scripts/commands/inspire.py index 99a03877..59aede34 100644 --- a/scripts/commands/inspire.py +++ b/scripts/commands/inspire.py @@ -7,7 +7,7 @@ def setup(): def run(core, actor, target, commandString): print ('Buffing Player: ' + str(target.getObjectId())) - openBuffWindow = BuffBuilderStartMessage(actor.getObjectId(), target.getObjectId()) + openBuffWindow = BuffBuilderStartMessage(actor.getObjectId(), actor.getObjectId(), target.getObjectId()) objController = ObjControllerMessage(11, openBuffWindow) actor.getClient().getSession().write(objController.serialize()) return \ No newline at end of file diff --git a/scripts/object/mobile/lifeday_saun_dann.py b/scripts/object/mobile/lifeday_saun_dann.py index 19a4da58..1b75a652 100644 --- a/scripts/object/mobile/lifeday_saun_dann.py +++ b/scripts/object/mobile/lifeday_saun_dann.py @@ -2,5 +2,5 @@ import sys def setup(core, object): object.setCustomName('Suan Dann') - object.setCurrentAnimation('appearance/animation/all_b_dnc_bowie_loop.ans') + #object.setCurrentAnimation('appearance/animation/all_b_dnc_bowie_loop.ans') return \ No newline at end of file diff --git a/src/protocol/swg/objectControllerObjects/BuffBuilderChange.java b/src/protocol/swg/objectControllerObjects/BuffBuilderChange.java index 31dea901..a561a132 100644 --- a/src/protocol/swg/objectControllerObjects/BuffBuilderChange.java +++ b/src/protocol/swg/objectControllerObjects/BuffBuilderChange.java @@ -1,66 +1,99 @@ package protocol.swg.objectControllerObjects; +import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; import java.nio.ByteOrder; +import java.util.Vector; import org.apache.mina.core.buffer.IoBuffer; import protocol.swg.ObjControllerMessage; +import resources.objects.BuffItem; public class BuffBuilderChange extends ObjControllerObject { - private long bufferId; - private long recipientId; private int buffCost; private int accepted; + private int startTime; - private long unk1; - private long unk2; - private long unk3; - - private int unkI1; - private int unkI2; + private long objectId; + private long bufferId; + private long recipientId; private byte unkByte; + private Vector buffs; + public BuffBuilderChange() { } - public BuffBuilderChange(long bufferId, long recipientId, int accepted, int cost) { + public BuffBuilderChange(long objectId, long bufferId, long recipientId, int accepted, int cost) { + this.objectId = objectId; this.bufferId = bufferId; this.recipientId = recipientId; this.accepted = accepted; this.buffCost = cost; + //this.unkByte = (byte) 0; } @Override public void deserialize(IoBuffer data) { - unk1 = data.getLong(); - unkI1 = data.getInt(); - unk2 = data.getLong(); - unk3 = data.getLong(); - unkI2 = data.getInt(); + objectId = data.getLong(); // acting players id + data.getInt(); // tick count + bufferId = data.getLong(); // objId + recipientId = data.getLong(); + startTime = data.getInt(); buffCost = data.getInt(); accepted = data.getInt(); unkByte = data.get(); + + int size = data.getInt(); // list size + for(int i = 0; i < size; i++) { + BuffItem buff = new BuffItem(); + int stringSize; + try { + stringSize = data.getShort(); + String buffName = new String(ByteBuffer.allocate(stringSize).put(data.array(), data.position(), size).array(), "US-ASCII"); + buff.setSkillName(buffName); + data.position(data.position() + size); + buff.setUnknown(data.getInt()); + buff.setAmount(data.getInt()); + + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + } + } @Override public IoBuffer serialize() { IoBuffer result = IoBuffer.allocate(100).order(ByteOrder.LITTLE_ENDIAN); - + result.putInt(ObjControllerMessage.BUFF_BUILDER_CHANGE); - result.putLong(unk1); + result.putLong(objectId); - result.putInt(unkI1); // tickCount - result.putLong(unk2); - result.putLong(unk3); - result.putInt(unkI2); // starting time + result.putInt(0); // tickCount + result.putLong(bufferId); + result.putLong(recipientId); + result.putInt(startTime); // starting time result.putInt(buffCost); result.putInt(accepted); - result.put(unkByte); // unk + result.put((byte) 0); // default 0 - //return result.flip(); + if (buffs == null || buffs.isEmpty()){ + result.putInt(0); + } else { + result.putInt(buffs.size()); + for (BuffItem buff : buffs) { + result.put(getAsciiString(buff.getSkillName())); + result.putInt(buff.getUnknown()); + result.putInt(buff.getAmount()); + } + } + return result.flip(); } @@ -72,14 +105,6 @@ public class BuffBuilderChange extends ObjControllerObject { this.bufferId = bufferId; } - public long getRecipientId() { - return recipientId; - } - - public void setRecipientId(long recipientId) { - this.recipientId = recipientId; - } - public int getBuffCost() { return buffCost; } @@ -96,46 +121,14 @@ public class BuffBuilderChange extends ObjControllerObject { this.accepted = accepted; } - public long getUnk1() { - return unk1; + public long getObjectId() { + return objectId; } - public void setUnk1(long unk1) { - this.unk1 = unk1; + public void setObjectId(long objId) { + this.objectId = objId; } - public long getUnk2() { - return unk2; - } - - public void setUnk2(long unk2) { - this.unk2 = unk2; - } - - public long getUnk3() { - return unk3; - } - - public void setUnk3(long unk3) { - this.unk3 = unk3; - } - - public int getUnkI1() { - return unkI1; - } - - public void setUnkI1(int unkI1) { - this.unkI1 = unkI1; - } - - public int getUnkI2() { - return unkI2; - } - - public void setUnkI2(int unkI2) { - this.unkI2 = unkI2; - } - public byte getUnkByte() { return this.unkByte; } @@ -144,4 +137,27 @@ public class BuffBuilderChange extends ObjControllerObject { this.unkByte = unkByte; } + public int getStartTime() { + return startTime; + } + + public void setStartTime(int startTime) { + this.startTime = startTime; + } + + public long getRecipientId() { + return recipientId; + } + + public void setRecipientId(long recipientId) { + this.recipientId = recipientId; + } + + public void setBuffs(Vector buffVector) { + this.buffs = buffVector; + } + + public Vector getBuffVector() { + return this.buffs; + } } diff --git a/src/protocol/swg/objectControllerObjects/BuffBuilderStartMessage.java b/src/protocol/swg/objectControllerObjects/BuffBuilderStartMessage.java index 622b3b70..dd75d45c 100644 --- a/src/protocol/swg/objectControllerObjects/BuffBuilderStartMessage.java +++ b/src/protocol/swg/objectControllerObjects/BuffBuilderStartMessage.java @@ -10,9 +10,11 @@ public class BuffBuilderStartMessage extends ObjControllerObject { private long objectId; private long recieverId; + private long bufferId; - public BuffBuilderStartMessage(long objectId, long recieverId) { + public BuffBuilderStartMessage(long objectId, long bufferId, long recieverId) { this.objectId = objectId; + this.bufferId = bufferId; this.recieverId = recieverId; } @@ -30,7 +32,7 @@ public class BuffBuilderStartMessage extends ObjControllerObject { result.putLong(objectId); result.putInt(0); // tick count - result.putLong(objectId); + result.putLong(bufferId); result.putLong(recieverId); diff --git a/src/resources/objects/BuffItem.java b/src/resources/objects/BuffItem.java new file mode 100644 index 00000000..a7eb3ab0 --- /dev/null +++ b/src/resources/objects/BuffItem.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2013 + * + * This File is part of NGECore2. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Using NGEngine to work with NGECore2 is making a combined work based on NGEngine. + * Therefore all terms and conditions of the GNU Lesser General Public License cover the combination. + ******************************************************************************/ +package resources.objects; + +public class BuffItem { + private String skillName; + private int unknown; + private int amount; + + public BuffItem() { + + } + + public BuffItem(String skillName, int unknown, int amount) { + this.skillName = skillName; + this.unknown = unknown; + this.amount = amount; + } + + public String getSkillName() { + return skillName; + } + + public void setSkillName(String skillName) { + this.skillName = skillName; + } + + public int getUnknown() { + return unknown; + } + + public void setUnknown(int unknown) { + this.unknown = unknown; + } + + public int getAmount() { + return amount; + } + + public void setAmount(int amount) { + this.amount = amount; + } +} diff --git a/src/resources/objects/creature/CreatureObject.java b/src/resources/objects/creature/CreatureObject.java index c29bf16f..9baf46fa 100644 --- a/src/resources/objects/creature/CreatureObject.java +++ b/src/resources/objects/creature/CreatureObject.java @@ -713,10 +713,10 @@ public class CreatureObject extends TangibleObject implements IPersistent { synchronized(objectMutex) { this.currentAnimation = currentAnimation; } - //Animation animation = new Animation(getObjectId(), currentAnimation); - //ObjControllerMessage objController = new ObjControllerMessage(0x1B, animation); + Animation animation = new Animation(getObjectId(), currentAnimation); + ObjControllerMessage objController = new ObjControllerMessage(0x1B, animation); - //notifyObservers(objController, true); + notifyObservers(objController, true); notifyObservers(messageBuilder.buildCurrentAnimationDelta(currentAnimation), true); diff --git a/src/services/BuffService.java b/src/services/BuffService.java index 9187fe37..13804f83 100644 --- a/src/services/BuffService.java +++ b/src/services/BuffService.java @@ -35,9 +35,13 @@ import java.util.concurrent.TimeUnit; + + + import org.apache.mina.core.buffer.IoBuffer; import org.apache.mina.core.session.IoSession; +import protocol.swg.ObjControllerMessage; import protocol.swg.objectControllerObjects.BuffBuilderChange; import protocol.swg.objectControllerObjects.BuffBuilderStartMessage; import resources.common.Console; @@ -48,6 +52,8 @@ import resources.objects.DamageOverTime; import resources.objects.creature.CreatureObject; import resources.objects.player.PlayerObject; import main.NGECore; +import engine.clients.Client; +import engine.resources.objects.SWGObject; import engine.resources.service.INetworkDispatch; import engine.resources.service.INetworkRemoteEvent; @@ -70,25 +76,64 @@ public class BuffService implements INetworkDispatch { Console.println("BUFF_BUILDER_CHANGE RECIEVED"); data.order(ByteOrder.LITTLE_ENDIAN); + Client client = core.getClient((Integer) session.getAttribute("connectionId")); + + if(client == null) + return; + + SWGObject sender = client.getParent(); + + if(sender == null) + return; + BuffBuilderChange changeMessage = new BuffBuilderChange(); changeMessage.deserialize(data); - //Console.println("Unknown Long 1 (objId?): " + changeMessage.getUnk1()); - //Console.println("Unknown Int 1 (tickCount?): " + changeMessage.getUnkI1()); - //Console.println("Unknown Long 2 (objId?): " + changeMessage.getUnk2()); - //Console.println("Unknown Long 3 (buff or buffer?): " + changeMessage.getUnk3()); - //Console.println("Unknown Int 2 (???): " + changeMessage.getUnkI2()); - //Console.println("Unknown Int 3 (buffCost?): " + changeMessage.getBuffCost()); - //Console.println("Unknown Int 4 (accepted?): " + changeMessage.getAccepted()); - //Console.println("Unknown Byte: " + changeMessage.getUnkByte()); - //CreatureObject player = (CreatureObject) core.objectService.getObject(changeMessage.getUnk1()); + SWGObject recipient = core.objectService.getObject(changeMessage.getRecipientId()); - //if (player == null) - //return; - - //BuffBuilderStartMessage startMsg = new BuffBuilderStartMessage(changeMessage.getBufferId(), changeMessage.getUnknown()); - //player.getClient().getSession().write(startMsg.serialize()); + if (recipient == null || recipient.getClient() == null) + return; + if (sender.getClient().getSession().containsAttribute("buffWorkshop")) { + + long attribute = (long) sender.getClient().getSession().getAttribute("buffWorkshop"); + Console.println("Sender Attribute = " + attribute); + Console.println("Recipient ID (Packet) = " + changeMessage.getRecipientId()); + + if (attribute == changeMessage.getObjectId()) { + // TODO: accepted checked? give buff + Console.println("Buffer buffing themselves!"); + return; + } + + if (attribute == changeMessage.getRecipientId() && attribute != changeMessage.getObjectId()) { + Console.println("Attribute check passed!"); + BuffBuilderChange recievingMsg = new BuffBuilderChange(recipient.getObjectId(), changeMessage.getBufferId(), recipient.getObjectId(), 0, changeMessage.getBuffCost()); + recievingMsg.setStartTime(changeMessage.getStartTime()); + + ObjControllerMessage objController = new ObjControllerMessage(0x23, recievingMsg); + recipient.getClient().getSession().write(objController.serialize()); + Console.println("Msg sent to: " + recipient.getCustomName()); + } + + } else { + + // Don't need a Buff Recipient Window for buffing themselves.. + if (changeMessage.getObjectId() == changeMessage.getRecipientId()) { + sender.getClient().getSession().setAttribute("buffWorkshop", recipient.getObjectId()); + Console.println("Sender attribute set to: " + sender.getClient().getSession().getAttribute("buffWorkshop").toString()); + return; + } + + BuffBuilderStartMessage startMsg = new BuffBuilderStartMessage(recipient.getObjectId(), sender.getObjectId(), recipient.getObjectId()); + ObjControllerMessage objController = new ObjControllerMessage(11, startMsg); + recipient.getClient().getSession().write(objController.serialize()); + + recipient.getClient().getSession().setAttribute("buffWorkshop", changeMessage.getObjectId()); + Console.println("Recipient attribute set to: " + recipient.getClient().getSession().getAttribute("buffWorkshop").toString()); + sender.getClient().getSession().setAttribute("buffWorkshop", recipient.getObjectId()); + Console.println("Sender attribute set to: " + sender.getClient().getSession().getAttribute("buffWorkshop").toString()); + } } }); }