Skip to content

Commit

Permalink
Update Combat to work properly, add a few specialists to test functio…
Browse files Browse the repository at this point in the history
…nality
  • Loading branch information
QuinnBast committed Mar 5, 2023
1 parent b2533cb commit 8d6b0c4
Show file tree
Hide file tree
Showing 118 changed files with 1,623 additions and 1,032 deletions.
2 changes: 1 addition & 1 deletion Core/Models/Network/GameEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class GameEndEventData : EventData
public class HireSpecialistEventData : EventData
{
public string HireLocation { get; set; }
public SpecialistIds SpecialistIdHired { get; set; }
public SpecialistTypeId SpecialistTypeIdHired { get; set; }
}

public class PromoteSpecialistEventData : EventData
Expand Down
12 changes: 6 additions & 6 deletions Core/Models/Network/GameLobbyModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ public class GameConfiguration {
public GameSettings GameSettings { get; set; }
public MapConfiguration MapConfiguration { get; set; }
public string RoomName { get; set; }
public GameVersion GameVersion { get; set; } = GameVersion.V1;
public GameVersion GameVersion { get; set; } = GameVersion.ALPHA01;
public DateTime TimeCreated { get; set; }
public DateTime TimeStarted { get; set; }
public DateTime ExpiresAt { get; set; } = DateTime.MaxValue;
public List<User> PlayersInLobby { get; set; }
public Dictionary<string, List<SpecialistIds>> PlayerSpecialistDecks { get; set; }
public Dictionary<string, List<SpecialistTypeId>> PlayerSpecialistDecks { get; set; }
}

public enum GameVersion
{
UNKNOWN = 0,
V1 = 1,
ALPHA01 = 1,
}

public class GameSettings
Expand Down Expand Up @@ -98,7 +98,7 @@ public class CreateRoomRequest
public MapConfiguration MapConfiguration { get; set; }
public string RoomName { get; set; }
public Boolean IsPrivate { get; set; }
public List<SpecialistIds> CreatorSpecialistDeck { get; set; }
public List<SpecialistTypeId> CreatorSpecialistDeck { get; set; }
}

public class CreateRoomResponse
Expand All @@ -110,7 +110,7 @@ public class JoinRoomResponse { }

public class JoinRoomRequest
{
public List<SpecialistIds> SpecialistDeck { get; set; }
public List<SpecialistTypeId> SpecialistDeck { get; set; }
}

public class LeaveRoomResponse { }
Expand All @@ -122,7 +122,7 @@ public class GetLobbyResponse
public GameConfiguration[] Lobbies { get; set; }
}

public enum SpecialistIds
public enum SpecialistTypeId
{
Unknown = 0,
Infiltrator = 1,
Expand Down
4 changes: 1 addition & 3 deletions Core/SubterfugeCore/Core/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Subterfuge.Remake.Core.Timing;

namespace Subterfuge.Remake.Core.Config
namespace Subterfuge.Remake.Core
{
/// <summary>
/// A Collection of Constants like player base stats etc.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using System;
using Subterfuge.Remake.Core.Entities;
using Subterfuge.Remake.Core.GameEvents.Base;
using Subterfuge.Remake.Core.GameEvents.EventPublishers;
using Subterfuge.Remake.Core.Players;

namespace Subterfuge.Remake.Core.Components
namespace Subterfuge.Remake.Core.Entities.Components
{
public class DrillerCarrier : EntityComponent
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using System;
using Subterfuge.Remake.Core.Config;
using Subterfuge.Remake.Core.Entities;
using Subterfuge.Remake.Core.GameEvents.EventPublishers;
using Subterfuge.Remake.Core.Resources.Producers;
using Subterfuge.Remake.Core.Timing;

namespace Subterfuge.Remake.Core.Components
namespace Subterfuge.Remake.Core.Entities.Components
{
public class DrillerProductionComponent : EntityComponent
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Subterfuge.Remake.Core.Entities;

namespace Subterfuge.Remake.Core.Components
namespace Subterfuge.Remake.Core.Entities.Components
{

public abstract class EntityComponent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using Subterfuge.Remake.Core.Entities;

namespace Subterfuge.Remake.Core.Components
namespace Subterfuge.Remake.Core.Entities.Components
{
public class IdentityManager : EntityComponent
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using System;
using System.Collections.Generic;
using Subterfuge.Remake.Core.Config;
using Subterfuge.Remake.Core.Entities;
using Subterfuge.Remake.Core.GameEvents.EventPublishers;
using Subterfuge.Remake.Core.Resources.Producers;
using Subterfuge.Remake.Core.Timing;

namespace Subterfuge.Remake.Core.Components
namespace Subterfuge.Remake.Core.Entities.Components
{
public class MineProductionComponent : EntityComponent
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Subterfuge.Remake.Core.Entities;
using Subterfuge.Remake.Core.GameEvents.Combat;
using Subterfuge.Remake.Core.GameEvents.EventPublishers;
using Subterfuge.Remake.Core.GameEvents.NaturalGameEvents.combat;
using Subterfuge.Remake.Core.Timing;
using Subterfuge.Remake.Core.Topologies;

namespace Subterfuge.Remake.Core.Components
namespace Subterfuge.Remake.Core.Entities.Components
{
public class PositionManager : EntityComponent, ICombatEventPublisher
{
Expand Down Expand Up @@ -113,6 +112,7 @@ private void CheckCombat(TimeMachine timeMachine, OnTickEventArgs onTick)
OnPreCombat?.Invoke(this, new OnPreCombatEventArgs()
{
Direction = onTick.Direction,
CurrentState = timeMachine.GetState(),
CombatEvent = combat,
});

Expand All @@ -123,8 +123,8 @@ private void CheckCombat(TimeMachine timeMachine, OnTickEventArgs onTick)
OnPostCombat?.Invoke(this, new PostCombatEventArgs()
{
Direction = onTick.Direction,
SurvivingEntity = combat.combatSummary._winner,
CombatSummary = combat.combatSummary
CombatResolution = combat.GetCombatResolution(),
CurrentState = timeMachine.GetState()
});
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using Subterfuge.Remake.Core.Entities;
using Subterfuge.Remake.Core.GameEvents.EventPublishers;

namespace Subterfuge.Remake.Core.Components
namespace Subterfuge.Remake.Core.Entities.Components
{
public class ShieldManager : EntityComponent, IShieldEventPublisher
{
Expand Down Expand Up @@ -65,7 +64,7 @@ public void SetShields(int shieldValue)
});
}

public void RemoveShields(int shieldsToRemove)
public int RemoveShields(int shieldsToRemove)
{
var previousValue = _shields;
this._shields = Math.Max(0, this._shields - shieldsToRemove);
Expand All @@ -75,6 +74,8 @@ public void RemoveShields(int shieldsToRemove)
ShieldDelta = this._shields - previousValue,
ShieldManager = this,
});

return this._shields - previousValue;
}

public void ToggleShield()
Expand All @@ -101,7 +102,7 @@ public bool IsShieldActive()
return this._shieldActive;
}

public void AddShield(int shields)
public int AddShield(int shields)
{
var previousValue = _shields;
this._shields = Math.Min(this._shieldCapacity, this._shields + shields);
Expand All @@ -111,6 +112,8 @@ public void AddShield(int shields)
ShieldDelta = this._shields - previousValue,
ShieldManager = this,
});

return this._shields - previousValue;
}

public int GetShieldCapacity()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using System;
using Subterfuge.Remake.Core.Config;
using Subterfuge.Remake.Core.Entities;
using Subterfuge.Remake.Core.GameEvents.EventPublishers;
using Subterfuge.Remake.Core.Resources.Producers;
using Subterfuge.Remake.Core.Timing;

namespace Subterfuge.Remake.Core.Components
namespace Subterfuge.Remake.Core.Entities.Components
{
public class ShieldRegenerationComponent : EntityComponent
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Subterfuge.Remake.Core.Entities;
using Subterfuge.Remake.Core.Entities.Specialists;
using Subterfuge.Remake.Core.GameEvents.EventPublishers;
using Subterfuge.Remake.Core.Players;

namespace Subterfuge.Remake.Core.Components
namespace Subterfuge.Remake.Core.Entities.Components
{
/// <summary>
/// Specialist management class to facilitate adding and removing specialists from ISpecialistCarrier classes.
Expand Down Expand Up @@ -65,6 +64,7 @@ public bool HireSpecialist(Specialist specialist)
if (_specialists.Count < _capacity)
{
_specialists.Add(specialist);
specialist.ArriveAt(Parent);
OnSpecialistHire?.Invoke(this, new OnSpecialistHireEventArgs()
{
HiredSpecialist = specialist,
Expand All @@ -84,9 +84,11 @@ public bool AddFriendlySpecialist(Specialist specialist)
if (_specialists.Count < _capacity)
{
_specialists.Add(specialist);
specialist.ArriveAt(Parent);
OnSpecialistArrive?.Invoke(this, new OnAddSpecialistEventArgs()
{
AddedSpecialist = specialist,
AddedTo = Parent,
});
return true;
}
Expand All @@ -106,9 +108,11 @@ public int AddFriendlySpecialists(List<Specialist> specialists)
{
addedSpecialists++;
_specialists.Add(s);
s.ArriveAt(Parent);
OnSpecialistArrive?.Invoke(this, new OnAddSpecialistEventArgs()
{
AddedSpecialist = s,
AddedTo = Parent,
});
}
}
Expand All @@ -125,9 +129,11 @@ public bool RemoveFriendlySpecialist(Specialist specialist)
if (_specialists.Contains(specialist))
{
_specialists.Remove(specialist);
specialist.LeaveLocation(Parent);
OnSpecialistLeave?.Invoke(this, new OnRemoveSpecialistEventArgs()
{
RemovedSpecialist = specialist,
RemovedFrom = Parent,
});
return true;
}
Expand All @@ -147,9 +153,11 @@ public int RemoveFriendlySpecialists(List<Specialist> specialists)
{
removedSpecialists++;
_specialists.Remove(s);
s.LeaveLocation(Parent);
OnSpecialistLeave?.Invoke(this, new OnRemoveSpecialistEventArgs()
{
RemovedSpecialist = s,
RemovedFrom = Parent,
});
}
}
Expand Down Expand Up @@ -232,6 +240,7 @@ public void CaptureAll()
foreach(Specialist s in _specialists)
{
s.SetCaptured(true);
s.OnCaptured(Parent);
}
OnCaptured?.Invoke(this, new OnSpecialistsCapturedEventArgs()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using Subterfuge.Remake.Core.Entities;
using Subterfuge.Remake.Core.GameEvents.EventPublishers;

namespace Subterfuge.Remake.Core.Components
namespace Subterfuge.Remake.Core.Entities.Components
{
public class SpeedManager : EntityComponent, ISpeedEventPublisher
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using System;
using System.Linq;
using Subterfuge.Remake.Api.Network;
using Subterfuge.Remake.Core.Entities;
using Subterfuge.Remake.Core.GameEvents.EventPublishers;
using Subterfuge.Remake.Core.GameEvents.PlayerTriggeredEvents;
using Subterfuge.Remake.Core.GameState;
using Subterfuge.Remake.Core.Timing;

namespace Subterfuge.Remake.Core.Components
namespace Subterfuge.Remake.Core.Entities.Components
{
public class SubLauncher : EntityComponent, ISubLaunchEventPublisher
{
Expand All @@ -32,7 +30,7 @@ LaunchEvent launchEvent
) {
// Determine any specialist effects if a specialist left the sub.
LaunchEventData launchData = launchEvent.GetEventData();
GameState.GameState state = timeMachine.GetState();
GameState state = timeMachine.GetState();
Entity source = state.GetEntity(launchData.SourceId);
Entity destination = state.GetEntity(launchData.DestinationId);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using Subterfuge.Remake.Core.Entities;
using Subterfuge.Remake.Core.GameEvents.EventPublishers;
using Subterfuge.Remake.Core.GameState;

namespace Subterfuge.Remake.Core.Components
namespace Subterfuge.Remake.Core.Entities.Components
{
public class VisionManager : EntityComponent, IVisionEventPublisher
{
Expand Down
17 changes: 9 additions & 8 deletions Core/SubterfugeCore/Core/Entities/Entity.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using Subterfuge.Remake.Core.Components;
using Subterfuge.Remake.Core.Entities.Components;

namespace Subterfuge.Remake.Core.Entities
{
Expand All @@ -18,19 +18,16 @@ public T GetComponent<T>()
{
if (_componentMap.ContainsKey(typeof(T)))
{
return _componentMap[typeof(T)] as T;
return _componentMap[typeof(T)] as T ?? throw new ComponentDoesNotExistException($"Found component {typeof(T)} but it was null.");
}
return null;
throw new ComponentDoesNotExistException($"Looking for component of {typeof(T)} but the component was not present.");
}

public bool HasComponent<T>()
where T : EntityComponent
{
if (_componentMap.ContainsKey(typeof(T)))
{
return _componentMap[typeof(T)] != null;
}
return false;
return _componentMap.ContainsKey(typeof(T));

}
}

Expand All @@ -39,6 +36,10 @@ public interface IEntity
bool HasComponent<T>() where T : EntityComponent;
T GetComponent<T>() where T : EntityComponent;
void AddComponent(EntityComponent component);
}

public class ComponentDoesNotExistException : Exception
{
public ComponentDoesNotExistException(string detail) : base(detail){}
}
}
3 changes: 1 addition & 2 deletions Core/SubterfugeCore/Core/Entities/Positions/Factory.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using Subterfuge.Remake.Core.Components;
using Subterfuge.Remake.Core.Config;
using Subterfuge.Remake.Core.Entities.Components;
using Subterfuge.Remake.Core.GameEvents.EventPublishers;
using Subterfuge.Remake.Core.Players;
using Subterfuge.Remake.Core.Timing;
Expand Down
2 changes: 1 addition & 1 deletion Core/SubterfugeCore/Core/Entities/Positions/Mine.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Subterfuge.Remake.Core.Components;
using Subterfuge.Remake.Core.Entities.Components;
using Subterfuge.Remake.Core.Players;
using Subterfuge.Remake.Core.Timing;
using Subterfuge.Remake.Core.Topologies;
Expand Down
Loading

0 comments on commit 8d6b0c4

Please sign in to comment.