public void addActive(Vector3 pos, SpellManager.spell spell)
    {
        int points = SpellManager.spellCosts [spell];

        activeSpellPoints += points;

        GameObject bindingObject = Instantiate(SpellBindingPrefab);

        bindingObject.transform.SetParent(spellDisplayObject.transform);
        bindingObject.transform.localScale = Vector3.one;
        SpellBindingDisplay bindingScript = bindingObject.GetComponent <SpellBindingDisplay> ();

        bindingScript.height = points;
        bindingScript.Init(spell);
        activeSpellBindings.Add(bindingScript);
        foreach (SpellBindingDisplay s in activeSpellBindings)
        {
            s.StartCoroutine(s.ShiftUp(points));
        }

        if (activeSpellPoints <= activeSpellLimit)
        {
            activeSpellObjects.Add(new KeyValuePair <Vector3, int>(pos, points));
        }
        else
        {
            while (activeSpellPoints > activeSpellLimit)
            {
                this.removeFirstActive();
            }
            activeSpellObjects.Add(new KeyValuePair <Vector3, int>(pos, points));
        }
    }
 public void Init(SpellManager.spell spell)
 {
     rect       = GetComponent <RectTransform> ();
     yPos       = -height * 100;
     image      = GetComponent <Image> ();
     childImage = transform.GetChild(0).GetComponent <RawImage> ();
     if (SpellManager.textureDict.ContainsKey(spell))
     {
         childImage.texture = SpellManager.textureDict [spell];
     }
 }
 public bool removeSpell(SpellManager.spell r)
 {
     if (spellInventory.Contains(r))
     {
         spellInventory.Remove(r);
         return(true);
     }
     else
     {
         return(false);
     }
 }
 public bool addSpell(SpellManager.spell s)
 {
     if (spellInventory.Contains(s))
     {
         return(false);
     }
     else if (spellInventory.Count < inventorySize)
     {
         spellInventory.Add(s);
         return(true);
     }
     else
     {
         return(false);
     }
 }
    public void rotateSpell()
    {
        int currentIndex = spellInventory.IndexOf(currentSpell);

        if (currentIndex != -1)
        {
            //if last spell
            if (currentIndex == spellInventory.Count - 1)
            {
                currentSpell = spellInventory [0];
            }
            else
            {
                currentSpell = spellInventory [currentIndex + 1];
            }
            spellDisplayObject.texture = SpellManager.textureDict [currentSpell];
        }
    }
 public bool hasSpell(SpellManager.spell h)
 {
     return(spellInventory.Contains(h));
 }
    public Level(string levelName)
    {
        string s     = System.IO.File.ReadAllText(levelName);
        Regex  regex = new Regex("([^/]+)\\.txt");
        Match  mc    = regex.Match(levelName);

        spellReward   = SpellManager.spell.NO_EFFECT;
        name          = mc.Groups[1].Value;
        nextLevels    = new List <Level> ();
        startBlocks   = new List <int3> ();
        endBlocks     = new List <int3> ();
        obj           = new GameObject(name);
        iceBlocks     = new List <Block> ();
        buttons       = new Dictionary <int, Block> ();
        doors         = new Dictionary <Block, int> ();
        blocks        = new List <Block> ();
        spellPrereqs  = new List <List <SpellManager.spell> > ();
        liminalBlocks = new List <Block> ();
        levelPrereqs  = new List <string> ();
        min           = new int3(int.MaxValue, int.MaxValue, int.MaxValue);
        max           = new int3(int.MinValue, int.MinValue, int.MinValue);

        foreach (string line in s.Split('\n'))
        {
            string[] item = line.Split(',');
            if (item [0] == "spells")
            {
                List <SpellManager.spell> andSpells = new List <SpellManager.spell>();
                for (int i = 1; i < item.Length; i++)
                {
                    andSpells.Add(toEnum [item [i]]);
                }
                spellPrereqs.Add(andSpells);
            }
            else if (item [0] == "prereq")
            {
                levelPrereqs.Add(item [1]);
            }
            else
            {
                int3 pos = new int3(
                    int.Parse(item [0]),
                    int.Parse(item [1]),
                    int.Parse(item [2]));
                BlockType type = WorldManager.blockTypes [0];
                bool      icy  = false;
                if (item [3].Substring(0, 4) == "ice_")
                {
                    item [3] = item [3].Substring(4);
                    icy      = true;
                }
                foreach (BlockType t in WorldManager.blockTypes)
                {
                    if (t.name == item [3])
                    {
                        type = t;
                        break;
                    }
                }

                byte  dir = item.Length < 5 ? (byte)0 : byte.Parse(item [4]);
                Block b   = new Block {
                    pos = pos, type = type, dir = dir
                };

                if (item [3] == "spawn")
                {
                    startBlocks.Add(pos);
                }
                else if (item [3] == "goal")
                {
                    endBlocks.Add(pos);
                }
                else if (item [3] == "button")
                {
                    buttons.Add(int.Parse(item [5]), b);
                }
                else if (item [3] == "door")
                {
                    doors.Add(b, int.Parse(item [5]));
                }

                blocks.Add(b);

                if (icy)
                {
                    iceBlocks.Add(b);
                }
                min = int3.minBound(pos, min);
                max = int3.maxBound(pos, max);
            }
        }

        visualMax    = new int3(max);
        visualMax.x += Mathf.RoundToInt(max.y * 5f / 7f);
        visualMax.z += Mathf.RoundToInt(max.y * 5f / 7f);
        visualMin    = new int3(min);
        visualMin.x += Mathf.RoundToInt(min.y * 5f / 7f);
        visualMin.z += Mathf.RoundToInt(min.y * 5f / 7f);
    }
 virtual public void ApplySpell(SpellManager.spell spellType, Vector3 casterPosition, Vector3 casterPosition2)
 {
 }
 public void UpdateText(SpellManager.spell spell)
 {
     CancelInvoke();
     text.text = spellNames [spell];
     Invoke("Clear", 1);
 }
Esempio n. 10
0
    public override void ApplySpell(SpellManager.spell spellType, Vector3 casterPosition, Vector3 casterPosition2)
    {
        switch (spellType)
        {
        case SpellManager.spell.PUSH:
            Vector3 newPosition = SpawnTiles.roundVector(transform.position * 2 - casterPosition);
            if (SpawnTiles.tileIsFree(newPosition) || (SpawnTiles.tileExists(newPosition) && SpawnTiles.blocks[newPosition].GetComponent <WaterManager>() != null) ||
                (SpawnTiles.tileExists(newPosition) && SpawnTiles.blocks[newPosition].GetComponent <VoidManager>() != null))
            {
                SpawnTiles.blocks.Remove(SpawnTiles.roundVector(transform.position));
                if (SpawnTiles.tileExists(newPosition))
                {
                    if (SpawnTiles.blocks [newPosition].GetComponent <WaterManager> () != null)
                    {
                        Destroy(SpawnTiles.blocks [newPosition]);
                        SpawnTiles.blocks.Remove(newPosition);
                        SpawnTiles.blocks.Add(newPosition, gameObject);
                    }
                    else
                    {
                        //must be a void block
                        VoidManager v = SpawnTiles.blocks [newPosition].GetComponent <VoidManager> ();
                        v.addObject(gameObject);
                        this.gameObject.GetComponent <MeshRenderer> ().enabled = false;
                    }
                }
                else
                {
                    SpawnTiles.blocks.Add(newPosition, gameObject);
                }
                transform.position = newPosition;
            }
            break;

        case SpellManager.spell.DOUBLE_PUSH:
            if (SpawnTiles.roundVector(casterPosition - transform.position) == SpawnTiles.roundVector(transform.position - casterPosition2))
            {
                SpawnTiles.blocks.Remove(SpawnTiles.roundVector(transform.position));
                Destroy(gameObject);
            }
            else
            {
                Vector3 midPosition = SpawnTiles.roundVector(transform.position * 2 - casterPosition);
                newPosition = SpawnTiles.roundVector(transform.position * 3 - casterPosition * 2);
                if (SpawnTiles.tileIsFree(midPosition))
                {
                    SpawnTiles.blocks.Remove(SpawnTiles.roundVector(transform.position));
                    if (SpawnTiles.tileIsFree(newPosition) || (SpawnTiles.tileExists(newPosition) && SpawnTiles.blocks[newPosition].GetComponent <WaterManager>() != null) ||
                        (SpawnTiles.tileExists(newPosition) && SpawnTiles.blocks[newPosition].GetComponent <VoidManager>() != null))
                    {
                        //pushing into water block
                        if (SpawnTiles.tileExists(newPosition))
                        {
                            if (SpawnTiles.blocks [newPosition].GetComponent <WaterManager> () != null)
                            {
                                Destroy(SpawnTiles.blocks [newPosition]);
                                SpawnTiles.blocks.Remove(newPosition);
                                SpawnTiles.blocks.Add(newPosition, gameObject);
                            }
                            else
                            {
                                //must be a void block
                                VoidManager v = SpawnTiles.blocks [newPosition].GetComponent <VoidManager> ();
                                v.addObject(gameObject);
                                this.gameObject.GetComponent <MeshRenderer> ().enabled = false;
                            }
                        }
                        else
                        {
                            SpawnTiles.blocks.Add(newPosition, gameObject);
                        }
                        transform.position = newPosition;
                    }
                    else
                    {
                        SpawnTiles.blocks.Add(midPosition, gameObject);
                        transform.position = midPosition;
                    }
                }
            }
            break;
        }
    }
Esempio n. 11
0
    // Use this for initialization
    void Awake()
    {
        //Random.InitState (7);
        instance          = this;
        levelsSpawned     = new List <Level> ();
        liminalBlocks     = new List <int3> ();
        extraLevels       = new Queue <Level> ();
        shortcuts         = new Dictionary <Level, Level> ();
        AOTargets         = new List <GameObject> ();
        SpawnTiles.blocks = new Dictionary <Vector3, GameObject> ();
        blockTypes        = publicBlockTypes;

        string[] files = Directory.GetFiles("Assets/Resources", "*.txt");
        levelPool = new Level[files.Length];

        List <Level> levelsAdded = new List <Level> ();

        List <SpellManager.spell> spellsLearned = new List <SpellManager.spell> {
            SpellManager.spell.PUSH,
            SpellManager.spell.PUSH
        };

        List <SpellManager.spell> spellsToLearn = new List <SpellManager.spell> {
            SpellManager.spell.CREATE_BLOCK,
            SpellManager.spell.DESTROY,
            SpellManager.spell.CREATE_BLOCK,
            SpellManager.spell.DESTROY
        };

        List <Level> possibleLevels = new List <Level> ();

        for (int i = 0; i < files.Length; i++)
        {
            string s = files [i];
            levelPool[i] = new Level(s);
            if (levelPool [i].canSpawn(spellsLearned, levelsAdded))
            {
                possibleLevels.Add(levelPool [i]);
            }
        }

        List <Level> openLevelExits = new List <Level> ();
        Level        firstLevel     = null;

        while (spellsToLearn.Count > 0)
        {
            while (true)
            {
                foreach (Level possibleLevel in levelPool)
                {
                    if (possibleLevel.canSpawn(spellsLearned, levelsAdded) && !levelsAdded.Contains(possibleLevel) && !possibleLevels.Contains(possibleLevel))
                    {
                        possibleLevels.Add(possibleLevel);
                    }
                }
                if (possibleLevels.Count == 0)
                {
                    break;
                }
                Level l = possibleLevels [Random.Range(0, possibleLevels.Count)];
                possibleLevels.Remove(l);
                if (openLevelExits.Count == 0)
                {
                    firstLevel = l;
                }
                else
                {
                    Level parent = openLevelExits [Random.Range(0, openLevelExits.Count)];
                    parent.nextLevels.Add(l);
                    openLevelExits.Remove(parent);
                }

                levelsAdded.Add(l);
                int paths = Random.Range(MIN_PATHS, MAX_PATHS + 1);
                for (int i = 0; i < paths; i++)
                {
                    openLevelExits.Add(l);
                }
            }
            SpellManager.spell spell = spellsToLearn [0];
            spellsToLearn.RemoveAt(0);
            spellsLearned.Add(spell);
            Level rewardPlace = openLevelExits [Random.Range(0, openLevelExits.Count)];
            int   timeout     = 1000;
            while (rewardPlace.spellReward != SpellManager.spell.NO_EFFECT)
            {
                if (--timeout == 0)
                {
                    break;
                }
                rewardPlace = openLevelExits [Random.Range(0, openLevelExits.Count)];
            }
            rewardPlace.spellReward = spell;
        }

        /*
         * foreach (Level l1 in levelsAdded) {
         *      foreach (Level l2 in l1.nextLevels) {
         *              Debug.Log (l1.name + ">>>" + l2.name);
         *      }
         * }*/

        firstLevel.Zero();
        levelsSpawned.Add(firstLevel);

        levelsToSpawn = new Queue <Level> ();
        levelsToSpawn.Enqueue(firstLevel);
        StartCoroutine("Generate");
    }