Понял, будем работать с текущей структурой SS14 и добавим все нужные компоненты и системы в уже существующие файлы проекта. Давайте упростим процесс, добавив необходимые компоненты и системы, чтобы наш аквариум заработал.
Шаг 1: Создание YAML-прототипов
Создайте файл aquariums.yml в папке с прототипами сущностей:
# Path: Resources/Prototypes/Entities/aquariums.yml
- type: entity
id: FishBowl
name: "Fish Bowl"
components:
- type: Transform
- type: Sprite
sprite: Aquarium/FishBowl.png
- type: Aquarium
aquariumType: "FishBowl"
- type: entity
id: FishTank
name: "Fish Tank"
components:
- type: Transform
- type: Sprite
sprite: Aquarium/FishTank.png
- type: Aquarium
aquariumType: "FishTank"
- type: entity
id: WallAquarium
name: "Wall Aquarium"
components:
- type: Transform
- type: Sprite
sprite: Aquarium/WallAquarium.png
- type: Aquarium
aquariumType: "WallAquarium"
Создайте файл fish.yml в папке с прототипами сущностей:
# Path: Resources/Prototypes/Entities/fish.yml
- type: entity
id: Goldfish
name: "Goldfish"
components:
- type: Transform
- type: Sprite
sprite: Fish/Goldfish.png
- type: Fish
species: "Goldfish"
- type: entity
id: Clownfish
name: "Clownfish"
components:
- type: Transform
- type: Sprite
sprite: Fish/Clownfish.png
- type: Fish
species: "Clownfish"
# Добавьте остальные типы рыб здесь аналогичным образом
Шаг 2: Создание компонентов на C#
Компонент для аквариума
Создайте файл AquariumComponent.cs в папке компонентов:
// Path: Content.Server/Aquarium/AquariumComponent.cs
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using System.Collections.Generic;
using Content.Server.Fish;
using Robust.Shared.ViewVariables;
namespace Content.Server.Aquarium
{
[RegisterComponent]
public class AquariumComponent : Component
{
public override string Name => "Aquarium";
[DataField("aquariumType")]
private string _type = "FishBowl";
[ViewVariables]
private int _maxWaterLevel;
[ViewVariables]
private int _currentWaterLevel;
[ViewVariables]
private int _maxFishCount;
private List<FishComponent> _fishes;
[ViewVariables(VVAccess.ReadWrite)]
private bool _isClean;
public override void Initialize()
{
base.Initialize();
_fishes = new List<FishComponent>();
_isClean = true;
switch (_type)
{
case "FishBowl":
_maxWaterLevel = 50;
_maxFishCount = 4;
break;
case "FishTank":
_maxWaterLevel = 200;
_maxFishCount = 10;
break;
case "WallAquarium":
_maxWaterLevel = 500;
_maxFishCount = 10;
break;
}
_currentWaterLevel = 0;
}
public void AddWater(int amount)
{
if ((_currentWaterLevel + amount) <= _maxWaterLevel)
{
_currentWaterLevel += amount;
}
else
{
_currentWaterLevel = _maxWaterLevel;
}
}
public void AddFish(FishComponent fish)
{
if (_fishes.Count < _maxFishCount)
{
_fishes.Add(fish);
}
}
public void Clean()
{
_isClean = true;
}
public void FeedFishes()
{
foreach (var fish in _fishes)
{
fish.Feed();
}
}
public void Tick()
{
foreach (var fish in _fishes)
{
fish.Update();
}
_isClean = _fishes.Count == 0 || (_isClean && _fishes.Count > 0);
}
}
}
Компонент для рыбы
Создайте файл FishComponent.cs в папке компонентов:
// Path: Content.Server/Fish/FishComponent.cs
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Server.Fish
{
[RegisterComponent]
public class FishComponent : Component
{
public override string Name => "Fish";
[DataField("species")]
public string Species { get; private set; }
[ViewVariables]
public bool IsHungry { get; private set; } = false;
[ViewVariables]
public bool IsAlive { get; private set; } = true;
public void Feed()
{
IsHungry = false;
}
public void Update()
{
if (IsHungry)
{
IsAlive = false;
}
else
{
IsHungry = true;
}
}
}
}
Шаг 3: Создание предметов
Создайте файл FishFoodCanComponent.cs в папке компонентов:
// Path: Content.Server/Items/FishFoodCanComponent.cs
using Robust.Shared.GameObjects;
namespace Content.Server.Items
{
[RegisterComponent]
public class FishFoodCanComponent : Component
{
public override string Name => "FishFoodCan";
public void Use(AquariumComponent aquarium)
{
aquarium.FeedFishes();
}
}
}
Шаг 4: Добавление системы для обновления состояния аквариумов
Создайте новый файл AquariumSystem.cs в папке с системами:
// Path: Content.Server/Aquarium/AquariumSystem.cs
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Timing;
namespace Content.Server.Aquarium
{
public class AquariumSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
private TimeSpan _lastUpdate;
public override void Initialize()
{
base.Initialize();
_lastUpdate = _gameTiming.CurTime;
SubscribeLocalEvent<AquariumComponent, ComponentStartup>(OnStartup);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
var currentTime = _gameTiming.CurTime;
if ((currentTime - _lastUpdate).TotalSeconds > 1)
{
foreach (var aquarium in EntityManager.ComponentManager.EntityQuery<AquariumComponent>())
{
aquarium.Tick();
}
_lastUpdate = currentTime;
}
}
private void OnStartup(EntityUid uid, AquariumComponent component, ComponentStartup args)
{
// Инициализация при запуске компонента
}
}
}
Шаг 5: Регистрация системы и компонентов
Обновите файл Content.Server/ServerInitializer.cs для регистрации новой системы:
// Path: Content.Server/ServerInitializer.cs
using Content.Server.Aquarium;
using Robust.Shared.IoC;
using Robust.Server.Player;
namespace Content.Server
{
public static class ServerInitializer
{
public static void Initialize()
{
IoCManager.InjectDependencies();
var entityManager = IoCManager.Resolve<IEntityManager>();
entityManager.SystemManager.AddDependency(new AquariumSystem());
IoCManager.Resolve<IPlayerManager>().PlayerJoin += OnPlayerJoin;
}
private static void OnPlayerJoin(object? sender, PlayerJoinEventArgs e)
{
// Игрок присоединяется к игре
}
}
}
Шаг 6: Тестирование и доработка
- Соберите и запустите проект: Убедитесь, что нет ошибок компиляции.
- Тестирование в игре: Создайте игровые объекты с новыми аквариумами и рыбами, взаимодействуйте с ними через консоль или игровой UI.
- Дополнительное тестирование и отладка: Убедитесь, что все типы рыб и взаимодействие с аквариумами работают корректно.
Таким образом, мы создали YAML-прототипы, компоненты и систему для работы с аквариумами и рыбой в SS14. Это должно запустить базовую работу и взаимодействие аквариумов в игре. Если у вас возникнут вопросы или требуется дополнительная помощь, сообщите об этом!