Skip to content

Commit 2610d4f

Browse files
committed
#27: Update initial implementation for remote weapon structure
1 parent bb0bc1d commit 2610d4f

96 files changed

Lines changed: 2192 additions & 1219 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

agents/AIAgent.cs

100644100755
File mode changed.

agents/AIAgent.tscn

100644100755
File mode changed.

agents/Agent.cs

100644100755
Lines changed: 101 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

agents/Agent.tscn

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ blend_mode = 1
2626
[sub_resource type="CircleShape2D" id=4]
2727
radius = 50.0
2828

29-
[node name="Agent" type="KinematicBody2D" groups=[
30-
"Obstacles",
31-
]]
29+
[node name="Agent" type="KinematicBody2D" groups=["Obstacles"]]
3230
collision_layer = 2
3331
collision_mask = 15
3432
script = ExtResource( 1 )

agents/GameCamera.cs

100644100755
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ public class GameCamera : Camera2D
1414

1515
private int _pripority = 0;
1616

17+
[Export]
18+
private int DefaultZoom = 2;
19+
20+
private int _currentZoom = 2;
21+
22+
[Export]
23+
private int MaxZoom = 6;
24+
25+
[Export]
26+
private int MinZoom = 1;
27+
1728
private Godot.RandomNumberGenerator random;
1829

1930

@@ -26,6 +37,33 @@ public override void _Ready()
2637

2738
random = new RandomNumberGenerator();
2839
Current = true;
40+
41+
_currentZoom = DefaultZoom;
42+
}
43+
44+
45+
public void ZoomIn()
46+
{
47+
_currentZoom--;
48+
49+
if(_currentZoom < MinZoom)
50+
{
51+
_currentZoom = MinZoom;
52+
}
53+
54+
Zoom = new Vector2(_currentZoom, _currentZoom);
55+
}
56+
57+
public void ZoomOut()
58+
{
59+
_currentZoom++;
60+
61+
if(_currentZoom > MaxZoom)
62+
{
63+
_currentZoom = MaxZoom;
64+
}
65+
66+
Zoom = new Vector2(_currentZoom, _currentZoom);
2967
}
3068

3169
public void StartScreenShake(float duration = 0.2f, float frequency = 15.0f, float amplitude = 15.0f, int pripority = 0)

agents/GameCamera.tscn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ script = ExtResource( 1 )
1313
one_shot = true
1414

1515
[node name="DurationTimer" type="Timer" parent="."]
16+
1617
[connection signal="timeout" from="FrequencyTimer" to="." method="FrequencyTimerTimeout"]
1718
[connection signal="timeout" from="DurationTimer" to="." method="DurationTimerTimeout"]

agents/GunTurret.tscn

100644100755
File mode changed.

agents/Observer.cs

100644100755
File mode changed.

agents/Observer.tscn

100644100755
File mode changed.

0 commit comments

Comments
 (0)