Beispiel #1
0
 void Start()
 {
     m_ButtonScriptA = m_Button_A.GetComponent <ButtonA>();
     m_ButtonScriptB = m_Button_B.GetComponent <ButtonB>();
     m_ButtonScriptC = m_Button_C.GetComponent <ButtonC>();
     m_ButtonScriptD = m_Button_D.GetComponent <ButtonD>();
     m_ButtonScriptE = m_Button_E.GetComponent <ButtonE>();
     m_ButtonScriptF = m_Button_F.GetComponent <ButtonF>();
 }
    //射線互動判斷
    public void RayInteraction()
    {
        //預設準心
        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        Vector3 v3Pos = Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0f));

        //射線範圍內
        if (Physics.Raycast(ray, out hit, raylength, 1 << 11))
        {
            Tagtext();
            Debug.DrawRay(Input.mousePosition, hit.point, Color.yellow);
            //Debug.Log(hit.transform.name);
        }
        //設線範圍外
        else
        {
            ButtonE.SetActive(false);
        }

        //P1玩家
        if (OutsideTheSchoolPUN.ServerConnect.playerID == 1 && Time.timeScale == 1f)
        {
            //木頭人出現
            if (Trigger.isEnter2ndFloor == true && isGhostAppear == false)
            {
                woodghost = GameObject.Find("木頭人");

                if (woodghost != null)
                {
                    isGhostAppear = true;
                }
            }

            //視野範圍判斷木頭人
            if (isGhostAppear == true)
            {
                //木頭人判定
                if (IsInView(woodghost.transform.position) && Player.currentHP != 0)
                {
                    isWoodGhostStop = true;
                }
                else
                {
                    isWoodGhostStop = false;
                }
            }
        }
        //P2玩家
        else if (OutsideTheSchoolPUN.ServerConnect.playerID == 2 && Time.timeScale == 1f)
        {
            //厭光怪出現
            if (Trigger.isEnter2ndFloor == true && isGhostAppear == false)
            {
                hatelightghost1 = GameObject.Find("厭光怪1");
                hatelightghost2 = GameObject.Find("厭光怪2");

                if (hatelightghost1 != null || hatelightghost2 != null)
                {
                    isGhostAppear = true;
                }
            }
            //手電筒範圍判斷厭光怪
            if (isGhostAppear == true)
            {
                //厭光怪判定
                if (IsInView(hatelightghost1.transform.position) || IsInView(hatelightghost2.transform.position))
                {
                    isHateLightGhostTrack = true;
                }
                else
                {
                    isHateLightGhostTrack = false;
                }
            }
        }
    }
Beispiel #3
0
        /// <summary>
        /// Parses the dungeon.lua file in the current project directory
        /// </summary>
        /// <returns> A Map object representing the current dungeon.lua file contents </returns>
        public static Map ParseMapFile()
        {
            Char[] delimiters            = { '=', ' ', ',', '"', '{', '}', '\r', '\n', '\t', ')', '(' };
            Char[] delimitersAttributes  = { '.', ':', ',', '"', '(', ')', '\r', '\n', '\t' };
            Char[] delimitersAttributes2 = { '.', ':', ',', '"', '(', ')', '\r', '\n', '\t', ' ' };

            Dictionary <string, MapElement> elements = new Dictionary <string, MapElement>();

            Monster.MonsterType             tmpMonstertype;
            Text.TextType                   tmpTextType;
            Door.DoorType                   tmpDoorType;
            Lever.LeverType                 tmpLeverType;
            Lock.LockType                   tmpLockType;
            ButtonE.ButtonType              tmpButtonType;
            Alcove.AlcoveType               tmpAlcoveType;
            PressurePlate.PressurePlateType tmpPressurePlateType;
            TrapDoor.TrapDoorType           tmpTrapDoorType;
            TorchHolder.TorchHolderType     tmpTorchHolderType;
            Lantern.LanternType             tmpLanternType;
            Altar.AltarType                 tmpAltarType;
            WallEffect.WallEffectType       tmpWallEffectType;
            Weapon.WeaponType               tmpWeaponType;
            Armor.ArmorType                 tmpArmorType;
            Food.FoodType                   tmpFoodType;
            Potion.PotionType               tmpPotionType;

            string fileText = System.IO.File.ReadAllText(DirectoryManager.DungeonFilePath);

            string patternSpawn      = @"spawn\(.*\)";
            string patternAttributes = @"\w+\.\w+\:\w+\(.*\)";
            string patternLoadLayer  = @"loadLayer\(([^)]+)\)";
            string patternParameters = @"\w+ = .*,";
            string patternTiles      = @"tiles = {(\n|\t|[^{])*(?=})";


            MatchCollection matchsSpawn      = Regex.Matches(fileText, patternSpawn, RegexOptions.IgnoreCase);
            MatchCollection matchsAttribute  = Regex.Matches(fileText, patternAttributes, RegexOptions.IgnoreCase);
            MatchCollection matchsParameters = Regex.Matches(fileText, patternParameters, RegexOptions.IgnoreCase);
            Match           matchLayer       = Regex.Match(fileText, patternLoadLayer, RegexOptions.IgnoreCase);
            Match           matchTiles       = Regex.Match(fileText, patternTiles, RegexOptions.IgnoreCase);

            string name = "", ambientTrack = "";
            int    width = 0, height = 0;

            int[]              levelCoord    = null;
            List <string>      tiles         = new List <string>();
            List <Cell>        cells         = new List <Cell>();
            List <EndingPoint> endingPoints  = new List <EndingPoint>();
            StartingPoint      startingPoint = null;

            foreach (Match m in matchsParameters)
            {
                string[] split = m.Value.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);

                if (split[0].Contains("name"))
                {
                    name = split[1];
                }
                else if (split[0].Contains("width"))
                {
                    width = Convert.ToInt32(split[1]);
                }
                else if (split[0].Contains("height"))
                {
                    height = Convert.ToInt32(split[1]);
                }
                else if (split[0].Contains("levelCoord"))
                {
                    levelCoord = new int[] { Convert.ToInt32(split[1]), Convert.ToInt32(split[2]), Convert.ToInt32(split[3]) };
                }
                else if (split[0].Contains("ambientTrack"))
                {
                    ambientTrack = split[1];
                }
            }

            string[] splitTiles = matchTiles.Value.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 1; i < splitTiles.Length; i++)
            {
                tiles.Add(splitTiles[i]);
            }

            string[] splitLayer = matchLayer.Value.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 2; i < splitLayer.Length; i++)
            {
                int  x    = (i - 2) % width;
                int  y    = (i - 2) / width;
                int  type = Convert.ToInt32(splitLayer[i]);
                Cell c    = new Cell(x, y, type);
                if (type == 1)
                {
                    c.IsWalkable = true;
                }
                else if (type == 2)
                {
                    c.IsWalkable = false;                 //FIXME: Se houverem mais tipos esta comparação pode não chegar.
                }
                cells.Add(c);
            }

            foreach (Match m in matchsSpawn)
            {
                string[] splitString = m.Value.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);

                string id       = splitString[1];
                int    x        = Convert.ToInt32(splitString[2]);
                int    y        = Convert.ToInt32(splitString[3]);
                int    o        = Convert.ToInt32(splitString[4]);
                int    h        = Convert.ToInt32(splitString[5]);
                string uniqueId = splitString[6];

                Cell       tmpCell    = cells.Where(c => c.X == x && c.Y == y).First();
                MapElement tmpElement = null;

                if (id.Contains("starting_location"))
                {
                    startingPoint           = new StartingPoint(id, x, y, o, h, uniqueId);
                    tmpCell.IsStartingPoint = true;
                    tmpCell.StartPoint      = startingPoint;

                    elements.Add(uniqueId, startingPoint);
                }
                else if (id.Contains("exit") || id.Contains("stairs") || id.Contains("healing_crystal"))
                {
                    var newEndingPoint = new EndingPoint(id, x, y, o, h, uniqueId);
                    tmpCell.IsEndingPoint = true;
                    tmpCell.EndPoint      = newEndingPoint;

                    endingPoints.Add(newEndingPoint);
                    elements.Add(uniqueId, newEndingPoint);
                }
                else if (Enum.TryParse(id, true, out tmpTorchHolderType))
                {
                    tmpElement = new TorchHolder(id, x, y, o, h, uniqueId);
                }
                else if (id.Equals("scroll"))
                {
                    tmpElement = new Scroll(id, x, y, o, h, uniqueId);
                }
                else if (Enum.TryParse(id, true, out tmpAlcoveType))
                {
                    tmpElement = new Alcove(id, x, y, o, h, uniqueId);
                }
                else if (Enum.TryParse(id, true, out tmpButtonType))
                {
                    tmpElement = new ButtonE(id, x, y, o, h, uniqueId);
                }
                else if (Enum.TryParse(id, true, out tmpDoorType))
                {
                    tmpElement = new Door(id, x, y, o, h, uniqueId);
                }
                else if (Enum.TryParse(id, true, out tmpLeverType))
                {
                    tmpElement = new Lever(id, x, y, o, h, uniqueId);
                }
                else if (Enum.TryParse(id, true, out tmpLockType))
                {
                    tmpElement = new Lock(id, x, y, o, h, uniqueId);
                }
                else if (Enum.TryParse(id, true, out tmpMonstertype))
                {
                    var newMonster = new Monster(id, x, y, o, h, uniqueId);
                    tmpCell.Monster = newMonster;
                    elements.Add(uniqueId, newMonster);
                }
                else if (Enum.TryParse(id, true, out tmpPressurePlateType))
                {
                    tmpElement = new PressurePlate(id, x, y, o, h, uniqueId);
                }
                else if (Enum.TryParse(id, true, out tmpTextType))
                {
                    tmpElement = new Text(id, x, y, o, h, uniqueId);
                }
                else if (Enum.TryParse(id, true, out tmpTrapDoorType))
                {
                    tmpElement = new TrapDoor(id, x, y, o, h, uniqueId);
                }
                else if (Enum.TryParse(id, true, out tmpLanternType))
                {
                    tmpElement = new Lantern(id, x, y, o, h, uniqueId);
                }
                else if (Enum.TryParse(id, true, out tmpAltarType))
                {
                    tmpElement = new Altar(id, x, y, o, h, uniqueId);
                }
                else if (Enum.TryParse(id, true, out tmpWallEffectType))
                {
                    tmpElement = new WallEffect(id, x, y, o, h, uniqueId);
                }
                else if (Enum.TryParse(id, true, out tmpWeaponType))
                {
                    tmpElement = new Weapon(id, x, y, o, h, uniqueId);
                }
                else if (Enum.TryParse(id, true, out tmpArmorType))
                {
                    tmpElement = new Armor(id, x, y, o, h, uniqueId);
                }
                else if (Enum.TryParse(id, true, out tmpFoodType))
                {
                    tmpElement = new Food(id, x, y, o, h, uniqueId);
                }
                else if (Enum.TryParse(id, true, out tmpPotionType))
                {
                    tmpElement = new Potion(id, x, y, o, h, uniqueId);
                }
                else
                {
                    tmpElement = new Item(id, x, y, o, h, uniqueId);
                }

                if (tmpElement != null)
                {
                    tmpCell.AddElement(tmpElement);
                    elements.Add(uniqueId, tmpElement);
                }
            }

            foreach (Match m in matchsAttribute)
            {
                Char[] delimit = delimitersAttributes;
                if (m.Value.Contains("addConnector"))
                {
                    delimit = delimitersAttributes2;
                }

                string[] split = m.Value.Split(delimit, StringSplitOptions.RemoveEmptyEntries);

                MapElement tmpElement = null;
                if (elements.TryGetValue(split[0], out tmpElement))
                {
                    if (split[2].Contains("addConnector"))
                    {
                        tmpElement.addConnector(split[3], split[4], split[5]);
                    }
                    else if (split[2].Contains("addItem") || split[2].Contains("setWallText") || split[2].Contains("setOpenedBy") || split[2].Contains("setState") || split[2].Contains("setDoorState") || split[2].Contains("setScrollText"))
                    {
                        tmpElement.setAttribute(split[2], split[3]);
                    }
                    else if (split[2].Contains("disable"))
                    {
                        tmpElement.setAttribute(split[2], "");
                    }
                    else // True or false
                    {
                        tmpElement.setAttribute(split[2], split[3].Contains("true") ? true : false);
                    }
                }
            }

            Map map = new Map(name, width, height)
            {
                StartPoint   = startingPoint,
                EndPointList = endingPoints,
                AmbientTrack = ambientTrack,
                LevelCoord   = levelCoord,
                Cells        = cells,
                Tiles        = new ArrayList(tiles), //FIXME
                Elements     = elements,
            };

            CurrentMap = map;

            return(map);
        }
    //GameObject互動判斷
    public void Tagtext()
    {
        //GameObject Tag判斷
        switch (hit.collider.gameObject.tag)
        {
        //取得物品
        case "InteractionGet":
        case "FireExtinguish":
        {
            ButtonE.SetActive(true);
            hit.transform.SendMessage("GetObject", gameObject, SendMessageOptions.DontRequireReceiver);
        }
        break;

        //滅火
        case "Smoke":
        {
            if (PuzzleObjController.puzzleDictionary["FireExtinguish"] == true)
            {
                ButtonE.SetActive(true);
                hit.transform.SendMessage("GetObject", gameObject, SendMessageOptions.DontRequireReceiver);
            }
        }
        break;

        //開關門
        case "Door":
        case "ToiletDoor":
        case "StudentDoor":
        case "GeneralDoor":
        case "BiologyDoor":
        case "LibraryDoor":
        {
            ButtonE.SetActive(true);
            hit.transform.SendMessage("DoorOpenClose", gameObject, SendMessageOptions.DontRequireReceiver);
        }
        break;

        //置物櫃開關門
        case "BiologyPuzzleDoor":
        {
            if (PuzzleObjController.puzzleDictionary["Key_BiologyPuzzle"] == true)
            {
                ButtonE.SetActive(true);
                hit.transform.SendMessage("DoorOpenClose", gameObject, SendMessageOptions.DontRequireReceiver);
            }
        }
        break;

        //鐵捲門開關
        case "IronDoorSwitch":
        {
            if (PuzzleObjController.puzzleDictionary["IronDoorPuzzle"] == true && PuzzleObjController.puzzleDictionary["IronDoorSwitch"] == false &&
                OutsideTheSchoolPUN.ServerConnect.playerID == 2)
            {
                ButtonE.SetActive(true);
                hit.transform.SendMessage("Switch", gameObject, SendMessageOptions.DontRequireReceiver);
            }
        }
        break;

        //蒸飯箱開關
        case "SteamBoxSwitch":
        {
            if (PuzzleObjController.puzzleDictionary["SteamBoxPuzzle"] == true && PuzzleObjController.puzzleDictionary["SteamBoxSwitch"] == false &&
                OutsideTheSchoolPUN.ServerConnect.playerID == 1)
            {
                ButtonE.SetActive(true);
                hit.transform.SendMessage("Switch", gameObject, SendMessageOptions.DontRequireReceiver);
            }
        }
        break;

        //2DUI
        case "Interaction2DUI":
        {
            if (hit.collider.gameObject.name == "Piano")
            {
                if (PuzzleObjController.puzzleDictionary["PianoFinish"] == true)
                {
                    ButtonE.SetActive(false);
                }
                else if ((PuzzleObjController.puzzleDictionary["SheetMusic902"] == true || PuzzleObjController.puzzleDictionary["SheetMusic802"] == true) &&
                         PuzzleObjController.puzzleDictionary["PianoFinish"] == false)
                {
                    ButtonE.SetActive(true);
                    hit.transform.SendMessage("Uiappear", gameObject, SendMessageOptions.DontRequireReceiver);
                }
            }
            else if (hit.collider.gameObject.name == "P1書籍謎題" || hit.collider.gameObject.name == "P2書籍謎題")
            {
                if (PuzzleObjController.puzzleDictionary["BookPuzzle"] == true)
                {
                    ButtonE.SetActive(false);
                }
                else
                {
                    ButtonE.SetActive(true);
                    hit.transform.SendMessage("Uiappear", gameObject, SendMessageOptions.DontRequireReceiver);
                }
            }
            else if (hit.collider.gameObject.name == "裝置藝術")
            {
                if (PuzzleObjController.puzzleDictionary["ArtPuzzle"] == true)
                {
                    ButtonE.SetActive(false);
                }
                else
                {
                    ButtonE.SetActive(true);
                    hit.transform.SendMessage("Uiappear", gameObject, SendMessageOptions.DontRequireReceiver);
                }
            }
            else
            {
                ButtonE.SetActive(true);
                hit.transform.SendMessage("Uiappear", gameObject, SendMessageOptions.DontRequireReceiver);
            }
        }
        break;

        //Text觸發
        case "InteractionText":
        {
            ButtonE.SetActive(true);
            hit.transform.SendMessage("Textappear", gameObject, SendMessageOptions.DontRequireReceiver);
        }
        break;

        default:
        {
            ButtonE.SetActive(false);
        }
        break;
        }
    }