Skip to content

Commit

Permalink
ReactiveTeleportArmorRD (SerbiaStrong-220#1802)
Browse files Browse the repository at this point in the history
* NeSMOTRET'

* x2

* ewe chyt' chyt' u ya ymry

* pochti!!!

* Spriteri RABOTAT'

* ChanceFix

* DexRev

* kto prochital tot sdox

* microfix

* ache)

* hz

* gnomaLoxGonaLust)

* cheki

* probel

* probel2

* cheki

* Update Resources/Locale/ru-RU/ss220/prototypes/entities/clothing/outerclothing/reactivearmor.ftl

Co-authored-by: Ady4ik <141335742+Ady4ik@users.noreply.github.com>

* Update Resources/Prototypes/Catalog/Fills/Lockers/heads.yml

Co-authored-by: Ady4ik <141335742+Ady4ik@users.noreply.github.com>

* fix typosti

* NASRANO

---------

Co-authored-by: Ady4ik <141335742+Ady4ik@users.noreply.github.com>
  • Loading branch information
21Melkuu and Ady4ik authored Oct 4, 2024
1 parent 3045660 commit 60ad045
Show file tree
Hide file tree
Showing 19 changed files with 354 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.tx
namespace Content.Server.SS220.ReactiveTeleportArmor
{
/// <summary>
/// Intermediate component to work with TeleportOnDamageComponent
/// </summary>
[RegisterComponent]
public sealed partial class ReactiveTeleportArmorComponent : Component
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
using Robust.Shared.Random;
using Content.Shared.Damage;
using Content.Shared.Movement.Pulling.Systems;
using Content.Shared.Movement.Pulling.Components;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Map.Components;
using System.Numerics;
using Content.Shared.Physics;
using Robust.Shared.Collections;
using Content.Shared.Clothing;
using Content.Shared.Clothing.EntitySystems;
using Content.Server.Explosion.EntitySystems;
using Content.Shared.Item;
using Content.Shared.Item.ItemToggle;
using Content.Shared.Item.ItemToggle.Components;
using Content.Shared.Timing;
using Timer = Robust.Shared.Timing.Timer;

namespace Content.Server.SS220.ReactiveTeleportArmor
{
internal class ReactiveTeleportArmorSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedTransformSystem _xform = default!;
[Dependency] private readonly PullingSystem _pullingSystem = default!;
[Dependency] private readonly EntityLookupSystem _lookupSystem = default!;
[Dependency] private readonly SharedMapSystem _mapSystem = default!;
[Dependency] private readonly ExplosionSystem _explosion = default!;
[Dependency] private readonly SharedItemSystem _item = default!;
[Dependency] private readonly ClothingSystem _clothing = default!;
[Dependency] private readonly ItemToggleSystem _toggle = default!;

private EntityQuery<PhysicsComponent> _physicsQuery;
private HashSet<Entity<MapGridComponent>> _targetGrids = [];

public override void Initialize()
{
_physicsQuery = GetEntityQuery<PhysicsComponent>();

base.Initialize();
SubscribeLocalEvent<TeleportOnDamageComponent, DamageChangedEvent>(TeleporWhenDamaged);
SubscribeLocalEvent<ReactiveTeleportArmorComponent, ClothingGotEquippedEvent>(OnEquip);
SubscribeLocalEvent<ReactiveTeleportArmorComponent, ClothingGotUnequippedEvent>(OnUnequip);
SubscribeLocalEvent<ReactiveTeleportArmorComponent, ItemToggledEvent>(ToggleDone);
}

private void OnEquip(Entity<ReactiveTeleportArmorComponent> ent, ref ClothingGotEquippedEvent args)
{
EnsureComp<TeleportOnDamageComponent>(args.Wearer, out var comp);
comp.SavedUid = ent;
}

private void OnUnequip(Entity<ReactiveTeleportArmorComponent> ent, ref ClothingGotUnequippedEvent args)
{
RemComp<TeleportOnDamageComponent>(args.Wearer);
}

private void ToggleDone(Entity<ReactiveTeleportArmorComponent> ent, ref ItemToggledEvent args)
{
var prefix = args.Activated ? "on" : null;
_item.SetHeldPrefix(ent, prefix);
_clothing.SetEquippedPrefix(ent, prefix);
}


private void TeleporWhenDamaged(Entity<TeleportOnDamageComponent> ent, ref DamageChangedEvent args)
{
if (!TryComp<TeleportOnDamageComponent>(ent, out var armor))
return;

var xform = Transform(ent.Owner);
var targetCoords = SelectRandomTileInRange(xform, armor.TeleportRadius);

if (!args.DamageIncreased || args.DamageDelta == null)
return;
///teleport entity if taken damage && coord = !null && armor is on && !cooldown
if (args.DamageDelta.GetTotal() >= ent.Comp.WakeThreshold && targetCoords != null && _toggle.IsActivated(ent.Comp.SavedUid) && !ent.Comp.OnCoolDown)
{
ent.Comp.OnCoolDown = true;

// We need stop the user from being pulled so they don't just get "attached" with whoever is pulling them.
// This can for example happen when the user is cuffed and being pulled.
if (TryComp<PullableComponent>(ent.Owner, out var pull) && _pullingSystem.IsPulled(ent.Owner, pull))
_pullingSystem.TryStopPull(ent.Owner, pull);

if (_random.Prob(ent.Comp.TeleportChance))
{
_xform.SetCoordinates(ent.Owner, targetCoords.Value);
_audio.PlayPvs(armor.TeleportSound, ent.Owner);
SelectRandomTileInRange(xform, armor.TeleportRadius);
}
else
{
_explosion.TriggerExplosive(ent.Comp.SavedUid);
}
Timer.Spawn(ent.Comp.CoolDownTime, () => ent.Comp.OnCoolDown = false);
}
}

private EntityCoordinates? SelectRandomTileInRange(TransformComponent userXform, float radius)
{
var userCoords = userXform.Coordinates.ToMap(EntityManager, _xform);
_targetGrids.Clear();
_lookupSystem.GetEntitiesInRange(userCoords, radius, _targetGrids);
Entity<MapGridComponent>? targetGrid = null;

if (_targetGrids.Count == 0)
return null;

// Give preference to the grid the entity is currently on.
// This does not guarantee that if the probability fails that the owner's grid won't be picked.
// In reality the probability is higher and depends on the number of grids.
if (userXform.GridUid != null && TryComp<MapGridComponent>(userXform.GridUid, out var gridComp))
{
var userGrid = new Entity<MapGridComponent>(userXform.GridUid.Value, gridComp);
if (_random.Prob(0.5f))
{
_targetGrids.Remove(userGrid);
targetGrid = userGrid;
}
}

if (targetGrid == null)
targetGrid = _random.GetRandom().PickAndTake(_targetGrids);

EntityCoordinates? targetCoords = null;

var valid = false;

var range = (float)Math.Sqrt(radius);
var box = Box2.CenteredAround(userCoords.Position, new Vector2(range, range));
var tilesInRange = _mapSystem.GetTilesEnumerator(targetGrid.Value.Owner, targetGrid.Value.Comp, box, false);
var tileList = new ValueList<Vector2i>();

while (tilesInRange.MoveNext(out var tile))
{
tileList.Add(tile.GridIndices);
}

while (tileList.Count != 0)
{
var tile = tileList.RemoveSwap(_random.Next(tileList.Count));
valid = true;
foreach (var entity in _mapSystem.GetAnchoredEntities(targetGrid.Value.Owner, targetGrid.Value.Comp,
tile))
{
if (!_physicsQuery.TryGetComponent(entity, out var body))
continue;

if (body.BodyType != BodyType.Static ||
!body.Hard ||
(body.CollisionLayer & (int)CollisionGroup.MobMask) == 0)
continue;

valid = false;
break;
}

if (valid)
{
targetCoords = new EntityCoordinates(targetGrid.Value.Owner,
_mapSystem.TileCenterToVector(targetGrid.Value, tile));
break;
}
}

if (!valid || _targetGrids.Count != 0) // if we don't do the check here then PickAndTake will blow up on an empty set.
targetGrid = _random.GetRandom().PickAndTake(_targetGrids);

return targetCoords;

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt

using Robust.Shared.Audio;
using Content.Shared.FixedPoint;

namespace Content.Server.SS220.ReactiveTeleportArmor;

/// <summary>
/// Randomly teleports entity when damaged.
/// </summary>
[RegisterComponent]
public sealed partial class TeleportOnDamageComponent : Component
{
/// <summary>
/// Up to how far to teleport the user
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float TeleportRadius = 50f;

[DataField, ViewVariables(VVAccess.ReadWrite)]
public SoundSpecifier TeleportSound = new SoundPathSpecifier("/Audio/Effects/teleport_arrival.ogg");

/// <summary>
/// How much damage of any type it takes to wake this entity.
/// </summary>
[DataField]
public FixedPoint2 WakeThreshold = FixedPoint2.New(4);

[DataField, ViewVariables(VVAccess.ReadWrite)]
public float TeleportChance = .9f;

/// <summary>
/// Need if you want to interact with the entity that provided the TeleportOnDamageComponent.
/// </summary>
[ViewVariables]
public EntityUid SavedUid;

public bool OnCoolDown = false;

[DataField]
public TimeSpan CoolDownTime = TimeSpan.FromSeconds(10);
}


3 changes: 3 additions & 0 deletions Resources/Locale/ru-RU/ss220/clothing/OuterClothing/armor.ftl
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
ent-ClothingOuterArmorCentcomNavalCarapace = флотский панцирь
.desc = Панцирь, который носят офицеры Командования флота.
ent-ClothingOuterReactiveArmor = экспериментальная реактивная броня
.desc = Новейший прототип брони, основанный на ядре аномалии. Ходят слухи, что учёные NT разрабатывают более стабильную и многозадачную версию.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
toggle-reactivearmor-verb-get-data-text = Переключить реактивную броню
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ steal-target-groups-wrist-watch-gold = наручные часы командо
steal-target-groups-expensive-lighter-syndicate = { ent-ExpensiveLighterSyndicate }
steal-target-groups-expensive-lighter-nanotrasen = { ent-ExpensiveLighterNanotrasen }
steal-target-groups-expensive-lighter-shield = { ent-ExpensiveLighterShield }
steal-target-groups-expensive-lighter-detective = { ent-ExpensiveLighterDetective }
steal-target-groups-expensive-lighter-detective = { ent-ExpensiveLighterDetective }
steal-target-groups-reactive-armor = { ent-ClothingOuterReactiveArmor }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ent-ActionToggleReactiveArmor = Переключить реактивную броню
.desc = Включает или выключает реактивную броню.
3 changes: 2 additions & 1 deletion Resources/Prototypes/Catalog/Fills/Lockers/heads.yml
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@
- id: ClothingWristWatchGold # SS220 Wrist Watch
- id: Telescopichka # SS220 Telescopic Baton
- id: CigPackRnD #SS220 Cigarettes
- id: ClothingOuterReactiveArmor #SS220 New RD highrisk

# Hardsuit table, used for suit storage as well
- type: entityTable
Expand Down Expand Up @@ -402,4 +403,4 @@
- id: JetpackBlue
- id: SpaceCash1000
- id: BeachBall
- id: BikeHorn
- id: BikeHorn
1 change: 1 addition & 0 deletions Resources/Prototypes/Objectives/objectiveGroups.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
EngravedKnuckledusterStealObjective: 1 #SS220 New Qm highrisk
CaptainGunStealObjective: 0.5
CaptainJetpackStealObjective: 0.5
ClothingOuterReactiveArmorObjective: 0.5 #SS220 New RD highrisk
HandTeleporterStealObjective: 0.5
SecretDocumentsStealObjective: 0.5
MultiPhaseEnergyGunStealObjective: 0.5 #SS220 MultiPhaze Energy Gun
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
- type: entity
parent: [ClothingOuterBaseLarge, AllowSuitStorageClothing, BaseToggleClothing]
id: ClothingOuterReactiveArmor
name: experimental reactive armor
description: The latest armor prototype based on the anomaly core. There are rumors that NT scientists are developing a more stable and multitasking version.
components:
- type: Sprite
sprite: SS220/Clothing/OuterClothing/Armor/reactive_armor.rsi
layers:
- state: icon
map: [ "enum.ToggleVisuals.Layer" ]
- type: Clothing
sprite: SS220/Clothing/OuterClothing/Armor/reactive_armor.rsi
- type: Appearance
- type: GenericVisualizer
visuals:
enum.ToggleVisuals.Toggled:
enum.ToggleVisuals.Layer:
True: {state: icon-on}
False: {state: icon}
- type: Armor
modifiers:
coefficients:
Blunt: 0.5
Slash: 0.5
Piercing: 0.6
Heat: 0.5
Caustic: 0.9
- type: HeldSpeedModifier
- type: ToggleClothing
action: ActionToggleReactiveArmor
- type: ToggleVerb
text: toggle-reactivearmor-verb-get-data-text
- type: GroupExamine
- type: ReactiveTeleportArmor
- type: Explosive
explosionType: Default
maxIntensity: 2
totalIntensity: 1.5
intensitySlope: 1
canCreateVacuum: false
deleteAfterExplosion: false
repeatable: true
- type: Tag
tags:
- HighRiskItem

- type: entity
id: ActionToggleReactiveArmor
name: Toggle Reactive armor
description: Toggles the armor on and off.
components:
- type: InstantAction
useDelay: 5
priority: -9
itemIconStyle: BigItem
event: !type:ToggleActionEvent
9 changes: 8 additions & 1 deletion Resources/Prototypes/SS220/Objectives/stealTargetGroups.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
state: icon

- type: stealTargetGroup
id: ClothingOuterReactiveArmor
name: steal-target-groups-reactive-armor
sprite:
sprite: SS220/Clothing/OuterClothing/Armor/reactive_armor.rsi
state: icon

- type: stealTargetGroup
id: WristWatchGold
name: steal-target-groups-wrist-watch-gold
sprite:
Expand Down Expand Up @@ -60,4 +67,4 @@
name: steal-target-groups-salvage-shuttle-console-board
sprite:
sprite: Objects/Misc/module.rsi
state: cpuboard
state: cpuboard
10 changes: 10 additions & 0 deletions Resources/Prototypes/SS220/Objectives/traitor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@
- type: StealCondition
stealGroup: WeaponMultiPhaseEnergyGun
owner: job-name-hos

- type: entity
parent: BaseTraitorStealObjective
id: ClothingOuterReactiveArmorObjective
components:
- type: NotJobRequirement
job: ResearchDirector
- type: StealCondition
stealGroup: ClothingOuterReactiveArmor
owner: job-name-rd
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 60ad045

Please sign in to comment.