diff --git a/scripts/commands/pvp.py b/scripts/commands/pvp.py index a42ea0dd..7750b2e6 100644 --- a/scripts/commands/pvp.py +++ b/scripts/commands/pvp.py @@ -31,16 +31,14 @@ def run(core, actor, target, commandString): actor.setFaction('') actor.sendSystemMessage('@faction_recruiter:resign_complete', 0) - if commandString == 'neutral': + if commandString == 'neutral' or commandString == 'resign': time.sleep(1) actor.setFaction('') - actor.setPvpStatus(PvpStatus.Player, False) actor.sendSystemMessage('@faction_recruiter:resign_complete', 0) return time.sleep(1) actor.setFaction(commandString) - actor.setPvpStatus(PvpStatus.Player, True) return if faction == 'neutral' or faction == '': @@ -53,7 +51,6 @@ def run(core, actor, target, commandString): time.sleep(1) actor.setFactionStatus(FactionStatus.Combatant) actor.setPvpStatus(PvpStatus.GoingCovert, False) - actor.setPvpStatus(PvpStatus.Enemy, True) actor.sendSystemMessage('@faction_recruiter:covert_complete', 0) return @@ -63,7 +60,6 @@ def run(core, actor, target, commandString): time.sleep(30) actor.setFactionStatus(FactionStatus.SpecialForces) actor.setPvpStatus(PvpStatus.GoingOvert, False) - actor.setPvpStatus(PvpStatus.Overt | PvpStatus.Attackable | PvpStatus.Aggressive, True) actor.sendSystemMessage('@faction_recruiter:overt_complete', 0) return @@ -72,7 +68,7 @@ def run(core, actor, target, commandString): actor.setPvpStatus(PvpStatus.GoingCovert, True) time.sleep(300) actor.setFactionStatus(FactionStatus.Combatant) - actor.setPvpStatus(PvpStatus.GoingCovert | PvpStatus.Overt | PvpStatus.Attackable | PvpStatus.Aggressive, False) + actor.setPvpStatus(PvpStatus.GoingCovert, False) actor.sendSystemMessage('@faction_recruiter:covert_complete', 0) return diff --git a/src/resources/objects/creature/CreatureObject.java b/src/resources/objects/creature/CreatureObject.java index ecf161ef..c615d628 100644 --- a/src/resources/objects/creature/CreatureObject.java +++ b/src/resources/objects/creature/CreatureObject.java @@ -458,7 +458,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { } notifyObservers(messageBuilder.buildFactionDelta(faction), true); - setPvpStatus(0, true); + updatePvpStatus(); } public int getFactionStatus() { @@ -473,6 +473,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { } notifyObservers(messageBuilder.buildFactionStatusDelta(factionStatus), true); + updatePvpStatus(); } public float getHeight() { diff --git a/src/resources/objects/tangible/TangibleObject.java b/src/resources/objects/tangible/TangibleObject.java index 9207eed0..de8bf1d3 100644 --- a/src/resources/objects/tangible/TangibleObject.java +++ b/src/resources/objects/tangible/TangibleObject.java @@ -22,10 +22,14 @@ package resources.objects.tangible; import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.Vector; +import main.NGECore; + import protocol.swg.ObjControllerMessage; import protocol.swg.PlayClientEffectObjectMessage; import protocol.swg.StopClientEffectObjectByLabel; @@ -58,7 +62,7 @@ public class TangibleObject extends SWGObject { protected int optionsBitmask = 0; private int maxDamage = 1000; private boolean staticObject = true; - protected String faction = "neutral"; // Says you're "Imperial Special Forces" if it's 0 for some reason + protected String faction = ""; // Says you're "Imperial Special Forces" if it's 0 for some reason @NotPersistent private Vector defendersList = new Vector(); // unused in packets but useful for the server @NotPersistent @@ -218,6 +222,20 @@ public class TangibleObject extends SWGObject { } } } + + updatePvpStatus(); + } + + public void updatePvpStatus() { + HashSet observers = new HashSet(getObservers()); + + for (Iterator it = observers.iterator(); it.hasNext();) { + Client observer = it.next(); + + if (observer.getParent() != null) { + observer.getSession().write(new UpdatePVPStatusMessage(this.getObjectID(), NGECore.getInstance().factionService.calculatePvpStatus(observer, this), getFaction()).serialize()); + } + } } public String getFaction() { @@ -230,6 +248,8 @@ public class TangibleObject extends SWGObject { synchronized(objectMutex) { this.faction = faction; } + + updatePvpStatus(); } public Vector getDefendersList() { diff --git a/src/services/combat/CombatService.java b/src/services/combat/CombatService.java index eb815e7a..d274194d 100644 --- a/src/services/combat/CombatService.java +++ b/src/services/combat/CombatService.java @@ -1005,8 +1005,8 @@ public class CombatService implements INetworkDispatch { requester.getDuelList().add(target); requester.sendSystemMessage("You accept " + target.getCustomName() + "'s challenge.", (byte) 0); target.sendSystemMessage(requester.getCustomName() + " accepts your challenge.", (byte) 0); - target.getClient().getSession().write(new UpdatePVPStatusMessage(requester.getObjectID(), 55, requester.getFaction()).serialize()); - requester.getClient().getSession().write(new UpdatePVPStatusMessage(target.getObjectID(), 55, target.getFaction()).serialize()); + target.updatePvpStatus(); + requester.updatePvpStatus(); } @@ -1021,8 +1021,8 @@ public class CombatService implements INetworkDispatch { target.removeDefender(requester); requester.removeDefender(target); - target.getClient().getSession().write(new UpdatePVPStatusMessage(requester.getObjectID(), 0x16, requester.getFaction()).serialize()); - requester.getClient().getSession().write(new UpdatePVPStatusMessage(target.getObjectID(), 0x16, target.getFaction()).serialize()); + target.updatePvpStatus(); + requester.updatePvpStatus(); if(announce) { diff --git a/src/services/gcw/FactionService.java b/src/services/gcw/FactionService.java index 5f985b54..f774e934 100644 --- a/src/services/gcw/FactionService.java +++ b/src/services/gcw/FactionService.java @@ -203,18 +203,36 @@ public class FactionService implements INetworkDispatch { int pvpBitmask = target.getPvPBitmask(); - if (target.getSlottedObject("ghost") != null) { - if (target.getFaction() == null || (!target.getFaction().equals("rebel") && !target.getFaction().equals("imperial"))) { - return 0; - } + if (target.getFactionStatus() == FactionStatus.Combatant) { + pvpBitmask |= PvpStatus.Enemy; + } + + if (target.getFactionStatus() == FactionStatus.SpecialForces) { + pvpBitmask |= PvpStatus.Overt; + if (target.getSlottedObject("ghost") != null) { + pvpBitmask |= PvpStatus.Enemy; + } + } + + if (target.getSlottedObject("ghost") != null) { pvpBitmask |= PvpStatus.Player; - if (player.getFactionStatus() == FactionStatus.SpecialForces && - ((CreatureObject) target).getFactionStatus() == FactionStatus.SpecialForces) { + if ((!player.getFaction().equals(target.getFaction()) && + player.getFactionStatus() == FactionStatus.SpecialForces && + ((CreatureObject) target).getFactionStatus() == FactionStatus.SpecialForces) || + core.combatService.areInDuel(player, (CreatureObject) target)) { pvpBitmask |= (PvpStatus.Attackable | PvpStatus.Aggressive); } + if (core.combatService.areInDuel(player, (CreatureObject) target)) { + //pvpBitmask |= PvpStatus.Dueling; + } + + return pvpBitmask; + } + + if (player.getFaction().equals(target.getFaction()) { return pvpBitmask; } diff --git a/src/services/object/DuplicateId.java b/src/services/object/DuplicateId.java index 57b52cea..db618527 100644 --- a/src/services/object/DuplicateId.java +++ b/src/services/object/DuplicateId.java @@ -1,3 +1,24 @@ +/******************************************************************************* + * 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 services.object; import com.sleepycat.persist.model.Entity;