using Content.Server.Ghost.Roles.Components; using Content.Shared.ActionBlocker; using Content.Shared.Actions; using Content.Shared.Examine; using Content.Shared.Mobs; using Content.Shared.Mobs.Components; using Content.Shared.Popups; using Content.Shared.Verbs; using Content.Shared._White.Events; using Robust.Shared.Player; namespace Content.Server._White.Other.CustomFluffSystems.Pets; public sealed class PetSummonSystem : EntitySystem { [Dependency] private readonly ActionBlockerSystem _blocker = default!; [Dependency] private readonly SharedPopupSystem _popupSystem = default!; [Dependency] private readonly IEntityManager _entityManager = default!; private IReadOnlyDictionary MobMap = new Dictionary() { { "Wanderer_", "KommandantPetSpider" }, }; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(GetSummonAction); SubscribeLocalEvent(OnExamine); SubscribeLocalEvent>(AddSummonVerb); SubscribeLocalEvent(OnSummon); SubscribeLocalEvent(OnGhostSummon); } private void OnGhostSummon(EntityUid uid, PetSummonComponent component, PetGhostSummonActionEvent args) { AttemptSummon(component, args.Performer, true); } private void OnSummon(EntityUid uid, PetSummonComponent component, PetSummonActionEvent args) { AttemptSummon(component, args.Performer, false); } private void AddSummonVerb(EntityUid uid, PetSummonComponent component, GetVerbsEvent args) { if (!args.CanInteract || !args.CanAccess) return; AlternativeVerb verb = new() { Act = () => { AttemptSummon(component, args.User, false); }, Text = "Призвать питомца", Priority = 2 }; AlternativeVerb ghostVerb = new() { Act = () => { AttemptSummon(component, args.User, true); }, Text = "Призвать питомца-призрак", Priority = 2 }; args.Verbs.Add(verb); args.Verbs.Add(ghostVerb); } private void OnExamine(EntityUid uid, PetSummonComponent component, ExaminedEvent args) { args.PushMarkup($"Осталось призывов: {component.UsesLeft}"); } private void AttemptSummon(PetSummonComponent component, EntityUid user, bool ghostRole) { if (!_blocker.CanInteract(user, component.Owner)) return; string? mobProto = null; if (TryComp(user, out var actorComponent)) { var userKey = actorComponent.PlayerSession.Name; if (!MobMap.TryGetValue(userKey, out var proto)) { _popupSystem.PopupEntity("Вы не достойны", user, PopupType.Medium); return; } mobProto = proto; } if (component.UsesLeft == 0) { _popupSystem.PopupEntity("Больше нет зарядов!", user, PopupType.Medium); return; } if (component.SummonedEntity != null) { if (!TryComp(component.SummonedEntity, out var mobState)) { component.SummonedEntity = null; } else { if (mobState.CurrentState is MobState.Dead or MobState.Invalid) component.SummonedEntity = null; else { _popupSystem.PopupEntity("Ваш питомец уже призван", user, PopupType.Medium); return; } } } if (mobProto != null) SummonPet(user, component, mobProto, ghostRole); } private void SummonPet(EntityUid user, PetSummonComponent component, string mobProto, bool ghostRole) { var transform = CompOrNull(user)?.Coordinates; if (transform == null) return; var entity = _entityManager.SpawnEntity(mobProto, transform.Value); component.UsesLeft--; component.SummonedEntity = entity; if (ghostRole) SetupGhostRole(entity, user); else RemComp(entity); } private void SetupGhostRole(EntityUid entity, EntityUid user) { EnsureComp(entity); if (!TryComp(entity, out var ghostRole)) return; var meta = MetaData(user); ghostRole.RoleName = $"Питомец {meta.EntityName}"; ghostRole.RoleDescription = $"Следуйте за хозяином - {meta.EntityName} и выполняйте его приказы"; ghostRole.RoleRules = $"Вы должны до самого конца следовать за своим хозяином - {meta.EntityName} и послушно выполнять его приказы, иначе можете быть уничтожены."; } private void GetSummonAction(EntityUid uid, PetSummonComponent component, GetItemActionsEvent args) { args.AddAction(ref component.PetSummonActionEntity, component.PetSummonAction); args.AddAction(ref component.PetGhostSummonActionEntity, component.PetGhostSummonAction); } }