From af69421c60b43d641879421b70d58911daaa8de2 Mon Sep 17 00:00:00 2001
From: auroxy <romaric.blonde@laposte.net>
Date: Mon, 5 Aug 2019 17:03:38 +0200
Subject: [PATCH] Correction draw limit

---
 Assets/Scripts/Cards/Card.cs |  4 ++--
 Assets/Scripts/Deck/Deck.cs  | 13 ++++++++++++-
 Assets/Scripts/Deck/Dump.cs  | 30 +++++++++++++-----------------
 Assets/Scripts/Deck/Hand.cs  | 17 ++++++++---------
 4 files changed, 35 insertions(+), 29 deletions(-)

diff --git a/Assets/Scripts/Cards/Card.cs b/Assets/Scripts/Cards/Card.cs
index 9e58092..5591d62 100644
--- a/Assets/Scripts/Cards/Card.cs
+++ b/Assets/Scripts/Cards/Card.cs
@@ -62,6 +62,7 @@ public class Card : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
             if (Player.Instance.Energy < mCost)
                 return;
             Player.Instance.Energy -= mCost;
+            gameObject.GetComponentInParent<Hand>().Discard(this);
             CardEvent<Card>.Trigger(Event.CARD_PLAYED, this);
             Effect endEffect = null;
             for (int i = 0; i < mEffectMultiplicator; i++)
@@ -79,8 +80,7 @@ public class Card : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
                     break;
                 }
             }
-            CardEvent<Card>.Trigger(Event.CARD_EFFECT_APPLIED, this);
-            gameObject.GetComponentInParent<Hand>().Discard(this);
+            CardEvent<Card>.Trigger(Event.CARD_EFFECT_APPLIED, this);           
         }
         else
         {
diff --git a/Assets/Scripts/Deck/Deck.cs b/Assets/Scripts/Deck/Deck.cs
index e965846..b4d7a98 100644
--- a/Assets/Scripts/Deck/Deck.cs
+++ b/Assets/Scripts/Deck/Deck.cs
@@ -8,6 +8,8 @@ public class Deck : MonoBehaviour
     private List<Card> totalCards;
 
     [SerializeField]
+    private List<Card> deckPreview;
+
     public Stack<Card> currentDeck;
 
     [SerializeField]
@@ -20,12 +22,14 @@ public class Deck : MonoBehaviour
         {
             totalCards = new List<Card>(GetComponentsInChildren<Card>());
             currentDeck = new Stack<Card>();
+           
             foreach (Card card in totalCards)
             {
                 initializer.InitCard(card);
                 card.gameObject.SetActive(false);
                 currentDeck.Push(card);
             }
+            deckPreview = currentDeck.ToList();
         }
     }
 
@@ -35,8 +39,13 @@ public class Deck : MonoBehaviour
         if(currentDeck.Count == 0)
         {
             Reshuffle();
+
         }
-        return currentDeck.Pop();
+        Card result = currentDeck.Pop();
+        deckPreview = currentDeck.ToList();
+        return result;
+
+
     }
 
 
@@ -70,6 +79,7 @@ public class Deck : MonoBehaviour
             totalCards.Insert(j, card);
         }
         PutCardInDeck(card);
+        deckPreview = currentDeck.ToList();
     }
 
     public void PutCardInDeck(Card card)
@@ -97,6 +107,7 @@ public class Deck : MonoBehaviour
             Card tmp = dump.Pop();
             PutCardInDeck(tmp);
             ShuffleDeck();
+            deckPreview = currentDeck.ToList();
         }
         if(currentDeck.Count == 0)
         {
diff --git a/Assets/Scripts/Deck/Dump.cs b/Assets/Scripts/Deck/Dump.cs
index 028f065..9b4bb9e 100644
--- a/Assets/Scripts/Deck/Dump.cs
+++ b/Assets/Scripts/Deck/Dump.cs
@@ -1,9 +1,13 @@
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
+using System.Linq;
 
 public class Dump : MonoBehaviour
 {
+    [SerializeField]
+    private List<Card> dumpPreview;
+
     public Stack<Card> dumpStack;
 
     public static Dump Instance
@@ -24,6 +28,7 @@ public class Dump : MonoBehaviour
         }
 
         dumpStack = new Stack<Card>();
+        dumpPreview = dumpStack.ToList();
     }
 
     public void Discard(Card card)
@@ -38,24 +43,12 @@ public class Dump : MonoBehaviour
     {
         CardEvent<Card>.Trigger(Event.CARD_DISCARD, card);
         card.transform.SetParent(transform);
-        card.gameObject.SetActive(false); dumpStack.Push(card);
-    }
+        card.gameObject.SetActive(false);
+        dumpStack.Push(card);
+        dumpPreview = dumpStack.ToList();
 
-    public void Init()
-    {
-        if (Instance == null)
-        {
-            Instance = this;
-        }
-        else if(Instance != this)
-        {
-            DestroyImmediate(this);
-        }
-
-        dumpStack = new Stack<Card>();
     }
 
-
     public Stack<Card> Recycle ()
     {
         Stack<Card> result = new Stack<Card>();
@@ -64,13 +57,16 @@ public class Dump : MonoBehaviour
         {
             result.Push(dumpStack.Pop());
         }
-
+        dumpPreview = dumpStack.ToList();
         return result;
     }
 
     public Card Draw()
     {
-        return dumpStack.Pop();
+        
+        Card result = dumpStack.Pop();
+        dumpPreview = dumpStack.ToList();
+        return result; 
     }
 
 
diff --git a/Assets/Scripts/Deck/Hand.cs b/Assets/Scripts/Deck/Hand.cs
index 1715686..475b27a 100644
--- a/Assets/Scripts/Deck/Hand.cs
+++ b/Assets/Scripts/Deck/Hand.cs
@@ -33,13 +33,12 @@ public class Hand : MonoBehaviour
 
     public void Draw()
     {
-        Debug.Log("Drawing");
 
         Card newCard = deck.Draw();
-        
-        if(hand.Count < MaxHandSize)
+        hand.Add(newCard);
+        if (hand.Count <= MaxHandSize)
         {
-            hand.Add(newCard);
+            
             newCard.transform.SetParent(transform);
             newCard.gameObject.SetActive(true);
             newCard.GetComponent<CardUi>().Show();
@@ -47,17 +46,17 @@ public class Hand : MonoBehaviour
         }
         else
         {
-            Discard(newCard);
+
+            Discard(newCard,true);
         }
     }
 
     public void ExtraDraw()
     {
         Card newCard = deck.Draw();
-
-        if (hand.Count < MaxHandSize)
+        hand.Add(newCard);
+        if (hand.Count <= MaxHandSize)
         {
-            hand.Add(newCard);
             newCard.transform.SetParent(transform);
             newCard.gameObject.SetActive(true);
             newCard.GetComponent<CardUi>().Show();
@@ -65,7 +64,7 @@ public class Hand : MonoBehaviour
         }
         else
         {
-            Discard(newCard);
+            Discard(newCard,true);
         }
     }
 
-- 
GitLab