Files
crystall-punk-14/Content.Client/_CP14/UserInterface/Systems/Skill/CP14SkillUIController.cs
Red 906033633e Vampire clan battle gamemode (#1672)
* vampire returns + transformstions redo

* carcat fangs fix + greetings music update

* vampire skill trees

* Blood essence gathering

Introduces the vampire blood essence mechanic, including the CP14SpellVampireGatherEssence spell, new skill point consumable component, and related UI/localization updates. Adds clientside effects for spell casting, new vampire skill and action, and refines skill point gain/loss popups. Also restructures vampire components, updates spell logic for client/server prediction, and removes unused parallax files.

* perma damage

* Add skill point cost to magic system and vampire essence spell

Introduced CP14MagicEffectSkillPointCostComponent to allow magic effects to consume skill points. Updated the shared magic system to handle skill point checks and consumption. Added a new vampire spell for creating blood essence, including new icons and localization. Adjusted vampire component to grant and remove skill points, and updated related skill tree and spell prototypes. Minor fixes and refactoring in spell logic and descriptions.

* blood step + blood vision skills

* vampire clans icons

* 50 players limit + vampire objectives

* fixes

* devourers altar transmutation

* Remove StealTarget component from animal, dino, and mole NPCs

The StealTarget component and associated stealGroup were removed from boar, dinosaur, and mole NPC definitions. This likely disables these entities from being targeted for stealing, possibly to adjust gameplay balance or fix unintended behavior.

* fix

* essence creation improve

* altars

* voice masks

* transmutation fix

* teleportation glyph

* crimson candles

* candle crafting

* fix pointer predictions

* Add Vampire Clan Battle gamemode and update vampire roles

Introduces the 'Vampire Clan Battle' gamemode with new localization in English and Russian, updated game preset definitions, and secret weights. Refactors vampire antagonist briefings and objectives for multiple clans, adjusts vampire role preferences and team settings, and reduces the damage of the Vampire Gather Essence spell. Also includes minor improvements to spell and game mode descriptions, and corrects file naming for game preset locales.

* powerful kicks in

* time gates + vampire tree

* vampire proto faction

* fix

* fixes

* tree progression

* search enemy

* Update CP14SharedVampireSystem.cs

* blood essence gathering redo

* essence gathering refactor 2

* blood healing

* Update secret_weights.yml

* tree planting

* boodgrass

* tree upgrade announcement

* construction graph integration

* delete transmutation system

* workbench crafting returns

* cloaks crafting + cloak invisibility

* make vampire tree is generic red tree (sad)

* clan heart sprite

* Refactor vampire tree to clan heart system

Replaces the CP14VampireTreeComponent with CP14VampireClanHeartComponent, updating all related logic, appearance, and localization. Adjusts skill requirements, examination, and level progression to use the new clan heart system. Updates entity prototypes, visuals, and adds new orb sprites for clan heart levels. Localization strings and logic are updated to reflect the new terminology and mechanics.

* Update SpeciesBlacklist.cs

* Refactor vampire clan heart and remove tree spell

Refactored the vampire clan heart to support essence regeneration over time and adjusted level thresholds. Removed the vampire tree planting spell and related prototype fields, as well as unused tree system code. Updated localization, entity prototypes, and faction definitions to reflect these changes.

* Add clan heart construction for vampire clans

Introduces construction graphs, entities, and conditions for building unique clan hearts for each vampire clan (Unnameable, Devourers, NightChildrens). Adds new construction conditions (all clan vampires required, singleton enforcement), updates skill tree to unlock constructions, and removes the now-obsolete CP14MagicEffectAllVampireClanRequiredComponent. Also adds new frame sprites and updates localization and prototype files accordingly.

* level up vfx

* VFX + lobby track

* orb resprite

* sprites

* Add vampire altar mechanics and improve clan heart behavior

Introduces the CP14VampireAltarComponent and altar entity, which doubles blood essence extraction when victims are strapped to the altar. Adds a custom explosion behavior for vampire clan hearts upon destruction, updates construction graphs and recipes for altars, and improves localization. Also refines skill description handling and adjusts vampire bite action text.

* essence get when heart destruction

* Add clan heart damage and destruction announcements

Introduces announcements for when a vampire clan heart is damaged or destroyed, with cooldown to prevent spam. Refactors examination logic and updates localization files for both English and Russian to support new messages and sender formatting.

* glyph adaptation

* resurrection

* Add round end summary for Vampire Clan Battles

Implemented detailed round end text for the Vampire Clan Battles game mode, displaying victory, defeat, or draw outcomes based on surviving factions and population percentage. Refactored alive player percentage logic into a shared method and updated localization files with new outcome messages in English and Russian. Also removed an unused field from the defence condition component.

* Update vampire_cloak.yml

* fix

* fix

* Update portal_glyph.yml
2025-08-22 18:46:28 +03:00

422 lines
12 KiB
C#

using System.Linq;
using System.Numerics;
using System.Text;
using Content.Client._CP14.Skill;
using Content.Client._CP14.Skill.Ui;
using Content.Client._CP14.UserInterface.Systems.NodeTree;
using Content.Client._CP14.UserInterface.Systems.Skill.Window;
using Content.Client.Gameplay;
using Content.Client.UserInterface.Controls;
using Content.Shared._CP14.Skill.Components;
using Content.Shared._CP14.Skill.Prototypes;
using Content.Shared._CP14.Skill.Restrictions;
using Content.Shared.Input;
using Content.Shared._CP14.Input;
using JetBrains.Annotations;
using Robust.Client.Player;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controllers;
using Robust.Client.UserInterface.Controls;
using Robust.Client.Utility;
using Robust.Shared.Input.Binding;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Client._CP14.UserInterface.Systems.Skill;
[UsedImplicitly]
public sealed class CP14SkillUIController : UIController, IOnStateEntered<GameplayState>, IOnStateExited<GameplayState>,
IOnSystemChanged<CP14ClientSkillSystem>
{
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly IEntityManager _entManager = default!;
[UISystemDependency] private readonly CP14ClientSkillSystem _skill = default!;
private CP14SkillWindow? _window;
private EntityUid? _targetPlayer;
private IEnumerable<CP14SkillPrototype> _allSkills = [];
private CP14SkillPrototype? _selectedSkill;
private CP14SkillTreePrototype? _selectedSkillTree;
private MenuButton? SkillButton => UIManager
.GetActiveUIWidgetOrNull<Client.UserInterface.Systems.MenuBar.Widgets.GameTopMenuBar>()
?.CP14SkillButton;
public void OnStateEntered(GameplayState state)
{
DebugTools.Assert(_window == null);
_window = UIManager.CreateWindow<CP14SkillWindow>();
LayoutContainer.SetAnchorPreset(_window, LayoutContainer.LayoutPreset.CenterTop);
CommandBinds.Builder
.Bind(CP14ContentKeyFunctions.CP14OpenSkillMenu,
InputCmdHandler.FromDelegate(_ => ToggleWindow()))
.Register<CP14SkillUIController>();
CacheSkillProto();
_proto.PrototypesReloaded += _ => CacheSkillProto();
_window.LearnButton.OnPressed += _ => _skill.RequestLearnSkill(_playerManager.LocalEntity, _selectedSkill);
_window.GraphControl.OnNodeSelected += SelectNode;
_window.GraphControl.OnOffsetChanged += offset =>
{
_window.ParallaxBackground.Offset = -offset * 0.25f + new Vector2(1000, 1000); //hardcoding is bad
};
}
private void CacheSkillProto()
{
_allSkills = _proto.EnumeratePrototypes<CP14SkillPrototype>();
}
public void OnStateExited(GameplayState state)
{
if (_window != null)
{
_window.GraphControl.OnNodeSelected -= SelectNode;
_window.Dispose();
_window = null;
}
CommandBinds.Unregister<CP14SkillUIController>();
}
public void OnSystemLoaded(CP14ClientSkillSystem system)
{
system.OnSkillUpdate += UpdateState;
_playerManager.LocalPlayerDetached += CharacterDetached;
}
public void OnSystemUnloaded(CP14ClientSkillSystem system)
{
system.OnSkillUpdate -= UpdateState;
_playerManager.LocalPlayerDetached -= CharacterDetached;
}
public void UnloadButton()
{
if (SkillButton is null)
return;
SkillButton.OnPressed -= SkillButtonPressed;
}
public void LoadButton()
{
if (SkillButton is null)
return;
SkillButton.OnPressed += SkillButtonPressed;
if (_window is null)
return;
_window.OnClose += DeactivateButton;
_window.OnOpen += ActivateButton;
}
private void DeactivateButton()
{
SkillButton!.Pressed = false;
}
private void ActivateButton()
{
SkillButton!.Pressed = true;
}
private void SelectNode(CP14NodeTreeElement? node)
{
if (_window is null)
return;
if (_targetPlayer == null)
return;
if (node == null)
{
DeselectNode();
return;
}
if (!_proto.TryIndex<CP14SkillPrototype>(node.NodeKey, out var skill))
{
DeselectNode();
return;
}
SelectNode(skill);
}
private void SelectNode(CP14SkillPrototype? skill)
{
if (skill is null)
{
DeselectNode();
UpdateGraphControl();
return;
}
if (_window is null)
return;
if (_targetPlayer == null)
return;
if (!_proto.TryIndex(skill.Tree, out var indexedTree))
return;
if (!_proto.TryIndex(indexedTree.SkillType, out var indexedSkillType))
return;
_selectedSkill = skill;
_window.SkillName.Text = _skill.GetSkillName(skill);
_window.SkillDescription.SetMessage(GetSkillDescription(skill));
_window.SkillFree.Visible = _skill.HaveFreeSkill(_targetPlayer.Value, skill);
_window.SkillView.Texture = skill.Icon.Frame0();
_window.LearnButton.Disabled = !_skill.CanLearnSkill(_targetPlayer.Value, skill);
_window.SkillPointText.Text =
Loc.GetString("cp14-skill-menu-learncost", ("type", Loc.GetString(indexedSkillType.Name)));
_window.SkillCost.Text = skill.LearnCost.ToString();
_window.SkillPointIcon.Texture = indexedSkillType.Icon?.Frame0();
UpdateGraphControl();
}
private void DeselectNode()
{
if (_window is null)
return;
_window.SkillName.Text = string.Empty;
_window.SkillDescription.Text = string.Empty;
_window.SkillFree.Visible = false;
_window.SkillView.Texture = null;
_window.LearnButton.Disabled = true;
}
private FormattedMessage GetSkillDescription(CP14SkillPrototype skill)
{
var msg = new FormattedMessage();
if (_targetPlayer == null)
return msg;
var sb = new StringBuilder();
//Description
sb.Append(_skill.GetSkillDescription(skill) + "\n \n");
if (!_skill.HaveSkill(_targetPlayer.Value, skill))
{
//Restrictions
foreach (var req in skill.Restrictions)
{
var color = req.Check(_entManager, _targetPlayer.Value) ? "green" : "red";
sb.Append($"- [color={color}]{req.GetDescription(_entManager, _proto)}[/color]\n");
}
}
msg.TryAddMarkup(sb.ToString(), out _);
return msg;
}
private void UpdateGraphControl()
{
if (_window is null)
return;
if (_selectedSkillTree == null)
return;
if (!EntityManager.TryGetComponent<CP14SkillStorageComponent>(_targetPlayer, out var storage))
return;
if (!_proto.TryIndex(_selectedSkillTree.SkillType, out var indexedSkillType))
return;
var skillPointsMap = storage.SkillPoints;
_window.LevelLabel.Text = skillPointsMap.TryGetValue(_selectedSkillTree.SkillType, out var skillContainer)
? $"{Loc.GetString(indexedSkillType.Name)}: {skillContainer.Sum}/{skillContainer.Max}"
: $"{Loc.GetString(indexedSkillType.Name)}: 0/0";
_window.LevelTexture.Texture = indexedSkillType.Icon?.Frame0();
HashSet<CP14NodeTreeElement> nodeTreeElements = new();
HashSet<(string, string)> nodeTreeEdges = new();
var learned = storage.LearnedSkills;
foreach (var skill in _allSkills)
{
if (skill.Tree != _selectedSkillTree)
continue;
var hide = false;
foreach (var req in skill.Restrictions)
{
if (req.HideFromUI && !req.Check(_entManager, _targetPlayer.Value))
{
hide = true;
break;
}
switch (req)
{
case NeedPrerequisite prerequisite:
if (!_proto.TryIndex(prerequisite.Prerequisite, out var prerequisiteSkill))
continue;
if (prerequisiteSkill.Tree != _selectedSkillTree)
continue;
nodeTreeEdges.Add((skill.ID, prerequisiteSkill.ID));
break;
}
}
if (!hide)
{
var nodeTreeElement = new CP14NodeTreeElement(
skill.ID,
gained: learned.Contains(skill),
active: _skill.CanLearnSkill(_targetPlayer.Value, skill),
skill.SkillUiPosition * 25f,
skill.Icon);
nodeTreeElements.Add(nodeTreeElement);
}
}
_window.GraphControl.UpdateState(
new CP14NodeTreeUiState(
nodes: nodeTreeElements,
edges: nodeTreeEdges,
frameIcon: _selectedSkillTree.FrameIcon,
hoveredIcon: _selectedSkillTree.HoveredIcon,
selectedIcon: _selectedSkillTree.SelectedIcon,
learnedIcon: _selectedSkillTree.LearnedIcon
)
);
}
private void UpdateState(EntityUid player)
{
_targetPlayer = player;
if (_window is null)
return;
if (!EntityManager.TryGetComponent<CP14SkillStorageComponent>(_targetPlayer, out var storage))
return;
//If tree not selected, select the first one
if (_selectedSkillTree == null)
{
var firstTree = storage.AvailableSkillTrees.First();
SelectTree(firstTree); // Set the first tree from the player's progress
}
if (_selectedSkillTree == null)
return;
// Reselect for update state
SelectNode(_selectedSkill);
UpdateGraphControl();
_window.TreeTabsContainer.RemoveAllChildren();
foreach (var tree in storage.AvailableSkillTrees)
{
if (!_proto.TryIndex(tree, out var indexedTree))
return;
if (!_proto.TryIndex(indexedTree.SkillType, out var indexedSkillType))
return;
float learnedPoints = 0;
foreach (var skillId in storage.LearnedSkills)
{
//TODO: Loop indexing each skill is bad
if (_proto.TryIndex(skillId, out var skill) && skill.Tree == tree)
{
if (_skill.HaveFreeSkill(_targetPlayer.Value, skillId))
continue;
learnedPoints += skill.LearnCost;
}
}
var treeButton2 = new CP14SkillTreeButtonControl(indexedTree.Color,
Loc.GetString(indexedTree.Name),
learnedPoints,
indexedSkillType.Icon?.Frame0());
treeButton2.ToolTip = Loc.GetString(indexedTree.Desc ?? string.Empty);
treeButton2.OnPressed += () =>
{
SelectTree(indexedTree);
};
_window.TreeTabsContainer.AddChild(treeButton2);
}
}
private void SelectTree(ProtoId<CP14SkillTreePrototype> tree)
{
if (_window == null)
return;
if (!_proto.TryIndex(tree, out var indexedTree))
return;
_selectedSkillTree = indexedTree;
_window.ParallaxBackground.ParallaxPrototype = indexedTree.Parallax;
_window.TreeName.Text = Loc.GetString(indexedTree.Name);
UpdateGraphControl();
}
private void CharacterDetached(EntityUid uid)
{
CloseWindow();
}
private void SkillButtonPressed(BaseButton.ButtonEventArgs args)
{
ToggleWindow();
}
private void CloseWindow()
{
_window?.Close();
}
private void ToggleWindow()
{
if (_window == null)
return;
if (SkillButton != null)
{
SkillButton.SetClickPressed(!_window.IsOpen);
}
if (_window.IsOpen)
{
CloseWindow();
}
else
{
_skill.RequestSkillData();
_window.Open();
}
}
}