2022-09-08 10:42:57 +02:00
|
|
|
/*
|
|
|
|
This file is a part of the SteamWar software.
|
|
|
|
|
|
|
|
Copyright (C) 2020 SteamWar.de-Serverteam
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package de.steamwar.sql;
|
|
|
|
|
|
|
|
import de.steamwar.sql.internal.Field;
|
|
|
|
import de.steamwar.sql.internal.SelectStatement;
|
|
|
|
import de.steamwar.sql.internal.Statement;
|
|
|
|
import de.steamwar.sql.internal.Table;
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
import lombok.Getter;
|
2022-12-23 23:14:52 +01:00
|
|
|
import lombok.Setter;
|
|
|
|
|
|
|
|
import java.sql.Timestamp;
|
|
|
|
import java.util.List;
|
2022-09-08 10:42:57 +02:00
|
|
|
|
|
|
|
@AllArgsConstructor
|
|
|
|
public class EventFight {
|
|
|
|
|
|
|
|
private static final Table<EventFight> table = new Table<>(EventFight.class);
|
|
|
|
private static final SelectStatement<EventFight> byId = table.select(Table.PRIMARY);
|
|
|
|
private static final Statement setResult = table.update(Table.PRIMARY, "Ergebnis");
|
|
|
|
private static final Statement setFight = table.update(Table.PRIMARY, "Fight");
|
2022-12-23 23:14:52 +01:00
|
|
|
private static final SelectStatement<EventFight> byEvent = table.selectFields("eventID");
|
|
|
|
private static final Statement update = table.update(Table.PRIMARY, "startTime", "spielModus", "map", "teamBlue", "teamRed", "kampfleiter");
|
|
|
|
private static final Statement create = table.insertFields(true, "eventID", "startTime", "spielModus", "map", "teamBlue", "teamRed", "kampfleiter");
|
2022-09-08 10:42:57 +02:00
|
|
|
|
|
|
|
public static EventFight get(int fightID) {
|
|
|
|
return byId.select(fightID);
|
|
|
|
}
|
|
|
|
|
2022-12-23 23:14:52 +01:00
|
|
|
public static EventFight create(int eventID, Timestamp startTime, String spielModus, String map, int teamBlue, int teamRed) {
|
|
|
|
return EventFight.get(create.insertGetKey(eventID, startTime, spielModus, map, teamBlue, teamRed, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static List<EventFight> getFromEvent(int eventID) {
|
|
|
|
return byEvent.listSelect(eventID);
|
|
|
|
}
|
|
|
|
|
2022-09-08 10:42:57 +02:00
|
|
|
@Getter
|
|
|
|
@Field
|
2022-12-23 23:14:52 +01:00
|
|
|
private int eventID;
|
2022-09-08 10:42:57 +02:00
|
|
|
@Getter
|
|
|
|
@Field(keys = {Table.PRIMARY}, autoincrement = true)
|
2022-12-23 23:14:52 +01:00
|
|
|
private int fightID;
|
|
|
|
@Getter
|
|
|
|
@Setter
|
|
|
|
@Field
|
|
|
|
private Timestamp startTime;
|
2022-09-08 10:42:57 +02:00
|
|
|
@Getter
|
2022-12-23 23:14:52 +01:00
|
|
|
@Setter
|
2022-09-08 10:42:57 +02:00
|
|
|
@Field
|
2022-12-23 23:14:52 +01:00
|
|
|
private String spielModus;
|
2022-09-08 10:42:57 +02:00
|
|
|
@Getter
|
2022-12-23 23:14:52 +01:00
|
|
|
@Setter
|
2022-09-08 10:42:57 +02:00
|
|
|
@Field
|
2022-12-23 23:14:52 +01:00
|
|
|
private String map;
|
2022-09-08 10:42:57 +02:00
|
|
|
@Getter
|
2022-12-23 23:14:52 +01:00
|
|
|
@Setter
|
2022-09-08 10:42:57 +02:00
|
|
|
@Field
|
2022-12-23 23:14:52 +01:00
|
|
|
private int teamBlue;
|
|
|
|
@Getter
|
|
|
|
@Setter
|
|
|
|
@Field
|
|
|
|
private int teamRed;
|
|
|
|
@Getter
|
|
|
|
@Setter
|
|
|
|
@Field
|
|
|
|
private int kampfleiter;
|
2022-09-08 10:42:57 +02:00
|
|
|
@Getter
|
|
|
|
@Field(def = "0")
|
|
|
|
private int ergebnis;
|
|
|
|
@Field(nullable = true)
|
|
|
|
private int fight;
|
|
|
|
|
|
|
|
public void setErgebnis(int winner) {
|
|
|
|
this.ergebnis = winner;
|
|
|
|
setResult.update(winner, fightID);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setFight(int fight) {
|
|
|
|
//Fight.FightID, not EventFight.FightID
|
|
|
|
this.fight = fight;
|
|
|
|
setFight.update(fight, fightID);
|
|
|
|
}
|
2022-12-23 23:14:52 +01:00
|
|
|
|
|
|
|
public void update() {
|
|
|
|
update.update(startTime, spielModus, map, teamBlue, teamRed, kampfleiter, fightID);
|
|
|
|
}
|
2022-09-08 10:42:57 +02:00
|
|
|
}
|