package electrosphere.net.client.protocol;

import electrosphere.engine.Globals;
import electrosphere.engine.loadingthreads.LoadingThread;
import electrosphere.engine.loadingthreads.LoadingThread.LoadingThreadType;
import electrosphere.net.parser.net.message.CharacterMessage;
import electrosphere.net.parser.net.message.TerrainMessage;
import electrosphere.net.template.ClientProtocolTemplate;

/**
 * The client protocol for handling character messages
 */
public class CharacterProtocol implements ClientProtocolTemplate<CharacterMessage> {

    @Override
    public CharacterMessage handleAsyncMessage(CharacterMessage message) {
        return message;
    }

    @Override
    public void handleSyncMessage(CharacterMessage message) {
        switch(message.getMessageSubtype()){
            case RESPONSECREATECHARACTERSUCCESS:
                //trigger request to spawn character
                Globals.clientConnection.queueOutgoingMessage(CharacterMessage.constructRequestSpawnCharacterMessage());
                Globals.clientConnection.queueOutgoingMessage(TerrainMessage.constructRequestMetadataMessage());
                LoadingThread clientThread = new LoadingThread(LoadingThreadType.CLIENT_WORLD);
                Globals.loadingThreadsList.add(clientThread);
                clientThread.start();
                break;
            case REQUESTCHARACTERLIST:
            case REQUESTCREATECHARACTER:
            case REQUESTSPAWNCHARACTER:
            case RESPONSECHARACTERLIST:
            case RESPONSECREATECHARACTERFAILURE:
            case RESPONSESPAWNCHARACTER:
                //silently ignore
                break;
        }
    }
    
}
