29 October 2021 by jr101dallas
⇠ Back to PostsHow Should They Work
Eventually, I’m almost certainly going to want to break out big System processing into microservices. Target system is about launching attacks, almost regardless of actual landing of any hits. For instance, imagining a First Person Shooter, if a character starts spraying machine gun fire everywhere, there could potentially be a lot of stuff “targeted” but another character might not even be in the list.
The projectiles might be entities if I care about where they might eventually end up, or they might be some other kind of object that doesn’t get an Id because we don’t really all the way care if they get lost by the system. Lose a player or maybe even monsters in the play area, and people get mad or maybe mock you about phantom mobs. Lose some projectiles, maybe nobody notices unless it happens a lot.
Back on Target
So, Target should handle things like checking the origin Entity for active weapon, calculating damage type and amount, creating projectiles, calculating trajectory and progress along the flight plan, and finally collisions, which are “successful” target objects actually landing a hit, on something at least. So, .Target(targetEntity)
is a spcial case something more like .TargetAdjacent(direction)
where an Entity is already known to be adjacent. This is kind of getting into the weeds on things we don’t need to figure out just yet, but it’s helping me think out the direction I’m headed.
At the Moment
Growing code monstrosity but passing test looks like this.
[TestMethod]
public void TargetEntityRemovedFromPlay()
{
var unv = new Universe();
var originEntity = unv.GetEntity();
var targetEntity = unv.GetEntity();
var tEntityId = targetEntity.Id;
var target = (Target)unv.systems[nameof(Target)];
target.TargetEntity(unv, originEntity, targetEntity);
Assert.IsFalse(unv.entities.TryGetValue(tEntityId, out _));
}
Next I have some really hard thinking and lots of refactoring to do to get the yuck out of it.
tags: code - system - architecture