package com.tronacadmey.phantom.killalot;

import java.util.Arrays;

import com.tronacademy.phantom.messaging.IncomingTransaction;
import com.tronacademy.phantom.messaging.Packet;
import com.tronacademy.phantom.messaging.ProtocolAssembler.DataType;

public class IncomingKillalotCommandTransaction extends IncomingTransaction {
	
	// state trackers
	private final StringBuilder mCmdStr;

	/**
	 * @param packets  Number of packets in the transaction.
	 * @param rows     Number of rows in the bitmap.
	 * @param cols     Number of columns in the bitmap.	
	 * @param encoding How each pixel in encoded.
	 */
	public IncomingKillalotCommandTransaction(int packets, int characters) {
		super(DataType.COMMAND, packets);
		
		mCmdStr = new StringBuilder(characters);
	}
	
	@Override
	public boolean capturePacket(final Packet packet) {
		KillalotPacket kPacket = (KillalotPacket) packet;
		byte[] relevantFragment;
		if (kPacket.getHeader()[2] < KillalotPacket.PAYLOAD_LEN) {
			relevantFragment = Arrays.copyOfRange(kPacket.getPayload(), 0, kPacket.getHeader()[2]);
		} else {
			relevantFragment = kPacket.getPayload();
		}
		
		mCmdStr.append(new String(relevantFragment));
		
		return super.capturePacket(packet);
	}
	
	public String getResult() {
		return mCmdStr.toString();
	}
}

@@ -1217,64 +1217,144 @@
 %0A%09%0A%09
-public String getResult() %7B%0A%09%09return mCmdStr.toString();
+@Override%0A%09public Object getDecodedResult() %7B%0A%09%09if (getPacketsToGo() %3C 1) %7B%0A%09%09%09return mCmdStr.toString();%0A%09%09%7D else %7B%0A%09%09%09return null;%0A%09%09%7D
 %0A%09%7D%0A

Fix for IncomingKillalotCommandTransaction