package electrosphere.net.client.protocol;

import org.joml.Vector3d;

import electrosphere.client.collision.ClientHitboxCollision;
import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.logger.LoggerInterface;
import electrosphere.net.parser.net.message.CombatMessage;
import electrosphere.net.template.ClientProtocolTemplate;

/**
 * Client protocl for dealing with combat messages
 */
public class CombatProtocol implements ClientProtocolTemplate<CombatMessage> {

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

    @Override
    public void handleSyncMessage(CombatMessage message) {
        switch(message.getMessageSubtype()){
            case SERVERREPORTHITBOXCOLLISION: {
                Vector3d position = new Vector3d(message.getpositionX(),message.getpositionY(),message.getpositionZ());
                Entity senderEntity = Globals.clientSceneWrapper.getEntityFromServerId(message.getentityID());
                Entity receiverEntity = Globals.clientSceneWrapper.getEntityFromServerId(message.getreceiverEntityID());
                if(senderEntity != null && receiverEntity != null){
                    ClientHitboxCollision.handleHitboxCollision(senderEntity, receiverEntity, position, message.gethitboxType(), message.gethurtboxType());
                } else {
                    LoggerInterface.loggerEngine.WARNING("Received collision event for entities that are undefined! " + senderEntity + " " + receiverEntity);
                }
            } break;
        }
    }
    
}
