diff --git a/scripts/buffs/buildabuff_inspiration.py b/scripts/buffs/buildabuff_inspiration.py index bfcff248..c6bf7407 100644 --- a/scripts/buffs/buildabuff_inspiration.py +++ b/scripts/buffs/buildabuff_inspiration.py @@ -10,18 +10,14 @@ def setup(core, actor, buff): buff.setDuration(3600) #1 hour - for BuffBuilder in buffWorkshop: - core.skillModService.addSkillMod(actor, BuffBuilder.getStatAffects(), BuffBuilder.getTotalAffected()) - print (' gave the skill mod ' + BuffBuilder.getStatAffects() + ' with affect of ' + str(BuffBuilder.getTotalAffected())) - return - + for BuffItem in buffWorkshop: + core.skillModService.addSkillMod(actor, BuffItem.getSkillName(), BuffItem.getAffectAmount()) + return def removeBuff(core, actor, buff): - for BuffBuilder in actor.getAttachment('buffWorkshop'): - core.skillModService.deductSkillMod(actor, BuffBuilder.getStatAffects(), BuffBuilder.getTotalAffected()) - print ('removed skill mod!') - return + for BuffItem in actor.getAttachment('buffWorkshop'): + core.skillModService.deductSkillMod(actor, BuffItem.getSkillName(), BuffItem.getAffectAmount()) actor.setAttachment('buffWorkshop', 'none') return \ No newline at end of file diff --git a/scripts/commands/inspire.py b/scripts/commands/inspire.py index 46a97aaf..4a2aa2c8 100644 --- a/scripts/commands/inspire.py +++ b/scripts/commands/inspire.py @@ -12,7 +12,6 @@ def run(core, actor, target, commandString): return if target is None or actor.getObjectId() == target.getObjectId(): - print ('Buffing Player: ' + str(target.getObjectId()) + ' or: ' + target.getCustomName()) openBuffWindow = BuffBuilderStartMessage(actor.getObjectId(), actor.getObjectId(), actor.getObjectId()) objController = ObjControllerMessage(11, openBuffWindow) actor.getClient().getSession().write(objController.serialize()) @@ -30,12 +29,11 @@ def run(core, actor, target, commandString): actor.sendSystemMessage('@performance:insp_buff_must_listen', 2) return - print ('Buffing Player: ' + str(target.getObjectId()) + ' or: ' + target.getCustomName()) - openBuffWindow = BuffBuilderStartMessage(actor.getObjectId(), actor.getObjectId(), target.getObjectId()) - objController = ObjControllerMessage(11, openBuffWindow) + builderWindow = BuffBuilderStartMessage(actor.getObjectId(), actor.getObjectId(), target.getObjectId()) + objController = ObjControllerMessage(11, builderWindow) actor.getClient().getSession().write(objController.serialize()) - openBuffWindow = BuffBuilderStartMessage(target.getObjectId(), actor.getObjectId(), target.getObjectId()) - objController2 = ObjControllerMessage(11, openBuffWindow) + recipientWindow = BuffBuilderStartMessage(target.getObjectId(), actor.getObjectId(), target.getObjectId()) + objController2 = ObjControllerMessage(11, recipientWindow) target.getClient().getSession().write(objController2.serialize()) return diff --git a/scripts/commands/watch.py b/scripts/commands/watch.py index 5658d8fb..6e55feef 100644 --- a/scripts/commands/watch.py +++ b/scripts/commands/watch.py @@ -4,31 +4,30 @@ def setup(): return def run(core, actor, target, commandString): - if not target: - #FIXME: should accept name as a parameter. - # since that probably needs support in many places, - # best find a generic place for it in the server code - return + entSvc = core.entertainmentService + + if not target and commandString is not None: + target = core.chatService.getObjectByFirstName(commandString) + + if target is None: + return + + if not target.isPlayer(): + actor.sendSystemMessage('@performance:dance_watch_npc', 0) + return - if not target.isPlayer(): - actor.sendSystemMessage('@performance:dance_watch_npc') - return + perf = entSvc.getPerformanceByIndex(target.getPerformanceId()) - - entSvc = core.entertainmentService - perf = entSvc.getPerformanceByIndex(target.getPerformanceId()) + if target.getPosture() != 0x09 or not perf or perf.getDanceVisualId() < 0: + actor.sendSystemMessage(target.getCustomName() + ' is not dancing.',0) + return - if target.getPosture() != 0x09 or not perf or perf.getDanceVisualId() < 0: - actor.sendSystemMessage('@performance:dance_watch_not_dancing',0) - return - - oldWatchee = actor.getPerformanceWatchee() - if oldWatchee and oldWatchee != target: - oldWatchee.removeAudience(actor) - - actor.setPerformanceWatchee(target) - target.addAudience(actor) - actor.setMoodAnimation('entertained') - actor.sendSystemMessage('@performance:dance_watch_self',0) - return + oldWatchee = actor.getPerformanceWatchee() + if oldWatchee and oldWatchee != target: + oldWatchee.removeAudience(actor) + actor.setPerformanceWatchee(target) + target.addAudience(actor) + actor.setMoodAnimation('entertained') + actor.sendSystemMessage('You start watching ' + target.getCustomName() + '.',0) + return \ No newline at end of file diff --git a/src/protocol/swg/ObjControllerMessage.java b/src/protocol/swg/ObjControllerMessage.java index af68bbe7..a441cad4 100644 --- a/src/protocol/swg/ObjControllerMessage.java +++ b/src/protocol/swg/ObjControllerMessage.java @@ -55,8 +55,9 @@ public class ObjControllerMessage extends SWGMessage { public static final int SHOW_FLY_TEXT = 0x01BD; public static final int START_TASK = 0x448; public static final int ANIMATION = 0x00F2; - public static final int BUFF_BUILDER_START = 0x025C; public static final int BUFF_BUILDER_CHANGE = 0x025A; + public static final int BUFF_BUILDER_END = 0x025B; + public static final int BUFF_BUILDER_START = 0x025C; public static final int UI_PLAY_EFFECT = 0x0401; public static final int SHOW_LOOT_BOX = 0x04BC; diff --git a/src/protocol/swg/objectControllerObjects/BuffBuilderChangeMessage.java b/src/protocol/swg/objectControllerObjects/BuffBuilderChangeMessage.java index a877944a..ef067e9c 100644 --- a/src/protocol/swg/objectControllerObjects/BuffBuilderChangeMessage.java +++ b/src/protocol/swg/objectControllerObjects/BuffBuilderChangeMessage.java @@ -6,28 +6,26 @@ import java.util.Vector; import org.apache.mina.core.buffer.IoBuffer; import protocol.swg.ObjControllerMessage; -import resources.common.ObjControllerOpcodes; -import resources.common.StringUtilities; import resources.objects.BuffItem; public class BuffBuilderChangeMessage extends ObjControllerObject { + private boolean accepted; private int buffCost; - private int time; + + private long bufferId; + private int buffRecipientAccepted; + private long buffRecipientId; private long objectId; - private long bufferId; - private long buffRecipientId; - - private boolean accepted; - private int buffRecipientAccepted; - private Vector statBuffs = new Vector(); - + + private int time; + public BuffBuilderChangeMessage() { - + } - + public BuffBuilderChangeMessage(long objectId, long bufferId, long buffRecipientId, Vector statBuffs) { this.objectId = objectId; this.bufferId = bufferId; @@ -35,136 +33,135 @@ public class BuffBuilderChangeMessage extends ObjControllerObject { this.statBuffs = statBuffs; } - + @Override - public void deserialize(IoBuffer buffer) { - setObjectId(buffer.getLong()); - buffer.getInt(); - setBufferId(buffer.getLong()); - setBuffRecipientId(buffer.getLong()); - setTime(buffer.getInt()); - setBuffCost(buffer.getInt()); - - byte value = buffer.get(); + public void deserialize(IoBuffer data) { + setObjectId(data.getLong()); + data.getInt(); + setBufferId(data.getLong()); + setBuffRecipientId(data.getLong()); + setTime(data.getInt()); + setBuffCost(data.getInt()); + + byte value = data.get(); if (value == (byte) 0) setAccepted(false); else if (value == (byte) 1) setAccepted(true); - - setBuffRecipientAccepted(buffer.getInt()); - - int statSize = buffer.getInt(); + + setBuffRecipientAccepted(data.getInt()); + + int statSize = data.getInt(); for (int i = 0; i < statSize; i++) { BuffItem item = new BuffItem(); - - String statName = getAsciiString(buffer); + + String statName = getAsciiString(data); item.setSkillName(statName); - - int investedPoints = buffer.getInt(); + + int investedPoints = data.getInt(); item.setInvested(investedPoints); - - int maxAmount = buffer.getInt(); - item.setBonusAmount(maxAmount); - + + int entBonus = data.getInt(); + item.setEntertainerBonus(entBonus); + statBuffs.add(item); - System.out.println("Added buff item with " + investedPoints + " invested points " + " which has a bonus amount of " + maxAmount); } } - @Override - public IoBuffer serialize() { - IoBuffer result = IoBuffer.allocate(65 + statBuffs.size()).order(ByteOrder.LITTLE_ENDIAN); - result.setAutoExpand(true); - - result.putInt(ObjControllerMessage.BUFF_BUILDER_CHANGE); - result.putLong(objectId); - - result.putInt(0); - - result.putLong(bufferId); - result.putLong(buffRecipientId); - - result.putInt(time); - result.putInt(buffCost); - - result.put((byte) ((accepted) ? 1 : 0)); - result.putInt(buffRecipientAccepted); - - result.putInt(statBuffs.size()); - - if (!statBuffs.isEmpty()) { - for (BuffItem item : statBuffs) { - result.put(getAsciiString(item.getSkillName())); - result.putInt(item.getInvested()); - result.putInt(item.getBonusAmount()); - } - } - - return result.flip(); - } - - public int getBuffCost() { - return buffCost; - } - - public void setBuffCost(int buffCost) { - this.buffCost = buffCost; - } - - public int getTime() { - return time; - } - - public void setTime(int time) { - this.time = time; - } - - public long getObjectId() { - return objectId; - } - - public void setObjectId(long objectId) { - this.objectId = objectId; - } - - public long getBufferId() { - return bufferId; - } - - public void setBufferId(long bufferId) { - this.bufferId = bufferId; - } - - public long getBuffRecipientId() { - return buffRecipientId; - } - - public void setBuffRecipientId(long buffRecipientId) { - this.buffRecipientId = buffRecipientId; - } - public boolean getAccepted() { return accepted; } - public void setAccepted(boolean accepted) { - this.accepted = accepted; + public int getBuffCost() { + return buffCost; + } + + public long getBufferId() { + return bufferId; } public int getBuffRecipientAccepted() { return buffRecipientAccepted; } - public void setBuffRecipientAccepted(int buffRecipientAccepted) { - this.buffRecipientAccepted = buffRecipientAccepted; + public long getBuffRecipientId() { + return buffRecipientId; + } + + public long getObjectId() { + return objectId; } public Vector getStatBuffs() { return statBuffs; } + public int getTime() { + return time; + } + + @Override + public IoBuffer serialize() { + IoBuffer result = IoBuffer.allocate(65 + statBuffs.size()).order(ByteOrder.LITTLE_ENDIAN); + result.setAutoExpand(true); + + result.putInt(ObjControllerMessage.BUFF_BUILDER_CHANGE); + result.putLong(objectId); + + result.putInt(0); + + result.putLong(bufferId); + result.putLong(buffRecipientId); + + result.putInt(time); + result.putInt(buffCost); + + result.put((byte) ((accepted) ? 1 : 0)); + result.putInt(buffRecipientAccepted); + + result.putInt(statBuffs.size()); + + if (!statBuffs.isEmpty()) { + for (BuffItem item : statBuffs) { + result.put(getAsciiString(item.getSkillName())); + result.putInt(item.getInvested()); + result.putInt(item.getEntertainerBonus()); + } + } + + return result.flip(); + } + + public void setAccepted(boolean accepted) { + this.accepted = accepted; + } + + public void setBuffCost(int buffCost) { + this.buffCost = buffCost; + } + + public void setBufferId(long bufferId) { + this.bufferId = bufferId; + } + + public void setBuffRecipientAccepted(int buffRecipientAccepted) { + this.buffRecipientAccepted = buffRecipientAccepted; + } + + public void setBuffRecipientId(long buffRecipientId) { + this.buffRecipientId = buffRecipientId; + } + + public void setObjectId(long objectId) { + this.objectId = objectId; + } + public void setStatBuffs(Vector statBuffs) { this.statBuffs = statBuffs; } + public void setTime(int time) { + this.time = time; + } + } diff --git a/src/protocol/swg/objectControllerObjects/BuffBuilderEndMessage.java b/src/protocol/swg/objectControllerObjects/BuffBuilderEndMessage.java new file mode 100644 index 00000000..96a959db --- /dev/null +++ b/src/protocol/swg/objectControllerObjects/BuffBuilderEndMessage.java @@ -0,0 +1,197 @@ +/******************************************************************************* + * 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 protocol.swg.objectControllerObjects; + +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 BuffBuilderEndMessage extends ObjControllerObject { + + private boolean accepted; + private int buffCost; + + private long bufferId; + private int buffRecipientAccepted; + private long buffRecipientId; + + private long objectId; + private Vector statBuffs = new Vector(); + + private int time; + + public BuffBuilderEndMessage() { + + } + + public BuffBuilderEndMessage(BuffBuilderEndMessage endMessage) { + this.buffCost = endMessage.getBuffCost(); + this.time = endMessage.getTime(); + this.accepted = endMessage.getAccepted(); + this.buffRecipientAccepted = endMessage.getBuffRecipientAccepted(); + this.statBuffs = endMessage.getStatBuffs(); + } + + public BuffBuilderEndMessage(BuffBuilderChangeMessage changeMessage) { + this.buffRecipientId = changeMessage.getBuffRecipientId(); + this.bufferId = changeMessage.getBufferId(); + this.buffCost = changeMessage.getBuffCost(); + this.time = changeMessage.getTime(); + this.accepted = changeMessage.getAccepted(); + this.buffRecipientAccepted = changeMessage.getBuffRecipientAccepted(); + this.statBuffs = changeMessage.getStatBuffs(); + } + @Override + public void deserialize(IoBuffer data) { + setObjectId(data.getLong()); + data.getInt(); + setBufferId(data.getLong()); + setBuffRecipientId(data.getLong()); + setTime(data.getInt()); + setBuffCost(data.getInt()); + + byte value = data.get(); + if (value == (byte) 0) + setAccepted(false); + else if (value == (byte) 1) + setAccepted(true); + + setBuffRecipientAccepted(data.getInt()); + + int statSize = data.getInt(); + for (int i = 0; i < statSize; i++) { + BuffItem item = new BuffItem(); + + String statName = getAsciiString(data); + item.setSkillName(statName); + + int investedPoints = data.getInt(); + item.setInvested(investedPoints); + + int entBonus = data.getInt(); + item.setEntertainerBonus(entBonus); + + statBuffs.add(item); + } + } + + public boolean getAccepted() { + return accepted; + } + + public int getBuffCost() { + return buffCost; + } + + public long getBufferId() { + return bufferId; + } + + public int getBuffRecipientAccepted() { + return buffRecipientAccepted; + } + + public long getBuffRecipientId() { + return buffRecipientId; + } + + public long getObjectId() { + return objectId; + } + + public Vector getStatBuffs() { + return statBuffs; + } + + public int getTime() { + return time; + } + + @Override + public IoBuffer serialize() { + IoBuffer result = IoBuffer.allocate(65 + statBuffs.size()).order(ByteOrder.LITTLE_ENDIAN); + result.setAutoExpand(true); + + result.putInt(ObjControllerMessage.BUFF_BUILDER_END); + result.putLong(objectId); + + result.putInt(0); + + result.putLong(bufferId); + result.putLong(buffRecipientId); + + result.putInt(time); + result.putInt(buffCost); + + result.put((byte) ((accepted) ? 1 : 0)); + result.putInt(buffRecipientAccepted); + + result.putInt(statBuffs.size()); + + if (!statBuffs.isEmpty()) { + for (BuffItem item : statBuffs) { + result.put(getAsciiString(item.getSkillName())); + result.putInt(item.getInvested()); + result.putInt(item.getEntertainerBonus()); + } + } + + return result.flip(); + } + + public void setAccepted(boolean accepted) { + this.accepted = accepted; + } + + public void setBuffCost(int buffCost) { + this.buffCost = buffCost; + } + + public void setBufferId(long bufferId) { + this.bufferId = bufferId; + } + + public void setBuffRecipientAccepted(int buffRecipientAccepted) { + this.buffRecipientAccepted = buffRecipientAccepted; + } + + public void setBuffRecipientId(long buffRecipientId) { + this.buffRecipientId = buffRecipientId; + } + + public void setObjectId(long objectId) { + this.objectId = objectId; + } + + public void setStatBuffs(Vector statBuffs) { + this.statBuffs = statBuffs; + } + + public void setTime(int time) { + this.time = time; + } + +} diff --git a/src/resources/common/BuffBuilder.java b/src/resources/common/BuffBuilder.java index c376ae5a..83b2d9fb 100644 --- a/src/resources/common/BuffBuilder.java +++ b/src/resources/common/BuffBuilder.java @@ -1,70 +1,92 @@ +/******************************************************************************* + * 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.common; public class BuffBuilder { - private String statName; - private String statAffects; - private int maxTimesApplied; private int affectAmount; - private String requiredExperience; - - private int entBonus; - + private String category; + private int cost; + private int maxTimesApplied; + private String requiredExpertise; + private String statAffects; + private String statName; + public BuffBuilder() { - - } - public String getStatName() { - return statName; - } - - public void setStatName(String statName) { - this.statName = statName; - } - - public String getStatAffects() { - return statAffects; - } - - public void setStatAffects(String statAffects) { - this.statAffects = statAffects; - } - - public int getMaxTimesApplied() { - return maxTimesApplied; - } - - public void setMaxTimesApplied(int maxTimesApplied) { - this.maxTimesApplied = maxTimesApplied; } public int getAffectAmount() { return affectAmount; } + public String getCategory() { + return category; + } + + public int getCost() { + return this.cost; + } + + public int getMaxTimesApplied() { + return maxTimesApplied; + } + + public String getRequiredExpertise() { + return requiredExpertise; + } + + public String getStatAffects() { + return statAffects; + } + + public String getStatName() { + return statName; + } + public void setAffectAmount(int affectAmount) { this.affectAmount = affectAmount; } - public String getRequiredExperience() { - return requiredExperience; + public void setCategory(String category) { + this.category = category; } - public void setRequiredExperience(String requiredExperience) { - this.requiredExperience = requiredExperience; - } - - public int getTotalAffected() { - // 10 * 10 = 100 - int totalAffected = getMaxTimesApplied() * getAffectAmount(); - Console.println("Total Affected: " + totalAffected + getEntBonus()); - return totalAffected + getEntBonus(); + public void setCost(int cost) { + this.cost = cost; } - public int getEntBonus() { - return entBonus; + public void setMaxTimesApplied(int maxTimesApplied) { + this.maxTimesApplied = maxTimesApplied; } - public void setEntBonus(int entBonus) { - this.entBonus = entBonus; + public void setRequiredExpertise(String requiredExpertise) { + this.requiredExpertise = requiredExpertise; + } + + public void setStatAffects(String statAffects) { + this.statAffects = statAffects; + } + + public void setStatName(String statName) { + this.statName = statName; } } diff --git a/src/resources/common/ObjControllerOpcodes.java b/src/resources/common/ObjControllerOpcodes.java index 5834038e..0317dfd0 100644 --- a/src/resources/common/ObjControllerOpcodes.java +++ b/src/resources/common/ObjControllerOpcodes.java @@ -32,6 +32,7 @@ public class ObjControllerOpcodes { public static final int OBJECT_MENU_REQUEST = 0x46010000; public static final int SECURE_TRADE = 0x15010000; public static final int BUFF_BUILDER_CHANGE = 0x5A020000; + public static final int BUFF_BUILDER_END = 0x5B020000; public static final int MISSION_LIST_REQUEST = 0xF5000000; public static final int ChangeRoleIconChoice = 0x4D040000; } diff --git a/src/resources/objects/BuffItem.java b/src/resources/objects/BuffItem.java index 8d647d4a..050c21e9 100644 --- a/src/resources/objects/BuffItem.java +++ b/src/resources/objects/BuffItem.java @@ -16,47 +16,56 @@ * 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. + * 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 affectAmount; + private int entertainerBonus; private int invested; - private int bonusAmount; // expertise bonus (50%*4 = 200) which would then result in bonusAmount + (maxTimesApplied * affectAmount) = result - + private String skillName; + public BuffItem() { - + } - - public BuffItem(String skillName, int invested, int amount) { + + public BuffItem(String skillName, int invested, int entBonus) { this.skillName = skillName; this.invested = invested; - this.bonusAmount = amount; + this.entertainerBonus = entBonus; } - public String getSkillName() { - return skillName; + public int getAffectAmount() { + return affectAmount; } - public void setSkillName(String skillName) { - this.skillName = skillName; + public int getEntertainerBonus() { + return entertainerBonus; } public int getInvested() { return invested; } + public String getSkillName() { + return skillName; + } + + public void setAffectAmount(int amount) { + this.affectAmount = amount; + } + + public void setEntertainerBonus(int entertainerBonus) { + this.entertainerBonus = entertainerBonus; + } + public void setInvested(int invested) { this.invested = invested; } - public int getBonusAmount() { - return bonusAmount; - } - - public void setBonusAmount(int amount) { - this.bonusAmount = amount; + public void setSkillName(String skillName) { + this.skillName = skillName; } } diff --git a/src/resources/objects/player/PlayerObject.java b/src/resources/objects/player/PlayerObject.java index 2735c475..7ea0ff18 100644 --- a/src/resources/objects/player/PlayerObject.java +++ b/src/resources/objects/player/PlayerObject.java @@ -232,8 +232,8 @@ public class PlayerObject extends IntangibleObject { synchronized(objectMutex) { xpExists = xpList.containsKey(type); xpList.put(type, amount); - Console.println("Put " + type + " exp of " + amount + " in the map."); - Console.println("Map is now: " + xpList.get(type).intValue()); + //Console.println("Put " + type + " exp of " + amount + " in the map."); + //Console.println("Map is now: " + xpList.get(type).intValue()); } if (getContainer() != null && getContainer().getClient() != null && getContainer().getClient().getSession() != null) { diff --git a/src/services/EntertainmentService.java b/src/services/EntertainmentService.java index 2f6adb3b..1732727b 100644 --- a/src/services/EntertainmentService.java +++ b/src/services/EntertainmentService.java @@ -19,11 +19,13 @@ import org.apache.mina.core.session.IoSession; import protocol.swg.ObjControllerMessage; import protocol.swg.OkMessage; import protocol.swg.objectControllerObjects.BuffBuilderChangeMessage; +import protocol.swg.objectControllerObjects.BuffBuilderEndMessage; import protocol.swg.objectControllerObjects.BuffBuilderStartMessage; import resources.common.BuffBuilder; import resources.common.Console; import resources.common.ObjControllerOpcodes; import resources.common.Performance; +import resources.common.StringUtilities; import resources.objects.Buff; import resources.objects.BuffItem; import resources.objects.creature.CreatureObject; @@ -55,52 +57,103 @@ public class EntertainmentService implements INetworkDispatch { @Override public void insertOpcodes(Map swgOpcodes, Map objControllerOpcodes) { + objControllerOpcodes.put(ObjControllerOpcodes.BUFF_BUILDER_END, new INetworkRemoteEvent() { + + @Override + public void handlePacket(IoSession session, IoBuffer data) throws Exception { + + data.order(ByteOrder.LITTLE_ENDIAN); + StringUtilities.printBytes(data.array()); + Client client = core.getClient(session); + + if(client == null) + return; + + SWGObject sender = client.getParent(); + + if(sender == null) + return; + + BuffBuilderEndMessage sentPacket = new BuffBuilderEndMessage(); + sentPacket.deserialize(data); + + SWGObject buffer = core.objectService.getObject(sentPacket.getBufferId()); + SWGObject buffRecipient = core.objectService.getObject(sentPacket.getBuffRecipientId()); + + if(buffer == null || buffRecipient == null) + return; + + // No need to send end packet when buffing yourself. + if (buffRecipient != buffer) { + if(buffRecipient.getClient() == null || buffRecipient.getClient().getSession() == null) + return; + + if (sender.getObjectId() == buffer.getObjectId()) { + // send close packet to recipient + BuffBuilderEndMessage end = new BuffBuilderEndMessage(sentPacket); + end.setObjectId(buffRecipient.getObjectId()); + + end.setBufferId(buffer.getObjectId()); + end.setBuffRecipientId(buffRecipient.getObjectId()); + + ObjControllerMessage closeMessage = new ObjControllerMessage(0x0B, end); + buffRecipient.getClient().getSession().write(closeMessage.serialize()); + + } + if (sender.getObjectId() == buffRecipient.getObjectId()) { + // send close packet to buffer + BuffBuilderEndMessage end = new BuffBuilderEndMessage(sentPacket); + end.setObjectId(buffer.getObjectId()); + + end.setBufferId(buffer.getObjectId()); + end.setBuffRecipientId(buffRecipient.getObjectId()); + + ObjControllerMessage closeMessage = new ObjControllerMessage(0x0B, end); + buffer.getClient().getSession().write(closeMessage.serialize()); + CreatureObject cre = (CreatureObject) buffer; + cre.sendSystemMessage("The buff recipient cancelled the buff builder session.", (byte) 0); + } + } + } + }); + objControllerOpcodes.put(ObjControllerOpcodes.BUFF_BUILDER_CHANGE, new INetworkRemoteEvent() { @Override public void handlePacket(IoSession session, IoBuffer data) throws Exception { - Console.println("BUFF_BUILDER_CHANGE RECIEVED"); data.order(ByteOrder.LITTLE_ENDIAN); - + Client client = core.getClient(session); - + if(client == null) return; - + SWGObject sender = client.getParent(); - + if(sender == null) return; - + BuffBuilderChangeMessage sentPacket = new BuffBuilderChangeMessage(); sentPacket.deserialize(data); Vector statBuffs = sentPacket.getStatBuffs(); - - /*for (BuffItem item : statBuffs) { - System.out.println("Buff Name: " + item.getSkillName()); - System.out.println("Ents bonus to item: " + item.getAmount()); - }*/ - + SWGObject buffer = core.objectService.getObject(sentPacket.getBufferId()); SWGObject buffRecipient = core.objectService.getObject(sentPacket.getBuffRecipientId()); - - Console.println("Packet Sender ID: " + sender.getObjectId()); - + if (buffer != buffRecipient) { - + BuffBuilderChangeMessage changeMessage = new BuffBuilderChangeMessage(); changeMessage.setBuffCost(sentPacket.getBuffCost()); changeMessage.setTime(sentPacket.getTime()); changeMessage.setBufferId(buffer.getObjectId()); changeMessage.setBuffRecipientId(buffRecipient.getObjectId()); - + if (!statBuffs.isEmpty()) changeMessage.setStatBuffs(statBuffs); - + if (sentPacket.getAccepted() == true && sentPacket.getBuffRecipientAccepted() == 1) { - System.out.println("both accepted!"); - + if (sentPacket.getBuffCost() > 0) { CreatureObject recipientCreature = (CreatureObject) buffRecipient; if (recipientCreature.getCashCredits() >= sentPacket.getBuffCost()) { @@ -109,36 +162,47 @@ public class EntertainmentService implements INetworkDispatch { return; } } - - OkMessage closeMsg = new OkMessage(); - buffer.getClient().getSession().write(closeMsg.serialize()); - + giveInspirationBuff(buffRecipient, statBuffs); - + + BuffBuilderEndMessage endBuilder = new BuffBuilderEndMessage(changeMessage); + endBuilder.setObjectId(buffer.getObjectId()); + + BuffBuilderEndMessage endRecipient = new BuffBuilderEndMessage(changeMessage); + endRecipient.setObjectId(buffRecipient.getObjectId()); + + ObjControllerMessage closeBuilder = new ObjControllerMessage(0x0B, endBuilder); + session.write(closeBuilder.serialize()); + + ObjControllerMessage closeRecipient = new ObjControllerMessage(0x0B, endRecipient); + session.write(closeRecipient.serialize()); + } else if (sentPacket.getAccepted() == true && sentPacket.getBuffRecipientAccepted() == 0) { changeMessage.setAccepted(true); changeMessage.setObjectId(buffRecipient.getObjectId()); - + ObjControllerMessage objMsg = new ObjControllerMessage(0x0B, changeMessage); buffRecipient.getClient().getSession().write(objMsg.serialize()); } else { changeMessage.setAccepted(false); changeMessage.setObjectId(sentPacket.getBuffRecipientId()); - + ObjControllerMessage objMsg = new ObjControllerMessage(0x0B, changeMessage); buffRecipient.getClient().getSession().write(objMsg.serialize()); } - + } else { if (sentPacket.getAccepted() == true) { - OkMessage closeMsg = new OkMessage(); - buffer.getClient().getSession().write(closeMsg.serialize()); - giveInspirationBuff(buffRecipient, statBuffs); + BuffBuilderEndMessage endBuilder = new BuffBuilderEndMessage(sentPacket); + endBuilder.setObjectId(buffer.getObjectId()); + + ObjControllerMessage objMsg = new ObjControllerMessage(0x0B, endBuilder); + buffRecipient.getClient().getSession().write(objMsg.serialize()); } } } - + }); } @@ -202,17 +266,21 @@ public class EntertainmentService implements INetworkDispatch { for (int r = 0; r < buffBuilder.getRowCount(); r++) { String skillName = ((String) buffBuilder.getObject(r, 0)); + String category = ((String) buffBuilder.getObject(r, 1)); String statAffects = ((String) buffBuilder.getObject(r, 2)); int maxTimes = ((int) buffBuilder.getObject(r, 3)); + int cost = ((int) buffBuilder.getObject(r, 4)); int affectAmount = ((int) buffBuilder.getObject(r, 5)); - String requiredExperience = ((String) buffBuilder.getObject(r, 6)); + String requiredExpertise = ((String) buffBuilder.getObject(r, 6)); BuffBuilder item = new BuffBuilder(); item.setStatName(skillName); + item.setCategory(category); item.setStatAffects(statAffects); item.setMaxTimesApplied(maxTimes); + item.setCost(cost); item.setAffectAmount(affectAmount); - item.setRequiredExperience(requiredExperience); + item.setRequiredExpertise(requiredExpertise); buffBuilderSkills.add(item); } @@ -235,22 +303,34 @@ public class EntertainmentService implements INetworkDispatch { public void giveInspirationBuff(SWGObject reciever, Vector buffVector) { CreatureObject buffCreature = (CreatureObject) reciever; - Vector availableSkills = buffBuilderSkills; - - Vector buffsToAdd = new Vector(); - + Vector availableStats = buffBuilderSkills; + Vector stats = new Vector(); + for (BuffItem item : buffVector) { - for (BuffBuilder builder : availableSkills) { - if (builder.getStatName().equals(item.getSkillName())) { - builder.setEntBonus(item.getBonusAmount()); - buffsToAdd.add(builder); - Console.println("Added buff item: " + builder.getStatAffects() + " with total affect of " + builder.getTotalAffected() + " and ent bonus of " + builder.getEntBonus()); - continue; + for(BuffBuilder builder : availableStats) { + if(builder.getStatName().equalsIgnoreCase(item.getSkillName())) { + if(builder.getMaxTimesApplied() < item.getInvested()) + return; + + // Ent. Expertise Percent + (invested points * affect amount) = stat + int bonusPoints = (int) (builder.getAffectAmount() *((float) item.getEntertainerBonus()/100f)); + int affectTotal = bonusPoints + (item.getInvested() * builder.getAffectAmount()); + + BuffItem stat = new BuffItem(builder.getStatAffects(), item.getInvested(), item.getEntertainerBonus()); + stat.setAffectAmount(affectTotal); + + /*System.out.println("Invested Points: " + item.getInvested()); + System.out.println("Entertainer Bonus: " + item.getEntertainerBonus()); + System.out.println("Affect Total: " + affectTotal);*/ + + stats.add(stat); + + break; } } } - reciever.setAttachment("buffWorkshop", buffsToAdd); + reciever.setAttachment("buffWorkshop", buffVector); core.buffService.addBuffToCreature(buffCreature, "buildabuff_inspiration"); diff --git a/src/services/chat/ChatService.java b/src/services/chat/ChatService.java index 2bd76a4f..356193c9 100644 --- a/src/services/chat/ChatService.java +++ b/src/services/chat/ChatService.java @@ -553,6 +553,9 @@ public class ChatService implements INetworkDispatch { public SWGObject getObjectByFirstName(String name) { ConcurrentHashMap clients = core.getActiveConnectionsMap(); + if(name.contains(" ")) + name = name.split(" ")[0]; + for(Client client : clients.values()) { if(client.getParent() == null) continue;