Files
tbd-station-14/Content.Server/EntryPoint.cs
Centronias ef506006b3 Toggleable flashlight (#106)
Fixes second half of #92 

Regarding the first half, Digitalis explained in discord that when an entity is picked up, visible components are made invisible by making the entire Godot scene node for the entity (based on the GodotTransformComponent) not visible. It's probably possible to exempt the pointlight from that invisibility, but that seems hacky and it seems like something that should be covered by a generic "items equipped in hands are visible" design.

Adds:
- Handheld light component for toggling light activation
- Lantern sprite with on and off layers
- Lantern prototype updates

Known issues:
- When light is on and on the ground, hovering over it with the cursor does not produce the outline effect. I'm not sure, but I think this is caused by the way I implemented the illuminated layer as an entire sprite rather than just the illuminated part. The outline only works on the first layer maybe? I checked it against the welder in its on state and it doesn't seem to outline the flame.
- Illuminated sprite (layer 1) is an entire flashlight, so to make it look okay, the whole first layer is turned off. Would be better / more correct to follow the example of the welder and just create an illuminated "cap" to overlay on the dark extinguished layer. I'd whip up some coder art myself, but I don't have the right tools to handle transparency.
- Illuminated sprite is slightly different from the extinguished sprite, so turning on the light makes it a little bit shorter.
2018-08-28 17:39:20 +02:00

240 lines
9.3 KiB
C#

using Content.Server.GameObjects;
using Content.Server.GameObjects.Components.Power;
using Content.Server.GameObjects.Components.Interactable.Tools;
using Content.Server.Interfaces.GameObjects;
using Content.Server.Placement;
using SS14.Server;
using SS14.Server.Interfaces;
using SS14.Server.Interfaces.Chat;
using SS14.Server.Interfaces.Maps;
using SS14.Server.Interfaces.Player;
using SS14.Server.Player;
using SS14.Shared.Console;
using SS14.Shared.ContentPack;
using SS14.Shared.Enums;
using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.Interfaces.Map;
using SS14.Shared.Interfaces.Timers;
using SS14.Shared.IoC;
using SS14.Shared.Log;
using SS14.Shared.Map;
using SS14.Shared.Timers;
using SS14.Shared.Interfaces.Timing;
using SS14.Shared.Maths;
using Content.Server.GameObjects.Components.Weapon.Ranged.Hitscan;
using Content.Server.GameObjects.Components.Weapon.Ranged.Projectile;
using Content.Server.GameObjects.Components.Projectiles;
using Content.Server.GameObjects.Components.Weapon.Melee;
using Content.Server.GameObjects.Components.Materials;
using Content.Server.GameObjects.Components.Stack;
using Content.Server.GameObjects.Components.Construction;
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Mobs;
using Content.Server.Players;
using Content.Server.GameObjects.Components.Interactable;
namespace Content.Server
{
public class EntryPoint : GameServer
{
const string PlayerPrototypeName = "HumanMob_Content";
private IBaseServer _server;
private IPlayerManager _players;
private IEntityManager entityManager;
private IChatManager chatManager;
private bool _countdownStarted;
private GridLocalCoordinates SpawnPoint;
/// <inheritdoc />
public override void Init()
{
base.Init();
_server = IoCManager.Resolve<IBaseServer>();
_players = IoCManager.Resolve<IPlayerManager>();
entityManager = IoCManager.Resolve<IEntityManager>();
chatManager = IoCManager.Resolve<IChatManager>();
_server.RunLevelChanged += HandleRunLevelChanged;
_players.PlayerStatusChanged += HandlePlayerStatusChanged;
var factory = IoCManager.Resolve<IComponentFactory>();
factory.Register<HandsComponent>();
factory.RegisterReference<HandsComponent, IHandsComponent>();
factory.Register<InventoryComponent>();
factory.Register<StoreableComponent>();
factory.Register<ItemComponent>();
factory.RegisterReference<ItemComponent, StoreableComponent>();
factory.Register<ClothingComponent>();
factory.RegisterReference<ClothingComponent, ItemComponent>();
factory.Register<DamageableComponent>();
factory.Register<DestructibleComponent>();
factory.Register<TemperatureComponent>();
factory.Register<ServerDoorComponent>();
//Power Components
factory.Register<PowerTransferComponent>();
factory.Register<PowerProviderComponent>();
factory.RegisterReference<PowerProviderComponent, PowerDeviceComponent>();
factory.Register<PowerNodeComponent>();
factory.Register<PowerStorageComponent>();
factory.Register<PowerDeviceComponent>();
factory.Register<PowerGeneratorComponent>();
//Tools
factory.Register<MultitoolComponent>();
factory.Register<WirecutterComponent>();
factory.Register<WrenchComponent>();
factory.Register<WelderComponent>();
factory.Register<ScrewdriverComponent>();
factory.Register<CrowbarComponent>();
factory.Register<HitscanWeaponComponent>();
factory.Register<ProjectileWeaponComponent>();
factory.Register<ProjectileComponent>();
factory.Register<MeleeWeaponComponent>();
factory.Register<HandheldLightComponent>();
factory.Register<ServerStorageComponent>();
factory.RegisterReference<ServerStorageComponent, IActivate>();
factory.Register<PowerDebugTool>();
factory.Register<PoweredLightComponent>();
factory.Register<SmesComponent>();
factory.Register<ApcComponent>();
factory.Register<MaterialComponent>();
factory.Register<StackComponent>();
factory.Register<ConstructionComponent>();
factory.Register<ConstructorComponent>();
factory.RegisterIgnore("ConstructionGhost");
factory.Register<MindComponent>();
}
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
if (disposing)
{
_server.RunLevelChanged -= HandleRunLevelChanged;
_players.PlayerStatusChanged -= HandlePlayerStatusChanged;
}
base.Dispose(disposing);
}
private void HandleRunLevelChanged(object sender, RunLevelChangedEventArgs args)
{
switch (args.NewLevel)
{
case ServerRunLevel.PreGame:
var timing = IoCManager.Resolve<IGameTiming>();
var mapLoader = IoCManager.Resolve<IMapLoader>();
var mapMan = IoCManager.Resolve<IMapManager>();
var newMap = mapMan.CreateMap();
var grid = mapLoader.LoadBlueprint(newMap, "Maps/stationstation.yml");
SpawnPoint = new GridLocalCoordinates(Vector2.Zero, grid);
var startTime = timing.RealTime;
var timeSpan = timing.RealTime - startTime;
Logger.Info($"Loaded map in {timeSpan.TotalMilliseconds:N2}ms.");
chatManager.DispatchMessage(ChatChannel.Server, "Gamemode: Round loaded!");
break;
case ServerRunLevel.Game:
_players.SendJoinGameToAll();
chatManager.DispatchMessage(ChatChannel.Server, "Gamemode: Round started!");
break;
case ServerRunLevel.PostGame:
chatManager.DispatchMessage(ChatChannel.Server, "Gamemode: Round over!");
break;
}
}
private void HandlePlayerStatusChanged(object sender, SessionStatusEventArgs args)
{
var session = args.Session;
switch (args.NewStatus)
{
case SessionStatus.Connected:
{
if (session.Data.ContentDataUncast == null)
{
session.Data.ContentDataUncast = new PlayerData(session.SessionId);
}
// timer time must be > tick length
Timer.Spawn(250, args.Session.JoinLobby);
chatManager.DispatchMessage(ChatChannel.Server, "Gamemode: Player joined server!", args.Session.SessionId);
}
break;
case SessionStatus.InLobby:
{
// auto start game when first player joins
if (_server.RunLevel == ServerRunLevel.PreGame && !_countdownStarted)
{
_countdownStarted = true;
Timer.Spawn(2000, () =>
{
_server.RunLevel = ServerRunLevel.Game;
_countdownStarted = false;
});
}
chatManager.DispatchMessage(ChatChannel.Server, "Gamemode: Player joined Lobby!", args.Session.SessionId);
}
break;
case SessionStatus.InGame:
{
//TODO: Check for existing mob and re-attach
var data = session.ContentData();
if (data.Mind == null)
{
// No mind yet (new session), make a new one.
data.Mind = new Mind(session.SessionId);
var mob = SpawnPlayerMob();
data.Mind.TransferTo(mob);
}
else
{
if (data.Mind.CurrentMob == null)
{
var mob = SpawnPlayerMob();
data.Mind.TransferTo(mob);
}
session.AttachToEntity(data.Mind.CurrentEntity);
}
chatManager.DispatchMessage(ChatChannel.Server, "Gamemode: Player joined Game!", args.Session.SessionId);
}
break;
case SessionStatus.Disconnected:
{
chatManager.DispatchMessage(ChatChannel.Server, "Gamemode: Player left!", args.Session.SessionId);
}
break;
}
}
IEntity SpawnPlayerMob()
{
return entityManager.ForceSpawnEntityAt(PlayerPrototypeName, SpawnPoint);
}
}
}