Public Repository for the Magicbane Shadowbane Emulator
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

526 lines
17 KiB

// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.net.client.msg;
import engine.gameManager.BuildingManager;
import engine.gameManager.PowersManager;
import engine.mbEnums;
import engine.mbEnums.GameObjectType;
import engine.net.*;
import engine.objects.Building;
import engine.objects.Item;
import engine.objects.MobLoot;
import engine.objects.NPC;
import engine.powers.EffectsBase;
import java.util.HashMap;
public class ItemProductionMsg extends ClientNetMsg {
public int size;
public int buildingUUID;
public int unknown01;
public int templateID;
public int itemType;
public int total_to_produce;
public int unknown03;
public int pToken;
public int sToken;
public String name;
public mbEnums.ProductionActionType actionType;
public int npcUUID;
public boolean add;
public int itemPrice;
public HashMap<Integer, Integer> items;
/**
* This is the general purpose constructor.
*/
public ItemProductionMsg() {
super(Protocol.ITEMPRODUCTION);
this.actionType = mbEnums.ProductionActionType.NONE;
this.size = 0;
this.buildingUUID = 0;
this.unknown01 = 0;
this.templateID = 0;
this.total_to_produce = 0;
this.unknown03 = 0;
this.pToken = 0;
this.sToken = 0;
this.name = "";
this.itemPrice = 0;
this.itemType = 0;
}
;
public ItemProductionMsg(Building building, NPC vendor, Item item, int actionType, boolean add) {
super(Protocol.ITEMPRODUCTION);
this.actionType = mbEnums.ProductionActionType.values()[actionType];
this.size = 0;
this.buildingUUID = building.getObjectUUID();
this.npcUUID = vendor.getObjectUUID();
this.itemType = item.getObjectType().ordinal();
this.templateID = item.getObjectUUID();
this.unknown01 = 0;
this.total_to_produce = 0;
this.unknown03 = 0;
this.pToken = 0;
this.sToken = 0;
this.name = "";
this.add = add;
this.itemPrice = item.getValue();
}
/**
* This constructor is used by NetMsgFactory. It attempts to deserialize the
* ByteBuffer into a message. If a BufferUnderflow occurs (based on reading
* past the limit) then this constructor Throws that Exception to the
* caller.
*/
public ItemProductionMsg(AbstractConnection origin, ByteBufferReader reader) {
super(Protocol.ITEMPRODUCTION, origin, reader);
}
/**
* @see AbstractNetMsg#getPowerOfTwoBufferSize()
*/
@Override
protected int getPowerOfTwoBufferSize() {
//Larger size for historically larger opcodes
return (16); // 2^16 == 64k
}
/**
* Serializes the subclass specific items to the supplied NetMsgWriter.
*/
@Override
protected void _serialize(ByteBufferWriter writer) {
Building building = BuildingManager.getBuildingFromCache(this.buildingUUID);
if (building == null)
return;
// Common Header
writer.putInt(this.actionType.ordinal());
writer.putInt(GameObjectType.Building.ordinal());
writer.putInt(this.buildingUUID);
writer.putInt(GameObjectType.NPC.ordinal());
writer.putInt(this.npcUUID);
switch (this.actionType) {
case CONFIRM_DEPOSIT:
writer.putInt(0); // Not item ordinal?
writer.putInt(0); // Not item uuid?
writer.putInt(1);
writer.putInt(0);
if (!add) {
writer.put((byte) 1);
Item item = Item.getFromCache(this.templateID);
if (item != null)
Item.serializeForClientMsgWithoutSlot(item, writer);
writer.putInt(building.getStrongboxValue());
writer.putInt(0);
writer.putInt(0);
writer.put((byte) 0);
break;
}
writer.putInt(0);
writer.putInt(0);
writer.putInt(0);
writer.put((byte) 1);
Item item;
if (this.itemType == GameObjectType.Item.ordinal())
item = Item.getFromCache(this.templateID);
else
item = MobLoot.getFromCache(this.templateID);
if (item != null)
Item.serializeForClientMsgWithoutSlot(item, writer);
writer.putInt(building.getStrongboxValue());
writer.putInt(0);
writer.putInt(0);
writer.put((byte) 0);
break;
case CONFIRM_TAKE:
writer.putInt(this.itemType);
writer.putInt(this.templateID);
writer.putInt(1);
writer.putInt(0);
writer.putInt(0);
writer.putInt(0);
writer.putInt(0);
writer.putInt(0);
writer.putInt(0);
writer.put((byte) 0);
break;
case SETPRICE:
writer.putInt(this.itemType);
writer.putInt(this.templateID);
writer.putInt(1);
writer.putInt(0);
writer.putInt(0);
writer.putInt(0);
writer.putInt(0);
writer.putInt(this.itemPrice); // new price
writer.putInt(0);
writer.putInt(0);
writer.put((byte) 0);
break;
case CONFIRM_SETPRICE:
writer.putInt(this.itemType);
writer.putInt(this.templateID);
writer.putInt(1);
writer.putInt(0);
writer.putInt(0);
writer.putInt(0);
writer.putInt(0);
writer.put((byte) 1);
writer.putInt(building.getStrongboxValue()); // new price
writer.putInt(0);
writer.putInt(0);
//writer.put((byte) 0);
break;
case DEPOSIT:
writer.putInt(this.itemType);
writer.putInt(this.templateID);
writer.putInt(1);
writer.putInt(0);
writer.putInt(0);
writer.putInt(0);
writer.putInt(0);
writer.putInt(0);
writer.putInt(0);
writer.put((byte) 0);
break;
case TAKE:
case RECYCLE:
writer.putInt(0);
writer.putInt(0);
writer.putInt(1);
writer.putInt(0);
writer.putInt(0);
writer.putInt(0);
writer.putInt(0);
writer.put((byte) 1);
writer.putInt(building.getStrongboxValue());
if (this.items != null) {
writer.putInt(this.items.size());
for (int itemID : this.items.keySet()) {
writer.putInt(this.items.get(itemID));
writer.putInt(itemID);
}
} else
writer.putInt(0);
writer.putInt(0);
break;
case CONFIRM_PRODUCE:
writer.putInt(0);
writer.putInt(0);
writer.putInt(1);
MobLoot toRoll = MobLoot.getFromCache(this.templateID);
writer.putInt(-1497023830);
if (toRoll != null && toRoll.getPrefix() != null && !toRoll.getPrefix().isEmpty()) {
EffectsBase eb = PowersManager.getEffectByIDString(toRoll.getPrefix());
if (eb == null)
this.pToken = 0;
else
this.pToken = eb.getToken();
}
if (toRoll != null && toRoll.getSuffix() != null && !toRoll.getSuffix().isEmpty()) {
EffectsBase eb = PowersManager.getEffectByIDString(toRoll.getSuffix());
if (eb == null)
this.sToken = 0;
else
this.sToken = eb.getToken();
}
if (toRoll.isRandom() == false || (toRoll != null && toRoll.isComplete())) {
writer.putInt(this.pToken);
writer.putInt(this.sToken);
} else {
writer.putInt(0);
writer.putInt(0);
}
writer.putString(toRoll.name);
writer.putInt(GameObjectType.MobLoot.ordinal());
writer.putInt(this.templateID);
writer.putInt(0); //items left to produce?
if (toRoll != null) {
writer.putInt(toRoll.templateID);
writer.putInt(toRoll.getValue());
} else {
writer.putInt(0);
writer.putInt(0);
}
NPC vendor = NPC.getFromCache(this.npcUUID);
if (vendor != null) {
if (toRoll.isComplete()) {
writer.putInt(0);
writer.putInt(0);
} else {
long timeLeft = toRoll.getDateToUpgrade() - System.currentTimeMillis();
timeLeft /= 1000;
writer.putInt((int) timeLeft);
writer.putInt(vendor.getRollingTimeInSeconds(toRoll.templateID));
}
} else {
writer.putInt(0);
writer.putInt(0);
}
if (toRoll.isComplete())
writer.putInt(0);
else
writer.putInt(1);
writer.put((byte) 0);
if (toRoll != null && toRoll.isComplete())
writer.put((byte) 1);
else
writer.put((byte) 0);
writer.put((byte) 0);
writer.put((byte) 1);
writer.putInt(vendor.getBuilding().getStrongboxValue());
writer.putInt(0);
writer.putInt(0);
//writer.putInt(0); //error popup
break;
case COMPLETE:
writer.putInt(this.itemType);
writer.putInt(this.templateID);
writer.putInt(this.total_to_produce);
writer.putInt(this.unknown03);
writer.putInt(this.pToken);
writer.putInt(this.sToken);
writer.putInt(0);
writer.putInt(0);
writer.putInt(0);
writer.put((byte) 0);
break;
case JUNK:
writer.putInt(this.itemType);
writer.putInt(this.templateID);
writer.putInt(this.total_to_produce);
writer.putInt(this.unknown03);
writer.putInt(this.pToken);
writer.putInt(this.sToken);
writer.putString(this.name);
writer.putInt(0);
writer.putInt(0);
writer.putShort((short) 0);
writer.put((byte) 0);
break;
default:
writer.putInt(0);
writer.putInt(1);
writer.putInt(0);
writer.putInt(0);
break;
}
}
/**
* Deserializes the subclass specific items from the supplied NetMsgReader.
*/
@Override
protected void _deserialize(ByteBufferReader reader) {
// Common header
this.actionType = mbEnums.ProductionActionType.values()[reader.getInt()];
reader.getInt(); // Building type padding
this.buildingUUID = reader.getInt();
reader.getInt(); // NPC type padding
this.npcUUID = reader.getInt();
switch (this.actionType) {
case SETPRICE:
this.itemType = reader.getInt();
this.templateID = reader.getInt();
reader.getInt();
reader.getInt();
reader.getInt();
reader.getInt();
reader.getInt();
this.itemPrice = reader.getInt();
reader.getInt();
reader.getInt();
reader.get();
break;
case RECYCLE:
case TAKE:
reader.getInt();
reader.getInt();
reader.getInt();
reader.getInt();
reader.getInt();
reader.getInt();
reader.getInt();
reader.get();
this.size = reader.getInt();
HashMap<Integer, Integer> tempIDs = new HashMap<>();
for (int i = 0; i < this.size; i++) {
int type = reader.getInt(); // Item type padding
this.templateID = reader.getInt();
tempIDs.put(this.templateID, type);
}
reader.getInt();
this.items = tempIDs;
break;
case DEPOSIT:
this.itemType = reader.getInt();
this.templateID = reader.getInt();
reader.getInt();
reader.getInt();
reader.getInt();
reader.getInt();
reader.getInt();
reader.getInt();
reader.getInt();
reader.get();
break;
case JUNK:
this.itemType = reader.getInt();
this.templateID = reader.getInt();
this.total_to_produce = reader.getInt();
this.unknown03 = reader.getInt();
this.pToken = reader.getInt();
this.sToken = reader.getInt();
this.name = reader.getString();
reader.getInt();
reader.getInt();
reader.get();
break;
default:
this.itemType = reader.getInt();
this.templateID = reader.getInt();
this.total_to_produce = reader.getInt();
this.unknown03 = reader.getInt();
this.pToken = reader.getInt();
this.sToken = reader.getInt();
this.name = reader.getString();
this.size = reader.getInt();
reader.getInt();
if (this.actionType == mbEnums.ProductionActionType.COMPLETE || this.actionType == mbEnums.ProductionActionType.JUNK)
reader.get();
else
reader.getShort();
break;
}
}
public int getItemType() {
return itemType;
}
public int getUnknown01() {
return unknown01;
}
public void setUnknown01(int unknown01) {
this.unknown01 = unknown01;
}
public int getTotal_to_produce() {
return total_to_produce;
}
public void setTotal_to_produce(int unknown02) {
this.total_to_produce = unknown02;
}
public int getUnknown03() {
return unknown03;
}
public void setUnknown03(int unknown03) {
this.unknown03 = unknown03;
}
public int getTemplateID() {
return templateID;
}
public void setTemplateID(int templateID) {
this.templateID = templateID;
}
public int getpToken() {
return pToken;
}
public void setpToken(int pToken) {
this.pToken = pToken;
}
public int getsToken() {
return sToken;
}
public void setsToken(int sToken) {
this.sToken = sToken;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public final void setActionType(int actionType) {
this.actionType = mbEnums.ProductionActionType.values()[actionType];
}
public int getNpcUUID() {
return npcUUID;
}
public HashMap<Integer, Integer> getItems() {
return items;
}
/**
* @return the itemPrice
*/
public int getItemPrice() {
return itemPrice;
}
}