KF-MMO-Server/Classes/playerData.ts

62 lines
1.7 KiB
TypeScript
Raw Normal View History

2023-09-21 02:17:18 +08:00
import { enemyDamageInfo } from "./enemyDamageInfo";
2023-09-16 05:42:42 +08:00
import { physicsObject } from "./physicsObject";
import { playerInventory } from "./playerInventory";
2023-11-03 07:15:58 +08:00
import { questBook } from "./questBook";
2023-09-16 05:42:42 +08:00
export class playerData{
id : number
2023-09-18 18:33:06 +08:00
level : number = 1
2023-09-21 02:17:18 +08:00
room : string = "0_0"
2023-09-16 05:42:42 +08:00
characterId : number
inventory : playerInventory = new playerInventory()
rigidbody : physicsObject = new physicsObject()
2023-11-03 07:15:58 +08:00
questBook : questBook = new questBook()
2023-09-21 02:17:18 +08:00
damageInfo : enemyDamageInfo[] = []
2023-09-16 05:42:42 +08:00
2023-11-03 07:15:58 +08:00
constructor(init?: Partial<playerData>) {
Object.assign(this, init);
this.questBook = new questBook(this.questBook)
}
2023-11-02 02:46:59 +08:00
copyStart(){
let player : any = {}
2023-09-18 18:33:06 +08:00
player.id = this.id
2023-11-02 02:46:59 +08:00
player.characterId = this.characterId
player.rigidbody = physicsObject.characterOnly(this.rigidbody)
return player
}
copyUpdate(){
let player : any = {}
player.id = this.id
if(this.rigidbody == null){
console.log(this)
}
player.rigidbody = physicsObject.characterOnly(this.rigidbody)
if(this.damageInfo.length > 0) player.damageInfo = this.damageInfo
return player
}
copyInventory(){
let player : any = {}
player.id = this.id
player.inventory = this.inventory
2023-09-16 05:42:42 +08:00
return player
}
2023-09-18 18:33:06 +08:00
getItemById(id : number){
let item = this.inventory.items.find(i=>i.id == id)
return item
}
validateEquipment(){
2023-11-03 00:12:24 +08:00
if(this.inventory.equipment.length < 3){
this.inventory.equipment = [-1, -1, -1]
2023-09-18 18:33:06 +08:00
}
}
save(fs){
let data = JSON.stringify(this, null, 2);
fs.writeFileSync(`Database/Players/${this.id}.json`, data);
}
2023-09-16 05:42:42 +08:00
}