Buildable wall light (#2644)

* Added empty light

* Can build light fixture

* Can construct and deconstruct small light

* You can build bulbs only on walls

* Playing with placement conditions

* Refactored code a bit

* Added check for north direction and snapping

* Fixed all small light sprites (wrong directions order)

* Fixed weird problem with bulb lights

* Fixed rotation on all stations

* Fixed map again

* Much better placement mode

* Deleted shared wall component and moved all logic to raycasts

* Missing bracket

* Better texture

* Moved wallmount condition to tags

* Removed station station

* Added suffix and fixed on map init bug
This commit is contained in:
Alex Evgrashin
2021-02-07 02:05:53 +03:00
committed by GitHub
parent 2f01d7899f
commit 59e72697cb
14 changed files with 306 additions and 59 deletions

View File

@@ -0,0 +1,68 @@
#nullable enable
using Robust.Client.Placement;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Content.Client.Placement.Modes
{
public class WallmountLight : PlacementMode
{
public WallmountLight(PlacementManager pMan) : base(pMan)
{
}
public override void AlignPlacementMode(ScreenCoordinates mouseScreen)
{
MouseCoords = ScreenToCursorGrid(mouseScreen);
CurrentTile = GetTileRef(MouseCoords);
if (pManager.CurrentPermission!.IsTile)
{
return;
}
var tileCoordinates = new EntityCoordinates(MouseCoords.EntityId, CurrentTile.GridIndices);
Vector2 offset;
switch (pManager.Direction)
{
case Direction.North:
offset = new Vector2(0.5f, 1f);
break;
case Direction.South:
offset = new Vector2(0.5f, 0f);
break;
case Direction.East:
offset = new Vector2(1f, 0.5f);
break;
case Direction.West:
offset = new Vector2(0f, 0.5f);
break;
default:
return;
}
tileCoordinates = tileCoordinates.Offset(offset);
MouseCoords = tileCoordinates;
}
public override bool IsValidPosition(EntityCoordinates position)
{
if (pManager.CurrentPermission!.IsTile)
{
return false;
}
else if (!RangeCheck(position))
{
return false;
}
return true;
}
}
}

View File

@@ -38,6 +38,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
private static readonly TimeSpan _thunkDelay = TimeSpan.FromSeconds(2);
private TimeSpan _lastThunk;
private bool _hasLampOnSpawn;
[ViewVariables] private bool _on;
@@ -148,6 +149,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
{
serializer.DataField(ref BulbType, "bulb", LightBulbType.Tube);
serializer.DataField(ref _on, "on", true);
serializer.DataField(ref _hasLampOnSpawn, "hasLampOnSpawn", true);
}
/// <summary>
@@ -228,6 +230,8 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
}
void IMapInit.MapInit()
{
if (_hasLampOnSpawn)
{
var prototype = BulbType switch
{
@@ -238,6 +242,8 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
var entity = Owner.EntityManager.SpawnEntity(prototype, Owner.Transform.Coordinates);
_lightBulbContainer.Insert(entity);
UpdateLight();
}
}
public void TriggerSignal(bool signal)

View File

@@ -0,0 +1,55 @@
#nullable enable
using Content.Shared.GameObjects.Components.Tag;
using Content.Shared.Physics;
using JetBrains.Annotations;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Physics;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Serialization;
using System.Linq;
namespace Content.Shared.Construction.ConstructionConditions
{
[UsedImplicitly]
public class WallmountCondition : IConstructionCondition
{
public void ExposeData(ObjectSerializer serializer) { }
public bool Condition(IEntity user, EntityCoordinates location, Direction direction)
{
var entManager = IoCManager.Resolve<IEntityManager>();
// get blueprint and user position
var userWorldPosition = user.Transform.WorldPosition;
var objWorldPosition = location.ToMap(entManager).Position;
// find direction from user to blueprint
var userToObject = (objWorldPosition - userWorldPosition);
// dot product will be positive if user direction and blueprint are co-directed
var dotProd = Vector2.Dot(direction.ToVec(), userToObject);
if (dotProd > 0)
return false;
// now we need to check that user actually tries to build wallmount on a wall
var physics = IoCManager.Resolve<IPhysicsManager>();
var rUserToObj = new CollisionRay(userWorldPosition, userToObject.Normalized, (int) CollisionGroup.Impassable);
var length = userToObject.Length;
var userToObjRaycastResults = physics.IntersectRayWithPredicate(user.Transform.MapID, rUserToObj, maxLength: length,
predicate: (e) => !e.HasTag("Wall"));
if (!userToObjRaycastResults.Any())
return false;
// get this wall entity
var targetWall = userToObjRaycastResults.First().HitEntity;
// check that we didn't try to build wallmount that facing another adjacent wall
var rAdjWall = new CollisionRay(objWorldPosition, direction.ToVec(), (int) CollisionGroup.Impassable);
var adjWallRaycastResults = physics.IntersectRayWithPredicate(user.Transform.MapID, rAdjWall, maxLength: 0.5f,
predicate: (e) => e == targetWall || !e.HasTag("Wall"));
return !adjWallRaycastResults.Any();
}
}
}

View File

@@ -20002,7 +20002,7 @@ entities:
components:
- parent: 853
pos: -12.5,-5
rot: -1.5707963267948966 rad
rot: 1.5707963267948966 rad
type: Transform
- color: '#FFFFFFFF'
type: PointLight
@@ -21324,7 +21324,7 @@ entities:
components:
- parent: 853
pos: -6.5,-26
rot: 1.5707963267948966 rad
rot: -1.5707963267948966 rad
type: Transform
- color: '#FFFFFFFF'
type: PointLight
@@ -21430,6 +21430,7 @@ entities:
type: PoweredSmallLight
components:
- parent: 853
rot: 3.141592653589793 rad
pos: -7,-23.5
type: Transform
- color: '#FFFFFFFF'
@@ -22573,7 +22574,7 @@ entities:
components:
- parent: 853
pos: -29.5,15
rot: 1.5707963267948966 rad
rot: -1.5707963267948966 rad
type: Transform
- color: '#FFFFFFFF'
type: PointLight
@@ -22602,7 +22603,7 @@ entities:
components:
- parent: 853
pos: -34,-0.5
rot: 3.141592653589793 rad
rot: 0 rad
type: Transform
- color: '#FFFFFFFF'
type: PointLight
@@ -22616,6 +22617,7 @@ entities:
type: PoweredSmallLight
components:
- parent: 853
rot: 3.141592653589793 rad
pos: -18,-4.5
type: Transform
- color: '#FFFFFFFF'
@@ -22700,7 +22702,7 @@ entities:
components:
- parent: 853
pos: -29.5,-9
rot: -1.5707963267948966 rad
rot: 1.5707963267948966 rad
type: Transform
- color: '#FFFFFFFF'
type: PointLight
@@ -22883,6 +22885,7 @@ entities:
type: PoweredSmallLight
components:
- parent: 853
rot: 3.141592653589793 rad
pos: -19,9.5
type: Transform
- color: '#FFFFFFFF'
@@ -22912,7 +22915,7 @@ entities:
components:
- parent: 853
pos: -14.5,-16
rot: -1.5707963267948966 rad
rot: 1.5707963267948966 rad
type: Transform
- color: '#FFFFFFFF'
type: PointLight
@@ -22926,6 +22929,7 @@ entities:
type: PoweredSmallLight
components:
- parent: 853
rot: 3.141592653589793 rad
pos: -7,-12.5
type: Transform
- color: '#FFFFFFFF'
@@ -22940,6 +22944,7 @@ entities:
type: PoweredSmallLight
components:
- parent: 853
rot: 3.141592653589793 rad
pos: -11,-10.5
type: Transform
- color: '#FFFFFFFF'
@@ -23112,7 +23117,7 @@ entities:
components:
- parent: 853
pos: -19,16.5
rot: 3.141592653589793 rad
rot: 0 rad
type: Transform
- color: '#FFFFFFFF'
type: PointLight
@@ -23127,7 +23132,7 @@ entities:
components:
- parent: 853
pos: -14.5,26
rot: 1.5707963267948966 rad
rot: -1.5707963267948966 rad
type: Transform
- color: '#FFFFFFFF'
type: PointLight
@@ -23142,7 +23147,7 @@ entities:
components:
- parent: 853
pos: -19,22.5
rot: 3.141592653589793 rad
rot: 0 rad
type: Transform
- color: '#FFFFFFFF'
type: PointLight
@@ -23157,7 +23162,7 @@ entities:
components:
- parent: 853
pos: -18,9.5
rot: 3.141592653589793 rad
rot: 0 rad
type: Transform
- color: '#FFFFFFFF'
type: PointLight
@@ -23172,7 +23177,7 @@ entities:
components:
- parent: 853
pos: -0.5,-12
rot: -1.5707963267948966 rad
rot: 1.5707963267948966 rad
type: Transform
- color: '#FFFFFFFF'
type: PointLight
@@ -23386,7 +23391,7 @@ entities:
components:
- parent: 853
pos: -1,8.5
rot: 3.141592653589793 rad
rot: 0 rad
type: Transform
- color: '#FFFFFFFF'
type: PointLight
@@ -23401,7 +23406,7 @@ entities:
components:
- parent: 853
pos: -4,8.5
rot: 3.141592653589793 rad
rot: 0 rad
type: Transform
- color: '#FFFFFFFF'
type: PointLight
@@ -23528,7 +23533,7 @@ entities:
components:
- parent: 853
pos: -7.5,26
rot: 1.5707963267948966 rad
rot: -1.5707963267948966 rad
type: Transform
- color: '#FFFFFFFF'
type: PointLight
@@ -23550,7 +23555,7 @@ entities:
components:
- parent: 853
pos: -4,17.5
rot: 3.141592653589793 rad
rot: 0 rad
type: Transform
- color: '#FFFFFFFF'
type: PointLight
@@ -23783,6 +23788,7 @@ entities:
type: PoweredSmallLight
components:
- parent: 853
rot: 3.141592653589793 rad
pos: 17,15.5
type: Transform
- color: '#FFFFFFFF'
@@ -23797,6 +23803,7 @@ entities:
type: PoweredSmallLight
components:
- parent: 853
rot: 3.141592653589793 rad
pos: 14,16.5
type: Transform
- color: '#FFFFFFFF'
@@ -23812,7 +23819,7 @@ entities:
components:
- parent: 853
pos: 8.5,15
rot: 1.5707963267948966 rad
rot: -1.5707963267948966 rad
type: Transform
- color: '#FFFFFFFF'
type: PointLight
@@ -24274,7 +24281,7 @@ entities:
components:
- parent: 853
pos: 30.5,-6
rot: 1.5707963267948966 rad
rot: -1.5707963267948966 rad
type: Transform
- color: '#FFFFFFFF'
type: PointLight
@@ -24289,7 +24296,7 @@ entities:
components:
- parent: 853
pos: 25.5,-1
rot: 1.5707963267948966 rad
rot: -1.5707963267948966 rad
type: Transform
- color: '#FFFFFFFF'
type: PointLight
@@ -24304,7 +24311,7 @@ entities:
components:
- parent: 853
pos: 9.5,-18
rot: 1.5707963267948966 rad
rot: -1.5707963267948966 rad
type: Transform
- color: '#FFFFFFFF'
type: PointLight
@@ -24347,7 +24354,7 @@ entities:
components:
- parent: 853
pos: 12.5,-19
rot: 1.5707963267948966 rad
rot: -1.5707963267948966 rad
type: Transform
- color: '#FFFFFFFF'
type: PointLight
@@ -24369,7 +24376,7 @@ entities:
components:
- parent: 853
pos: 25.5,-19
rot: -1.5707963267948966 rad
rot: 1.5707963267948966 rad
type: Transform
- color: '#FFFFFFFF'
type: PointLight
@@ -24383,6 +24390,7 @@ entities:
type: PoweredSmallLight
components:
- parent: 853
rot: 3.141592653589793 rad
pos: 28,-15.5
type: Transform
- color: '#FFFFFFFF'
@@ -24432,6 +24440,7 @@ entities:
type: PoweredSmallLight
components:
- parent: 853
rot: 3.141592653589793 rad
pos: 28,-10.5
type: Transform
- color: '#FFFFFFFF'
@@ -24453,6 +24462,7 @@ entities:
type: PoweredSmallLight
components:
- parent: 853
rot: 3.141592653589793 rad
pos: 24,0.5
type: Transform
- color: '#FFFFFFFF'
@@ -24468,7 +24478,7 @@ entities:
components:
- parent: 853
pos: 26,-4.5
rot: 3.141592653589793 rad
rot: 0 rad
type: Transform
- color: '#FFFFFFFF'
type: PointLight
@@ -24483,7 +24493,7 @@ entities:
components:
- parent: 853
pos: 35.5,-6
rot: 1.5707963267948966 rad
rot: -1.5707963267948966 rad
type: Transform
- color: '#FFFFFFFF'
type: PointLight
@@ -24498,7 +24508,7 @@ entities:
components:
- parent: 853
pos: 38.5,-3
rot: 1.5707963267948966 rad
rot: -1.5707963267948966 rad
type: Transform
- color: '#FFFFFFFF'
type: PointLight
@@ -24513,7 +24523,7 @@ entities:
components:
- parent: 853
pos: 26,11.5
rot: 3.141592653589793 rad
rot: 0 rad
type: Transform
- color: '#FFFFFFFF'
type: PointLight
@@ -24709,6 +24719,7 @@ entities:
type: PoweredSmallLight
components:
- parent: 853
rot: 3.141592653589793 rad
pos: 44,-1.5
type: Transform
- color: '#FFFFFFFF'
@@ -26432,7 +26443,7 @@ entities:
components:
- parent: 853
pos: -12.5,-6
rot: 1.5707963267948966 rad
rot: -1.5707963267948966 rad
type: Transform
- color: '#FFFFFFFF'
type: PointLight
@@ -26447,7 +26458,7 @@ entities:
components:
- parent: 853
pos: -25.5,-10
rot: 1.5707963267948966 rad
rot: -1.5707963267948966 rad
type: Transform
- color: '#FFFFFFFF'
type: PointLight
@@ -42390,7 +42401,7 @@ entities:
components:
- parent: 853
pos: 22.528679,-9.003884
rot: 1.5707963267948966 rad
rot: -1.5707963267948966 rad
type: Transform
- powerLoad: 0
type: PowerReceiver
@@ -42772,7 +42783,7 @@ entities:
components:
- parent: 853
pos: -1.4929452,19.970068
rot: -1.5707963267948966 rad
rot: 1.5707963267948966 rad
type: Transform
- powerLoad: 0
type: PowerReceiver
@@ -42799,7 +42810,7 @@ entities:
components:
- parent: 853
pos: -15.494916,15.968084
rot: -1.5707963267948966 rad
rot: 1.5707963267948966 rad
type: Transform
- powerLoad: 0
type: PowerReceiver
@@ -44360,7 +44371,7 @@ entities:
components:
- parent: 853
pos: -22.5,-16
rot: -1.5707963267948966 rad
rot: 1.5707963267948966 rad
type: Transform
- powerLoad: 0
type: PowerReceiver

View File

@@ -4,6 +4,9 @@
components:
- type: Clickable
- type: InteractionOutline
- type: Construction
graph: lightFixture
node: tubeLight
- type: Physics
shapes:
- !type:PhysShapeAabb
@@ -47,10 +50,39 @@
- !type:DoActsBehavior
acts: ["Destruction"]
- type: entity
id: PoweredlightEmpty
suffix: Empty
parent: Poweredlight
components:
- type: Sprite
state: empty
- type: PoweredLight
hasLampOnSpawn: False
- type: entity
name: unpowered small light
id: SmallLight
parent: WallLight
components:
- type: Sprite
sprite: Constructible/Lighting/light_small.rsi
state: on
- type: PointLight
energy: 1.0
enabled: true
offset: "-0.5, 0"
- type: Destructible
deadThreshold: 25
resistances: metallicResistances
- type: Construction
graph: lightFixture
node: bulbLight
- type: entity
name: small light
id: PoweredSmallLight
parent: WallLight
parent: SmallLight
components:
- type: Sprite
sprite: Constructible/Lighting/light_small.rsi
@@ -79,24 +111,11 @@
acts: ["Destruction"]
- type: entity
name: unpowered small light
id: SmallLight
parent: WallLight
id: PoweredSmallLightEmpty
suffix: Empty
parent: PoweredSmallLight
components:
- type: Sprite
sprite: Constructible/Lighting/light_small.rsi
state: on
- type: PointLight
energy: 1.0
enabled: true
offset: "-0.5, 0"
- type: Damageable
resistances: metallicResistances
- type: Destructible
thresholds:
- trigger:
!type:TotalDamageTrigger
damage: 25
behaviors:
- !type:DoActsBehavior
acts: ["Destruction"]
state: empty
- type: PoweredLight
hasLampOnSpawn: False

View File

@@ -1,4 +1,4 @@
- type: entity
- type: entity
id: base_wall
name: basewall
description: Keeps the air in and the greytide out.
@@ -9,6 +9,9 @@
- Wall
components:
- type: RCDDeconstructWhitelist
- type: Tag
tags:
- Wall
- type: Clickable
- type: InteractionOutline
- type: Sprite

View File

@@ -0,0 +1,46 @@
- type: constructionGraph
id: lightFixture
start: start
graph:
- node: start
edges:
- to: bulbLight
steps:
- material: Metal
amount: 1
doAfter: 2.0
- to: tubeLight
steps:
- material: Metal
amount: 2
doAfter: 2.0
- node: tubeLight
entity: PoweredlightEmpty
edges:
- to: start
conditions:
- !type:ContainerEmpty
container: "light_bulb"
steps:
- tool: Screwing
doAfter: 2.0
completed:
- !type:SpawnPrototype
prototype: SteelSheet1
amount: 2
- !type:DeleteEntity {}
- node: bulbLight
entity: PoweredSmallLightEmpty
edges:
- to: start
conditions:
- !type:ContainerEmpty
container: "light_bulb"
steps:
- tool: Screwing
doAfter: 2.0
completed:
- !type:SpawnPrototype
prototype: SteelSheet1
amount: 1
- !type:DeleteEntity {}

View File

@@ -0,0 +1,36 @@
- type: construction
name: wall light
id: LightTubeFixture
graph: lightFixture
startNode: start
targetNode: tubeLight
category: Structures
description: A wall light fixture. Use light tubes.
icon:
sprite: Constructible/Lighting/light_tube.rsi
state: off
objectType: Structure
placementMode: WallmountLight
canRotate: true
canBuildInImpassable: true
conditions:
- !type:WallmountCondition {}
- type: construction
name: small wall light
id: LightSmallFixture
graph: lightFixture
startNode: start
targetNode: bulbLight
category: Structures
description: A wall light fixture. Use light bulbs.
icon:
sprite: Constructible/Lighting/light_small.rsi
state: off
objectType: Structure
placementMode: WallmountLight
canRotate: true
canBuildInImpassable: true
conditions:
- !type:WallmountCondition {}

View File

@@ -1,2 +1,5 @@
- type: Tag
id: ExplosivePassable
- type: Tag
id: Wall

Binary file not shown.

Before

Width:  |  Height:  |  Size: 246 B

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 274 B

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 199 B

After

Width:  |  Height:  |  Size: 1007 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 262 B

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 287 B

After

Width:  |  Height:  |  Size: 440 B