-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port Cool Punpun #1157
Merged
Merged
Port Cool Punpun #1157
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Content.Server.Punpun; | ||
|
||
[RegisterComponent] | ||
public sealed partial class PunpunComponent : Component | ||
{ | ||
/// How many rounds Punpun will be around for before disappearing with a note | ||
[DataField] | ||
public int Lifetime = 14; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
using System.Linq; | ||
using Content.Server.GameTicking; | ||
using Content.Shared.Containers.ItemSlots; | ||
using Content.Shared.Inventory; | ||
using Content.Shared.Mobs; | ||
using Content.Shared.Mobs.Components; | ||
using Robust.Server.GameObjects; | ||
|
||
namespace Content.Server.Punpun; | ||
|
||
public sealed class PunpunSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly InventorySystem _inventory = default!; | ||
[Dependency] private readonly ServerMetaDataSystem _meta = default!; | ||
|
||
private (int, string, string, string) _punpunData = (1, string.Empty, string.Empty, string.Empty); | ||
|
||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<PunpunComponent, ComponentStartup>(OnRoundStart); | ||
SubscribeLocalEvent<RoundEndTextAppendEvent>(OnRoundEnd); | ||
} | ||
|
||
|
||
// Checks if the Punpun data has any items to equip, and names the Punpun upon initialization | ||
private void OnRoundStart(EntityUid uid, PunpunComponent component, ComponentStartup args) | ||
{ | ||
if (_punpunData.Item1 > component.Lifetime) | ||
{ | ||
EntityManager.SpawnEntity("PaperWrittenPunpunNote", Transform(uid).Coordinates); | ||
EntityManager.QueueDeleteEntity(uid); | ||
_punpunData = (1, string.Empty, string.Empty, string.Empty); | ||
|
||
return; | ||
} | ||
|
||
var meta = MetaData(uid); | ||
_meta.SetEntityName(uid, $"{meta.EntityName} {ToRomanNumeral(_punpunData.Item1)}", meta); | ||
|
||
if (!EntityManager.TryGetComponent<InventoryComponent>(uid, out _)) | ||
return; | ||
EquipItem(uid, "head", _punpunData.Item2); | ||
EquipItem(uid, "mask", _punpunData.Item3); | ||
EquipItem(uid, "jumpsuit", _punpunData.Item4); | ||
} | ||
|
||
// Checks if Punpun exists, and is alive at round end | ||
// If so, stores the items and increments the Punpun count | ||
private void OnRoundEnd(RoundEndTextAppendEvent ev) | ||
{ | ||
// I couldn't find a method to get a single entity, so this just enumerates over the first and disposes it | ||
var punpunComponents = EntityManager.EntityQueryEnumerator<PunpunComponent>(); | ||
punpunComponents.MoveNext(out var punpun, out _); | ||
|
||
if (!EntityManager.TryGetComponent<MobStateComponent>(punpun, out var mobState) | ||
|| mobState.CurrentState == MobState.Dead) | ||
_punpunData = (1, string.Empty, string.Empty, string.Empty); | ||
|
||
_punpunData.Item1++; | ||
|
||
if (EntityManager.HasComponent<InventoryComponent>(punpun)) | ||
{ | ||
_punpunData.Item2 = CheckSlot(punpun, "head"); | ||
_punpunData.Item3 = CheckSlot(punpun, "mask"); | ||
_punpunData.Item4 = CheckSlot(punpun, "jumpsuit"); | ||
} | ||
|
||
punpunComponents.Dispose(); | ||
} | ||
|
||
// Equips an item to a slot, and names it. | ||
private void EquipItem(EntityUid uid, string slot, string item) | ||
{ | ||
if (item == string.Empty) | ||
return; | ||
|
||
var itemEnt = EntityManager.SpawnEntity(item, EntityManager.GetComponent<TransformComponent>(uid).Coordinates); | ||
if (_inventory.TryEquip(uid, itemEnt, slot, true, true)) | ||
_meta.SetEntityName(itemEnt, $"{MetaData(uid).EntityName}'s {MetaData(itemEnt).EntityName}"); | ||
else | ||
EntityManager.DeleteEntity(itemEnt); | ||
} | ||
|
||
// Checks if an item exists in a slot, and returns its name | ||
private string CheckSlot(EntityUid uid, string slot) | ||
{ | ||
return _inventory.TryGetSlotEntity(uid, slot, out var item) | ||
? EntityManager.GetComponent<MetaDataComponent>(item.Value).EntityPrototype!.ID | ||
: string.Empty; | ||
} | ||
|
||
|
||
// Punpun, the lord of Roman Numerals | ||
public static List<string> RomanNumerals = new() { "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" }; | ||
public static List<int> Numerals = new() { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 }; | ||
|
||
public static string ToRomanNumeral(int number) | ||
{ | ||
var romanNumeral = string.Empty; | ||
while (number > 0) | ||
{ | ||
// Find the biggest numeral that is less than equal to number | ||
var index = Numerals.FindIndex(x => x <= number); | ||
// Subtract its value from your number | ||
number -= Numerals[index]; | ||
// Add it onto the end of your roman numeral | ||
romanNumeral += RomanNumerals[index]; | ||
} | ||
return romanNumeral; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should really be a named struct/class