-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerModel.js
More file actions
147 lines (137 loc) · 3.93 KB
/
Copy pathPlayerModel.js
File metadata and controls
147 lines (137 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import * as THREE from "three";
import * as C from "../ConstData/Constants.js";
import { PlayerStates } from "../ConstData/PlayerStates.js";
// =================================================================================
// 1. Model (PlayerModel)
// =================================================================================
/**
* プレイヤーのロジック状態(位置・向き・ステータス等)を保持するモデル。
* 表示や操作に依存せずデータのみを提供する。
*/
export default class PlayerModel {
/** プレイヤー識別情報・現在値をカプセル化したプライベートフィールド群 */
#id;
#team;
#isUser;
#position;
#quaternion;
#state;
#hasBall;
#velocity;
#stunTimer;
#catchCooldown;
#isCharging;
/**
* プレイヤーの初期状態を構築する。
* @param {string} id プレイヤー識別子
* @param {string} team 所属チーム名
* @param {boolean} [isUser=false] ユーザー操作キャラクターかどうか
*/
constructor(id, team, isUser = false) {
this.#id = id;
this.#team = team;
this.#isUser = isUser;
this.#position = new THREE.Vector3(0, C.PLAYER_Y, 0);
this.#quaternion = new THREE.Quaternion();
this.#state = PlayerStates.Idle;
this.#hasBall = false;
this.#velocity = new THREE.Vector3();
this.#stunTimer = C.STUN_DURATION;
this.#catchCooldown = 0;
this.#isCharging = false;
}
/** 現在の各種状態を参照するためのアクセサ */
// --- Getters ---
getId() {
return this.#id;
}
getTeam() {
return this.#team;
}
isUser() {
return this.#isUser;
}
getPosition() {
return this.#position.clone();
}
getQuaternion() {
return this.#quaternion.clone();
}
getState() {
return this.#state;
}
hasBall() {
return this.#hasBall;
}
getVelocity() {
return this.#velocity.clone();
}
getStunTimer() {
return this.#stunTimer;
}
getCatchCooldown() {
return this.#catchCooldown;
}
getIsCharging() {
return this.#isCharging;
}
/** ロジックから状態を更新するためのミューテータ */
// --- Setters ---
setPosition(x, y, z) {
const halfW = C.FIELD_WIDTH / 2;
const halfH = C.FIELD_HEIGHT / 2;
this.#position.x = Math.max(-halfW, Math.min(halfW, x));
this.#position.z = Math.max(-halfH, Math.min(halfH, z));
this.#position.y = y; // Y方向は制限しない(必要なら追加)
}
setQuaternion(quaternion) {
this.#quaternion.copy(quaternion);
}
/**
* ステートを変更する。PlayerStates に存在しない値は無視する。
* @param {string} state PlayerStates のいずれか
*/
setState(state) {
if (!PlayerStates.values().includes(state)) {
console.warn(`[PlayerModel] Unknown state: ${state}`);
return;
}
this.#state = state;
}
/**
* ボール保持フラグを更新する。変化時はデバッグログを出力する。
* @param {boolean} hasBall 保持状態
*/
setHasBall(hasBall) {
if (this.#hasBall !== hasBall) {
console.log(`[State Change] ${this.#id} のボール所持状態: ${hasBall}`);
}
this.#hasBall = hasBall;
}
setVelocity(velocity) {
this.#velocity.copy(velocity);
}
setStunTimer(duration) {
this.#stunTimer = Math.max(0, duration);
}
setCatchCooldown(value) {
this.#catchCooldown = Math.max(0, value);
}
/**
* チャージ状態を切り替える。変化時はデバッグログを出力する。
* @param {boolean} value チャージ中かどうか
*/
setCharging(value) {
const next = Boolean(value);
if (this.#isCharging !== next) {
console.log(`[State Change] ${this.#id} のチャージ状態: ${next}`);
}
this.#isCharging = next;
}
setKickChargeRatio(ratio) {
this.kickChargeRatio = Math.max(0, Math.min(1, ratio));
}
getKickChargeRatio() {
return this.kickChargeRatio ?? 0;
}
}