Exemple #1
0
    public GameObject SpawnCard(CardDescriptionClass CardDescription, bool build_mode)
    {
        GameObject      Card;
        CardInteraction CardInteraction;
        GameObject      Pawn;
        Pawn            PawnComponent;
        SpriteRenderer  cardSpriteRenderer;

        if (!CardDescription.CardEnabled)
        {
            return(null);
        }

        Card = (GameObject)Instantiate(CardPrefab, new Vector3(0, 0, 0), Quaternion.identity);
        Pawn = Card.transform.Find("Pawn").gameObject;
        Pawn.GetComponent <SpriteRenderer> ().sprite = CardDescription.Background;
        Pawn.transform.Find("Character").gameObject.GetComponent <SpriteRenderer> ().sprite = CardDescription.Character;
        cardSpriteRenderer = Card.GetComponent <SpriteRenderer> ();

        PawnComponent          = Pawn.GetComponent <Pawn> ();
        PawnComponent.CardID   = CardDescription.CardID;
        PawnComponent.Name     = CardDescription.Name;
        PawnComponent.Desc     = CardDescription.Description;
        PawnComponent.CardType = CardDescription.CardMode;

        PawnComponent.SetAttack(CardDescription.Attack);
        PawnComponent.SetHealth(CardDescription.Health);
        PawnComponent.SetConfig(CardDescription.PawnConfig, CardDescription.SpecialMovement);
        PawnComponent.ApplyConfig();
        PawnComponent.ItemApplyConfig = CardDescription.ItemChangePawnConfig;
        PawnComponent.ItemMergeConfig = CardDescription.ItemMergePawnConfig;

        if (CardDescription.BulletParticlePrefab != null)
        {
            PawnComponent.ShotParticlePrefab = CardDescription.BulletParticlePrefab;
        }
        PawnComponent.ShootingMode  = CardDescription.ShootingMode;
        PawnComponent.ShootInterval = CardDescription.ShootInterval;

        PawnComponent.PawnEffectParameters = CardDescription.EffectParameters;
        PawnComponent.PawnEffectParticle   = CardDescription.EffectParticles;
        if (CardDescription.DeathSound != null)
        {
            PawnComponent.DeathSound = CardDescription.DeathSound;
        }

        CardInteraction = Card.GetComponent <CardInteraction> ();
        CardInteraction.SetName(CardDescription.Name);
        CardInteraction.SetDescription(CardDescription.Description);
        CardInteraction.SetCardCost(CardDescription.Cost);
        CardInteraction.SetCardOrder(1);
        CardInteraction.CardRole   = CardDescription.Role;
        CardInteraction.CardRarity = CardDescription.Rarity;

        if (CardDescription.CardMode == CardTypesEnum.Pawn)
        {
            CardInteraction.SetTypeDescText("Postać");
        }
        else if (CardDescription.CardMode == CardTypesEnum.Weapon)
        {
            CardInteraction.SetTypeDescText("Ekwipunek");
        }
        else if (CardDescription.CardMode == CardTypesEnum.Effect)
        {
            CardInteraction.SetTypeDescText("Efekt");
        }

        if (CardDescription.Rarity == CardInteraction.CardRarityEnum.common)
        {
            cardSpriteRenderer.sprite = SilverCardSprite;
        }
        else if (CardDescription.Rarity == CardInteraction.CardRarityEnum.gold)
        {
            cardSpriteRenderer.sprite = GoldCardSprite;
        }
        else if (CardDescription.Rarity == CardInteraction.CardRarityEnum.diamond)
        {
            cardSpriteRenderer.sprite = DiamondCardSprite;
        }

        if (!build_mode)
        {
            if (CardDescription.EffectComponent.Length > 0)
            {
                Type componentType = Type.GetType(CardDescription.EffectComponent);
                if (componentType != null)
                {
                    Pawn.AddComponent(componentType);
                }
                else
                {
                    Debug.LogWarning("You are missing to add component class named: " + CardDescription.EffectComponent);
                }
            }
        }

        Card.SetActive(true);

        return(Card);
    }