Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Timmlion committed Jan 28, 2024
1 parent f1bf3b3 commit 9505427
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
46 changes: 29 additions & 17 deletions backend/MemeBE/Models/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ public Result AddCardToPersistentSlot(Card card)

public int PrepareLaugh(int value, out List<int?> cardsToDelete)
{
cardsToDelete = new List<int?>();
int result = value;
foreach (var card in PersistentSlot)
cardsToDelete = new List<int?>();
var cardsCopy = new List<Card>(PersistentSlot);
PersistentSlot.Clear();
foreach (var card in cardsCopy)
{
foreach (Effect effect in card.EffectList)
{
Expand All @@ -47,6 +49,10 @@ public int PrepareLaugh(int value, out List<int?> cardsToDelete)
result += effect.Value;
cardsToDelete.Add(card.DeckId);
}
else
{
PersistentSlot.Add(card);
}

}
}
Expand All @@ -55,52 +61,58 @@ public int PrepareLaugh(int value, out List<int?> cardsToDelete)
return result;
}

public void ReceiveLaugh(int laughValue,out List<int?> cardsToDelete)
public int PrepareGrumpy(int value, out List<int?> cardsToDelete)
{
var laughReceived = laughValue;
int result = value;
cardsToDelete = new List<int?>();
var cardsCopy = new List<Card>(PersistentSlot);
PersistentSlot.Clear();
foreach (var card in cardsCopy)
{
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<int?> cardsToDelete)
public void ReceiveLaugh(int laughValue,out List<int?> cardsToDelete)
{
int result = value;
var laughReceived = laughValue;
cardsToDelete = new List<int?>();
foreach (var card in PersistentSlot)
var cardsCopy = new List<Card>(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<int?> cardsToDelete)
Expand Down
5 changes: 2 additions & 3 deletions backend/MemeBE/hubs/GameHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int?> cardsToDeleteFromShieldBuff);
// Emit
await Clients.Client(player.ConnectionID).SendAsync("TakeGrumpy",player.LaughPoints);
Expand All @@ -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<int?> cardsToDeleteFromShieldBuff);
// emit
Expand Down

0 comments on commit 9505427

Please sign in to comment.