Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TagAction improvements #13974

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ namespace Barotrauma
/// </summary>
class TagAction : EventAction
{
public enum SubType { Any = 0, Player = 1, Outpost = 2, Wreck = 4, BeaconStation = 8 }
public enum SubType { Any = 0, Player = 1, Outpost = 2, Wreck = 4, BeaconStation = 8, Enemy = 16, Ruin = 32 }
public enum CharacterTeam { Any = 0, None = 1, Team1 = 2, Team2 = 4, FriendlyNPC = 8 }

[Serialize("", IsPropertySaveable.Yes, description: "What criteria to use to select the entities to target. Valid values are players, player, traitor, nontraitor, nontraitorplayer, bot, crew, humanprefabidentifier:[id], jobidentifier:[id], structureidentifier:[id], structurespecialtag:[tag], itemidentifier:[id], itemtag:[tag], hull, hullname:[name], submarine:[type], eventtag:[tag].")]
[Serialize("", IsPropertySaveable.Yes, description: "What criteria to use to select the entities to target. Valid values are players, player, traitor, nontraitor, nontraitorplayer, bot, crew, humanprefabidentifier:[id], jobidentifier:[id], structureidentifier:[id], structurespecialtag:[tag], itemidentifier:[id], itemtag:[tag], hull, hullname:[name], submarine:[type], eventtag:[tag], speciesname:[id].")]
public string Criteria { get; set; }

[Serialize("", IsPropertySaveable.Yes, description: "The tag to apply to the target.")]
Expand All @@ -22,6 +23,9 @@ public enum SubType { Any = 0, Player = 1, Outpost = 2, Wreck = 4, BeaconStation
[Serialize(SubType.Any, IsPropertySaveable.Yes, description: "The type of submarine the target needs to be in.")]
public SubType SubmarineType { get; set; }

[Serialize(CharacterTeam.Any, IsPropertySaveable.Yes, description: "The team the target needs to be on.")]
public CharacterTeam Team { get; set; }

[Serialize("", IsPropertySaveable.Yes, "If set, the target must be in an outpost module that has this tag.")]
public Identifier RequiredModuleTag { get; set; }

Expand Down Expand Up @@ -77,6 +81,7 @@ public TagAction(ScriptedEvent parentEvent, ContentXElement element) : base(pare
("hullname", TagHullsByName),
("submarine", TagSubmarinesByType),
("eventtag", TagByEventTag),
("speciesname", TagBySpeciesName)
}.Select(t => (t.k.ToIdentifier(), t.v)).ToImmutableDictionary();
}

Expand All @@ -89,6 +94,11 @@ public override void Reset()
isFinished = false;
}

private void TagBySpeciesName(Identifier speciesName)
{
AddTarget(Tag, Character.CharacterList.Where(c => c.SpeciesName == speciesName && CharacterTeamMatches(c)));
}

private void TagByEventTag(Identifier eventTag)
{
AddTarget(Tag, ParentEvent.GetTargets(eventTag).Where(t => MatchesRequirements(t)));
Expand All @@ -99,7 +109,7 @@ private void TagPlayers()
AddTargetPredicate(
Tag,
ScriptedEvent.TargetPredicate.EntityType.Character,
e => e is Character c && c.IsPlayer && (!c.IsIncapacitated || !IgnoreIncapacitatedCharacters));
e => e is Character c && c.IsPlayer && (!c.IsIncapacitated || !IgnoreIncapacitatedCharacters) && CharacterTeamMatches(c));
}

private void TagTraitors()
Expand Down Expand Up @@ -150,12 +160,12 @@ private void TagCrew()

private void TagHumansByIdentifier(Identifier identifier)
{
AddTarget(Tag, Character.CharacterList.Where(c => c.HumanPrefab?.Identifier == identifier));
AddTarget(Tag, Character.CharacterList.Where(c => c.HumanPrefab?.Identifier == identifier && CharacterTeamMatches(c)));
}

private void TagHumansByJobIdentifier(Identifier jobIdentifier)
{
AddTarget(Tag, Character.CharacterList.Where(c => c.HasJob(jobIdentifier)));
AddTarget(Tag, Character.CharacterList.Where(c => c.HasJob(jobIdentifier) && CharacterTeamMatches(c)));
}

private void TagStructuresByIdentifier(Identifier identifier)
Expand Down Expand Up @@ -260,6 +270,23 @@ private bool ModuleTagMatches(Entity e)
return hull != null && hull.OutpostModuleTags.Contains(RequiredModuleTag);
}

private bool CharacterTeamMatches(Character character)
{
if (Team == CharacterTeam.Any) { return true; }
switch (Team)
{
case CharacterTeam.None:
return character.TeamID == CharacterTeamType.None;
case CharacterTeam.Team1:
return character.TeamID == CharacterTeamType.Team1;
case CharacterTeam.Team2:
return character.TeamID == CharacterTeamType.Team2;
case CharacterTeam.FriendlyNPC:
return character.TeamID == CharacterTeamType.FriendlyNPC;
default:
return false;
}
}

private bool SubmarineTypeMatches(Submarine sub)
{
Expand All @@ -281,6 +308,10 @@ public static bool SubmarineTypeMatches(Submarine sub, SubType submarineType)
return submarineType.HasFlag(SubType.Wreck);
case Barotrauma.SubmarineType.BeaconStation:
return submarineType.HasFlag(SubType.BeaconStation);
case Barotrauma.SubmarineType.EnemySubmarine:
return submarineType.HasFlag(SubType.Enemy);
case Barotrauma.SubmarineType.Ruin:
return submarineType.HasFlag(SubType.Ruin);
default:
return false;
}
Expand Down Expand Up @@ -407,7 +438,7 @@ public override void Update(float deltaTime)

public override string ToDebugString()
{
return $"{ToolBox.GetDebugSymbol(isFinished)} {nameof(TagAction)} -> (Criteria: {Criteria.ColorizeObject()}, Tag: {Tag.ColorizeObject()}, Sub: {SubmarineType.ColorizeObject()})";
return $"{ToolBox.GetDebugSymbol(isFinished)} {nameof(TagAction)} -> (Criteria: {Criteria.ColorizeObject()}, Tag: {Tag.ColorizeObject()}, Sub: {SubmarineType.ColorizeObject()}, Team: {Team.ColorizeObject()})";
}
}
}