2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.items.interactions.wired.conditions ;
import com.eu.habbo.habbohotel.games.GameTeamColors ;
import com.eu.habbo.habbohotel.items.Item ;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition ;
import com.eu.habbo.habbohotel.rooms.Room ;
import com.eu.habbo.habbohotel.rooms.RoomUnit ;
import com.eu.habbo.habbohotel.users.Habbo ;
import com.eu.habbo.habbohotel.wired.WiredConditionType ;
2021-01-04 23:05:45 +01:00
import com.eu.habbo.habbohotel.wired.WiredHandler ;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.messages.ClientMessage ;
import com.eu.habbo.messages.ServerMessage ;
import java.sql.ResultSet ;
import java.sql.SQLException ;
2019-05-26 20:14:53 +02:00
public class WiredConditionNotInTeam extends InteractionWiredCondition {
2018-07-06 15:30:00 +02:00
public static final WiredConditionType type = WiredConditionType . NOT_ACTOR_IN_TEAM ;
private GameTeamColors teamColor = GameTeamColors . RED ;
2019-05-26 20:14:53 +02:00
public WiredConditionNotInTeam ( 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 WiredConditionNotInTeam ( 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 execute ( RoomUnit roomUnit , Room room , Object [ ] stuff ) {
2018-07-06 15:30:00 +02:00
Habbo habbo = room . getHabbo ( roomUnit ) ;
2019-05-26 20:14:53 +02:00
if ( habbo ! = null ) {
2020-10-12 11:18:52 +02:00
return habbo . getHabboInfo ( ) . getGamePlayer ( ) = = null | | ! habbo . getHabboInfo ( ) . getGamePlayer ( ) . getTeamColor ( ) . equals ( this . teamColor ) ; // user is not part of any team
2018-07-06 15:30:00 +02:00
}
2020-10-12 11:18:52 +02:00
return true ;
2018-07-06 15:30:00 +02:00
}
@Override
2019-05-26 20:14:53 +02:00
public String getWiredData ( ) {
2021-01-04 23:05:45 +01:00
return WiredHandler . getGsonBuilder ( ) . create ( ) . toJson ( new JsonData (
this . teamColor
) ) ;
2018-07-06 15:30:00 +02:00
}
@Override
2019-05-26 20:14:53 +02:00
public void loadWiredData ( ResultSet set , Room room ) throws SQLException {
try {
2021-01-04 23:05:45 +01:00
String wiredData = set . getString ( " wired_data " ) ;
if ( wiredData . startsWith ( " { " ) ) {
JsonData data = WiredHandler . getGsonBuilder ( ) . create ( ) . fromJson ( wiredData , JsonData . class ) ;
this . teamColor = data . teamColor ;
} else {
if ( ! wiredData . equals ( " " ) )
this . teamColor = GameTeamColors . values ( ) [ Integer . parseInt ( wiredData ) ] ;
}
2019-05-26 20:14:53 +02:00
} catch ( Exception e ) {
2018-07-06 15:30:00 +02:00
this . teamColor = GameTeamColors . RED ;
}
}
@Override
2019-05-26 20:14:53 +02:00
public void onPickUp ( ) {
2018-07-06 15:30:00 +02:00
this . teamColor = GameTeamColors . RED ;
}
@Override
2019-05-26 20:14:53 +02:00
public WiredConditionType getType ( ) {
2018-07-06 15:30:00 +02:00
return type ;
}
@Override
2019-05-26 20:14:53 +02:00
public void serializeWiredData ( ServerMessage message , Room room ) {
2018-07-06 15:30:00 +02:00
message . appendBoolean ( false ) ;
message . appendInt ( 5 ) ;
message . appendInt ( 0 ) ;
message . appendInt ( this . getBaseItem ( ) . getSpriteId ( ) ) ;
message . appendInt ( this . getId ( ) ) ;
message . appendString ( " " ) ;
message . appendInt ( 1 ) ;
2019-06-10 18:06:22 +02:00
message . appendInt ( this . teamColor . type ) ;
2018-07-06 15:30:00 +02:00
message . appendInt ( 0 ) ;
message . appendInt ( this . getType ( ) . code ) ;
message . appendInt ( 0 ) ;
message . appendInt ( 0 ) ;
}
@Override
2019-05-26 20:14:53 +02:00
public boolean saveData ( ClientMessage packet ) {
2018-07-06 15:30:00 +02:00
packet . readInt ( ) ;
2019-06-16 13:09:19 +02:00
this . teamColor = GameTeamColors . values ( ) [ packet . readInt ( ) ] ;
2018-07-06 15:30:00 +02:00
return true ;
}
2021-01-04 23:05:45 +01:00
static class JsonData {
GameTeamColors teamColor ;
public JsonData ( GameTeamColors teamColor ) {
this . teamColor = teamColor ;
}
}
2018-07-06 15:30:00 +02:00
}