Moved cooldowns to TangibleObject

This commit is contained in:
Treeku
2014-08-25 21:35:38 +01:00
parent 1dd7d712a3
commit 727e679ebb
@@ -32,6 +32,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.mina.core.buffer.IoBuffer;
@@ -41,6 +42,7 @@ import protocol.swg.PlayClientEffectObjectMessage;
import protocol.swg.StopClientEffectObjectByLabel;
import protocol.swg.UpdatePVPStatusMessage;
import protocol.swg.objectControllerObjects.ShowFlyText;
import protocol.swg.objectControllerObjects.StartTask;
import resources.common.OutOfBand;
import resources.datatables.Options;
import resources.datatables.PvpStatus;
@@ -49,6 +51,7 @@ import resources.objects.ObjectMessageBuilder;
import resources.objects.SWGList;
import resources.objects.SWGSet;
import resources.objects.creature.CreatureObject;
import services.command.BaseSWGCommand;
import engine.clientdata.ClientFileManager;
import engine.clientdata.visitors.IDManagerVisitor;
import engine.clients.Client;
@@ -73,7 +76,6 @@ public class TangibleObject extends SWGObject implements Serializable {
private transient int pvpBitmask = 0;
//private TreeSet<TreeMap<String,Integer>> lootSpecification = new TreeSet<TreeMap<String,Integer>>();
private transient List<LootGroup> lootGroups = new ArrayList<LootGroup>();
private transient boolean looted = false;
private transient boolean lootLock = false;
@@ -81,6 +83,8 @@ public class TangibleObject extends SWGObject implements Serializable {
private transient boolean lootItem = false;
private transient TangibleObject killer = null;
private transient ConcurrentHashMap<String, Long> cooldowns = new ConcurrentHashMap<String, Long>();
public TangibleObject(long objectID, Planet planet, Point3D position, Quaternion orientation, String template) {
super(objectID, planet, position, orientation, template);
if (this.getClass().getSimpleName().equals("TangibleObject")) setIntAttribute("volume", 1);
@@ -419,7 +423,7 @@ public class TangibleObject extends SWGObject implements Serializable {
}
}
public boolean isAttackableBy(CreatureObject attacker) {
public boolean isAttackableBy(TangibleObject attacker) {
int pvpStatus = NGECore.getInstance().factionService.calculatePvpStatus(attacker, this);
return (((pvpStatus & PvpStatus.Attackable) == PvpStatus.Attackable) || ((pvpStatus & PvpStatus.Aggressive) == PvpStatus.Aggressive));
}
@@ -608,9 +612,52 @@ public class TangibleObject extends SWGObject implements Serializable {
return false;
}
public void addCooldown(String cooldownGroup, float cooldownTime) {
if (cooldowns.containsKey(cooldownGroup)) {
cooldowns.remove(cooldownGroup);
}
long duration = System.currentTimeMillis() + ((long) (cooldownTime * 1000F));
cooldowns.put(cooldownGroup, duration);
}
public boolean hasCooldown(String cooldownGroup) {
if (cooldowns.containsKey(cooldownGroup)) {
if (System.currentTimeMillis() < cooldowns.get(cooldownGroup)) {
return true;
} else {
cooldowns.remove(cooldownGroup);
}
}
return false;
}
public boolean removeCooldown(int actionCounter, BaseSWGCommand command) {
if (cooldowns.containsKey(command.getCooldownGroup())) {
cooldowns.remove(command.getCooldownGroup());
getClient().getSession().write(new ObjControllerMessage(0x0B, new StartTask(actionCounter, getObjectID(), command.getCommandCRC(), CRC.StringtoCRC(command.getCooldownGroup()), -1)).serialize());
return true;
}
return false;
}
public long getRemainingCooldown(String cooldownGroup) {
if (cooldowns.containsKey(cooldownGroup)) {
if (System.currentTimeMillis() < cooldowns.get(cooldownGroup)) {
return (long) (cooldowns.get(cooldownGroup) - System.currentTimeMillis());
} else {
cooldowns.remove(cooldownGroup);
}
}
return 0L;
}
public void notifyClients(IoBuffer buffer, boolean notifySelf) {
// notifyObservers(buffer, false); // ??? Ignores the notifySelf argument. Was this done purposely? Faction Status etc. can't update the client without it
notifyObservers(buffer, notifySelf);
notifyObservers(buffer, false);
}
public ObjectMessageBuilder getMessageBuilder() {
@@ -623,26 +670,9 @@ public class TangibleObject extends SWGObject implements Serializable {
}
}
@Override
public void sendBaselines(Client destination) {
if (destination != null && destination.getSession() != null) {
// Factional peculiarities
Baseline baseLine3 = getBaseline(3);
if (destination.getParent() instanceof CreatureObject){
if (((CreatureObject) destination.getParent()).isPlayer() && ((CreatureObject) destination.getParent()).getFaction()!=this.getFaction()){
int optionsBitMask = getOptionsBitmask();
if (getOption(Options.QUEST))
optionsBitMask = optionsBitMask & ~Options.QUEST;
if (!getOption(Options.ATTACKABLE))
optionsBitMask = optionsBitMask | Options.ATTACKABLE;
baseLine3.set("optionsBitmask", optionsBitMask);
}
}
//destination.getSession().write(getBaseline(3).getBaseline());
destination.getSession().write(baseLine3.getBaseline());
destination.getSession().write(getBaseline(3).getBaseline());
destination.getSession().write(getBaseline(6).getBaseline());
Client parent = ((getGrandparent() == null) ? null : getGrandparent().getClient());
@@ -655,18 +685,12 @@ public class TangibleObject extends SWGObject implements Serializable {
if (destination.getParent() != this) {
UpdatePVPStatusMessage upvpm = new UpdatePVPStatusMessage(getObjectID());
upvpm.setFaction(CRC.StringtoCRC(getFaction()));
// if (this.getTemplate().contains("barricade")){
// System.out.println("BARTANO RESULT " + NGECore.getInstance().factionService.calculatePvpStatus((CreatureObject) destination.getParent(), this));
// }
upvpm.setStatus(NGECore.getInstance().factionService.calculatePvpStatus((CreatureObject) destination.getParent(), this));
destination.getSession().write(upvpm.serialize());
}
}
}
public void sendListDelta(byte viewType, short updateType, IoBuffer buffer) {
switch (viewType) {
case 3: