2019-10-11 16:57:16 -04:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using Content.Server.GameObjects.Components.Mobs;
|
Bodysystem and damagesystem rework (#1544)
* Things and stuff with grids, unfinished w/ code debug changes.
* Updated submodule and also lost some progress cause I fucked it up xd
* First unfinished draft of the BodySystem. Doesn't compile.
* More changes to make it compile, but still just a framework. Doesn't do anything at the moment.
* Many cleanup changes.
* Revert "Merge branch 'master' of https://github.com/GlassEclipse/space-station-14 into body_system"
This reverts commit ddd4aebbc76cf2a0b7b102f72b93d55a0816c88c, reversing
changes made to 12d0dd752706bdda8879393bd8191a1199a0c978.
* Commit human.yml
* Updated a lot of things to be more classy, more progress overall, etc. etc.
* Latest update with many changes
* Minor changes
* Fixed Travis build bug
* Adds first draft of Body Scanner console, apparently I also forgot to tie Mechanisms into body parts so now a heart just sits in the Torso like a good boy :)
* Commit rest of stuff
* Latest changes
* Latest changes again
* 14 naked cowboys
* Yay!
* Latest changes (probably doesnt compile)
* Surgery!!!!!!!!!~1116y
* Cleaned some stuff up
* More cleanup
* Refactoring of code. Basic surgery path now done.
* Removed readme, has been added to HackMD
* Fixes typo (and thus test errors)
* WIP changes, committing so I can pull latest master changes
* Still working on that god awful merge
* Latest changes
* Latest changes!!
* Beginning of refactor to BoundUserInterface
* Surgery!
* Latest changes - fixes pr change requests and random fixes
* oops
* Fixes bodypart recursion
* Beginning of work on revamping the damage system.
* More latest changes
* Latest changes
* Finished merge
* Commit before removing old healthcode
* Almost done with removing speciescomponent...
* It compiles!!!
* yahoo more work
* Fixes to make it work
* Merge conflict fixes
* Deleting species visualizer was a mistake
* IDE warnings are VERBOTEN
* makes the server not kill itself on startup, some cleanup (#1)
* Namespaces, comments and exception fixes
* Fix conveyor and conveyor switch serialization
SS14 in reactive when
* Move damage, acts and body to shared
Damage cleanup
Comment cleanup
* Rename SpeciesComponent to RotationComponent and cleanup
Damage cleanup
Comment cleanup
* Fix nullable warnings
* Address old reviews
Fix off welder suicide damage type, deathmatch and suspicion
* Fix new test fail with units being able to accept items when unpowered
* Remove RotationComponent, change references to IBodyManagerComponent
* Add a bloodstream to humans
* More cleanups
* Add body conduits, connections, connectors substances and valves
* Revert "Add body conduits, connections, connectors substances and valves"
This reverts commit 9ab0b50e6b15fe98852d7b0836c0cdbf4bd76d20.
* Implement the heart mechanism behavior with the circulatory network
* Added network property to mechanism behaviors
* Changed human organ sprites and added missing ones
* Fix tests
* Add individual body part sprite rendering
* Fix error where dropped mechanisms are not initialized
* Implement client/server body damage
* Make DamageContainer take care of raising events
* Reimplement medical scanner with the new body system
* Improve the medical scanner ui
* Merge conflict fixes
* Fix crash when colliding with something
* Fix microwave suicides and eyes sprite rendering
* Fix nullable reference error
* Fix up surgery client side
* Fix missing using from merge conflict
* Add breathing
*inhale
* Merge conflict fixes
* Fix accumulatedframetime being reset to 0 instead of decreased by the threshold
https://github.com/space-wizards/space-station-14/pull/1617
* Use and add to the new AtmosHelpers
* Fix feet
* Add proper coloring to dropped body parts
* Fix Urist's lungs being too strong
* Merge conflict fixes
* Merge conflict fixes
* Merge conflict fixes
Co-authored-by: GlassEclipse <tsymall5@gmail.com>
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
Co-authored-by: AJCM-git <60196617+AJCM-git@users.noreply.github.com>
2020-08-17 01:42:42 +02:00
|
|
|
|
using Content.Shared.GameObjects.EntitySystems;
|
2019-10-11 16:57:16 -04:00
|
|
|
|
using Content.Shared.Maps;
|
|
|
|
|
|
using Robust.Server.GameObjects.EntitySystems;
|
|
|
|
|
|
using Robust.Server.Interfaces.GameObjects;
|
|
|
|
|
|
using Robust.Server.Interfaces.Player;
|
|
|
|
|
|
using Robust.Shared.GameObjects.EntitySystemMessages;
|
|
|
|
|
|
using Robust.Shared.Interfaces.GameObjects;
|
|
|
|
|
|
using Robust.Shared.Interfaces.Map;
|
|
|
|
|
|
using Robust.Shared.Interfaces.Random;
|
|
|
|
|
|
using Robust.Shared.Interfaces.Timing;
|
|
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
|
using Robust.Shared.Map;
|
|
|
|
|
|
using Robust.Shared.Maths;
|
|
|
|
|
|
using Robust.Shared.Random;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Explosions
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class ExplosionHelper
|
|
|
|
|
|
{
|
2020-02-08 14:46:12 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Distance used for camera shake when distance from explosion is (0.0, 0.0).
|
|
|
|
|
|
/// Avoids getting NaN values down the line from doing math on (0.0, 0.0).
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private static Vector2 _epicenterDistance = (0.1f, 0.1f);
|
|
|
|
|
|
|
2020-09-06 16:11:53 +02:00
|
|
|
|
public static void SpawnExplosion(EntityCoordinates coords, int devastationRange, int heavyImpactRange, int lightImpactRange, int flashRange)
|
2019-10-11 16:57:16 -04:00
|
|
|
|
{
|
|
|
|
|
|
var tileDefinitionManager = IoCManager.Resolve<ITileDefinitionManager>();
|
|
|
|
|
|
var serverEntityManager = IoCManager.Resolve<IServerEntityManager>();
|
|
|
|
|
|
var entitySystemManager = IoCManager.Resolve<IEntitySystemManager>();
|
|
|
|
|
|
var mapManager = IoCManager.Resolve<IMapManager>();
|
|
|
|
|
|
var robustRandom = IoCManager.Resolve<IRobustRandom>();
|
2020-09-06 16:11:53 +02:00
|
|
|
|
var entityManager = IoCManager.Resolve<IEntityManager>();
|
2019-10-11 16:57:16 -04:00
|
|
|
|
|
|
|
|
|
|
var maxRange = MathHelper.Max(devastationRange, heavyImpactRange, lightImpactRange, 0f);
|
|
|
|
|
|
//Entity damage calculation
|
|
|
|
|
|
var entitiesAll = serverEntityManager.GetEntitiesInRange(coords, maxRange).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var entity in entitiesAll)
|
|
|
|
|
|
{
|
2020-01-21 12:13:57 -05:00
|
|
|
|
if (entity.Deleted)
|
|
|
|
|
|
continue;
|
2019-10-11 16:57:16 -04:00
|
|
|
|
if (!entity.Transform.IsMapTransform)
|
|
|
|
|
|
continue;
|
2020-01-21 12:13:57 -05:00
|
|
|
|
|
2020-09-06 16:11:53 +02:00
|
|
|
|
if (!entity.Transform.Coordinates.TryDistance(entityManager, coords, out var distance))
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-22 20:30:36 -03:00
|
|
|
|
ExplosionSeverity severity;
|
2020-09-06 16:11:53 +02:00
|
|
|
|
if (distance < devastationRange)
|
2019-10-11 16:57:16 -04:00
|
|
|
|
{
|
|
|
|
|
|
severity = ExplosionSeverity.Destruction;
|
|
|
|
|
|
}
|
2020-09-06 16:11:53 +02:00
|
|
|
|
else if (distance < heavyImpactRange)
|
2019-10-11 16:57:16 -04:00
|
|
|
|
{
|
|
|
|
|
|
severity = ExplosionSeverity.Heavy;
|
|
|
|
|
|
}
|
2020-09-06 16:11:53 +02:00
|
|
|
|
else if (distance < lightImpactRange)
|
2019-10-11 16:57:16 -04:00
|
|
|
|
{
|
|
|
|
|
|
severity = ExplosionSeverity.Light;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2020-02-22 20:30:36 -03:00
|
|
|
|
var exAct = entitySystemManager.GetEntitySystem<ActSystem>();
|
2019-10-11 16:57:16 -04:00
|
|
|
|
//exAct.HandleExplosion(Owner, entity, severity);
|
2020-02-24 07:52:15 +05:00
|
|
|
|
exAct.HandleExplosion(coords, entity, severity);
|
2019-10-11 16:57:16 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Tile damage calculation mockup
|
|
|
|
|
|
//TODO: make it into some sort of actual damage component or whatever the boys think is appropriate
|
2020-09-06 16:11:53 +02:00
|
|
|
|
var mapGrid = mapManager.GetGrid(coords.GetGridId(entityManager));
|
2019-10-11 16:57:16 -04:00
|
|
|
|
var circle = new Circle(coords.Position, maxRange);
|
|
|
|
|
|
var tiles = mapGrid.GetTilesIntersecting(circle);
|
|
|
|
|
|
foreach (var tile in tiles)
|
|
|
|
|
|
{
|
|
|
|
|
|
var tileLoc = mapGrid.GridTileToLocal(tile.GridIndices);
|
2020-02-22 20:30:36 -03:00
|
|
|
|
var tileDef = (ContentTileDefinition) tileDefinitionManager[tile.Tile.TypeId];
|
|
|
|
|
|
var baseTurfs = tileDef.BaseTurfs;
|
|
|
|
|
|
if (baseTurfs.Count == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2020-09-06 16:11:53 +02:00
|
|
|
|
|
|
|
|
|
|
if (!tileLoc.TryDistance(entityManager, coords, out var distance))
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2020-02-24 07:52:15 +05:00
|
|
|
|
|
2020-08-08 18:14:22 +02:00
|
|
|
|
var zeroTile = new Tile(tileDefinitionManager[baseTurfs[0]].TileId);
|
|
|
|
|
|
var previousTile = new Tile(tileDefinitionManager[baseTurfs[^1]].TileId);
|
2020-02-24 07:52:15 +05:00
|
|
|
|
|
2020-09-06 16:11:53 +02:00
|
|
|
|
switch (distance)
|
2020-02-22 20:30:36 -03:00
|
|
|
|
{
|
2020-08-08 18:14:22 +02:00
|
|
|
|
case var d when d < devastationRange:
|
|
|
|
|
|
mapGrid.SetTile(tileLoc, zeroTile);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case var d when d < heavyImpactRange
|
|
|
|
|
|
&& !previousTile.IsEmpty
|
|
|
|
|
|
&& robustRandom.Prob(0.8f):
|
|
|
|
|
|
mapGrid.SetTile(tileLoc, previousTile);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case var d when d < lightImpactRange
|
|
|
|
|
|
&& !previousTile.IsEmpty
|
|
|
|
|
|
&& robustRandom.Prob(0.5f):
|
|
|
|
|
|
mapGrid.SetTile(tileLoc, previousTile);
|
|
|
|
|
|
break;
|
2019-10-11 16:57:16 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Effects and sounds
|
|
|
|
|
|
var time = IoCManager.Resolve<IGameTiming>().CurTime;
|
|
|
|
|
|
var message = new EffectSystemMessage
|
|
|
|
|
|
{
|
|
|
|
|
|
EffectSprite = "Effects/explosion.rsi",
|
|
|
|
|
|
RsiState = "explosionfast",
|
|
|
|
|
|
Born = time,
|
|
|
|
|
|
DeathTime = time + TimeSpan.FromSeconds(5),
|
|
|
|
|
|
Size = new Vector2(flashRange / 2, flashRange / 2),
|
|
|
|
|
|
Coordinates = coords,
|
|
|
|
|
|
//Rotated from east facing
|
|
|
|
|
|
Rotation = 0f,
|
|
|
|
|
|
ColorDelta = new Vector4(0, 0, 0, -1500f),
|
|
|
|
|
|
Color = Vector4.Multiply(new Vector4(255, 255, 255, 750), 0.5f),
|
|
|
|
|
|
Shaded = false
|
|
|
|
|
|
};
|
|
|
|
|
|
entitySystemManager.GetEntitySystem<EffectSystem>().CreateParticle(message);
|
2020-07-07 13:19:00 -04:00
|
|
|
|
entitySystemManager.GetEntitySystem<AudioSystem>().PlayAtCoords("/Audio/Effects/explosion.ogg", coords);
|
2019-10-11 16:57:16 -04:00
|
|
|
|
|
|
|
|
|
|
// Knock back cameras of all players in the area.
|
2019-11-13 17:37:46 -05:00
|
|
|
|
|
2019-10-11 16:57:16 -04:00
|
|
|
|
var playerManager = IoCManager.Resolve<IPlayerManager>();
|
|
|
|
|
|
foreach (var player in playerManager.GetAllPlayers())
|
|
|
|
|
|
{
|
|
|
|
|
|
if (player.AttachedEntity == null
|
|
|
|
|
|
|| player.AttachedEntity.Transform.MapID != mapGrid.ParentMapId
|
|
|
|
|
|
|| !player.AttachedEntity.TryGetComponent(out CameraRecoilComponent recoil))
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var playerPos = player.AttachedEntity.Transform.WorldPosition;
|
2020-09-06 16:11:53 +02:00
|
|
|
|
var delta = coords.ToMapPos(entityManager) - playerPos;
|
2020-02-08 14:46:12 -05:00
|
|
|
|
//Change if zero. Will result in a NaN later breaking camera shake if not changed
|
|
|
|
|
|
if (delta.EqualsApprox((0.0f, 0.0f)))
|
|
|
|
|
|
delta = _epicenterDistance;
|
2019-10-11 16:57:16 -04:00
|
|
|
|
|
2020-02-08 14:46:12 -05:00
|
|
|
|
var distance = delta.LengthSquared;
|
2020-08-09 20:56:02 +02:00
|
|
|
|
var effect = 10 * (1 / (1 + distance));
|
2019-10-11 16:57:16 -04:00
|
|
|
|
if (effect > 0.01f)
|
|
|
|
|
|
{
|
|
|
|
|
|
var kick = -delta.Normalized * effect;
|
|
|
|
|
|
recoil.Kick(kick);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|