package net.cobem.grizzly.habbohotel.rooms.items.interactions;

import net.cobem.grizzly.habbohotel.pathfinding.Position;
import net.cobem.grizzly.habbohotel.rooms.actors.Actor;
import net.cobem.grizzly.habbohotel.rooms.items.FloorItem;
import net.cobem.grizzly.habbohotel.rooms.items.WallItem;
import net.cobem.grizzly.habbohotel.sessions.Session;

public class DefaultInteraction implements Interaction {

    @Override
    public void onPlace(Session Session, Object Item) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onRemove(Session Session, Object Item) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onTrigger(Session Session, Object Item, int Request) {
        boolean IsWall = false;

        Actor Actor = Session.getActor();

        try {
            @SuppressWarnings("unused")
            FloorItem RoomItem = (FloorItem) Item;
        } catch (Exception Ex) {
            IsWall = true;
        } //It's probably a wall Item

        if (IsWall) {
            WallItem RoomItem = (WallItem) Item;

            RoomItem.changeState();
            RoomItem.serializeUpdate(Actor.CurrentRoom);
            RoomItem.saveState();
        } else {
            FloorItem RoomItem = (FloorItem) Item;

            Position ItemPosition = new Position(RoomItem.X, RoomItem.Y, RoomItem.Height.intValue());

            if (!Actor.CurrentPosition.TilesTouching(ItemPosition)) {
                Session.getActor().GoalPosition = ItemPosition.GetPositionInFront(Actor.Rotation);
            } else {
                RoomItem.changeState();
                RoomItem.serializeUpdate(Actor.CurrentRoom);
                RoomItem.saveState();
            }
        }
    }

    @Override
    public void onCycle(Object Item) {
        //To change body of implemented methods use File | Settings | File Templates.
    }

}
