Conflicts:
	src/services/bazaar/BazaarService.java
This commit is contained in:
Light2
2014-04-15 01:12:44 +02:00
53 changed files with 1317 additions and 291 deletions
@@ -27,7 +27,6 @@ import java.util.Vector;
import org.apache.mina.core.buffer.IoBuffer;
import resources.objects.ObjectMessageBuilder;
import resources.objects.harvester.HarvesterObject;
public class BuildingMessageBuilder extends ObjectMessageBuilder {
@@ -0,0 +1,46 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* 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 <http://www.gnu.org/licenses/>.
*
* Using NGEngine to work with NGECore2 is making a combined work based on NGEngine.
* Therefore all terms and conditions of the GNU Lesser General Public License cover the combination.
******************************************************************************/
package resources.objects.craft;
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 DraftSchematic extends SWGObject {
public DraftSchematic(long objectID, Planet planet, String template, Point3D position, Quaternion orientation){
super(objectID, planet, position, orientation, template);
}
@Override
public void sendBaselines(Client arg0) {
// TODO Auto-generated method stub
}
}
@@ -1149,8 +1149,7 @@ public class CreatureMessageBuilder extends ObjectMessageBuilder {
buffer.putLong(ownerId);
int size = buffer.position();
buffer.flip();
//buffer = createDelta("CREO", (byte) 3, (short) 1, (short) 0x0D, buffer, size + 4); 0F,12 doesnt crash
buffer = createDelta("CREO", (byte) 3, (short) 1, (short) 0x0F, buffer, size + 4); // checked from 0xA up to 0x1F
buffer = createDelta("CREO", (byte) 3, (short) 1, (short) 0x0F, buffer, size + 4); // This is the correct one
return buffer;
}
@@ -1799,18 +1799,26 @@ public class CreatureObject extends TangibleObject implements IPersistent {
this.mountedVehicle = mountedVehicle;
}
public boolean canMount(CreatureObject vehicle)
{
if(vehicle.getOwnerId() == this.getObjectId()) return true;
return false;
}
public void mount(CreatureObject owner) {
boolean remove = false;
synchronized(objectMutex) {
if ((this.getOptionsBitmask() & Options.MOUNT) == Options.MOUNT){
synchronized(objectMutex)
{
if ((this.getOptionsBitmask() & Options.MOUNT) == Options.MOUNT)
{
remove = true;
_add(owner);
UpdateContainmentMessage updateContainmentMessage = new UpdateContainmentMessage(owner.getObjectID(), this.getObjectID(), 4);
notifyObservers(updateContainmentMessage, true);
}
}
if(remove)
NGECore.getInstance().simulationService.remove(owner, owner.getWorldPosition().x, owner.getWorldPosition().z, false);
if(remove) NGECore.getInstance().simulationService.remove(owner, owner.getWorldPosition().x, owner.getWorldPosition().z, false);
}
public void unmount(CreatureObject owner) {
@@ -1835,19 +1843,13 @@ public class CreatureObject extends TangibleObject implements IPersistent {
public void initMount(CreatureObject owner) {
synchronized(objectMutex) {
this.ownerId = owner.getObjectID();
setStateBitmask(0x10000000);
owner.setMountedVehicle(this);
this.setOwnerId(owner.getObjectID());
//this.add(owner); // NPE at engine.resources.objects.SWGObject.getCorrectArrangementId(kd:844)
this.mount(owner);
// setStateBitmask(28);
// owner.setStateBitmask(27);
owner.setStateBitmask(0x8000000);
this.setPosture((byte)10);
//this.sendBaselines(owner.getClient());
}
}
@@ -21,6 +21,156 @@
******************************************************************************/
package resources.objects.factorycrate;
public class FactoryCrateMessageBuilder {
import java.nio.ByteOrder;
import org.apache.mina.core.buffer.IoBuffer;
import resources.objects.ObjectMessageBuilder;
import resources.objects.resource.GalacticResource;
import resources.objects.resource.ResourceContainerObject;
/**
* @author Charon
*/
public class FactoryCrateMessageBuilder extends ObjectMessageBuilder{
public FactoryCrateMessageBuilder(FactoryCrateObject factoryCrateObject) {
setObject(factoryCrateObject);
}
public IoBuffer buildBaseline3() {
FactoryCrateObject factoryCrateObject = (FactoryCrateObject) object;
IoBuffer buffer = IoBuffer.allocate(10).order(ByteOrder.LITTLE_ENDIAN);
buffer.setAutoExpand(true);
buffer.putShort((short)0x0D);
buffer.putFloat(1.0f); //op0
buffer.put(getAsciiString("factory_n"));
buffer.putInt(0);
buffer.put(getAsciiString("food_crate"));
if (factoryCrateObject.getCustomName().length()>0)
buffer.put(getUnicodeString(factoryCrateObject.getCustomName()));
else
buffer.putInt(0);
buffer.putInt(1);
buffer.putShort((short)0);
buffer.putInt(0);
buffer.putInt(0);
buffer.putInt(0);
buffer.putInt(0);
buffer.putInt(0x2100); // optionsbitmask
buffer.putInt((int)factoryCrateObject.getQuantity()); // Quantity // op9
buffer.putInt(0);
buffer.putInt(0x64); // condition maybe
buffer.put((byte)1);
int size = buffer.position();
buffer = bufferPool.allocate(size, false).put(buffer.array(), 0, size);
buffer.flip();
buffer = createBaseline("TYCF", (byte) 3, buffer, size);
return buffer;
// 01 00 00 00
// 00 00
// 00 00 00 00
// 00 00 00 00
// 00 00 00 00
// 00 00 00 00
// 00 21 00 00
// 2A 00 00 00
// 00 00 00 00
// 64 00 00 00
// 01
}
public IoBuffer buildBaseline6() {
FactoryCrateObject factoryCrateObject = (FactoryCrateObject) object;
IoBuffer buffer = IoBuffer.allocate(10).order(ByteOrder.LITTLE_ENDIAN);
buffer.setAutoExpand(true);
buffer.putShort((short)6);
buffer.putInt(3);
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(0);
buffer.putInt(0);
buffer.putInt(0);
buffer.put((byte)0);
int size = buffer.position();
buffer = bufferPool.allocate(size, false).put(buffer.array(), 0, size);
buffer.flip();
buffer = createBaseline("TYCF", (byte) 6, buffer, size);
return buffer;
}
public IoBuffer buildBaseline8() {
IoBuffer buffer = IoBuffer.allocate(10).order(ByteOrder.LITTLE_ENDIAN);
buffer.setAutoExpand(true);
buffer.putShort((short)0);
int size = buffer.position();
buffer = bufferPool.allocate(size, false).put(buffer.array(), 0, size);
buffer.flip();
buffer = createBaseline("RCNO", (byte) 8, buffer, size);
return buffer;
}
public IoBuffer buildBaseline9() {
IoBuffer buffer = IoBuffer.allocate(10).order(ByteOrder.LITTLE_ENDIAN);
buffer.setAutoExpand(true);
buffer.putShort((short)0);
int size = buffer.position();
buffer = bufferPool.allocate(size, false).put(buffer.array(), 0, size);
buffer.flip();
buffer = createBaseline("TYCF", (byte) 9, buffer, size);
return buffer;
}
public IoBuffer buildDelta3() {
FactoryCrateObject factoryCrateObject = (FactoryCrateObject) object;
IoBuffer buffer = IoBuffer.allocate(10).order(ByteOrder.LITTLE_ENDIAN);
buffer.setAutoExpand(true);
buffer.putInt(factoryCrateObject.getQuantity());
int size = buffer.position();
buffer.flip();
buffer = createDelta("TYCF", (byte) 3, (short) 1, (short) 9, buffer, size + 4);
return buffer;
}
@Override
public void sendListDelta(byte viewType, short updateType, IoBuffer buffer) {
// TODO Auto-generated method stub
}
@Override
public void sendBaselines() {
// TODO Auto-generated method stub
}
}
@@ -21,11 +21,250 @@
******************************************************************************/
package resources.objects.factorycrate;
import java.util.Map;
import java.util.Vector;
import main.NGECore;
import protocol.swg.SceneCreateObjectByCrc;
import protocol.swg.SceneDestroyObject;
import protocol.swg.SceneEndBaselines;
import protocol.swg.UpdateContainmentMessage;
import protocol.swg.UpdatePVPStatusMessage;
import com.sleepycat.persist.model.NotPersistent;
import com.sleepycat.persist.model.Persistent;
import engine.clients.Client;
import engine.resources.common.CRC;
import engine.resources.objects.SWGObject;
import engine.resources.scene.Planet;
import engine.resources.scene.Point3D;
import engine.resources.scene.Quaternion;
import resources.objects.creature.CreatureObject;
import resources.objects.tangible.TangibleObject;
/**
* @author Charon
*/
@Persistent(version=0)
public class FactoryCrateObject extends TangibleObject {
private Vector<TangibleObject> contents;
private byte capacity;
private byte contentObjectQuantity;
private int contentCRC;
private TangibleObject contentObjectType;
@NotPersistent
private FactoryCrateMessageBuilder messageBuilder;
public FactoryCrateObject() {
}
public FactoryCrateObject(long objectID, Planet planet, String template, Point3D position, Quaternion orientation) {
super(objectID, planet, template, position, orientation);
this.messageBuilder = new FactoryCrateMessageBuilder(this);
this.contents = new Vector<TangibleObject>();
this.contentObjectQuantity = 0;
this.capacity = 25;
this.getAttributes().put("@obj_attr_n:condition", "100/100");
this.getAttributes().put("@obj_attr_n:volume", "1");
this.getAttributes().put("@obj_attr_n:quantity", "1");
this.getAttributes().put("@obj_attr_n:factory_count", "1");
this.getAttributes().put("@obj_attr_n:factory_attribs", "------------");
this.getAttributes().put("@obj_attr_n:type", "@got_n:component");
this.getAttributes().put("@obj_attr_n:serial_number", "123");
}
public boolean setContentType(TangibleObject contentObject) {
synchronized(objectMutex) {
this.contentObjectType = contentObject;
if (contentObject.getTemplate().length()>0)
this.contentCRC = CRC.StringtoCRC(contentObject.getTemplate());
else
this.contentCRC = 0;
Map<String,String> contentAttributes = contentObject.getAttributes();
for (Map.Entry<String, String> entry : contentAttributes.entrySet())
{
//if (!entry.getKey().equals(@obj_attr_n:condition))
this.getAttributes().put(entry.getKey(), entry.getValue());
}
return true;
}
}
public TangibleObject getContentType() {
return this.contentObjectType;
}
public boolean setContentTypeAndQuantity(TangibleObject contentObject, int quantity) {
synchronized(objectMutex) {
this.contentObjectType = contentObject;
if (contentObject.getTemplate().length()>0)
this.contentCRC = CRC.StringtoCRC(contentObject.getTemplate());
else{
this.contentCRC = 0;
return false; // Does it make sense to continue anyway?
}
Map<String,String> contentAttributes = contentObject.getAttributes();
for (Map.Entry<String, String> entry : contentAttributes.entrySet())
{
//if (!entry.getKey().equals(@obj_attr_n:condition))
this.getAttributes().put(entry.getKey(), entry.getValue());
System.out.println(entry.getKey() + " " + entry.getValue());
}
if (quantity<capacity) {
contentObject.setSerialNumber(contentObject.getSerialNumber());
for (int i=0;i<quantity;i++){
contents.add(contentObject);
}
contentObjectQuantity = (byte) quantity;
return true;
}
return false;
}
}
public boolean addToCrate(TangibleObject contentObject) {
synchronized(objectMutex) {
if (contentObjectQuantity<capacity) {
if (! contents.isEmpty()) {
TangibleObject serialProvider = contents.firstElement();
contentObject.setSerialNumber(serialProvider.getSerialNumber());
}
contents.add(contentObject);
contentObjectQuantity ++;
return true;
}
return false;
}
}
public String getContentFilename() {
if (!contents.isEmpty()) {
return contents.firstElement().getStfFilename();
} else {
System.err.println("Crate is empty");
}
return null;
}
public void getObjectOutOfCrate(CreatureObject player,NGECore core) {
synchronized(objectMutex) {
if (this.getQuantity()>0){
TangibleObject contentType = this.getContentType();
if (contentType==null)
return; // Bad, crate had no content type set
TangibleObject contentItem = (TangibleObject) core.objectService.createObject(contentType.getTemplate(), player.getPlanet());
contentItem.setOptions(resources.datatables.Options.SERIAL, true);
int crc = this.getContentCRC();//CRC.StringtoCRC("object/tangible/food/crafted/shared_drink_alcohol.iff");
SceneCreateObjectByCrc createObjectMsg = new SceneCreateObjectByCrc(contentItem.getObjectID(), player.getOrientation().x, player.getOrientation().y, player.getOrientation().z, player.getOrientation().w, player.getPosition().x, player.getPosition().y, player.getPosition().z, crc, (byte) 0);
player.getClient().getSession().write(createObjectMsg.serialize());
contentItem.sendBaselines(player.getClient()); // TANO 3,6,8,9 Baselines
SceneEndBaselines sceneEndBaselinesMsg = new SceneEndBaselines(contentItem.getObjectID());
player.getClient().getSession().write(sceneEndBaselinesMsg.serialize());
long parentId = this.getParentId();
SWGObject parentContainer = core.objectService.getObject(parentId);
if (parentContainer==null)
return; // crate has no parent, error
UpdateContainmentMessage updateContainmentMessage= new UpdateContainmentMessage(contentItem.getObjectID(), parentContainer.getObjectID(), -1);
player.getClient().getSession().write(updateContainmentMessage.serialize());
this.sendSetQuantity(player.getClient(),this.getQuantity()-1);
if (this.getQuantity()==0){ // Crate is empty now, delete it
parentContainer._remove(this);
SceneDestroyObject destroyObjectMsg = new SceneDestroyObject(this.getObjectID());
player.getClient().getSession().write(destroyObjectMsg.serialize());
core.objectService.destroyObject(this);
}
} else { // should give players the chance to clean faulty, empty crates from their containers
long parentId = this.getParentId();
SWGObject parentContainer = core.objectService.getObject(parentId);
if (parentContainer==null)
return; // crate has no parent, error
parentContainer._remove(this);
SceneDestroyObject destroyObjectMsg = new SceneDestroyObject(this.getObjectID());
player.getClient().getSession().write(destroyObjectMsg.serialize());
core.objectService.destroyObject(this);
}
}
}
public byte getQuantity() {
return contentObjectQuantity;
}
public String getSerialNumber() {
if (!contents.isEmpty()) {
return contents.firstElement().getSerialNumber();
}
return "";
}
public int getContentCRC() {
return contentCRC;
}
}
public void setContentCRC(int contentCRC) {
synchronized(objectMutex) {
this.contentCRC = contentCRC;
}
}
public void handleSplit(){
}
public void sendAddItem(Client destination) {
destination.getSession().write(messageBuilder.buildDelta3());
this.getAttributes().put("@obj_attr_n:factory_count", ""+this.getQuantity());
this.getAttributes().put("@obj_attr_n:quantity", ""+this.getQuantity());
//services.CharonPacketUtils.printAnalysis(messageBuilder.buildDelta3(),"FCYT3 Delta");
}
public void sendSetQuantity(Client destination,int quantity) {
contentObjectQuantity = (byte) quantity;
destination.getSession().write(messageBuilder.buildDelta3());
this.getAttributes().put("@obj_attr_n:factory_count", ""+quantity);
this.getAttributes().put("@obj_attr_n:quantity", ""+this.getQuantity());
//services.CharonPacketUtils.printAnalysis(messageBuilder.buildDelta3(),"FCYT3 Delta");
}
@Override
public void sendBaselines(Client destination) {
if(destination == null || destination.getSession() == null) {
System.out.println("NULL destination");
return;
}
destination.getSession().write(messageBuilder.buildBaseline3());
destination.getSession().write(messageBuilder.buildBaseline6());
destination.getSession().write(messageBuilder.buildBaseline8());
destination.getSession().write(messageBuilder.buildBaseline9());
// services.CharonPacketUtils.printAnalysis(messageBuilder.buildBaseline3(),"FCYT3 Baseline");
// services.CharonPacketUtils.printAnalysis(messageBuilder.buildBaseline6(),"FCYT6 Baseline");
// services.CharonPacketUtils.printAnalysis(messageBuilder.buildBaseline8(),"FCYT8 Baseline");
// services.CharonPacketUtils.printAnalysis(messageBuilder.buildBaseline9(),"FCYT9 Baseline");
}
public void sendDelta3(Client destination) {
destination.getSession().write(messageBuilder.buildDelta3());
this.getAttributes().put("@obj_attr_n:factory_count", ""+this.getQuantity());
//services.CharonPacketUtils.printAnalysis(messageBuilder.buildDelta3(),"FCYT3 Delta");
}
}
@@ -29,7 +29,6 @@ import org.apache.mina.core.buffer.IoBuffer;
import engine.resources.objects.SWGObject;
import resources.objects.ObjectMessageBuilder;
import resources.objects.building.BuildingObject;
import resources.objects.creature.CreatureObject;
import resources.objects.resource.GalacticResource;
import resources.objects.resource.ResourceContainerObject;
@@ -22,7 +22,6 @@
package resources.objects.installation;
import com.sleepycat.persist.model.Entity;
import com.sleepycat.persist.model.Persistent;
import engine.clients.Client;
import engine.resources.scene.Planet;
@@ -21,11 +21,27 @@
******************************************************************************/
package resources.objects.manufacture;
import com.sleepycat.persist.model.Persistent;
import resources.objects.intangible.IntangibleObject;
import com.sleepycat.persist.model.Persistent;
import engine.resources.scene.Planet;
import engine.resources.scene.Point3D;
import engine.resources.scene.Quaternion;
/**
* @author Charon
*/
@Persistent(version=0)
public class ManufactureSchematicObject extends IntangibleObject {
public class ManufactureSchematicObject extends IntangibleObject{
//@NotPersistent
//private ManufactureSchematicMessageBuilder messageBuilder;
public ManufactureSchematicObject(long objectID, Planet planet, String template, Point3D position, Quaternion orientation) {
super(objectID, planet, position, orientation, template);
//messageBuilder = new ManufactureSchematicMessageBuilder(this);
}
}
@@ -161,6 +161,49 @@ public class TangibleMessageBuilder extends ObjectMessageBuilder {
return buffer;
}
public IoBuffer buildDelta3() {
IoBuffer buffer = bufferPool.allocate(2, false).order(ByteOrder.LITTLE_ENDIAN);
buffer.setAutoExpand(true);
buffer.putShort((short)5);
buffer.putInt(0x12862153);
buffer.putLong(getObject().getObjectID());
buffer.putInt(0x54414E4F);
buffer.put((byte)3);
buffer.putInt(8);//buffer.putInt(8+6);
buffer.putShort((short) 2);
buffer.putShort((short)8);
buffer.put((byte)0);
buffer.putShort((short) 0x21);
buffer.put((byte)0);
// buffer.putShort((short) 0);
// buffer.putFloat(4.0F);
int size = buffer.position();
buffer.flip();
return IoBuffer.allocate(size).put(buffer.array(), 0, size).flip();
}
public IoBuffer buildAssemblyDelta3() {
IoBuffer buffer = bufferPool.allocate(2, false).order(ByteOrder.LITTLE_ENDIAN);
buffer.setAutoExpand(true);
buffer.putShort((short)5);
buffer.putInt(0x12862153);
buffer.putLong(getObject().getObjectID());
buffer.putInt(0x54414E4F);
buffer.put((byte)3);
buffer.putInt(8);//buffer.putInt(8+6);
buffer.putShort((short) 1);
buffer.putShort((short)0x0B);
buffer.putInt(0x000003E8); // ?
int size = buffer.position();
buffer.flip();
return IoBuffer.allocate(size).put(buffer.array(), 0, size).flip();
}
@Override
public void sendListDelta(byte viewType, short updateType, IoBuffer buffer) {
// TODO Auto-generated method stub
@@ -53,7 +53,7 @@ import engine.resources.scene.Planet;
import engine.resources.scene.Point3D;
import engine.resources.scene.Quaternion;
@Persistent(version=6)
@Persistent(version=7)
public class TangibleObject extends SWGObject {
// TODO: Thread safety
@@ -486,13 +486,28 @@ public class TangibleObject extends SWGObject {
}
public String getSerialNumber() {
return serialNumber;
return getStringAttribute("serial_number");
}
public void setSerialNumber(String serialNumber) {
this.serialNumber = serialNumber;
setStringAttribute("serial_number", serialNumber);
}
public void sendDelta3(Client destination) {
destination.getSession().write(messageBuilder.buildDelta3());
//tools.CharonPacketUtils.printAnalysis(messageBuilder.buildDelta3(),"TANO3 Delta");
}
public void sendAssemblyDelta3(Client destination) {
destination.getSession().write(messageBuilder.buildAssemblyDelta3());
//tools.CharonPacketUtils.printAnalysis(messageBuilder.buildAssemblyDelta3(),"TANO3 Assembly Delta");
}
public void sendCustomizationDelta3(Client destination, String enteredName){
destination.getSession().write(messageBuilder.buildCustomNameDelta(enteredName));
//tools.CharonPacketUtils.printAnalysis(messageBuilder.buildCustomNameDelta(enteredName),"TANO3 Customization Delta");
}
@Override
public void sendBaselines(Client destination) {
+36 -92
View File
@@ -31,7 +31,7 @@ import engine.resources.scene.Planet;
import engine.resources.scene.Point3D;
import engine.resources.scene.Quaternion;
@Persistent(version=0)
@Persistent(version=1)
public class WeaponObject extends TangibleObject {
// TODO: Thread safety
@@ -39,53 +39,24 @@ public class WeaponObject extends TangibleObject {
@NotPersistent
private WeaponMessageBuilder messageBuilder;
private float attackSpeed = 1;
private float maxRange;
public WeaponObject(long objectID, Planet planet, String template) {
super(objectID, planet, template, new Point3D(0, 0, 0), new Quaternion(1, 0, 1, 0));
messageBuilder = new WeaponMessageBuilder(this);
if (this.getClass().getSimpleName().equals("WeaponObject")) setIntAttribute("volume", 1);
calculateRange();
calculateAttackSpeed();
setStringAttribute("cat_wpn_damage.damage", "0-0");
}
public WeaponObject(long objectID, Planet planet, String template, Point3D position, Quaternion orientation) {
super(objectID, planet, template, position, orientation);
messageBuilder = new WeaponMessageBuilder(this);
if (this.getClass().getSimpleName().equals("WeaponObject")) setIntAttribute("volume", 1);
calculateRange();
calculateAttackSpeed();
setStringAttribute("cat_wpn_damage.damage", "0-0");
}
public WeaponObject() {
super();
messageBuilder = new WeaponMessageBuilder(this);
//calculateRange();
}
private void calculateRange() {
int weaponType = getWeaponType();
switch(weaponType) {
case 0: maxRange = 64; break;
case 1: maxRange = 50; break;
case 2: maxRange = 35; break;
case 12: maxRange = 64; break;
case 4: maxRange = 5; break;
case 5: maxRange = 5; break;
case 6: maxRange = 5; break;
case 7: maxRange = 5; break;
case 8: maxRange = 64; break;
case 9: maxRange = 5; break;
case 10: maxRange = 5; break;
case 11: maxRange = 5; break;
}
}
public int getIncapTimer() {
@@ -118,7 +89,9 @@ public class WeaponObject extends TangibleObject {
}
public void setMaxDamage(int maxDamage) {
setStringAttribute("cat_wpn_damage.damage", String.valueOf(getMinDamage()) + "-" + String.valueOf(maxDamage));
setIntAttribute("cat_wpn_damage.dps", getDamagePerSecond());
}
public int getMinDamage() {
@@ -126,7 +99,9 @@ public class WeaponObject extends TangibleObject {
}
public void setMinDamage(int minDamage) {
setStringAttribute("cat_wpn_damage.damage", String.valueOf(minDamage) + "-" + String.valueOf(getMaxDamage()));
setIntAttribute("cat_wpn_damage.dps", getDamagePerSecond());
}
public int getElementalDamage() {
@@ -135,14 +110,17 @@ public class WeaponObject extends TangibleObject {
public void setElementalDamage(int elementalDamage) {
setIntAttribute("cat_wpn_damage.wpn_elemental_value", elementalDamage);
setIntAttribute("cat_wpn_damage.dps", getDamagePerSecond());
}
public String getElementalType() {
return getStringAttribute("cat_wpn_damage.wpn_elemental_type");
if (getStringAttribute("cat_wpn_damage.wpn_elemental_type") != null )
return getStringAttribute("cat_wpn_damage.wpn_elemental_type").replace("@obj_attr_n:elemental_", "");
return null;
}
public void setElementalType(String elementalType) {
setStringAttribute("cat_wpn_damage.wpn_elemental_type", elementalType);
setStringAttribute("cat_wpn_damage.wpn_elemental_type", "@obj_attr_n:elemental_" + elementalType);
}
public String getDamageType() {
@@ -150,43 +128,26 @@ public class WeaponObject extends TangibleObject {
}
public void setDamageType(String damageType) {
setStringAttribute("cat_wpn_damage.wpn_damage_type", damageType);
setStringAttribute("cat_wpn_damage.wpn_damage_type", "@obj_attr_n:armor_eff_" + damageType);
}
public int getDamagePerSecond() {
if (getElementalType() != null)
if(getAttributes().containsKey("cat_wpn_damage.damage") && getAttributes().containsKey("cat_wpn_damage.wpn_attack_speed")) {
if (getElementalType() != null )
return (int) (((getMaxDamage() + getElementalDamage() + getMinDamage() + getElementalDamage()) / 2 + getElementalDamage()) * (1 / getAttackSpeed()));
else
return (int) (((getMaxDamage() + getMinDamage()) / 2 ) * (1 / getAttackSpeed()));
else
return (int) (((getMaxDamage() + getMinDamage()) / 2 ) * (1 / getAttackSpeed()));
} else
return 0;
}
public int getWeaponType() {
int weaponType = -1;
String template = getTemplate();
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 = 12;
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;
return Integer.parseInt(getStringAttribute("cat_wpn_damage.wpn_category").replace("@obj_attr_n:wpn_category_", ""));
}
public void setWeaponType(int weaponType) {
setStringAttribute("cat_wpn_damage.wpn_category", "@obj_attr_n:wpn_category_" + weaponType);
}
@Override
@@ -204,11 +165,15 @@ public class WeaponObject extends TangibleObject {
}
public float getAttackSpeed() {
return attackSpeed;
return getFloatAttribute("cat_wpn_damage.wpn_attack_speed");
}
public void setAttackSpeed(float attackSpeed) {
this.attackSpeed = attackSpeed;
if((int) attackSpeed != attackSpeed)
setFloatAttribute("cat_wpn_damage.wpn_attack_speed", attackSpeed);
else
setIntAttribute("cat_wpn_damage.wpn_attack_speed", (int) attackSpeed);
}
public WeaponMessageBuilder getMessageBuilder() {
@@ -216,11 +181,14 @@ public class WeaponObject extends TangibleObject {
}
public float getMaxRange() {
return maxRange;
return Float.parseFloat(getStringAttribute("cat_wpn_damage.wpn_range").replace("0-", "").replace("m", ""));
}
public void setMaxRange(float maxRange) {
this.maxRange = maxRange;
if((int) maxRange != maxRange)
setStringAttribute("cat_wpn_damage.wpn_range", "0-" + String.valueOf(maxRange) + "m");
else
setStringAttribute("cat_wpn_damage.wpn_range", "0-" + String.valueOf((int) maxRange) + "m");
}
public boolean isMelee() {
@@ -244,29 +212,5 @@ public class WeaponObject extends TangibleObject {
return false;
}
private void calculateAttackSpeed() {
int weaponType = getWeaponType();
switch(weaponType) {
case 0: attackSpeed = 0.8f; break;
case 1: attackSpeed = 0.6f; break;
case 2: attackSpeed = 0.4f; break;
case 12: attackSpeed = 1; break;
case 4: attackSpeed = 1; break;
case 5: attackSpeed = 1; break;
case 6: attackSpeed = 1; break;
case 7: attackSpeed = 1; break;
case 8: attackSpeed = 1; break;
case 9: attackSpeed = 1; break;
case 10: attackSpeed = 1; break;
case 11: attackSpeed = 1; break;
}
}
}