2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.pets ;
import com.eu.habbo.Emulator ;
import com.eu.habbo.habbohotel.achievements.AchievementManager ;
2018-09-12 18:45:00 +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.HabboItem ;
2018-09-12 18:45:00 +02:00
import com.eu.habbo.messages.ISerialize ;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.messages.ServerMessage ;
2018-12-22 11:39:00 +01:00
import com.eu.habbo.messages.outgoing.rooms.pets.PetLevelUpdatedComposer ;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetExperienceComposer ;
import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetRespectComposer ;
2019-05-12 09:59:01 +02:00
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserRemoveComposer ;
2018-09-12 18:45:00 +02:00
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserTalkComposer ;
import com.eu.habbo.plugin.events.pets.PetTalkEvent ;
2018-07-06 15:30:00 +02:00
import gnu.trove.map.hash.THashMap ;
import java.sql.* ;
2018-09-28 21:25:00 +02:00
import java.util.Calendar ;
import java.util.Map ;
import java.util.TimeZone ;
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
public class Pet implements ISerialize , Runnable {
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
public int levelThirst ;
public int levelHunger ;
public boolean needsUpdate = false ;
public boolean packetUpdate = false ;
2018-09-12 18:45:00 +02:00
protected int id ;
protected int userId ;
protected Room room ;
protected String name ;
protected PetData petData ;
protected int race ;
protected String color ;
protected int happyness ;
protected int experience ;
protected int energy ;
protected int respect ;
protected int created ;
protected int level ;
RoomUnit roomUnit ;
2019-05-26 20:14:53 +02:00
private int chatTimeout ;
2018-07-06 15:30:00 +02:00
private int tickTimeout = Emulator . getIntUnixTimestamp ( ) ;
private int happynessDelay = Emulator . getIntUnixTimestamp ( ) ;
private int gestureTickTimeout = Emulator . getIntUnixTimestamp ( ) ;
private int randomActionTickTimeout = Emulator . getIntUnixTimestamp ( ) ;
private int postureTimeout = Emulator . getIntUnixTimestamp ( ) ;
2019-05-26 22:46:02 +02:00
private int stayStartedAt = 0 ;
2018-07-06 15:30:00 +02:00
private int idleCommandTicks = 0 ;
private int freeCommandTicks = - 1 ;
private PetTasks task = PetTasks . FREE ;
private boolean muted = false ;
2019-05-26 20:14:53 +02:00
public Pet ( ResultSet set ) throws SQLException {
2018-07-06 15:30:00 +02:00
super ( ) ;
this . id = set . getInt ( " id " ) ;
this . userId = set . getInt ( " user_id " ) ;
this . room = null ;
this . name = set . getString ( " name " ) ;
this . petData = Emulator . getGameEnvironment ( ) . getPetManager ( ) . getPetData ( set . getInt ( " type " ) ) ;
2019-05-26 20:14:53 +02:00
if ( this . petData = = null ) {
2018-09-28 21:25:00 +02:00
Emulator . getLogging ( ) . logErrorLine ( " WARNING! Missing pet data for type: " + set . getInt ( " type " ) + " ! Insert a new entry into the pet_actions table for this type! " ) ;
this . petData = Emulator . getGameEnvironment ( ) . getPetManager ( ) . getPetData ( 0 ) ;
}
2018-07-06 15:30:00 +02:00
this . race = set . getInt ( " race " ) ;
this . experience = set . getInt ( " experience " ) ;
this . happyness = set . getInt ( " happyness " ) ;
this . energy = set . getInt ( " energy " ) ;
this . respect = set . getInt ( " respect " ) ;
this . created = set . getInt ( " created " ) ;
this . color = set . getString ( " color " ) ;
this . levelThirst = set . getInt ( " thirst " ) ;
this . levelHunger = set . getInt ( " hunger " ) ;
this . level = PetManager . getLevel ( this . experience ) ;
}
2019-05-26 20:14:53 +02:00
public Pet ( int type , int race , String color , String name , int userId ) {
2018-07-06 15:30:00 +02:00
this . id = 0 ;
this . userId = userId ;
this . room = null ;
this . name = name ;
this . petData = Emulator . getGameEnvironment ( ) . getPetManager ( ) . getPetData ( type ) ;
2019-05-26 20:14:53 +02:00
if ( this . petData = = null ) {
2018-09-28 21:25:00 +02:00
Emulator . getLogging ( ) . logErrorLine ( new Exception ( " WARNING! Missing pet data for type: " + type + " ! Insert a new entry into the pet_actions table for this type! " ) ) ;
2018-07-06 15:30:00 +02:00
}
this . race = race ;
this . color = color ;
this . experience = 0 ;
this . happyness = 100 ;
this . energy = 100 ;
this . respect = 0 ;
this . levelThirst = 0 ;
this . levelHunger = 0 ;
this . created = Emulator . getIntUnixTimestamp ( ) ;
this . level = 1 ;
}
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
protected void say ( String message ) {
if ( this . roomUnit ! = null & & this . room ! = null & & ! message . isEmpty ( ) ) {
2018-09-12 18:45:00 +02:00
RoomChatMessage chatMessage = new RoomChatMessage ( message , this . roomUnit , RoomChatMessageBubbles . NORMAL ) ;
PetTalkEvent talkEvent = new PetTalkEvent ( this , chatMessage ) ;
2019-05-26 20:14:53 +02:00
if ( ! Emulator . getPluginManager ( ) . fireEvent ( talkEvent ) . isCancelled ( ) ) {
2018-09-12 18:45:00 +02:00
this . room . petChat ( new RoomUserTalkComposer ( chatMessage ) . compose ( ) ) ;
}
}
}
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
public void say ( PetVocal vocal ) {
if ( vocal ! = null )
2018-09-12 18:45:00 +02:00
this . say ( vocal . message ) ;
}
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
public void addEnergy ( int amount ) {
2018-09-12 18:45:00 +02:00
this . energy + = amount ;
2019-05-26 20:14:53 +02:00
if ( this . energy > PetManager . maxEnergy ( this . level ) )
2018-09-12 18:45:00 +02:00
this . energy = PetManager . maxEnergy ( this . level ) ;
2019-05-26 20:14:53 +02:00
if ( this . energy < 0 )
2018-09-12 18:45:00 +02:00
this . energy = 0 ;
}
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
public void addHappyness ( int amount ) {
2018-09-12 18:45:00 +02:00
this . happyness + = amount ;
2019-05-26 20:14:53 +02:00
if ( this . happyness > 100 )
2018-09-12 18:45:00 +02:00
this . happyness = 100 ;
2019-05-26 20:14:53 +02:00
if ( this . happyness < 0 )
2018-09-12 18:45:00 +02:00
this . happyness = 0 ;
}
2019-05-26 20:14:53 +02:00
public int getRespect ( ) {
2019-03-18 02:22:00 +01:00
return this . respect ;
2018-09-12 18:45:00 +02:00
}
2019-05-26 20:14:53 +02:00
public void addRespect ( ) {
2018-09-12 18:45:00 +02:00
this . respect + + ;
}
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
public int daysAlive ( ) {
2018-09-12 18:45:00 +02:00
return ( Emulator . getIntUnixTimestamp ( ) - this . created ) / 86400 ;
}
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
public String bornDate ( ) {
2018-09-12 18:45:00 +02:00
Calendar cal = Calendar . getInstance ( TimeZone . getDefault ( ) ) ;
cal . setTime ( new java . util . Date ( this . created ) ) ;
return cal . get ( Calendar . DAY_OF_MONTH ) + " / " + cal . get ( Calendar . MONTH ) + " / " + cal . get ( Calendar . YEAR ) ;
}
2018-07-06 15:30:00 +02:00
@Override
2019-05-26 20:14:53 +02:00
public void run ( ) {
if ( this . needsUpdate ) {
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ) {
if ( this . id > 0 ) {
try ( PreparedStatement statement = connection . prepareStatement ( " UPDATE users_pets SET room_id = ?, experience = ?, energy = ?, respect = ?, x = ?, y = ?, z = ?, rot = ?, hunger = ?, thirst = ?, happyness = ?, created = ? WHERE id = ? " ) ) {
2018-07-06 15:30:00 +02:00
statement . setInt ( 1 , ( this . room = = null ? 0 : this . room . getId ( ) ) ) ;
statement . setInt ( 2 , this . experience ) ;
statement . setInt ( 3 , this . energy ) ;
statement . setInt ( 4 , this . respect ) ;
2018-09-12 18:45:00 +02:00
statement . setInt ( 5 , this . roomUnit ! = null ? this . roomUnit . getX ( ) : 0 ) ;
statement . setInt ( 6 , this . roomUnit ! = null ? this . roomUnit . getY ( ) : 0 ) ;
statement . setDouble ( 7 , this . roomUnit ! = null ? this . roomUnit . getZ ( ) : 0 . 0 ) ;
statement . setInt ( 8 , this . roomUnit ! = null ? this . roomUnit . getBodyRotation ( ) . getValue ( ) : 0 ) ;
2018-07-06 15:30:00 +02:00
statement . setInt ( 9 , this . levelHunger ) ;
statement . setInt ( 10 , this . levelThirst ) ;
statement . setInt ( 11 , this . happyness ) ;
2018-09-12 18:45:00 +02:00
statement . setInt ( 12 , this . created ) ;
statement . setInt ( 13 , this . id ) ;
2018-07-06 15:30:00 +02:00
statement . execute ( ) ;
}
2019-05-26 20:14:53 +02:00
} else if ( this . id = = 0 ) {
try ( PreparedStatement statement = connection . prepareStatement ( " INSERT INTO users_pets (user_id, room_id, name, race, type, color, experience, energy, respect, created) VALUES (?, 0, ?, ?, ?, ?, 0, 0, 0, ?) " , Statement . RETURN_GENERATED_KEYS ) ) {
2018-07-06 15:30:00 +02:00
statement . setInt ( 1 , this . userId ) ;
statement . setString ( 2 , this . name ) ;
statement . setInt ( 3 , this . race ) ;
statement . setInt ( 4 , 0 ) ;
2019-05-26 20:14:53 +02:00
if ( this . petData ! = null ) {
2018-07-06 15:30:00 +02:00
statement . setInt ( 4 , this . petData . getType ( ) ) ;
}
statement . setString ( 5 , this . color ) ;
statement . setInt ( 6 , this . created ) ;
statement . execute ( ) ;
2019-05-26 20:14:53 +02:00
try ( ResultSet set = statement . getGeneratedKeys ( ) ) {
if ( set . next ( ) ) {
2018-07-06 15:30:00 +02:00
this . id = set . getInt ( 1 ) ;
}
}
}
}
2019-05-26 20:14:53 +02:00
} catch ( SQLException e ) {
2018-07-06 15:30:00 +02:00
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
this . needsUpdate = false ;
}
}
2019-05-26 20:14:53 +02:00
public void cycle ( ) {
2018-07-06 15:30:00 +02:00
this . idleCommandTicks + + ;
int time = Emulator . getIntUnixTimestamp ( ) ;
2019-05-26 20:14:53 +02:00
if ( this . roomUnit ! = null & & this . task ! = PetTasks . RIDE ) {
if ( time - this . gestureTickTimeout > 5 ) {
2018-09-12 18:45:00 +02:00
this . roomUnit . removeStatus ( RoomUnitStatus . GESTURE ) ;
2018-07-06 15:30:00 +02:00
this . packetUpdate = true ;
}
2019-05-26 20:14:53 +02:00
if ( time - this . postureTimeout > 1 & & this . task = = null ) {
2018-07-06 15:30:00 +02:00
this . clearPosture ( ) ;
2018-12-22 11:39:00 +01:00
this . postureTimeout = time + 120 ;
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
if ( this . freeCommandTicks > 0 ) {
2018-07-06 15:30:00 +02:00
this . freeCommandTicks - - ;
2019-05-26 20:14:53 +02:00
if ( this . freeCommandTicks = = 0 ) {
2019-03-18 02:22:00 +01:00
this . freeCommand ( ) ;
2018-07-06 15:30:00 +02:00
}
}
2019-05-26 20:14:53 +02:00
if ( ! this . roomUnit . isWalking ( ) ) {
2018-09-12 18:45:00 +02:00
this . roomUnit . removeStatus ( RoomUnitStatus . MOVE ) ;
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
if ( this . roomUnit . getWalkTimeOut ( ) < time & & this . canWalk ( ) ) {
2018-09-28 21:25:00 +02:00
RoomTile tile = this . room . getRandomWalkableTile ( ) ;
2019-05-26 20:14:53 +02:00
if ( tile ! = null ) {
2018-09-28 21:25:00 +02:00
this . roomUnit . setGoalLocation ( tile ) ;
}
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
if ( this . task = = PetTasks . NEST | | this . task = = PetTasks . DOWN ) {
2018-07-06 15:30:00 +02:00
if ( this . levelHunger > 0 )
this . levelHunger - - ;
if ( this . levelThirst > 0 )
this . levelThirst - - ;
this . addEnergy ( 5 ) ;
this . addHappyness ( 1 ) ;
2019-05-26 20:14:53 +02:00
if ( this . energy = = PetManager . maxEnergy ( this . level ) ) {
2018-09-12 18:45:00 +02:00
this . roomUnit . removeStatus ( RoomUnitStatus . LAY ) ;
2018-07-06 15:30:00 +02:00
this . roomUnit . setCanWalk ( true ) ;
this . roomUnit . setGoalLocation ( this . room . getRandomWalkableTile ( ) ) ;
this . task = null ;
2018-09-12 18:45:00 +02:00
this . roomUnit . setStatus ( RoomUnitStatus . GESTURE , PetGestures . ENERGY . getKey ( ) ) ;
2018-07-06 15:30:00 +02:00
this . gestureTickTimeout = time ;
}
2019-05-26 20:14:53 +02:00
} else if ( this . tickTimeout > = 5 ) {
if ( this . levelHunger < 100 )
2018-07-06 15:30:00 +02:00
this . levelHunger + + ;
2019-05-26 20:14:53 +02:00
if ( this . levelThirst < 100 )
2018-07-06 15:30:00 +02:00
this . levelThirst + + ;
2019-05-26 20:14:53 +02:00
if ( this . energy < PetManager . maxEnergy ( this . level ) )
2018-07-06 15:30:00 +02:00
this . energy + + ;
this . tickTimeout = time ;
}
2019-05-26 22:46:02 +02:00
if ( this . task = = PetTasks . STAY & & Emulator . getIntUnixTimestamp ( ) - this . stayStartedAt > = 120 ) {
this . task = null ;
this . getRoomUnit ( ) . setCanWalk ( true ) ;
}
2019-05-26 20:14:53 +02:00
} else {
2018-07-06 15:30:00 +02:00
int timeout = Emulator . getRandom ( ) . nextInt ( 10 ) * 2 ;
this . roomUnit . setWalkTimeOut ( timeout < 20 ? 20 + time : timeout + time ) ;
2019-05-26 20:14:53 +02:00
if ( this . energy > = 2 )
2018-07-06 15:30:00 +02:00
this . addEnergy ( - 1 ) ;
2019-05-26 20:14:53 +02:00
if ( this . levelHunger < 100 )
2018-07-06 15:30:00 +02:00
this . levelHunger + + ;
2019-05-26 20:14:53 +02:00
if ( this . levelThirst < 100 )
2018-07-06 15:30:00 +02:00
this . levelThirst + + ;
2019-05-26 20:14:53 +02:00
if ( this . happyness > 0 & & time - this . happynessDelay > = 30 ) {
2018-07-06 15:30:00 +02:00
this . happyness - - ;
this . happynessDelay = time ;
}
}
2019-05-26 20:14:53 +02:00
if ( time - this . gestureTickTimeout > 15 ) {
2019-03-18 02:22:00 +01:00
this . updateGesture ( time ) ;
2019-05-26 20:14:53 +02:00
} else if ( time - this . randomActionTickTimeout > 30 ) {
2018-07-06 15:30:00 +02:00
this . randomAction ( ) ;
this . randomActionTickTimeout = time + ( 10 * Emulator . getRandom ( ) . nextInt ( 60 ) ) ;
}
2019-05-26 20:14:53 +02:00
if ( ! this . muted ) {
if ( this . chatTimeout < = time ) {
if ( this . energy < = 30 ) {
2018-09-12 18:45:00 +02:00
this . say ( this . petData . randomVocal ( PetVocalsType . TIRED ) ) ;
2019-05-26 20:14:53 +02:00
if ( this . energy < = 10 )
2018-07-06 15:30:00 +02:00
this . findNest ( ) ;
2019-05-26 20:14:53 +02:00
} else if ( this . happyness > 85 ) {
2018-09-12 18:45:00 +02:00
this . say ( this . petData . randomVocal ( PetVocalsType . GENERIC_HAPPY ) ) ;
2019-05-26 20:14:53 +02:00
} else if ( this . happyness < 15 ) {
2018-09-12 18:45:00 +02:00
this . say ( this . petData . randomVocal ( PetVocalsType . GENERIC_SAD ) ) ;
2019-05-26 20:14:53 +02:00
} else if ( this . levelHunger > 50 ) {
2018-09-12 18:45:00 +02:00
this . say ( this . petData . randomVocal ( PetVocalsType . HUNGRY ) ) ;
2018-07-06 15:30:00 +02:00
this . eat ( ) ;
2019-05-26 20:14:53 +02:00
} else if ( this . levelThirst > 50 ) {
2018-09-12 18:45:00 +02:00
this . say ( this . petData . randomVocal ( PetVocalsType . THIRSTY ) ) ;
2018-07-06 15:30:00 +02:00
this . drink ( ) ;
}
int timeOut = Emulator . getRandom ( ) . nextInt ( 30 ) ;
2018-09-12 18:45:00 +02:00
this . chatTimeout = time + ( timeOut < 3 ? 30 : timeOut ) ;
2018-07-06 15:30:00 +02:00
}
}
}
}
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
public void handleCommand ( PetCommand command , Habbo habbo , String [ ] data ) {
2018-07-06 15:30:00 +02:00
this . idleCommandTicks = 0 ;
2019-05-26 22:46:02 +02:00
if ( this . task = = PetTasks . STAY ) {
this . stayStartedAt = 0 ;
this . task = null ;
this . getRoomUnit ( ) . setCanWalk ( true ) ;
}
2018-09-12 18:45:00 +02:00
command . handle ( this , habbo , data ) ;
2018-07-06 15:30:00 +02:00
}
2019-05-26 20:14:53 +02:00
public boolean canWalk ( ) {
if ( this . task = = null )
2018-07-06 15:30:00 +02:00
return true ;
2019-05-26 20:14:53 +02:00
switch ( this . task ) {
2018-07-06 15:30:00 +02:00
case DOWN :
case FLAT :
case HERE :
case SIT :
case BEG :
case PLAY :
case PLAY_FOOTBALL :
case PLAY_DEAD :
case FOLLOW :
case JUMP :
case STAND :
case NEST :
case RIDE :
return false ;
}
return true ;
}
2019-05-26 20:14:53 +02:00
public void clearPosture ( ) {
2018-09-28 21:25:00 +02:00
THashMap < RoomUnitStatus , String > keys = new THashMap < > ( ) ;
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
if ( this . roomUnit . hasStatus ( RoomUnitStatus . MOVE ) )
2018-09-12 18:45:00 +02:00
keys . put ( RoomUnitStatus . MOVE , this . roomUnit . getStatus ( RoomUnitStatus . MOVE ) ) ;
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
if ( this . roomUnit . hasStatus ( RoomUnitStatus . SIT ) )
2018-09-12 18:45:00 +02:00
keys . put ( RoomUnitStatus . SIT , this . roomUnit . getStatus ( RoomUnitStatus . SIT ) ) ;
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
if ( this . roomUnit . hasStatus ( RoomUnitStatus . LAY ) )
2018-09-12 18:45:00 +02:00
keys . put ( RoomUnitStatus . LAY , this . roomUnit . getStatus ( RoomUnitStatus . LAY ) ) ;
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
if ( this . roomUnit . hasStatus ( RoomUnitStatus . GESTURE ) )
2018-09-12 18:45:00 +02:00
keys . put ( RoomUnitStatus . GESTURE , this . roomUnit . getStatus ( RoomUnitStatus . GESTURE ) ) ;
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
if ( this . task = = null ) {
2018-12-22 11:39:00 +01:00
boolean isDead = false ;
if ( this . roomUnit . hasStatus ( RoomUnitStatus . RIP ) )
isDead = true ;
2018-09-12 18:45:00 +02:00
this . roomUnit . clearStatus ( ) ;
2018-12-22 11:39:00 +01:00
if ( isDead ) this . roomUnit . setStatus ( RoomUnitStatus . RIP , " " ) ;
2019-05-26 20:14:53 +02:00
for ( Map . Entry < RoomUnitStatus , String > entry : keys . entrySet ( ) ) {
2018-09-12 18:45:00 +02:00
this . roomUnit . setStatus ( entry . getKey ( ) , entry . getValue ( ) ) ;
}
2018-07-06 15:30:00 +02:00
}
this . packetUpdate = true ;
}
2019-05-26 20:14:53 +02:00
public void updateGesture ( int time ) {
2018-07-06 15:30:00 +02:00
this . gestureTickTimeout = time ;
2019-05-26 20:14:53 +02:00
if ( this . energy < 30 ) {
2018-09-12 18:45:00 +02:00
this . roomUnit . setStatus ( RoomUnitStatus . GESTURE , PetGestures . TIRED . getKey ( ) ) ;
2018-07-06 15:30:00 +02:00
this . findNest ( ) ;
2019-05-26 20:14:53 +02:00
} else if ( this . happyness = = 100 ) {
2018-09-12 18:45:00 +02:00
this . roomUnit . setStatus ( RoomUnitStatus . GESTURE , PetGestures . LOVE . getKey ( ) ) ;
2019-05-26 20:14:53 +02:00
} else if ( this . happyness > = 90 ) {
2018-07-06 15:30:00 +02:00
this . randomHappyAction ( ) ;
2018-09-12 18:45:00 +02:00
this . roomUnit . setStatus ( RoomUnitStatus . GESTURE , PetGestures . HAPPY . getKey ( ) ) ;
2019-05-26 20:14:53 +02:00
} else if ( this . happyness < = 5 ) {
2018-07-06 15:30:00 +02:00
this . randomSadAction ( ) ;
2018-09-12 18:45:00 +02:00
this . roomUnit . setStatus ( RoomUnitStatus . GESTURE , PetGestures . SAD . getKey ( ) ) ;
2019-05-26 20:14:53 +02:00
} else if ( this . levelHunger > 80 ) {
2018-09-12 18:45:00 +02:00
this . roomUnit . setStatus ( RoomUnitStatus . GESTURE , PetGestures . HUNGRY . getKey ( ) ) ;
2018-07-06 15:30:00 +02:00
this . eat ( ) ;
2019-05-26 20:14:53 +02:00
} else if ( this . levelThirst > 80 ) {
2018-09-12 18:45:00 +02:00
this . roomUnit . setStatus ( RoomUnitStatus . GESTURE , PetGestures . THIRSTY . getKey ( ) ) ;
2018-07-06 15:30:00 +02:00
this . drink ( ) ;
2019-05-26 20:14:53 +02:00
} else if ( this . idleCommandTicks > 240 ) {
2018-07-06 15:30:00 +02:00
this . idleCommandTicks = 0 ;
2018-09-12 18:45:00 +02:00
this . roomUnit . setStatus ( RoomUnitStatus . GESTURE , PetGestures . QUESTION . getKey ( ) ) ;
2018-07-06 15:30:00 +02:00
}
}
2019-05-26 20:14:53 +02:00
2018-07-06 15:30:00 +02:00
@Override
2019-05-26 20:14:53 +02:00
public void serialize ( ServerMessage message ) {
2018-09-12 18:45:00 +02:00
message . appendInt ( this . id ) ;
message . appendString ( this . name ) ;
2019-05-26 20:14:53 +02:00
if ( this . petData ! = null ) {
2018-09-28 21:25:00 +02:00
message . appendInt ( this . petData . getType ( ) ) ;
2019-05-26 20:14:53 +02:00
} else {
2018-09-28 21:25:00 +02:00
message . appendInt ( - 1 ) ;
}
2018-07-06 15:30:00 +02:00
message . appendInt ( this . race ) ;
message . appendString ( this . color ) ;
message . appendInt ( 0 ) ;
message . appendInt ( 0 ) ;
message . appendInt ( 0 ) ;
}
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
public void findNest ( ) {
2018-07-06 15:30:00 +02:00
HabboItem item = this . petData . randomNest ( this . room . getRoomSpecialTypes ( ) . getNests ( ) ) ;
this . roomUnit . setCanWalk ( true ) ;
2019-05-26 20:14:53 +02:00
if ( item ! = null ) {
2018-07-06 15:30:00 +02:00
this . roomUnit . setGoalLocation ( this . room . getLayout ( ) . getTile ( item . getX ( ) , item . getY ( ) ) ) ;
2019-05-26 20:14:53 +02:00
} else {
2018-09-12 18:45:00 +02:00
this . roomUnit . setStatus ( RoomUnitStatus . LAY , this . room . getStackHeight ( this . roomUnit . getX ( ) , this . roomUnit . getY ( ) , false ) + " " ) ;
this . say ( this . petData . randomVocal ( PetVocalsType . SLEEPING ) ) ;
2018-07-06 15:30:00 +02:00
this . task = PetTasks . DOWN ;
}
}
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
public void drink ( ) {
2018-07-06 15:30:00 +02:00
HabboItem item = this . petData . randomDrinkItem ( this . room . getRoomSpecialTypes ( ) . getPetDrinks ( ) ) ;
2019-05-26 20:14:53 +02:00
if ( item ! = null ) {
2018-07-06 15:30:00 +02:00
this . roomUnit . setCanWalk ( true ) ;
this . roomUnit . setGoalLocation ( this . room . getLayout ( ) . getTile ( item . getX ( ) , item . getY ( ) ) ) ;
}
}
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
public void eat ( ) {
2018-07-06 15:30:00 +02:00
HabboItem item = this . petData . randomFoodItem ( this . room . getRoomSpecialTypes ( ) . getPetFoods ( ) ) ;
{
2019-05-26 20:14:53 +02:00
if ( item ! = null ) {
2018-07-06 15:30:00 +02:00
this . roomUnit . setCanWalk ( true ) ;
this . roomUnit . setGoalLocation ( this . room . getLayout ( ) . getTile ( item . getX ( ) , item . getY ( ) ) ) ;
}
}
}
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
public void findToy ( ) {
2018-07-06 15:30:00 +02:00
HabboItem item = this . petData . randomToyItem ( this . room . getRoomSpecialTypes ( ) . getPetToys ( ) ) ;
{
2019-05-26 20:14:53 +02:00
if ( item ! = null ) {
2018-07-06 15:30:00 +02:00
this . roomUnit . setCanWalk ( true ) ;
this . roomUnit . setGoalLocation ( this . room . getLayout ( ) . getTile ( item . getX ( ) , item . getY ( ) ) ) ;
}
}
}
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
public void randomHappyAction ( ) {
if ( this . petData . actionsHappy . length > 0 ) {
2019-04-22 01:42:00 +02:00
this . roomUnit . setStatus ( RoomUnitStatus . fromString ( this . petData . actionsHappy [ Emulator . getRandom ( ) . nextInt ( this . petData . actionsHappy . length ) ] ) , " " ) ;
}
2018-07-06 15:30:00 +02:00
}
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
public void randomSadAction ( ) {
if ( this . petData . actionsTired . length > 0 ) {
2019-04-22 01:42:00 +02:00
this . roomUnit . setStatus ( RoomUnitStatus . fromString ( this . petData . actionsTired [ Emulator . getRandom ( ) . nextInt ( this . petData . actionsTired . length ) ] ) , " " ) ;
}
2018-07-06 15:30:00 +02:00
}
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
public void randomAction ( ) {
if ( this . petData . actionsRandom . length > 0 ) {
2019-04-22 01:42:00 +02:00
this . roomUnit . setStatus ( RoomUnitStatus . fromString ( this . petData . actionsRandom [ Emulator . getRandom ( ) . nextInt ( this . petData . actionsRandom . length ) ] ) , " " ) ;
}
2018-07-06 15:30:00 +02:00
}
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
public void addExperience ( int amount ) {
2018-07-06 15:30:00 +02:00
this . experience + = amount ;
2019-05-26 20:14:53 +02:00
if ( this . room ! = null ) {
2018-07-06 15:30:00 +02:00
this . room . sendComposer ( new RoomPetExperienceComposer ( this , amount ) . compose ( ) ) ;
2019-05-26 20:14:53 +02:00
if ( this . level < PetManager . experiences . length + 1 & & this . experience > = PetManager . experiences [ this . level - 1 ] ) {
2018-07-06 15:30:00 +02:00
this . levelUp ( ) ;
}
}
}
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
protected void levelUp ( ) {
2018-12-22 11:39:00 +01:00
if ( this . level > = PetManager . experiences . length )
return ;
2019-05-26 20:14:53 +02:00
if ( this . experience < PetManager . experiences [ this . level ] ) {
2018-12-22 11:39:00 +01:00
this . experience = PetManager . experiences [ this . level ] ;
}
2019-04-22 01:42:00 +02:00
this . level + + ;
2018-09-12 18:45:00 +02:00
this . say ( this . petData . randomVocal ( PetVocalsType . LEVEL_UP ) ) ;
2018-07-06 15:30:00 +02:00
this . addHappyness ( 100 ) ;
2019-05-27 00:20:27 +02:00
this . roomUnit . setStatus ( RoomUnitStatus . GESTURE , PetGestures . LVLUP . getKey ( ) ) ;
2018-07-06 15:30:00 +02:00
this . gestureTickTimeout = Emulator . getIntUnixTimestamp ( ) ;
AchievementManager . progressAchievement ( Emulator . getGameEnvironment ( ) . getHabboManager ( ) . getHabbo ( this . userId ) , Emulator . getGameEnvironment ( ) . getAchievementManager ( ) . getAchievement ( " PetLevelUp " ) ) ;
2018-12-22 11:39:00 +01:00
this . room . sendComposer ( new PetLevelUpdatedComposer ( this ) . compose ( ) ) ;
2018-07-06 15:30:00 +02:00
}
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
public void addThirst ( int amount ) {
2018-07-06 15:30:00 +02:00
this . levelThirst + = amount ;
2019-05-26 20:14:53 +02:00
if ( this . levelThirst > 100 )
2018-07-06 15:30:00 +02:00
this . levelThirst = 100 ;
2019-05-26 20:14:53 +02:00
if ( this . levelThirst < 0 )
2018-07-06 15:30:00 +02:00
this . levelThirst = 0 ;
}
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
public void addHunger ( int amount ) {
2018-07-06 15:30:00 +02:00
this . levelHunger + = amount ;
2019-05-26 20:14:53 +02:00
if ( this . levelHunger > 100 )
2018-07-06 15:30:00 +02:00
this . levelHunger = 100 ;
2019-05-26 20:14:53 +02:00
if ( this . levelHunger < 0 )
2018-07-06 15:30:00 +02:00
this . levelHunger = 0 ;
}
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
public void freeCommand ( ) {
2018-07-06 15:30:00 +02:00
this . task = null ;
2018-09-12 18:45:00 +02:00
this . roomUnit . setGoalLocation ( this . getRoomUnit ( ) . getCurrentLocation ( ) ) ;
this . roomUnit . clearStatus ( ) ;
2018-07-06 15:30:00 +02:00
this . roomUnit . setCanWalk ( true ) ;
2018-09-12 18:45:00 +02:00
this . say ( this . petData . randomVocal ( PetVocalsType . GENERIC_NEUTRAL ) ) ;
2018-07-06 15:30:00 +02:00
}
2018-12-22 11:39:00 +01:00
2019-05-26 20:14:53 +02:00
public void scratched ( Habbo habbo ) {
2019-05-27 23:18:24 +02:00
this . addHappyness ( 10 ) ;
2018-07-06 15:30:00 +02:00
this . addRespect ( ) ;
2019-05-26 20:14:53 +02:00
if ( habbo ! = null ) {
2018-07-06 15:30:00 +02:00
habbo . getHabboStats ( ) . petRespectPointsToGive - - ;
habbo . getHabboInfo ( ) . getCurrentRoom ( ) . sendComposer ( new RoomPetRespectComposer ( this ) . compose ( ) ) ;
AchievementManager . progressAchievement ( habbo , Emulator . getGameEnvironment ( ) . getAchievementManager ( ) . getAchievement ( " PetRespectGiver " ) ) ;
}
2018-09-12 18:45:00 +02:00
AchievementManager . progressAchievement ( Emulator . getGameEnvironment ( ) . getHabboManager ( ) . getHabbo ( this . userId ) , Emulator . getGameEnvironment ( ) . getAchievementManager ( ) . getAchievement ( " PetRespectReceiver " ) ) ;
}
2019-05-26 20:14:53 +02:00
public int getId ( ) {
2018-09-12 18:45:00 +02:00
return this . id ;
}
2019-05-26 20:14:53 +02:00
public int getUserId ( ) {
2018-09-12 18:45:00 +02:00
return this . userId ;
}
2019-05-26 20:14:53 +02:00
public void setUserId ( int userId ) {
2018-09-12 18:45:00 +02:00
this . userId = userId ;
}
2019-05-26 20:14:53 +02:00
public Room getRoom ( ) {
2018-09-12 18:45:00 +02:00
return this . room ;
}
2019-05-26 20:14:53 +02:00
public void setRoom ( Room room ) {
2018-09-12 18:45:00 +02:00
this . room = room ;
}
2019-05-26 20:14:53 +02:00
public String getName ( ) {
2018-09-12 18:45:00 +02:00
return this . name ;
}
2019-05-26 20:14:53 +02:00
public void setName ( String name ) {
2018-09-12 18:45:00 +02:00
this . name = name ;
}
2019-05-26 20:14:53 +02:00
public PetData getPetData ( ) {
2018-09-12 18:45:00 +02:00
return this . petData ;
}
2019-05-26 20:14:53 +02:00
public void setPetData ( PetData petData ) {
2018-09-12 18:45:00 +02:00
this . petData = petData ;
}
2019-05-26 20:14:53 +02:00
public int getRace ( ) {
2018-09-12 18:45:00 +02:00
return this . race ;
}
2019-05-26 20:14:53 +02:00
public void setRace ( int race ) {
2018-09-12 18:45:00 +02:00
this . race = race ;
}
2019-05-26 20:14:53 +02:00
public String getColor ( ) {
2018-09-12 18:45:00 +02:00
return this . color ;
}
2019-05-26 20:14:53 +02:00
public void setColor ( String color ) {
2018-09-12 18:45:00 +02:00
this . color = color ;
}
2019-05-26 20:14:53 +02:00
public int getHappyness ( ) {
2019-03-18 02:22:00 +01:00
return this . happyness ;
2018-09-12 18:45:00 +02:00
}
2019-05-26 20:14:53 +02:00
public void setHappyness ( int happyness ) {
2018-09-12 18:45:00 +02:00
this . happyness = happyness ;
}
2019-05-26 20:14:53 +02:00
public int getExperience ( ) {
2019-03-18 02:22:00 +01:00
return this . experience ;
2018-09-12 18:45:00 +02:00
}
2019-05-26 20:14:53 +02:00
public void setExperience ( int experience ) {
2018-09-12 18:45:00 +02:00
this . experience = experience ;
}
2019-05-26 20:14:53 +02:00
public int getEnergy ( ) {
2018-09-12 18:45:00 +02:00
return this . energy ;
}
2019-05-26 20:14:53 +02:00
public void setEnergy ( int energy ) {
this . energy = energy ;
2018-09-12 18:45:00 +02:00
}
2019-05-26 20:14:53 +02:00
public int getMaxEnergy ( ) {
return this . level * 100 ;
2018-09-12 18:45:00 +02:00
}
2019-05-26 20:14:53 +02:00
public int getCreated ( ) {
2018-09-12 18:45:00 +02:00
return this . created ;
}
2019-05-26 20:14:53 +02:00
public void setCreated ( int created ) {
2018-09-12 18:45:00 +02:00
this . created = created ;
}
2019-05-26 20:14:53 +02:00
public int getLevel ( ) {
2018-09-12 18:45:00 +02:00
return this . level ;
}
2019-05-26 20:14:53 +02:00
public void setLevel ( int level ) {
2018-09-12 18:45:00 +02:00
this . level = level ;
}
2019-05-26 20:14:53 +02:00
public RoomUnit getRoomUnit ( ) {
2018-09-12 18:45:00 +02:00
return this . roomUnit ;
}
2019-05-26 20:14:53 +02:00
public void setRoomUnit ( RoomUnit roomUnit ) {
2018-09-12 18:45:00 +02:00
this . roomUnit = roomUnit ;
}
2019-05-26 20:14:53 +02:00
public PetTasks getTask ( ) {
2018-09-12 18:45:00 +02:00
return this . task ;
}
2019-05-26 20:14:53 +02:00
public void setTask ( PetTasks newTask ) {
2018-09-12 18:45:00 +02:00
this . task = newTask ;
}
2019-05-26 20:14:53 +02:00
public boolean isMuted ( ) {
2019-03-18 02:22:00 +01:00
return this . muted ;
2018-09-12 18:45:00 +02:00
}
2019-05-26 20:14:53 +02:00
public void setMuted ( boolean muted ) {
2018-09-12 18:45:00 +02:00
this . muted = muted ;
}
2019-05-26 20:14:53 +02:00
public int getLevelThirst ( ) {
2019-03-18 02:22:00 +01:00
return this . levelThirst ;
2018-09-12 18:45:00 +02:00
}
2019-05-26 20:14:53 +02:00
public void setLevelThirst ( int levelThirst ) {
2018-09-12 18:45:00 +02:00
this . levelThirst = levelThirst ;
}
2019-05-26 20:14:53 +02:00
public int getLevelHunger ( ) {
2019-03-18 02:22:00 +01:00
return this . levelHunger ;
2018-09-12 18:45:00 +02:00
}
2019-05-26 20:14:53 +02:00
public void setLevelHunger ( int levelHunger ) {
2018-09-12 18:45:00 +02:00
this . levelHunger = levelHunger ;
2018-07-06 15:30:00 +02:00
}
2019-05-12 09:59:01 +02:00
public void removeFromRoom ( ) {
removeFromRoom ( false ) ;
}
public void removeFromRoom ( boolean dontSendPackets ) {
2019-05-26 20:14:53 +02:00
if ( this . roomUnit ! = null & & this . roomUnit . getCurrentLocation ( ) ! = null ) {
2019-05-12 09:59:01 +02:00
this . roomUnit . getCurrentLocation ( ) . removeUnit ( this . roomUnit ) ;
}
2019-05-26 20:14:53 +02:00
if ( ! dontSendPackets ) {
2019-05-12 09:59:01 +02:00
room . sendComposer ( new RoomUserRemoveComposer ( this . roomUnit ) . compose ( ) ) ;
room . removePet ( this . id ) ;
}
this . roomUnit = null ;
this . room = null ;
this . needsUpdate = true ;
}
2019-05-26 22:46:02 +02:00
public int getStayStartedAt ( ) {
return stayStartedAt ;
}
public void setStayStartedAt ( int stayStartedAt ) {
this . stayStartedAt = stayStartedAt ;
}
2018-07-06 15:30:00 +02:00
}