@@ -5,9 +5,11 @@ import StatSystem from '../mechanics/StatSystem';
55import BuffManager from '../managers/BuffManager' ;
66import { ModifierType , StatType } from '../mechanics/StatDefinitions' ;
77import DataManager from '../managers/DataManager' ;
8- import { DashConfig , DashLv1Buff , DashLv2Buff , DashLv3Buff , TransitionDashConfig } from '../config/BuffConfig' ;
8+ import { DashConfig , DashLv1Buff , DashLv2Buff , DashLv3Buff , TacticsConfig , TransitionDashConfig } from '../config/BuffConfig' ;
99import { KiteConfigs } from '../config/KiteBuffConfig' ;
1010import { EVENTS , gameEvents } from '../config/Events' ;
11+ import { SummonId } from '../config/SummonConfig' ;
12+ import type { BaseSummon } from './summons/BaseSummon' ;
1113
1214export default class PlayerState {
1315 private player : Player ;
@@ -23,6 +25,9 @@ export default class PlayerState {
2325 public coldness : number = 0 ; // 0 - 100
2426 public dashEnergy : number = 0 ; // 0 - 100
2527
28+ private shieldEffect : BaseSummon | null = null ;
29+ private wasDashing : boolean = false ;
30+
2631 public get isInvincible ( ) : boolean {
2732 return this . buffs . hasTag ( 'State.Invincible' ) ;
2833 }
@@ -47,6 +52,9 @@ export default class PlayerState {
4752
4853 // 2. 注入基础属性 (Base Stats)
4954 this . initBaseStats ( ) ;
55+
56+ gameEvents . on ( EVENTS . ADD_SHIELD , this . handleAddShield , this ) ;
57+ gameEvents . on ( EVENTS . REMOVE_SHIELD , this . handleRemoveShield , this ) ;
5058 }
5159
5260 private initBaseStats ( ) {
@@ -88,8 +96,10 @@ export default class PlayerState {
8896 }
8997
9098 update ( dt : number ) {
99+ this . refreshShieldRef ( ) ;
91100 // 1. 更新 Buff 系统 (转为秒)
92101 this . buffs . update ( dt / 1000 ) ;
102+ this . syncDashShieldState ( ) ;
93103 // 2. 更新寒冷值
94104 this . updateColdness ( dt ) ;
95105 // 4. ✅ 核心:将寒冷值同步到 StatSystem
@@ -245,7 +255,7 @@ export default class PlayerState {
245255 }
246256
247257 // ⚡️ 冲刺效果:清除所有寒冷
248- this . coldness = 0 ;
258+ this . addColdness ( - this . coldness ) ;
249259
250260 // ⚡️ 冲刺效果:无敌 & 向上猛冲 (逻辑在 Player.update 里配合)
251261 // this.player.setVelocityY(GameConfig.playerState.dashSpeed);
@@ -329,4 +339,60 @@ export default class PlayerState {
329339 public getStartBoostForce ( ) : number {
330340 return GameConfig . player . startForce ;
331341 }
332- }
342+
343+ public destroy ( ) {
344+ gameEvents . off ( EVENTS . ADD_SHIELD , this . handleAddShield , this ) ;
345+ gameEvents . off ( EVENTS . REMOVE_SHIELD , this . handleRemoveShield , this ) ;
346+ }
347+
348+ private syncDashShieldState ( ) {
349+ const isDashingNow = this . isDashing ;
350+ if ( ! this . wasDashing && isDashingNow ) {
351+ this . ensureShieldSummoned ( ) ;
352+ } else if ( this . wasDashing && ! isDashingNow ) {
353+ if ( ! this . buffs . hasTag ( TacticsConfig . tag ) ) {
354+ this . removeShield ( ) ;
355+ }
356+ }
357+ this . wasDashing = isDashingNow ;
358+ }
359+
360+ private handleAddShield ( ) {
361+ this . ensureShieldSummoned ( ) ;
362+ }
363+
364+ private handleRemoveShield ( ) {
365+ if ( ! this . isDashing ) {
366+ this . removeShield ( ) ;
367+ }
368+ }
369+
370+ private ensureShieldSummoned ( ) {
371+ if ( this . shieldEffect && this . shieldEffect . active ) return ;
372+ const summonManager = ( this . player . scene as any ) . summonManager ;
373+ if ( ! summonManager ) return ;
374+ const summoned = summonManager . summon (
375+ SummonId . Shield ,
376+ this . player . x ,
377+ this . player . y ,
378+ { lifeTime : - 1 }
379+ ) ;
380+ if ( summoned ) {
381+ this . shieldEffect = summoned ;
382+ }
383+ }
384+
385+ private removeShield ( ) {
386+ if ( this . shieldEffect && this . shieldEffect . active ) {
387+ this . shieldEffect . despawn ( ) ;
388+ } else {
389+ this . shieldEffect = null ;
390+ }
391+ }
392+
393+ private refreshShieldRef ( ) {
394+ if ( this . shieldEffect && ! this . shieldEffect . active ) {
395+ this . shieldEffect = null ;
396+ }
397+ }
398+ }
0 commit comments