diff --git a/.gitignore b/.gitignore index a4f49551..e9956083 100644 --- a/.gitignore +++ b/.gitignore @@ -47,6 +47,7 @@ clientdata/ # SWG Client Folders footprint/ interiorlayout/ +clientdata/quest/ # External tool builders .externalToolBuilders/ diff --git a/README.md b/README.md index c138cb9e..24abfa1e 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ Then export the following folders to your clientdata folder(should be located in - object - quest - snapshot +- string - terrain Export the same folders from sku1_client.toc, sku2_client.toc and sku3_client.toc to avoid errors with kashyyyk. diff --git a/options.cfg b/options.cfg index 6b6462d7..4f6d91ad 100644 --- a/options.cfg +++ b/options.cfg @@ -1 +1,2 @@ LOAD.SNAPSHOT_OBJECTS=1 +LOAD.BUILDOUT_OBJECTS=1 \ No newline at end of file diff --git a/scripts/commands/waypoint.py b/scripts/commands/waypoint.py index 029fe3ad..fddb0508 100644 --- a/scripts/commands/waypoint.py +++ b/scripts/commands/waypoint.py @@ -28,7 +28,7 @@ def run(core, actor, target, commandString): waypoint.setPlanetCRC(crc.StringtoCRC(planet.getName())) actorPlayer.getWaypoints().add(waypoint) actorPlayer.waypointAdd(waypoint) - actor.sendSystemMessage('A waypoint has been created in your datapad at your location.', 0) + actor.sendSystemMessage('A waypoint has been created in your datapad at the location.', 0) return @@ -42,7 +42,7 @@ def run(core, actor, target, commandString): waypoint.setPlanetCRC(crc.StringtoCRC(actor.getPlanet().getName())) actorPlayer.getWaypoints().add(waypoint) actorPlayer.waypointAdd(waypoint) - actor.sendSystemMessage('A waypoint has been created in your datapad at your location.', 0) + actor.sendSystemMessage('A waypoint has been created in your datapad at the location.', 0) return #/wp X Z Name elif len(commandArgs) >= 3 and isFloat(commandArgs[0]) and isFloat(commandArgs[1]): @@ -54,7 +54,7 @@ def run(core, actor, target, commandString): waypoint.setPlanetCRC(crc.StringtoCRC(actor.getPlanet().getName())) actorPlayer.getWaypoints().add(waypoint) actorPlayer.waypointAdd(waypoint) - actor.sendSystemMessage('A waypoint has been created in your datapad at your location.', 0) + actor.sendSystemMessage('A waypoint has been created in your datapad at the location.', 0) return #/wp X Z elif len(commandArgs) >= 2 and isFloat(commandArgs[0]) and isFloat(commandArgs[1]): @@ -65,7 +65,7 @@ def run(core, actor, target, commandString): waypoint.setPlanetCRC(crc.StringtoCRC(actor.getPlanet().getName())) actorPlayer.getWaypoints().add(waypoint) actorPlayer.waypointAdd(waypoint) - actor.sendSystemMessage('A waypoint has been created in your datapad at your location.', 0) + actor.sendSystemMessage('A waypoint has been created in your datapad at the location.', 0) return #/wp planet x z y name @@ -81,7 +81,7 @@ def run(core, actor, target, commandString): waypoint.setPlanetCRC(crc.StringtoCRC(actor.getPlanet().getName())) actorPlayer.getWaypoints().add(waypoint) actorPlayer.waypointAdd(waypoint) - actor.sendSystemMessage('A waypoint has been created in your datapad at your location.', 0) + actor.sendSystemMessage('A waypoint has been created in your datapad at the location.', 0) return #/wp NAME diff --git a/src/resources/common/AString.java b/src/resources/common/AString.java new file mode 100644 index 00000000..1a9f73f2 --- /dev/null +++ b/src/resources/common/AString.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * 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; + +import java.nio.ByteOrder; + +import org.apache.mina.core.buffer.IoBuffer; + +import com.sleepycat.persist.model.Persistent; + +import resources.objects.Delta; + +@Persistent +public final class AString extends Delta { + + private String string; + + public AString() { + string = ""; + } + + public AString(String string) { + this.string = ((string == null) ? "" : string); + } + + public String get() { + synchronized(objectMutex) { + return string; + } + } + + public void set(String string) { + synchronized(objectMutex) { + this.string = string; + } + } + + public short length() { + synchronized(objectMutex) { + return (short) string.length(); + } + } + + public byte[] getBytes() { + synchronized(objectMutex) { + return IoBuffer.allocate(2 + string.length(), false).order(ByteOrder.LITTLE_ENDIAN).putShort((short) string.length()).put(string.getBytes()).flip().array(); + } + } + +} diff --git a/src/resources/common/Opcodes.java b/src/resources/common/Opcodes.java index 5d03db30..fce03203 100644 --- a/src/resources/common/Opcodes.java +++ b/src/resources/common/Opcodes.java @@ -46,7 +46,8 @@ public class Opcodes { public static int RequestGalaxyLoopTimes = 0x7D842D68; public static int SelectCharacter = 0xB5098D76; public static int SuiEventNotification = 0x092D3564; - public static int DeltasMessage = 0x12862153; + public static int BaselinesMessage = CRC.StringtoCRC("BaselinesMessage"); + public static int DeltasMessage = CRC.StringtoCRC("DeltasMessage"); public static int ChatAddFriend = 0x6FE7BD90; public static int GcwRegionsReq = CRC.StringtoCRC("GcwRegionsReq"); public static int GcwRegionsRsp = CRC.StringtoCRC("GcwRegionsRsp"); diff --git a/src/resources/common/Stf.java b/src/resources/common/Stf.java new file mode 100644 index 00000000..191b2a60 --- /dev/null +++ b/src/resources/common/Stf.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * 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; + +import org.apache.mina.core.buffer.IoBuffer; + +import resources.z.exp.objects.Baseline; +import resources.objects.Delta; + +import com.sleepycat.persist.model.Persistent; + +@Persistent +public class Stf extends Delta { + + private AString stfFilename; + private int spacer = 0; + private AString stfName; + + public Stf(String stfFilename, int spacer, String stfName) { + this.stfFilename = new AString(stfFilename); + this.spacer = spacer; + this.stfName = new AString(stfName); + } + + public Stf() { + + } + + public String getStfFilename() { + synchronized(objectMutex) { + return stfFilename.get(); + } + } + + public void setStfFilename(String stfFilename) { + synchronized(objectMutex) { + this.stfFilename = new AString(stfFilename); + } + } + + public int getSpacer() { + synchronized(objectMutex) { + return spacer; + } + } + + public void setSpacer(int spacer) { + synchronized(objectMutex) { + this.spacer = spacer; + } + } + + public String getStfName() { + synchronized(objectMutex) { + return stfName.get(); + } + } + + public void setStfName(String stfName) { + synchronized(objectMutex) { + this.stfName = new AString(stfName); + } + } + + public byte[] getBytes() { + synchronized(objectMutex) { + int size = stfFilename.getBytes().length + 4 + stfName.getBytes().length; + + IoBuffer buffer = Baseline.createBuffer(size); + buffer.put(stfFilename.getBytes()); + buffer.putInt(spacer); + buffer.put(stfName.getBytes()); + buffer.flip(); + + return buffer.array(); + } + } + +} diff --git a/src/resources/common/UString.java b/src/resources/common/UString.java new file mode 100644 index 00000000..5aa290dc --- /dev/null +++ b/src/resources/common/UString.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * 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; + +import java.io.UnsupportedEncodingException; +import java.nio.ByteOrder; + +import org.apache.mina.core.buffer.IoBuffer; + +import com.sleepycat.persist.model.Persistent; + +import resources.objects.Delta; + +@Persistent +public final class UString extends Delta { + + private String string; + + public UString() { + string = ""; + } + + public UString(String string) { + this.string = ((string == null) ? "" : string); + } + + public String get() { + synchronized(objectMutex) { + return string; + } + } + + public void set(String string) { + synchronized(objectMutex) { + this.string = string; + } + } + + public int length() { + synchronized(objectMutex) { + return string.length(); + } + } + + public byte[] getBytes() { + synchronized(objectMutex) { + try { + return IoBuffer.allocate(4 + string.length(), false).order(ByteOrder.LITTLE_ENDIAN).putInt(string.length()).put(string.getBytes("UTF-16LE")).flip().array(); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + return new byte[] { 0x00, 0x00, 0x00, 0x00 }; + } + } + } + +} diff --git a/src/resources/datatables/FactionStatus.java b/src/resources/datatables/FactionStatus.java index 7ab5ffdd..2cae4212 100644 --- a/src/resources/datatables/FactionStatus.java +++ b/src/resources/datatables/FactionStatus.java @@ -23,8 +23,8 @@ package resources.datatables; public class FactionStatus { - public static int OnLeave = 0; - public static int Combatant = 1; - public static int SpecialForces = 2; + public static final int OnLeave = 0; + public static final int Combatant = 1; + public static final int SpecialForces = 2; } diff --git a/src/resources/z/exp/buffs/Buff.java b/src/resources/z/exp/buffs/Buff.java new file mode 100644 index 00000000..dc6259d6 --- /dev/null +++ b/src/resources/z/exp/buffs/Buff.java @@ -0,0 +1,324 @@ +/******************************************************************************* + * 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.z.exp.buffs; + +import java.nio.ByteOrder; + +import org.apache.mina.core.buffer.IoBuffer; +import org.apache.mina.core.buffer.SimpleBufferAllocator; + +import resources.objects.IDelta; + +import com.sleepycat.persist.model.NotPersistent; +import com.sleepycat.persist.model.Persistent; + +import engine.clientdata.ClientFileManager; +import engine.clientdata.visitors.DatatableVisitor; + +@Persistent(version=3) +public class Buff implements IDelta { + + @NotPersistent + private SimpleBufferAllocator bufferPool = new SimpleBufferAllocator(); + private float duration; + private String buffName; + private long ownerId; + private String effect1Name, effect2Name, effect3Name, effect4Name, effect5Name; + private float effect1Value, effect2Value, effect3Value, effect4Value, effect5Value; + private String particleEffect; + private boolean isDebuff; + private boolean removeOnDeath; + private boolean isRemovableByPlayer; + private int maxStacks; + private boolean isPersistent; + private boolean removeOnRespec; + private boolean aiRemoveOnEndCombat; + private boolean decayOnPvPDeath; + private long startTime; + private int totalPlayTime; + + public Buff(String buffName, long ownerId) { + this.buffName = buffName; + this.ownerId = ownerId; + + DatatableVisitor visitor; + + try { + + visitor = ClientFileManager.loadFile("datatables/buff/buff.iff", DatatableVisitor.class); + + for (int i = 0; i < visitor.getRowCount(); i++) { + + if (visitor.getObject(i, 0) != null) { + + if (((String) visitor.getObject(i, 0)).equalsIgnoreCase(buffName)) { + + duration = (Float) visitor.getObject(i, 6); + effect1Name = (String) visitor.getObject(i, 7); + effect1Value = (Float) visitor.getObject(i, 8); + effect2Name = (String) visitor.getObject(i, 9); + effect2Value = (Float) visitor.getObject(i, 10); + effect3Name = (String) visitor.getObject(i, 11); + effect3Value = (Float) visitor.getObject(i, 12); + effect4Name = (String) visitor.getObject(i, 13); + effect4Value = (Float) visitor.getObject(i, 14); + effect5Name = (String) visitor.getObject(i, 15); + effect5Value = (Float) visitor.getObject(i, 16); + particleEffect = (String) visitor.getObject(i, 19); + isDebuff = (Boolean) visitor.getObject(i, 22); + removeOnDeath = (Integer) visitor.getObject(i, 25) != 0; + isRemovableByPlayer = (Integer) visitor.getObject(i, 26) != 0; + maxStacks = (Integer) visitor.getObject(i, 28); + isPersistent = (Integer) visitor.getObject(i, 29) != 0; + removeOnRespec = (Integer) visitor.getObject(i, 31) != 0; + aiRemoveOnEndCombat = (Integer) visitor.getObject(i, 32) != 0; + decayOnPvPDeath = (Integer) visitor.getObject(i, 33) != 0; + + } + + } + + } + + } catch (InstantiationException | IllegalAccessException e) { + e.printStackTrace(); + } + } + + public Buff() { + + } + + public byte[] getBytes() { + IoBuffer buffer = bufferPool.allocate(28, false).order(ByteOrder.LITTLE_ENDIAN); + if (duration > 0) { + buffer.putInt((int) (totalPlayTime + getRemainingDuration())); + buffer.putInt(0); + buffer.putInt((int) duration); + } else { + buffer.putInt(-1); + buffer.putInt(0); + buffer.putInt(-1); + } + buffer.putLong(ownerId); + buffer.putInt(1); // Unknown + buffer.flip(); + return buffer.array(); + } + + public float getDuration() { + return duration; + } + + public void setDuration(float duration) { + this.duration = duration; + } + + public String getBuffName() { + return buffName; + } + + public void setBuffName(String buffName) { + this.buffName = buffName; + } + + public long getOwnerId() { + return ownerId; + } + + public void setOwnerId(long ownerId) { + this.ownerId = ownerId; + } + + public String getEffect1Name() { + return effect1Name; + } + + public void setEffect1Name(String effect1Name) { + this.effect1Name = effect1Name; + } + + public String getEffect2Name() { + return effect2Name; + } + + public void setEffect2Name(String effect2Name) { + this.effect2Name = effect2Name; + } + + public String getEffect3Name() { + return effect3Name; + } + + public void setEffect3Name(String effect3Name) { + this.effect3Name = effect3Name; + } + + public String getEffect4Name() { + return effect4Name; + } + + public void setEffect4Name(String effect4Name) { + this.effect4Name = effect4Name; + } + + public String getEffect5Name() { + return effect5Name; + } + + public void setEffect5Name(String effect5Name) { + this.effect5Name = effect5Name; + } + + public float getEffect1Value() { + return effect1Value; + } + + public void setEffect1Value(float effect1Value) { + this.effect1Value = effect1Value; + } + + public float getEffect2Value() { + return effect2Value; + } + + public void setEffect2Value(float effect2Value) { + this.effect2Value = effect2Value; + } + + public float getEffect3Value() { + return effect3Value; + } + + public void setEffect3Value(float effect3Value) { + this.effect3Value = effect3Value; + } + + public float getEffect4Value() { + return effect4Value; + } + + public void setEffect4Value(float effect4Value) { + this.effect4Value = effect4Value; + } + + public float getEffect5Value() { + return effect5Value; + } + + public void setEffect5Value(float effect5Value) { + this.effect5Value = effect5Value; + } + + public String getParticleEffect() { + return particleEffect; + } + + public void setParticleEffect(String particleEffect) { + this.particleEffect = particleEffect; + } + + public boolean isDebuff() { + return isDebuff; + } + + public void setDebuff(boolean isDebuff) { + this.isDebuff = isDebuff; + } + + public boolean isRemoveOnDeath() { + return removeOnDeath; + } + + public void setRemoveOnDeath(boolean removeOnDeath) { + this.removeOnDeath = removeOnDeath; + } + + public boolean isRemovableByPlayer() { + return isRemovableByPlayer; + } + + public void setRemovableByPlayer(boolean isRemovableByPlayer) { + this.isRemovableByPlayer = isRemovableByPlayer; + } + + public int getMaxStacks() { + return maxStacks; + } + + public void setMaxStacks(int maxStacks) { + this.maxStacks = maxStacks; + } + + public boolean isPersistent() { + return isPersistent; + } + + public void setPersistent(boolean isPersistent) { + this.isPersistent = isPersistent; + } + + public boolean isRemoveOnRespec() { + return removeOnRespec; + } + + public void setRemoveOnRespec(boolean removeOnRespec) { + this.removeOnRespec = removeOnRespec; + } + + public boolean isAiRemoveOnEndCombat() { + return aiRemoveOnEndCombat; + } + + public void setAiRemoveOnEndCombat(boolean aiRemoveOnEndCombat) { + this.aiRemoveOnEndCombat = aiRemoveOnEndCombat; + } + + public boolean isDecayOnPvPDeath() { + return decayOnPvPDeath; + } + + public void setDecayOnPvPDeath(boolean decayOnPvPDeath) { + this.decayOnPvPDeath = decayOnPvPDeath; + } + + public void setStartTime() { + this.startTime = System.currentTimeMillis(); + } + + public int getRemainingDuration() { + long currentTime = System.currentTimeMillis(); + long timeDiff = (currentTime - startTime) / 1000; + int remaining = (int) (duration - timeDiff); + System.out.println("Buff remaining: " + remaining); + return remaining; + } + + public int getTotalPlayTime() { + return totalPlayTime; + } + + public void setTotalPlayTime(int totalPlayTime) { + this.totalPlayTime = totalPlayTime; + } + +} diff --git a/src/resources/z/exp/craft/DraftSchematic.java b/src/resources/z/exp/craft/DraftSchematic.java new file mode 100644 index 00000000..7192c98b --- /dev/null +++ b/src/resources/z/exp/craft/DraftSchematic.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * 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.z.exp.craft; + +import java.nio.ByteOrder; + +import org.apache.mina.core.buffer.IoBuffer; + +import com.sleepycat.persist.model.Persistent; + +import resources.objects.Delta; + +@Persistent +public class DraftSchematic extends Delta { + + private int serverSchematicCrc = 0; + private int schematicCrc = 0; + private int amount = 1; + + public DraftSchematic(int serverSchematicCrc, int schematicCrc, int amount) { + this.serverSchematicCrc = serverSchematicCrc; + this.schematicCrc = schematicCrc; + this.amount = amount; + } + + public DraftSchematic(int serverSchematicCrc, int schematicCrc) { + this.serverSchematicCrc = serverSchematicCrc; + this.schematicCrc = schematicCrc; + } + + public DraftSchematic() { + + } + + public int getServerSchematicCrc() { + synchronized(objectMutex) { + return serverSchematicCrc; + } + } + + public int getSchematicCrc() { + synchronized(objectMutex) { + return schematicCrc; + } + } + + public int getAmount() { + synchronized(objectMutex) { + return amount; + } + } + + public void setAmount(int amount) { + synchronized(objectMutex) { + this.amount = amount; + } + } + + public byte[] getBytes() { + synchronized(objectMutex) { + IoBuffer buffer = bufferPool.allocate(12, false).order(ByteOrder.LITTLE_ENDIAN); + buffer.putInt(serverSchematicCrc); + buffer.putInt(schematicCrc); + buffer.putInt(amount); + return buffer.array(); + } + } + +} diff --git a/src/resources/z/exp/equipment/Equipment.java b/src/resources/z/exp/equipment/Equipment.java new file mode 100644 index 00000000..4e7e06cc --- /dev/null +++ b/src/resources/z/exp/equipment/Equipment.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * 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.z.exp.equipment; + +import java.nio.ByteOrder; + +import org.apache.mina.core.buffer.IoBuffer; + +import com.sleepycat.persist.model.Persistent; + +import engine.resources.common.CRC; +import engine.resources.objects.SWGObject; +import resources.objects.Delta; +import resources.z.exp.objects.tangible.TangibleObject; +import resources.z.exp.objects.weapon.WeaponObject; + +@Persistent +public class Equipment extends Delta { + + private TangibleObject object; + + public Equipment(SWGObject object) { + this.object = ((object instanceof TangibleObject) ? (TangibleObject) object : null); + } + + public Equipment() { + + } + + public SWGObject getObject() { + synchronized(objectMutex) { + return object; + } + } + + public long getObjectId() { + synchronized(objectMutex) { + return object.getObjectId(); + } + } + + public byte[] getBytes() { + synchronized(objectMutex) { + int size = 18 + object.getCustomization().length; + + IoBuffer buffer = bufferPool.allocate(size, false).order(ByteOrder.LITTLE_ENDIAN); + buffer.setAutoExpand(true); + buffer.putShort((short) object.getCustomization().length); + buffer.put(object.getCustomization()); + buffer.putInt(object.getArrangementId()); + buffer.putLong(object.getObjectID()); + buffer.putInt(CRC.StringtoCRC(object.getTemplate())); + buffer.put(getBoolean((object instanceof WeaponObject))); + if (object instanceof WeaponObject) { + buffer.put(((WeaponObject) object).getBaseline3().getBaseline()); + buffer.put(((WeaponObject) object).getBaseline6().getBaseline()); + } + buffer.flip(); + + return buffer.array(); + } + } + +} diff --git a/src/resources/z/exp/gcw/CurrentServerGCWZoneHistory.java b/src/resources/z/exp/gcw/CurrentServerGCWZoneHistory.java new file mode 100644 index 00000000..3171a5eb --- /dev/null +++ b/src/resources/z/exp/gcw/CurrentServerGCWZoneHistory.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * 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.z.exp.gcw; + +import java.nio.ByteOrder; + +import org.apache.mina.core.buffer.IoBuffer; + +import com.sleepycat.persist.model.Persistent; + +import resources.objects.Delta; + +@Persistent +public class CurrentServerGCWZoneHistory extends Delta implements Cloneable { + + private int lastUpdateTime; + private int percent; + + public CurrentServerGCWZoneHistory(CurrentServerGCWZonePercent zone) { + this.percent = zone.getPercent().intValue(); + this.lastUpdateTime = zone.getLastUpdateTime(); + } + + public CurrentServerGCWZoneHistory() { + + } + + public int getLastUpdateTime() { + synchronized(objectMutex) { + return lastUpdateTime; + } + } + + public int getPercent() { + synchronized(objectMutex) { + return percent; + } + } + + public byte[] getBytes() { + synchronized(objectMutex) { + IoBuffer buffer = bufferPool.allocate((8), false).order(ByteOrder.LITTLE_ENDIAN); + buffer.putInt(lastUpdateTime); + buffer.putInt(percent); + return buffer.array(); + } + } + + public CurrentServerGCWZoneHistory clone() { + try { + return (CurrentServerGCWZoneHistory) super.clone(); + } catch (CloneNotSupportedException e) { + e.printStackTrace(); + return null; + } + } + +} diff --git a/src/resources/z/exp/gcw/CurrentServerGCWZonePercent.java b/src/resources/z/exp/gcw/CurrentServerGCWZonePercent.java new file mode 100644 index 00000000..930671f0 --- /dev/null +++ b/src/resources/z/exp/gcw/CurrentServerGCWZonePercent.java @@ -0,0 +1,173 @@ +/******************************************************************************* + * 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.z.exp.gcw; + +import java.math.BigDecimal; +import java.math.MathContext; +import java.nio.ByteOrder; + +import org.apache.mina.core.buffer.IoBuffer; + +import com.sleepycat.persist.model.Persistent; + +import engine.resources.scene.Point2D; + +import resources.objects.Delta; + +@Persistent +public class CurrentServerGCWZonePercent extends Delta implements Cloneable { + + private Point2D position; + private float radius = 0; + private BigDecimal weight; + private int type = 0; + private BigDecimal percent; + private int gcwPoints = 1; + private long lastUpdateTime = (System.currentTimeMillis() / ((long) 1000)); + + public CurrentServerGCWZonePercent(Point2D position, float radius, int weight, int type) { + this.position = position; + this.radius = radius; + this.weight = new BigDecimal(weight, MathContext.DECIMAL128); + this.weight = this.weight.divide(new BigDecimal("10000000.0", MathContext.DECIMAL128), MathContext.DECIMAL128); + this.type = type; + this.percent = new BigDecimal("50.0", MathContext.DECIMAL128); + } + + public CurrentServerGCWZonePercent() { + + } + + public Point2D getPosition() { + synchronized(objectMutex) { + return position.clone(); + } + } + + public void setPosition(Point2D position) { + synchronized(objectMutex) { + this.position = position; + } + } + + public float getRadius() { + synchronized(objectMutex) { + return radius; + } + } + + public void setRadius(float radius) { + synchronized(objectMutex) { + this.radius = radius; + } + } + + public int getGroup() { + synchronized(objectMutex) { + return weight.unscaledValue().intValue(); + } + } + + public BigDecimal getWeight() { + synchronized(objectMutex) { + return weight; + } + } + + public void setWeight(int weight) { + synchronized(objectMutex) { + this.weight = new BigDecimal(weight, MathContext.DECIMAL128); + this.weight = this.weight.divide(new BigDecimal("10000000.0", MathContext.DECIMAL128), MathContext.DECIMAL128); + } + } + + public int getType() { + synchronized(objectMutex) { + return type; + } + } + + public void setType(int type) { + synchronized(objectMutex) { + this.type = type; + } + } + + public BigDecimal getPercent() { + synchronized(objectMutex) { + return percent; + } + } + + public CurrentServerGCWZonePercent setPercent(BigDecimal percent) { + synchronized(objectMutex) { + this.percent = percent; + this.lastUpdateTime = (System.currentTimeMillis() / ((long) 1000)); + return this; + } + } + + public int getGCWPoints() { + synchronized(objectMutex) { + return gcwPoints; + } + } + + public void addGCWPoints(int gcwPoints) { + synchronized(objectMutex) { + this.gcwPoints += gcwPoints; + } + } + + public void removeGCWPoints(int gcwPoints) { + synchronized(objectMutex) { + this.gcwPoints = (((this.gcwPoints - gcwPoints) < 1) ? 1 : this.gcwPoints - gcwPoints); + } + } + + public int getLastUpdateTime() { + synchronized(objectMutex) { + return ((int) lastUpdateTime); + } + } + + public byte[] getBytes() { + synchronized(objectMutex) { + IoBuffer buffer = bufferPool.allocate(4, false).order(ByteOrder.LITTLE_ENDIAN); + buffer.putInt(percent.intValue()); + return buffer.array(); + } + } + + @Override + public CurrentServerGCWZonePercent clone() { + try { + CurrentServerGCWZonePercent object = (CurrentServerGCWZonePercent) super.clone(); + object.setPosition(getPosition()); + return object; + } catch (CloneNotSupportedException e) { + e.printStackTrace(); + return null; + } + } + +} diff --git a/src/resources/z/exp/gcw/OtherServerGCWZonePercent.java b/src/resources/z/exp/gcw/OtherServerGCWZonePercent.java new file mode 100644 index 00000000..8411980d --- /dev/null +++ b/src/resources/z/exp/gcw/OtherServerGCWZonePercent.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * 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.z.exp.gcw; + +import java.nio.ByteOrder; + +import org.apache.mina.core.buffer.IoBuffer; + +import com.sleepycat.persist.model.Persistent; + +import resources.objects.Delta; + +@Persistent +public class OtherServerGCWZonePercent extends Delta implements Cloneable { + + private String zone = ""; + private int percent = 50; + + public OtherServerGCWZonePercent(String zone) { + this.zone = zone; + } + + public OtherServerGCWZonePercent() { + + } + + public String getZone() { + synchronized(objectMutex) { + return zone; + } + } + + public int getPercent() { + synchronized(objectMutex) { + return percent; + } + } + + public OtherServerGCWZonePercent setPercent(double percent) { + synchronized(objectMutex) { + this.percent = (int) percent; + return this; + } + } + + public byte[] getBytes() { + synchronized(objectMutex) { + IoBuffer buffer = bufferPool.allocate((2 + zone.length() + 4), false).order(ByteOrder.LITTLE_ENDIAN); + buffer.put(getAsciiString(zone)); + buffer.putInt(percent); + return buffer.array(); + } + } + + @Override + public OtherServerGCWZonePercent clone() { + try { + return (OtherServerGCWZonePercent) super.clone(); + } catch (CloneNotSupportedException e) { + e.printStackTrace(); + return null; + } + } + +} diff --git a/src/resources/z/exp/gcw/RegionDefender.java b/src/resources/z/exp/gcw/RegionDefender.java new file mode 100644 index 00000000..3f0194fa --- /dev/null +++ b/src/resources/z/exp/gcw/RegionDefender.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * 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.z.exp.gcw; + +import org.apache.mina.core.buffer.IoBuffer; + +import com.sleepycat.persist.model.Persistent; + +import resources.common.AString; +import resources.z.exp.objects.Baseline; +import resources.objects.Delta; + +@Persistent +public class RegionDefender extends Delta { + + private AString region; + private byte byte1 = 0; + private byte byte2 = 0; + + public RegionDefender(String region, byte byte1, byte byte2) { + this.region = new AString(region); + this.byte1 = byte1; + this.byte2 = byte2; + } + + public RegionDefender(String region) { + this.region = new AString(region); + } + + public RegionDefender() { + this.region = new AString(); + } + + public String getRegion() { + synchronized(objectMutex) { + return region.get(); + } + } + + public void setRegion(String region) { + synchronized(objectMutex) { + this.region = new AString(region); + } + } + + public byte getByte1() { + synchronized(objectMutex) { + return byte1; + } + } + + public void setByte1(byte byte1) { + synchronized(objectMutex) { + this.byte1 = byte1; + } + } + + public byte getByte2() { + synchronized(objectMutex) { + return byte2; + } + } + + public void setByte2(byte byte2) { + synchronized(objectMutex) { + this.byte2 = byte2; + } + } + + public byte[] getBytes() { + synchronized(objectMutex) { + IoBuffer buffer = Baseline.createBuffer(region.getBytes().length + 2); + buffer.put(region.getBytes()); + buffer.put(byte1); + buffer.put(byte2); + return buffer.array(); + } + } + +} diff --git a/src/resources/z/exp/group/GroupInviteInfo.java b/src/resources/z/exp/group/GroupInviteInfo.java new file mode 100644 index 00000000..97c53445 --- /dev/null +++ b/src/resources/z/exp/group/GroupInviteInfo.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * 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.z.exp.group; + +import org.apache.mina.core.buffer.IoBuffer; + +import com.sleepycat.persist.model.Persistent; + +import resources.common.AString; +import resources.z.exp.objects.Baseline; +import resources.objects.Delta; + +@Persistent +public class GroupInviteInfo extends Delta { + + private long senderId; + private AString senderName; + private long inviteCounter; + + public GroupInviteInfo(long senderId, String senderName) { + this.senderId = senderId; + this.senderName = new AString(senderName); + inviteCounter = 1; + } + + public GroupInviteInfo() { + + } + + public long getSenderId() { + synchronized(objectMutex) { + return senderId; + } + } + + public String getSenderName() { + synchronized(objectMutex) { + return senderName.get(); + } + } + + public void setSender(long senderId, String senderName) { + synchronized(objectMutex) { + this.senderId = senderId; + this.senderName = new AString(senderName); + inviteCounter++; + } + } + + public byte[] getBytes() { + synchronized(objectMutex) { + IoBuffer buffer = Baseline.createBuffer(16 + senderName.getBytes().length); + buffer.putLong(senderId); + buffer.put(senderName.getBytes()); + buffer.putLong(inviteCounter); + return buffer.array(); + } + } + +} diff --git a/src/resources/z/exp/group/Member.java b/src/resources/z/exp/group/Member.java new file mode 100644 index 00000000..93c5b64b --- /dev/null +++ b/src/resources/z/exp/group/Member.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * 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.z.exp.group; + +import java.nio.ByteOrder; + +import org.apache.mina.core.buffer.IoBuffer; + +import com.sleepycat.persist.model.Persistent; + +import engine.resources.objects.SWGObject; + +import resources.objects.Delta; + +@Persistent +public class Member extends Delta { + + private SWGObject member; + + public Member(SWGObject member) { + this.member = member; + } + + public Member() { + + } + + public SWGObject getMember() { + synchronized(objectMutex) { + return member; + } + } + + public long getObjectId() { + return member.getObjectID(); + } + + public String getCustomName() { + return member.getCustomName(); + } + + public byte[] getBytes() { + synchronized(objectMutex) { + IoBuffer buffer = bufferPool.allocate(8 + getAsciiString(getCustomName()).length, false).order(ByteOrder.LITTLE_ENDIAN); + buffer.putLong(getObjectId()); + buffer.put(getAsciiString(getCustomName())); + return buffer.array(); + } + } + +} diff --git a/src/resources/z/exp/group/MemberInfo.java b/src/resources/z/exp/group/MemberInfo.java new file mode 100644 index 00000000..a19fce7c --- /dev/null +++ b/src/resources/z/exp/group/MemberInfo.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * 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.z.exp.group; + +import java.nio.ByteOrder; + +import org.apache.mina.core.buffer.IoBuffer; + +import com.sleepycat.persist.model.Persistent; + +import resources.objects.Delta; + +@Persistent +public class MemberInfo extends Delta { + + private long info; + private int memberId; + + public MemberInfo(long info, int memberId) { + this.info = info; + this.memberId = memberId; + } + + public MemberInfo() { + + } + + public long getInfo() { + synchronized(objectMutex) { + return info; + } + } + + public MemberInfo setInfo(long info) { + synchronized(objectMutex) { + this.info = info; + return this; + } + } + + public int getMemberId() { + synchronized(objectMutex) { + return memberId; + } + } + + public MemberInfo setMemberId(int memberId) { + synchronized(objectMutex) { + this.memberId = memberId; + return this; + } + } + + public byte[] getBytes() { + synchronized(objectMutex) { + IoBuffer buffer = bufferPool.allocate(12, false).order(ByteOrder.LITTLE_ENDIAN); + buffer.putLong(info); + buffer.putInt(memberId); + return buffer.array(); + } + } + +} diff --git a/src/resources/z/exp/guild/Guild.java b/src/resources/z/exp/guild/Guild.java new file mode 100644 index 00000000..7e29d8a2 --- /dev/null +++ b/src/resources/z/exp/guild/Guild.java @@ -0,0 +1,120 @@ +/******************************************************************************* + * 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.z.exp.guild; + +import java.nio.ByteOrder; +import java.util.List; + +import org.apache.mina.core.buffer.IoBuffer; + +import com.sleepycat.persist.model.Persistent; + +import resources.objects.Delta; + +import engine.resources.objects.SWGObject; + +@Persistent +public class Guild extends Delta { + + private int id; + private String abbreviation; + private String name; + private SWGObject leader; + private List members; + + public Guild(int id, String abbreviation, String name, SWGObject leader) { + this.id = id; + this.abbreviation = abbreviation; + this.name = name; + this.leader = leader; + this.members.add(leader); + } + + public Guild() { + + } + + public int getId() { + synchronized(objectMutex) { + return id; + } + } + + public void setId(int id) { + synchronized(objectMutex) { + this.id = id; + } + } + + public String getAbbreviation() { + synchronized(objectMutex) { + return abbreviation; + } + } + + public void setAbbreviation(String abbreviation) { + synchronized(objectMutex) { + this.abbreviation = abbreviation; + } + } + + public String getName() { + synchronized(objectMutex) { + return name; + } + } + + public void setName(String name) { + synchronized(objectMutex) { + this.name = name; + } + } + + public String getString() { + return (Integer.toString(getId()) + ":" + getAbbreviation()); + } + + public SWGObject getLeader() { + synchronized(objectMutex) { + return leader; + } + } + + public void setLeader(SWGObject leader) { + synchronized(objectMutex) { + this.leader = leader; + } + } + + public List getMembers() { + return members; + } + + public byte[] getBytes() { + synchronized(objectMutex) { + IoBuffer buffer = bufferPool.allocate((getString().length() + 2), false).order(ByteOrder.LITTLE_ENDIAN); + buffer.put(getAsciiString(getString())); + return buffer.array(); + } + } + +} diff --git a/src/resources/z/exp/manufacture/Property.java b/src/resources/z/exp/manufacture/Property.java new file mode 100644 index 00000000..254c1689 --- /dev/null +++ b/src/resources/z/exp/manufacture/Property.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * 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.z.exp.manufacture; + +import java.nio.ByteOrder; + +import org.apache.mina.core.buffer.IoBuffer; + +import com.sleepycat.persist.model.Persistent; + +import resources.objects.Delta; + +@Persistent +public class Property extends Delta { + + private int unused = 0; + private String key = ""; + private float value = 0; + + public Property(String key, float value) { + this.key = key; + this.value = value; + } + + public Property() { + + } + + public String getKey() { + synchronized(objectMutex) { + return key; + } + } + + public Property setKey(String key) { + synchronized(objectMutex) { + this.key = key; + return this; + } + } + + public float getValue() { + synchronized(objectMutex) { + return value; + } + } + + public Property setValue(float value) { + synchronized(objectMutex) { + this.value = value; + return this; + } + } + + public byte[] getBytes() { + synchronized(objectMutex) { + IoBuffer buffer = bufferPool.allocate(8 + getAsciiString(key).length, false).order(ByteOrder.LITTLE_ENDIAN); + buffer.putInt(unused); + buffer.put(getAsciiString(key)); + buffer.putFloat(value); + return buffer.array(); + } + } + +} diff --git a/src/resources/z/exp/manufacture/SubList.java b/src/resources/z/exp/manufacture/SubList.java new file mode 100644 index 00000000..4a65aaa9 --- /dev/null +++ b/src/resources/z/exp/manufacture/SubList.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * 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.z.exp.manufacture; + +import java.nio.ByteOrder; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.apache.mina.core.buffer.IoBuffer; + +import com.sleepycat.persist.model.Persistent; + +import resources.objects.Delta; +import resources.z.exp.objects.Baseline; + +@Persistent +public class SubList extends Delta { + + private List list = new CopyOnWriteArrayList(); + + public SubList() { + + } + + public List getList() { + return list; + } + + public byte[] getBytes() { + synchronized(objectMutex) { + int size = 4; + for (o object : list) size += Baseline.toBytes(object).length; + + IoBuffer buffer = bufferPool.allocate(size, false).order(ByteOrder.LITTLE_ENDIAN); + buffer.putInt(list.size()); + for (o object : list) { + buffer.put(Baseline.toBytes(object)); + } + + return buffer.array(); + } + } + +} diff --git a/src/resources/z/exp/manufacture/TableAndKey.java b/src/resources/z/exp/manufacture/TableAndKey.java new file mode 100644 index 00000000..acf3aa73 --- /dev/null +++ b/src/resources/z/exp/manufacture/TableAndKey.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * 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.z.exp.manufacture; + +import java.nio.ByteOrder; + +import org.apache.mina.core.buffer.IoBuffer; + +import com.sleepycat.persist.model.Persistent; + +import resources.objects.Delta; + +@Persistent +public class TableAndKey extends Delta { + + private String table = ""; + private int unused = 0; + private String key = ""; + + public TableAndKey(String table, String key) { + this.table = table; + this.table = key; + } + + public TableAndKey() { + + } + + public String getTable() { + synchronized(objectMutex) { + return table; + } + } + + public TableAndKey setTable(String table) { + synchronized(objectMutex) { + this.table = table; + return this; + } + } + + public String getKey() { + synchronized(objectMutex) { + return key; + } + } + + public TableAndKey setKey(String key) { + synchronized(objectMutex) { + this.key = key; + return this; + } + } + + public byte[] getBytes() { + synchronized(objectMutex) { + IoBuffer buffer = bufferPool.allocate(4 + getAsciiString(table).length + getAsciiString(key).length, false).order(ByteOrder.LITTLE_ENDIAN); + buffer.put(getAsciiString(table)); + buffer.putInt(unused); + buffer.put(getAsciiString(key)); + return buffer.array(); + } + } + +} diff --git a/src/resources/z/exp/mission/MissionLocation.java b/src/resources/z/exp/mission/MissionLocation.java new file mode 100644 index 00000000..52a37dc1 --- /dev/null +++ b/src/resources/z/exp/mission/MissionLocation.java @@ -0,0 +1,47 @@ +package resources.z.exp.mission; + +import com.sleepycat.persist.model.Persistent; + +import engine.resources.common.CRC; +import engine.resources.scene.Point3D; + +@Persistent +public class MissionLocation { + + private float x, y, z; + private long objectId; + private String planet; + + public MissionLocation(Point3D position, long objectId, String planet) { + this.x = position.x; + this.y = position.y; + this.z = position.z; + this.objectId = objectId; + this.planet = planet; + } + + public MissionLocation() { + + } + + public Point3D getPosition() { + return new Point3D(x, y, z); + } + + public long getObjectId() { + return objectId; + } + + public String getPlanet() { + return planet; + } + + public int getPlanetCRC() { + if (planet != null) { + return CRC.StringtoCRC(planet); + } else { + return 0; + } + } + +} diff --git a/src/resources/z/exp/objects/Baseline.java b/src/resources/z/exp/objects/Baseline.java new file mode 100644 index 00000000..9ae536c6 --- /dev/null +++ b/src/resources/z/exp/objects/Baseline.java @@ -0,0 +1,747 @@ +/******************************************************************************* + * 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.z.exp.objects; + +import java.io.UnsupportedEncodingException; +import java.nio.ByteOrder; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; +import java.util.Map.Entry; +import java.util.TreeMap; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.apache.mina.core.buffer.IoBuffer; +import org.apache.mina.core.buffer.SimpleBufferAllocator; + +import resources.common.AString; +import resources.common.Opcodes; +import resources.common.UString; +import resources.objects.IDelta; +import resources.z.exp.objects.object.BaseObject; + +import com.sleepycat.persist.model.NotPersistent; +import com.sleepycat.persist.model.Persistent; + +import engine.resources.objects.SWGObject; + +@Persistent +public class Baseline implements List { + + private List list = new CopyOnWriteArrayList(); + private Map definition = new TreeMap(); + private BaseObject object; + private byte viewType; + @NotPersistent + protected final Object objectMutex = new Object(); + @NotPersistent + private static SimpleBufferAllocator bufferPool = new SimpleBufferAllocator(); + @NotPersistent + private Map baselineBuilders; + @NotPersistent + private Map deltaBuilders; + + public Baseline() { } + + public Baseline(BaseObject object, int viewType) { + this.viewType = (byte) viewType; + this.object = object; + } + + public boolean add(Object e) { + synchronized(objectMutex) { + if (list.add(e)) { + definition.put(Integer.toString(list.size() - 1), list.size() - 1); + return true; + } else { + return false; + } + } + } + + public void add(int index, Object element) { + synchronized(objectMutex) { + return; + } + } + + public boolean addAll(Collection c) { + synchronized(objectMutex) { + return false; + } + } + + public boolean addAll(int index, Collection c) { + synchronized(objectMutex) { + return false; + } + } + + public void clear() { + synchronized(objectMutex) { + list.clear(); + definition.clear(); + } + } + + public boolean contains(Object o) { + synchronized(objectMutex) { + return list.contains(o); + } + } + + public boolean containsAll(Collection c) { + synchronized(objectMutex) { + return list.containsAll(c); + } + } + + private boolean compareTypes(Object o1, Object o2) { + if ((o1 instanceof IDelta && o2 instanceof IDelta) || + (o1 instanceof AString && o2 instanceof AString) || + (o1 instanceof UString && o2 instanceof UString) || + (o1 instanceof Byte[] && o2 instanceof Byte[]) || + (o1 instanceof Byte && o2 instanceof Byte) || + (o1 instanceof Boolean && o2 instanceof Boolean) || + (o1 instanceof Short && o2 instanceof Short) || + (o1 instanceof Integer && o2 instanceof Integer) || + (o1 instanceof Float && o2 instanceof Float) || + (o1 instanceof Long && o2 instanceof Long) || + (o1 instanceof SWGObject && o2 instanceof SWGObject) || + (o1 instanceof SWGList && o2 instanceof SWGList) || + (o1 instanceof SWGSet && o2 instanceof SWGSet) || + (o1 instanceof SWGMap && o2 instanceof SWGMap) || + (o1 instanceof SWGMultiMap && o2 instanceof SWGMultiMap) || + (o1 instanceof ArrayList && o2 instanceof ArrayList)) { + return true; + } + + return false; + } + + public IoBuffer createBaseline() { + byte[] objects = { }; + int size = 0; + + for (Object o : list) { + byte[] object; + + if (baselineBuilders != null && baselineBuilders.containsKey(o)) { + object = baselineBuilders.get(o).build(); + } else { + object = toBytes(o); + } + + size += object.length; + + IoBuffer buffer = createBuffer(size); + buffer.put(objects); + buffer.put(object); + buffer.flip(); + + objects = buffer.array(); + } + + IoBuffer buffer = createBuffer(25 + size); + buffer.putShort((short) 5); + buffer.putInt(Opcodes.BaselinesMessage); + buffer.putLong(object.getObjectID()); + try { + buffer.put(reverse(getShortTemplate()).getBytes("US-ASCII")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + buffer.put(viewType); + buffer.putInt(size); + buffer.putShort((short) list.size()); + buffer.put(objects); + buffer.flip(); + + return buffer; + } + + public static IoBuffer createBuffer(int size) { + return bufferPool.allocate(size, false).order(ByteOrder.LITTLE_ENDIAN); + } + + public IoBuffer createDelta() { + List objectQueue = new ArrayList(); + + synchronized(objectMutex) { + for (int i = 0; i < list.size(); i++) { + objectQueue.add(i); + } + } + + return createDelta(objectQueue, null); + } + + public IoBuffer createDelta(int object) { + List objectQueue = new ArrayList(); + objectQueue.add(object); + return createDelta(objectQueue, null); + } + + public IoBuffer createDelta(int object, byte[] data) { + List objectQueue = new ArrayList(); + objectQueue.add(object); + return createDelta(objectQueue, data); + } + + public IoBuffer createDelta(List objectQueue, byte[] data) { + byte[] objects = { }; + int size = 0; + + for (Integer o : objectQueue) { + byte[] object; + + if (deltaBuilders != null && deltaBuilders.containsKey(o)) { + object = deltaBuilders.get(o).build(); + } else if (data != null) { + object = data; + } else { + object = toBytes(get(o)); + } + + size += 2 + object.length; + + IoBuffer buffer = createBuffer(size); + buffer.put(objects); + buffer.putShort(o.shortValue()); + buffer.put(object); + buffer.flip(); + + objects = buffer.array(); + } + + IoBuffer buffer = createBuffer(27 + size); + buffer.putShort((short) 5); + buffer.putInt(Opcodes.DeltasMessage); + buffer.putLong(object.getObjectID()); + try { + buffer.put(reverse(getShortTemplate()).getBytes("US-ASCII")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + buffer.put(viewType); + buffer.putInt(size); + buffer.putShort((short) objectQueue.size()); + buffer.put(objects); + buffer.flip(); + + return buffer; + } + + public Object get(int index) { + synchronized(objectMutex) { + return list.get(index); + } + } + + public Object get(String name) { + synchronized(objectMutex) { + return list.get(definition.get(name)); + } + } + + public IoBuffer getBaseline() { + return createBaseline(); + } + + public Map getBaselineBuilders() { + synchronized(objectMutex) { + return baselineBuilders; + } + } + + public static byte getBoolean(boolean condition) { + return ((byte) ((condition) ? 1 : 0)); + } + + public byte[] getBytes() { + synchronized(objectMutex) { + int size = 0; + + for (Object o : list) { + size += toBytes(o).length; + } + + IoBuffer buffer = createBuffer(size); + + for (Object o : list) { + buffer.put(toBytes(o)); + } + + buffer.flip(); + + return buffer.array(); + } + } + + public byte[] getBytes(int index) { + synchronized(objectMutex) { + return toBytes(list.get(index)); + } + } + + public byte[] getBytes(String name) { + synchronized(objectMutex) { + return toBytes(list.get(definition.get(name))); + } + } + + private String getDefinition(int index) { + for (Entry entry : definition.entrySet()) { + if (entry.getValue() == index) { + return entry.getKey(); + } + } + + return null; + } + + public Map getDefinitions() { + synchronized(objectMutex) { + return definition; + } + } + + public IoBuffer getDelta(int index) { + return createDelta(index); + } + + public IoBuffer getDelta(String name) { + return createDelta(definition.get(name)); + } + + public Map getDeltaBuilders() { + synchronized(objectMutex) { + return deltaBuilders; + } + } + + public Object getMutex() { + return objectMutex; + } + + public String getShortTemplate() throws Exception { + String Template = object.getTemplate(); + + if (Template.startsWith("object/battlefield_marker")) { + return "BMRK"; + } else if(Template.startsWith("object/building")){ + return "BUIO"; + } else if(Template.startsWith("object/cell")) { + return "SCLT"; + } else if (Template.startsWith("object/construction_contract")) { + throw new Exception(); + } else if (Template.startsWith("object/counting")) { + throw new Exception(); + } else if (Template.startsWith("object/creature")) { + return "CREO"; + } else if (Template.startsWith("object/draft_schematic")) { + throw new Exception(); + } else if (Template.startsWith("object/factory")) { + return "FCYT"; + } else if(Template.startsWith("object/group")) { + return "GRUP"; + } else if(Template.startsWith("object/guild")) { + return "GILD"; + } else if (Template.startsWith("object/installation")) { + return "INSO"; + } else if (Template.startsWith("object/installation/battlefield")) { + throw new Exception(); + } else if (Template.startsWith("object/installation/faction_perk/covert_detector")) { + throw new Exception(); + } else if (Template.startsWith("object/installation/faction_perk/minefield")) { + throw new Exception(); + } else if (Template.startsWith("object/installation/faction_perk/turret")) { + throw new Exception(); + } else if (Template.startsWith("object/installation/generators")) { + return "HINO"; + } else if (Template.startsWith("object/installation/manufacture")) { + return "MINO"; + } else if (Template.startsWith("object/installation/mining_gas")) { + throw new Exception(); + } else if (Template.startsWith("object/installation/mining_liquid")) { + throw new Exception(); + } else if (Template.startsWith("object/installation/mining_gas")) { + throw new Exception(); + } else if (Template.startsWith("object/installation/mining_ore")) { + throw new Exception(); + } else if (Template.startsWith("object/installation/mining_organic")) { + throw new Exception(); + } else if (Template.startsWith("object/installation/turret")) { + throw new Exception(); + } else if (Template.startsWith("object/intangible")) { + return "ITNO"; + } else if (Template.startsWith("object/jedi_manager")) { + throw new Exception(); + } else if (Template.startsWith("object/manufacture_schematic")) { + return "MSCO"; + } else if (Template.startsWith("object/mission")) { + return "MISO"; + } else if (Template.startsWith("object/mobile")) { + throw new Exception(); + } else if (Template.startsWith("object/object")) { + throw new Exception(); + } else if (Template.startsWith("object/path_waypoint")) { + throw new Exception(); + } else if (Template.startsWith("object/player")) { + return "PLAY"; + } else if (Template.startsWith("object/player_quest")) { + return "PQOS"; + } else if (Template.startsWith("object/resource_container")) { + return "RCNO"; + } else if (Template.startsWith("object/ship")) { + return "SHIP"; + } else if (Template.startsWith("object/soundobject")) { + throw new Exception(); + } else if(Template.startsWith("object/static")) { + return "STAO"; + } else if (Template.startsWith("object/tangible")) { + return "TANO"; + } else if (Template.startsWith("object/token")) { + throw new Exception(); + } else if (Template.startsWith("object/universe")) { + throw new Exception(); + } else if(Template.startsWith("object/waypoint")) { + return "WAYP"; + } else if (Template.startsWith("object/weapon")) { + return "WEAO"; + } else { + throw new Exception(); + } + } + + public int indexOf(Object o) { + synchronized(objectMutex) { + return list.indexOf(o); + } + } + + public boolean isEmpty() { + synchronized(objectMutex) { + return list.isEmpty(); + } + } + + public Iterator iterator() { + synchronized(objectMutex) { + return list.iterator(); + } + } + + public int lastIndexOf(Object o) { + synchronized(objectMutex) { + return lastIndexOf(o); + } + } + + public ListIterator listIterator() { + synchronized(objectMutex) { + return list.listIterator(); + } + } + + public ListIterator listIterator(int index) { + synchronized(objectMutex) { + return listIterator(index); + } + } + + public void put(String name, Object o) { + synchronized(objectMutex) { + definition.put(name, list.size()); + list.add(o); + } + } + + public boolean remove(Object o) { + return false; + } + + public Object remove(int index) { + return null; + } + + public boolean removeAll(Collection c) { + return false; + } + + public boolean retainAll(Collection c) { + return false; + } + + private String reverse(String reverseString) { + if (reverseString.length() <= 1) { + return reverseString; + } + + return reverse(reverseString.substring(1, reverseString.length())) + reverseString.charAt(0); + } + + public Object set(int index, Object element) { + return null; + } + + public IoBuffer set(String name, Object o) { + synchronized(objectMutex) { + int index = definition.get(name); + + if (compareTypes(o, list.get(index)) && list.set(index, o) != null) { + return createDelta(index); + } else { + return null; + } + } + } + + public void setBaselineBuilders(Map baselineBuilders) { + synchronized(objectMutex) { + this.baselineBuilders = baselineBuilders; + } + } + + public void setDeltaBuilders(Map deltaBuilders) { + synchronized(objectMutex) { + this.deltaBuilders = deltaBuilders; + } + } + + public int size() { + synchronized(objectMutex) { + return list.size(); + } + } + + public List subList(int fromIndex, int toIndex) { + synchronized(objectMutex) { + return list.subList(fromIndex, toIndex); + } + } + + public Object[] toArray() { + synchronized(objectMutex) { + return list.toArray(); + } + } + + public T[] toArray(T[] a) { + synchronized(objectMutex) { + return list.toArray(a); + } + } + + public static byte[] toBytes(Object o) { + try { + if (o != null) { + if (o instanceof IDelta) { + return ((IDelta) o).getBytes(); + } else if (o instanceof String) { + return (new AString((String) o)).getBytes(); + } else if (o instanceof AString) { + return ((AString) o).getBytes(); + } else if (o instanceof UString) { + return ((UString) o).getBytes(); + } else if (o instanceof Byte[]) { + IoBuffer buffer = createBuffer(2 + ((Byte[]) o).length); + buffer.putShort((short) ((Byte[]) o).length); + for (Byte b : (Byte[]) o) buffer.put(b); + return buffer.array(); + } else if (o instanceof Byte) { + return createBuffer(1).put((Byte) o).array(); + } else if (o instanceof Boolean) { + return createBuffer(1).put(((((Boolean) o)) ? (byte) 1 : (byte) 0)).array(); + } else if (o instanceof Short) { + return createBuffer(2).putShort((Short) o).array(); + } else if (o instanceof Integer) { + return createBuffer(4).putInt((Integer) o).array(); + } else if (o instanceof Float) { + return createBuffer(4).putFloat((Float) o).array(); + } else if (o instanceof Long) { + return createBuffer(8).putLong((Long) o).array(); + } else if (o instanceof SWGObject) { + long objectId = ((((SWGObject) o) == null) ? (long) 0 : ((SWGObject) o).getObjectID()); + return createBuffer(8).putLong(objectId).array(); + } else if (o instanceof SWGList) { + return ((SWGList) o).getBytes(); + } else if (o instanceof SWGSet) { + return ((SWGSet) o).getBytes(); + } else if (o instanceof SWGMap) { + return ((SWGMap) o).getBytes(); + } else if (o instanceof SWGMultiMap) { + return ((SWGMultiMap) o).getBytes(); + } else if (o instanceof ArrayList) { + ArrayList list = ((ArrayList) o); + int size = 0; + byte[] objects = { }; + + for (int i = 0; i < list.size(); i++) { + byte[] object = toBytes(list.get(i)); + size += object.length; + + IoBuffer buffer = createBuffer(size); + buffer.put(objects); + buffer.put(object); + buffer.flip(); + + objects = buffer.array(); + } + + return createBuffer(size + 4).putInt(list.size()).array(); + } else { + System.out.println("ERROR: Unsupported type used in Baseline: " + (o.getClass()).getSimpleName()); + throw new Exception(); + //return new byte[] { }; + } + } else { + if (o instanceof IDelta) { + System.out.println("ERROR: a baseline object that implements IDelta is null. This could cause crashes! Make it at least a new instance with all fields set to 0."); + return new byte[] { }; + } else if (o instanceof String) { + return new byte[] { 0x00, 0x00 }; + } else if (o instanceof AString) { + return new byte[] { 0x00, 0x00 }; + } else if (o instanceof UString) { + return new byte[] { 0x00, 0x00, 0x00, 0x00 }; + } else if (o instanceof Byte[]) { + return new byte[] { 0x00, 0x00 }; + } else if (o instanceof Byte) { + return new byte[] { 0x00 }; + } else if (o instanceof Boolean) { + return new byte[] { 0x00 }; + } else if (o instanceof Short) { + return new byte[] { 0x00, 0x00 }; + } else if (o instanceof Integer) { + return new byte[] { 0x00, 0x00, 0x00, 0x00 }; + } else if (o instanceof Float) { + return new byte[] { 0x00, 0x00, 0x00, 0x00 }; + } else if (o instanceof Long) { + return new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + } else if (o instanceof SWGObject) { + return null; + } else if (o instanceof SWGList) { + return new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + } else if (o instanceof SWGSet) { + return new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + } else if (o instanceof SWGMap) { + return new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + } else if (o instanceof SWGMultiMap) { + return new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + } else if (o instanceof ArrayList) { + return new byte[] { 0x00, 0x00, 0x00, 0x00 }; + } else { + System.out.println("ERROR: Unsupported type used in Baseline."); + System.out.println("~additionally, the type was null, which is dangerous."); + return new byte[] { }; + } + } + } catch (Exception e) { + e.printStackTrace(); + return new byte[] { }; + } + } + + public void transformStructure(Baseline defaults) { + synchronized(objectMutex) { + List oldStruct = list; + Baseline newStruct = defaults; + + for (int i = 0; i < newStruct.size(); i++) { + if (definition.containsKey(newStruct.getDefinition(i))) { + int oldIndex = definition.get(newStruct.getDefinition(i)); + Object newObject = newStruct.get(i); + Object oldObject = oldStruct.get(oldIndex); + + if (compareTypes(newObject, oldObject)) { + newStruct.set(i, oldObject); + } else { + if (newObject instanceof String) { + if (oldObject instanceof AString) { + newStruct.set(i, ((AString) oldObject).get()); + } else if (oldObject instanceof UString) { + newStruct.set(i, ((UString) oldObject).get()); + } + } else if (newObject instanceof AString) { + if (oldObject instanceof String) { + newStruct.set(i, new AString((String) oldObject)); + } else if (oldObject instanceof UString) { + newStruct.set(i, new AString(((UString) oldObject).get())); + } + } else if (newObject instanceof UString) { + if (oldObject instanceof String) { + newStruct.set(i, new UString((String) oldObject)); + } else if (oldObject instanceof AString) { + newStruct.set(i, new UString(((AString) oldObject).get())); + } + } else if (newObject instanceof Byte) { + if (oldObject instanceof Short && (Short) oldObject < 0xFF) { + newStruct.set(i, ((Short) oldObject).byteValue()); + } else if (oldObject instanceof Integer && (Integer) oldObject < 0xFF) { + newStruct.set(i, ((Integer) oldObject).byteValue()); + } else if (oldObject instanceof Long && (Long) oldObject < 0xFF) { + newStruct.set(i, ((Long) oldObject).byteValue()); + } + } else if (newObject instanceof Short) { + if (oldObject instanceof Byte) { + newStruct.set(i, ((Byte) oldObject).shortValue()); + } else if (oldObject instanceof Integer && (Integer) oldObject < 0xFFFF) { + newStruct.set(i, ((Integer) oldObject).shortValue()); + } else if (oldObject instanceof Long && (Long) oldObject < 0xFFFF) { + newStruct.set(i, ((Long) oldObject).shortValue()); + } + } else if (newObject instanceof Integer) { + if (oldObject instanceof Byte) { + newStruct.set(i, ((Byte) oldObject).intValue()); + } else if (oldObject instanceof Short) { + newStruct.set(i, ((Short) oldObject).intValue()); + } else if (oldObject instanceof Long && (Long) oldObject < 0xFFFFFFFF) { + newStruct.set(i, ((Long) oldObject).intValue()); + } + } else if (newObject instanceof Long) { + if (oldObject instanceof Byte) { + newStruct.set(i, ((Byte) oldObject).longValue()); + } else if (oldObject instanceof Short) { + newStruct.set(i, ((Short) oldObject).longValue()); + } else if (oldObject instanceof Integer) { + newStruct.set(i, ((Integer) oldObject).longValue()); + } else if (oldObject instanceof SWGObject) { + newStruct.set(i, ((SWGObject) oldObject).getObjectID()); + } + } + } + } + } + + list = newStruct.list; + } + } + +} diff --git a/src/resources/z/exp/objects/Builder.java b/src/resources/z/exp/objects/Builder.java new file mode 100644 index 00000000..8bc6b647 --- /dev/null +++ b/src/resources/z/exp/objects/Builder.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * 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.z.exp.objects; + +public interface Builder { + + public byte[] build(); + +} diff --git a/src/resources/z/exp/objects/ObjectMessageBuilder.java b/src/resources/z/exp/objects/ObjectMessageBuilder.java new file mode 100644 index 00000000..0ef9564f --- /dev/null +++ b/src/resources/z/exp/objects/ObjectMessageBuilder.java @@ -0,0 +1,127 @@ +/******************************************************************************* + * 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.z.exp.objects; + +import java.nio.ByteBuffer; +import java.util.Map; + +import org.apache.mina.core.buffer.IoBuffer; + +import com.sleepycat.persist.model.Persistent; + +import resources.common.StringUtilities; +import resources.z.exp.objects.object.BaseObject; + +@Persistent +public class ObjectMessageBuilder { + + protected BaseObject object; + + public ObjectMessageBuilder(BaseObject object) { + setObject(object); + } + + public ObjectMessageBuilder() { + + } + + public void buildBaseline1(Map baselineBuilders, Map deltaBuilders) { + /* + baselineBuilders.put(5, new Builder { + public byte[] build() { + IoBuffer = Baseline.createBuffer(2); + buffer.putShort((short) 27); + return buffer.array(); + } + }); + + deltaBuilders.put(7, new Builder { + public byte[] build() { + IoBuffer = Baseline.createBuffer(4); + buffer.putInt(27); + return buffer.array(); + } + }); + */ + } + + public void buildBaseline3(Map baselineBuilders, Map deltaBuilders) { + + } + + public void buildBaseline4(Map baselineBuilders, Map deltaBuilders) { + + } + + public void buildBaseline6(Map baselineBuilders, Map deltaBuilders) { + + } + + public void buildBaseline7(Map baselineBuilders, Map deltaBuilders) { + + } + + public void buildBaseline8(Map baselineBuilders, Map deltaBuilders) { + + } + + public void buildBaseline9(Map baselineBuilders, Map deltaBuilders) { + + } + + public IoBuffer createBuffer(int size, boolean autoSize) { + return createBuffer(size).setAutoExpand(autoSize); + } + + public IoBuffer createBuffer(int size) { + return Baseline.createBuffer(size); + } + + public BaseObject getObject() { + return object; + } + + public void setObject(BaseObject object) { + this.object = object; + } + + protected byte getBoolean(boolean variable) { + return Baseline.getBoolean(variable); + } + + protected String getAsciiString(ByteBuffer buffer) { + return StringUtilities.getAsciiString(buffer); + } + + protected String getUnicodeString(ByteBuffer buffer) { + return StringUtilities.getUnicodeString(buffer); + } + + protected byte[] getAsciiString(String string) { + return StringUtilities.getAsciiString(string); + } + + protected byte[] getUnicodeString(String string) { + return StringUtilities.getUnicodeString(string); + } + +} diff --git a/src/resources/z/exp/objects/SWGList.java b/src/resources/z/exp/objects/SWGList.java new file mode 100644 index 00000000..5e1883ec --- /dev/null +++ b/src/resources/z/exp/objects/SWGList.java @@ -0,0 +1,410 @@ +/******************************************************************************* + * 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.z.exp.objects; + +import java.nio.ByteOrder; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.apache.mina.core.buffer.IoBuffer; + +import resources.objects.IDelta; +import resources.z.exp.objects.object.BaseObject; + +import com.sleepycat.persist.model.NotPersistent; +import com.sleepycat.persist.model.Persistent; + +/* A SWGList element should extend Delta or implement IDelta */ + +@Persistent +public class SWGList implements List { + + private List list = new CopyOnWriteArrayList(); + @NotPersistent + private int updateCounter = 0; + private BaseObject object; + private byte viewType; + private short updateType; + private boolean addByte; + @NotPersistent + protected final Object objectMutex = new Object(); + + public SWGList() { } + + public SWGList(BaseObject object, int viewType, int updateType, boolean addByte) { + this.object = object; + this.viewType = (byte) viewType; + this.updateType = (short) updateType; + this.addByte = addByte; + } + + public boolean add(E e) { + synchronized(objectMutex) { + if (valid(e) && list.add(e)) { + queue(item(1, list.lastIndexOf(e), Baseline.toBytes(e), true, true)); + return true; + } + + return false; + } + } + + public void add(int index, E element) { + synchronized(objectMutex) { + if (valid(element)) { + list.add(index, element); + queue(item(1, index, Baseline.toBytes(element), true, true)); + } + } + } + + public boolean addAll(Collection c) { + synchronized(objectMutex) { + if (!c.isEmpty()) { + List buffer = new ArrayList(); + boolean success = false; + + for (E element : c) { + if (valid(element)) { + if (list.add(element)) { + buffer.add(item(1, list.lastIndexOf(element), Baseline.toBytes(element), true, true)); + success = true; + } + } else { + return false; + } + } + + if (success == true) { + queue(buffer); + } else { + return false; + } + } + + return false; + } + } + + public boolean addAll(int index, Collection c) { + synchronized(objectMutex) { + if (!c.isEmpty()) { + List buffer = new ArrayList(); + + for (E element : c) { + if (valid(element)) { + list.add(index, element); + buffer.add(item(1, index, Baseline.toBytes(element), true, true)); + index++; + } else { + return false; + } + } + + queue(buffer); + + return true; + } + + return false; + } + } + + public void clear() { + synchronized(objectMutex) { + list.clear(); + queue(item(4, 0, null, false, false)); + } + } + + public boolean contains(Object o) { + synchronized(objectMutex) { + return list.contains(o); + } + } + + public boolean containsAll(Collection c) { + synchronized(objectMutex) { + return list.containsAll(c); + } + } + + public E get(int index) { + synchronized(objectMutex) { + return list.get(index); + } + } + + public List get() { + return list; + } + + public int indexOf(Object o) { + synchronized(objectMutex) { + return list.indexOf(o); + } + } + + public boolean isEmpty() { + synchronized(objectMutex) { + return list.isEmpty(); + } + } + + public Iterator iterator() { + synchronized(objectMutex) { + return list.iterator(); + } + } + + public int lastIndexOf(Object o) { + synchronized(objectMutex) { + return list.lastIndexOf(o); + } + } + + public ListIterator listIterator() { + synchronized(objectMutex) { + return list.listIterator(); + } + } + + public ListIterator listIterator(int index) { + synchronized(objectMutex) { + return listIterator(index); + } + } + + public boolean remove(Object o) { + synchronized(objectMutex) { + int index = list.indexOf(o); + + if (list.remove(o)) { + queue(item(1, index, null, true, false)); + return true; + } else { + return false; + } + } + } + + public E remove(int index) { + synchronized(objectMutex) { + E element = list.remove(index); + + queue(item(1, index, null, true, false)); + + return (E) element; + } + } + + public boolean removeAll(Collection c) { + synchronized(objectMutex) { + if (!c.isEmpty()) { + List buffer = new ArrayList(); + int index; + boolean success = false; + + for (Object element : c) { + index = list.indexOf(element); + + if (list.remove(element)) { + buffer.add(item(0, index, null, true, false)); + success = true; + } + } + + if (success) { + queue(buffer); + } + + return success; + } + + return false; + } + } + + public boolean retainAll(Collection c) { + synchronized(objectMutex) { + return list.retainAll(c); + } + } + + public E set(int index, E element) { + synchronized(objectMutex) { + if (valid(element)) { + E previousElement = list.set(index, element); + + queue(item(2, index, Baseline.toBytes(element), true, true)); + + return previousElement; + } + + return null; + } + } + + public boolean set(List list) { + synchronized(objectMutex) { + byte[] newListData = { 0x03 }; + + if (!list.isEmpty()) { + for (E element : list) { + if (valid(element)) { + IoBuffer buffer = IoBuffer.allocate((newListData.length + Baseline.toBytes(element).length), false).order(ByteOrder.LITTLE_ENDIAN); + buffer.put(newListData); + buffer.put(Baseline.toBytes(element)); + newListData = buffer.array(); + } else { + return false; + } + } + + this.list = list; + + updateCounter++; + queue(newListData); + + return true; + } + + return false; + } + } + + public int size() { + synchronized(objectMutex) { + return list.size(); + } + } + + public List subList(int fromIndex, int toIndex) { + synchronized(objectMutex) { + return list.subList(fromIndex, toIndex); + } + } + + public Object[] toArray() { + synchronized(objectMutex) { + return list.toArray(); + } + } + + public T[] toArray(T[] a) { + synchronized(objectMutex) { + return list.toArray(a); + } + } + + public int getUpdateCounter() { + synchronized(objectMutex) { + return updateCounter; + } + } + + public Object getMutex() { + return objectMutex; + } + + public byte[] getBytes() { + synchronized(objectMutex) { + byte[] objects = { }; + int size = 0; + + for (Object o : list) { + byte[] object = Baseline.toBytes(o); + size += object.length; + + IoBuffer buffer = Baseline.createBuffer(size); + buffer.put(objects); + if (addByte) buffer.put((byte) 0); + buffer.put(object); + buffer.flip(); + + objects = buffer.array(); + } + + IoBuffer buffer = Baseline.createBuffer(8 + size); + buffer.putInt(list.size()); + buffer.putInt(updateCounter); + buffer.put(objects); + buffer.flip(); + + return buffer.array(); + } + } + + private boolean valid(Object o) { + if (o instanceof String || o instanceof Byte || o instanceof Short || + o instanceof Integer || o instanceof Float || o instanceof Long || + o instanceof IDelta) { + return true; + } else { + return false; + } + } + + private byte[] item(int type, int index, byte[] data, boolean useIndex, boolean useData) { + int size = 1 + ((useIndex) ? 2 : 0) + ((useData) ? data.length : 0); + + IoBuffer buffer = IoBuffer.allocate((size), false).order(ByteOrder.LITTLE_ENDIAN); + buffer.put((byte) type); + if (useIndex) buffer.putShort((short) index); + if (useData) buffer.put(data); + buffer.flip(); + + updateCounter++; + + return buffer.array(); + } + + private void queue(byte[] data) { + IoBuffer buffer = IoBuffer.allocate((data.length + 8), false).order(ByteOrder.LITTLE_ENDIAN); + buffer.putInt(1); + buffer.putInt(updateCounter); + buffer.put(data); + buffer.flip(); + object.sendListDelta(viewType, updateType, buffer); + } + + private void queue(List data) { + int size = 0; + + for (byte[] queued : data) { + size += queued.length; + } + + IoBuffer buffer = IoBuffer.allocate((size + 8), false).order(ByteOrder.LITTLE_ENDIAN); + buffer.putInt(data.size()); + buffer.putInt(updateCounter); + for (byte[] queued : data) buffer.put(queued); + buffer.flip(); + + object.sendListDelta(viewType, updateType, buffer); + } + +} diff --git a/src/resources/z/exp/objects/SWGMap.java b/src/resources/z/exp/objects/SWGMap.java new file mode 100644 index 00000000..663d3fd3 --- /dev/null +++ b/src/resources/z/exp/objects/SWGMap.java @@ -0,0 +1,279 @@ +/******************************************************************************* + * 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.z.exp.objects; + +import java.nio.ByteOrder; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; + +import org.apache.mina.core.buffer.IoBuffer; + +import resources.objects.IDelta; +import resources.z.exp.objects.object.BaseObject; + +import com.sleepycat.persist.model.NotPersistent; +import com.sleepycat.persist.model.Persistent; + +/* A SWGMap element should extend Delta or implement IDelta */ + +@Persistent +public class SWGMap implements Map { + + private Map map = new TreeMap(); + @NotPersistent + private int updateCounter = 0; + private BaseObject object; + private byte viewType; + private short updateType; + private boolean addByte; + @NotPersistent + protected final Object objectMutex = new Object(); + + public SWGMap() { } + + public SWGMap(BaseObject object, int viewType, int updateType, boolean addByte) { + this.object = object; + this.viewType = (byte) viewType; + this.updateType = (short) updateType; + this.addByte = addByte; + } + + public SWGMap(Map m) { + if (m instanceof SWGMap) { + this.object = ((SWGMap) m).object; + this.viewType = ((SWGMap) m).viewType; + this.updateType = ((SWGMap) m).updateType; + map.putAll(m); + } + } + + public void clear() { + throw new UnsupportedOperationException(); + } + + public boolean containsKey(Object key) { + synchronized(objectMutex) { + return map.containsKey(key); + } + } + + public boolean containsValue(Object value) { + synchronized(objectMutex) { + return map.containsValue(value); + } + } + + public Set> entrySet() { + synchronized(objectMutex) { + return map.entrySet(); + } + } + + public V get(Object key) { + return map.get(key); + } + + public boolean isEmpty() { + synchronized(objectMutex) { + return map.isEmpty(); + } + } + + public Set keySet() { + synchronized(objectMutex) { + return map.keySet(); + } + } + + public V put(K key, V value) { + synchronized(objectMutex) { + if (valid(key) && valid(value)) { + if (map.containsKey(key)) { + V oldValue = map.put(key, value); + + queue(item(2, key, Baseline.toBytes(value), true, true)); + + return oldValue; + } else { + V oldValue = map.put(key, value); + + queue(item(0, key, Baseline.toBytes(value), true, true)); + + return oldValue; + } + } + + return null; + } + } + + public void putAll(Map m) { + synchronized(objectMutex) { + List buffer = new ArrayList(); + + for (Entry entry : m.entrySet()) { + K key = entry.getKey(); + V value = entry.getValue(); + + if (valid(key) && valid(value)) { + if (map.containsKey(key)) { + if (map.put(key, value) != null) { + buffer.add(item(2, key, Baseline.toBytes(value), true, true)); + } + } else { + if (map.put(key, value) != null) { + buffer.add(item(0, key, Baseline.toBytes(value), true, true)); + } + } + } + } + + if (buffer.size() > 0) { + queue(buffer); + } + } + } + + public V remove(Object key) { + synchronized(objectMutex) { + if (valid(key)) { + V value = map.remove(key); + + queue(item(1, key, Baseline.toBytes(map.get(key)), true, true)); + + return value; + } + + return null; + } + } + + public int size() { + synchronized(objectMutex) { + return map.size(); + } + } + + public Collection values() { + synchronized(objectMutex) { + return map.values(); + } + } + + public int getUpdateCounter() { + synchronized(objectMutex) { + return updateCounter; + } + } + + public Object getMutex() { + return objectMutex; + } + + public byte[] getBytes() { + synchronized(objectMutex) { + byte[] objects = { }; + int size = 0; + + for (Entry entry : map.entrySet()) { + byte[] key = Baseline.toBytes(entry.getKey()); + byte[] value = Baseline.toBytes(entry.getValue()); + size += ((addByte) ? 1 : 0) + key.length + value.length; + + IoBuffer buffer = Baseline.createBuffer(size); + buffer.put(objects); + if (addByte) buffer.put((byte) 0); + buffer.put(key); + buffer.put(value); + buffer.flip(); + + objects = buffer.array(); + } + + IoBuffer buffer = Baseline.createBuffer(8 + size); + buffer.putInt(map.size()); + buffer.putInt(updateCounter); + buffer.put(objects); + buffer.flip(); + + return buffer.array(); + } + } + + private boolean valid(Object o) { + if (o instanceof String || o instanceof Byte || o instanceof Short || + o instanceof Integer || o instanceof Float || o instanceof Long || + o instanceof IDelta) { + return true; + } else { + return false; + } + } + + private byte[] item(int type, Object index, byte[] data, boolean useIndex, boolean useData) { + if (useIndex && ((index instanceof IDelta) || !valid(index))) { + throw new IllegalArgumentException(); + } + + int size = 1 + ((useIndex) ? (2 + Baseline.toBytes(index).length) : 0) + ((useData) ? data.length : 0); + + IoBuffer buffer = IoBuffer.allocate(size, false).order(ByteOrder.LITTLE_ENDIAN); + buffer.put((byte) type); + if (useIndex) buffer.put(Baseline.toBytes(index)); + if (useData) buffer.put(data); + buffer.flip(); + + updateCounter++; + + return buffer.array(); + } + + private void queue(byte[] data) { + IoBuffer buffer = IoBuffer.allocate(data.length + 8, false).order(ByteOrder.LITTLE_ENDIAN); + buffer.putInt(1); + buffer.putInt(updateCounter); + buffer.put(data); + buffer.flip(); + object.sendListDelta(viewType, updateType, buffer); + } + + private void queue(List data) { + int size = 0; + + for (byte[] queued : data) { + size += queued.length; + } + + IoBuffer buffer = IoBuffer.allocate((size + 8), false).order(ByteOrder.LITTLE_ENDIAN); + buffer.putInt(data.size()); + buffer.putInt(updateCounter); + for (byte[] queued : data) buffer.put(queued); + buffer.flip(); + + object.sendListDelta(viewType, updateType, buffer); + } + +} diff --git a/src/resources/z/exp/objects/SWGMultiMap.java b/src/resources/z/exp/objects/SWGMultiMap.java new file mode 100644 index 00000000..3a63d514 --- /dev/null +++ b/src/resources/z/exp/objects/SWGMultiMap.java @@ -0,0 +1,382 @@ +/******************************************************************************* + * 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.z.exp.objects; + +import java.nio.ByteOrder; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.TreeMap; + +import org.apache.mina.core.buffer.IoBuffer; +import org.python.google.common.collect.ArrayListMultimap; +import org.python.google.common.collect.Multimap; +import org.python.google.common.collect.Multiset; +import org.python.google.common.collect.Ordering; +import org.python.google.common.collect.TreeMultimap; + +import resources.common.StringUtilities; +import resources.objects.IDelta; +import resources.z.exp.objects.object.BaseObject; + +import com.sleepycat.persist.model.NotPersistent; +import com.sleepycat.persist.model.Persistent; + +@SuppressWarnings("unused") + +@Persistent +public class SWGMultiMap implements Multimap { + + private Multimap map = ArrayListMultimap.create(); + @NotPersistent + private int updateCounter = 0; + private BaseObject object; + private byte viewType; + private short updateType; + private boolean addByte; + @NotPersistent + protected final Object objectMutex = new Object(); + + public SWGMultiMap() { } + + public SWGMultiMap(BaseObject object, int viewType, int updateType, boolean addByte) { + this.object = object; + this.viewType = (byte) viewType; + this.updateType = (short) updateType; + this.addByte = addByte; + } + + public SWGMultiMap(Multimap m) { + if (m instanceof SWGMultiMap) { + this.object = ((SWGMultiMap) m).object; + this.viewType = ((SWGMultiMap) m).viewType; + this.updateType = ((SWGMultiMap) m).updateType; + map.putAll(m); + } + } + + public Map> asMap() { + synchronized(objectMutex) { + return map.asMap(); + } + } + + public void clear() { + throw new UnsupportedOperationException(); + } + + public boolean containsEntry(Object key, Object value) { + synchronized(objectMutex) { + return map.containsEntry(key, value); + } + } + + public boolean containsKey(Object key) { + synchronized(objectMutex) { + return map.containsKey(key); + } + } + + public boolean containsValue(Object value) { + synchronized(objectMutex) { + return map.containsValue(value); + } + } + + public Collection> entries() { + synchronized(objectMutex) { + return map.entries(); + } + } + + public Collection get(K key) { + synchronized(objectMutex) { + return map.get(key); + } + } + + public boolean isEmpty() { + synchronized(objectMutex) { + return map.isEmpty(); + } + } + + public Multiset keys() { + synchronized(objectMutex) { + return map.keys(); + } + } + + public Set keySet() { + synchronized(objectMutex) { + return map.keySet(); + } + } + + public boolean put(K key, V value) { + synchronized(objectMutex) { + if (key instanceof String || key instanceof Byte || key instanceof Short || + key instanceof Integer || key instanceof Float || key instanceof Long || + value instanceof IDelta) { + if (map.put(key, value)) { + queue(item(0, (String) key, ((IDelta) value).getBytes(), true, true)); + return true; + } + } + + return false; + } + } + + public boolean putAll(K key, Iterable values) { + synchronized(objectMutex) { + if (key instanceof String || key instanceof Byte || key instanceof Short || + key instanceof Integer || key instanceof Float || key instanceof Long) { + List buffer = new ArrayList(); + + for (V value : values) { + if (value instanceof IDelta) { + if (map.put(key, value)) { + buffer.add(item(0, (String) key, ((IDelta) value).getBytes(), true, true)); + } + } + } + + if (buffer.size() > 0) { + queue(buffer); + return true; + } + } + + return false; + } + } + + public boolean putAll(Multimap map) { + synchronized(objectMutex) { + List buffer = new ArrayList(); + + for (Entry entry : map.entries()) { + K key = entry.getKey(); + V value = entry.getValue(); + + if (key instanceof String || key instanceof Byte || key instanceof Short || + key instanceof Integer || key instanceof Float || key instanceof Long || + value instanceof IDelta) { + if (this.map.put(key, value)) { + buffer.add(item(0, (String) key, ((IDelta) value).getBytes(), true, true)); + } + } + } + + if (buffer.size() > 0) { + queue(buffer); + return true; + } + + return false; + } + } + + @SuppressWarnings("unchecked") + public boolean remove(Object key, Object value) { + synchronized(objectMutex) { + if (key instanceof String || key instanceof Byte || key instanceof Short || + key instanceof Integer || key instanceof Float || key instanceof Long) { + if (map.remove(key, value)) { + queue(item(1, (String) key, ((IDelta) map.get((K) key)).getBytes(), true, true)); + + return true; + } + } + + return false; + } + } + + @SuppressWarnings("unchecked") + public Collection removeAll(Object key) { + synchronized(objectMutex) { + if (key instanceof String || key instanceof Byte || key instanceof Short || + key instanceof Integer || key instanceof Float || key instanceof Long) { + Collection collection = map.get((K) key); + List buffer = new ArrayList(); + + for (V value : map.get((K) key)) { + if (map.remove(key, value)) { + buffer.add(item(1, (String) key, ((IDelta) map.get((K) key)).getBytes(), true, true)); + } + } + + if (buffer.size() > 0) { + queue(buffer); + return collection; + } + } + + return null; + } + } + + public Collection replaceValues(K key, Iterable values) { + synchronized(objectMutex) { + if (key instanceof String || key instanceof Byte || key instanceof Short || + key instanceof Integer || key instanceof Float || key instanceof Long) { + if (map.containsKey(key)) { + List buffer = new ArrayList(); + + for (V value : values) { + if (value instanceof IDelta) { + if (!map.get(key).contains(value)) { + buffer.add(item(2, (String) key, ((IDelta) value).getBytes(), true, true)); + } + } else { + return null; + } + } + + if (buffer.size() > 0) { + queue(buffer); + return map.replaceValues(key, values); + } + } + } + + return null; + } + } + + public int size() { + synchronized(objectMutex) { + return map.size(); + } + } + + public Collection values() { + synchronized(objectMutex) { + return map.values(); + } + } + + public int getUpdateCounter() { + synchronized(objectMutex) { + return updateCounter; + } + } + + public Object getMutex() { + return objectMutex; + } + + public byte[] getBytes() { + synchronized(objectMutex) { + byte[] objects = { }; + int size = 0; + + for (Entry entry : map.entries()) { + byte[] key = Baseline.toBytes(entry.getKey()); + byte[] value = Baseline.toBytes(entry.getValue()); + size += ((addByte) ? 1 : 0) + key.length + value.length; + + IoBuffer buffer = Baseline.createBuffer(size); + buffer.put(objects); + if (addByte) buffer.put((byte) 0); + buffer.put(key); + buffer.put(value); + buffer.flip(); + + objects = buffer.array(); + } + + IoBuffer buffer = Baseline.createBuffer(8 + size); + buffer.putInt(map.size()); + buffer.putInt(updateCounter); + buffer.put(objects); + buffer.flip(); + + return buffer.array(); + } + } + + private byte[] item(int type, Object index, byte[] data, boolean useIndex, boolean useData) { + if (useIndex && !(index instanceof Byte) && !(index instanceof Short) + && !(index instanceof Integer) && !(index instanceof Float) + && !(index instanceof Long) && !(index instanceof String)) { + throw new IllegalArgumentException(); + } + + int size = 1 + ((useIndex) ? (2 + index.toString().getBytes().length) : 0) + ((useData) ? data.length : 0); + + IoBuffer buffer = IoBuffer.allocate((size), false).order(ByteOrder.LITTLE_ENDIAN); + buffer.put((byte) type); + if (useIndex) { + if (index instanceof String) { + buffer.put(StringUtilities.getAsciiString((String) index)); + } else if (index instanceof Byte) { + buffer.put(((Byte) index).byteValue()); + } else if (index instanceof Short) { + buffer.putShort(((Short) index).shortValue()); + } else if (index instanceof Integer) { + buffer.putInt(((Integer) index).intValue()); + } else if (index instanceof Float) { + buffer.putFloat(((Float) index).floatValue()); + } else if (index instanceof Long) { + buffer.putLong(((Long) index).longValue()); + } else { + throw new IllegalArgumentException(); + } + } + if (useData) buffer.put(data); + + updateCounter++; + + return buffer.array(); + } + + private void queue(byte[] data) { + IoBuffer buffer = IoBuffer.allocate((data.length + 8), false).order(ByteOrder.LITTLE_ENDIAN); + buffer.putInt(1); + buffer.putInt(updateCounter); + buffer.put(data); + object.sendListDelta(viewType, updateType, buffer); + } + + private void queue(List data) { + int size = 0; + + for (byte[] queued : data) { + size += queued.length; + } + + IoBuffer buffer = IoBuffer.allocate((size + 8), false).order(ByteOrder.LITTLE_ENDIAN); + buffer.putInt(data.size()); + buffer.putInt(updateCounter); + for (byte[] queued : data) buffer.put(queued); + + object.sendListDelta(viewType, updateType, buffer); + } + +} diff --git a/src/resources/z/exp/objects/SWGSet.java b/src/resources/z/exp/objects/SWGSet.java new file mode 100644 index 00000000..a960c0f2 --- /dev/null +++ b/src/resources/z/exp/objects/SWGSet.java @@ -0,0 +1,280 @@ +/******************************************************************************* + * 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.z.exp.objects; + +import java.nio.ByteOrder; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +import org.apache.mina.core.buffer.IoBuffer; + +import resources.objects.IDelta; +import resources.z.exp.objects.object.BaseObject; + +import com.sleepycat.persist.model.NotPersistent; +import com.sleepycat.persist.model.Persistent; + +/* A SWGSet element should extend Delta or implement IDelta */ + +@Persistent +public class SWGSet implements Set { + + private TreeSet set = new TreeSet(); + @NotPersistent + private int updateCounter = 0; + private BaseObject object; + private byte viewType; + private short updateType; + private boolean addByte; + @NotPersistent + protected final Object objectMutex = new Object(); + + public SWGSet() { } + + public SWGSet(BaseObject object, int viewType, int updateType, boolean addByte) { + this.object = object; + this.viewType = (byte) viewType; + this.updateType = (short) updateType; + this.addByte = addByte; + } + + public SWGSet(Set s) { + if (s instanceof SWGSet) { + this.object = ((SWGSet) s).object; + this.viewType = ((SWGSet) s).viewType; + this.updateType = ((SWGSet) s).updateType; + set.addAll(s); + } + } + + public boolean add(E e) { + synchronized(objectMutex) { + if (valid(e)) { + if (set.add(e)) { + queue(item(1, e, null, true, false)); + return true; + } + } + + return false; + } + } + + public boolean addAll(Collection c) { + synchronized(objectMutex) { + List buffer = new ArrayList(); + + for (E e : c) { + if (valid(e) && set.add(e)) { + buffer.add(item(1, e, null, true, false)); + } + } + + if (buffer.size() > 0) { + queue(buffer); + return true; + } else { + return false; + } + } + } + + public void clear() { + synchronized(objectMutex) { + queue(item(2, null, null, false, false)); + } + } + + public boolean contains(Object o) { + synchronized(objectMutex) { + return set.contains(o); + } + } + + public boolean containsAll(Collection c) { + synchronized(objectMutex) { + return set.containsAll(c); + } + } + + public boolean isEmpty() { + synchronized(objectMutex) { + return set.isEmpty(); + } + } + + public Iterator iterator() { + synchronized(objectMutex) { + return set.iterator(); + } + } + + public boolean remove(Object e) { + synchronized(objectMutex) { + if (valid(e) && set.remove(e)) { + queue(item(0, e, null, true, false)); + return true; + } + + return false; + } + } + + public boolean removeAll(Collection c) { + synchronized(objectMutex) { + List buffer = new ArrayList(); + + for (Object o : c) { + if (valid(o) && set.remove(o)) { + buffer.add(item(0, o, null, true, false)); + } + } + + if (buffer.size() > 0) { + queue(buffer); + return true; + } else { + return false; + } + } + } + + public boolean retainAll(Collection c) { + synchronized(objectMutex) { + return set.retainAll(c); + } + } + + public int size() { + synchronized(objectMutex) { + return set.size(); + } + } + + public Object[] toArray() { + synchronized(objectMutex) { + return set.toArray(); + } + } + + public T[] toArray(T[] a) { + synchronized(objectMutex) { + return set.toArray(a); + } + } + + public int getUpdateCounter() { + synchronized(objectMutex) { + return updateCounter; + } + } + + public Object getMutex() { + return objectMutex; + } + + public byte[] getBytes() { + synchronized(objectMutex) { + byte[] objects = { }; + int size = 0; + + for (Object o : set) { + byte[] object = Baseline.toBytes(o); + size += object.length; + + IoBuffer buffer = Baseline.createBuffer(size); + buffer.put(objects); + if (addByte) buffer.put((byte) 0); + buffer.put(object); + buffer.flip(); + + objects = buffer.array(); + } + + IoBuffer buffer = Baseline.createBuffer(8 + size); + buffer.putInt(set.size()); + buffer.putInt(updateCounter); + buffer.put(objects); + buffer.flip(); + + return buffer.array(); + } + } + + private boolean valid(Object o) { + if (o instanceof String || o instanceof Byte || o instanceof Short || + o instanceof Integer || o instanceof Float || o instanceof Long || + o instanceof IDelta) { + return true; + } else { + return false; + } + } + + private byte[] item(int type, Object index, byte[] data, boolean useIndex, boolean useData) { + if (useIndex && ((index instanceof IDelta) || !valid(index))) { + throw new IllegalArgumentException(); + } + + int size = 1 + ((useIndex) ? (2 + Baseline.toBytes(index).length) : 0) + ((useData) ? data.length : 0); + + IoBuffer buffer = IoBuffer.allocate(size, false).order(ByteOrder.LITTLE_ENDIAN); + buffer.put((byte) type); + if (useIndex) buffer.put(Baseline.toBytes(index)); + if (useData) buffer.put(data); + buffer.flip(); + + updateCounter++; + + return buffer.array(); + } + + private void queue(byte[] data) { + IoBuffer buffer = IoBuffer.allocate((data.length + 8), false).order(ByteOrder.LITTLE_ENDIAN); + buffer.putInt(1); + buffer.putInt(updateCounter); + buffer.put(data); + buffer.flip(); + object.sendListDelta(viewType, updateType, buffer); + } + + private void queue(List data) { + int size = 0; + + for (byte[] queued : data) { + size += queued.length; + } + + IoBuffer buffer = IoBuffer.allocate((size + 8), false).order(ByteOrder.LITTLE_ENDIAN); + buffer.putInt(data.size()); + buffer.putInt(updateCounter); + for (byte[] queued : data) buffer.put(queued); + buffer.flip(); + + object.sendListDelta(viewType, updateType, buffer); + } + +} diff --git a/src/resources/z/exp/objects/building/BuildingMessageBuilder.java b/src/resources/z/exp/objects/building/BuildingMessageBuilder.java new file mode 100644 index 00000000..b6905d33 --- /dev/null +++ b/src/resources/z/exp/objects/building/BuildingMessageBuilder.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * 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.z.exp.objects.building; + +import java.util.Map; + +import resources.z.exp.objects.Builder; +import resources.z.exp.objects.tangible.TangibleMessageBuilder; + +public class BuildingMessageBuilder extends TangibleMessageBuilder { + + public BuildingMessageBuilder(BuildingObject object) { + super(object); + } + + public BuildingMessageBuilder() { + super(); + } + + @Override + public void buildBaseline3(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline3(deltaBuilders, deltaBuilders); + } + + @Override + public void buildBaseline6(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline6(deltaBuilders, deltaBuilders); + } + +} diff --git a/src/resources/z/exp/objects/building/BuildingObject.java b/src/resources/z/exp/objects/building/BuildingObject.java new file mode 100644 index 00000000..578c0dd7 --- /dev/null +++ b/src/resources/z/exp/objects/building/BuildingObject.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * 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.z.exp.objects.building; + +import org.apache.mina.core.buffer.IoBuffer; + +import resources.z.exp.objects.Baseline; +import resources.z.exp.objects.tangible.TangibleObject; + +import com.sleepycat.persist.model.Entity; +import com.sleepycat.persist.model.NotPersistent; + +import engine.clients.Client; +import engine.resources.scene.Planet; +import engine.resources.scene.Point3D; +import engine.resources.scene.Quaternion; + +@Entity +public class BuildingObject extends TangibleObject { + + @NotPersistent + private BuildingMessageBuilder messageBuilder; + + public BuildingObject(long objectID, Planet planet, Point3D position, Quaternion orientation, String Template) { + super(objectID, planet, position, orientation, Template); + setVolume(255); + setOptionsBitmask(256); + setMaximumCondition(4320); + toggleStatic(); + } + + public BuildingObject() { + super(); + } + + @Override + public void initializeBaselines() { + super.initializeBaselines(); + } + + @Override + public Baseline getOtherVariables() { + Baseline baseline = super.getOtherVariables(); + return baseline; + } + + @Override + public Baseline getBaseline3() { + Baseline baseline = super.getBaseline3(); + return baseline; + } + + @Override + public Baseline getBaseline6() { + Baseline baseline = super.getBaseline6(); + return baseline; + } + + @Override + public void notifyClients(IoBuffer buffer, boolean notifySelf) { + notifyObservers(buffer, false); + } + + @Override + public BuildingMessageBuilder getMessageBuilder() { + synchronized(objectMutex) { + if (messageBuilder == null) { + messageBuilder = new BuildingMessageBuilder(this); + } + + return messageBuilder; + } + } + + @Override + public void sendBaselines(Client destination) { + if (destination != null && destination.getSession() != null) { + //destination.getSession().write(baseline3.getBaseline()); + //destination.getSession().write(baseline6.getBaseline()); + } + } + +} diff --git a/src/resources/z/exp/objects/cell/CellMessageBuilder.java b/src/resources/z/exp/objects/cell/CellMessageBuilder.java new file mode 100644 index 00000000..92e25457 --- /dev/null +++ b/src/resources/z/exp/objects/cell/CellMessageBuilder.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * 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.z.exp.objects.cell; + +import java.util.Map; + +import resources.z.exp.objects.Builder; +import resources.z.exp.objects.ObjectMessageBuilder; + +public class CellMessageBuilder extends ObjectMessageBuilder { + + public CellMessageBuilder(CellObject object) { + super(object); + } + + public CellMessageBuilder() { + super(); + } + + @Override + public void buildBaseline3(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline3(baselineBuilders, deltaBuilders); + } + + @Override + public void buildBaseline6(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline6(baselineBuilders, deltaBuilders); + } + + @Override + public void buildBaseline8(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline8(baselineBuilders, deltaBuilders); + } + + @Override + public void buildBaseline9(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline9(baselineBuilders, deltaBuilders); + } + +} diff --git a/src/resources/z/exp/objects/cell/CellObject.java b/src/resources/z/exp/objects/cell/CellObject.java new file mode 100644 index 00000000..059c8d3d --- /dev/null +++ b/src/resources/z/exp/objects/cell/CellObject.java @@ -0,0 +1,137 @@ +/******************************************************************************* + * 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.z.exp.objects.cell; + +import org.apache.mina.core.buffer.IoBuffer; + +import resources.z.exp.objects.Baseline; +import resources.z.exp.objects.object.BaseObject; + +import com.sleepycat.persist.model.NotPersistent; +import com.sleepycat.persist.model.Persistent; + +import engine.clients.Client; +import engine.resources.scene.Planet; +import engine.resources.scene.Point3D; +import engine.resources.scene.Quaternion; + +@Persistent +public class CellObject extends BaseObject { + + @NotPersistent + CellMessageBuilder messageBuilder; + + public CellObject(long objectID, Planet planet, int cellNumber) { + super(objectID, planet, new Point3D(0, 0, 0), new Quaternion(0, 0, 0, 1), "object/cell/shared_cell.iff"); + setCellNumber(cellNumber); + } + + public CellObject(long objectID, Planet planet) { + super(objectID, planet, new Point3D(0, 0, 0), new Quaternion(0, 0, 0, 1), "object/cell/shared_cell.iff"); + } + + public CellObject() { + super(); + } + + @Override + public void initializeBaselines() { + super.initializeBaselines(); + initializeBaseline(8); + initializeBaseline(9); + } + + @Override + public Baseline getOtherVariables() { + Baseline baseline = super.getOtherVariables(); + return baseline; + } + + @Override + public Baseline getBaseline3() { + Baseline baseline = super.getBaseline3(); + baseline.put("4", (byte) 1); // Unknown + baseline.put("cellNumber", 0); + return baseline; + } + + @Override + public Baseline getBaseline6() { + Baseline baseline = super.getBaseline6(); + baseline.put("2", (long) 0); // Unknown + baseline.put("3", (long) 0); // Unknown + return baseline; + } + + @Override + public Baseline getBaseline8() { + Baseline baseline = super.getBaseline8(); + return baseline; + } + + @Override + public Baseline getBaseline9() { + Baseline baseline = super.getBaseline9(); + return baseline; + } + + public int getCellNumber() { + return (int) baseline3.get("cellNumber"); + } + + public void setCellNumber(int cellNumber) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("cellNumber", cellNumber); + } + + getContainer().notifyObservers(buffer, false); + } + + @Override + public void notifyClients(IoBuffer buffer, boolean notifySelf) { + getContainer().notifyObservers(buffer, false); + } + + @Override + public CellMessageBuilder getMessageBuilder() { + synchronized(objectMutex) { + if (messageBuilder == null) { + messageBuilder = new CellMessageBuilder(); + } + + return messageBuilder; + } + } + + @Override + public void sendBaselines(Client destination) { + if (destination != null && destination.getSession() != null) { + //destination.getSession().write(baseline3.getBaseline()); + //destination.getSession().write(baseline6.getBaseline()); + //destination.getSession().write(baseline8.getBaseline()); + //destination.getSession().write(baseline9.getBaseline()); + } + } + +} diff --git a/src/resources/z/exp/objects/creature/CreatureMessageBuilder.java b/src/resources/z/exp/objects/creature/CreatureMessageBuilder.java new file mode 100644 index 00000000..d76e8383 --- /dev/null +++ b/src/resources/z/exp/objects/creature/CreatureMessageBuilder.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * 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.z.exp.objects.creature; + +import java.util.Map; + +import com.sleepycat.persist.model.Persistent; + +import resources.z.exp.objects.Builder; +import resources.z.exp.objects.tangible.TangibleMessageBuilder; + +@Persistent +public class CreatureMessageBuilder extends TangibleMessageBuilder { + + public CreatureMessageBuilder(CreatureObject creatureObject) { + super(creatureObject); + } + + public CreatureMessageBuilder() { + super(); + } + + @Override + public void buildBaseline1(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline1(baselineBuilders, deltaBuilders); + } + + @Override + public void buildBaseline3(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline3(baselineBuilders, deltaBuilders); + } + + @Override + public void buildBaseline4(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline4(baselineBuilders, deltaBuilders); + } + + @Override + public void buildBaseline6(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline6(baselineBuilders, deltaBuilders); + } + + @Override + public void buildBaseline8(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline8(baselineBuilders, deltaBuilders); + } + + @Override + public void buildBaseline9(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline9(baselineBuilders, deltaBuilders); + } + +} diff --git a/src/resources/z/exp/objects/creature/CreatureObject.java b/src/resources/z/exp/objects/creature/CreatureObject.java new file mode 100644 index 00000000..511875ea --- /dev/null +++ b/src/resources/z/exp/objects/creature/CreatureObject.java @@ -0,0 +1,1086 @@ +/******************************************************************************* + * 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.z.exp.objects.creature; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map.Entry; + +import org.apache.mina.core.buffer.IoBuffer; + +import protocol.swg.ChatSystemMessage; +import protocol.swg.ObjControllerMessage; +import protocol.swg.UpdatePVPStatusMessage; +import protocol.swg.UpdatePostureMessage; +import protocol.swg.objectControllerObjects.Posture; + +import com.sleepycat.je.Environment; +import com.sleepycat.je.Transaction; +import com.sleepycat.persist.model.Entity; +import com.sleepycat.persist.model.NotPersistent; + +import engine.clients.Client; +import resources.z.exp.buffs.Buff; +import resources.common.StringUtilities; +import resources.z.exp.equipment.Equipment; +import resources.z.exp.group.GroupInviteInfo; +import resources.z.exp.objects.Baseline; +import resources.z.exp.objects.SWGList; +import resources.z.exp.objects.SWGMap; +import resources.z.exp.objects.SWGSet; +import engine.resources.common.CRC; +import engine.resources.objects.IPersistent; +import engine.resources.objects.SWGObject; +import resources.z.exp.skills.SkillMod; +import engine.resources.scene.Planet; +import engine.resources.scene.Point3D; +import engine.resources.scene.Quaternion; + +import resources.z.exp.objects.player.PlayerObject; +import resources.z.exp.objects.tangible.TangibleObject; + +@Entity +public class CreatureObject extends TangibleObject implements IPersistent { + + @NotPersistent + private Transaction txn; + + @NotPersistent + private CreatureMessageBuilder messageBuilder; + + // non-baseline vars + @NotPersistent + private List duelList = Collections.synchronizedList(new ArrayList()); + + public CreatureObject(long objectID, Planet planet, Point3D position, Quaternion orientation, String Template) { + super(objectID, planet, position, orientation, Template); + getBaseHAMList().add(0x00002FF8); + getBaseHAMList().add(0x000003E8); + getBaseHAMList().add(0x0000245F); + getBaseHAMList().add(0x000001F4); + getBaseHAMList().add(0x0000012C); + getBaseHAMList().add(0x000003E8); + setVolume(0x000F4240); + getComponentCustomizationList().add(0); + setOptionsBitmask(0x80); + setMaximumCondition(0x3A98); + getHamList().add(20000); + getHamList().add(0); + getHamList().add(12500); + getHamList().add(0); + getHamList().add(0x2C01); + getHamList().add(0); + getMaxHamList().add(20000); + getMaxHamList().add(0); + getMaxHamList().add(12500); + getMaxHamList().add(0); + getMaxHamList().add(0x2C01); + getMaxHamList().add(0); + getBuffList().put(0, new Buff("", 0)); // Initial Default Buff + } + + public CreatureObject() { + super(); + } + + @Override + public void initializeBaselines() { + super.initializeBaselines(); + initializeBaseline(1); + initializeBaseline(4); + } + + @Override + public Baseline getOtherVariables() { + Baseline baseline = super.getOtherVariables(); + return baseline; + } + + @Override + public Baseline getBaseline1() { + Baseline baseline = super.getBaseline1(); + baseline.put("bankCredits", 0); + baseline.put("cashCredits", 0); + baseline.put("baseHamList", new SWGList(this, 1, 2, false)); + baseline.put("skills", new SWGSet(this, 1, 3, false)); + return baseline; + } + + @Override + public Baseline getBaseline3() { + Baseline baseline = super.getBaseline3(); + baseline.put("posture", (byte) 1); + baseline.put("factionRank", (byte) 0); // For NPCs probably + baseline.put("ownerId", (long) 0); + baseline.put("height", (float) 1); + baseline.put("battleFatigue", 0); + baseline.put("stateBitmask", (long) 0); + return baseline; + } + + @Override + public Baseline getBaseline4() { + Baseline baseline = super.getBaseline4(); + baseline.put("accelerationMultiplierBase", (float) 1); + baseline.put("accelerationMultiplierMod", (float) 1); + baseline.put("hamEncumberanceList", new SWGList(this, 4, 2, false)); + baseline.put("skillMods", new SWGMap(this, 4, 3, true)); + baseline.put("speedMultiplierBase", (float) 1); + baseline.put("speedMultiplierMod", (float) 1); + baseline.put("listenToId", (long) 0); + baseline.put("runSpeed", (float) 7.3); + baseline.put("slopeModAngle", (float) 1); + baseline.put("slopeModPercent", (float) 1); + baseline.put("turnRadius", (float) 1); + baseline.put("walkSpeed", (float) 2.75); + baseline.put("waterModPercent", (float) 1); + baseline.put("missionCriticalObjects", new SWGMap(this, 4, 13, false)); + baseline.put("abilities", new SWGMap(this, 4, 14, true)); + baseline.put("15", (byte) 0); // Unknown (been seen as 0xD4) + return baseline; + } + + @Override + public Baseline getBaseline6() { + Baseline baseline = super.getBaseline6(); + baseline.put("level", (short) 90); + baseline.put("9", (int) 0xD007); + baseline.put("currentAnimation", ""); + baseline.put("moodAnimation", "neutral"); + baseline.put("weaponId", (long) 0); + baseline.put("groupId", (long) 0); + baseline.put("groupInviteInfo", new GroupInviteInfo((long) 0, "")); + baseline.put("guildId", 0); + baseline.put("targetId", (long) 0); + baseline.put("moodId", (byte) 0); + baseline.put("performanceCounter", 0); + baseline.put("performanceId", 0); + baseline.put("20", new SWGList(this, 6, 20, false)); // Unknown List + baseline.put("hamList", new SWGList(this, 6, 21, false)); + baseline.put("maxHamList", new SWGList(this, 6, 22, false)); + baseline.put("equipmentList", new SWGList(this, 6, 23, false)); + baseline.put("costume", ""); + baseline.put("lockMovement", false); + baseline.put("buffList", new SWGMap(this, 6, 26, false)); + // need to build an 0x01 int after the bufflist + baseline.put("27", (short) 0); + baseline.put("hologramColor", -1); + baseline.put("29", (byte) 1); + baseline.put("30", (short) 0); + baseline.put("appearanceEquipmentList", new SWGList(this, 6, 31, false)); + baseline.put("32", 0); + baseline.put("33", (short) 0); + baseline.put("34", (short) 0); // there's 35 elements, so 2 of these = shorts + return baseline; + } + + @Override + public Baseline getBaseline8() { + Baseline baseline = super.getBaseline8(); + return baseline; + } + + @Override + public Baseline getBaseline9() { + Baseline baseline = super.getBaseline9(); + return baseline; + } + + public int getBankCredits() { + synchronized(objectMutex) { + return (int) baseline1.get("bankCredits"); + } + } + + public void setBankCredits(int bankCredits) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline1.set("bankCredits", bankCredits); + } + + if (getClient() != null && getClient().getSession() != null) { + getClient().getSession().write(buffer); + } + } + + public int getCashCredits() { + synchronized(objectMutex) { + return (int) baseline1.get("cashCredits"); + } + } + + public void setCashCredits(int cashCredits) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline1.set("cashCredits", cashCredits); + } + + if (getClient() != null && getClient().getSession() != null) { + getClient().getSession().write(buffer); + } + } + + @SuppressWarnings("unchecked") + public SWGList getBaseHAMList() { + return (SWGList) baseline1.get("baseHamList"); + } + + @SuppressWarnings("unchecked") + public SWGSet getSkills() { + return (SWGSet) baseline3.get("skills"); + } + + public void addSkill(String skill) { + if (!getSkills().contains(skill)) { + getSkills().add(skill); + } + } + + public void removeSkill(String skill) { + if (getSkills().contains(skill)) { + getSkills().remove(skill); + } + } + + public byte getPosture() { + synchronized(objectMutex) { + return (byte) baseline3.get("posture"); + } + } + + public void setPosture(byte posture) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("posture", posture); + } + + notifyObservers(buffer, true); + notifyObservers(new ObjControllerMessage(0x1B, new Posture(getObjectID(), posture)), true); + } + + public byte getFactionRank() { + synchronized(objectMutex) { + return (byte) baseline3.get("factionRank"); + } + } + + public void setFactionRank(byte factionRank) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("factionRank", factionRank); + } + + notifyObservers(buffer, true); + } + + public long getOwnerId() { + synchronized(objectMutex) { + return (long) baseline3.get("ownerId"); + } + } + + public void setOwnerId(long ownerId) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("ownerId", ownerId); + } + + notifyObservers(buffer, true); + } + + public float getHeight() { + synchronized(objectMutex) { + return (float) baseline3.get("height"); + } + } + + public void setHeight(float height) { + height = (((height < 0.7) || (height > 1.5)) ? 1 : height); + + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("height", height); + } + + notifyObservers(buffer, true); + } + + public int getBattleFatigue() { + synchronized(objectMutex) { + return (int) baseline3.get("battleFatigue"); + } + } + + public void setBattleFatigue(int battleFatigue) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("battleFatigue", battleFatigue); + } + + notifyObservers(buffer, true); + } + + public long getStateBitmask() { + synchronized(objectMutex) { + return (long) baseline3.get("stateBitmask"); + } + } + + public void setStateBitmask(long stateBitmask) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("stateBitmask", stateBitmask); + } + + notifyObservers(buffer, true); + } + + public float getAccelerationMultiplierBase() { + synchronized(objectMutex) { + return (float) baseline4.get("accelerationMultiplierBase"); + } + } + + public void setAccelerationMultiplierBase(float accelerationMultiplierBase) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline4.set("accelerationMultiplierBase", accelerationMultiplierBase); + } + + if (getClient() != null && getClient().getSession() != null) { + getClient().getSession().write(buffer); + } + } + + public float getAccelerationMultiplierMod() { + synchronized(objectMutex) { + return (float) baseline4.get("accelerationMultiplierMod"); + } + } + + public void setAccelerationMultiplierMod(float accelerationMultiplierMod) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline4.set("accelerationMultiplierMod", accelerationMultiplierMod); + } + + if (getClient() != null && getClient().getSession() != null) { + getClient().getSession().write(buffer); + } + } + + @SuppressWarnings("unchecked") + public SWGList getHamEncumberanceList() { + return (SWGList) baseline4.get("hamEncumberanceList"); + } + + @SuppressWarnings("unchecked") + public SWGMap getSkillMods() { + return (SWGMap) baseline4.get("skillMods"); + } + + public SkillMod getSkillMod(String name) { + synchronized(objectMutex) { + if (getSkillMods().containsKey(name) && getSkillMods().get(name) != null) { + return getSkillMods().get(name); + } + + return null; + } + } + + public void addSkillMod(String name, int base) { + if (!getSkillMods().containsKey(name)) { + getSkillMods().put(name, new SkillMod(base, 0)); + } else { + SkillMod mod = getSkillMods().get(name); + getSkillMods().put(name, new SkillMod(mod.getBase() + base, mod.getModifier())); + } + } + + public void deductSkillMod(String name, int base) { + if (getSkillMods().containsKey(name)) { + SkillMod mod = getSkillMods().get(name); + mod = new SkillMod(mod.getBase() - base, mod.getModifier()); + + if (mod.getBase() - base <= 0) { + removeSkillMod(name); + } else { + getSkillMods().put(name, mod); + } + } + } + + public void removeSkillMod(String name) { + getSkillMods().remove(name); + } + + public float getSpeedMultiplierBase() { + synchronized(objectMutex) { + return (float) baseline4.get("speedMultiplierBase"); + } + } + + public void setSpeedMultiplierBase(float speedMultiplierBase) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline4.set("speedMultiplierBase", speedMultiplierBase); + } + + if (getClient() != null && getClient().getSession() != null) { + getClient().getSession().write(buffer); + } + } + + public float getSpeedMultiplierMod() { + synchronized(objectMutex) { + return (float) baseline4.get("speedMultiplierMod"); + } + } + + public void setSpeedMultiplierMod(float speedMultiplierMod) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline4.set("speedMultiplierMod", speedMultiplierMod); + } + + if (getClient() != null && getClient().getSession() != null) { + getClient().getSession().write(buffer); + } + } + + public long getListenToId() { + synchronized(objectMutex) { + return (long) baseline4.get("listenToId"); + } + } + + public void setListenToId(long listenToId) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline4.set("listenToId", listenToId); + } + + if (getClient() != null && getClient().getSession() != null) { + getClient().getSession().write(buffer); + } + } + + public float getRunSpeed() { + synchronized(objectMutex) { + return (float) baseline4.get("runSpeed"); + } + } + + public void setRunSpeed(float runSpeed) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline4.set("runSpeed", runSpeed); + } + + if (getClient() != null && getClient().getSession() != null) { + getClient().getSession().write(buffer); + } + } + + public float getSlopeModAngle() { + synchronized(objectMutex) { + return (float) baseline4.get("slopeModAngle"); + } + } + + public void setSlopeModAngle(float slopeModAngle) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline4.set("slopeModAngle", slopeModAngle); + } + + if (getClient() != null && getClient().getSession() != null) { + getClient().getSession().write(buffer); + } + } + + public float getSlopeModPercent() { + synchronized(objectMutex) { + return (float) baseline4.get("slopeModPercent"); + } + } + + public void setSlopeModPercent(float slopeModPercent) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline4.set("slopeModPercent", slopeModPercent); + } + + if (getClient() != null && getClient().getSession() != null) { + getClient().getSession().write(buffer); + } + } + + public float getTurnRadius() { + synchronized(objectMutex) { + return (float) baseline4.get("turnRadius"); + } + } + + public void setTurnRadius(float turnRadius) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline4.set("turnRadius", turnRadius); + } + + if (getClient() != null && getClient().getSession() != null) { + getClient().getSession().write(buffer); + } + } + + public float getWalkSpeed() { + synchronized(objectMutex) { + return (float) baseline4.get("walkSpeed"); + } + } + + public void setWalkSpeed(float walkSpeed) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline4.set("walkSpeed", walkSpeed); + } + + if (getClient() != null && getClient().getSession() != null) { + getClient().getSession().write(buffer); + } + } + + public float getWaterModPercent() { + synchronized(objectMutex) { + return (float) baseline4.get("waterModPercent"); + } + } + + public void setWaterModPercent(float waterModPercent) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline4.set("waterModPercent", waterModPercent); + } + + if (getClient() != null && getClient().getSession() != null) { + getClient().getSession().write(buffer); + } + } + + @SuppressWarnings("unchecked") + public SWGMap getMissionCriticalObjects() { + return (SWGMap) baseline4.get("missionCriticalObjects"); + } + + @SuppressWarnings("unchecked") + public SWGMap getAbilities() { + return (SWGMap) baseline4.get("abilities"); + } + + public void addAbility(String abilityName) { + if (!getAbilities().containsKey(abilityName)) { + getAbilities().put(abilityName, 1); + } + } + + public void removeAbility(String abilityName) { + if (getAbilities().containsKey(abilityName)) { + getAbilities().remove(abilityName); + } + } + + public short getLevel() { + synchronized(objectMutex) { + return (short) baseline6.get("level"); + } + } + + public void setLevel(short level) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("level", level); + } + + notifyObservers(buffer, true); + } + + public String getCurrentAnimation() { + synchronized(objectMutex) { + return (String) baseline6.get("currentAnimation"); + } + } + + public void setCurrentAnimation(String currentAnimation) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("currentAnimation", currentAnimation); + } + + notifyObservers(buffer, true); + } + + public String getMoodAnimation() { + synchronized(objectMutex) { + return (String) baseline6.get("moodAnimation"); + } + } + + public void setMoodAnimation(String moodAnimation) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("moodAnimation", moodAnimation); + } + + notifyObservers(buffer, true); + } + + public long getWeaponId() { + synchronized(objectMutex) { + return (long) baseline6.get("weaponId"); + } + } + + public void setWeaponId(long weaponId) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("weaponId", weaponId); + } + + notifyObservers(buffer, true); + } + + public long getGroupId() { + synchronized(objectMutex) { + return (long) baseline6.get("groupId"); + } + } + + public void setGroupId(long groupId) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("groupId", groupId); + } + + notifyObservers(buffer, true); + } + + public GroupInviteInfo getGroupInviteInfo() { + return (GroupInviteInfo) baseline6.get("groupInviteInfo"); + } + + public long getInviteSenderId() { + synchronized(objectMutex) { + return getGroupInviteInfo().getSenderId(); + } + } + + public void setInviteSenderId(long inviteSenderId) { + synchronized(objectMutex) { + getGroupInviteInfo().setSender(inviteSenderId, getInviteSenderName()); + } + } + + public String getInviteSenderName() { + synchronized(objectMutex) { + return getGroupInviteInfo().getSenderName(); + } + } + + public void setInviteSenderName(String inviteSenderName) { + synchronized(objectMutex) { + getGroupInviteInfo().setSender(getInviteSenderId(), inviteSenderName); + } + } + + public long getInviteCounter() { + return 0; + } + + public void setInviteCounter(long inviteCounter) { + + } + + public void updateGroupInviteInfo() { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("groupInviteInfo", getGroupInviteInfo()); + } + + if (getClient() != null && getClient().getSession() != null) { + getClient().getSession().write(buffer); + } + } + + public int getGuildId() { + synchronized(objectMutex) { + return (int) baseline6.get("guildId"); + } + } + + public void setGuildId(int guildId) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("guildId", guildId); + } + + notifyObservers(buffer, true); + } + + public long getTargetId() { + synchronized(objectMutex) { + return (long) baseline6.get("targetId"); + } + } + + public void setTargetId(long targetId) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("targetId", targetId); + } + + notifyObservers(buffer, true); + } + + public byte getMoodId() { + synchronized(objectMutex) { + return (byte) baseline6.get("moodId"); + } + } + + public void setMoodId(byte moodId) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("moodId", moodId); + } + + notifyObservers(buffer, true); + } + + public int getPerformanceCounter() { + synchronized(objectMutex) { + return (int) baseline6.get("performanceCounter"); + } + } + + public void setPerformanceCounter(int performanceCounter) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("performanceCounter", performanceCounter); + } + + notifyObservers(buffer, true); + } + + public int getPerformanceId() { + synchronized(objectMutex) { + return (int) baseline6.get("performanceId"); + } + } + + public void setPerformanceId(int performanceId) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("performanceId", performanceId); + } + + notifyObservers(buffer, true); + } + + @SuppressWarnings("unchecked") + public SWGList getHamList() { + return (SWGList) baseline6.get("hamList"); + } + + public int getHealth() { + synchronized(objectMutex) { + return getHamList().get(0); + } + } + + public void setHealth(int health) { + if (health > getMaxHealth()) { + health = getMaxHealth(); + } + + synchronized(objectMutex) { + getHamList().set(0, health); + } + } + + public int getAction() { + synchronized(objectMutex) { + return getHamList().get(2); + } + } + + public void setAction(int action) { + if (action > getMaxAction()) { + action = getMaxAction(); + } + + synchronized(objectMutex) { + getHamList().set(2, action); + } + } + + @SuppressWarnings("unchecked") + public SWGList getMaxHamList() { + return (SWGList) baseline6.get("maxHamList"); + } + + public int getMaxHealth() { + synchronized(objectMutex) { + return getMaxHamList().get(0); + } + } + + public void setMaxHealth(int maxHealth) { + synchronized(objectMutex) { + getMaxHamList().set(0, maxHealth); + } + } + + public int getMaxAction() { + synchronized(objectMutex) { + return getMaxHamList().get(2); + } + } + + public void setMaxAction(int maxAction) { + synchronized(objectMutex) { + getMaxHamList().set(2, maxAction); + } + } + + @SuppressWarnings("unchecked") + public SWGList getEquipmentList() { + return (SWGList) baseline6.get("equipmentList"); + } + + public void equipObject(SWGObject object) { + if (object instanceof TangibleObject) { + getEquipmentList().add(new Equipment(object)); + } + } + + public void unequipObject(SWGObject object) { + if (object instanceof TangibleObject) { + for (Equipment equipment : getEquipmentList()) { + if (equipment.getObjectId() == object.getObjectId()) { + getEquipmentList().remove(equipment); + } + } + } + } + + @SuppressWarnings("unchecked") + public SWGMap getBuffList() { + return (SWGMap) baseline6.get("buffList"); + } + + public void addBuff(Buff buff) { + synchronized(objectMutex) { + PlayerObject player = (PlayerObject) this.getSlottedObject("ghost"); + buff.setTotalPlayTime((int) (player.getTotalPlayTime() + (System.currentTimeMillis() - player.getLastPlayTimeUpdate()) / 1000)); + } + + getBuffList().put(CRC.StringtoCRC(buff.getBuffName()), buff); + + synchronized(objectMutex) { + buff.setStartTime(); + } + } + + public void removeBuff(Buff buff) { + getBuffList().remove(CRC.StringtoCRC(buff.getBuffName())); + } + + public Buff getBuffByName(String buffName) { + for (Entry entry : getBuffList().entrySet()) { + if (entry.getKey().equals(CRC.StringtoCRC(buffName))) { + return entry.getValue(); + } + } + + return null; + } + + @SuppressWarnings("unchecked") + public SWGList getAppearanceEquipmentList() { + return (SWGList) baseline6.get("appearanceEquipmentList"); + } + + public void equipAppearance(SWGObject object) { + if (object instanceof TangibleObject) { + getAppearanceEquipmentList().add(new Equipment(object)); + } + } + + public void unequipAppearance(SWGObject object) { + if (object instanceof TangibleObject) { + for (Equipment equipment : getAppearanceEquipmentList()) { + if (equipment.getObjectId() == object.getObjectId()) { + getAppearanceEquipmentList().remove(equipment); + } + } + } + } + + public List getDuelList() { + return duelList; + } + + public boolean isInDuelList(long objectId) { + if (duelList.contains(objectId)) { + return true; + } + + return false; + } + + public boolean isInDuelList(SWGObject object) { + return isInDuelList(object.getObjectId()); + } + + @Override + public void notifyClients(IoBuffer buffer, boolean notifySelf) { + notifyObservers(buffer, notifySelf); + } + + @Override + public CreatureMessageBuilder getMessageBuilder() { + synchronized(objectMutex) { + if (messageBuilder == null) { + messageBuilder = new CreatureMessageBuilder(this); + } + + return messageBuilder; + } + } + + @SuppressWarnings("unused") + @Override + public void sendBaselines(Client destination) { + if (destination == null || destination.getSession() == null) { + System.out.println("NULL session"); + return; + } + + System.out.println(StringUtilities.bytesToHex(baseline3.getBaseline().array())); + destination.getSession().write(baseline3.getBaseline()); + //destination.getSession().write(baseline6.getBaseline()); + if (destination == getClient()) { + //destination.getSession().write(baseline1.getBaseline()); + //destination.getSession().write(baseline4.getBaseline()); + } + //destination.getSession().write(baseline8().getBaseline()); + //destination.getSession().write(baseline9().getBaseline()); + + UpdatePostureMessage upm = new UpdatePostureMessage(getObjectID(), (byte) 0); + //destination.getSession().write(upm.serialize()); + + if (destination != getClient()) { + UpdatePVPStatusMessage upvpm = new UpdatePVPStatusMessage(getObjectID()); + + int factionStatus = getFactionStatus(); + String faction = getFaction(); + + if (factionStatus == 1 && faction == "imperial") { + upvpm.setFaction(UpdatePVPStatusMessage.factionCRC.Imperial); + upvpm.setStatus(16); + } + + if (factionStatus == 1 && faction == "rebel") { + upvpm.setFaction(UpdatePVPStatusMessage.factionCRC.Rebel); + upvpm.setStatus(16); + } + + if (factionStatus == 2 && faction == "imperial") { + upvpm.setFaction(UpdatePVPStatusMessage.factionCRC.Imperial); + upvpm.setStatus(55); + } + + if (factionStatus == 2 && faction == "rebel") { + upvpm.setFaction(UpdatePVPStatusMessage.factionCRC.Rebel); + upvpm.setStatus(55); + } + + if (factionStatus == 0 && faction == "neutral") { + upvpm.setFaction(UpdatePVPStatusMessage.factionCRC.Neutral); + upvpm.setStatus(16); + } else { + upvpm.setFaction(UpdatePVPStatusMessage.factionCRC.Neutral); + upvpm.setStatus(16); + } + + destination.getSession().write(upvpm.serialize()); + } + } + + public void sendSystemMessage(String message, byte displayType) { + if (getClient() != null && getClient().getSession() != null) { + ChatSystemMessage systemMsg = new ChatSystemMessage(message, displayType); + getClient().getSession().write(systemMsg.serialize()); + } + } + + public Transaction getTransaction() { + return txn; + } + + public void createTransaction(Environment env) { + txn = env.beginTransaction(null, null); + } + +} diff --git a/src/resources/z/exp/objects/factorycrate/FactoryCrateMessageBuilder.java b/src/resources/z/exp/objects/factorycrate/FactoryCrateMessageBuilder.java new file mode 100644 index 00000000..a3558047 --- /dev/null +++ b/src/resources/z/exp/objects/factorycrate/FactoryCrateMessageBuilder.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * 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.z.exp.objects.factorycrate; + +public class FactoryCrateMessageBuilder { + +} diff --git a/src/resources/z/exp/objects/factorycrate/FactoryCrateObject.java b/src/resources/z/exp/objects/factorycrate/FactoryCrateObject.java new file mode 100644 index 00000000..e69c6c15 --- /dev/null +++ b/src/resources/z/exp/objects/factorycrate/FactoryCrateObject.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * 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.z.exp.objects.factorycrate; + +public class FactoryCrateObject { + +} diff --git a/src/resources/z/exp/objects/group/GroupMessageBuilder.java b/src/resources/z/exp/objects/group/GroupMessageBuilder.java new file mode 100644 index 00000000..807b0a2a --- /dev/null +++ b/src/resources/z/exp/objects/group/GroupMessageBuilder.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * 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.z.exp.objects.group; + +import java.util.Map; + +import resources.z.exp.objects.Builder; +import resources.z.exp.objects.universe.UniverseMessageBuilder; + +public class GroupMessageBuilder extends UniverseMessageBuilder { + + public GroupMessageBuilder(GroupObject groupObject) { + super(groupObject); + } + + public GroupMessageBuilder() { + super(); + } + + @Override + public void buildBaseline3(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline3(baselineBuilders, deltaBuilders); + } + + @Override + public void buildBaseline6(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline6(baselineBuilders, deltaBuilders); + } + +} diff --git a/src/resources/z/exp/objects/group/GroupObject.java b/src/resources/z/exp/objects/group/GroupObject.java new file mode 100644 index 00000000..30ddc659 --- /dev/null +++ b/src/resources/z/exp/objects/group/GroupObject.java @@ -0,0 +1,256 @@ +/******************************************************************************* + * 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.z.exp.objects.group; + +import org.apache.mina.core.buffer.IoBuffer; + +import com.sleepycat.persist.model.NotPersistent; + +import resources.z.exp.group.Member; +import resources.z.exp.group.MemberInfo; +import resources.z.exp.objects.Baseline; +import resources.z.exp.objects.SWGList; +import resources.z.exp.objects.creature.CreatureObject; +import resources.z.exp.objects.universe.UniverseObject; + +import engine.clients.Client; +import engine.resources.objects.SWGObject; +import engine.resources.scene.Point3D; +import engine.resources.scene.Quaternion; + +public class GroupObject extends UniverseObject { + + @NotPersistent + private GroupMessageBuilder messageBuilder; + + public GroupObject(long objectId) { + super(objectId, null, new Point3D(0, 0, 0), new Quaternion(0, 0, 0, 1), "object/group/shared_group_object.iff"); + } + + public GroupObject() { + super(); + } + + @Override + public void initializeBaselines() { + super.initializeBaselines(); + } + + @Override + public Baseline getOtherVariables() { + Baseline baseline = super.getOtherVariables(); + return baseline; + } + + @Override + public Baseline getBaseline3() { + Baseline baseline = super.getBaseline3(); + return baseline; + } + + @Override + public Baseline getBaseline6() { + Baseline baseline = super.getBaseline6(); + baseline.put("memberList", new SWGList(this, 6, 2, false)); + baseline.put("memberInfoList", new SWGList(this, 6, 3, false)); + baseline.put("4", ""); + baseline.put("groupLevel", (short) 0); + baseline.put("6", 0); + baseline.put("groupLeader", null); + baseline.put("lootMaster", null); + baseline.put("lootMode", 0); + return baseline; + } + + @SuppressWarnings("unchecked") + public SWGList getMemberList() { + return (SWGList) baseline6.get("memberList"); + } + + @SuppressWarnings("unchecked") + public SWGList getMemberInfoList() { + return (SWGList) baseline6.get("memberInfoList"); + } + + public void addMember(SWGObject member) { + if (member instanceof CreatureObject && member.getClient() != null) { + SWGList memberList = getMemberList(); + SWGList memberInfoList = getMemberInfoList(); + + if (memberList.size() >= 8) { + ((CreatureObject) member).sendSystemMessage("@group:join_full", (byte) 0); + } else { + Member newMember = new Member(member); + + if (memberList.add(newMember)) { + memberInfoList.add(new MemberInfo(memberList.indexOf(newMember), 0)); + + if (((CreatureObject) member).getLevel() > getGroupLevel()) { + setGroupLevel(((CreatureObject) member).getLevel()); + } + } + } + } + } + + public void removeMember(SWGObject member) { + if (member instanceof CreatureObject && member.getClient() != null) { + SWGList memberList = getMemberList(); + SWGList memberInfoList = getMemberInfoList(); + + if (!(memberList.size() <= 0)) { + int index = memberList.indexOf(member); + + if (memberList.remove(member)) { + memberInfoList.remove(index); + + synchronized(objectMutex) { + for (int i = 0; i < memberInfoList.size(); i++) { + if (memberInfoList.get(i).getMemberId() != i) { + memberInfoList.set(i, memberInfoList.get(i).setMemberId(i)); + } + } + } + } + + short maxLevel = 0; + + for (Member memberObject : getMemberList()) { + if (memberObject.getMember() instanceof CreatureObject) { + CreatureObject creature = (CreatureObject) memberObject.getMember(); + + if (creature.getLevel() > maxLevel) { + maxLevel = creature.getLevel(); + } + } + } + + if (maxLevel != getGroupLevel()) { + setGroupLevel(maxLevel); + } + } + } + } + + public boolean setMemberInfo(SWGObject object, long info) { + if (object instanceof CreatureObject && object.getClient() != null) { + for (Member member : getMemberList()) { + if (member.getMember().equals(member)) { + int id = getMemberList().indexOf(member); + getMemberInfoList().set(id, new MemberInfo(info, id)); + return true; + } + } + } + + return false; + } + + public short getGroupLevel() { + synchronized(objectMutex) { + return (short) baseline6.get("groupLevel"); + } + } + + public void setGroupLevel(short groupLevel) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("groupLevel", groupLevel); + } + + notifyObservers(buffer, false); + } + + public SWGObject getGroupLeader() { + synchronized(objectMutex) { + return (SWGObject) baseline6.get("groupLeader"); + } + } + + public void setGroupLeader(SWGObject groupLeader) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("groupLeader", groupLeader); + } + + notifyObservers(buffer, false); + } + + public SWGObject getLootMaster() { + synchronized(objectMutex) { + return (SWGObject) baseline6.get("lootMaster"); + } + } + + public void setLootMaster(SWGObject lootMaster) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("lootMaster", lootMaster); + } + + notifyObservers(buffer, false); + } + + public int getLootMode() { + synchronized(objectMutex) { + return (int) baseline6.get("lootMode"); + } + } + + public void setLootMode(int lootMode) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("lootMode", lootMode); + } + + notifyObservers(buffer, false); + } + + @Override + public void notifyClients(IoBuffer buffer, boolean notifySelf) { + notifyObservers(buffer, false); + } + + @Override + public GroupMessageBuilder getMessageBuilder() { + synchronized(objectMutex) { + if (messageBuilder == null) { + messageBuilder = new GroupMessageBuilder(); + } + + return messageBuilder; + } + } + + @Override + public void sendBaselines(Client destination) { + if (destination != null && destination.getSession() != null) { + destination.getSession().write(baseline3.getBaseline()); + destination.getSession().write(baseline6.getBaseline()); + } + } + +} diff --git a/src/resources/z/exp/objects/guild/GuildMessageBuilder.java b/src/resources/z/exp/objects/guild/GuildMessageBuilder.java new file mode 100644 index 00000000..21d64947 --- /dev/null +++ b/src/resources/z/exp/objects/guild/GuildMessageBuilder.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * 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.z.exp.objects.guild; + +import java.util.Map; +import resources.z.exp.objects.Builder; +import resources.z.exp.objects.universe.UniverseMessageBuilder; + +public class GuildMessageBuilder extends UniverseMessageBuilder { + + public GuildMessageBuilder(GuildObject guildObject) { + super(guildObject); + } + + public GuildMessageBuilder() { + super(); + } + + @Override + public void buildBaseline3(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline3(baselineBuilders, deltaBuilders); + } + + @Override + public void buildBaseline6(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline6(baselineBuilders, deltaBuilders); + } + +} diff --git a/src/resources/z/exp/objects/guild/GuildObject.java b/src/resources/z/exp/objects/guild/GuildObject.java new file mode 100644 index 00000000..7df685e4 --- /dev/null +++ b/src/resources/z/exp/objects/guild/GuildObject.java @@ -0,0 +1,192 @@ +/******************************************************************************* + * 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.z.exp.objects.guild; + +import java.util.Map; +import java.util.TreeMap; + +import org.apache.mina.core.buffer.IoBuffer; + +import resources.gcw.CurrentServerGCWZoneHistory; +import resources.gcw.CurrentServerGCWZonePercent; +import resources.gcw.OtherServerGCWZonePercent; +import resources.z.exp.guild.Guild; +import resources.z.exp.objects.Baseline; +import resources.z.exp.objects.SWGList; +import resources.z.exp.objects.SWGMap; +import resources.z.exp.objects.SWGMultiMap; +import resources.z.exp.objects.universe.UniverseObject; + +import com.sleepycat.je.Environment; +import com.sleepycat.je.Transaction; +import com.sleepycat.persist.model.Entity; +import com.sleepycat.persist.model.NotPersistent; + +import engine.clients.Client; +import engine.resources.objects.IPersistent; +import engine.resources.scene.Planet; +import engine.resources.scene.Point3D; +import engine.resources.scene.Quaternion; + +@Entity +public class GuildObject extends UniverseObject implements IPersistent { + + @NotPersistent + private GuildMessageBuilder messageBuilder = new GuildMessageBuilder(this); + + private Map> zoneMap = new TreeMap>(); + + @NotPersistent + private Transaction txn; + + public GuildObject(long objectID, Planet planet, Point3D position, Quaternion orientation, String Template) { + super(objectID, planet, position, orientation, Template); + } + + public GuildObject() { + super(); + } + + @Override + public void initializeBaselines() { + super.initializeBaselines(); + } + + @Override + public Baseline getOtherVariables() { + Baseline baseline = super.getOtherVariables(); + baseline.put("nextUpdateTime", 1321383613); + return baseline; + } + + @Override + public Baseline getBaseline3() { + Baseline baseline = super.getBaseline3(); + baseline.put("guildList", new SWGList(this, 3, 4, false)); + return baseline; + } + + @Override + public Baseline getBaseline6() { + Baseline baseline = super.getBaseline6(); + baseline.put("currentServerGCWZonePercentMap", new SWGMap(this, 6, 2, true)); + baseline.put("currentServerGCWTotalPercentMap", new SWGMap(this, 6, 3, true)); + baseline.put("currentServerGCWZoneHistoryMap", new SWGMultiMap(this, 6, 4, true)); + baseline.put("currentServerGCWTotalHistoryMap", new SWGMultiMap(this, 6, 5, true)); + baseline.put("otherServerGCWZonePercentMap", new SWGMultiMap(this, 6, 6, true)); + baseline.put("otherServerGCWTotalPercentMap", new SWGMultiMap(this, 6, 7, true)); + baseline.put("8", 5); + return baseline; + } + + @SuppressWarnings("unchecked") + public SWGList getGuildList() { + return (SWGList) baseline3.get("guildList"); + } + + @SuppressWarnings("unchecked") + public SWGMap getCurrentServerGCWZonePercentMap() { + return (SWGMap) baseline6.get("currentServerGCWZonePercentMap"); + } + + @SuppressWarnings("unchecked") + public SWGMap getCurrentServerGCWTotalPercentMap() { + return (SWGMap) baseline6.get("currentServerGCWTotalPercentMap"); + } + + @SuppressWarnings("unchecked") + public SWGMultiMap getCurrentServerGCWZoneHistoryMap() { + return (SWGMultiMap) baseline6.get("currentServerGCWZoneHistoryMap"); + } + + @SuppressWarnings("unchecked") + public SWGMultiMap getCurrentServerGCWTotalHistoryMap() { + return (SWGMultiMap) baseline6.get("currentServerGCWTotalHistoryMap"); + } + + @SuppressWarnings("unchecked") + public SWGMultiMap getOtherServerGCWZonePercentMap() { + return (SWGMultiMap) baseline6.get("otherServerGCWZonePercentMap"); + } + + @SuppressWarnings("unchecked") + public SWGMultiMap getOtherServerGCWTotalPercentMap() { + return (SWGMultiMap) baseline6.get("otherServerGCWTotalPercentMap"); + } + + public Map> getZoneMap() { + synchronized(objectMutex) { + return zoneMap; + } + } + + public int getNextUpdateTime() { + synchronized(objectMutex) { + return (int) otherVariables.get("nextUpdateTime"); + } + } + + public int setNextUpdateTime(long nextUpdateTime) { + synchronized(objectMutex) { + otherVariables.set("nextUpdateTime", (int) nextUpdateTime); + return getNextUpdateTime(); + } + } + + @Override + public void notifyClients(IoBuffer buffer, boolean notifySelf) { + notifyObservers(buffer, false); + } + + @Override + public GuildMessageBuilder getMessageBuilder() { + synchronized(objectMutex) { + if (messageBuilder == null) { + messageBuilder = new GuildMessageBuilder(this); + } + + return messageBuilder; + } + } + + @Override + public void sendBaselines(Client destination) { + if (destination != null && destination.getSession() != null) { + //destination.getSession().write(baseline3.getBaseline()); + //destination.getSession().write(baseline6.getBaseline()); + } + } + + @Override + public void sendListDelta(byte viewType, short updateType, IoBuffer buffer) { + notifyClients(baseline6.createDelta(updateType, buffer.array()), false); + } + + public Transaction getTransaction() { + return txn; + } + + public void createTransaction(Environment env) { + txn = env.beginTransaction(null, null); + } + +} diff --git a/src/resources/z/exp/objects/harvester/HarvesterMessageBuilder.java b/src/resources/z/exp/objects/harvester/HarvesterMessageBuilder.java new file mode 100644 index 00000000..06f08e30 --- /dev/null +++ b/src/resources/z/exp/objects/harvester/HarvesterMessageBuilder.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * 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.z.exp.objects.harvester; + +public class HarvesterMessageBuilder { + +} diff --git a/src/resources/z/exp/objects/harvester/HarvesterObject.java b/src/resources/z/exp/objects/harvester/HarvesterObject.java new file mode 100644 index 00000000..a09905cb --- /dev/null +++ b/src/resources/z/exp/objects/harvester/HarvesterObject.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * 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.z.exp.objects.harvester; + +public class HarvesterObject { + +} diff --git a/src/resources/z/exp/objects/installation/InstallationMessageBuilder.java b/src/resources/z/exp/objects/installation/InstallationMessageBuilder.java new file mode 100644 index 00000000..054ba875 --- /dev/null +++ b/src/resources/z/exp/objects/installation/InstallationMessageBuilder.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * 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.z.exp.objects.installation; + +public class InstallationMessageBuilder { + +} diff --git a/src/resources/z/exp/objects/installation/InstallationObject.java b/src/resources/z/exp/objects/installation/InstallationObject.java new file mode 100644 index 00000000..e57c0460 --- /dev/null +++ b/src/resources/z/exp/objects/installation/InstallationObject.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * 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.z.exp.objects.installation; + +public class InstallationObject { + +} diff --git a/src/resources/z/exp/objects/intangible/IntangibleMessageBuilder.java b/src/resources/z/exp/objects/intangible/IntangibleMessageBuilder.java new file mode 100644 index 00000000..b069678a --- /dev/null +++ b/src/resources/z/exp/objects/intangible/IntangibleMessageBuilder.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.z.exp.objects.intangible; + +import java.util.Map; + +import com.sleepycat.persist.model.Persistent; + +import resources.z.exp.objects.Builder; +import resources.z.exp.objects.ObjectMessageBuilder; + +@Persistent +public class IntangibleMessageBuilder extends ObjectMessageBuilder { + + public IntangibleMessageBuilder(IntangibleObject object) { + super(object); + } + + public IntangibleMessageBuilder() { + super(); + } + + @Override + public void buildBaseline3(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline3(baselineBuilders, deltaBuilders); + } + + @Override + public void buildBaseline6(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline6(baselineBuilders, deltaBuilders); + } + + @Override + public void buildBaseline8(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline8(baselineBuilders, deltaBuilders); + } + + @Override + public void buildBaseline9(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline9(baselineBuilders, deltaBuilders); + } + +} diff --git a/src/resources/z/exp/objects/intangible/IntangibleObject.java b/src/resources/z/exp/objects/intangible/IntangibleObject.java new file mode 100644 index 00000000..d02b9ccf --- /dev/null +++ b/src/resources/z/exp/objects/intangible/IntangibleObject.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * 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.z.exp.objects.intangible; + +import org.apache.mina.core.buffer.IoBuffer; + +import resources.z.exp.objects.Baseline; +import resources.z.exp.objects.object.BaseObject; + +import com.sleepycat.persist.model.NotPersistent; +import com.sleepycat.persist.model.Persistent; + +import engine.clients.Client; +import engine.resources.scene.Planet; +import engine.resources.scene.Point3D; +import engine.resources.scene.Quaternion; + +@Persistent +public class IntangibleObject extends BaseObject { + + @NotPersistent + private IntangibleMessageBuilder messageBuilder; + + public IntangibleObject(long objectID, Planet planet, Point3D position, Quaternion orientation, String Template) { + super(objectID, planet, position, orientation, Template); + } + + public IntangibleObject() { + super(); + } + + @Override + public void initializeBaselines() { + super.initializeBaselines(); + initializeBaseline(8); + initializeBaseline(9); + } + + @Override + public Baseline getOtherVariables() { + Baseline baseline = super.getOtherVariables(); + return baseline; + } + + @Override + public Baseline getBaseline3() { + Baseline baseline = super.getBaseline3(); + baseline.put("genericInt", 0); + return baseline; + } + + @Override + public Baseline getBaseline6() { + Baseline baseline = super.getBaseline6(); + return baseline; + } + + @Override + public Baseline getBaseline8() { + Baseline baseline = super.getBaseline8(); + return baseline; + } + + @Override + public Baseline getBaseline9() { + Baseline baseline = super.getBaseline9(); + return baseline; + } + + public int getGenericInt() { + synchronized(objectMutex) { + return (int) baseline3.get("genericInt"); + } + } + + public void setGenericInt(int genericInt) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("genericInt", genericInt); + } + + notifyClients(buffer, true); + } + + public void incrementGenericInt(int increase) { + setGenericInt((getGenericInt() + increase)); + } + + public void decrementGenericInt(int decrease) { + setGenericInt((((getGenericInt() - decrease) < 1) ? 0 : (getGenericInt() - decrease))); + } + + @Override + public void notifyClients(IoBuffer buffer, boolean notifySelf) { + notifyObservers(buffer, notifySelf); + } + + @Override + public IntangibleMessageBuilder getMessageBuilder() { + synchronized(objectMutex) { + if (messageBuilder == null) { + messageBuilder = new IntangibleMessageBuilder(this); + } + + return messageBuilder; + } + } + + @Override + public void sendBaselines(Client destination) { + if (destination != null && destination.getSession() != null) { + //destination.getSession().write(baseline3.getBaseline()); + //destination.getSession().write(baseline6.getBaseline()); + //destination.getSession().write(baseline8.getBaseline()); + //destination.getSession().write(baseline9.getBaseline()); + } + } + +} diff --git a/src/resources/z/exp/objects/manufacture/ManufactureSchematicMessageBuilder.java b/src/resources/z/exp/objects/manufacture/ManufactureSchematicMessageBuilder.java new file mode 100644 index 00000000..97d20d8e --- /dev/null +++ b/src/resources/z/exp/objects/manufacture/ManufactureSchematicMessageBuilder.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * 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.z.exp.objects.manufacture; + +import java.util.Map; + +import resources.z.exp.objects.Builder; +import resources.z.exp.objects.intangible.IntangibleMessageBuilder; + +public class ManufactureSchematicMessageBuilder extends IntangibleMessageBuilder { + + public ManufactureSchematicMessageBuilder(ManufactureSchematicObject object) { + super(object); + } + + public ManufactureSchematicMessageBuilder() { + super(); + } + + @Override + public void buildBaseline3(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline3(baselineBuilders, deltaBuilders); + } + + @Override + public void buildBaseline6(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline6(baselineBuilders, deltaBuilders); + } + + @Override + public void buildBaseline7(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline7(baselineBuilders, deltaBuilders); + } + + @Override + public void buildBaseline8(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline8(baselineBuilders, deltaBuilders); + } + + @Override + public void buildBaseline9(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline9(baselineBuilders, deltaBuilders); + } + +} diff --git a/src/resources/z/exp/objects/manufacture/ManufactureSchematicObject.java b/src/resources/z/exp/objects/manufacture/ManufactureSchematicObject.java new file mode 100644 index 00000000..88e49380 --- /dev/null +++ b/src/resources/z/exp/objects/manufacture/ManufactureSchematicObject.java @@ -0,0 +1,603 @@ +/******************************************************************************* + * 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.z.exp.objects.manufacture; + +import java.util.ArrayList; +import java.util.Collection; + +import org.apache.mina.core.buffer.IoBuffer; + +import com.sleepycat.persist.model.NotPersistent; +import com.sleepycat.persist.model.Persistent; + +import engine.clients.Client; +import engine.resources.scene.Planet; +import engine.resources.scene.Point3D; +import engine.resources.scene.Quaternion; +import resources.z.exp.manufacture.Property; +import resources.z.exp.manufacture.SubList; +import resources.z.exp.manufacture.TableAndKey; +import resources.z.exp.objects.Baseline; +import resources.z.exp.objects.SWGList; +import resources.z.exp.objects.SWGMultiMap; +import resources.z.exp.objects.intangible.IntangibleObject; + +@Persistent +public class ManufactureSchematicObject extends IntangibleObject { + + @NotPersistent + private ManufactureSchematicMessageBuilder messageBuilder; + + public ManufactureSchematicObject(long objectID, Planet planet, Point3D position, Quaternion orientation, String Template) { + super(objectID, planet, position, orientation, Template); + initializeBaseline(7); + } + + public ManufactureSchematicObject() { + super(); + } + + @Override + public void initializeBaselines() { + super.initializeBaselines(); + } + + @Override + public Baseline getOtherVariables() { + Baseline baseline = super.getOtherVariables(); + baseline.put("totalSlots", (byte) 0); + return baseline; + } + + @Override + public Baseline getBaseline3() { + Baseline baseline = super.getBaseline3(); + baseline.put("properties", new SWGMultiMap(this, 3, 5, true)); + baseline.put("schematicComplexity", 0); + baseline.put("schematicDataSize", (float) 1); + return baseline; + } + + @Override + public Baseline getBaseline6() { + Baseline baseline = super.getBaseline6(); + baseline.put("schematicCustomization", new byte[] { }); + baseline.put("customizationTemplate", ""); + baseline.put("schematicPrototype", ""); + baseline.put("inUse", false); + baseline.put("filledSlots", (byte) 0); + return baseline; + } + + @Override + public Baseline getBaseline7() { + Baseline baseline = super.getBaseline7(); + baseline.put("slotNameList", new SWGList(this, 7, 0, false)); + baseline.put("slotContentsList", new SWGList(this, 7, 1, false)); + baseline.put("ingredientList", new SWGList>(this, 7, 2, false)); + baseline.put("quantityList", new SWGList>(this, 7, 3, false)); + baseline.put("qualityList", new SWGList(this, 7, 4, false)); + baseline.put("cleanSlotList", new SWGList(this, 7, 5, false)); + baseline.put("slotIndexList", new SWGList(this, 7, 6, false)); + baseline.put("ingredientsCounter", (byte) 0); + baseline.put("experimentationNameList", new SWGList(this, 7, 8, false)); + baseline.put("currentExperimentationValueList", new SWGList(this, 7, 9, false)); + baseline.put("experimentationOffsetList", new SWGList(this, 7, 10, false)); + baseline.put("bluebarList", new SWGList(this, 7, 11, false)); + baseline.put("maxExperimentationList", new SWGList(this, 7, 12, false)); + baseline.put("customizationNameList", new SWGList(this, 7, 13, false)); + baseline.put("palleteSelectionList", new SWGList(this, 7, 14, false)); + baseline.put("palleteStartIndexList", new SWGList(this, 7, 15, false)); + baseline.put("palleteEndIndexList", new SWGList(this, 7, 16, false)); + baseline.put("customizationCounter", (byte) 0); + baseline.put("riskFactor", (float) 0); + baseline.put("objectTemplateCustomizationList", new SWGList(this, 7, 19, false)); + baseline.put("ready", true); + return baseline; + } + + @Override + public Baseline getBaseline8() { + Baseline baseline = super.getBaseline8(); + return baseline; + } + + @Override + public Baseline getBaseline9() { + Baseline baseline = super.getBaseline9(); + return baseline; + } + + public void setQuantity(int quantity) { + setGenericInt(quantity); + } + + public void incrementQuantity(int increase) { + incrementGenericInt(increase); + } + + public void decrementQuantity(int decrease) { + decrementGenericInt(decrease); + } + + @SuppressWarnings("unchecked") + public SWGMultiMap getPropertiesMap() { + return (SWGMultiMap) baseline3.get("properties"); + } + + public Collection getPropertiesForFile(String stfFile) { + synchronized(objectMutex) { + if (getPropertiesMap().containsKey(stfFile)) { + return getPropertiesMap().get(stfFile); + } else { + return new ArrayList(); + } + } + } + + public Collection getAllProperties() { + synchronized(objectMutex) { + return getPropertiesMap().values(); + } + } + + public boolean containsKey(String stfFile, String key) { + synchronized(objectMutex) { + for (Property property : getPropertiesMap().get(stfFile)) { + if (property.getKey().equals(key)) { + return true; + } + } + + return false; + } + } + + public boolean containsKey(String key) { + synchronized(objectMutex) { + for (Property property : getPropertiesMap().values()) { + if (property.getKey().equals(key)) { + return true; + } + } + + return false; + } + } + + public Property getProperty(String stfFile, String key) { + synchronized(objectMutex) { + for (Property property: getPropertiesMap().get(stfFile)) { + if (property.getKey().equals(key)) { + return property; + } + } + + return null; + } + } + + public Property getProperty(String key) { + synchronized(objectMutex) { + for (Property property: getPropertiesMap().values()) { + if (property.getKey().equals(key)) { + return property; + } + } + + return null; + } + } + + public void addProperty(String stfFile, String key, float value) { + if (!containsKey(stfFile, key)) { + getPropertiesMap().put(stfFile, new Property(key, value)); + } + } + + public void setProperty(String stfFile, String key, float value) { + if (getPropertiesMap().containsKey(stfFile)) { + for (Property property : getPropertiesMap().get(stfFile)) { + if (property.getKey().equals(key)) { + property.setValue(value); + getPropertiesMap().replaceValues(stfFile, getPropertiesMap().get(stfFile)); + return; + } + } + } + } + + public void removeProperty(String stfFile, String key) { + if (containsKey(stfFile, key)) { + getPropertiesMap().remove(stfFile, getProperty(key)); + } + } + + public void removeFile(String stfFile) { + getPropertiesMap().removeAll(stfFile); + } + + public int getSchematicComplexity() { + synchronized(objectMutex) { + return (int) baseline3.get("schematicComplexity"); + } + } + + public void setSchematicComplexity(int schematicComplexity) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("schematicComplexity", schematicComplexity); + } + + notifyClients(buffer, false); + } + + public float getSchematicDataSize() { + synchronized(objectMutex) { + return (float) baseline3.get("schematicDataSize"); + } + } + + public void setSchematicDataSize(float schematicDataSize) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("schematicDataSize", schematicDataSize); + } + + notifyClients(buffer, false); + } + + public byte[] getSchematicCustomization() { + synchronized(objectMutex) { + return (byte[]) baseline6.get("schematicCustomization"); + } + } + + public void setSchematicCustomization(byte[] schematicCustomization) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("schematicCustomization", schematicCustomization); + } + + notifyClients(buffer, false); + } + + public String getCustomizationTemplate() { + synchronized(objectMutex) { + return (String) baseline6.get("customizationTemplate"); + } + } + + public void setCustomizationTemplate(String customizationTemplate) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("customizationTemplate", customizationTemplate); + } + + notifyClients(buffer, false); + } + + public String getSchematicTemplate() { + synchronized(objectMutex) { + return (String) baseline6.get("schematicTemplate"); + } + } + + public void setSchematicTemplate(String schematicTemplate) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("schematicTemplate", schematicTemplate); + } + + notifyClients(buffer, false); + } + + public boolean inUse() { + synchronized(objectMutex) { + return (boolean) baseline6.get("inUse"); + } + } + + public void setInUse(boolean inUse) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("inUse", inUse); + } + + notifyClients(buffer, false); + } + + public void toggleInUse() { + setInUse(!inUse()); + } + + public byte getTotalSlots() { + synchronized(objectMutex) { + return (byte) otherVariables.get("totalSlots"); + } + } + + public void setTotalSlots(byte totalSlots) { + synchronized(objectMutex) { + otherVariables.set("totalSlots", totalSlots); + } + } + + public byte getFilledSlots() { + synchronized(objectMutex) { + return (byte) baseline6.get("filledSlots"); + } + } + + public void setFilledSlots(byte filledSlots) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("filledSlots", filledSlots); + } + + notifyClients(buffer, false); + } + + public void incrementFilledSlots(int increase) { + setFilledSlots(((byte) (getFilledSlots() + ((byte) increase)))); + } + + public void decrementFilledSlots(int decrease) { + setFilledSlots(((byte) (((getFilledSlots() - ((byte) decrease)) < 0) ? ((byte) 0) : (getFilledSlots() - ((byte) decrease))))); + } + + @SuppressWarnings("unchecked") + public SWGList getSlotNameList() { + return (SWGList) baseline7.get("slotNameList"); + } + + @SuppressWarnings("unchecked") + public SWGList getSlotContentsList() { + return (SWGList) baseline7.get("slotContentsList"); + } + + @SuppressWarnings("unchecked") + public SWGList> getIngredientList() { + return (SWGList>) baseline7.get("ingredientList"); + } + + @SuppressWarnings("unchecked") + public SWGList> getQuantityList() { + return (SWGList>) baseline7.get("quantityList"); + } + + @SuppressWarnings("unchecked") + public SWGList getQualityList() { + return (SWGList) baseline7.get("quantityList"); + } + + @SuppressWarnings("unchecked") + public SWGList getCleanSlotList() { + return (SWGList) baseline7.get("cleanSlotList"); + } + + @SuppressWarnings("unchecked") + public SWGList getSlotIndexList() { + return (SWGList) baseline7.get("slotIndexList"); + } + + public byte getIngredientsCounter() { + return (byte) baseline7.get("ingredientsCounter"); + } + + public void setIngredientsCounter(byte ingredientsCounter) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline7.set("ingredientsCounter", ingredientsCounter); + } + + if (getGrandparent().getClient() != null) { + getGrandparent().getClient().getSession().write(buffer); + } + } + + public void incrementIngredientsCounter(int increase) { + setIngredientsCounter((byte) (getIngredientsCounter() + ((byte) increase))); + } + + public void decrementIngredientsCoutner(int decrease) { + byte ingredientsCounter = getIngredientsCounter(); + setIngredientsCounter(((ingredientsCounter < 0) ? 0 : ((byte) (ingredientsCounter - ((byte) decrease))))); + } + + @SuppressWarnings("unchecked") + public SWGList getExperimentationNameList() { + return (SWGList) baseline7.get("experimentationNameList"); + } + + @SuppressWarnings("unchecked") + public SWGList getCurrentExperimentationValueList() { + return (SWGList) baseline7.get("currentExperimentationValueList"); + } + + @SuppressWarnings("unchecked") + public SWGList getExperimentationOffsetList() { + return (SWGList) baseline7.get("experimentationOffsetList"); + } + + @SuppressWarnings("unchecked") + public SWGList getBlueBarList() { + return (SWGList) baseline7.get("blueBarList"); + } + + @SuppressWarnings("unchecked") + public SWGList getMaxExperimentationList() { + return (SWGList) baseline7.get("maxExperimentationList"); + } + + @SuppressWarnings("unchecked") + public SWGList getCustomizationNameList() { + return (SWGList) baseline7.get("customizationNameList"); + } + + @SuppressWarnings("unchecked") + public SWGList getPalleteSelectionList() { + return (SWGList) baseline7.get("palleteSelectionList"); + } + + @SuppressWarnings("unchecked") + public SWGList getPalleteStartIndexList() { + return (SWGList) baseline7.get("palleteStartIndexList"); + } + + @SuppressWarnings("unchecked") + public SWGList getPalleteEndIndexList() { + return (SWGList) baseline7.get("palleteEndIndexList"); + } + + public byte getCustomizationCounter() { + synchronized(objectMutex) { + return (byte) baseline7.get("customizationCounter"); + } + } + + public void setCustomizationCounter(byte customizationCounter) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline7.set("customizationCounter", customizationCounter); + } + + if (getGrandparent().getClient() != null) { + getGrandparent().getClient().getSession().write(buffer); + } + } + + public void incrementCustomizationCounter(int increase) { + + } + + public void decrementCustomizationCounter(int decrease) { + + } + + public float getRiskFactor() { + synchronized(objectMutex) { + return (float) baseline7.get("riskFactor"); + } + } + + public void setRiskFactor(float riskFactor) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline7.set("riskFactor", riskFactor); + } + + if (getGrandparent().getClient() != null) { + getGrandparent().getClient().getSession().write(buffer); + } + } + + @SuppressWarnings("unchecked") + public SWGList getObjectTemplateCustomizationList() { + return (SWGList) baseline7.get("objectTemplateCustomizationList"); + } + + public boolean isReady() { + synchronized(objectMutex) { + return (boolean) baseline7.get("isReady"); + } + } + + public void setReady(boolean ready) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline7.set("ready", ready); + } + + if (getGrandparent().getClient() != null) { + getGrandparent().getClient().getSession().write(buffer); + } + } + + public void toggleReady() { + setReady(!isReady()); + } + + @Override + public void notifyClients(IoBuffer buffer, boolean notifySelf) { + notifyObservers(buffer, notifySelf); + } + + @Override + public ManufactureSchematicMessageBuilder getMessageBuilder() { + synchronized(objectMutex) { + if (messageBuilder == null) { + messageBuilder = new ManufactureSchematicMessageBuilder(this); + } + + return messageBuilder; + } + } + + public void sendBaseline7(Client destination) { + destination.getSession().write(baseline7.getBaseline()); + } + + @Override + public void sendBaselines(Client destination) { + if (destination != null && destination.getSession() != null) { + destination.getSession().write(baseline3.getBaseline()); + destination.getSession().write(baseline6.getBaseline()); + destination.getSession().write(baseline8.getBaseline()); + destination.getSession().write(baseline9.getBaseline()); + } + } + + @Override + public void sendListDelta(byte viewType, short updateType, IoBuffer buffer) { + switch (viewType) { + case 1: + case 4: + case 7: + if (getGrandparent().getClient() != null) { + buffer = getBaseline(viewType).createDelta(updateType, buffer.array()); + getGrandparent().getClient().getSession().write(buffer); + } + + return; + case 3: + case 6: + case 8: + case 9: + notifyObservers(getBaseline(viewType).createDelta(updateType, buffer.array()), true); + default: + return; + } + } + +} diff --git a/src/resources/z/exp/objects/mission/MissionMessageBuilder.java b/src/resources/z/exp/objects/mission/MissionMessageBuilder.java new file mode 100644 index 00000000..b1626472 --- /dev/null +++ b/src/resources/z/exp/objects/mission/MissionMessageBuilder.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * 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.z.exp.objects.mission; + +import java.util.Map; + +import resources.z.exp.objects.Builder; +import resources.z.exp.objects.intangible.IntangibleMessageBuilder; + +public class MissionMessageBuilder extends IntangibleMessageBuilder { + + public MissionMessageBuilder(MissionObject object) { + super(object); + } + + public MissionMessageBuilder() { + super(); + } + + @Override + public void buildBaseline3(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline3(baselineBuilders, deltaBuilders); + } + + @Override + public void buildBaseline6(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline6(baselineBuilders, deltaBuilders); + } + + @Override + public void buildBaseline8(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline8(baselineBuilders, deltaBuilders); + } + + @Override + public void buildBaseline9(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline9(baselineBuilders, deltaBuilders); + } + +} diff --git a/src/resources/z/exp/objects/mission/MissionObject.java b/src/resources/z/exp/objects/mission/MissionObject.java new file mode 100644 index 00000000..fdb43469 --- /dev/null +++ b/src/resources/z/exp/objects/mission/MissionObject.java @@ -0,0 +1,329 @@ +/******************************************************************************* + * 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.z.exp.objects.mission; + +import org.apache.mina.core.buffer.IoBuffer; + +import main.NGECore; + +import com.sleepycat.persist.model.NotPersistent; +import com.sleepycat.persist.model.Persistent; + +import engine.clients.Client; +import engine.resources.objects.SWGObject; +import engine.resources.scene.Planet; +import engine.resources.scene.Point3D; +import engine.resources.scene.Quaternion; + +import resources.common.Stf; +import resources.common.UString; +import resources.z.exp.mission.MissionLocation; +import resources.z.exp.objects.Baseline; +import resources.z.exp.objects.intangible.IntangibleObject; +import resources.z.exp.objects.waypoint.WaypointObject; + +@Persistent +public class MissionObject extends IntangibleObject { + + @NotPersistent + private MissionMessageBuilder messageBuilder; + + public MissionObject(NGECore core, long objectID, Planet planet, Point3D position, Quaternion orientation, String Template) { + super(objectID, planet, position, orientation, Template); + baseline3.set("waypoint", (WaypointObject) core.objectService.createObject("object/waypoint/base/shared_base_waypoint.iff", planet)); + } + + public MissionObject() { + super(); + } + + @Override + public void initializeBaselines() { + super.initializeBaselines(); + } + + @Override + public Baseline getOtherVariables() { + Baseline baseline = super.getOtherVariables(); + return baseline; + } + + @Override + public Baseline getBaseline3() { + Baseline baseline = super.getBaseline3(); + baseline.put("difficultyLevel", 0); + baseline.put("startLocation", new MissionLocation(new Point3D(0, 0, 0), 0, "")); + baseline.put("creator", new UString()); + baseline.put("creditReward", 0); + baseline.put("targetObject", 0); + baseline.put("description", new Stf()); + baseline.put("title", new Stf()); + baseline.put("repeatCounter", 0); + baseline.put("missionType", ""); + baseline.put("targetName", ""); + baseline.put("waypoint", new WaypointObject()); + return baseline; + } + + @Override + public Baseline getBaseline6() { + Baseline baseline = super.getBaseline6(); + return baseline; + } + + @Override + public Baseline getBaseline8() { + Baseline baseline = super.getBaseline8(); + return baseline; + } + + @Override + public Baseline getBaseline9() { + Baseline baseline = super.getBaseline9(); + return baseline; + } + + public int getDifficultyLevel() { + synchronized(objectMutex) { + return (int) baseline3.get("difficultyLevel"); + } + } + + public void setDifficultyLevel(int difficultyLevel) { + synchronized(objectMutex) { + baseline3.set("difficultyLevel", difficultyLevel); + } + } + + public MissionLocation getStartLocation() { + synchronized(objectMutex) { + return (MissionLocation) baseline3.get("startLocation"); + } + } + + public void setStartLocation(Point3D position, SWGObject object, Planet planet) { + setStartLocation(position, object, planet.getName()); + } + + public void setStartLocation(Point3D position, SWGObject object, String planet) { + synchronized(objectMutex) { + MissionLocation startLocation = new MissionLocation(position.clone(), object.getObjectID(), planet); + baseline3.set("startLocation", startLocation); + } + } + + public String getCreator() { + synchronized(objectMutex) { + return (String) baseline3.get("creator"); + } + } + + public void setCreator(String creator) { + synchronized(objectMutex) { + baseline3.set("creator", creator); + } + } + + public int getCreditReward() { + synchronized(objectMutex) { + return (int) baseline3.get("creditReward"); + } + } + + public void setCreditReward(int creditReward) { + synchronized(objectMutex) { + baseline3.set("creditReward", creditReward); + } + } + + public MissionLocation getDestination() { + synchronized(objectMutex) { + return (MissionLocation) baseline3.get("destination"); + } + } + + public void setDestination(Point3D position, SWGObject object, Planet planet) { + setDestination(position, object, planet.getName()); + } + + public void setDestination(Point3D position, SWGObject object, String planet) { + synchronized(objectMutex) { + MissionLocation destination = new MissionLocation(position.clone(), object.getObjectID(), planet); + baseline3.set("destination", destination); + } + } + + public int getTargetObject() { + synchronized(objectMutex) { + return (int) baseline3.get("targetObject"); + } + } + + public void setTargetObject(int targetObject) { + synchronized(objectMutex) { + baseline3.set("targetObject", targetObject); + } + } + + public Stf getDescription() { + synchronized(objectMutex) { + return (Stf) baseline3.get("description"); + } + } + + public void setDescription(String stfFilename, String string) { + synchronized(objectMutex) { + Stf description = new Stf(stfFilename, 0, string); + baseline3.set("description", description); + } + } + + public Stf getTitle() { + synchronized(objectMutex) { + return (Stf) baseline3.get("title"); + } + } + + public void setTitle(String stfFilename, String string) { + synchronized(objectMutex) { + Stf title = new Stf(stfFilename, 0, string); + baseline3.set("title", title); + } + } + + public int getRepeatCounter() { + synchronized(objectMutex) { + return (int) baseline3.get("repeatCounter"); + } + } + + public void setRepeatCounter(int repeatCounter) { + synchronized(objectMutex) { + baseline3.set("repeatCounter", repeatCounter); + } + } + + public void incrementRepeatCounter(int increase) { + setRepeatCounter(getRepeatCounter() + 1); + } + + public void decrementRepeatCounter(int decrease) { + int repeatCounter = getRepeatCounter() + 1; + setRepeatCounter((repeatCounter < 0) ? 0 : repeatCounter); + } + + public String getMissionType() { + synchronized(objectMutex) { + return (String) baseline3.get("missionType"); + } + } + + public void setMissionType(String missionType) { + synchronized(objectMutex) { + baseline3.set("missionType", missionType); + } + } + + public String getTargetName() { + synchronized(objectMutex) { + return (String) baseline3.get("targetName"); + } + } + + public void setTargetName(String targetName) { + synchronized(objectMutex) { + baseline3.set("targetName", targetName); + } + } + + public WaypointObject getWaypoint() { + synchronized(objectMutex) { + return (WaypointObject) baseline3.get("waypoint"); + } + } + + public void setWaypoint(WaypointObject waypoint) { + synchronized(objectMutex) { + baseline3.set("waypoint", waypoint); + } + } + + // A new mission listing is just one big delta to one of the player's + // empty, pre-existing MissionObjects + public void updateMission() { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.createDelta(); + } + + if (getGrandparent().getClient() != null) { + getGrandparent().getClient().getSession().write(buffer); + } + } + + @Override + public void notifyClients(IoBuffer buffer, boolean notifySelf) { + getGrandparent().getClient().getSession().write(buffer); + } + + @Override + public MissionMessageBuilder getMessageBuilder() { + synchronized(objectMutex) { + if (messageBuilder == null) { + messageBuilder = new MissionMessageBuilder(this); + } + + return messageBuilder; + } + } + + @Override + public void sendBaselines(Client destination) { + if (destination != null && destination.getSession() != null) { + destination.getSession().write(baseline3.getBaseline()); + destination.getSession().write(baseline6.getBaseline()); + destination.getSession().write(baseline8.getBaseline()); + destination.getSession().write(baseline9.getBaseline()); + } + } + + @Override + public void sendListDelta(byte viewType, short updateType, IoBuffer buffer) { + switch (viewType) { + case 1: + case 4: + case 3: + case 6: + case 7: + case 8: + case 9: + if (getGrandparent().getClient() != null) { + buffer = getBaseline(viewType).createDelta(updateType, buffer.array()); + getGrandparent().getClient().getSession().write(buffer); + } + default: + return; + } + } + +} diff --git a/src/resources/z/exp/objects/object/BaseObject.java b/src/resources/z/exp/objects/object/BaseObject.java new file mode 100644 index 00000000..37dc0f85 --- /dev/null +++ b/src/resources/z/exp/objects/object/BaseObject.java @@ -0,0 +1,543 @@ +/******************************************************************************* + * 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.z.exp.objects.object; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import org.apache.mina.core.buffer.IoBuffer; + +import resources.common.Stf; +import resources.common.UString; +import resources.z.exp.objects.Baseline; +import resources.z.exp.objects.Builder; +import resources.z.exp.objects.ObjectMessageBuilder; + +import com.sleepycat.persist.model.NotPersistent; +import com.sleepycat.persist.model.Persistent; + +import engine.clients.Client; +import engine.resources.objects.SWGObject; +import engine.resources.scene.Planet; +import engine.resources.scene.Point3D; +import engine.resources.scene.Quaternion; + +@Persistent +public class BaseObject extends SWGObject { + + @NotPersistent + private ObjectMessageBuilder messageBuilder; + + protected Baseline baseline1; + protected Baseline baseline3; + protected Baseline baseline4; + protected Baseline baseline6; + protected Baseline baseline7; + protected Baseline baseline8; + protected Baseline baseline9; + protected Baseline otherVariables; + + @NotPersistent + private ScheduledExecutorService scheduler; + + private boolean ready = false; + + public BaseObject(long objectID, Planet planet, Point3D position, Quaternion orientation, String Template) { + super(objectID, planet, position, orientation, Template); + super.setCustomName(""); + if (super.getDetailFilename() == null) super.setDetailFilename(""); + if (super.getDetailName() == null) super.setDetailName(""); + initializeBaselines(); + otherVariables = getOtherVariables(); + ready = true; + } + + public BaseObject() { + super(); + + scheduler = Executors.newScheduledThreadPool(2); + + // Makes sure this runs after the baselines have been restored from DB + + scheduler.schedule(new Runnable() { + + public void run() { + while (!ready); + initializeBaselines(); + } + + }, 0, TimeUnit.NANOSECONDS); + } + + public void initializeBaselines() { + // Transform the structures of any baselines incase they've been altered + + if (otherVariables != null) { + otherVariables.transformStructure(getOtherVariables()); + } + + if (baseline1 != null) { + baseline1.transformStructure(getBaseline1()); + addBuilders(1); + } + + if (baseline3 != null) { + baseline3.transformStructure(getBaseline3()); + addBuilders(3); + } + + if (baseline4 != null) { + baseline4.transformStructure(getBaseline4()); + addBuilders(4); + } + + if (baseline6 != null) { + baseline6.transformStructure(getBaseline6()); + addBuilders(6); + } + + if (baseline7 != null) { + baseline7.transformStructure(getBaseline7()); + addBuilders(7); + } + + if (baseline8 != null) { + baseline8.transformStructure(getBaseline8()); + addBuilders(8); + } + + if (baseline9 != null) { + baseline9.transformStructure(getBaseline9()); + addBuilders(9); + } + + // Inheriting objects initialize these only if needed, for efficiency + + initializeBaseline(3); + initializeBaseline(6); + } + + public void initializeBaseline(int viewType) { + // Won't initialize any baselines if they've already been initialized + + switch (viewType) { + case 1: + if (baseline1 == null) { + baseline1 = getBaseline1(); + addBuilders(viewType); + getMessageBuilder().buildBaseline1(baseline1.getBaselineBuilders(), baseline1.getDeltaBuilders()); + } + + return; + case 3: + if (baseline3 == null) { + baseline3 = getBaseline3(); + addBuilders(viewType); + getMessageBuilder().buildBaseline3(baseline3.getBaselineBuilders(), baseline3.getDeltaBuilders()); + } + + return; + case 4: + if (baseline4 == null) { + baseline4 = getBaseline4(); + addBuilders(viewType); + getMessageBuilder().buildBaseline4(baseline4.getBaselineBuilders(), baseline4.getDeltaBuilders()); + } + + return; + case 6: + if (baseline6 == null) { + baseline6 = getBaseline6(); + addBuilders(viewType); + getMessageBuilder().buildBaseline6(baseline6.getBaselineBuilders(), baseline6.getDeltaBuilders()); + } + + return; + case 7: + if (baseline7 == null) { + baseline7 = getBaseline7(); + addBuilders(viewType); + getMessageBuilder().buildBaseline7(baseline7.getBaselineBuilders(), baseline7.getDeltaBuilders()); + } + + return; + case 8: + if (baseline8 == null) { + baseline8 = getBaseline8(); + addBuilders(viewType); + getMessageBuilder().buildBaseline8(baseline8.getBaselineBuilders(), baseline8.getDeltaBuilders()); + } + + return; + case 9: + if (baseline9 == null) { + baseline9 = getBaseline9(); + addBuilders(viewType); + getMessageBuilder().buildBaseline9(baseline9.getBaselineBuilders(), baseline9.getDeltaBuilders()); + } + default: + return; + } + } + + public void addBuilders(int viewType) { + Baseline baseline = getBaseline(viewType); + Map baselineBuilders = new HashMap(); + Map deltaBuilders = new HashMap(); + + switch (viewType) { + case 1: + getMessageBuilder().buildBaseline1(baselineBuilders, deltaBuilders); + break; + case 3: + getMessageBuilder().buildBaseline3(baselineBuilders, deltaBuilders); + break; + case 4: + getMessageBuilder().buildBaseline4(baselineBuilders, deltaBuilders); + break; + case 6: + getMessageBuilder().buildBaseline6(baselineBuilders, deltaBuilders); + break; + case 7: + getMessageBuilder().buildBaseline7(baselineBuilders, deltaBuilders); + break; + case 8: + getMessageBuilder().buildBaseline8(baselineBuilders, deltaBuilders); + break; + case 9: + getMessageBuilder().buildBaseline9(baselineBuilders, deltaBuilders); + break; + } + + if (baselineBuilders.size() > 0) { + baseline.setBaselineBuilders(baselineBuilders); + } + + if (deltaBuilders.size() > 0) { + baseline.setDeltaBuilders(deltaBuilders); + } + } + + public Baseline getOtherVariables() { + Baseline baseline = new Baseline(this, 0); + return baseline; + } + + public Baseline getBaseline1() { + Baseline baseline = new Baseline(this, 1); + return baseline; + } + + public Baseline getBaseline3() { + Baseline baseline = new Baseline(this, 3); + baseline.put("complexity", (float) 1); + baseline.put("stf", new Stf(getStfFilename(), 0, getStfName())); + baseline.put("customName", new UString("")); + baseline.put("volume", 1); + return baseline; + } + + public Baseline getBaseline4() { + Baseline baseline = new Baseline(this, 4); + return baseline; + } + + public Baseline getBaseline6() { + Baseline baseline = new Baseline(this, 6); + baseline.put("serverId", 0); + baseline.put("detail", new Stf(getDetailFilename(), 0, getDetailName())); + return baseline; + } + + public Baseline getBaseline7() { + Baseline baseline = new Baseline(this, 7); + return baseline; + } + + public Baseline getBaseline8() { + Baseline baseline = new Baseline(this, 8); + return baseline; + } + + public Baseline getBaseline9() { + Baseline baseline = new Baseline(this, 9); + return baseline; + } + + public float getComplexity() { + synchronized(objectMutex) { + return (float) baseline3.get("complexity"); + } + } + + public void setComplexity(float complexity) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("complexity", complexity); + } + + if (baseline3 != null) { + notifyClients(buffer, true); + } + } + + public Stf getStf() { + return (Stf) baseline3.get("stf"); + } + + public void setStfFilename(String stfFilename) { + super.setStfFilename(stfFilename); + + if (baseline3 != null) { + IoBuffer buffer; + + getStf().setStfFilename(stfFilename); + + synchronized(objectMutex) { + buffer = baseline3.set("stf", getStf()); + } + + if (baseline3 != null) { + notifyClients(buffer, true); + } + } + } + + public int getStfSpacer() { + synchronized(objectMutex) { + return ((Stf) baseline3.get("stf")).getSpacer(); + } + } + + public void setStfSpacer(int stfSpacer) { + IoBuffer buffer; + + getStf().setSpacer(stfSpacer); + + synchronized(objectMutex) { + buffer = baseline3.set("stf", getStf()); + } + + if (baseline3 != null) { + notifyClients(buffer, true); + } + } + + public void setStfName(String stfName) { + super.setStfName(stfName); + + if (baseline3 != null) { + IoBuffer buffer; + + getStf().setStfName(stfName); + + synchronized(objectMutex) { + buffer = baseline3.set("stf", getStf()); + } + + if (baseline3 != null) { + notifyClients(buffer, true); + } + } + } + + public void setCustomName(String customName) { + super.setCustomName(customName); + + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("customName", customName); + } + + if (baseline3 != null) { + notifyClients(buffer, true); + } + } + + public void setVolume(int volume) { + super.setVolume(volume); + + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("volume", volume); + } + + if (baseline3 != null) { + notifyClients(buffer, true); + } + } + + public void incrementVolume(int increase) { + setVolume((getVolume() + increase)); + } + + public void decrementVolume(int decrease) { + setVolume((((getVolume() - decrease) < 1) ? 0 : (getVolume() - decrease))); + } + + public int getServerId() { + synchronized(objectMutex) { + return (int) baseline6.get("serverId"); + } + } + + public void setServerId(int serverId) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("serverId", serverId); + } + + if (baseline6 != null) { + notifyClients(buffer, true); + } + } + + public Stf getDetail() { + return (Stf) baseline3.get("detail"); + } + + public void setDetailFilename(String detailFilename) { + super.setDetailFilename(detailFilename); + + if (baseline6 != null) { + IoBuffer buffer; + + getDetail().setStfFilename(detailFilename); + + synchronized(objectMutex) { + buffer = baseline6.set("detail", getDetail()); + } + + if (baseline6 != null) { + notifyClients(buffer, true); + } + } + } + + public int getDetailSpacer() { + synchronized(objectMutex) { + return ((Stf) baseline6.get("detail")).getSpacer(); + } + } + + public void setDetailSpacer(int detailSpacer) { + IoBuffer buffer; + + getDetail().setSpacer(detailSpacer); + + synchronized(objectMutex) { + buffer = baseline6.set("detail", getDetail()); + } + + if (baseline6 != null) { + notifyClients(buffer, true); + } + } + + public void setDetailName(String detailName) { + super.setDetailName(detailName); + + if (baseline6 != null) { + IoBuffer buffer; + + getDetail().setStfName(detailName); + + synchronized(objectMutex) { + buffer = baseline6.set("detail", getDetail()); + } + + if (baseline6 != null) { + notifyClients(buffer, true); + } + } + } + + protected Baseline getBaseline(int viewType) { + switch (viewType) { + case 1: return baseline1; + case 3: return baseline3; + case 4: return baseline4; + case 6: return baseline6; + case 7: return baseline7; + case 8: return baseline8; + case 9: return baseline9; + default: return null; + } + } + + /* + This should contain the method of notifying observers, as + it tends to vary depending on the type of object, which is + a problem for inheritance when the master object uses a + different method (ie. ITNO and PLAY). + */ + public void notifyClients(IoBuffer buffer, boolean notifySelf) { + notifyObservers(buffer, notifySelf); + } + + public ObjectMessageBuilder getMessageBuilder() { + synchronized(objectMutex) { + if (messageBuilder == null) { + messageBuilder = new ObjectMessageBuilder(this); + } + + return messageBuilder; + } + } + + @Override + public void sendBaselines(Client destination) { + if (destination != null && destination.getSession() != null) { + destination.getSession().write(baseline3.getBaseline()); + destination.getSession().write(baseline6.getBaseline()); + } + } + + public void sendListDelta(byte viewType, short updateType, IoBuffer buffer) { + switch (viewType) { + case 1: + case 4: + case 7: + if (getClient() != null) { + buffer = getBaseline(viewType).createDelta(updateType, buffer.array()); + getClient().getSession().write(buffer); + } + + return; + case 3: + case 6: + case 8: + case 9: + notifyClients(getBaseline(viewType).createDelta(updateType, buffer.array()), true); + default: + return; + } + } + +} diff --git a/src/resources/z/exp/objects/player/PlayerMessageBuilder.java b/src/resources/z/exp/objects/player/PlayerMessageBuilder.java new file mode 100644 index 00000000..f4886ec9 --- /dev/null +++ b/src/resources/z/exp/objects/player/PlayerMessageBuilder.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * 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.z.exp.objects.player; + +import java.util.Map; + +import com.sleepycat.persist.model.Persistent; + +import resources.z.exp.objects.Builder; +import resources.z.exp.objects.intangible.IntangibleMessageBuilder; + +@Persistent +public class PlayerMessageBuilder extends IntangibleMessageBuilder { + + public PlayerMessageBuilder(PlayerObject playerObject) { + super(playerObject); + } + + public PlayerMessageBuilder() { + super(); + } + + @Override + public void buildBaseline3(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline3(baselineBuilders, deltaBuilders); + } + + @Override + public void buildBaseline6(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline6(baselineBuilders, deltaBuilders); + } + + public void buildBaseline8(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline8(baselineBuilders, deltaBuilders); + } + + public void buildBaseline9(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline9(baselineBuilders, deltaBuilders); + } + +} diff --git a/src/resources/z/exp/objects/player/PlayerObject.java b/src/resources/z/exp/objects/player/PlayerObject.java new file mode 100644 index 00000000..df7284b0 --- /dev/null +++ b/src/resources/z/exp/objects/player/PlayerObject.java @@ -0,0 +1,999 @@ +/******************************************************************************* + * 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.z.exp.objects.player; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; +import java.util.Locale; + +import org.apache.mina.core.buffer.IoBuffer; + +import resources.datatables.Professions; +import resources.z.exp.gcw.RegionDefender; +import resources.z.exp.objects.Baseline; +import resources.z.exp.objects.SWGList; +import resources.z.exp.objects.SWGMap; +import resources.z.exp.objects.intangible.IntangibleObject; +import resources.z.exp.objects.waypoint.WaypointObject; + +import com.sleepycat.persist.model.NotPersistent; +import com.sleepycat.persist.model.Persistent; + +import engine.clients.Client; +import resources.z.exp.craft.DraftSchematic; +import resources.z.exp.quest.Quest; +import engine.resources.scene.Planet; +import engine.resources.scene.Point3D; +import engine.resources.scene.Quaternion; + +@Persistent +public class PlayerObject extends IntangibleObject { + + @NotPersistent + private PlayerMessageBuilder messageBuilder; + + @NotPersistent + private long lastPlayTimeUpdate = System.currentTimeMillis(); + + public PlayerObject(long objectID, Planet planet) { + super(objectID, planet, new Point3D(0, 0, 0), new Quaternion(1, 0, 0, 0), "object/player/shared_player.iff"); + setServerId(0x8A); + } + + public PlayerObject() { + super(); + } + + @Override + public void initializeBaselines() { + super.initializeBaselines(); + } + + @Override + public Baseline getOtherVariables() { + Baseline baseline = super.getOtherVariables(); + return baseline; + } + + @Override + public Baseline getBaseline3() { + Baseline baseline = super.getBaseline3(); + List flagsList = new ArrayList(); + flagsList.add(0); + flagsList.add(0); + flagsList.add(0); + flagsList.add(0); + baseline.put("flagsList", flagsList); + List profileFlagsList = new ArrayList(); + profileFlagsList.add(0); + profileFlagsList.add(0); + profileFlagsList.add(0); + profileFlagsList.add(0); + baseline.put("profileFlagsList", profileFlagsList); + baseline.put("title", ""); + baseline.put("bornDate", Integer.parseInt(new SimpleDateFormat("yyyymmdd", Locale.ENGLISH).format(Calendar.getInstance().getTime()))); + baseline.put("totalPlayTime", 0); + baseline.put("professionIcon", 0); + baseline.put("profession", "trader_1a"); + baseline.put("gcwPoints", 0); + baseline.put("pvpKills", 0); + baseline.put("lifetimeGcwPoints", (long) 0); + baseline.put("lifetimePvpKills", 0); + baseline.put("16", new SWGList(this, 3, 16, false)); // Misc data size (varies, 0 in tutorial) <- collections?) <- this isn't a SWGList, but it'll work until we need it + baseline.put("17", new SWGList(this, 3, 17, false)); // Misc ints (2 ints in tutorial, 5 bytes other times...) + baseline.put("18", (byte) 0); // Unknown Flag (regularly changed in tutorial) + baseline.put("19", (byte) 0); // Unknown Flag (regularly changed in tutorial) + return baseline; + } + + @Override + public Baseline getBaseline6() { + Baseline baseline = super.getBaseline6(); + baseline.put("adminFlags", (byte) 0); + baseline.put("currentRank", 0); + baseline.put("rankProgress", (float) 0); + baseline.put("highestRebelRank", 0); + baseline.put("highestImperialRank", 0); + baseline.put("nextUpdateTime", 0); // TODO set correctly + baseline.put("home", ""); + baseline.put("citizenship", (byte) 0); // Homeless/Citizen/Militia/Mayor? + baseline.put("cityRegionDefender", new RegionDefender()); + baseline.put("guildRegionDefender", new RegionDefender()); + baseline.put("12", 0); // General? + baseline.put("13", 0); // Guild Rank Title? + baseline.put("14", 0); // Citizen Rank Title? + baseline.put("15", 0); // All random guesses, always seem to be 0 + baseline.put("16", 0); + return baseline; + } + + @Override + public Baseline getBaseline8() { + Baseline baseline = super.getBaseline8(); + baseline.put("xpList", new SWGMap(this, 8, 0, true)); + baseline.put("waypoints", new SWGMap(this, 8, 1, true)); + baseline.put("currentForcePower", 100); + baseline.put("maxForcePower", 100); + baseline.put("currentFSQuestList", new SWGList(this, 8, 4, false)); + baseline.put("completedFSQuestList", new SWGList(this, 8, 5, false)); + baseline.put("questJournal", new SWGList(this, 8, 6, false)); + baseline.put("professionWheelPosition", ""); + return baseline; + } + + @Override + public Baseline getBaseline9() { + Baseline baseline = super.getBaseline9(); + baseline.put("experimentationFlag", 0); + baseline.put("craftingStage", 0); + baseline.put("nearestCraftingStation", 0); + baseline.put("draftSchematicList", new SWGList(this, 9, 3, true)); + baseline.put("4", new SWGList(this, 9, 4, false)); // Might or might not be a list, but at the very least it's two 0 ints that are part of the same delta. + baseline.put("experimentationPoints", 0); + baseline.put("accomplishmentCounter", 0); + baseline.put("friendList", new SWGList(this, 9, 7, false)); + baseline.put("ignoreList", new SWGList(this, 9, 8, false)); + baseline.put("languageId", 0); + baseline.put("currentStomach", 0); + baseline.put("maxStomach", 100); + baseline.put("currentDrink", 0); + baseline.put("maxDrink", 100); + baseline.put("currentConsumable", 0); + baseline.put("maxConsumable", 100); + // The others are unknown, commented below. + // it won't send the rest and won't have to by using a lower object count. + // If we figure all these structs out all we have to do is add them the + // same way as above + /* + buffer.putInt(0); // Related to stomach in CU + buffer.putInt(0); // Related to stomach in CU + buffer.putInt(0); // Been seen as 0x0A + buffer.putInt(3); // Also been seen as 0x0A and 0x02 and 0x18 + buffer.putInt(0); + buffer.putInt(0); + buffer.putInt(0); + buffer.putInt(0); + buffer.putInt(0); + buffer.putInt(0); + buffer.putInt(0); // Unused Waypoint List? + buffer.putInt(0); // Update Counter? + buffer.putInt(2); // Unknown, sometimes a number and sometimes 0 + buffer.putInt(0); + buffer.putInt(0); + buffer.putInt(0); + buffer.putInt(0); + buffer.putInt(0); + buffer.putInt(0); + buffer.putInt(0); + buffer.putInt(0); + buffer.putInt(object.getJediState()); + buffer.putShort((short) 0); + */ + return baseline; + } + + @SuppressWarnings("unchecked") + public List getFlagsList() { + return (List) baseline3.get("flagsList"); + } + + public void setFlagsList(int flag1, int flag2, int flag3, int flag4) { + IoBuffer buffer; + + synchronized(objectMutex) { + List flagsList = getFlagsList(); + flagsList.set(0, flag1); + flagsList.set(1, flag2); + flagsList.set(2, flag3); + flagsList.set(3, flag4); + buffer = baseline3.set("flagsList", flagsList); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + @SuppressWarnings("unchecked") + public List getProfileFlagsList() { + return (List) baseline3.get("profileFlagsList"); + } + + public void setProfileFlagsList(int flag1, int flag2, int flag3, int flag4) { + IoBuffer buffer; + + synchronized(objectMutex) { + List profileFlagsList = getProfileFlagsList(); + profileFlagsList.set(0, flag1); + profileFlagsList.set(1, flag2); + profileFlagsList.set(2, flag3); + profileFlagsList.set(3, flag4); + buffer = baseline3.set("profileFlagsList", profileFlagsList); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public String getTitle() { + synchronized(objectMutex) { + return (String) baseline3.get("title"); + } + } + + public void setTitle(String title) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("title", title); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public int getBornDate() { + synchronized(objectMutex) { + return (int) baseline3.get("bornDate"); + } + } + + public long getLastPlayTimeUpdate() { + synchronized(objectMutex) { + return (long) baseline3.get("lastPlayTimeUpdate"); + } + } + + public void setLastPlayTimeUpdate(long lastPlayTimeUpdate) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("lastPlayTimeUpdate", lastPlayTimeUpdate); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public int getTotalPlayTime() { + synchronized(objectMutex) { + return (int) baseline3.get("totalPlayTime"); + } + } + + public void setTotalPlayTime(int totalPlayTime) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("totalPlayTime", totalPlayTime); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public int getProfessionIcon() { + synchronized(objectMutex) { + return (int) baseline3.get("professionIcon"); + } + } + + public void setProfessionIcon(int professionIcon) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("professionIcon", professionIcon); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public String getProfession() { + synchronized(objectMutex) { + return (String) baseline3.get("profession"); + } + } + + public void setProfession(String profession) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("profession", profession); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + + setProfessionIcon(Professions.get(profession)); + } + + public int getGcwPoints() { + synchronized(objectMutex) { + return (int) baseline3.get("gcwPoints"); + } + } + + public void addGcwPoints(int gcwPoints) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("gcwPoints", (((int) baseline3.get("gcwPoints")) + gcwPoints)); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public void resetGcwPoints() { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("gcwPoints", 0); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public int getPvpKills() { + synchronized(objectMutex) { + return (int) baseline3.get("pvpKills"); + } + } + + public void addPvpKill() { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("pvpKills", (((int) baseline3.get("pvpKills")) + 1)); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public void resetPvpKills() { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("pvpKills", 0); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public long getLifetimeGcwPoints() { + synchronized(objectMutex) { + return (long) baseline3.get("lifetimeGcwPoints"); + } + } + + public void addLifetimeGcwPoints(long gcwPoints) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("lifetimeGcwPoints", (((long) baseline3.get("lifetimeGcwPoints")) + gcwPoints)); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public int getLifetimePvpKills() { + synchronized(objectMutex) { + return (int) baseline3.get("lifetimePvpKills"); + } + } + + public void addLifetimePvpKills(int pvpKills) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("lifetimePvpKills", (((int) baseline3.get("lifetimePvpKills")) + pvpKills)); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public byte getAdminFlag() { + synchronized(objectMutex) { + return (byte) baseline6.get("adminFlag"); + } + } + + public void setAdminFlag(byte adminFlag) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("adminFlag", adminFlag); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public int getCurrentRank() { + synchronized(objectMutex) { + return (int) baseline6.get("currentRank"); + } + } + + public void setCurrentRank(int currentRank) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("currentRank", currentRank); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public float getRankProgress() { + synchronized(objectMutex) { + return (float) baseline6.get("rankProgress"); + } + } + + public void setRankProgress(float rankProgress) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("rankProgress", rankProgress); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public int getHighestRebelRank() { + synchronized(objectMutex) { + return (int) baseline6.get("highestRebelRank"); + } + } + + public void setHighestIRank(int highestRebelRank) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("highestRebelRank", highestRebelRank); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public int getHighestImperialRank() { + synchronized(objectMutex) { + return (int) baseline6.get("highestImperialRank"); + } + } + + public void setHighestImperialRank(int highestImperialRank) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("highestImperialRank", highestImperialRank); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public int getNextUpdateTime() { + synchronized(objectMutex) { + return (int) baseline6.get("nextUpdateTime"); + } + } + + public void setNextUpdateTime(int nextUpdateTime) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("nextUpdateTime", nextUpdateTime); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public String getHome() { + synchronized(objectMutex) { + return (String) baseline6.get("home"); + } + } + + public void setHome(String home) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("home", home); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public byte getCitizenship() { + synchronized(objectMutex) { + return (byte) baseline6.get("citizenship"); + } + } + + public void setCitizenship(byte citizenship) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("citizenship", citizenship); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public RegionDefender getCityRegionDefender() { + synchronized(objectMutex) { + return (RegionDefender) baseline6.get("cityRegionDefender"); + } + } + + public void setCityRegionDefender(RegionDefender cityRegionDefender) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("cityRegionDefender", cityRegionDefender); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public RegionDefender getGuildRegionDefender() { + synchronized(objectMutex) { + return (RegionDefender) baseline6.get("guildRegionDefender"); + } + } + + public void setGuildRegionDefender(RegionDefender guildRegionDefender) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("guildRegionDefender", guildRegionDefender); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + @SuppressWarnings("unchecked") + public SWGMap getXpList() { + return (SWGMap) baseline8.get("xpList"); + } + + @SuppressWarnings("unchecked") + public SWGMap getWaypoints() { + return (SWGMap) baseline8.get("waypoints"); + } + + public void waypointUpdate(WaypointObject waypoint) { + getWaypoints().put(waypoint.getObjectID(), waypoint); + } + + public void waypointRemove(WaypointObject waypoint) { + getWaypoints().remove(waypoint.getObjectID()); + } + + public void waypointAdd(WaypointObject waypoint) { + getWaypoints().put(waypoint.getObjectID(), waypoint); + } + + public WaypointObject getWaypointFromList(WaypointObject waypoint) { + synchronized(objectMutex) { + if (getWaypoints().containsKey(waypoint.getObjectID())) { + return getWaypoints().get(waypoint.getObjectID()); + } + } + + return null; + } + + public int getCurrentForcePower() { + synchronized(objectMutex) { + return (int) baseline8.get("currentForcePower"); + } + } + + public void setCurrentForcePower(int currentForcePower) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline8.set("currentForcePower", currentForcePower); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public int getMaxForcePower() { + synchronized(objectMutex) { + return (int) baseline8.get("maxForcePower"); + } + } + + public void setMaxForcePower(int maxForcePower) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline8.set("maxForcePower", maxForcePower); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + @SuppressWarnings("unchecked") + public SWGList getCurrentFSQuestList() { + return (SWGList) baseline8.get("currentFSQuestList"); + } + + @SuppressWarnings("unchecked") + public SWGList getCompletedFSQuestList() { + return (SWGList) baseline8.get("completedFSQuestList"); + } + + @SuppressWarnings("unchecked") + public SWGList getQuestJournal() { + return (SWGList) baseline8.get("questJournal"); + } + + public String getProfessionWheelPosition() { + synchronized(objectMutex) { + return (String) baseline8.get("professionWheelPosition"); + } + } + + public void setProfessionWheelPosition(String professionWheelPosition) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline8.set("professionWheelPosition", professionWheelPosition); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public int getExperimentationFlag() { + synchronized(objectMutex) { + return (int) baseline9.get("experimentationFlag"); + } + } + + public void setExperimentationFlag(int experimentationFlag) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline9.set("experimentationFlag", experimentationFlag); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public int getCraftingStage() { + synchronized(objectMutex) { + return (int) baseline9.get("craftingStage"); + } + } + + public void setCraftingStage(int craftingStage) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline9.set("craftingStage", craftingStage); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public long getNearestCraftingStation() { + synchronized(objectMutex) { + return (long) baseline9.get("nearestCraftingStation"); + } + } + + public void setNearestCraftingStation(long nearestCraftingStation) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline9.set("nearestCraftingStation", nearestCraftingStation); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + @SuppressWarnings("unchecked") + public SWGList getDraftSchematicList() { + return (SWGList) baseline9.get("draftSchematicList"); + } + + public int getExperimentationPoints() { + synchronized(objectMutex) { + return (int) baseline9.get("experimentationPoints"); + } + } + + public void setExperimentationPoints(int experimentationPoints) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline9.set("experimentationPoints", experimentationPoints); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public int getAccomplishmentCounter() { + synchronized(objectMutex) { + return (int) baseline9.get("accomplishmentCounter"); + } + } + + public void setAccomplishmentCounter(int accomplishmentCounter) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline9.set("accomplishmentCounter", accomplishmentCounter); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + @SuppressWarnings("unchecked") + public SWGList getFriendList() { + return (SWGList) baseline9.get("friendList"); + } + + public void friendAdd(String friend) { + getFriendList().add(friend); + } + + public void friendRemove(String friend) { + getFriendList().remove(friend); + } + + @SuppressWarnings("unchecked") + public SWGList getIgnoreList() { + return (SWGList) baseline9.get("ignoreList"); + } + + public void ignoreAdd(String name) { + getIgnoreList().add(name); + } + + public void ignoreRemove(String name) { + getIgnoreList().remove(name); + } + + public int getLanguageId() { + synchronized(objectMutex) { + return (int) baseline9.get("languageId"); + } + } + + public void setLanguageId(int languageId) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline9.set("languageId", languageId); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public int getCurrentStomach() { + synchronized(objectMutex) { + return (int) baseline9.get("currentStomach"); + } + } + + public void setCurrentStomach(int currentStomach) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline9.set("currentStomach", currentStomach); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public int getMaxStomach() { + synchronized(objectMutex) { + return (int) baseline9.get("maxStomach"); + } + } + + public void setMaxStomach(int maxStomach) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline9.set("maxStomach", maxStomach); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public int getCurrentDrink() { + synchronized(objectMutex) { + return (int) baseline9.get("currentDrink"); + } + } + + public void setCurrentDrink(int currentDrink) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline9.set("currentDrink", currentDrink); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public int getMaxDrink() { + synchronized(objectMutex) { + return (int) baseline9.get("maxDrink"); + } + } + + public void setMaxDrink(int maxDrink) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline9.set("maxDrink", maxDrink); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public int getCurrentConsumable() { + synchronized(objectMutex) { + return (int) baseline9.get("currentConsumable"); + } + } + + public void setCurrentConsumable(int currentConsumable) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline9.set("currentConsumable", currentConsumable); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + public int getMaxConsumable() { + synchronized(objectMutex) { + return (int) baseline9.get("maxConsumable"); + } + } + + public void setMaxConsumable(int maxConsumable) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline9.set("maxConsumable", maxConsumable); + } + + if (getContainer() != null) { + getContainer().notifyObservers(buffer, true); + } + } + + @Override + public void notifyClients(IoBuffer buffer, boolean notifySelf) { + if (getContainer() != null) { + getContainer().notifyObservers(buffer, notifySelf); + } + } + + @Override + public PlayerMessageBuilder getMessageBuilder() { + synchronized(objectMutex) { + if (messageBuilder == null) { + messageBuilder = new PlayerMessageBuilder(this); + } + + return messageBuilder; + } + } + + @Override + public void sendBaselines(Client destination) { + if (destination != null && destination.getSession() != null) { + //if(destination.getParent().getObjectID() == getParentId()) { // only send to self + //destination.getSession().write(getBaseline(3).getBaseline()); + //destination.getSession().write(getBaseline(6).getBaseline()); + //destination.getSession().write(getBaseline(8).getBaseline()); + //destination.getSession().write(getBaseline(9).getBaseline()); + //} + } + } + + @Override + public void sendListDelta(byte viewType, short updateType, IoBuffer buffer) { + if (getContainer() != null) { + getContainer().notifyObservers(getBaseline(viewType).createDelta(updateType, buffer.array()), true); + } + } + +} diff --git a/src/resources/z/exp/objects/resource/ResourceContainerMessageBuilder.java b/src/resources/z/exp/objects/resource/ResourceContainerMessageBuilder.java new file mode 100644 index 00000000..10450243 --- /dev/null +++ b/src/resources/z/exp/objects/resource/ResourceContainerMessageBuilder.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * 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.z.exp.objects.resource; + +public class ResourceContainerMessageBuilder { + +} diff --git a/src/resources/z/exp/objects/resource/ResourceContainerObject.java b/src/resources/z/exp/objects/resource/ResourceContainerObject.java new file mode 100644 index 00000000..a3ef31ad --- /dev/null +++ b/src/resources/z/exp/objects/resource/ResourceContainerObject.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * 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.z.exp.objects.resource; + +public class ResourceContainerObject { + +} diff --git a/src/resources/z/exp/objects/ship/ShipMessageBuilder.java b/src/resources/z/exp/objects/ship/ShipMessageBuilder.java new file mode 100644 index 00000000..a1a8de8e --- /dev/null +++ b/src/resources/z/exp/objects/ship/ShipMessageBuilder.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * 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.z.exp.objects.ship; + +public class ShipMessageBuilder { + +} diff --git a/src/resources/z/exp/objects/ship/ShipObject.java b/src/resources/z/exp/objects/ship/ShipObject.java new file mode 100644 index 00000000..5789f04d --- /dev/null +++ b/src/resources/z/exp/objects/ship/ShipObject.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * 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.z.exp.objects.ship; + +public class ShipObject { + +} diff --git a/src/resources/z/exp/objects/staticobject/StaticMessageBuilder.java b/src/resources/z/exp/objects/staticobject/StaticMessageBuilder.java new file mode 100644 index 00000000..5156390b --- /dev/null +++ b/src/resources/z/exp/objects/staticobject/StaticMessageBuilder.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * 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.z.exp.objects.staticobject; + +import java.util.Map; + +import resources.z.exp.objects.Builder; +import resources.z.exp.objects.ObjectMessageBuilder; + +public class StaticMessageBuilder extends ObjectMessageBuilder { + + public StaticMessageBuilder(StaticObject object) { + super(object); + } + + public StaticMessageBuilder() { + super(); + } + + @Override + public void buildBaseline3(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline3(baselineBuilders, deltaBuilders); + } + + @Override + public void buildBaseline6(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline6(baselineBuilders, deltaBuilders); + } + +} diff --git a/src/resources/z/exp/objects/staticobject/StaticObject.java b/src/resources/z/exp/objects/staticobject/StaticObject.java new file mode 100644 index 00000000..309be323 --- /dev/null +++ b/src/resources/z/exp/objects/staticobject/StaticObject.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * 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.z.exp.objects.staticobject; + +import org.apache.mina.core.buffer.IoBuffer; + +import resources.z.exp.objects.Baseline; +import resources.z.exp.objects.object.BaseObject; + +import com.sleepycat.persist.model.NotPersistent; +import com.sleepycat.persist.model.Persistent; + +import engine.clients.Client; +import engine.resources.scene.Planet; +import engine.resources.scene.Point3D; +import engine.resources.scene.Quaternion; + +@Persistent +public class StaticObject extends BaseObject { + + @NotPersistent + private StaticMessageBuilder messageBuilder; + + public StaticObject(long objectID, Planet planet, Point3D position, Quaternion orientation, String Template) { + super(objectID, planet, position, orientation, Template); + } + + public StaticObject() { + super(); + } + + @Override + public Baseline getOtherVariables() { + Baseline baseline = super.getOtherVariables(); + return baseline; + } + + @Override + public Baseline getBaseline3() { + Baseline baseline = super.getBaseline3(); + return baseline; + } + + @Override + public Baseline getBaseline6() { + Baseline baseline = super.getBaseline6(); + return baseline; + } + + @Override + public void notifyClients(IoBuffer buffer, boolean notifySelf) { + notifyObservers(buffer, false); + } + + @Override + public StaticMessageBuilder getMessageBuilder() { + synchronized(objectMutex) { + if (messageBuilder == null) { + messageBuilder = new StaticMessageBuilder(this); + } + + return messageBuilder; + } + } + + @Override + public void sendBaselines(Client destination) { + if (destination != null && destination.getSession() != null) { + //destination.getSession().write(baseline3.getBaseline()); + //destination.getSession().write(baseline6.getBaseline()); + } + } + +} diff --git a/src/resources/z/exp/objects/tangible/TangibleMessageBuilder.java b/src/resources/z/exp/objects/tangible/TangibleMessageBuilder.java new file mode 100644 index 00000000..0575128c --- /dev/null +++ b/src/resources/z/exp/objects/tangible/TangibleMessageBuilder.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.z.exp.objects.tangible; + +import java.util.Map; + +import com.sleepycat.persist.model.Persistent; + +import resources.z.exp.objects.Builder; +import resources.z.exp.objects.ObjectMessageBuilder; + +@Persistent +public class TangibleMessageBuilder extends ObjectMessageBuilder { + + public TangibleMessageBuilder(TangibleObject object) { + super(object); + } + + public TangibleMessageBuilder() { + super(); + } + + @Override + public void buildBaseline3(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline3(baselineBuilders, deltaBuilders); + } + + @Override + public void buildBaseline6(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline6(baselineBuilders, deltaBuilders); + } + + @Override + public void buildBaseline8(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline8(baselineBuilders, deltaBuilders); + } + + @Override + public void buildBaseline9(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline9(baselineBuilders, deltaBuilders); + } + +} diff --git a/src/resources/z/exp/objects/tangible/TangibleObject.java b/src/resources/z/exp/objects/tangible/TangibleObject.java new file mode 100644 index 00000000..1a54abb6 --- /dev/null +++ b/src/resources/z/exp/objects/tangible/TangibleObject.java @@ -0,0 +1,400 @@ +/******************************************************************************* + * 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.z.exp.objects.tangible; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.mina.core.buffer.IoBuffer; + +import resources.datatables.FactionStatus; +import resources.z.exp.objects.Baseline; +import resources.z.exp.objects.SWGList; +import resources.z.exp.objects.creature.CreatureObject; +import resources.z.exp.objects.object.BaseObject; + +import com.sleepycat.persist.model.NotPersistent; +import com.sleepycat.persist.model.Persistent; + +import engine.clients.Client; +import engine.resources.common.CRC; +import engine.resources.scene.Planet; +import engine.resources.scene.Point3D; +import engine.resources.scene.Quaternion; + +@Persistent +public class TangibleObject extends BaseObject { + + @NotPersistent + private TangibleMessageBuilder messageBuilder; + + @NotPersistent + private List defendersList = new ArrayList(); + + public TangibleObject(long objectID, Planet planet, Point3D position, Quaternion orientation, String template) { + super(objectID, planet, position, orientation, template); + } + + public TangibleObject(long objectID, Planet planet, String template) { + super(objectID, planet, new Point3D(0, 0, 0), new Quaternion(1, 0, 1, 0), template); + } + + public TangibleObject() { + super(); + } + + @Override + public void initializeBaselines() { + super.initializeBaselines(); + initializeBaseline(8); + initializeBaseline(9); + } + + @Override + public Baseline getOtherVariables() { + Baseline baseline = super.getOtherVariables(); + baseline.put("faction", ""); + baseline.put("pvpBitmask", 0); + return baseline; + } + + @Override + public Baseline getBaseline3() { + Baseline baseline = super.getBaseline3(); + baseline.put("faction", 0); + baseline.put("factionStatus", 0); + baseline.put("customization", new Byte[] { 0x00, 0x00 }); + baseline.put("componentCustomizationList", new SWGList(this, 3, 7, false)); + baseline.put("optionsBitmask", 0); + baseline.put("incapacityTimer", 0); + baseline.put("conditionDamage", 0); + baseline.put("maximumCondition", 0); + baseline.put("isStatic", false); + return baseline; + } + + @Override + public Baseline getBaseline6() { + Baseline baseline = super.getBaseline6(); + baseline.put("inCombat", false); + baseline.put("3", (long) 0); // Unknown + baseline.put("4", (long) 0); // Unknown + baseline.put("5", (long) 0); // Unknown + baseline.put("6", (long) 0); // Unknown + baseline.put("7", 0); // Unknown + return baseline; + } + + @Override + public Baseline getBaseline8() { + Baseline baseline = super.getBaseline8(); + return baseline; + } + + @Override + public Baseline getBaseline9() { + Baseline baseline = super.getBaseline9(); + return baseline; + } + + public String getFaction() { + synchronized(objectMutex) { + return (String) otherVariables.get("faction"); + } + } + + public void setFaction(String faction) { + IoBuffer buffer; + + synchronized(objectMutex) { + otherVariables.set("faction", faction); + buffer = baseline3.set("faction", CRC.StringtoCRC(faction)); + } + + notifyClients(buffer, true); + } + + public int getFactionStatus() { + synchronized(objectMutex) { + return (int) baseline3.get("factionStatus"); + } + } + + public void setFactionStatus(int factionStatus) { + switch (factionStatus) { + case FactionStatus.OnLeave: + case FactionStatus.Combatant: + case FactionStatus.SpecialForces: + break; + default: + factionStatus = 0; + } + + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("factionStatus", factionStatus); + } + + notifyClients(buffer, true); + } + + public byte[] getCustomization() { + synchronized(objectMutex) { + return (byte[]) baseline3.get("customization"); + } + } + + public void setCustomization(byte[] customization) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("customization", customization); + } + + notifyClients(buffer, true); + } + + @SuppressWarnings("unchecked") + public SWGList getComponentCustomizationList() { + return (SWGList) baseline3.get("componentCustomizationList"); + } + + public int getOptionsBitmask() { + synchronized(objectMutex) { + return (int) baseline3.get("optionsBitmask"); + } + } + + public void setOptionsBitmask(int optionsBitmask) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("optionsBitmask", optionsBitmask); + } + + notifyClients(buffer, true); + } + + public int getIncapacityTimer() { + synchronized(objectMutex) { + return (int) baseline3.get("incapacityTimer"); + } + } + + public void setIncapacityTimer(int incapacityTimer) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("incapacityTimer", incapacityTimer); + } + + notifyClients(buffer, true); + } + + public int getConditionDamage() { + synchronized(objectMutex) { + return (int) baseline3.get("conditionDamage"); + } + } + + public void setConditionDamage(int conditionDamage) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("conditionDamage", conditionDamage); + } + + notifyClients(buffer, true); + } + + public int getMaximumCondition() { + synchronized(objectMutex) { + return (int) baseline3.get("maximumCondition"); + } + } + + public void setMaximumCondition(int maximumCondition) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("maximumCondition", maximumCondition); + } + + notifyClients(buffer, true); + } + + public boolean isStatic() { + synchronized(objectMutex) { + return (boolean) baseline3.get("isStatic"); + } + } + + public void setStatic(boolean isStatic) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("isStatic", isStatic); + } + + notifyClients(buffer, true); + } + + public void toggleStatic() { + setStatic(!isStatic()); + } + + public boolean inCombat() { + synchronized(objectMutex) { + return (boolean) baseline6.get("inCombat"); + } + } + + public void setInCombat(boolean inCombat) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline6.set("inCombat", inCombat); + } + + notifyClients(buffer, true); + } + + public void toggleCombat() { + setInCombat(!inCombat()); + } + + public List getDefendersList() { + return defendersList; + } + + // All objects can be in combat (terminal mission flag bases, tutorial target box) + public void addDefender(TangibleObject defender) { + defendersList.add(defender); + + if (!inCombat()) { + setInCombat(true); + } + } + + public void removeDefender(TangibleObject defender) { + defendersList.remove(defender); + + if (defendersList.isEmpty() && inCombat()) { + setInCombat(false); + } + } + + public int getPvPBitmask() { + synchronized(objectMutex) { + return (int) otherVariables.get("pvpBitmask"); + } + } + + public void setPvPBitmask(int pvpBitmask) { + synchronized(objectMutex) { + otherVariables.set("pvpBitmask", pvpBitmask); + } + } + + public boolean isAttackableBy(CreatureObject attacker) { + CreatureObject creature; + + if (this instanceof CreatureObject) { + creature = (CreatureObject) this; + + if (creature.getDuelList().contains(attacker) && attacker.getDuelList().contains(this)) { + return true; + } + } + + if (getFaction().equals("rebel") && attacker.getFaction().equals("rebel")) { + return false; + } else if (getFaction().equals("imperial") && attacker.getFaction().equals("imperial")) { + return false; + } else if(attacker.getSlottedObject("ghost") != null) { + if (this instanceof CreatureObject && getSlottedObject("ghost") != null) { + creature = (CreatureObject) this; + + if (creature.getFactionStatus() == 2 && attacker.getFactionStatus() == 2) { + return true; + } else { + return false; + } + } + + if ((getFaction().equals("rebel") || getFaction().equals("imperial")) && attacker.getFactionStatus() >= 1) { + return true; + } else if ((getFaction().equals("rebel") || getFaction().equals("imperial")) && attacker.getFactionStatus() == 0) { + return false; + } + + return getPvPBitmask() == 1 || getPvPBitmask() == 2; + } + + return getPvPBitmask() == 1 || getPvPBitmask() == 2; + } + + @Override + public void notifyClients(IoBuffer buffer, boolean notifySelf) { + notifyObservers(buffer, false); + } + + @Override + public TangibleMessageBuilder getMessageBuilder() { + synchronized(objectMutex) { + if (messageBuilder == null) { + messageBuilder = new TangibleMessageBuilder(this); + } + + return messageBuilder; + } + } + + @Override + public void sendBaselines(Client destination) { + if (destination != null && destination.getSession() != null) { + //destination.getSession().write(baseline3.getBaseline()); + //destination.getSession().write(baseline6.getBaseline()); + //destination.getSession().write(baseline8.getBaseline()); + //destination.getSession().write(baseline9.getBaseline()); + } + } + + @Override + public void sendListDelta(byte viewType, short updateType, IoBuffer buffer) { + switch (viewType) { + case 3: + { + switch (updateType) { + case 7: + { + buffer = baseline3.createDelta(7, buffer.array()); + notifyClients(buffer, true); + break; + } + } + } + } + } + +} diff --git a/src/resources/z/exp/objects/universe/UniverseMessageBuilder.java b/src/resources/z/exp/objects/universe/UniverseMessageBuilder.java new file mode 100644 index 00000000..d318a313 --- /dev/null +++ b/src/resources/z/exp/objects/universe/UniverseMessageBuilder.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * 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.z.exp.objects.universe; + +import resources.z.exp.objects.ObjectMessageBuilder; + +public class UniverseMessageBuilder extends ObjectMessageBuilder { + + public UniverseMessageBuilder(UniverseObject object) { + super(object); + } + + public UniverseMessageBuilder() { + super(); + } + +} diff --git a/src/resources/z/exp/objects/universe/UniverseObject.java b/src/resources/z/exp/objects/universe/UniverseObject.java new file mode 100644 index 00000000..e01bbf1e --- /dev/null +++ b/src/resources/z/exp/objects/universe/UniverseObject.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * 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.z.exp.objects.universe; + +import org.apache.mina.core.buffer.IoBuffer; + +import resources.z.exp.objects.Baseline; +import resources.z.exp.objects.object.BaseObject; + +import com.sleepycat.persist.model.NotPersistent; +import com.sleepycat.persist.model.Persistent; + +import engine.clients.Client; +import engine.resources.scene.Planet; +import engine.resources.scene.Point3D; +import engine.resources.scene.Quaternion; + +@Persistent +public class UniverseObject extends BaseObject { + + @NotPersistent + private UniverseMessageBuilder messageBuilder; + + public UniverseObject(long objectID, Planet planet, Point3D position, Quaternion orientation, String Template) { + super(objectID, planet, position, orientation, Template); + } + + public UniverseObject() { + super(); + } + + @Override + public void initializeBaselines() { + super.initializeBaselines(); + } + + @Override + public Baseline getOtherVariables() { + Baseline baseline = super.getOtherVariables(); + return baseline; + } + + @Override + public void notifyClients(IoBuffer buffer, boolean notifySelf) { + notifyObservers(buffer, false); + } + + @Override + public UniverseMessageBuilder getMessageBuilder() { + synchronized(objectMutex) { + if (messageBuilder == null) { + messageBuilder = new UniverseMessageBuilder(this); + } + + return messageBuilder; + } + } + + @Override + public void sendBaselines(Client destination) { + + } + +} diff --git a/src/resources/z/exp/objects/waypoint/WaypointObject.java b/src/resources/z/exp/objects/waypoint/WaypointObject.java new file mode 100644 index 00000000..df08f5ca --- /dev/null +++ b/src/resources/z/exp/objects/waypoint/WaypointObject.java @@ -0,0 +1,172 @@ +/******************************************************************************* + * 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.z.exp.objects.waypoint; + +import java.nio.ByteOrder; + +import org.apache.mina.core.buffer.IoBuffer; + +import resources.common.StringUtilities; +import resources.objects.IDelta; +import resources.z.exp.objects.intangible.IntangibleObject; +import resources.z.exp.objects.Baseline; + +import com.sleepycat.persist.model.Persistent; + +import engine.clients.Client; +import engine.resources.scene.Planet; +import engine.resources.scene.Point3D; +import engine.resources.scene.Quaternion; + +@Persistent +public class WaypointObject extends IntangibleObject implements IDelta { + + public static final byte BLUE, GREEN, ORANGE, YELLOW, PURPLE, WHITE, MULTICOLOR; + + static { + BLUE = 1; + GREEN = 2; + ORANGE = 3; + YELLOW = 4; + PURPLE = 5; + WHITE = 6; + MULTICOLOR = 7; + }; + + // WAYP 3 + private int cellId; + //private Point3D position = new Point3D(0, 0, 0); + private long targetId = 0; + private int planetCrc = 0; + private String name = "Waypoint"; + //private long waypointId = 0; + private byte color = 1; + private boolean isActive = false; + + public WaypointObject(long objectID, Planet planet, Point3D position) { + super(objectID, planet, position, new Quaternion(0, 0, 0, 1), "object/waypoint/shared_waypoint.iff"); + } + + public WaypointObject() { + super(); + } + + public int getCellId() { + synchronized(objectMutex) { + return cellId; + } + } + + public void setCellId(int cellId) { + synchronized(objectMutex) { + this.cellId = cellId; + } + } + + public long getTargetId() { + synchronized(objectMutex) { + return targetId; + } + } + + public void setTargetId(long targetId) { + synchronized(objectMutex) { + this.targetId = targetId; + } + } + + public int getPlanetCrc() { + synchronized(objectMutex) { + return planetCrc; + } + } + + public void setPlanetCrc(int planetCrc) { + synchronized(objectMutex) { + this.planetCrc = planetCrc; + } + } + + public String getName() { + synchronized(objectMutex) { + return name; + } + } + + public void setName(String name) { + synchronized(objectMutex) { + this.name = name; + } + } + + public byte getColor() { + synchronized(objectMutex) { + return color; + } + } + + public void setColor(byte color) { + synchronized(objectMutex) { + this.color = color; + } + } + + public boolean isActive() { + synchronized(objectMutex) { + return isActive; + } + } + + public void setActive(boolean isActive) { + synchronized(objectMutex) { + this.isActive = isActive; + } + } + + public void toggleActive() { + setActive(!isActive()); + } + + @Override + public void sendBaselines(Client destination) { + + } + + public byte[] getBytes() { + synchronized(objectMutex) { + IoBuffer buffer = IoBuffer.allocate(42, false).order(ByteOrder.LITTLE_ENDIAN).setAutoExpand(true); + buffer.putInt(cellId); + buffer.putFloat(getPosition().x); + buffer.putFloat(getPosition().y); + buffer.putFloat(getPosition().z); + buffer.putLong(targetId); + buffer.putInt(planetCrc); + buffer.put(StringUtilities.getUnicodeString(name)); + buffer.putLong(getObjectID()); + buffer.put(color); + buffer.put(Baseline.getBoolean(isActive)); + buffer.flip(); + return buffer.array(); + } + } + +} diff --git a/src/resources/z/exp/objects/weapon/WeaponMessageBuilder.java b/src/resources/z/exp/objects/weapon/WeaponMessageBuilder.java new file mode 100644 index 00000000..860f5bd2 --- /dev/null +++ b/src/resources/z/exp/objects/weapon/WeaponMessageBuilder.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * 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.z.exp.objects.weapon; + +import java.util.Map; + +import resources.z.exp.objects.Baseline; +import resources.z.exp.objects.Builder; +import resources.z.exp.objects.tangible.TangibleMessageBuilder; + +public class WeaponMessageBuilder extends TangibleMessageBuilder { + + public WeaponMessageBuilder(WeaponObject weaponObject) { + super(weaponObject); + } + + public WeaponMessageBuilder() { + super(); + } + + @Override + public void buildBaseline3(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline3(baselineBuilders, deltaBuilders); + } + + @Override + public void buildBaseline6(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline6(baselineBuilders, deltaBuilders); + + baselineBuilders.put(13, new Builder() { + + public byte[] build() { + return Baseline.createBuffer(4).putInt(((WeaponObject) object).getWeaponType()).array(); + } + + }); + + deltaBuilders.put(13, new Builder() { + + public byte[] build() { + return Baseline.createBuffer(4).putInt(((WeaponObject) object).getWeaponType()).array(); + } + + }); + + } + + @Override + public void buildBaseline8(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline8(baselineBuilders, deltaBuilders); + } + + @Override + public void buildBaseline9(Map baselineBuilders, Map deltaBuilders) { + super.buildBaseline9(baselineBuilders, deltaBuilders); + } + +} diff --git a/src/resources/z/exp/objects/weapon/WeaponObject.java b/src/resources/z/exp/objects/weapon/WeaponObject.java new file mode 100644 index 00000000..d1b92a7b --- /dev/null +++ b/src/resources/z/exp/objects/weapon/WeaponObject.java @@ -0,0 +1,246 @@ +/******************************************************************************* + * 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.z.exp.objects.weapon; + +import org.apache.mina.core.buffer.IoBuffer; + +import resources.z.exp.objects.Baseline; +import resources.z.exp.objects.tangible.TangibleObject; + +import com.sleepycat.persist.model.NotPersistent; +import com.sleepycat.persist.model.Persistent; + +import engine.clients.Client; +import engine.resources.scene.Planet; +import engine.resources.scene.Point3D; +import engine.resources.scene.Quaternion; + +@Persistent +public class WeaponObject extends TangibleObject { + + @NotPersistent + private WeaponMessageBuilder messageBuilder; + + public WeaponObject(long objectID, Planet planet, String template) { + super(objectID, planet, new Point3D(0, 0, 0), new Quaternion(1, 0, 1, 0), template); + } + + public WeaponObject(long objectID, Planet planet, Point3D position, Quaternion orientation, String template) { + super(objectID, planet, position, orientation, template); + } + + public WeaponObject() { + super(); + } + + @Override + public void initializeBaselines() { + super.initializeBaselines(); + initializeBaseline(8); + initializeBaseline(9); + } + + @Override + public Baseline getOtherVariables() { + Baseline baseline = super.getOtherVariables(); + baseline.put("maxDamage", 0); + return baseline; + } + + @Override + public Baseline getBaseline3() { + Baseline baseline = super.getBaseline3(); + baseline.put("attackSpeed", (float) 1); + baseline.put("14", 0); + baseline.put("15", 0); + baseline.put("maxRange", calculateRange()); + baseline.put("17", 0); // Could be lightsaber color? Seen as 2 on a saber + baseline.put("18", 0); // something to do with particle color + baseline.put("19", 0); // something to do with particle color + return baseline; + } + + @Override + public Baseline getBaseline6() { + Baseline baseline = super.getBaseline6(); + baseline.put("weaponType", 0); + return baseline; + } + + @Override + public Baseline getBaseline8() { + Baseline baseline = super.getBaseline8(); + return baseline; + } + + @Override + public Baseline getBaseline9() { + Baseline baseline = super.getBaseline9(); + return baseline; + } + + public float getAttackSpeed() { + synchronized(objectMutex) { + return (float) baseline3.get("attackSpeed"); + } + } + + public void setAttackSpeed(float attackSpeed) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("attackSpeed", attackSpeed); + } + + notifyClients(buffer, false); + } + + private float calculateRange() { + int weaponType = getWeaponType(); + + switch (weaponType) { + case 4: + case 5: + case 6: + case 7: + case 9: + case 10: + case 11: + return 5; + case 2: + return 35; + case 1: + return 50; + case 0: + case 3: + case 8: + return 64; + default: + return 0; + } + } + + public float getMaxRange() { + synchronized(objectMutex) { + return (float) baseline3.get("maxRange"); + } + } + + public void setMaxRange(float maxRange) { + IoBuffer buffer; + + synchronized(objectMutex) { + buffer = baseline3.set("maxRange", maxRange); + } + + notifyClients(buffer, false); + } + + public int getWeaponType() { + String template = getTemplate(); + int weaponType = -1; + + synchronized(objectMutex) { + if (template == null) { + return weaponType; + } + + if (template.contains("rifle")) weaponType = 0; + if (template.contains("carbine")) weaponType = 1; + if (template.contains("pistol")) weaponType = 2; + if (template.contains("heavy")) weaponType = 3; + if (template.contains("sword") || template.contains("baton")) weaponType = 4; + if (template.contains("2h_sword") || template.contains("axe")) weaponType = 5; + if (template.contains("unarmed")) weaponType = 6; + if (template.contains("polearm") || template.contains("lance")) weaponType = 7; + if (template.contains("thrown")) weaponType = 8; + if (template.contains("lightsaber_one_handed")) weaponType = 9; + if (template.contains("lightsaber_two_handed")) weaponType = 10; + if (template.contains("lightsaber_polearm")) weaponType = 11; + + if (weaponType == -1) { + weaponType = 6; + } + + return weaponType; + } + } + + public int getMaxDamage() { + synchronized(objectMutex) { + return (int) otherVariables.get("maxDamage"); + } + } + + public void setMaxDamage(int maxDamage) { + synchronized(objectMutex) { + otherVariables.set("maxDamage", maxDamage); + } + } + + public boolean isMelee() { + int weaponType = getWeaponType(); + + if ((weaponType > 4 && weaponType < 8) || (weaponType > 8 && weaponType < 12)) { + return true; + } + + return false; + } + + public boolean isRanged() { + int weaponType = getWeaponType(); + + if (weaponType == 0 || weaponType == 1 || weaponType == 2 || weaponType == 3) { + return true; + } + + return false; + } + + @Override + public void notifyClients(IoBuffer buffer, boolean notifySelf) { + notifyObservers(buffer, notifySelf); + } + + @Override + public WeaponMessageBuilder getMessageBuilder() { + synchronized(objectMutex) { + if (messageBuilder == null) { + messageBuilder = new WeaponMessageBuilder(this); + } + + return messageBuilder; + } + } + + @Override + public void sendBaselines(Client destination) { + if (destination != null && destination.getSession() != null) { + //destination.getSession().write(baseline3.getBaseline()); + //destination.getSession().write(baseline6.getBaseline()); + //destination.getSession().write(baseline8.getBaseline()); + //destination.getSession().write(baseline9.getBaseline()); + } + } + +} diff --git a/src/resources/z/exp/quest/Quest.java b/src/resources/z/exp/quest/Quest.java new file mode 100644 index 00000000..9dfc1ae4 --- /dev/null +++ b/src/resources/z/exp/quest/Quest.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * 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.z.exp.quest; + +import resources.objects.Delta; + +public class Quest extends Delta { + + public Quest() { + + } + + public byte[] getBytes() { + return new byte[] { }; + } + +} diff --git a/src/resources/z/exp/skills/SkillMod.java b/src/resources/z/exp/skills/SkillMod.java new file mode 100644 index 00000000..82cdb237 --- /dev/null +++ b/src/resources/z/exp/skills/SkillMod.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * 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.z.exp.skills; + +import java.nio.ByteOrder; + +import org.apache.mina.core.buffer.IoBuffer; + +import com.sleepycat.persist.model.Persistent; + +import resources.objects.Delta; + +// Proxy for engine.resources.objects.SkillMod so it uses Delta + +@Persistent +public class SkillMod extends Delta { + + private int base = 0; + private int modifier = 0; + + public SkillMod(int base, int modifier) { + engine.resources.objects.SkillMod skillMod = new engine.resources.objects.SkillMod(); + skillMod.setBase(base); + skillMod.setModifier(modifier); + this.base = skillMod.getBase(); + this.modifier = skillMod.getModifier(); + } + + public SkillMod() { + + } + + public int getBase() { + synchronized(objectMutex) { + engine.resources.objects.SkillMod skillMod = new engine.resources.objects.SkillMod(); + skillMod.setBase(base); + skillMod.setModifier(modifier); + return skillMod.getBase(); + } + } + + public void setBase(int base) { + synchronized(objectMutex) { + engine.resources.objects.SkillMod skillMod = new engine.resources.objects.SkillMod(); + skillMod.setBase(this.base); + skillMod.setModifier(modifier); + skillMod.setBase(base); + this.base = skillMod.getBase(); + } + } + + public int getModifier() { + synchronized(objectMutex) { + engine.resources.objects.SkillMod skillMod = new engine.resources.objects.SkillMod(); + skillMod.setBase(base); + skillMod.setModifier(modifier); + return skillMod.getModifier(); + } + } + + public void setModifier(int modifier) { + synchronized(objectMutex) { + engine.resources.objects.SkillMod skillMod = new engine.resources.objects.SkillMod(); + skillMod.setBase(base); + skillMod.setModifier(this.modifier); + skillMod.setModifier(modifier); + this.modifier = skillMod.getModifier(); + } + } + + public byte[] getBytes() { + synchronized(objectMutex) { + IoBuffer buffer = bufferPool.allocate(8, false).order(ByteOrder.LITTLE_ENDIAN); + engine.resources.objects.SkillMod skillMod = new engine.resources.objects.SkillMod(); + skillMod.setBase(base); + skillMod.setModifier(modifier); + buffer.putInt(skillMod.getBase()); + buffer.putInt(skillMod.getModifier()); + return buffer.array(); + } + } + +} diff --git a/src/services/CharacterService.java b/src/services/CharacterService.java index c9bb3d83..aee93138 100644 --- a/src/services/CharacterService.java +++ b/src/services/CharacterService.java @@ -361,7 +361,7 @@ public class CharacterService implements INetworkDispatch { PreparedStatement ps2 = databaseConnection.preparedStatement("SELECT \"accountId\" FROM temp_reserved_char_names WHERE \"accountId\"!=? AND LOWER(\"firstName\")=?"); ps2.setLong(1, accountId); - ps2.setString(2, firstName); + ps2.setString(2, firstName.toLowerCase()); ResultSet resultSet2 = ps2.executeQuery(); boolean isReserved = resultSet2.next(); resultSet2.getStatement().close(); diff --git a/src/services/LoginService.java b/src/services/LoginService.java index a4904be8..5343ecae 100644 --- a/src/services/LoginService.java +++ b/src/services/LoginService.java @@ -100,6 +100,7 @@ public class LoginService implements INetworkDispatch{ String user = clientID.getAccountName(); String pass = clientID.getPassword(); int id = LoginProvider.getAccountId(user, pass, session.getRemoteAddress().toString()); + System.out.println("LOGIN: " + user + " login attempt "+session.getRemoteAddress().toString()+" returned " + id); if (id < 0) { diff --git a/src/services/PlayerService.java b/src/services/PlayerService.java index a0c536eb..e0d001a2 100644 --- a/src/services/PlayerService.java +++ b/src/services/PlayerService.java @@ -68,6 +68,7 @@ import engine.resources.common.CRC; import engine.resources.objects.DraftSchematic; import engine.resources.objects.SWGObject; import engine.resources.scene.Point3D; +import engine.resources.scene.Quaternion; import engine.resources.service.INetworkDispatch; import engine.resources.service.INetworkRemoteEvent; @@ -475,12 +476,15 @@ public class PlayerService implements INetworkDispatch { } try { + String customServerTemplate = null; + if (!item.contains("/")) { + customServerTemplate = item; item = core.scriptService.callScript("scripts/roadmap/", "roadmap_rewards", "get", item).asString(); } if (item != null && item != "") { - creature.getSlottedObject("inventory").add(core.objectService.createObject(item, creature.getPlanet())); + creature.getSlottedObject("inventory").add(core.objectService.createObject(item, 0, creature.getPlanet(), new Point3D(0, 0, 0), new Quaternion(1, 0, 0, 0), customServerTemplate)); } else { //System.out.println("Can't find template: " + item); } diff --git a/src/services/TerrainService.java b/src/services/TerrainService.java index e58d6cfa..960d48f0 100644 --- a/src/services/TerrainService.java +++ b/src/services/TerrainService.java @@ -191,10 +191,18 @@ public class TerrainService { public void run() { Config config = new Config(); config.setFilePath("options.cfg"); + boolean loaded = config.loadConfigFile(); - if (config.loadConfigFile() && config.getInt("LOAD.SNAPSHOT_OBJECTS") > 0) { + if (loaded && config.getInt("LOAD.SNAPSHOT_OBJECTS") > 0) { try { core.objectService.loadSnapshotObjects(planet); + } catch (Exception e) { + e.printStackTrace(); + } + } + + if (loaded && config.getInt("LOAD.BUILDOUT_OBJECTS") > 0) { + try { core.objectService.loadBuildoutObjects(planet); } catch (InstantiationException | IllegalAccessException e) { e.printStackTrace(); diff --git a/src/services/object/ObjectService.java b/src/services/object/ObjectService.java index 8107835f..42726dde 100644 --- a/src/services/object/ObjectService.java +++ b/src/services/object/ObjectService.java @@ -225,7 +225,7 @@ public class ObjectService implements INetworkDispatch { object.setPlanetId(planet.getID()); - object.setAttachment("serverTemplate", ((customServerTemplate != null) ? customServerTemplate : object.getTemplate())); + object.setAttachment("customServerTemplate", customServerTemplate); object.setisInSnapshot(isSnapshot); loadServerTemplate(object); @@ -268,7 +268,7 @@ public class ObjectService implements INetworkDispatch { public void loadServerTemplate(SWGObject object) { - String template = ((object.getAttachment("serverTemplate") == null) ? object.getTemplate() : ((String) object.getAttachment("serverTemplate"))); + String template = ((object.getAttachment("customServerTemplate") == null) ? object.getTemplate() : (object.getTemplate().split("shared_")[0] + "shared_" + ((String) object.getAttachment("customServerTemplate")) + ".iff")); String serverTemplate = template.replace(".iff", ""); // check if template is empty(4 default lines) to reduce RAM usage(saves about 500 MB of RAM) try {