using System; using System.Linq; using BriarQueen.Data.Identifiers; using BriarQueen.Framework.Coordinators.Events; using BriarQueen.Framework.Events.Gameplay; using BriarQueen.Framework.Events.UI; using BriarQueen.Framework.Managers.Interaction.Data; using BriarQueen.Framework.Managers.Player; using BriarQueen.Framework.Managers.Player.Data; using Cysharp.Threading.Tasks; namespace BriarQueen.Game.Items.Interactions.ChapterOne.Village { [Serializable] public class PliersInteraction : BaseInteraction { public override UniTask TryUseWith( ItemDataSo self, ItemDataSo other, PlayerManager playerManager, EventCoordinator eventCoordinator) { if (other == null) { eventCoordinator.Publish(new DisplayInteractEvent(InteractEventIDs.Get(ItemInteractKey.CantUseItem))); return UniTask.FromResult(false); } var pliersId = ItemIDs.Get(ItemKey.Pliers); var emeraldAmuletId = ItemIDs.Get(ItemKey.EmeraldAmulet); var rubyRingId = ItemIDs.Get(ItemKey.RubyRing); var diamondTiaraId = ItemIDs.Get(ItemKey.DiamondTiara); var emeraldId = ItemIDs.Get(ItemKey.Emerald); var rubyId = ItemIDs.Get(ItemKey.Ruby); var diamondId = ItemIDs.Get(ItemKey.Diamond); var success = other.UniqueID switch { var id when id == emeraldAmuletId => ExtractGem( emeraldId, emeraldAmuletId, "You carefully pull the emerald out of the amulet."), var id when id == rubyRingId => ExtractGem( rubyId, rubyRingId, "You carefully pull the ruby out of the ring."), var id when id == diamondTiaraId => ExtractGem( diamondId, diamondTiaraId, "You carefully pull the diamond out of the tiara."), _ => FailInteraction() }; return UniTask.FromResult(success); bool ExtractGem(string gemId, string sourceItemId, string message) { eventCoordinator.Publish(new DisplayInteractEvent(message)); playerManager.CollectItem(gemId); playerManager.RemoveItem(sourceItemId); eventCoordinator.Publish(new SelectedItemChangedEvent(null)); CheckIfPliersBreak(); return true; } bool FailInteraction() { eventCoordinator.Publish(new DisplayInteractEvent(InteractEventIDs.Get(ItemInteractKey.CantUseItem))); return false; } void CheckIfPliersBreak() { var collectedItems = playerManager.GetAllCollectedItems(); var hasEmerald = collectedItems.Any(x => x.UniqueID == emeraldId); var hasRuby = collectedItems.Any(x => x.UniqueID == rubyId); var hasDiamond = collectedItems.Any(x => x.UniqueID == diamondId); if (hasEmerald && hasRuby && hasDiamond) { eventCoordinator.Publish(new DisplayInteractEvent(InteractEventIDs.Get(ItemInteractKey.PliersSnapped))); playerManager.RemoveItem(pliersId); eventCoordinator.Publish(new SelectedItemChangedEvent(null)); } } } } }