public void ChangeTarget(int i)
    {
        selectChar += i;
        selectChar  = Mathf.Clamp(selectChar, 0, targets.Count - 1);

        targetToAttack = targets[selectChar];
    }
 void NextEnemy()
 {
     player = null;
     EnemyQueue.Dequeue();
     STATES = STATEMACHINE.IDLE;
     //print("Progress: " + EnemyQueue.Count);
 }
 void AttackCalculations(o_character targ)
 {
     if (player == null)
     {
         return;
     }
     targ.health         -= player.attack;
     player.actionPoints -= 2;
     player.health        = Mathf.Clamp(player.health, 0, player.maxHealth);
     //actionPoints = Mathf.Clamp(actionPoints, 0, maxActionPoints);
 }
    o_character GetTargetWithLowestHealth()
    {
        int         lasthealth = int.MaxValue;
        o_character chara      = null;

        foreach (o_character t in targets)
        {
            if (lasthealth > t.health)
            {
                lasthealth = t.health;
                chara      = t;
            }
        }
        return(chara);
    }
    void FeedGridData(s_leveldat levelData)
    {
        foreach (s_nodedat block in levelData.nodes_blocks)
        {
            Grid.block_layer[block.x, block.y] = Grid.SpawnObject(block.objectstr, new Vector2(20 * block.x, 20 * block.y));

            //SpriteRenderer rend = Grid.block_layer[block.x, block.y].gameObject.GetComponent<SpriteRenderer>();

            /*
             * if (rend != null)
             *  if (block.spr != null)
             *      //rend.sprite = block.spr;
             *
             *      Grid.block_layer[block.x, block.y].transform.rotation = block.rot;
             */
        }
        foreach (s_nodedat cha in levelData.nodes_character)
        {
            o_character character =
                (o_character)Grid.SpawnObject(cha.objectstr, new Vector2(20 * cha.x, 20 * cha.y));
            if (character.GetComponent <ICharacter>() != null)
            {
                character.GetComponent <ICharacter>().Intialize();
            }
        }
        foreach (s_nodedat cha in levelData.nodes_items)
        {
            o_item it = (o_item)Grid.SpawnObject(cha.objectstr, new Vector2(20 * cha.x, 20 * cha.y));
            if (it != null)
            {
                Grid.item_layer[cha.x, cha.y] = it;
            }
        }

        for (int x = 0; x < Grid.gridworldsize.x; x++)
        {
            for (int y = 0; y < Grid.gridworldsize.y; y++)
            {
                s_nodedat block_nod     = levelData.nodes_blocks.Find(obj => obj.x == x && obj.y == y);
                s_nodedat character_nod = levelData.nodes_character.Find(obj => obj.x == x && obj.y == y);
                s_nodedat item_nod      = levelData.nodes_items.Find(obj => obj.x == x && obj.y == y);
            }
        }
        Grid.ResetNodes();
    }
    public override IEnumerator EventPlay()
    {
        switch ((EVENT_TYPES)current_ev.eventType)
        {
        default:
            yield return(StartCoroutine(base.EventPlay()));

            break;

        case EVENT_TYPES.CAMERA_MOVEMENT:

            GameObject ca = GameObject.Find("Main Camera");
            ca.GetComponent <s_camera>().focus = false;
            ca.GetComponent <s_camera>().ResetSpeedProg();
            ca.GetComponent <s_camera>().lerping = true;

            float spe = current_ev.float0;     //SPEED
            float s   = 0;

            s_object obje = null;

            if (current_ev.string0 != "o_player")
            {
                if (GameObject.Find(current_ev.string0) != null)
                {
                    obje = GameObject.Find(current_ev.string0).GetComponent <s_object>();
                }
            }
            else
            {
                if (host != null)
                {
                    obje = host;
                }
                else
                {
                    obje = player;
                }
            }

            Vector2 pos = new Vector2(0, 0);
            if (obje != null)
            {
                pos = obje.transform.position;
            }

            if (obje != null)
            {
                ca.GetComponent <s_camera>().targetPos = obje.transform.position;
            }
            else
            {
                ca.GetComponent <s_camera>().targetPos = new Vector2(current_ev.pos.x, current_ev.pos.y);
            }

            if (current_ev.boolean)
            {
                float dista = Vector2.Distance(ca.transform.position, new Vector3(pos.x, pos.y));

                while (Vector2.Distance(ca.transform.position, new Vector3(pos.x, pos.y))
                       > dista * 0.05f)
                {
                    // s += spe * Time.deltaTime * travSpeed;
                    // ca.transform.position = Vector3.Lerp(ca.transform.position, new Vector3(pos.x, pos.y, -15), s);
                    yield return(new WaitForSeconds(Time.deltaTime));
                }
                if (current_ev.boolean1)
                {
                    ca.GetComponent <s_camera>().focus = true;
                    // ca.GetComponent<s_camera>(). = obje.GetComponent<o_character>();
                }
            }
            else
            {
                float dista = Vector2.Distance(ca.transform.position, new Vector3(current_ev.pos.x, current_ev.pos.y));
                while (Vector2.Distance(ca.transform.position, new Vector3(current_ev.pos.x, current_ev.pos.y))
                       > dista * 0.05f)
                {
                    // s += spe * Time.deltaTime * travSpeed;
                    // ca.transform.position = Vector2.Lerp(ca.transform.position, new Vector3(current_ev.pos.x, current_ev.pos.y, -15), s);
                    //ca.transform.position = new Vector3(ca.transform.position.x, ca.transform.position.y, -15);
                    yield return(new WaitForSeconds(Time.deltaTime));
                }
            }
            ca.GetComponent <s_camera>().lerping = false;
            break;

        case EVENT_TYPES.MOVEMNET:

            float       timer     = 1.02f;
            o_character charaMove = null;

            s_map.s_tileobj to = s_levelloader.LevEd.mapDat.tilesdata.Find(
                x => x.TYPENAME == "teleport_object" &&
                x.name == current_ev.string1);

            if (current_ev.string0 == "o_player")
            {
                if (host == null)
                {
                    charaMove = player;
                }
                else
                {
                    charaMove = host;
                }
            }
            else
            {
                charaMove = GameObject.Find(current_ev.string0).GetComponent <o_character>();
            }

            Vector2 newpos = charaMove.transform.position;

            if (current_ev.boolean)
            {
                newpos = new Vector2(to.pos_x, to.pos_y);
                charaMove.transform.position = new Vector3(newpos.x, newpos.y, 0);
                break;
            }

            float   dist = Vector2.Distance(charaMove.transform.position, newpos);
            Vector2 dir  = (newpos - new Vector2(charaMove.transform.position.x, charaMove.transform.position.y)).normalized;
            print(newpos);

            while (Vector2.Distance(charaMove.transform.position, newpos)
                   > dist * 0.01f)
            {
                charaMove.transform.position += (Vector3)(dir * current_ev.float0 * current_ev.float1) * 0.007f;
                yield return(new WaitForSeconds(Time.deltaTime));
            }
            break;

        case EVENT_TYPES.CHANGE_MAP:

            dialogueChoices.Clear();
            if (player != null)
            {
                player.direction        = new Vector2(0, 0);
                player.rbody2d.velocity = Vector2.zero;
                player.control          = false;
                player.SetAnimation("idle_d", false);
                player.CHARACTER_STATE = o_character.CHARACTER_STATES.STATE_IDLE;
            }
            if (host != null)
            {
                host.direction        = new Vector2(0, 0);
                host.rbody2d.velocity = Vector2.zero;
                host.control          = false;
                host.SetAnimation("idle_d", false);
                host.CHARACTER_STATE = o_character.CHARACTER_STATES.STATE_IDLE;
            }

            float t2 = 0;
            while (fade.color != Color.black)
            {
                t2        += Time.deltaTime;
                fade.color = Color.Lerp(Color.clear, Color.black, t2);
                yield return(new WaitForSeconds(Time.deltaTime));
            }

            if (host == null)
            {
                s_levelloader.LevEd.TriggerSpawn(current_ev.string0, current_ev.string1, player);
            }
            else
            {
                s_levelloader.LevEd.TriggerSpawn(current_ev.string0, current_ev.string1, host);
            }

            t2 = 0;
            while (fade.color != Color.clear)
            {
                t2        += Time.deltaTime;
                fade.color = Color.Lerp(Color.black, Color.clear, t2);
                yield return(new WaitForSeconds(Time.deltaTime));
            }

            if (player != null)
            {
                player.control = true;
            }
            if (host != null)
            {
                host.control = true;
            }

            pointer     = -1;
            doingEvents = false;
            break;

        case EVENT_TYPES.DEPOSSES:

            if (host != null)
            {
                host.OnDeposess();
                host = null;
            }
            break;

        case EVENT_TYPES.ADD_CHOICE_OPTION:
            s_dialogue_choice dialo = new s_dialogue_choice(current_ev.string0, FindLabel(current_ev.string1));

            if (dialogueChoices != null)
            {
                dialogueChoices.Add(dialo);
            }
            else
            {
                dialogueChoices = new List <s_dialogue_choice>();
                dialogueChoices.Add(dialo);
            }
            break;

        case EVENT_TYPES.CHECK_FLAG:

            int integr = s_globals.GetGlobalFlag(current_ev.string0);

            int labelNum = FindLabel(current_ev.string1);

            if (labelNum == int.MinValue)
            {
                labelNum = current_ev.int1 - 1;
            }

            switch ((LOGIC_TYPE)current_ev.logic)
            {
            default:
                yield return(StartCoroutine(base.EventPlay()));

                break;

            case LOGIC_TYPE.CHECK_CHARACTER:
                if (host != null)
                {
                    if (host.ID == current_ev.string0) //Check if it is equal to the value
                    {
                        pointer = labelNum;            //Label to jump to
                    }
                }
                break;

            case LOGIC_TYPE.CHECK_CHARACTER_NOT:
                if (host != null)
                {
                    if (host.ID != current_ev.string0)
                    {
                        pointer = labelNum;           //Label to jump to
                    }
                }
                else
                {
                    pointer = labelNum;
                }
                break;


                /*
                 * case LOGIC_TYPE.CHECK_UTILITY_RETURN_NUM:
                 *
                 * //This checks utilities after the INITIALIZE function
                 * if (GetComponent<s_utility>().eventState == current_ev.int0)
                 * {
                 *  pointer = current_ev.int1 - 1;   //Label to jump to
                 * }
                 * else
                 * {
                 *  pointer = current_ev.int2 - 1;
                 * }
                 * break;
                 */
            }
            break;

        case EVENT_TYPES.CHOICE:
            int choice = 0, finalchoice = -1;
            print(choice);

            while (finalchoice == -1)
            {
                if (Input.GetKeyDown(KeyCode.UpArrow))
                {
                    choice--;
                }

                if (Input.GetKeyDown(KeyCode.DownArrow))
                {
                    choice++;
                }

                choice = Mathf.Clamp(choice, 0, dialogueChoices.Count - 1);

                if (Input.GetKeyDown(KeyCode.Z))
                {
                    print("Chosen");
                    finalchoice = choice;
                }
                Dialogue.text  = "Arrow keys to scroll, Z to select" + "\n";
                Dialogue.text += current_ev.string0 + "\n";
                for (int i = 0; i < dialogueChoices.Count - 1; i++)
                {
                    if (choice == i)
                    {
                        Dialogue.text += "-> ";
                    }

                    Dialogue.text += dialogueChoices[i].option + "\n";
                }
                print(choice);
                yield return(new WaitForSeconds(Time.deltaTime));
            }
            Dialogue.text = "";
            pointer       = dialogueChoices[finalchoice].flagTojump - 1;
            break;

        case EVENT_TYPES.CLEAR_CHOICES:
            dialogueChoices.Clear();
            break;

        case EVENT_TYPES.RUN_CHARACTER_SCRIPT:


            if (current_ev.string0 == "o_player")
            {
                o_character ch = null;
                if (host == null)
                {
                    ch = player.GetComponent <o_character>();
                }
                else
                {
                    ch = host.GetComponent <o_character>();
                }

                if (ch.rbody2d != null)
                {
                    ch.rbody2d.velocity = Vector2.zero;
                }
                ch.control         = current_ev.boolean;
                ch.CHARACTER_STATE = o_character.CHARACTER_STATES.STATE_IDLE;
            }
            else
            {
                GameObject obj = GameObject.Find(current_ev.string0);
                if (obj != null)
                {
                    o_character ch = obj.GetComponent <o_character>();
                    if (ch != null)
                    {
                        if (ch.rbody2d != null)
                        {
                            ch.rbody2d.velocity = Vector2.zero;
                        }
                        ch.control         = current_ev.boolean;
                        ch.CHARACTER_STATE = o_character.CHARACTER_STATES.STATE_IDLE;
                    }
                }
            }
            break;
        }
    }
    private void Update()
    {
        if (PlayerPrefs.GetInt("MonsterMode") == 0)
        {
            if (Players.Count < 10)
            {
                PlayerCount.text = "0" + Players.Count;
            }
            else
            {
                PlayerCount.text = "" + Players.Count;
            }

            if (Enemies.Count < 10)
            {
                EnemyCount.text = "0" + Enemies.Count;
            }
            else
            {
                EnemyCount.text = "" + Enemies.Count;
            }
        }
        else
        {
            if (Players.Count < 10)
            {
                PlayerCount.text = "0" + Enemies.Count;
            }
            else
            {
                PlayerCount.text = "" + Enemies.Count;
            }

            if (Enemies.Count < 10)
            {
                EnemyCount.text = "0" + Players.Count;
            }
            else
            {
                EnemyCount.text = "" + Players.Count;
            }
        }

        Vector3 mousePositon = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        if (player == null)
        {
            pathfcost  = 0;
            stats.text = "Nothing";
        }

        if (GetWinner == VICTORY_DICTATOR.ENEMY)
        {
            s_camera.staticCam.StartCoroutine(s_camera.staticCam.Fade(Color.black, 0.3f));

            game_on = false;
            if (s_camera.staticCam.isfaded)
            {
                UnityEngine.SceneManagement.SceneManager.LoadScene("Title");
            }
        }


        if (game_on)
        {
            switch (STATES)
            {
            case STATEMACHINE.IDLE:

                switch (TURNSTATE)
                {
                case TURNS.PLAYER:
                    if (Input.GetMouseButtonDown(0))
                    {
                        if (CheckForObject(mousePositon))
                        {
                            s_object obj = GetObjectFromWorld(mousePositon);
                            if (IsCharacter(mousePositon, obj))
                            {
                                o_character obselect = obj.GetComponent <o_character>();
                                if (obselect.health > 0)
                                {
                                    if (obselect.playable)
                                    {
                                        pathfcost = 0;
                                        SwitchCharacter((o_character)obj);
                                        CheckCharacterSurroundings(false);
                                    }
                                    player = obselect;
                                    STATES = STATEMACHINE.SELECT_CHAR;
                                }
                            }
                        }
                    }
                    break;

                    #region ENEMY
                case TURNS.ENEMY:

                    if (EnemyQueue.Count > 0)
                    {
                        //print("Chara " + EnemyQueue.Peek());
                        player = EnemyQueue.Peek();
                        //print("pl " + player);
                        STATES = STATEMACHINE.SELECT_CHAR;
                    }
                    else
                    {
                        s_camera.staticCam.StartCoroutine(s_camera.staticCam.Fade(Color.clear, 4));
                        if (s_camera.staticCam.isfaded)
                        {
                            print("Progress END: " + EnemyQueue.Count);
                            EndTurn();
                        }
                    }

                    break;
                    #endregion
                }

                break;

            case STATEMACHINE.SELECT_CHAR:

                switch (TURNSTATE)
                {
                case TURNS.PLAYER:

                    if (player.current_item != null)
                    {
                        stats.text = player.name + "\n" + "Item: " + player.current_item.name;
                    }
                    else
                    {
                        stats.text = player.name;
                    }

                    //actionpoints = "AP: " + player.actionPoints + "/" + player.maxActionPoints;

                    if (CheckForObject(mousePositon))
                    {
                        if (Input.GetMouseButtonDown(0))
                        {
                            CheckCharacterSurroundings(false);
                            s_object obj = GetObjectFromWorld(mousePositon);

                            if (obj != null)
                            {
                                if (obj.GetType() == typeof(o_character))
                                {
                                    o_character chara = obj.GetComponent <o_character>();
                                    if (targets.Contains(chara))
                                    {
                                        if (!chara.playable)
                                        {
                                            targetToAttack = chara;
                                            STATES         = STATEMACHINE.ATTACK_SELECT;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (Input.GetMouseButtonDown(0))
                    {
                        Vector2 mousepos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

                        if (player.MoveCost(mousepos) != -1)
                        {
                            Grid.UnpaintAllNodes();
                            pathfcost = player.MoveCost(mousepos);
                            player.SetDirections(Grid.NodeFromWorld(mousepos));
                            List <o_node> dir = player.directions;

                            foreach (o_node d in dir)
                            {
                                Grid.PaintNode(Grid.NodePositionFromWorld(d), Color.yellow);
                            }
                            STATES = STATEMACHINE.MOVE_TO;
                        }
                    }

                    break;

                    #region ENEMY
                case TURNS.ENEMY:

                    if (player.current_item != null)
                    {
                        UseItem();
                    }

                    /*if (targetToAttack != null)
                     *  if (targetToAttack.health == 0 && !targetToAttack.IsDisappear())
                     *      return;
                     */
                    CheckCharacterSurroundings(true);
                    if (targets.Count == 0)
                    {
                        STATES = STATEMACHINE.MOVE_TO;
                    }
                    else
                    {
                        STATES = STATEMACHINE.ATTACK_SELECT;
                    }
                    break;
                    #endregion
                }

                //Have a cancel button where this player is no longer the focus

                //Attack button where it checks enemies

                break;

            case STATEMACHINE.MOVE_TO:

                switch (TURNSTATE)
                {
                case TURNS.PLAYER:
                    if (Input.GetMouseButtonDown(0))
                    {
                        Vector2 mousepos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                        if (player.playable)
                        {
                            if (player.actionPoints >= pathfcost)
                            {
                                if (Grid.NodeFromWorld(mousepos) == player.directions[player.directions.Count - 1])
                                {
                                    ConfirmMovement();
                                    return;
                                }
                            }
                        }

                        if (player.MoveCost(mousepos) != -1)
                        {
                            Grid.UnpaintAllNodes();
                            pathfcost = player.MoveCost(mousepos);
                            player.SetDirections(Grid.NodeFromWorld(mousepos));
                            List <o_node> dir = player.directions;

                            foreach (o_node d in dir)
                            {
                                Grid.PaintNode(Grid.NodePositionFromWorld(d), Color.yellow);
                            }
                        }
                    }

                    if (Input.GetMouseButtonDown(1))
                    {
                        Grid.UnpaintAllNodes();
                        LooseFocus();
                    }

                    break;

                    #region ENEMY
                case TURNS.ENEMY:

                    int         newcost = int.MaxValue;
                    o_character tar     = null;

                    foreach (o_character e in Players)
                    {
                        //Check around the target and pathfind for each position.
                        HashSet <o_node> aroundChar = Grid.CheckAroundNode(Grid.NodeFromWorld(e.transform.position));

                        int potentialMoveCost = int.MaxValue;
                        e.GetComponent <SpriteRenderer>().color = Color.red;
                        o_node nof = null;

                        foreach (o_node no in aroundChar)
                        {
                            if (!no.walkable)
                            {
                                continue;
                            }

                            int comp = player.MoveCost(no.position);
                            if (comp == -1)
                            {
                                continue;
                            }

                            potentialMoveCost = Mathf.Min(potentialMoveCost, comp);
                            if (potentialMoveCost == comp)
                            {
                                nof = no;
                            }
                        }

                        e.GetComponent <SpriteRenderer>().color = Color.white;
                        if (potentialMoveCost <= player.range)
                        {
                            if (potentialMoveCost <= player.actionPoints)
                            {
                                tar     = e;
                                newcost = Mathf.Min(newcost, potentialMoveCost);
                                if (newcost == potentialMoveCost)
                                {
                                    if (nof != null)
                                    {
                                        player.SetDirections(nof);
                                    }
                                }
                            }
                        }
                        else
                        {
                            continue;
                        }
                        Grid.UnpaintAllNodes();
                    }

                    if (newcost != int.MaxValue)
                    {
                        Grid.UnpaintAllNodes();
                        pathfcost = newcost;
                        if (pathfcost > 0)
                        {
                            ConfirmMovement();
                        }
                        else
                        {
                            NextEnemy();
                        }
                    }
                    else
                    {
                        NextEnemy();
                    }

                    break;
                    #endregion
                }
                //Confirm?
                //Cancecl Move

                break;

            case STATEMACHINE.ATTACK_SELECT:

                switch (TURNSTATE)
                {
                case TURNS.PLAYER:


                    if (targetToAttack != null)
                    {
                        targetToAttack.renderer.color = Color.magenta;
                    }

                    if (Input.GetMouseButtonDown(0))
                    {
                        s_object obj = GetObjectFromWorld(mousePositon);
                        if (obj != targetToAttack)
                        {
                            o_character newtarg = targets.Find(x => obj == x);

                            if (newtarg != null)
                            {
                                targetToAttack.renderer.color = Color.white;
                                targetToAttack = newtarg;
                                return;
                            }
                        }
                    }


                    if (targetToAttack.health > 0 && player.actionPoints >= 2)
                    {
                        if (Input.GetMouseButtonDown(0))
                        {
                            targetToAttack.renderer.color = Color.white;
                            STATES = STATEMACHINE.ATTACK_EXECUTE;
                        }
                    }

                    if (targetToAttack.health <= 0 || player.actionPoints < 2)
                    {
                        targetToAttack.renderer.color = Color.white;
                        LooseFocus();
                    }

                    if (Input.GetMouseButtonDown(1))
                    {
                        if (targetToAttack != null)
                        {
                            targetToAttack.renderer.color = Color.white;
                        }
                        LooseFocus();
                    }
                    break;

                    #region ENEMY
                case TURNS.ENEMY:

                    CheckCharacterSurroundings(true);
                    if (targets.Count > 0)
                    {
                        //The enemy can attack the player again if they have sufficent points
                        if (player.actionPoints >= 2)
                        {
                            targetToAttack = GetTargetWithLowestHealth();

                            if (targetToAttack.health > 0)
                            {
                                if (!isattacking && !IsSkipped)
                                {
                                    StartCoroutine(AttackingAnim());
                                }

                                if (IsSkipped)
                                {
                                    AttackCalculations(targetToAttack);
                                }
                            }
                        }
                        else
                        {
                            NextEnemy();
                        }
                    }
                    else
                    {
                        STATES = STATEMACHINE.SELECT_CHAR;
                    }

                    break;
                    #endregion
                }

                break;

            case STATEMACHINE.ATTACK_EXECUTE:

                if (!isattacking)
                {
                    StartCoroutine(AttackingAnim());
                }
                else if (TURNSTATE == TURNS.PLAYER)
                {
                    STATES = STATEMACHINE.ATTACK_SELECT;
                }

                break;

            case STATEMACHINE.WALK:
                //Call Player enumarator to walk
                //Once done go back to select char

                break;
            }
        }
    }
 public void LooseFocus()
 {
     STATES = STATEMACHINE.IDLE;
     player = null;
 }
    public void CheckCharacterSurroundings(bool is_enemy)
    {
        //If an enemy or two appears enable the confirm attack button
        targets.Clear();
        HashSet <o_node> enemynodes = Grid.CheckAroundNode(Grid.NodeFromWorld(player.transform.position));

        foreach (o_node e in enemynodes)
        {
            s_object enemyObject = Grid.ObjectFromWorld(e);

            if (enemyObject == null)
            {
                continue;
            }

            if (enemyObject.GetType() == typeof(o_character))
            {
                o_character enemy = enemyObject.GetComponent <o_character>();

                if (PlayerPrefs.GetInt("MonsterMode") == 0)
                {
                    if (!is_enemy)
                    {
                        if (!Heroes.Contains(enemy.name))
                        {
                            targets.Add(enemy);
                        }
                    }
                    else
                    {
                        if (!Adversaries.Contains(enemy.name))
                        {
                            targets.Add(enemy);
                        }
                    }
                }
                else
                if (PlayerPrefs.GetInt("MonsterMode") == 1)
                {
                    if (!is_enemy)
                    {
                        if (!Adversaries.Contains(enemy.name))
                        {
                            targets.Add(enemy);
                        }
                    }
                    else
                    {
                        if (!Heroes.Contains(enemy.name))
                        {
                            targets.Add(enemy);
                        }
                    }
                }
            }
            else
            {
                continue;
            }
        }
    }
 public void SwitchCharacter(o_character character)
 {
     player = character;
 }
Example #11
0
    new void Update()
    {
        if (floatingNum > Mathf.PI * 2)
        {
            floatingNum = 0;
        }
        else
        {
            floatingNum += 0.04f;
        }

        rendererObj.transform.position = new Vector3(transform.position.x, transform.position.y + ((Mathf.Sin(floatingNum) * 25) * Time.deltaTime));
        Collider2D col = IfTouchingGetCol <o_character>(collision);

        if (col != null)
        {
            o_character p = col.GetComponent <o_character>();

            if (p != null)
            {
                switch (it)
                {
                case ITEM_TYPE.COLLECTIBLE:
                    /*
                     * npc_customer mask = p.GetComponent<npc_customer>();
                     * if (mask != null)
                     * {
                     *  if (mask.desiredItemName == name)
                     *  {
                     *      mask.satisfied = true;
                     *      DespawnObject();
                     *  }
                     * }
                     */
                    break;
                }
                if (!p.AI)
                {
                    switch (it)
                    {
                    case ITEM_TYPE.MONEY:
                        s_globals.Money += 1;
                        s_map mp = GameObject.Find("General").GetComponent <s_leveledit>().mapDat;
                        s_leveledit.LevEd.GetComponent <s_leveledit>().SetItemData(name, false);
                        mp.gemCount++;
                        s_save_item it = mp.itemdat.Find(x => x.ID == indexID);
                        it.iscollected = true;
                        s_soundmanager.sound.PlaySound(ref collectSound, false);
                        DespawnObject();
                        break;

                    case ITEM_TYPE.COLLECTIBLE:
                        s_soundmanager.sound.PlaySound(ref collectSound, false);
                        DespawnObject();
                        break;
                    }
                }
            }
            //DespawnObject();
        }
    }
Example #12
0
    public override void DisplayCutsceneEditor(int eventType, ref ev_details ev, int i)
    {
        switch ((EVENT_TYPES)eventType)
        {
        default:
            base.DisplayCutsceneEditor(eventType, ref ev, i);
            break;

            #region CHECK FLAG
        case EVENT_TYPES.CHECK_FLAG:
            ev.logic = (int)(LOGIC_TYPE)EditorGUILayout.EnumPopup("Logic Type", (LOGIC_TYPE)ev.logic);
            switch ((LOGIC_TYPE)ev.logic)
            {
            default:
                base.DisplayCutsceneEditor(eventType, ref ev, i);
                break;

            case LOGIC_TYPE.NUM_OF_GEMS:

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("IF NUMBER OF GEMS  =< ");
                ev.int0 = EditorGUILayout.IntField(ev.int0);
                EditorGUILayout.Space();
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("THEN JUMP TO ");
                ev.int1 = EditorGUILayout.IntField(ev.int1);
                EditorGUILayout.LabelField(" OR ");
                ev.string1 = EditorGUILayout.TextField(ev.string1);
                EditorGUILayout.EndHorizontal();
                break;

            case LOGIC_TYPE.ITEM_OWNED:

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("IF "); EditorGUILayout.LabelField("ITEM ");
                ev.string0 = EditorGUILayout.TextField(ev.string0);
                EditorGUILayout.LabelField(" WITH TYPE ");
                ev.int0 = EditorGUILayout.IntField(ev.int0);
                EditorGUILayout.LabelField(" (" + (o_item.ITEM_TYPE)ev.int0 + ")");
                EditorGUILayout.LabelField(" POSSESED.");
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("THEN JUMP TO ");
                ev.int1 = EditorGUILayout.IntField(ev.int1);
                EditorGUILayout.EndHorizontal();
                break;

            case LOGIC_TYPE.CHECK_CHARACTER:

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("IF CHARACTER IS ");
                ev.string0 = EditorGUILayout.TextField(ev.string0);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("THEN JUMP TO ");
                ev.int1 = EditorGUILayout.IntField(ev.int1);
                EditorGUILayout.EndHorizontal();
                break;

            case LOGIC_TYPE.CHECK_CHARACTER_NOT:

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("IF CHARACTER IS NOT");
                ev.string0 = EditorGUILayout.TextField(ev.string0);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("THEN JUMP TO ");
                ev.int1 = EditorGUILayout.IntField(ev.int1);
                EditorGUILayout.LabelField(" OR ");
                ev.string1 = EditorGUILayout.TextField(ev.string1);
                EditorGUILayout.EndHorizontal();
                break;

            case LOGIC_TYPE.CHECK_UTILITY_RETURN_NUM:

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("IF UITILITY ");
                SetStringToObjectName(ref ev);
                EditorGUILayout.LabelField(ev.string0);
                EditorGUILayout.LabelField(" RETURN NUMBER IS ");
                ev.int0 = EditorGUILayout.IntField(ev.int0);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("THEN JUMP TO ");
                ev.int1 = EditorGUILayout.IntField(ev.int1);
                EditorGUILayout.LabelField(" OR ");
                ev.string1 = EditorGUILayout.TextField(ev.string1);
                EditorGUILayout.EndHorizontal();
                break;

            case LOGIC_TYPE.VAR_NOT_EQUAL:

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("IF ");
                ev.string0 = EditorGUILayout.TextField(ev.string0);
                EditorGUILayout.LabelField(" != ");
                ev.int0 = EditorGUILayout.IntField(ev.int0);
                EditorGUILayout.Space();
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("THEN JUMP TO LABEL");
                ev.string1 = EditorGUILayout.TextField(ev.string1);
                EditorGUILayout.EndHorizontal();
                break;
            }
            break;
            #endregion

            #region CREATE OBJECT
        case EVENT_TYPES.CREATE_OBJECT:

            EditorGUILayout.LabelField("Object type:");
            ev.string0 = EditorGUILayout.TextField(ev.string0);
            EditorGUILayout.LabelField("Object name: " + ev.string1);
            ev.string1 = EditorGUILayout.TextField(ev.string1);
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Object position:");
            EditorGUILayout.BeginHorizontal();
            ev.float0 = EditorGUILayout.FloatField(ev.float0);
            ev.float1 = EditorGUILayout.FloatField(ev.float1);
            EditorGUILayout.EndHorizontal();
            break;
            #endregion

            #region DELETE OBJECT
        case EVENT_TYPES.DELETE_OBJECT:

            EditorGUILayout.LabelField("Object type: " + ev.string0);
            EditorGUILayout.LabelField("Object name: " + ev.string1);
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Object position:");
            EditorGUILayout.BeginHorizontal();
            ev.float0 = EditorGUILayout.FloatField(ev.float0);
            ev.float1 = EditorGUILayout.FloatField(ev.float1);
            EditorGUILayout.EndHorizontal();
            break;
            #endregion

            #region SET OBJECT COLLISION SIZE
        case EVENT_TYPES.SET_OBJ_COLLISION:

            EditorGUILayout.LabelField("Name:");
            ev.string0 = EditorGUILayout.TextField(ev.string0);
            EditorGUILayout.BeginHorizontal();
            ev.float0 = EditorGUILayout.FloatField(ev.float0);
            ev.float1 = EditorGUILayout.FloatField(ev.float1);
            EditorGUILayout.EndHorizontal();
            break;
            #endregion

            #region DISPLAY CHARACTER HEALTH
        case EVENT_TYPES.DISPLAY_CHARACTER_HEALTH:
            leng = EditorGUILayout.IntField(leng);
            if (GUILayout.Button("New list"))
            {
                ev.stringList = new string[leng];
                objlist       = new s_object[leng];
            }

            if (ev.stringList != null || ev.stringList.Length > 0)
            {
                if (objlist == null)
                {
                    objlist = new s_object[leng];
                }
                for (int o = 0; o < ev.stringList.Length; o++)
                {
                    objlist[o] = (o_character)EditorGUILayout.ObjectField(objlist[o], typeof(o_character), true);

                    if (objlist[o] != null)
                    {
                        ev.stringList[o] = objlist[o].name;
                    }
                }
                for (int o = 0; o < ev.stringList.Length; o++)
                {
                    EditorGUILayout.LabelField(ev.stringList[o]);
                }
            }
            //There will be one GUI for the top (near main character health) and one in the bottom (boss health)
            ev.boolean1 = EditorGUILayout.Toggle("Top?", ev.boolean1);
            //
            ev.boolean = EditorGUILayout.Toggle("Show?", ev.boolean);

            break;
            #endregion

            #region WAIT
        case EVENT_TYPES.WAIT:

            ev.float0 = EditorGUILayout.FloatField("Length: ", ev.float0);

            break;

            #endregion

            #region SET_HEALTH
        case EVENT_TYPES.SET_HEALTH:

            selectedCharacter = (o_character)EditorGUILayout.ObjectField(selectedCharacter, typeof(o_character), true);
            if (selectedCharacter != null)
            {
                ev.string0 = selectedCharacter.name;
            }
            ev.float0 = EditorGUILayout.FloatField("Set health to: ", ev.float0);
            break;
            #endregion

            #region CHOICE
        case EVENT_TYPES.CHOICE:
            ev.string0 = EditorGUILayout.TextField("Question label:", ev.string0);

            /*
             * leng = EditorGUILayout.IntField(leng);
             * if (GUILayout.Button("New list"))
             * {
             *  ev.stringList = new string[leng];
             *  ev.intList = new int[leng];
             * }
             * if (ev.stringList != null)
             * {
             *  //EditorGUILayout.BeginScrollView(scrollview2);
             *  for (int o = 0; o < ev.stringList.Length; o++)
             *  {
             *      ev.stringList[o] = EditorGUILayout.TextField("Name of choice" + o + " :", ev.stringList[o]);
             *      ev.intList[o] = EditorGUILayout.IntField("Event position to jump to: ", ev.intList[o]);
             *      EditorGUILayout.Space();
             *  }
             *  //EditorGUILayout.EndScrollView();
             *
             *  for (int o = 0; o < ev.stringList.Length; o++)
             *  {
             *      EditorGUILayout.LabelField(ev.stringList[o]);
             *      EditorGUILayout.LabelField("" + ev.intList[o]);
             *  }
             * }
             */
            break;
            #endregion

            #region ADD CHOICE
        case EVENT_TYPES.ADD_CHOICE_OPTION:
            ev.string0 = EditorGUILayout.TextField("Name of choice: ", ev.string0);
            ev.int0    = EditorGUILayout.IntField("Event position to jump to: ", ev.int0);
            ev.string1 = EditorGUILayout.TextField("or label name: ", ev.string1);
            break;
            #endregion

            #region SHOW_TEXT
        case EVENT_TYPES.SHOW_TEXT:

            ev.float0  = EditorGUILayout.FloatField(ev.float0);
            ev.string0 = EditorGUILayout.TextArea(ev.string0);
            break;
            #endregion
        }
    }