2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.items.interactions ;
import com.eu.habbo.Emulator ;
2018-12-22 11:39:00 +01:00
import com.eu.habbo.habbohotel.bots.Bot ;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.gameclients.GameClient ;
import com.eu.habbo.habbohotel.items.Item ;
2019-08-05 19:14:33 +02:00
import com.eu.habbo.habbohotel.rooms.* ;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.users.Habbo ;
import com.eu.habbo.habbohotel.users.HabboGender ;
import com.eu.habbo.habbohotel.users.HabboItem ;
import com.eu.habbo.habbohotel.wired.WiredEffectType ;
import com.eu.habbo.messages.ServerMessage ;
import java.sql.ResultSet ;
import java.sql.SQLException ;
2019-05-26 20:14:53 +02:00
public class InteractionDefault extends HabboItem {
public InteractionDefault ( ResultSet set , Item baseItem ) throws SQLException {
2018-07-06 15:30:00 +02:00
super ( set , baseItem ) ;
}
2019-05-26 20:14:53 +02:00
public InteractionDefault ( int id , int userId , Item item , String extradata , int limitedStack , int limitedSells ) {
2018-07-06 15:30:00 +02:00
super ( id , userId , item , extradata , limitedStack , limitedSells ) ;
}
@Override
2019-05-26 20:14:53 +02:00
public void serializeExtradata ( ServerMessage serverMessage ) {
2018-07-06 15:30:00 +02:00
serverMessage . appendInt ( ( this . isLimited ( ) ? 256 : 0 ) ) ;
serverMessage . appendString ( this . getExtradata ( ) ) ;
super . serializeExtradata ( serverMessage ) ;
}
@Override
2019-05-26 20:14:53 +02:00
public boolean isWalkable ( ) {
2018-07-06 15:30:00 +02:00
return this . getBaseItem ( ) . allowWalk ( ) ;
}
@Override
2019-05-26 20:14:53 +02:00
public boolean canWalkOn ( RoomUnit roomUnit , Room room , Object [ ] objects ) {
2018-07-06 15:30:00 +02:00
return true ;
}
2019-05-18 17:32:13 +02:00
@Override
2019-05-26 20:14:53 +02:00
public void onMove ( Room room , RoomTile oldLocation , RoomTile newLocation ) {
2019-05-18 17:32:13 +02:00
super . onMove ( room , oldLocation , newLocation ) ;
for ( RoomUnit unit : room . getRoomUnits ( ) ) {
2019-05-26 20:14:53 +02:00
if ( ! oldLocation . unitIsOnFurniOnTile ( unit , this . getBaseItem ( ) ) )
continue ; // If the unit was previously on the furni...
2019-05-18 17:32:13 +02:00
if ( newLocation . unitIsOnFurniOnTile ( unit , this . getBaseItem ( ) ) ) continue ; // but is not anymore...
try {
this . onWalkOff ( unit , room , new Object [ ] { } ) ; // the unit walked off!
} catch ( Exception ignored ) {
}
}
}
2018-07-06 15:30:00 +02:00
@Override
2019-05-26 20:14:53 +02:00
public void onClick ( GameClient client , Room room , Object [ ] objects ) throws Exception {
if ( room ! = null & & ( client = = null | | this . canToggle ( client . getHabbo ( ) , room ) | | ( objects . length > = 2 & & objects [ 1 ] instanceof WiredEffectType & & objects [ 1 ] = = WiredEffectType . TOGGLE_STATE ) ) ) {
2018-07-06 15:30:00 +02:00
super . onClick ( client , room , objects ) ;
2019-05-26 20:14:53 +02:00
if ( objects ! = null & & objects . length > 0 ) {
if ( objects [ 0 ] instanceof Integer ) {
2018-07-06 15:30:00 +02:00
if ( this . getExtradata ( ) . length ( ) = = 0 )
this . setExtradata ( " 0 " ) ;
2019-05-26 20:14:53 +02:00
if ( this . getBaseItem ( ) . getStateCount ( ) > 0 ) {
2018-07-06 15:30:00 +02:00
int currentState = 0 ;
2019-05-26 20:14:53 +02:00
try {
2018-07-06 15:30:00 +02:00
currentState = Integer . valueOf ( this . getExtradata ( ) ) ;
2019-05-26 20:14:53 +02:00
} catch ( NumberFormatException e ) {
2018-07-06 15:30:00 +02:00
Emulator . getLogging ( ) . logErrorLine ( " Incorrect extradata ( " + this . getExtradata ( ) + " ) for item ID ( " + this . getId ( ) + " ) of type ( " + this . getBaseItem ( ) . getName ( ) + " ) " ) ;
}
this . setExtradata ( " " + ( currentState + 1 ) % this . getBaseItem ( ) . getStateCount ( ) ) ;
this . needsUpdate ( true ) ;
room . updateItemState ( this ) ;
}
}
}
}
}
@Override
2019-05-26 20:14:53 +02:00
public void onWalk ( RoomUnit roomUnit , Room room , Object [ ] objects ) throws Exception {
2018-07-06 15:30:00 +02:00
}
@Override
2019-05-26 20:14:53 +02:00
public void onWalkOn ( RoomUnit roomUnit , Room room , Object [ ] objects ) throws Exception {
2018-07-06 15:30:00 +02:00
super . onWalkOn ( roomUnit , room , objects ) ;
2019-05-26 20:14:53 +02:00
if ( roomUnit ! = null ) {
if ( this . getBaseItem ( ) . getEffectF ( ) > 0 | | this . getBaseItem ( ) . getEffectM ( ) > 0 ) {
if ( roomUnit . getRoomUnitType ( ) . equals ( RoomUnitType . USER ) ) {
2018-07-06 15:30:00 +02:00
Habbo habbo = room . getHabbo ( roomUnit ) ;
2019-05-26 20:14:53 +02:00
if ( habbo ! = null ) {
if ( habbo . getHabboInfo ( ) . getGender ( ) . equals ( HabboGender . M ) & & this . getBaseItem ( ) . getEffectM ( ) > 0 & & habbo . getRoomUnit ( ) . getEffectId ( ) ! = this . getBaseItem ( ) . getEffectM ( ) ) {
2019-03-18 02:22:00 +01:00
room . giveEffect ( habbo , this . getBaseItem ( ) . getEffectM ( ) , - 1 ) ;
2018-07-06 15:30:00 +02:00
return ;
}
2019-05-26 20:14:53 +02:00
if ( habbo . getHabboInfo ( ) . getGender ( ) . equals ( HabboGender . F ) & & this . getBaseItem ( ) . getEffectF ( ) > 0 & & habbo . getRoomUnit ( ) . getEffectId ( ) ! = this . getBaseItem ( ) . getEffectF ( ) ) {
2019-03-18 02:22:00 +01:00
room . giveEffect ( habbo , this . getBaseItem ( ) . getEffectF ( ) , - 1 ) ;
2018-07-06 15:30:00 +02:00
}
}
2019-05-26 20:14:53 +02:00
} else if ( roomUnit . getRoomUnitType ( ) . equals ( RoomUnitType . BOT ) ) {
2018-12-22 11:39:00 +01:00
Bot bot = room . getBot ( roomUnit ) ;
2019-05-26 20:14:53 +02:00
if ( bot ! = null ) {
if ( bot . getGender ( ) . equals ( HabboGender . M ) & & this . getBaseItem ( ) . getEffectM ( ) > 0 & & roomUnit . getEffectId ( ) ! = this . getBaseItem ( ) . getEffectM ( ) ) {
2019-03-18 02:22:00 +01:00
room . giveEffect ( bot . getRoomUnit ( ) , this . getBaseItem ( ) . getEffectM ( ) , - 1 ) ;
2018-12-22 11:39:00 +01:00
return ;
}
2019-05-26 20:14:53 +02:00
if ( bot . getGender ( ) . equals ( HabboGender . F ) & & this . getBaseItem ( ) . getEffectF ( ) > 0 & & roomUnit . getEffectId ( ) ! = this . getBaseItem ( ) . getEffectF ( ) ) {
2019-03-18 02:22:00 +01:00
room . giveEffect ( bot . getRoomUnit ( ) , this . getBaseItem ( ) . getEffectF ( ) , - 1 ) ;
2018-12-22 11:39:00 +01:00
}
}
}
2018-07-06 15:30:00 +02:00
}
}
}
@Override
2019-05-26 20:14:53 +02:00
public void onWalkOff ( RoomUnit roomUnit , Room room , Object [ ] objects ) throws Exception {
2018-07-06 15:30:00 +02:00
super . onWalkOff ( roomUnit , room , objects ) ;
2019-05-26 20:14:53 +02:00
if ( roomUnit ! = null ) {
if ( this . getBaseItem ( ) . getEffectF ( ) > 0 | | this . getBaseItem ( ) . getEffectM ( ) > 0 ) {
if ( objects ! = null & & objects . length = = 2 ) {
if ( objects [ 0 ] instanceof RoomTile & & objects [ 1 ] instanceof RoomTile ) {
2018-12-22 11:39:00 +01:00
RoomTile goalTile = ( RoomTile ) objects [ 1 ] ;
HabboItem topItem = room . getTopItemAt ( goalTile . x , goalTile . y ) ;
2019-05-26 20:14:53 +02:00
if ( topItem ! = null & & ( topItem . getBaseItem ( ) . getEffectM ( ) = = this . getBaseItem ( ) . getEffectM ( ) | | topItem . getBaseItem ( ) . getEffectF ( ) = = this . getBaseItem ( ) . getEffectF ( ) ) ) {
2018-12-22 11:39:00 +01:00
return ;
}
}
}
2019-05-26 20:14:53 +02:00
if ( roomUnit . getRoomUnitType ( ) . equals ( RoomUnitType . USER ) ) {
2018-07-06 15:30:00 +02:00
Habbo habbo = room . getHabbo ( roomUnit ) ;
2019-05-26 20:14:53 +02:00
if ( habbo ! = null ) {
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
if ( habbo . getHabboInfo ( ) . getGender ( ) . equals ( HabboGender . M ) & & this . getBaseItem ( ) . getEffectM ( ) > 0 ) {
2019-03-18 02:22:00 +01:00
room . giveEffect ( habbo , 0 , - 1 ) ;
2018-07-06 15:30:00 +02:00
return ;
}
2019-05-26 20:14:53 +02:00
if ( habbo . getHabboInfo ( ) . getGender ( ) . equals ( HabboGender . F ) & & this . getBaseItem ( ) . getEffectF ( ) > 0 ) {
2019-03-18 02:22:00 +01:00
room . giveEffect ( habbo , 0 , - 1 ) ;
2018-07-06 15:30:00 +02:00
}
}
2019-05-26 20:14:53 +02:00
} else if ( roomUnit . getRoomUnitType ( ) . equals ( RoomUnitType . BOT ) ) {
2018-12-22 11:39:00 +01:00
Bot bot = room . getBot ( roomUnit ) ;
2019-05-26 20:14:53 +02:00
if ( bot ! = null ) {
if ( bot . getGender ( ) . equals ( HabboGender . M ) & & this . getBaseItem ( ) . getEffectM ( ) > 0 ) {
2019-03-18 02:22:00 +01:00
room . giveEffect ( roomUnit , 0 , - 1 ) ;
2018-12-22 11:39:00 +01:00
return ;
}
2019-05-26 20:14:53 +02:00
if ( bot . getGender ( ) . equals ( HabboGender . F ) & & this . getBaseItem ( ) . getEffectF ( ) > 0 ) {
2019-03-18 02:22:00 +01:00
room . giveEffect ( roomUnit , 0 , - 1 ) ;
2018-12-22 11:39:00 +01:00
}
}
}
2018-07-06 15:30:00 +02:00
}
}
}
2019-05-26 20:14:53 +02:00
public boolean canToggle ( Habbo habbo , Room room ) {
2019-08-05 19:14:33 +02:00
if ( room . hasRights ( habbo ) ) return true ;
if ( ! habbo . getHabboStats ( ) . isRentingSpace ( ) ) return false ;
HabboItem rentSpace = room . getHabboItem ( habbo . getHabboStats ( ) . rentedItemId ) ;
return rentSpace ! = null & & RoomLayout . squareInSquare ( RoomLayout . getRectangle ( rentSpace . getX ( ) , rentSpace . getY ( ) , rentSpace . getBaseItem ( ) . getWidth ( ) , rentSpace . getBaseItem ( ) . getLength ( ) , rentSpace . getRotation ( ) ) , RoomLayout . getRectangle ( this . getX ( ) , this . getY ( ) , this . getBaseItem ( ) . getWidth ( ) , this . getBaseItem ( ) . getLength ( ) , this . getRotation ( ) ) ) ;
2018-07-06 15:30:00 +02:00
}
@Override
2019-05-26 20:14:53 +02:00
public boolean allowWiredResetState ( ) {
2018-07-06 15:30:00 +02:00
return true ;
}
}