Merge branch 'rank-inventory-effects' into 'dev'

Add rank effects to inventory

See merge request morningstar/Arcturus-Community!88
This commit is contained in:
Harmonic 2020-01-30 10:01:39 -05:00
commit 4ef1f4f104
3 changed files with 25 additions and 11 deletions

View File

@ -747,11 +747,6 @@ public class RoomManager {
} }
int effect = habbo.getInventory().getEffectsComponent().activatedEffect; int effect = habbo.getInventory().getEffectsComponent().activatedEffect;
if (effect == 0) {
effect = habbo.getHabboInfo().getRank().getRoomEffect();
}
room.giveEffect(habbo.getRoomUnit(), effect, -1); room.giveEffect(habbo.getRoomUnit(), effect, -1);
} }

View File

@ -4,6 +4,7 @@ import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.modtool.ModToolBan; import com.eu.habbo.habbohotel.modtool.ModToolBan;
import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.permissions.Permission;
import com.eu.habbo.habbohotel.permissions.Rank; import com.eu.habbo.habbohotel.permissions.Rank;
import com.eu.habbo.habbohotel.users.inventory.EffectsComponent;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.catalog.*; import com.eu.habbo.messages.outgoing.catalog.*;
import com.eu.habbo.messages.outgoing.catalog.marketplace.MarketplaceConfigComposer; import com.eu.habbo.messages.outgoing.catalog.marketplace.MarketplaceConfigComposer;
@ -246,7 +247,9 @@ public class HabboManager {
Rank oldRank = habbo.getHabboInfo().getRank(); Rank oldRank = habbo.getHabboInfo().getRank();
if (!oldRank.getBadge().isEmpty()) { if (!oldRank.getBadge().isEmpty()) {
habbo.deleteBadge(habbo.getInventory().getBadgesComponent().getBadge(oldRank.getBadge())); habbo.deleteBadge(habbo.getInventory().getBadgesComponent().getBadge(oldRank.getBadge()));
//BadgesComponent.deleteBadge(userId, oldRank.getBadge()); // unnecessary as Habbo.deleteBadge does this }
if(oldRank.getRoomEffect() > 0) {
habbo.getInventory().getEffectsComponent().effects.remove(oldRank.getRoomEffect());
} }
habbo.getHabboInfo().setRank(newRank); habbo.getHabboInfo().setRank(newRank);
@ -255,6 +258,10 @@ public class HabboManager {
habbo.addBadge(newRank.getBadge()); habbo.addBadge(newRank.getBadge());
} }
if(newRank.getRoomEffect() > 0) {
habbo.getInventory().getEffectsComponent().createRankEffect(habbo.getHabboInfo().getRank().getRoomEffect());
}
habbo.getClient().sendResponse(new UserPermissionsComposer(habbo)); habbo.getClient().sendResponse(new UserPermissionsComposer(habbo));
habbo.getClient().sendResponse(new UserPerksComposer(habbo)); habbo.getClient().sendResponse(new UserPerksComposer(habbo));

View File

@ -31,6 +31,8 @@ public class EffectsComponent {
} catch (SQLException e) { } catch (SQLException e) {
Emulator.getLogging().logSQLException(e); Emulator.getLogging().logSQLException(e);
} }
if(habbo.getHabboInfo().getRank().getRoomEffect() > 0)
this.createRankEffect(habbo.getHabboInfo().getRank().getRoomEffect());
} }
public HabboEffect createEffect(int effectId) { public HabboEffect createEffect(int effectId) {
@ -58,6 +60,17 @@ public class EffectsComponent {
return effect; return effect;
} }
public HabboEffect createRankEffect(int effectId) {
HabboEffect rankEffect = new HabboEffect(effectId, habbo.getHabboInfo().getId());
rankEffect.duration = 0;
rankEffect.isRankEnable = true;
rankEffect.activationTimestamp = Emulator.getIntUnixTimestamp();
rankEffect.enabled = true;
this.effects.put(effectId, rankEffect);
this.activatedEffect = effectId; // enabled by default
return rankEffect;
}
public void addEffect(HabboEffect effect) { public void addEffect(HabboEffect effect) {
this.effects.put(effect.effect, effect); this.effects.put(effect.effect, effect);
@ -67,9 +80,8 @@ public class EffectsComponent {
public void dispose() { public void dispose() {
synchronized (this.effects) { synchronized (this.effects) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users_effects SET duration = ?, activation_timestamp = ?, total = ? WHERE user_id = ? AND effect = ?")) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users_effects SET duration = ?, activation_timestamp = ?, total = ? WHERE user_id = ? AND effect = ?")) {
this.effects.forEachValue(new TObjectProcedure<HabboEffect>() { this.effects.forEachValue(effect -> {
@Override if(!effect.isRankEnable) {
public boolean execute(HabboEffect effect) {
try { try {
statement.setInt(1, effect.duration); statement.setInt(1, effect.duration);
statement.setInt(2, effect.activationTimestamp); statement.setInt(2, effect.activationTimestamp);
@ -80,9 +92,8 @@ public class EffectsComponent {
} catch (SQLException e) { } catch (SQLException e) {
Emulator.getLogging().logSQLException(e); Emulator.getLogging().logSQLException(e);
} }
return true;
} }
return true;
}); });
statement.executeBatch(); statement.executeBatch();
@ -145,6 +156,7 @@ public class EffectsComponent {
public int activationTimestamp = -1; public int activationTimestamp = -1;
public int total = 1; public int total = 1;
public boolean enabled = false; public boolean enabled = false;
public boolean isRankEnable = false;
public HabboEffect(ResultSet set) throws SQLException { public HabboEffect(ResultSet set) throws SQLException {
this.effect = set.getInt("effect"); this.effect = set.getInt("effect");