second commit

This commit is contained in:
CharonInferar
2014-04-14 19:58:44 +02:00
parent cbaf74a92e
commit 8077c517ff
5 changed files with 463 additions and 4 deletions
@@ -66,6 +66,14 @@ public class ObjControllerMessage extends SWGMessage {
public static final int STOP_CONVERSATION = 0x00DE;
public static final int CONVERSATION_MESSAGE = 0x00DF;
public static final int CONVERSATION_OPTIONS = 0x00E0;
public static final int DRAFT_SCHEMATICS = 0x0102;
public static final int DRAFT_SLOTS = 0x0103;
public static final int CRAFT_EXPERIMENT = 0x0106;
public static final int CRAFT_ACKNOWLEDGE = 0x010C;
public static final int CRAFT_CUSTOMIZATION = 0x015A;
public static final int NEXT_CRAFTING_STAGE_RESULT = 0x01BE;
public static final int DRAFT_SLOTS_QUERY_RESPONSE = 0x01BF;
public static final int RESOURCE_WEIGHTS = 0x0207;
public ObjControllerMessage() {
@@ -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
}
}
@@ -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");
}
}
@@ -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);
}
}