151 lines
4.5 KiB
Kotlin
151 lines
4.5 KiB
Kotlin
package com.dowstats.data.entities
|
|
|
|
import com.dowstats.data.dto.controllers.UnitFullDto
|
|
import com.dowstats.data.dto.controllers.UnitShortDto
|
|
import com.dowstats.data.entities.research.Research
|
|
import jakarta.persistence.*
|
|
|
|
|
|
@Entity
|
|
@Table(name = "units")
|
|
class DowUnit {
|
|
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
var id: Long? = null
|
|
|
|
@ManyToOne
|
|
@JoinColumn(name = "race_id", nullable = false)
|
|
var race: Race? = null
|
|
|
|
@ManyToOne(fetch = FetchType.LAZY)
|
|
@JoinColumn(name = "armour_type_id", nullable = false)
|
|
var armorType: ArmorType? = null
|
|
|
|
@ManyToOne(fetch = FetchType.LAZY)
|
|
@JoinColumn(name = "armour_type_2_id")
|
|
var armorType2: ArmorType? = null
|
|
|
|
@ManyToMany(mappedBy = "units")
|
|
var buildFrom: Set<Building> = setOf()
|
|
|
|
var name: String? = null
|
|
var description: String? = null
|
|
var filenameSquad: String? = null
|
|
var filenameUnit: String? = null
|
|
var buildCostRequisition: Double? = null
|
|
var buildCostPower: Double? = null
|
|
var buildCostPopulation: Double? = null
|
|
var buildCostFaith: Double? = null
|
|
var buildCostSouls: Double? = null
|
|
var buildCostTime: Int? = null
|
|
var capInfantry: Int? = null
|
|
var capSupport: Int? = null
|
|
var squadStartSize: Int? = null
|
|
var squadMaxSize: Int? = null
|
|
var squadLimit: Int? = null
|
|
var health: Int? = null
|
|
var armour: Double? = null
|
|
var healthRegeneration: Double? = null
|
|
var moraleDeathPenalty: Int? = null
|
|
var repairMax: Int? = null
|
|
var repairSpeed: Int? = null
|
|
var repairCostPercent: Int? = null
|
|
var moraleMax: Int? = null
|
|
var moraleBroken: Int? = null
|
|
var moraleRegeneration: Int? = null
|
|
var mass: Int? = null
|
|
var upTime: Double? = null
|
|
var moveSpeed: Int? = null
|
|
var sightRadius: Int? = null
|
|
var detectRadius: Int? = null
|
|
var reinforceCostRequisition: Double? = null
|
|
var reinforceCostPower: Double? = null
|
|
var reinforceCostPopulation: Double? = null
|
|
var reinforceCostFaith: Double? = null
|
|
var reinforceCostSouls: Double? = null
|
|
var reinforceTime: Int? = null
|
|
var maxSergeants: Int? = null
|
|
var faithIncome: Double? = null
|
|
var powerIncome: Double? = null
|
|
var requisitionIncome: Double? = null
|
|
var icon: String? = null
|
|
var modId: Long? = null
|
|
|
|
@OneToMany(mappedBy = "unit", cascade = [CascadeType.ALL])
|
|
var sergeants: MutableSet<Sergeant>? = null
|
|
|
|
@OneToMany(mappedBy = "unit", cascade = [CascadeType.ALL])
|
|
var weapons: MutableSet<UnitWeapon>? = null
|
|
|
|
@ManyToMany
|
|
@JoinTable(name = "researches_affected_units",
|
|
joinColumns = [JoinColumn(name = "unit_id")],
|
|
inverseJoinColumns = [JoinColumn(name = "research_id")])
|
|
var affectedResearches: MutableSet<Research> = mutableSetOf()
|
|
|
|
|
|
fun toDto(): UnitFullDto =
|
|
UnitFullDto(
|
|
id!!,
|
|
race?.toDto(),
|
|
armorType?.toDto(),
|
|
armorType2?.toDto(),
|
|
name,
|
|
description,
|
|
filenameSquad!!,
|
|
buildCostRequisition,
|
|
buildCostPower,
|
|
buildCostPopulation,
|
|
buildCostFaith,
|
|
buildCostSouls,
|
|
buildCostTime,
|
|
faithIncome,
|
|
powerIncome,
|
|
requisitionIncome,
|
|
capInfantry,
|
|
capSupport,
|
|
squadStartSize,
|
|
squadMaxSize,
|
|
squadLimit,
|
|
health,
|
|
armour,
|
|
healthRegeneration,
|
|
moraleDeathPenalty,
|
|
moraleMax,
|
|
moraleBroken,
|
|
moraleRegeneration,
|
|
mass,
|
|
upTime,
|
|
moveSpeed,
|
|
sightRadius,
|
|
detectRadius,
|
|
reinforceCostRequisition,
|
|
reinforceCostPower,
|
|
reinforceCostPopulation,
|
|
reinforceCostFaith,
|
|
reinforceCostSouls,
|
|
reinforceTime,
|
|
repairMax,
|
|
repairSpeed,
|
|
repairCostPercent,
|
|
maxSergeants,
|
|
icon,
|
|
modId!!,
|
|
sergeants?.map { it.toDto() }?.toSet(),
|
|
weapons?.map { it.toWeaponSlotDto() }?.toSet(),
|
|
affectedResearches.map { it.toResearchShortDto() }.toSet(),
|
|
)
|
|
}
|
|
|
|
object DowUnitObject {
|
|
fun List<DowUnit>.toUnitDto(): Set<UnitShortDto> =
|
|
this.mapNotNull {
|
|
val name = it.name ?: it.filenameSquad
|
|
val icon = it.icon
|
|
if (name == null || icon == null) null else UnitShortDto(name, icon, it.id!!,
|
|
it.armorType?.name!!,
|
|
(it.detectRadius ?: 0) > 0)
|
|
}.toSet()
|
|
|
|
} |