server/src/entities/character.ts
2025-01-01 22:50:58 +01:00

298 lines
4.7 KiB
TypeScript

import { randomUUID } from 'node:crypto'
import { Collection, Entity, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
import { CharacterEquipment } from './characterEquipment'
import { CharacterHair } from './characterHair'
import { CharacterItem } from './characterItem'
import { CharacterType } from './characterType'
import { Chat } from './chat'
import { User } from './user'
import { Zone } from './zone'
import { BaseEntity } from '#application/base/baseEntity'
import { UUID } from '#application/types'
@Entity()
export class Character extends BaseEntity {
@PrimaryKey()
id = randomUUID()
@ManyToOne()
user!: User
@Property({ unique: true })
name!: string
@Property()
online = false
@Property()
role = 'player'
@OneToMany(() => Chat, (chat) => chat.character)
chats = new Collection<Chat>(this)
// Position
@ManyToOne()
zone!: Zone // @TODO: Update to spawn point when current zone is not found
@Property()
positionX = 0
@Property()
positionY = 0
@Property()
rotation = 0
// Customization
@ManyToOne({ deleteRule: 'set null' })
characterType?: CharacterType | null | undefined
@ManyToOne({ deleteRule: 'set null' })
characterHair?: CharacterHair | null | undefined
// Inventory
@OneToMany({ mappedBy: 'character' })
items = new Collection<CharacterItem>(this)
@OneToMany({ mappedBy: 'character' })
equipment = new Collection<CharacterEquipment>(this)
// Stats
@Property()
alignment = 50
@Property()
hitpoints = 100
@Property()
mana = 100
@Property()
level = 1
@Property()
experience = 0
@Property()
strength = 10
@Property()
dexterity = 10
@Property()
intelligence = 10
@Property()
wisdom = 10
setId(id: UUID) {
this.id = id
return this
}
getId() {
return this.id
}
setUser(user: User) {
this.user = user
return this
}
getUser() {
return this.user
}
setName(name: string) {
this.name = name
return this
}
getName() {
return this.name
}
setOnline(online: boolean) {
this.online = online
return this
}
getOnline() {
return this.online
}
setRole(role: string) {
this.role = role
return this
}
getRole() {
return this.role
}
setChats(chats: Collection<Chat>) {
this.chats = chats
return this
}
getChats() {
return this.chats
}
setZone(zone: Zone) {
this.zone = zone
return this
}
getZone() {
return this.zone
}
setPositionX(positionX: number) {
this.positionX = positionX
return this
}
getPositionX() {
return this.positionX
}
setPositionY(positionY: number) {
this.positionY = positionY
return this
}
getPositionY() {
return this.positionY
}
setRotation(rotation: number) {
this.rotation = rotation
return this
}
getRotation() {
return this.rotation
}
setCharacterType(characterType: CharacterType | null | undefined) {
this.characterType = characterType
return this
}
getCharacterType() {
return this.characterType
}
setCharacterHair(characterHair: CharacterHair | null | undefined) {
this.characterHair = characterHair
return this
}
getCharacterHair() {
return this.characterHair
}
setItems(items: Collection<CharacterItem>) {
this.items = items
return this
}
getItems() {
return this.items
}
setEquipment(equipment: Collection<CharacterEquipment>) {
this.equipment = equipment
return this
}
getEquipment() {
return this.equipment
}
setAlignment(alignment: number) {
this.alignment = alignment
return this
}
getAlignment() {
return this.alignment
}
setHitpoints(hitpoints: number) {
this.hitpoints = hitpoints
return this
}
getHitpoints() {
return this.hitpoints
}
setMana(mana: number) {
this.mana = mana
return this
}
getMana() {
return this.mana
}
setLevel(level: number) {
this.level = level
return this
}
getLevel() {
return this.level
}
setExperience(experience: number) {
this.experience = experience
return this
}
getExperience() {
return this.experience
}
setStrength(strength: number) {
this.strength = strength
return this
}
getStrength() {
return this.strength
}
setDexterity(dexterity: number) {
this.dexterity = dexterity
return this
}
getDexterity() {
return this.dexterity
}
setIntelligence(intelligence: number) {
this.intelligence = intelligence
return this
}
getIntelligence() {
return this.intelligence
}
setWisdom(wisdom: number) {
this.wisdom = wisdom
return this
}
getWisdom() {
return this.wisdom
}
}