private void CleanUpCard(CardDef def)
 {
     if (def != null)
     {
         UnityEngine.Object.Destroy(def);
     }
 }
Exemple #2
0
        protected override void OnCardOver(object sender, CardsEventArgs e)
        {
            base.OnCardOver(sender, e);
            e.CardSize = CardSize;

            if (!Program.GameSettings.UseTwoSidedTable)
            {
                return;
            }
            CardDef cardDef  = Program.Game.Definition.CardDefinition;
            var     cardCtrl = (CardControl)e.OriginalSource;
            Card    baseCard = cardCtrl.Card;
            double  mouseY   = Mouse.GetPosition(cardsView).Y;
            double  baseY    = (cardCtrl.IsInverted ||
                                (Player.LocalPlayer.InvertedTable && !cardCtrl.IsOnTableCanvas))
                               ? mouseY - cardDef.Height + e.MouseOffset.Y
                               : mouseY - e.MouseOffset.Y;

            if (baseCard == null)
            {
                return;
            }
            foreach (CardDragAdorner adorner in e.Adorners)
            {
                if (adorner == null || adorner.SourceCard == null || adorner.SourceCard.Card == null)
                {
                    continue;
                }
                double y = baseY + adorner.SourceCard.Card.Y - baseCard.Y;
                adorner.OnHoverRequestInverted = IsInInvertedZone(y) ^ Player.LocalPlayer.InvertedTable;
            }
        }
    private void SetInfo(string name, TAG_CLASS buttonClass, CardDef cardDef, int missionID, long deckID, bool flip)
    {
        this.SetMissionID(missionID);
        this.SetDeckID(deckID);
        this.SetButtonClass(buttonClass);
        Material practiceAIPortrait = cardDef.GetPracticeAIPortrait();

        if (flip)
        {
            this.GetHiddenNameMesh().Text = name;
            if (practiceAIPortrait != null)
            {
                this.SetHiddenMaterial(practiceAIPortrait);
            }
            this.Flip();
        }
        else
        {
            if (this.m_infoSet)
            {
                UnityEngine.Debug.LogWarning("PracticeAIButton.SetInfo() - button is being re-initialized!");
            }
            this.m_infoSet = true;
            if (practiceAIPortrait != null)
            {
                this.SetShowingMaterial(practiceAIPortrait);
            }
            this.GetShowingNameMesh().Text = name;
            base.SetOriginalLocalPosition();
        }
        this.m_covered = false;
        this.GetShowingCover().GetComponent <Renderer>().enabled = false;
    }
Exemple #4
0
        private void BuildReferences(AssestFile bundle)
        {
            foreach (var obj in bundle.Objects)
            {
                var unityClass = (UnityClass)obj.Info.ClassId;
                var data       = BinaryBlock.Create(obj.Buffer);
                switch (unityClass)
                {
                case UnityClass.GameObject:
                    _gameObjects[obj.Id] = new GameObject(data);
                    break;

                case UnityClass.MonoBehaviour:
                    // In this bundle, its a HS CardDef, SoundDef, HiddenCard
                    var cd = new CardDef(data);
                    if (!cd.FailedToLoad)                             // only want carddef (Hack)
                    {
                        _cardDefObjects[obj.Id] = cd;
                    }
                    break;

                case UnityClass.Material:
                    _materialObjects[obj.Id] = new GameMaterial(data);
                    break;

                default:
                    break;
                }
            }
        }
 private void UpdatePortrait()
 {
     if ((this.m_cardFlair != null) && (this.m_fullDef != null))
     {
         CardDef cardDef = this.m_fullDef.GetCardDef();
         if (cardDef != null)
         {
             Material deckPickerPortrait = cardDef.GetDeckPickerPortrait();
             if (deckPickerPortrait != null)
             {
                 DeckPickerHero component = base.GetComponent <DeckPickerHero>();
                 Material       premiumPortraitMaterial = cardDef.GetPremiumPortraitMaterial();
                 if ((this.m_cardFlair.Premium == TAG_PREMIUM.GOLDEN) && (premiumPortraitMaterial != null))
                 {
                     component.m_PortraitMesh.GetComponent <Renderer>().material = premiumPortraitMaterial;
                     component.m_PortraitMesh.GetComponent <Renderer>().material.mainTextureOffset = deckPickerPortrait.mainTextureOffset;
                     component.m_PortraitMesh.GetComponent <Renderer>().material.mainTextureScale  = deckPickerPortrait.mainTextureScale;
                     component.m_PortraitMesh.GetComponent <Renderer>().material.SetTexture("_ShadowTex", null);
                     if (!this.m_seed.HasValue)
                     {
                         this.m_seed = new float?(UnityEngine.Random.value);
                     }
                     if (component.m_PortraitMesh.GetComponent <Renderer>().material.HasProperty("_Seed"))
                     {
                         component.m_PortraitMesh.GetComponent <Renderer>().material.SetFloat("_Seed", this.m_seed.Value);
                     }
                 }
                 else
                 {
                     component.m_PortraitMesh.GetComponent <Renderer>().sharedMaterial = deckPickerPortrait;
                 }
             }
         }
     }
 }
Exemple #6
0
        public List <int> CreateOnTable(string modelId, int x, int y, bool persist, int quantity)
        {
            var result = new List <int>();

            Guid modelGuid;

            if (!Guid.TryParse(modelId, out modelGuid))
            {
                return(result); // e.g. modelId may be null if the cloned card is face down.
            }
            _engine.Invoke(() =>
            {
                CardModel model = Database.GetCardById(modelGuid);
                if (model == null)
                {
                }
                else
                {
                    var ids    = new int[quantity];
                    var keys   = new ulong[quantity];
                    var models = new Guid[quantity];
                    int[] xs   = new int[quantity], ys = new int[quantity];

                    CardDef def = Program.Game.Definition.CardDefinition;

                    if (Player.LocalPlayer.InvertedTable)
                    {
                        x -= def.Width;
                        y -= def.Height;
                    }
                    var offset = (int)(Math.Min(def.Width, def.Height) * 0.2);
                    if (Program.GameSettings.UseTwoSidedTable && TableControl.IsInInvertedZone(y))
                    {
                        offset = -offset;
                    }

                    for (int i = 0; i < quantity; ++i)
                    {
                        ulong key = ((ulong)Crypto.PositiveRandom()) << 32 | model.Id.Condense();
                        int id    = Program.Game.GenerateCardId();

                        new CreateCard(Player.LocalPlayer, id, key, true, model, x, y, !persist).Do();

                        ids[i]    = id;
                        keys[i]   = key;
                        models[i] = model.Id;
                        xs[i]     = x;
                        ys[i]     = y;
                        result.Add(id);

                        x += offset;
                        y += offset;
                    }

                    Program.Client.Rpc.CreateCardAt(ids, keys, models, xs, ys, true, persist);
                }
            });

            return(result);
        }
Exemple #7
0
    public void Initialize()
    {
        cards        = new List <CardDef>();
        cardDefsDict = new Dictionary <string, CardDef>();
        CardDefCollection cardDefs = JsonUtility.FromJson <CardDefCollection>(Resources.Load <TextAsset>("cards").text);

        foreach (CardDef def in cardDefs.cards)
        {
            cardDefsDict[def.name] = def;
        }
        StartingCards startingCards = JsonUtility.FromJson <StartingCards>(definition.text);

        foreach (string card in startingCards.cards)
        {
            cards.Add(cardDefsDict[card]);
        }
        System.Random rng = new System.Random();
        int           n   = cards.Count;

        while (n > 1)
        {
            n--;
            int     k    = rng.Next(n + 1);
            CardDef temp = cards[k];
            cards[k] = cards[n];
            cards[n] = temp;
        }
        count.Initialize(startingCards.cards.Length);
    }
Exemple #8
0
    private void FinishSettingUpActor(Actor actor, CardDef cardDef)
    {
        CardRewardData data = base.Data as CardRewardData;

        actor.SetCardDef(cardDef);
        actor.SetCardFlair(new CardFlair(data.Premium));
        actor.UpdateAllComponents();
    }
Exemple #9
0
 public static CardPortraitQuality GetFromDef(CardDef def)
 {
     if (def == null)
     {
         return(GetDefault());
     }
     return(def.GetPortraitQuality());
 }
 public CardDef(CardDef def)
 {
     Atlas   = def.Atlas;
     Stock   = def.Stock;
     Text    = def.Text;
     Symbol  = def.Symbol;
     Pattern = def.Pattern;
     Grade   = def.Grade;
 }
 public void UpdatePortrait(EntityDef entityDef, CardDef cardDef)
 {
     this.m_heroActor.SetEntityDef(entityDef);
     this.m_heroActor.SetCardDef(cardDef);
     this.m_heroActor.UpdateAllComponents();
     this.m_heroActor.SetUnlit();
     this.m_currentEntityDef = entityDef;
     this.m_currentCardDef   = cardDef;
 }
Exemple #12
0
 private void OnCardDefLoaded(string cardID, CardDef cardDef, object callbackData)
 {
     if ((this.m_entityDef != null) && (this.m_entityDef.GetCardId() == cardID))
     {
         this.m_cardDef = cardDef;
         this.InitDeckTileActor();
         this.InitCardActor();
     }
 }
 private void OnCardDefLoaded(string cardID, CardDef def, object userData)
 {
     this.m_cardsToLoad--;
     this.CleanUpCard(def);
     if (this.m_cardsToLoad <= 0)
     {
         this.FinishVerification();
     }
 }
Exemple #14
0
 public void ClearCardDef(string cardID)
 {
     if (this.m_cachedCardDefs.ContainsKey(cardID))
     {
         CardDef def = this.m_cachedCardDefs[cardID];
         this.m_cachedCardDefs.Remove(cardID);
         UnityEngine.Object.Destroy(def.gameObject);
     }
 }
Exemple #15
0
    public FullDef GetFullDef(string cardId, CardPortraitQuality quality = null)
    {
        EntityDef entityDef = this.GetEntityDef(cardId);
        CardDef   cardDef   = this.GetCardDef(cardId, quality);
        FullDef   def3      = new FullDef();

        def3.SetEntityDef(entityDef);
        def3.SetCardDef(cardDef);
        return(def3);
    }
Exemple #16
0
        private void ComputeChildWidth(object sender, RoutedEventArgs e)
        {
            var     panel   = sender as VirtualizingWrapPanel;
            CardDef cardDef = Program.Game.Definition.CardDefinition;

            if (panel != null)
            {
                panel.ChildWidth = panel.ChildHeight * cardDef.Width / cardDef.Height;
            }
        }
Exemple #17
0
    public bool HasCardDef(GameObject go)
    {
        CardDef def = SceneUtils.FindComponentInThisOrParents <CardDef>(go);

        if (def == null)
        {
            return(false);
        }
        return(this.m_cachedCardDefs.ContainsValue(def));
    }
    private void OnCardDefLoaded(string cardID, CardDef cardDef, object userData)
    {
        RDMDeckEntry      entry        = (RDMDeckEntry)userData;
        ActorLoadCallback callbackData = new ActorLoadCallback {
            choice  = entry,
            cardDef = cardDef
        };

        AssetLoader.Get().LoadActor(ActorNames.GetHandActor(entry.EntityDef, entry.Flair.Premium), new AssetLoader.GameObjectCallback(this.OnActorLoaded), callbackData, false);
    }
 private void OnVanillaHeroCardDefLoaded(string cardId, CardDef def, object userData)
 {
     if (def == null)
     {
         Debug.LogError("GoldenHeroEvent.LoadDefaultHeroTexture() faild to load CardDef!");
     }
     else
     {
         this.m_VanillaHeroCardDef = def;
     }
 }
Exemple #20
0
    public CardDef Pop()
    {
        int last = m_cards.Count - 1;

        if (last >= 0)
        {
            CardDef result = m_cards[last];
            m_cards.RemoveAt(last);
            return(result);
        }
        return(null);
    }
Exemple #21
0
 protected override Size MeasureOverride(Size constraint)
 {
     img.Measure(constraint);
     if (img.Clip != null)
     {
         CardDef cardDef  = Program.Game.Definition.CardDefinition;
         var     clipRect = ((RectangleGeometry)img.Clip);
         clipRect.Rect    = new Rect(img.DesiredSize);
         clipRect.RadiusX = clipRect.RadiusY = cardDef.CornerRadius * clipRect.Rect.Height / cardDef.Height;
     }
     return(img.DesiredSize);
 }
Exemple #22
0
    public CardDef Draw()
    {
        if (cards.Count <= 0)
        {
            return(null);
        }
        CardDef output = cards[0];

        cards.Remove(output);
        count.Increment(-1);
        return(output);
    }
        protected override void OnCardOver(object sender, CardsEventArgs e)
        {
            base.OnCardOver(sender, e);

            // Set overlay card size
            CardDef cardDef = Program.Game.Definition.CardDefinition;

            e.CardSize = new Size(cardDef.Width * 100 / cardDef.Height, 100);
            if (IsAlwaysUp)
            {
                e.FaceUp = true;
            }

            // Drop is forbidden when not ordered by position
            if (SortByName)
            {
                e.CanDrop = false;
                return;
            }

            // When the list is restricted to some cards only,
            // one cannot drop cards from outside this list
            if (RestrictDrop && !e.Cards.All(c => Cards.Contains(c)))
            {
                e.CanDrop = false;
                return;
            }

            // Display insert indicator
            _wrapPanel.DisplayInsertIndicator(e.ClickedCard, _wrapPanel.GetIndexFromPoint(Mouse.GetPosition(_wrapPanel)));

            // Scroll the scroll viewer if required
            double pos = Mouse.GetPosition(scroller).Y;

            if (pos <= ScrollMargin || pos >= scroller.ActualHeight - ScrollMargin)
            {
                if (_scrollTimer == null)
                {
                    _scrollSpeed       = ScrollInitialSpeed;
                    _scrollDirectionUp = pos <= ScrollMargin;
                    _scrollTimer       = new DispatcherTimer {
                        Interval = TimeSpan.FromMilliseconds(ScrollTimeInterval)
                    };
                    _scrollTimer.Tick += DragScroll;
                    _scrollTimer.Start();
                }
            }
            else
            {
                StopDragScroll();
            }
        }
Exemple #24
0
 private void OnCardPrefabLoaded(string cardID, CardDef cardDef, object callbackData)
 {
     if (cardDef == null)
     {
         Debug.LogError(string.Format("CollectionCardCache.OnCardPrefabLoaded() - asset for card {0} has no CardDef!", cardID));
     }
     else
     {
         this.AddCard(cardID, cardDef);
         CallbackData data = (CallbackData)callbackData;
         data.callback(cardID, cardDef, data.callbackData);
     }
 }
Exemple #25
0
 public void Shuffle()
 {
     for (int i = 0; i < m_cards.Count; ++i)
     {
         int other = Random.Range(0, m_cards.Count);
         if (other != i)
         {
             CardDef swap = m_cards[i];
             m_cards[i]     = m_cards[other];
             m_cards[other] = swap;
         }
     }
 }
Exemple #26
0
    public CardDef Pop()
    {
        Debug.Log("Pop Youxi");
        int last = m_cards.Count - 1;

        if (last >= 0)
        {
            CardDef result = m_cards[last];
            m_cards.RemoveAt(last);
            return(result);
        }
        return(null);
    }
Exemple #27
0
    public CardDef Wujiangpop()
    {
        Debug.Log("Pop Wujiang");
        int last = Wujiang_cards.Count - 1;

        if (last >= 0)
        {
            CardDef result = Wujiang_cards[last];
            Wujiang_cards.RemoveAt(last);
            return(result);
        }
        return(null);
    }
Exemple #28
0
 //下面这个函数WujiangShuffle()是用来洗武将牌的
 public void WujiangShuffle()
 {
     for (int i = 0; i < Wujiang_cards.Count; ++i)
     {
         int other = Random.Range(0, Wujiang_cards.Count);
         if (other != i)
         {
             CardDef swap = Wujiang_cards[i];
             Wujiang_cards[i]     = Wujiang_cards[other];
             Wujiang_cards[other] = swap;
         }
     }
 }
Exemple #29
0
    public override void Initialize()
    {
        if (Atlas == null)
        {
            Debug.LogError("CardAtlas is not initialized.");
        }
        if (Stock == null)
        {
            Debug.LogError("CardStock is not initialized.");
        }

        Debug.Log("Atlas = " + Atlas.name);
        string []      suits    = new string[] { "Heart", "Spade", "Diamond", "Club" };
        string []      prefixes = new string[] { "H-", "S-", "D-", "C-" };
        List <CardDef> defs     = new List <CardDef>();

        for (int i = 0; i < 4; ++i)
        {
            //int ii = i*13;
            string symbol = suits[i];
            defs.Add(new CardDef(Atlas, Stock, "A", symbol, 1));
            defs.Add(new CardDef(Atlas, Stock, "2", symbol, 2));
            defs.Add(new CardDef(Atlas, Stock, "3", symbol, 3));
            defs.Add(new CardDef(Atlas, Stock, "4", symbol, 4));
            defs.Add(new CardDef(Atlas, Stock, "5", symbol, 5));
            defs.Add(new CardDef(Atlas, Stock, "6", symbol, 6));
            defs.Add(new CardDef(Atlas, Stock, "7", symbol, 7));
            defs.Add(new CardDef(Atlas, Stock, "8", symbol, 8));
            defs.Add(new CardDef(Atlas, Stock, "9", symbol, 9));
            defs.Add(new CardDef(Atlas, Stock, "10", symbol, 10));
            string  prefix = prefixes[i];
            CardDef jj     = new CardDef(Atlas, Stock, "J", symbol, 0);
            jj.Image = prefix + "Jack";
            defs.Add(jj);
            CardDef qq = new CardDef(Atlas, Stock, "Q", symbol, 0);
            qq.Image = prefix + "Queen";
            defs.Add(qq);
            CardDef kk = new CardDef(Atlas, Stock, "K", symbol, 0);
            kk.Image = prefix + "King";
            defs.Add(kk);
        }

        m_itemList = new DeckItem[52];
        for (int i = 0; i < defs.Count; ++i)
        {
            DeckItem item = new DeckItem();
            item.Count    = 1;
            item.Card     = defs[i];
            m_itemList[i] = item;
        }
    }
Exemple #30
0
 private void OnFullDefLoaded(string cardId, FullDef fullDef, object userData)
 {
     if (fullDef == null)
     {
         Debug.LogWarning(string.Format("RewardCard.OnFullDefLoaded() - FAILED to load \"{0}\"", cardId));
     }
     else
     {
         this.m_entityDef = fullDef.GetEntityDef();
         this.m_cardDef   = fullDef.GetCardDef();
         string handActor = ActorNames.GetHandActor(this.m_entityDef, this.m_cardFlair.Premium);
         AssetLoader.Get().LoadActor(handActor, new AssetLoader.GameObjectCallback(this.OnActorLoaded), null, false);
     }
 }