From f2b156cb612d3fc3ef63f9c78ece34e139332c70 Mon Sep 17 00:00:00 2001 From: Light2 Date: Wed, 27 Nov 2013 00:11:48 +0100 Subject: [PATCH] Added group buffs --- scripts/buffs/co_position_secured.py | 7 +---- scripts/commands/of_charge_1.py | 3 -- scripts/commands/of_drillmaster_1.py | 3 -- scripts/commands/of_focus_fire_4.py | 3 -- scripts/commands/of_focus_fire_5.py | 3 -- scripts/commands/of_focus_fire_6.py | 3 -- scripts/commands/of_inspiration_1.py | 3 -- scripts/commands/of_inspiration_2.py | 3 -- scripts/commands/of_inspiration_3.py | 3 -- scripts/commands/of_inspiration_4.py | 3 -- scripts/commands/of_inspiration_5.py | 3 -- scripts/commands/of_inspiration_6.py | 3 -- scripts/commands/of_scatter_1.py | 3 -- src/resources/objects/Buff.java | 15 +++++++++- src/services/BuffService.java | 42 ++++++++++++++++++++++++++-- src/services/GroupService.java | 38 +++++++++++++++++++------ 16 files changed, 83 insertions(+), 55 deletions(-) diff --git a/scripts/buffs/co_position_secured.py b/scripts/buffs/co_position_secured.py index b81046bf..e0be4042 100644 --- a/scripts/buffs/co_position_secured.py +++ b/scripts/buffs/co_position_secured.py @@ -18,12 +18,7 @@ def setup(core, actor, buff): core.skillModService.addSkillMod(actor, 'display_only_expertise_critical_hit_reduction', actor.getSkillMod('expertise_co_pos_secured_line_protection').getBase() * 100) if actor.hasSkill('expertise_co_base_of_operations_1'): - if actor.getGroupId() != 0 and core.objectService.getObject(actor.getGroupId()): - group = core.objectService.getObject(actor.getGroupId()) - for member in group.getMemberList(): - core.buffService.addBuffToCreature(member, 'co_base_of_operations') - else: - core.buffService.addBuffToCreature(actor, 'co_base_of_operations') + core.buffService.addBuffToCreature(actor, 'co_base_of_operations') return diff --git a/scripts/commands/of_charge_1.py b/scripts/commands/of_charge_1.py index 8b1194d2..8a1c683d 100644 --- a/scripts/commands/of_charge_1.py +++ b/scripts/commands/of_charge_1.py @@ -5,8 +5,5 @@ def setup(core, actor, buff): def run(core, actor, target, commandString): core.buffService.addBuffToCreature(actor, 'of_charge_1') - group = core.objectService.getObject(actor.getGroupId()) - for creature in group.getMemberList(): - core.buffService.addBuffToCreature(creature, 'of_charge_1') return \ No newline at end of file diff --git a/scripts/commands/of_drillmaster_1.py b/scripts/commands/of_drillmaster_1.py index 313f855b..0b448c2b 100644 --- a/scripts/commands/of_drillmaster_1.py +++ b/scripts/commands/of_drillmaster_1.py @@ -5,8 +5,5 @@ def setup(core, actor, buff): def run(core, actor, target, commandString): core.buffService.addBuffToCreature(actor, 'of_drillmaster_1') - group = core.objectService.getObject(actor.getGroupId()) - for creature in group.getMemberList(): - core.buffService.addBuffToCreature(creature, 'of_drillmaster_1') return \ No newline at end of file diff --git a/scripts/commands/of_focus_fire_4.py b/scripts/commands/of_focus_fire_4.py index 4091e213..a5fa51f9 100644 --- a/scripts/commands/of_focus_fire_4.py +++ b/scripts/commands/of_focus_fire_4.py @@ -5,7 +5,4 @@ def setup(core, actor, buff): def run(core, actor, target, commandString): core.buffService.addBuffToCreature(actor, 'of_focus_fire_1') - group = core.objectService.getObject(actor.getGroupId()) - for creature in group.getMemberList(): - core.buffService.addBuffToCreature(creature, 'of_focus_fire_4') return \ No newline at end of file diff --git a/scripts/commands/of_focus_fire_5.py b/scripts/commands/of_focus_fire_5.py index 704dc3c4..a5fa51f9 100644 --- a/scripts/commands/of_focus_fire_5.py +++ b/scripts/commands/of_focus_fire_5.py @@ -5,7 +5,4 @@ def setup(core, actor, buff): def run(core, actor, target, commandString): core.buffService.addBuffToCreature(actor, 'of_focus_fire_1') - group = core.objectService.getObject(actor.getGroupId()) - for creature in group.getMemberList(): - core.buffService.addBuffToCreature(creature, 'of_focus_fire_5') return \ No newline at end of file diff --git a/scripts/commands/of_focus_fire_6.py b/scripts/commands/of_focus_fire_6.py index 5027e12c..a5fa51f9 100644 --- a/scripts/commands/of_focus_fire_6.py +++ b/scripts/commands/of_focus_fire_6.py @@ -5,7 +5,4 @@ def setup(core, actor, buff): def run(core, actor, target, commandString): core.buffService.addBuffToCreature(actor, 'of_focus_fire_1') - group = core.objectService.getObject(actor.getGroupId()) - for creature in group.getMemberList(): - core.buffService.addBuffToCreature(creature, 'of_focus_fire_6') return \ No newline at end of file diff --git a/scripts/commands/of_inspiration_1.py b/scripts/commands/of_inspiration_1.py index 95c691d9..001b0e69 100644 --- a/scripts/commands/of_inspiration_1.py +++ b/scripts/commands/of_inspiration_1.py @@ -5,8 +5,5 @@ def setup(core, actor, buff): def run(core, actor, target, commandString): core.buffService.addBuffToCreature(actor, 'of_inspiration_1') - group = core.objectService.getObject(actor.getGroupId()) - for creature in group.getMemberList(): - core.buffService.addBuffToCreature(creature, 'of_inspiration_1') return \ No newline at end of file diff --git a/scripts/commands/of_inspiration_2.py b/scripts/commands/of_inspiration_2.py index f667ecd4..01dbef43 100644 --- a/scripts/commands/of_inspiration_2.py +++ b/scripts/commands/of_inspiration_2.py @@ -5,8 +5,5 @@ def setup(core, actor, buff): def run(core, actor, target, commandString): core.buffService.addBuffToCreature(actor, 'of_inspiration_2') - group = core.objectService.getObject(actor.getGroupId()) - for creature in group.getMemberList(): - core.buffService.addBuffToCreature(creature, 'of_inspiration_2') return \ No newline at end of file diff --git a/scripts/commands/of_inspiration_3.py b/scripts/commands/of_inspiration_3.py index ce4e0b49..a1d2296f 100644 --- a/scripts/commands/of_inspiration_3.py +++ b/scripts/commands/of_inspiration_3.py @@ -5,8 +5,5 @@ def setup(core, actor, buff): def run(core, actor, target, commandString): core.buffService.addBuffToCreature(actor, 'of_inspiration_3') - group = core.objectService.getObject(actor.getGroupId()) - for creature in group.getMemberList(): - core.buffService.addBuffToCreature(creature, 'of_inspiration_3') return \ No newline at end of file diff --git a/scripts/commands/of_inspiration_4.py b/scripts/commands/of_inspiration_4.py index 198e36b5..d1954310 100644 --- a/scripts/commands/of_inspiration_4.py +++ b/scripts/commands/of_inspiration_4.py @@ -5,8 +5,5 @@ def setup(core, actor, buff): def run(core, actor, target, commandString): core.buffService.addBuffToCreature(actor, 'of_inspiration_4') - group = core.objectService.getObject(actor.getGroupId()) - for creature in group.getMemberList(): - core.buffService.addBuffToCreature(creature, 'of_inspiration_4') return \ No newline at end of file diff --git a/scripts/commands/of_inspiration_5.py b/scripts/commands/of_inspiration_5.py index e114bec1..e2d35933 100644 --- a/scripts/commands/of_inspiration_5.py +++ b/scripts/commands/of_inspiration_5.py @@ -5,8 +5,5 @@ def setup(core, actor, buff): def run(core, actor, target, commandString): core.buffService.addBuffToCreature(actor, 'of_inspiration_5') - group = core.objectService.getObject(actor.getGroupId()) - for creature in group.getMemberList(): - core.buffService.addBuffToCreature(creature, 'of_inspiration_5') return \ No newline at end of file diff --git a/scripts/commands/of_inspiration_6.py b/scripts/commands/of_inspiration_6.py index 230aaa5f..c73a2000 100644 --- a/scripts/commands/of_inspiration_6.py +++ b/scripts/commands/of_inspiration_6.py @@ -5,8 +5,5 @@ def setup(core, actor, buff): def run(core, actor, target, commandString): core.buffService.addBuffToCreature(actor, 'of_inspiration_6') - group = core.objectService.getObject(actor.getGroupId()) - for creature in group.getMemberList(): - core.buffService.addBuffToCreature(creature, 'of_inspiration_6') return \ No newline at end of file diff --git a/scripts/commands/of_scatter_1.py b/scripts/commands/of_scatter_1.py index c1ae742a..8ee17071 100644 --- a/scripts/commands/of_scatter_1.py +++ b/scripts/commands/of_scatter_1.py @@ -5,8 +5,5 @@ def setup(core, actor, buff): def run(core, actor, target, commandString): core.buffService.addBuffToCreature(actor, 'of_scatter_1') - group = core.objectService.getObject(actor.getGroupId()) - for creature in group.getMemberList(): - core.buffService.addBuffToCreature(creature, 'of_scatter_1') return \ No newline at end of file diff --git a/src/resources/objects/Buff.java b/src/resources/objects/Buff.java index 16fb49f3..db19f967 100644 --- a/src/resources/objects/Buff.java +++ b/src/resources/objects/Buff.java @@ -41,7 +41,7 @@ import engine.clientdata.ClientFileManager; import engine.clientdata.visitors.DatatableVisitor; import engine.resources.common.CRC; -@Persistent(version=6) +@Persistent(version=7) public class Buff implements IListObject { @NotPersistent @@ -68,6 +68,7 @@ public class Buff implements IListObject { @NotPersistent private ScheduledFuture removalTask; private int stacks = 1; + private long groupBufferId; public Buff(String buffName, long ownerId) { @@ -417,5 +418,17 @@ public class Buff implements IListObject { public void setStacks(int stacks) { this.stacks = stacks; } + + public boolean isGroupBuff() { + return effect1Name.equals("group"); + } + + public long getGroupBufferId() { + return groupBufferId; + } + + public void setGroupBufferId(long groupBufferId) { + this.groupBufferId = groupBufferId; + } } diff --git a/src/services/BuffService.java b/src/services/BuffService.java index 50de0f71..c5db3a8e 100644 --- a/src/services/BuffService.java +++ b/src/services/BuffService.java @@ -52,6 +52,7 @@ import resources.objects.Buff; import resources.objects.BuffItem; import resources.objects.DamageOverTime; import resources.objects.creature.CreatureObject; +import resources.objects.group.GroupObject; import resources.objects.player.PlayerObject; import main.NGECore; import engine.clients.Client; @@ -85,6 +86,16 @@ public class BuffService implements INetworkDispatch { return; }*/ + final Buff buff = new Buff(buffName, creature.getObjectID()); + if(buff.isGroupBuff()) { + addGroupBuff(creature, buffName); + } else { + doAddBuff(creature, buffName); + } + } + + public Buff doAddBuff(final CreatureObject creature, String buffName) { + final Buff buff = new Buff(buffName, creature.getObjectID()); buff.setTotalPlayTime(((PlayerObject) creature.getSlottedObject("ghost")).getTotalPlayTime()); @@ -103,7 +114,7 @@ public class BuffService implements INetworkDispatch { } if (otherBuff.getRemainingDuration() > buff.getDuration() && otherBuff.getStacks() >= otherBuff.getMaxStacks()) { - return; + return null; } } @@ -111,7 +122,7 @@ public class BuffService implements INetworkDispatch { break; } else { System.out.println("buff not added:" + buffName); - return; + return null; } } @@ -138,6 +149,8 @@ public class BuffService implements INetworkDispatch { } + return buff; + } public void removeBuffFromCreature(CreatureObject creature, Buff buff) { @@ -163,6 +176,11 @@ public class BuffService implements INetworkDispatch { for(final Buff buff : creature.getBuffList().get().toArray(new Buff[] { })) { if (buff.getGroup1().startsWith("setBonus")) { continue; } + + if(buff.isGroupBuff() && buff.getGroupBufferId() != creature.getObjectID()) { + removeBuffFromCreature(creature, buff); + continue; + } if(buff.getRemainingDuration() > 0 && buff.getDuration() > 0) { ScheduledFuture task = scheduler.schedule(new Runnable() { @@ -185,6 +203,24 @@ public class BuffService implements INetworkDispatch { } - + public void addGroupBuff(final CreatureObject buffer, String buffName) { + + if(buffer.getGroupId() == 0) { + doAddBuff(buffer, buffName); + return; + } + + GroupObject group = (GroupObject) core.objectService.getObject(buffer.getGroupId()); + + if(group == null) { + doAddBuff(buffer, buffName); + return; + } + + for(SWGObject member : group.getMemberList()) { + Buff buff = doAddBuff((CreatureObject) member, buffName); + buff.setGroupBufferId(buffer.getObjectID()); + } + } } diff --git a/src/services/GroupService.java b/src/services/GroupService.java index 092648a8..86258f15 100644 --- a/src/services/GroupService.java +++ b/src/services/GroupService.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import resources.objects.Buff; import resources.objects.creature.CreatureObject; import resources.objects.group.GroupObject; @@ -150,6 +151,8 @@ public class GroupService implements INetworkDispatch { leader.setGroupId(group.getObjectID()); invited.makeAware(group); invited.setGroupId(group.getObjectID()); + addGroupBuffsToMember(group, leader); + addGroupBuffsToMember(group, invited); return; } @@ -162,6 +165,7 @@ public class GroupService implements INetworkDispatch { invited.makeAware(group); invited.setGroupId(group.getObjectID()); invited.sendSystemMessage("@group:joined_self", (byte) 0); + addGroupBuffsToMember(group, invited); } else if(group.getMemberList().size() >= 8) { @@ -175,10 +179,33 @@ public class GroupService implements INetworkDispatch { } + } + + public void addGroupBuffsToMember(GroupObject group, CreatureObject member) { + // loop until we find a member other than ourself + for(SWGObject otherMember : group.getMemberList()) { + if(otherMember != member) { + for(Buff buff : ((CreatureObject) otherMember).getBuffList().get()) { + if(buff.isGroupBuff()) { + Buff newBuff = core.buffService.doAddBuff(member, buff.getBuffName()); + newBuff.setGroupBufferId(buff.getGroupBufferId()); + } + } + return; + } + } } + public void removeGroupBuffs(CreatureObject member) { + for(Buff buff : member.getBuffList().get()) { + if(buff.isGroupBuff() && buff.getGroupBufferId() != member.getObjectID()) { + core.buffService.removeBuffFromCreature(member, buff); + } + } + } + public void handleGroupDisband(CreatureObject creature) { if(creature.getGroupId() == 0) @@ -209,11 +236,7 @@ public class GroupService implements INetworkDispatch { } - // Remove group buffs - - if(creature.hasBuff("co_base_of_operations")) - core.buffService.removeBuffFromCreature(creature, creature.getBuffByName("co_base_of_operations")); - + removeGroupBuffs(creature); } else { @@ -231,11 +254,8 @@ public class GroupService implements INetworkDispatch { creature2.sendSystemMessage("The group has been disbanded.", (byte) 0); - // Remove group buffs + removeGroupBuffs((CreatureObject) member); - if(creature2.hasBuff("co_base_of_operations")) - core.buffService.removeBuffFromCreature(creature2, creature2.getBuffByName("co_base_of_operations")); - } core.objectService.destroyObject(group.getObjectID());