Nerf ninja research stealing (#26421)
* nerf ninja steal objective * fubar
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
using Content.Shared.Research.Components;
|
using Content.Shared.Research.Components;
|
||||||
using Content.Shared.Research.Systems;
|
using Content.Shared.Research.Systems;
|
||||||
|
using Robust.Shared.Random;
|
||||||
|
|
||||||
namespace Content.Server.Research.Systems;
|
namespace Content.Server.Research.Systems;
|
||||||
|
|
||||||
public sealed class ResearchStealerSystem : SharedResearchStealerSystem
|
public sealed class ResearchStealerSystem : SharedResearchStealerSystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly SharedResearchSystem _research = default!;
|
[Dependency] private readonly SharedResearchSystem _research = default!;
|
||||||
|
[Dependency] private readonly IRobustRandom _random = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
@@ -24,16 +26,26 @@ public sealed class ResearchStealerSystem : SharedResearchStealerSystem
|
|||||||
if (!TryComp<TechnologyDatabaseComponent>(target, out var database))
|
if (!TryComp<TechnologyDatabaseComponent>(target, out var database))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var ev = new ResearchStolenEvent(uid, target, database.UnlockedTechnologies);
|
var ev = new ResearchStolenEvent(uid, target, new());
|
||||||
|
var count = _random.Next(comp.MinToSteal, comp.MaxToSteal + 1);
|
||||||
|
for (var i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
if (database.UnlockedTechnologies.Count == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
var toRemove = _random.Pick(database.UnlockedTechnologies);
|
||||||
|
if (_research.TryRemoveTechnology((target, database), toRemove))
|
||||||
|
ev.Techs.Add(toRemove);
|
||||||
|
}
|
||||||
RaiseLocalEvent(uid, ref ev);
|
RaiseLocalEvent(uid, ref ev);
|
||||||
// oops, no more advanced lasers!
|
|
||||||
_research.ClearTechs(target, database);
|
args.Handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Event raised on the user when research is stolen from a R&D server.
|
/// Event raised on the user when research is stolen from a RND server.
|
||||||
/// Techs contains every technology id researched.
|
/// Techs contains every technology id researched.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ByRefEvent]
|
[ByRefEvent]
|
||||||
public record struct ResearchStolenEvent(EntityUid Used, EntityUid Target, List<String> Techs);
|
public record struct ResearchStolenEvent(EntityUid Used, EntityUid Target, List<string> Techs);
|
||||||
|
|||||||
@@ -14,4 +14,16 @@ public sealed partial class ResearchStealerComponent : Component
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("delay"), ViewVariables(VVAccess.ReadWrite)]
|
[DataField("delay"), ViewVariables(VVAccess.ReadWrite)]
|
||||||
public TimeSpan Delay = TimeSpan.FromSeconds(20);
|
public TimeSpan Delay = TimeSpan.FromSeconds(20);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The minimum number of technologies that will be stolen
|
||||||
|
/// </summary>
|
||||||
|
[DataField]
|
||||||
|
public int MinToSteal = 4;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The maximum number of technologies that will be stolen
|
||||||
|
/// </summary>
|
||||||
|
[DataField]
|
||||||
|
public int MaxToSteal = 8;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Content.Shared.Research.Components;
|
using Content.Shared.Research.Components;
|
||||||
using Content.Shared.Research.Prototypes;
|
using Content.Shared.Research.Prototypes;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
@@ -219,16 +220,58 @@ public abstract class SharedResearchSystem : EntitySystem
|
|||||||
if (!Resolve(uid, ref component))
|
if (!Resolve(uid, ref component))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var discipline = PrototypeManager.Index<TechDisciplinePrototype>(prototype.Discipline);
|
var discipline = PrototypeManager.Index(prototype.Discipline);
|
||||||
if (prototype.Tier < discipline.LockoutTier)
|
if (prototype.Tier < discipline.LockoutTier)
|
||||||
return;
|
return;
|
||||||
component.MainDiscipline = prototype.Discipline;
|
component.MainDiscipline = prototype.Discipline;
|
||||||
Dirty(uid, component);
|
Dirty(uid, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes a technology and its recipes from a technology database.
|
||||||
|
/// </summary>
|
||||||
|
public bool TryRemoveTechnology(Entity<TechnologyDatabaseComponent> entity, ProtoId<TechnologyPrototype> tech)
|
||||||
|
{
|
||||||
|
return TryRemoveTechnology(entity, PrototypeManager.Index(tech));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes a technology and its recipes from a technology database.
|
||||||
|
/// </summary>
|
||||||
|
[PublicAPI]
|
||||||
|
public bool TryRemoveTechnology(Entity<TechnologyDatabaseComponent> entity, TechnologyPrototype tech)
|
||||||
|
{
|
||||||
|
if (!entity.Comp.UnlockedTechnologies.Remove(tech.ID))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// check to make sure we didn't somehow get the recipe from another tech.
|
||||||
|
// unlikely, but whatever
|
||||||
|
var recipes = tech.RecipeUnlocks;
|
||||||
|
foreach (var recipe in recipes)
|
||||||
|
{
|
||||||
|
var hasTechElsewhere = false;
|
||||||
|
foreach (var unlockedTech in entity.Comp.UnlockedTechnologies)
|
||||||
|
{
|
||||||
|
var unlockedTechProto = PrototypeManager.Index<TechnologyPrototype>(unlockedTech);
|
||||||
|
|
||||||
|
if (!unlockedTechProto.RecipeUnlocks.Contains(recipe))
|
||||||
|
continue;
|
||||||
|
hasTechElsewhere = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasTechElsewhere)
|
||||||
|
entity.Comp.UnlockedRecipes.Remove(recipe);
|
||||||
|
}
|
||||||
|
Dirty(entity, entity.Comp);
|
||||||
|
UpdateTechnologyCards(entity, entity);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clear all unlocked technologies from the database.
|
/// Clear all unlocked technologies from the database.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[PublicAPI]
|
||||||
public void ClearTechs(EntityUid uid, TechnologyDatabaseComponent? comp = null)
|
public void ClearTechs(EntityUid uid, TechnologyDatabaseComponent? comp = null)
|
||||||
{
|
{
|
||||||
if (!Resolve(uid, ref comp) || comp.UnlockedTechnologies.Count == 0)
|
if (!Resolve(uid, ref comp) || comp.UnlockedTechnologies.Count == 0)
|
||||||
|
|||||||
@@ -39,8 +39,8 @@
|
|||||||
sprite: Structures/Machines/server.rsi
|
sprite: Structures/Machines/server.rsi
|
||||||
state: server
|
state: server
|
||||||
- type: NumberObjective
|
- type: NumberObjective
|
||||||
min: 5
|
min: 9
|
||||||
max: 10
|
max: 13
|
||||||
title: objective-condition-steal-research-title
|
title: objective-condition-steal-research-title
|
||||||
- type: StealResearchCondition
|
- type: StealResearchCondition
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user