Fix wf_blob

This commit is contained in:
Alejandro 2020-02-05 21:30:11 +02:00
parent 34d8d0f8c5
commit e993a0e95e
3 changed files with 95 additions and 35 deletions

View File

@ -1,4 +1,7 @@
ALTER TABLE `users_pets`
ADD COLUMN `saddle_item_id` int(11) NULL;
INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('hotel.bot.placement.messages', 'Yo!;Hello I\'m a real party animal!;Hello!');
INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('hotel.bot.placement.messages', 'Yo!;Hello I\'m a real party animal!;Hello!');
UPDATE `items_base` SET `customparams` = '1,true' WHERE `item_name` = 'wf_blob';
UPDATE `items_base` SET `customparams` = '5,false' WHERE `item_name` = 'wf_blob2';

View File

@ -132,8 +132,7 @@ public abstract class Game implements Runnable {
}
for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(WiredBlob.class)) {
item.setExtradata("0");
this.room.updateItem(item);
((WiredBlob) item).onGameStart(this.room);
}
}
@ -191,6 +190,10 @@ public abstract class Game implements Runnable {
((InteractionWiredHighscore) item).reloadData();
this.room.updateItem(item);
}
for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(WiredBlob.class)) {
((WiredBlob) item).onGameEnd(this.room);
}
}
public abstract void run();

View File

@ -1,66 +1,120 @@
package com.eu.habbo.habbohotel.items.interactions.wired.extra;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.games.Game;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.games.GamePlayer;
import com.eu.habbo.habbohotel.games.GameTeam;
import com.eu.habbo.habbohotel.games.GameState;
import com.eu.habbo.habbohotel.games.battlebanzai.BattleBanzaiGame;
import com.eu.habbo.habbohotel.games.freeze.FreezeGame;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionDefault;
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.WiredEffectType;
import java.sql.ResultSet;
import java.sql.SQLException;
public class WiredBlob extends InteractionDefault {
enum WiredBlobState {
ACTIVE("0"),
USED("1");
private String state;
WiredBlobState(String state) {
this.state = state;
}
public String getState() {
return state;
}
}
private int POINTS_REWARD = 0;
private boolean RESETS_WITH_GAME = true;
public WiredBlob(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.parseCustomParams();
}
public WiredBlob(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
this.parseCustomParams();
}
@Override
public void onPlace(Room room) {
super.onPlace(room);
this.setExtradata(WiredBlobState.USED.getState());
room.updateItem(this);
}
@Override
public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
super.onWalkOn(roomUnit, room, objects);
if (this.getExtradata().equals("0")) {
Habbo habbo = room.getHabbo(roomUnit);
if (!this.getExtradata().equals(WiredBlobState.ACTIVE.getState())) return;
if (habbo != null && habbo.getHabboInfo().getCurrentGame() != null) {
int points = Emulator.getConfig().getInt("hotel.item.wiredblob." + this.getBaseItem().getName());
Habbo habbo = room.getHabbo(roomUnit);
if (points == 0) {
Emulator.getConfig().register("hotel.item.wiredblob." + this.getBaseItem().getName(), "3000");
points = 1;
if (habbo != null) {
GamePlayer player = habbo.getHabboInfo().getGamePlayer();
if (player != null) {
player.addScore(this.POINTS_REWARD);
BattleBanzaiGame battleBanzaiGame = (BattleBanzaiGame) room.getGame(BattleBanzaiGame.class);
if (battleBanzaiGame != null && battleBanzaiGame.getState() != GameState.IDLE) {
battleBanzaiGame.refreshCounters(habbo.getHabboInfo().getGamePlayer().getTeamColor());
}
boolean triggered = false;
Game game = room.getGame(habbo.getHabboInfo().getCurrentGame());
if (game != null) {
GameTeam team = game.getTeamForHabbo(habbo);
if (team != null) {
team.addTeamScore(points);
triggered = true;
} else {
GamePlayer player = habbo.getHabboInfo().getGamePlayer();
if (player != null) {
player.addScore(points);
triggered = true;
}
}
}
if (triggered) {
this.setExtradata("1");
room.updateItem(this);
}
this.setExtradata(WiredBlobState.USED.getState());
room.updateItem(this);
}
}
}
@Override
public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
if (!this.RESETS_WITH_GAME && objects != null && objects.length == 2 && objects[1].equals(WiredEffectType.TOGGLE_STATE) && room.getGames().stream().anyMatch(game -> game.getState().equals(GameState.RUNNING) || game.getState().equals(GameState.PAUSED))) {
this.setExtradata(this.getExtradata().equals(WiredBlobState.ACTIVE.getState()) ? WiredBlobState.USED.getState() : WiredBlobState.ACTIVE.getState());
room.updateItem(this);
}
}
public void onGameStart(Room room) {
if (this.RESETS_WITH_GAME) {
this.setExtradata(WiredBlobState.ACTIVE.getState());
room.updateItem(this);
}
}
public void onGameEnd(Room room) {
this.setExtradata(WiredBlobState.USED.getState());
room.updateItem(this);
}
private void parseCustomParams() {
String[] params = this.getBaseItem().getCustomParams().split(",");
if (params.length != 2) {
Emulator.getLogging().logErrorLine("Wired blobs should have customparams with two parameters (points,resetsWithGame)");
return;
}
try {
this.POINTS_REWARD = Integer.parseInt(params[0]);
} catch (NumberFormatException e) {
Emulator.getLogging().logErrorLine("Wired blobs should have customparams with the first parameter being the amount of points (number)");
return;
}
this.RESETS_WITH_GAME = params[1].equalsIgnoreCase("true");
}
}