Explosions and Grenades, Triggers, OnDestroy, OnExAct, Fueltanks and destructible tables (#247)

* initial explosiveComponent

* remove garbagee

* assets

* tile mass deletion baby

* grenades

* tweaks

* Update Content.Server/GameObjects/Components/Explosion/ExplosiveComponent.cs

Co-Authored-By: Pieter-Jan Briers <pieterjan.briers@gmail.com>

* Ex_act based on damage, fixes and tweaks

* One finishing touch

Done the most cringe way

* ex_act explosions, tables are destructible now

also adds fuel tanks

* adds ex_act to mobs
This commit is contained in:
Injazz
2019-06-07 16:15:20 +05:00
committed by Pieter-Jan Briers
parent f1aeaaa640
commit 10801af2f7
42 changed files with 756 additions and 18 deletions

View File

@@ -1,21 +1,27 @@
using System;
using System.Collections.Generic;
using Robust.Shared.GameObjects;
using Robust.Shared.Log;
using Robust.Shared.Utility;
using YamlDotNet.RepresentationModel;
using Content.Server.Interfaces;
using Content.Shared.GameObjects;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Content.Server.Interfaces;
using Content.Server.GameObjects.EntitySystems;
using Content.Shared.GameObjects;
namespace Content.Server.GameObjects.Components.Destructible
{
/// <summary>
/// Deletes the entity once a certain damage threshold has been reached.
/// </summary>
public class DestructibleComponent : Component, IOnDamageBehavior
public class DestructibleComponent : Component, IOnDamageBehavior, IDestroyAct, IExAct
{
#pragma warning disable 649
[Dependency] private readonly IEntitySystemManager _entitySystemManager;
#pragma warning restore 649
/// <inheritdoc />
public override string Name => "Destructible";
@@ -28,16 +34,24 @@ namespace Content.Server.GameObjects.Components.Destructible
public DamageType damageType = DamageType.Total;
public int damageValue = 0;
public string spawnOnDestroy = "SteelSheet";
public string spawnOnDestroy = "";
public bool destroyed = false;
ActSystem _actSystem;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref damageValue, "thresholdvalue", 100);
serializer.DataField(ref damageType, "thresholdtype", DamageType.Total);
serializer.DataField(ref spawnOnDestroy, "spawnondestroy", "SteelSheet");
serializer.DataField(ref spawnOnDestroy, "spawnondestroy", "");
}
public override void Initialize()
{
base.Initialize();
_actSystem = _entitySystemManager.GetEntitySystem<ActSystem>();
}
/// <inheritdoc />
@@ -49,13 +63,40 @@ namespace Content.Server.GameObjects.Components.Destructible
/// <inheritdoc />
void IOnDamageBehavior.OnDamageThresholdPassed(object obj, DamageThresholdPassedEventArgs e)
{
{
if (e.Passed && e.DamageThreshold == Threshold && destroyed == false)
{
destroyed = true;
var wreck = Owner.EntityManager.SpawnEntity(spawnOnDestroy);
wreck.Transform.GridPosition = Owner.Transform.GridPosition;
Owner.EntityManager.DeleteEntity(Owner);
_actSystem.HandleDestruction(Owner, true);
}
}
void IExAct.OnExplosion(ExplosionEventArgs eventArgs)
{
var prob = new Random();
switch (eventArgs.Severity)
{
case ExplosionSeverity.Destruction:
_actSystem.HandleDestruction(Owner, false);
break;
case ExplosionSeverity.Heavy:
_actSystem.HandleDestruction(Owner, true);
break;
case ExplosionSeverity.Light:
if (RandomExtensions.Prob(prob, 40))
_actSystem.HandleDestruction(Owner, true);
break;
}
}
void IDestroyAct.OnDestroy(DestructionEventArgs eventArgs)
{
if (!string.IsNullOrWhiteSpace(spawnOnDestroy) && eventArgs.IsSpawnWreck)
{
Owner.EntityManager.TrySpawnEntityAt(spawnOnDestroy, Owner.Transform.GridPosition, out var wreck);
}
}
}