예제 #1
0
    static void AddDeck(GameObject obj, string name)
    {
        List <Card> deck = new List <Card>();

        if (name == "")
        {
            obj.GetComponent <Unit>().deck = new AbilityDeck(new List <Card>());
            return;
        }
        DeckRecipe recipe = Resources.Load <DeckRecipe>("Recipes/DeckRecipes/" + name);

        if (recipe == null)
        {
            Debug.LogError("No Deck Recipe Found: " + name);
            return;
        }
        for (int i = 0; i < recipe.CardNames.Length; ++i)
        {
            CardRecipe data = Resources.Load("Recipes/CardRecipes/" + recipe.CardNames[i]) as CardRecipe;
            if (data == null)
            {
                Debug.LogError("No CardData for name: " + recipe.CardNames[i]);
                continue;
            }
            GameObject prefab = new GameObject(recipe.CardNames[i]);
            Card       card   = prefab.AddComponent <Card>();
            card.transform.parent = obj.transform;
            card.Load(data);
            deck.Add(card);
        }
        obj.GetComponent <Unit>().deck = new AbilityDeck(deck);
        obj.GetComponent <Unit>().deck.Shuffle();
        obj.GetComponent <Unit>().discards = new AbilityDeck(new List <Card>());
    }
    static CardRecipe GetOrCreateRecipe(string abilityName)
    {
        string     fullPath = string.Format("Assets/Resources/Recipes/CardRecipes/{0}.asset", abilityName);
        CardRecipe obj      = AssetDatabase.LoadAssetAtPath <CardRecipe>(fullPath);

        if (obj == null)
        {
            obj = CreateRecipe(fullPath);
        }
        EditorUtility.SetDirty(obj);
        return(obj);
    }
    static CardRecipe CreateRecipe(string fullPath)
    {
        CardRecipe instance = ScriptableObject.CreateInstance <CardRecipe>();

        AssetDatabase.CreateAsset(instance, fullPath);
        CardRecipe prefab = AssetDatabase.LoadAssetAtPath <CardRecipe>(fullPath);

        if (prefab == null)
        {
            Debug.Log("Recipe Creation Failed");
        }
        return(prefab);
    }
    static void ParseAbilities(string line)
    {
        string[]   elements = line.Split(',');
        CardRecipe recipe   = GetOrCreateRecipe(elements[0]);


        recipe.Name        = elements[0];
        recipe.Description = elements[1];

        string spritePath                = string.Format("Sprites/Abilities/{0}", elements[2]);
        string rangeSpritePath           = string.Format("Sprites/RangeIndicators/{0}", elements[3]);
        string particleEffectPath        = string.Format("Prefabs/ParticleEffects/FinalizedEffects/{0}", elements[4]);
        string redHitPath                = "Prefabs/ParticleEffects/FinalizedEffects/particle_hitred";
        string blueHitPath               = "Prefabs/ParticleEffects/FinalizedEffects/particle_hitblue";
        string defaultSpritePath         = "Sprites/Abilities/ability_default";
        string defaultRangeSpritePath    = "Sprites/RangeIndicators/range_default";
        string defaultParticleEffectPath = "Prefabs/ParticleEffects/FinalizedEffects/particle_default";

        recipe.Sprite = Resources.Load <Sprite>(spritePath);
        recipe.AbilityRangeIndicator = Resources.Load <Sprite>(rangeSpritePath);
        recipe.ParticleEffect        = Resources.Load <ParticleSystem>(particleEffectPath);
        recipe.RedHitMarker          = Resources.Load <ParticleSystem>(redHitPath);
        recipe.BlueHitMarker         = Resources.Load <ParticleSystem>(blueHitPath);
        Debug.Log(recipe.ParticleEffect);
        Debug.Log(recipe.RedHitMarker);
        Debug.Log(recipe.BlueHitMarker);

        switch (elements[5])
        {
        case "single":
            recipe.ParticalEffectType = ParticleEffectType.Single;
            break;

        case "hybrid":
            recipe.ParticalEffectType = ParticleEffectType.Hybrid;
            break;

        case "multiple":
        default:
            recipe.ParticalEffectType = ParticleEffectType.Multiple;
            break;
        }

        int manaCost = DefaultManaCost;
        int power    = DefaultPower;
        int range    = DefaultRange;

        recipe.ProjectileEffect = elements[6].Equals("TRUE") ? true : false;
        Int32.TryParse(elements[7], out manaCost);
        Int32.TryParse(elements[11], out power);
        Int32.TryParse(elements[13], out range);
        recipe.AbilityManaCost        = manaCost;
        recipe.BasePower              = power;
        recipe.AbilityRangeHorizontal = range;

        string abilityEffect       = string.Format("{0}AbilityEffect", elements[8]);
        string abilityEffectTarget = string.Format("{0}AbilityEffectTarget", elements[9]);
        string abilityPower        = string.Format("{0}AbilityPower", elements[10]);
        string abilityRange        = string.Format("{0}AbilityRange", elements[12]);

        recipe.AbilityEffect       = abilityEffect;
        recipe.AbilityEffectTarget = abilityEffectTarget;
        recipe.AbilityPower        = abilityPower;
        recipe.AbilityRange        = abilityRange;


        GameObject obj  = GetOrCreateCard(elements[0]);
        Card       card = obj.GetComponent <Card>();

        card.Load(recipe);

        if (recipe.AbilityEffect.Contains("InflictStatus"))
        {
            Debug.Log(recipe.AbilityEffect);
        }

        // Useful, but annoying when debugging this script
        if (recipe.Sprite == null)
        {
            Debug.Log(string.Format("Couldn't load {0} card sprite, titled \"{1}\", at \"{2}\". Setting default.", elements[0], elements[2], spritePath));
            recipe.Sprite = Resources.Load <Sprite>(defaultSpritePath);
        }
        if (recipe.AbilityRangeIndicator == null)
        {
            Debug.Log(string.Format("Couldn't load {0} card range indicator, titled \"{1}\", at \"{2}\". Setting default.", elements[0], elements[3], rangeSpritePath));
            recipe.AbilityRangeIndicator = Resources.Load <Sprite>(defaultRangeSpritePath);
        }
        Debug.Log(recipe.ParticleEffect);
        if (recipe.ParticleEffect == null)
        {
            Debug.Log(string.Format("Couldn't load {0} card particle effect, titled \"{1}\", at \"{2}\". Setting default.", elements[0], elements[4], particleEffectPath));
            recipe.ParticleEffect = Resources.Load <ParticleSystem>(defaultParticleEffectPath);
        }
    }
예제 #5
0
    public void Load(CardRecipe data)
    {
        AbilityManaCost abilityManaCost = GetComponent <AbilityManaCost>();

        if (abilityManaCost == null)
        {
            abilityManaCost = gameObject.AddComponent <AbilityManaCost>();
        }

        AbilityEffectTarget abilityEffectTarget = GetComponent <AbilityEffectTarget>();

        if (abilityEffectTarget != null)
        {
            DestroyImmediate(abilityEffectTarget, true);
        }

        BaseAbilityEffect abilityEffect = GetComponent <BaseAbilityEffect>();

        if (abilityEffect != null)
        {
            DestroyImmediate(abilityEffect, true);
        }

        BaseAbilityPower power = GetComponent <BaseAbilityPower>();

        if (power != null)
        {
            DestroyImmediate(power, true);
        }

        AbilityRange range = GetComponent <AbilityRange>();

        if (range != null)
        {
            DestroyImmediate(range, true);
        }

        if (data == null)
        {
            Name = "";
            Desc = "";
            abilityManaCost.amount = 0;
            abilityEffectTarget    = gameObject.AddComponent <DefaultAbilityEffectTarget>();
            abilityEffect          = gameObject.AddComponent <DamageAbilityEffect>();
            power            = gameObject.AddComponent <PhysicalAbilityPower>();
            power.Power      = 0;
            range            = gameObject.AddComponent <ConstantAbilityRange>();
            range.horizontal = 0;
            this.data        = Resources.Load("Recipes/CardRecipes/Empty Card Data") as CardRecipe;
            ID           = GetInstanceID();
            visualEffect = null;
            return;
        }
        Name = data.Name;
        Desc = data.Description;
        abilityManaCost.amount = data.AbilityManaCost;
        abilityEffectTarget    = gameObject.AddComponent(Type.GetType(data.AbilityEffectTarget)) as AbilityEffectTarget;

        if (data.AbilityEffect.Contains("InflictStatus"))
        {
            string ae     = "InflictStatusAbilityEffect";
            string status = string.Format("{0}StatusEffect", data.AbilityEffect.Substring(13, data.AbilityEffect.Length - 26));

            InflictStatusAbilityEffect effect = gameObject.AddComponent(Type.GetType(ae)) as InflictStatusAbilityEffect;
            effect.statusName = status;
            abilityEffect     = effect;
        }
        else
        {
            abilityEffect = gameObject.AddComponent(Type.GetType(data.AbilityEffect)) as BaseAbilityEffect;
        }

        power            = gameObject.AddComponent(Type.GetType(data.AbilityPower)) as BaseAbilityPower;
        power.Power      = data.BasePower;
        range            = gameObject.AddComponent(Type.GetType(data.AbilityRange)) as AbilityRange;
        range.horizontal = data.AbilityRangeHorizontal;
        this.data        = data;
        ID           = GetInstanceID();
        visualEffect = data.ParticleEffect;
    }
예제 #6
0
    public void Display(CardRecipe data)
    {
        cardBack.color = Color.white;
        if (data.AbilityPower.StartsWith("Physical"))
        {
            cardBack.color = Color.red;
        }
        if (data.AbilityPower.StartsWith("Special"))
        {
            cardBack.color = Color.blue;
        }

        cardImage.color      = Color.white;
        rangeIndicator.color = Color.white;
        if (cardBack.sprite == null)
        {
            cardBack.sprite = Resources.Load <Sprite>("Sprites/Cards/cardBack");
        }

        if (manaIndicator.color.Equals(Color.clear) || powerIndicator.color.Equals(Color.clear))
        {
            manaIndicator.sprite  = Resources.Load <Sprite>("Sprites/Cards/Mana");
            manaIndicator.color   = Color.white;
            powerIndicator.sprite = Resources.Load <Sprite>("Sprites/Cards/Damage");
            powerIndicator.color  = Color.white;
        }

        card.Load(data);
        normalSprite = data.Sprite;
        //TODO
        disabledSprite = normalSprite;
        selectedSprite = normalSprite;

        cardImage.sprite = normalSprite;
        cardImage.SetNativeSize();

        rangeIndicator.sprite = data.AbilityRangeIndicator;
        //rangeIndicator.SetNativeSize();

        Name.text     = card.GetName();
        ManaCost.text = card.GetComponent <AbilityManaCost>().amount.ToString();
        Power.text    = card.GetComponent <BaseAbilityPower>().Power.ToString();
        int numTargets = card.GetComponent <AbilityEffectTarget>().maxTargets();

        if (numTargets == int.MaxValue)
        {
            NumTargets.text = "∞";
        }
        else
        {
            NumTargets.text = numTargets.ToString();
        }
        if (data.Name.Equals(""))
        {
            rangeIndicator.sprite = cardImage.sprite;
            ManaCost.text         = null;
            Power.text            = null;
            NumTargets.text       = null;
            manaIndicator.sprite  = null;
            manaIndicator.color   = Color.clear;
            powerIndicator.sprite = null;
            powerIndicator.color  = Color.clear;
        }
    }