2018-07-06 15:30:00 +02:00
|
|
|
package com.eu.habbo.habbohotel.catalog;
|
|
|
|
|
2020-10-05 03:13:09 +02:00
|
|
|
import com.eu.habbo.Emulator;
|
|
|
|
import com.eu.habbo.messages.ISerialize;
|
|
|
|
import com.eu.habbo.messages.ServerMessage;
|
|
|
|
|
2018-07-06 15:30:00 +02:00
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
2020-10-05 03:13:09 +02:00
|
|
|
import java.util.Calendar;
|
2020-10-06 01:08:51 +02:00
|
|
|
import java.util.TimeZone;
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2020-10-05 03:13:09 +02:00
|
|
|
public class ClubOffer implements ISerialize {
|
2018-07-08 23:32:00 +02:00
|
|
|
|
2018-07-06 15:30:00 +02:00
|
|
|
private final int id;
|
|
|
|
|
2018-07-08 23:32:00 +02:00
|
|
|
|
2018-07-06 15:30:00 +02:00
|
|
|
private final String name;
|
|
|
|
|
2018-07-08 23:32:00 +02:00
|
|
|
|
2018-07-06 15:30:00 +02:00
|
|
|
private final int days;
|
|
|
|
|
2018-07-08 23:32:00 +02:00
|
|
|
|
2018-07-06 15:30:00 +02:00
|
|
|
private final int credits;
|
|
|
|
|
2018-07-08 23:32:00 +02:00
|
|
|
|
2018-07-06 15:30:00 +02:00
|
|
|
private final int points;
|
|
|
|
|
2018-07-08 23:32:00 +02:00
|
|
|
|
2018-07-06 15:30:00 +02:00
|
|
|
private final int pointsType;
|
|
|
|
|
2018-07-08 23:32:00 +02:00
|
|
|
|
2018-07-06 15:30:00 +02:00
|
|
|
private final boolean vip;
|
|
|
|
|
2018-07-08 23:32:00 +02:00
|
|
|
|
2018-07-06 15:30:00 +02:00
|
|
|
private final boolean deal;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public ClubOffer(ResultSet set) throws SQLException {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.id = set.getInt("id");
|
|
|
|
this.name = set.getString("name");
|
|
|
|
this.days = set.getInt("days");
|
|
|
|
this.credits = set.getInt("credits");
|
|
|
|
this.points = set.getInt("points");
|
|
|
|
this.pointsType = set.getInt("points_type");
|
|
|
|
this.vip = set.getString("type").equalsIgnoreCase("vip");
|
|
|
|
this.deal = set.getString("deal").equals("1");
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public int getId() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.id;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public String getName() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.name;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public int getDays() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.days;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public int getCredits() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.credits;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public int getPoints() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.points;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public int getPointsType() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.pointsType;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean isVip() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.vip;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean isDeal() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.deal;
|
|
|
|
}
|
2020-10-05 03:13:09 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void serialize(ServerMessage message) {
|
|
|
|
serialize(message, Emulator.getIntUnixTimestamp());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void serialize(ServerMessage message, int hcExpireTimestamp) {
|
2020-10-06 00:47:15 +02:00
|
|
|
hcExpireTimestamp = Math.max(Emulator.getIntUnixTimestamp(), hcExpireTimestamp);
|
2020-10-05 03:13:09 +02:00
|
|
|
message.appendInt(this.id);
|
|
|
|
message.appendString(this.name);
|
|
|
|
message.appendBoolean(false); //unused
|
|
|
|
message.appendInt(this.credits);
|
|
|
|
message.appendInt(this.points);
|
|
|
|
message.appendInt(this.pointsType);
|
|
|
|
message.appendBoolean(this.vip);
|
|
|
|
|
2020-10-06 01:08:51 +02:00
|
|
|
long seconds = this.days * 86400;
|
2020-10-05 03:13:09 +02:00
|
|
|
|
|
|
|
long secondsTotal = seconds;
|
|
|
|
|
2020-10-06 01:08:51 +02:00
|
|
|
int totalYears = (int) Math.floor((int) seconds / (86400.0 * 31 * 12));
|
|
|
|
seconds -= totalYears * (86400 * 31 * 12);
|
2020-10-05 03:13:09 +02:00
|
|
|
|
2020-10-06 01:08:51 +02:00
|
|
|
int totalMonths = (int) Math.floor((int) seconds / (86400.0 * 31));
|
|
|
|
seconds -= totalMonths * (86400 * 31);
|
2020-10-05 03:13:09 +02:00
|
|
|
|
2020-10-06 01:08:51 +02:00
|
|
|
int totalDays = (int) Math.floor((int) seconds / 86400.0);
|
2020-10-05 03:13:09 +02:00
|
|
|
seconds -= totalDays * 86400;
|
|
|
|
|
|
|
|
message.appendInt((int) secondsTotal / 86400 / 31);
|
|
|
|
message.appendInt((int) seconds);
|
|
|
|
message.appendBoolean(false); //giftable
|
|
|
|
message.appendInt((int) seconds);
|
|
|
|
|
|
|
|
hcExpireTimestamp += secondsTotal;
|
|
|
|
|
|
|
|
Calendar cal = Calendar.getInstance();
|
2020-10-06 01:08:51 +02:00
|
|
|
cal.setTimeZone(TimeZone.getTimeZone("UTC"));
|
2020-10-05 03:13:09 +02:00
|
|
|
cal.setTimeInMillis(hcExpireTimestamp * 1000L);
|
|
|
|
message.appendInt(cal.get(Calendar.YEAR));
|
2020-10-06 01:08:51 +02:00
|
|
|
message.appendInt(cal.get(Calendar.MONTH) + 1);
|
2020-10-05 03:13:09 +02:00
|
|
|
message.appendInt(cal.get(Calendar.DAY_OF_MONTH));
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|