2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.items.interactions ;
import com.eu.habbo.Emulator ;
import com.eu.habbo.habbohotel.achievements.AchievementManager ;
import com.eu.habbo.habbohotel.gameclients.GameClient ;
import com.eu.habbo.habbohotel.items.Item ;
import com.eu.habbo.habbohotel.rooms.Room ;
2021-01-03 17:33:27 +01:00
import com.eu.habbo.habbohotel.rooms.RoomLayout ;
import com.eu.habbo.habbohotel.rooms.RoomTile ;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.rooms.RoomUnit ;
2021-01-03 17:33:27 +01:00
import com.eu.habbo.habbohotel.users.Habbo ;
import com.eu.habbo.habbohotel.wired.WiredEffectType ;
import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
2018-07-06 15:30:00 +02:00
import java.sql.ResultSet ;
import java.sql.SQLException ;
2021-01-03 17:33:27 +01:00
import java.util.ArrayList ;
import java.util.List ;
public class InteractionFireworks extends InteractionDefault {
private static final Logger LOGGER = LoggerFactory . getLogger ( InteractionFireworks . class ) ;
private static final String STATE_EMPTY = " 0 " ; // Not used since the removal of pixels
private static final String STATE_CHARGED = " 1 " ;
private static final String STATE_EXPLOSION = " 2 " ;
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
public InteractionFireworks ( 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 InteractionFireworks ( 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 boolean canWalkOn ( RoomUnit roomUnit , Room room , Object [ ] objects ) {
2018-07-06 15:30:00 +02:00
return false ;
}
2021-01-03 17:33:27 +01:00
/ * *
* Checked in Habbo on 2021 - 01 - 03
* - Fireworks should be charged to be able to detonate them
* - Habbos with Rights can detonate fireworks from anywhere in a room
2021-01-03 17:38:49 +01:00
* - Habbos without rights have to walk to an adjecent tile to be able to detonate ( see Interaction Switch )
2021-01-03 17:33:27 +01:00
* - Wired can always detonate fireworks
* /
2018-07-06 15:30:00 +02:00
@Override
2021-01-03 17:33:27 +01:00
public void onClick ( GameClient client , Room room , Object [ ] objects ) throws Exception {
if ( room = = null )
return ;
// Wireds can always detonate fireworks if charged
if ( objects . length > = 2 & & objects [ 1 ] instanceof WiredEffectType & & objects [ 1 ] = = WiredEffectType . TOGGLE_STATE ) {
if ( this . getExtradata ( ) . equalsIgnoreCase ( STATE_CHARGED ) ) {
super . onClick ( client , room , objects ) ;
if ( this . getExtradata ( ) . equalsIgnoreCase ( STATE_EXPLOSION ) ) {
this . reCharge ( room ) ;
}
}
return ;
}
if ( client = = null )
return ;
// Habbos without rights have to walk to an adjecent tile to be able to detonate the fireworks
if ( ! this . canToggle ( client . getHabbo ( ) , room ) ) {
RoomTile closestTile = null ;
for ( RoomTile tile : room . getLayout ( ) . getTilesAround ( room . getLayout ( ) . getTile ( this . getX ( ) , this . getY ( ) ) ) ) {
if ( tile . isWalkable ( ) & & ( closestTile = = null | | closestTile . distance ( client . getHabbo ( ) . getRoomUnit ( ) . getCurrentLocation ( ) ) > tile . distance ( client . getHabbo ( ) . getRoomUnit ( ) . getCurrentLocation ( ) ) ) ) {
closestTile = tile ;
}
}
if ( closestTile ! = null & & ! closestTile . equals ( client . getHabbo ( ) . getRoomUnit ( ) . getCurrentLocation ( ) ) ) {
List < Runnable > onSuccess = new ArrayList < > ( ) ;
onSuccess . add ( ( ) - > {
try {
this . onClick ( client , room , objects ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
} ) ;
client . getHabbo ( ) . getRoomUnit ( ) . setGoalLocation ( closestTile ) ;
Emulator . getThreading ( ) . run ( new RoomUnitWalkToLocation ( client . getHabbo ( ) . getRoomUnit ( ) , closestTile , room , onSuccess , new ArrayList < > ( ) ) ) ;
}
}
if ( this . getExtradata ( ) . equalsIgnoreCase ( STATE_CHARGED ) ) {
super . onClick ( client , room , objects ) ;
if ( this . getExtradata ( ) . equalsIgnoreCase ( STATE_EXPLOSION ) )
{
this . reCharge ( room ) ;
AchievementManager . progressAchievement ( client . getHabbo ( ) , Emulator . getGameEnvironment ( ) . getAchievementManager ( ) . getAchievement ( " FireworksCharger " ) ) ;
}
}
2018-07-06 15:30:00 +02:00
}
@Override
2021-01-03 17:33:27 +01:00
public boolean allowWiredResetState ( ) {
return false ;
2018-07-06 15:30:00 +02:00
}
@Override
2021-01-03 17:33:27 +01:00
public void onPlace ( Room room ) {
super . onPlace ( room ) ;
this . setExtradata ( STATE_CHARGED ) ;
2018-07-06 15:30:00 +02:00
}
@Override
2021-01-03 17:33:27 +01:00
public boolean canToggle ( Habbo habbo , Room room ) {
return room . hasRights ( habbo ) | | RoomLayout . tilesAdjecent (
room . getLayout ( ) . getTile ( this . getX ( ) , this . getY ( ) ) ,
habbo . getRoomUnit ( ) . getCurrentLocation ( )
) ;
}
2018-07-06 15:30:00 +02:00
2021-01-03 17:33:27 +01:00
private void reCharge ( Room room ) {
// Default = 5000, Nuclear Firework should have 10000 in its custom params according to Habbo
int explodeDuration = 5000 ;
if ( ! this . getBaseItem ( ) . getCustomParams ( ) . isEmpty ( ) ) {
try {
explodeDuration = Integer . parseInt ( this . getBaseItem ( ) . getCustomParams ( ) ) ;
} catch ( NumberFormatException e ) {
LOGGER . error ( " Incorrect customparams ( " + this . getBaseItem ( ) . getCustomParams ( ) + " ) for base item ID ( " + this . getBaseItem ( ) . getId ( ) + " ) of type ( " + this . getBaseItem ( ) . getName ( ) + " ) " ) ;
}
2018-07-06 15:30:00 +02:00
}
2021-01-03 17:33:27 +01:00
Emulator . getThreading ( ) . run ( ( ) - > {
this . setExtradata ( STATE_CHARGED ) ;
this . needsUpdate ( true ) ;
room . updateItemState ( this ) ;
} , explodeDuration ) ;
2018-07-06 15:30:00 +02:00
}
}