Пример #1
0
 public void ChangeCOlour(Color colou)
 {
     character.GetComponent <SpriteRenderer>().color = colou;
 }
    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;
        }
    }