forked from noxious/server
296 lines
4.7 KiB
TypeScript
296 lines
4.7 KiB
TypeScript
import { randomUUID } from 'node:crypto'
|
|
|
|
import { Collection, Entity, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
|
|
|
|
import { BaseEntity } from '#application/base/baseEntity'
|
|
import { UUID } from '#application/types'
|
|
import { CharacterEquipment } from '#entities/characterEquipment'
|
|
import { CharacterHair } from '#entities/characterHair'
|
|
import { CharacterItem } from '#entities/characterItem'
|
|
import { CharacterType } from '#entities/characterType'
|
|
import { Chat } from '#entities/chat'
|
|
import { Map } from '#entities/map'
|
|
import { User } from '#entities/user'
|
|
|
|
export class BaseCharacter extends BaseEntity {
|
|
@PrimaryKey()
|
|
id = randomUUID()
|
|
|
|
@ManyToOne({ deleteRule: 'cascade' })
|
|
user!: User
|
|
|
|
@Property({ unique: true })
|
|
name!: string
|
|
|
|
@Property()
|
|
online = false
|
|
|
|
@Property()
|
|
role = 'player'
|
|
|
|
@OneToMany(() => Chat, (chat) => chat.character)
|
|
chats = new Collection<Chat>(this)
|
|
|
|
// Position - @TODO: Update to spawn point when current map is not found
|
|
@ManyToOne()
|
|
map!: Map
|
|
|
|
@Property()
|
|
positionX = 0
|
|
|
|
@Property()
|
|
positionY = 0
|
|
|
|
@Property()
|
|
rotation = 0
|
|
|
|
// Customization
|
|
@ManyToOne({ deleteRule: 'set null' })
|
|
characterType: CharacterType | null = null
|
|
|
|
@ManyToOne({ deleteRule: 'set null' })
|
|
characterHair: CharacterHair | null = null
|
|
|
|
// 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
|
|
}
|
|
|
|
setMap(map: Map) {
|
|
this.map = map
|
|
return this
|
|
}
|
|
|
|
getMap() {
|
|
return this.map
|
|
}
|
|
|
|
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) {
|
|
this.characterType = characterType
|
|
return this
|
|
}
|
|
|
|
getCharacterType() {
|
|
return this.characterType
|
|
}
|
|
|
|
setCharacterHair(characterHair: CharacterHair | null) {
|
|
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
|
|
}
|
|
}
|