Tesla (#21124)
* upload all textures
finished easiest part - TeslaGenerator
* Added Tesla energy logic
* add lightning pulse priority
* work
* optimise lightning arc system
* now tesla moving to LightningTarget entity and consume it
* some audio work
add airlock and computers to the LightningTarget
* add nice visual and explosions
add crashing to game
* rsi meta fix
* disabling explosions (crashing server)
I'll get back to that problem later.
* adding important admin logging
* a little bit of cleaning and documentation
* Persistent attempts to fix the server crashing on explosions. Accidental cleaning of everything I see.
* now the tesla incinerates everything it touches except the containment field.
* colliders work
* fix falling tesla on ground after being exploded
* add consume sound, add spawn and collapses sound
* added TeslaGenerator to cargo trading console
* add all tesla part to cargo trading console
* Tesla coils: Turn on and off, get energy from lightning, give energy to the grid.
* tesla coil is ready
* tesla grounding rod is ready
* clean up
* clean up 2
* grounding rods now working without power
* add LightningResistance parameter for LightningTarget Component
* add chaotic teleport
* eletrocution remove?
* deltanedas fix pack
* more fixes
* FIXES
* FIIIXEEES
* The "Grounding Rod" component is removed, and replaced with "LightiningSparking", which is responsible for changing the visuals when hit by lightning. Duplicate code from the coil is removed.
* ops
* fix
* nah, is escaped anyway
* increase tesla collider size
* keron bb
* try fix test?
* fix
* bruh
* check turn off sus comp
* prototype cleaning
* FIIX
* return and fix sus component
* fix tesla eating lightnings, now mini tesla is electrocuted
* commented some issues
* remove linq sorting
fix jumping system
minor fixes
* fix second Linq
* fix tesla colliders! Yeah, it works
* fix componentregistration
* Just retests
* not fix
* FIX TESLA
* fixes
* store targets
* back
* make dictionary of hashsets
* some sloth fixes
* stump
* playtest balance energy generation, return to unpotimized (but working) lightning shoot
* parity
* work on
* some new fix, some new bug (chasingComponent not chasing)
* comment
* fix ChasingWalkSystem
* fix collider tesla problem
* revert old unoptimized shoot lightning
* new fix pack
---------
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
2023-12-28 16:11:50 +03:00
using System.Linq ;
using System.Numerics ;
using Content.Server.Physics.Components ;
using Robust.Shared.Random ;
using Robust.Shared.Timing ;
using Robust.Shared.Physics.Systems ;
using Robust.Shared.Physics.Components ;
using Robust.Shared.Physics.Controllers ;
namespace Content.Server.Physics.Controllers ;
/// <summary>
/// A system which makes its entity chasing another entity with selected component.
/// </summary>
public sealed class ChasingWalkSystem : VirtualController
{
[Dependency] private readonly IGameTiming _gameTiming = default ! ;
[Dependency] private readonly IRobustRandom _random = default ! ;
[Dependency] private readonly SharedTransformSystem _transform = default ! ;
[Dependency] private readonly EntityLookupSystem _lookup = default ! ;
[Dependency] private readonly SharedPhysicsSystem _physics = default ! ;
private readonly HashSet < Entity < IComponent > > _potentialChaseTargets = new ( ) ;
public override void Initialize ( )
{
base . Initialize ( ) ;
SubscribeLocalEvent < ChasingWalkComponent , MapInitEvent > ( OnChasingMapInit ) ;
}
private void OnChasingMapInit ( EntityUid uid , ChasingWalkComponent component , MapInitEvent args )
{
component . NextImpulseTime = _gameTiming . CurTime ;
component . NextChangeVectorTime = _gameTiming . CurTime ;
}
public override void UpdateBeforeSolve ( bool prediction , float frameTime )
{
base . UpdateBeforeSolve ( prediction , frameTime ) ;
var query = EntityQueryEnumerator < ChasingWalkComponent > ( ) ;
while ( query . MoveNext ( out var uid , out var chasing ) )
{
//Set Velocity to Target
if ( chasing . NextImpulseTime < = _gameTiming . CurTime )
{
ForceImpulse ( uid , chasing ) ;
chasing . NextImpulseTime + = TimeSpan . FromSeconds ( chasing . ImpulseInterval ) ;
}
//Change Target
if ( chasing . NextChangeVectorTime < = _gameTiming . CurTime )
{
ChangeTarget ( uid , chasing ) ;
var delay = TimeSpan . FromSeconds ( _random . NextFloat ( chasing . ChangeVectorMinInterval , chasing . ChangeVectorMaxInterval ) ) ;
chasing . NextChangeVectorTime + = delay ;
}
}
}
private void ChangeTarget ( EntityUid uid , ChasingWalkComponent component )
{
//We find our coordinates and calculate the radius of the target search.
var xform = Transform ( uid ) ;
var range = component . MaxChaseRadius ;
var compType = _random . Pick ( component . ChasingComponent . Values ) . Component . GetType ( ) ;
_potentialChaseTargets . Clear ( ) ;
_lookup . GetEntitiesInRange ( compType , _transform . GetMapCoordinates ( xform ) , range , _potentialChaseTargets , LookupFlags . Uncontained ) ;
//If there are no required components in the radius, don't moving.
if ( _potentialChaseTargets . Count < = 0 )
return ;
//In the case of finding required components, we choose a random one of them and remember its uid.
component . ChasingEntity = _random . Pick ( _potentialChaseTargets ) . Owner ;
component . Speed = _random . NextFloat ( component . MinSpeed , component . MaxSpeed ) ;
}
//pushing the entity toward its target
private void ForceImpulse ( EntityUid uid , ChasingWalkComponent component )
{
if ( Deleted ( component . ChasingEntity ) | | component . ChasingEntity = = null )
{
ChangeTarget ( uid , component ) ;
return ;
}
if ( ! TryComp < PhysicsComponent > ( uid , out var physics ) )
return ;
//Calculating direction to the target.
var pos1 = _transform . GetWorldPosition ( uid ) ;
var pos2 = _transform . GetWorldPosition ( component . ChasingEntity . Value ) ;
var delta = pos2 - pos1 ;
var speed = delta . Length ( ) > 0 ? delta . Normalized ( ) * component . Speed : Vector2 . Zero ;
_physics . SetLinearVelocity ( uid , speed ) ;
2024-03-25 02:37:25 -04:00
_physics . SetBodyStatus ( uid , physics , BodyStatus . InAir ) ; //If this is not done, from the explosion up close, the tesla will "Fall" to the ground, and almost stop moving.
Tesla (#21124)
* upload all textures
finished easiest part - TeslaGenerator
* Added Tesla energy logic
* add lightning pulse priority
* work
* optimise lightning arc system
* now tesla moving to LightningTarget entity and consume it
* some audio work
add airlock and computers to the LightningTarget
* add nice visual and explosions
add crashing to game
* rsi meta fix
* disabling explosions (crashing server)
I'll get back to that problem later.
* adding important admin logging
* a little bit of cleaning and documentation
* Persistent attempts to fix the server crashing on explosions. Accidental cleaning of everything I see.
* now the tesla incinerates everything it touches except the containment field.
* colliders work
* fix falling tesla on ground after being exploded
* add consume sound, add spawn and collapses sound
* added TeslaGenerator to cargo trading console
* add all tesla part to cargo trading console
* Tesla coils: Turn on and off, get energy from lightning, give energy to the grid.
* tesla coil is ready
* tesla grounding rod is ready
* clean up
* clean up 2
* grounding rods now working without power
* add LightningResistance parameter for LightningTarget Component
* add chaotic teleport
* eletrocution remove?
* deltanedas fix pack
* more fixes
* FIXES
* FIIIXEEES
* The "Grounding Rod" component is removed, and replaced with "LightiningSparking", which is responsible for changing the visuals when hit by lightning. Duplicate code from the coil is removed.
* ops
* fix
* nah, is escaped anyway
* increase tesla collider size
* keron bb
* try fix test?
* fix
* bruh
* check turn off sus comp
* prototype cleaning
* FIIX
* return and fix sus component
* fix tesla eating lightnings, now mini tesla is electrocuted
* commented some issues
* remove linq sorting
fix jumping system
minor fixes
* fix second Linq
* fix tesla colliders! Yeah, it works
* fix componentregistration
* Just retests
* not fix
* FIX TESLA
* fixes
* store targets
* back
* make dictionary of hashsets
* some sloth fixes
* stump
* playtest balance energy generation, return to unpotimized (but working) lightning shoot
* parity
* work on
* some new fix, some new bug (chasingComponent not chasing)
* comment
* fix ChasingWalkSystem
* fix collider tesla problem
* revert old unoptimized shoot lightning
* new fix pack
---------
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
2023-12-28 16:11:50 +03:00
}
}