@@ -43,6 +43,7 @@ public class Agent : KinematicBody2D
4343
4444 public int RightWeaponAction { set ; get ; }
4545 public int LeftWeaponAction { set ; get ; }
46+ public int RemoteWeaponAction { set ; get ; }
4647 protected List < Weapon > RightWeapons ;
4748 protected List < Weapon > LeftWeapons ;
4849
@@ -93,6 +94,8 @@ public class Agent : KinematicBody2D
9394
9495 protected Agent CurrentTargetAgent ;
9596
97+ protected RemoteWeaponManager RemoteWeaponManager = null ;
98+
9699 public enum EngineType {
97100 Battery ,
98101 NuclearReactor
@@ -129,7 +132,7 @@ public override void _Ready()
129132 CurrentWeaponIndex . Add ( Weapon . WeaponOrder . Right , 0 ) ;
130133
131134 EmitSignal ( nameof ( HealthChangedSignal ) , _health * 100 / MaxHealth ) ;
132- EmitSignal ( nameof ( EnergyChangedSignal ) , _health * 100 / MaxHealth ) ;
135+ EmitSignal ( nameof ( EnergyChangedSignal ) , _energy * 100 / MaxEnergy ) ;
133136
134137 DetectionZone = ( DetectionZone ) ( GetNode ( "DetectionZone" ) ) ;
135138
@@ -152,15 +155,25 @@ public Inventory GetInventory()
152155 }
153156
154157 public void SetEngineType ( EngineType engineType )
158+ {
159+ Rpc ( nameof ( _clientSetEngineTypeClient ) , engineType ) ;
160+ }
161+
162+ public EngineType GetEngineType ( )
163+ {
164+ return CurrentEngineType ;
165+ }
166+
167+ [ Remote ]
168+ public void _clientSetEngineTypeClient ( EngineType engineType )
155169 {
156170 CurrentEngineType = engineType ;
157171
158172 // Reload the current weapon to let it get the benefit
159173 for ( int index = 0 ; index < Enum . GetNames ( typeof ( Weapon . WeaponOrder ) ) . Length ; index ++ )
160174 {
161- ChangeWeapon ( GetCurrentWeaponIndex ( ( Weapon . WeaponOrder ) index ) , ( Weapon . WeaponOrder ) index ) ;
175+ ChangeWeapon ( GetCurrentWeaponIndex ( ( Weapon . WeaponOrder ) index ) , ( Weapon . WeaponOrder ) index ) ;
162176 }
163-
164177 }
165178
166179 public virtual void Initialize ( GameWorld gameWorld , String unitID , String displayName , TeamMapAI teamMapAI , PathFinding pathFinding )
@@ -182,6 +195,8 @@ public virtual void Initialize(GameWorld gameWorld, String unitID, String displa
182195 _initializeWeapon ( RightWeapons ) ;
183196
184197 DetectionZone . Initialize ( gameWorld , this , DetectionRadius ) ;
198+
199+ RemoteWeaponManager = _gameWorld . GetRemoteWeaponManager ( ) ;
185200 }
186201
187202 public GameWorld GetGameWorld ( )
@@ -328,6 +343,27 @@ public bool EquipWeapon(PackedScene weaponScene, Weapon.WeaponOrder weaponOrder,
328343 return true ;
329344 }
330345
346+ /**
347+ AddRemoteWeapon
348+ Assign weapon to target weaponOrder and index
349+ **/
350+ public void AddRemoteWeapon ( PackedScene weaponScene )
351+ {
352+ RemoteWeaponManager . AddRemoteWeaponForAgent ( this , weaponScene ) ;
353+ }
354+
355+ public Boolean IsMoreRemoteWeaponUnitsAllowed ( )
356+ {
357+ if ( RemoteWeaponManager . GetRemoteWeaponUnitsCount ( this ) < MaxWeaponCount * 2 )
358+ {
359+ return true ;
360+ }
361+ else
362+ {
363+ return false ;
364+ }
365+ }
366+
331367 public List < Weapon > GetWeapons ( Weapon . WeaponOrder weaponOrder )
332368 {
333369 if ( weaponOrder == Weapon . WeaponOrder . Right )
@@ -386,14 +422,11 @@ public Team.TeamCode GetTeam()
386422 return _team . CurrentTeamCode ;
387423 }
388424
389-
390425 public TeamMapAI GetTeamMapAI ( )
391426 {
392427 return _teamMapAI ;
393428 }
394429
395-
396-
397430 public String GetDisplayName ( )
398431 {
399432 return _displayName ;
@@ -450,10 +483,10 @@ protected void slowDownBoostTrail()
450483 }
451484
452485
453- public void Sync ( Vector2 position , float rotation , int rightWeapon , int leftWeapon )
486+ public void Sync ( NetworkSnapshotManager . ClientData snapshot )
454487 {
455488 // Move effect
456- if ( position != Position )
489+ if ( snapshot . Position != Position )
457490 {
458491 //AudioManager audioManager = (AudioManager)GetNode("/root/AUDIOMANAGER");
459492 //audioManager.playSoundEffect(moveMusicClip);
@@ -465,12 +498,23 @@ public void Sync(Vector2 position, float rotation, int rightWeapon, int leftWeap
465498 slowDownBoostTrail ( ) ;
466499 }
467500
468- GlobalPosition = position ;
469- GlobalRotation = rotation ;
501+ GlobalPosition = snapshot . Position ;
502+ GlobalRotation = snapshot . Rotation ;
470503
471- Fire ( Weapon . WeaponOrder . Right , rightWeapon ) ;
472- Fire ( Weapon . WeaponOrder . Left , leftWeapon ) ;
504+ SetHealth ( snapshot . Health ) ;
505+ SetHealth ( snapshot . Energy ) ;
473506
507+ // Update Target Agent
508+ DetectionZone . SetTargetAgent ( snapshot . TargetAgentUnitID ) ;
509+
510+ // Update and fire weapon
511+ ChangeWeapon ( snapshot . RightWeaponIndex , Weapon . WeaponOrder . Right ) ;
512+ ChangeWeapon ( snapshot . LeftWeaponIndex , Weapon . WeaponOrder . Left ) ;
513+
514+ Fire ( Weapon . WeaponOrder . Right , snapshot . RightWeaponAction ) ;
515+ Fire ( Weapon . WeaponOrder . Left , snapshot . LeftWeaponAction ) ;
516+
517+ FireRemoteWeapon ( snapshot . RemoteWeaponAction ) ;
474518 }
475519
476520
@@ -479,6 +523,18 @@ public void RotateToward(Vector2 location, float delta)
479523 GlobalRotation = Mathf . LerpAngle ( GlobalRotation , GlobalPosition . DirectionTo ( location ) . Angle ( ) , RotationSpeed * delta ) ;
480524 }
481525
526+ public void FireRemoteWeapon ( int weaponAction )
527+ {
528+ if ( weaponAction == ( int ) NetworkSnapshotManager . PlayerInput . InputAction . TRIGGER )
529+ {
530+ RemoteWeaponManager . Fire ( this ) ;
531+ }
532+ else if ( weaponAction == ( int ) NetworkSnapshotManager . PlayerInput . InputAction . RELOAD )
533+ {
534+ RemoteWeaponManager . Reload ( this ) ;
535+ }
536+ }
537+
482538 public void Fire ( Weapon . WeaponOrder weaponOrder , int weaponAction )
483539 {
484540 Weapon weapon = GetWeapons ( weaponOrder ) [ CurrentWeaponIndex [ weaponOrder ] ] ;
@@ -517,23 +573,29 @@ public void ApplyKnockBackForce(Vector2 force)
517573 MoveAndSlide ( force * 100 ) ;
518574 }
519575
520- public void setHealth ( int health )
576+ public void SetHealth ( int health )
521577 {
522578 _health = health ;
523579 EmitSignal ( nameof ( HealthChangedSignal ) , health * 100 / MaxHealth ) ;
524580 }
525581
526- public void setEnergy ( int energy )
582+ public void SetEnergy ( int energy )
527583 {
528584 _energy = energy ;
529- EmitSignal ( nameof ( HealthChangedSignal ) , energy * 100 / MaxEnergy ) ;
585+ EmitSignal ( nameof ( EnergyChangedSignal ) , energy * 100 / MaxEnergy ) ;
530586 }
531587
532- public int getHealth ( )
588+ public int GetHealth ( )
533589 {
534590 return _health ;
535591 }
536592
593+ public int GetEnergy ( )
594+ {
595+ return _energy ;
596+ }
597+
598+
537599 public void IncrementDefeatedAgentCount ( )
538600 {
539601 defeatedAgentCount ++ ;
@@ -634,6 +696,8 @@ public void Heal(int amount)
634696
635697 public virtual void Explode ( )
636698 {
699+ RemoteWeaponManager . DeleteRemoteWeaponForAgent ( this ) ;
700+
637701 for ( int index = 0 ; index <= ( int ) Weapon . WeaponOrder . Left ; index ++ )
638702 {
639703 List < Weapon > weapons = GetWeapons ( ( Weapon . WeaponOrder ) index ) ;
@@ -663,24 +727,39 @@ public virtual void Explode()
663727
664728 AudioManager audioManager = ( AudioManager ) GetNode ( "/root/AUDIOMANAGER" ) ;
665729 audioManager . playSoundEffect ( explosionMusicClip ) ;
730+ }
666731
732+ // Change to target selection enable/disable
733+ public void TriggerTargetAgentSelection ( )
734+ {
735+ DetectionZone . TriggerTargetAgentSelection ( ) ;
736+ }
667737
738+ // Change to next target (if available)
739+ public void GetNextTargeAgent ( )
740+ {
741+ DetectionZone . GetNextTargetAgent ( ) ;
742+ }
668743
744+ // Change to previous target (if available)
745+ public void GetPreviousTargeAgent ( )
746+ {
747+ DetectionZone . GetPreviousTargetAgent ( ) ;
669748 }
670749
671750 public virtual void OnTargetAgentChange ( )
672751 {
673- CurrentTargetAgent = DetectionZone . getTargetAgent ( ) ;
752+ CurrentTargetAgent = DetectionZone . GetTargetAgent ( ) ;
674753 }
675754
676- private void _OnExplosionAnimationFinished ( )
755+ public Agent GetTargetAgent ( )
677756 {
678- QueueFree ( ) ;
679- EmitSignal ( nameof ( DeadSignal ) ) ;
757+ return CurrentTargetAgent ;
680758 }
681759
682- public override void _Process ( float delta )
760+ private void _OnExplosionAnimationFinished ( )
683761 {
762+ QueueFree ( ) ;
763+ EmitSignal ( nameof ( DeadSignal ) ) ;
684764 }
685-
686765}
0 commit comments