From 9505427b6418868f48a232eca5a6e97e2dbcff72 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 28 Jan 2024 11:58:58 +0100 Subject: [PATCH] update --- backend/MemeBE/Models/Player.cs | 46 +++++++++++++++++++++------------ backend/MemeBE/hubs/GameHub.cs | 5 ++-- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/backend/MemeBE/Models/Player.cs b/backend/MemeBE/Models/Player.cs index 3b6339c..1548b57 100644 --- a/backend/MemeBE/Models/Player.cs +++ b/backend/MemeBE/Models/Player.cs @@ -36,9 +36,11 @@ public Result AddCardToPersistentSlot(Card card) public int PrepareLaugh(int value, out List cardsToDelete) { - cardsToDelete = new List(); int result = value; - foreach (var card in PersistentSlot) + cardsToDelete = new List(); + var cardsCopy = new List(PersistentSlot); + PersistentSlot.Clear(); + foreach (var card in cardsCopy) { foreach (Effect effect in card.EffectList) { @@ -47,6 +49,10 @@ public int PrepareLaugh(int value, out List cardsToDelete) result += effect.Value; cardsToDelete.Add(card.DeckId); } + else + { + PersistentSlot.Add(card); + } } } @@ -55,9 +61,9 @@ public int PrepareLaugh(int value, out List cardsToDelete) return result; } - public void ReceiveLaugh(int laughValue,out List cardsToDelete) + public int PrepareGrumpy(int value, out List cardsToDelete) { - var laughReceived = laughValue; + int result = value; cardsToDelete = new List(); var cardsCopy = new List(PersistentSlot); PersistentSlot.Clear(); @@ -65,42 +71,48 @@ public void ReceiveLaugh(int laughValue,out List cardsToDelete) { foreach (Effect effect in card.EffectList) { - if (effect.EffectName.Equals("Shield")) + if (effect.EffectName.Equals("Buff")) { - Console.WriteLine("Shiled used laugh"); - laughReceived -= effect.Value; + result += effect.Value; cardsToDelete.Add(card.DeckId); } else { PersistentSlot.Add(card); } - + } } - laughReceived = laughReceived < 0 ? 0 : laughReceived; - LaughPoints += laughReceived; + return result; } - public int PrepareGrumpy(int value, out List cardsToDelete) + public void ReceiveLaugh(int laughValue,out List cardsToDelete) { - int result = value; + var laughReceived = laughValue; cardsToDelete = new List(); - foreach (var card in PersistentSlot) + var cardsCopy = new List(PersistentSlot); + PersistentSlot.Clear(); + foreach (var card in cardsCopy) { foreach (Effect effect in card.EffectList) { - if (effect.EffectName.Equals("Buff")) + if (effect.EffectName.Equals("Shield")) { - result += effect.Value; + Console.WriteLine("Shiled used laugh"); + laughReceived -= effect.Value; cardsToDelete.Add(card.DeckId); } + else + { + PersistentSlot.Add(card); + } } } - - return result; + laughReceived = laughReceived < 0 ? 0 : laughReceived; + LaughPoints += laughReceived; + } public void ReceiveGrumpy(int grumpyValue,out List cardsToDelete) diff --git a/backend/MemeBE/hubs/GameHub.cs b/backend/MemeBE/hubs/GameHub.cs index bb8fab5..65b159c 100644 --- a/backend/MemeBE/hubs/GameHub.cs +++ b/backend/MemeBE/hubs/GameHub.cs @@ -340,7 +340,7 @@ public async Task MakeGrumpy(Room room, int value, string? targetNick = null) Console.WriteLine("MakeGrumpy - To All"); foreach (var player in room.Players.Values) { - Console.WriteLine("Player " +player.Nick +" is gone take laugh: " + grumpyValue); + Console.WriteLine("Player " +player.Nick +" is gone take grumpy: " + grumpyValue); player.ReceiveGrumpy(grumpyValue, out List cardsToDeleteFromShieldBuff); // Emit await Clients.Client(player.ConnectionID).SendAsync("TakeGrumpy",player.LaughPoints); @@ -359,8 +359,7 @@ await Clients.Group(room.RoomId) } else // Single player { - Console.WriteLine("MakeGrumpy - To: " + targetNick); - Console.WriteLine("Player " +targetNick +" is gone take laugh: " + grumpyValue); + Console.WriteLine("Player " +targetNick +" is gone take grumpy " + grumpyValue); var targetPlayer = room.GetPlayerByNick(targetNick); targetPlayer.ReceiveGrumpy(grumpyValue,out List cardsToDeleteFromShieldBuff); // emit