Example #1
0
        public override void Execute()
        {
            base.Execute();

            Inventory inventory = Actor.GetComponent <Inventory>();

            if (inventory != null)
            {
                if (inventory.Contains(RequiredItem))
                {
                    usedItem = inventory.RemoveItem(RequiredItem);
                    Locator.Get <EntityManager>().Recycle(usedItem.GetComponent <Entity>().Guid);

                    TrapDoor.BlocksLineOfSight = false;
                    TrapDoor.BlocksMovement    = false;

                    Animator animator = TrapDoor.GetComponent <Animator>();

                    if (animator != null)
                    {
                        animator.SetBool("IsOpen", true);
                    }

                    TrapDoor trapDoor = TrapDoor.GetComponent <TrapDoor>();
                    trapDoor.IsOpen = true;

                    TrapDoor.Events.TriggerEvent(new TrapDoorOpenEvent(TrapDoor));
                }
            }
        }
Example #2
0
        protected override NodeStates Tick(Tick tick)
        {
            NodeStates    result          = NodeStates.Failure;
            GameManager   gameManager     = Locator.Get <GameManager>();
            Entity        player          = gameManager.Player;
            CellTransform playerTransform = player.CellTransform;

            Cell playerCell = gameManager.MapManager[playerTransform.Position.x, playerTransform.Position.y];

            if
            (
                playerCell != null &&
                playerCell.Prop != null &&
                playerCell.Prop.Info != null &&
                playerCell.Prop.Info.NameId == "Stairs Exit"
            )
            {
                TrapDoor trapDoor = playerCell.Prop.GetComponent <TrapDoor>();

                if (trapDoor != null && trapDoor.IsOpen)
                {
                    result = NodeStates.Success;
                }
            }

            return(result);
        }
    public override void Generate(GenerationRandom ran)
    {
        GenRan = ran;

        LocalPosition = new Vec2i(5, 5);

        // Densities = new float[TileSize.x, World.ChunkHeight, TileSize.z];
        for (int x = 0; x < TileSize.x; x++)
        {
            for (int z = 0; z < TileSize.z; z++)
            {
                float scale  = 0.1f;
                float height = (8 * Mathf.PerlinNoise(x * scale, z * scale));
                int   thingy = (int)Mathf.Clamp(8 * Mathf.PerlinNoise(x * scale, z * scale), 0, 3);
                SetHeight(x, z, height);

                /*
                 * for(int y=0; y<height; y++)
                 * {
                 *  SetVoxelNode(x, y, z, new VoxelNode(Voxel.stone));
                 *
                 * }*/
            }
        }
        SubworldEntrance = new Vec2i(5, 5);
        Exit             = new TrapDoor();
        (Exit as WorldObjectData).SetPosition(new Vec2i(5, 5));
        AddObject((Exit as WorldObjectData), true);
        return;
    }
Example #4
0
 public void Interact()
 {
     if (_isOnDialogueTrigger)
     {
         if (!_hasDialogueStarted && !_hasDialogueBeenSaid)
         {
             _playerMovement.LockMovement(true);
             _playerUI.DialogueUI.StartDialogue();
             DialogueManager.Instance.StartDialogue(_dialogue, 1);
             _hasDialogueStarted  = true;
             _hasDialogueBeenSaid = true;
         }
         else
         {
             DialogueManager.Instance.NextSentence();
             if (DialogueManager.Instance.HasDialogueEnded())
             {
                 _playerMovement.LockMovement(false);
             }
         }
     }
     if (_trapDoor != null)
     {
         _playerCinematic.EnterDoor();
         _trapDoor.OpenDoor();
         _trapDoor = null;
     }
     if (_lever != null)
     {
         _lever.OpenGate();
         _lever = null;
     }
     _playerUI.InteractUI.SetPrompt(false);
 }
Example #5
0
 public void settrap(string str)
 {
     string[] arr1 = str.Split('t');
     trapList = new List <TrapVo>(arr1.Length);
     for (int i = 0; i < arr1.Length; i++)
     {
         string[] arr = arr1[i].Split('=');
         if (arr[0] == "1")
         {
             TrapDoor trap = new TrapDoor();
             trap.type = 1;
             trap.inittrap(arr);
             trapList.Add(trap);
         }
         else if (arr[0] == "2")
         {
             MonsterRefreshVo trap = new MonsterRefreshVo();
             trap.type = 2;
             trap.inittrap(arr);
             trapList.Add(trap);
         }
         else if (arr[0] == "3")
         {
             AtkOffice trap = new AtkOffice();
             trap.type = 3;
             trap.inittrap(arr);
             trapList.Add(trap);
         }
         else if (arr[0] == "4")
         {
             CubeTrap trap = new CubeTrap();
             trap.type = 4;
             trap.inittrap(arr);
             trapList.Add(trap);
         }
         else if (arr[0] == "5")
         {
             Transfer trap = new Transfer();
             trap.type = 5;
             trap.inittrap(arr);
             trapList.Add(trap);
         }
         else if (arr[0] == "6")
         {
             TrapLandmine trap = new TrapLandmine();
             trap.type = 6;
             trap.inittrap(arr);
             trapList.Add(trap);
         }
         else if (arr[0] == "7")
         {
             TrapSpring trap = new TrapSpring();
             trap.type = 7;
             trap.inittrap(arr);
             trapList.Add(trap);
         }
     }
 }
 public void TriggerTraps()
 {
     foreach (GameObject trap in trapDoors)
     {
         TrapDoor  trapdoor = trap.GetComponent <TrapDoor>();
         Rigidbody rbL      = trapdoor.leftDoor.GetComponent <Rigidbody>();
         Rigidbody rbr      = trapdoor.rightDoor.GetComponent <Rigidbody>();
         rbL.useGravity  = true;
         rbL.isKinematic = false;
         rbr.useGravity  = true;
         rbr.isKinematic = false;
     }
 }
Example #7
0
        protected override NodeStates Tick(Tick tick)
        {
            NodeStates result     = NodeStates.Failure;
            MapManager mapManager = Locator.Get <MapManager>();
            Entity     exit       = mapManager.Map[mapManager.Map.ExitPoint].Prop;
            TrapDoor   trapDoor   = exit.GetComponent <TrapDoor>();

            if (trapDoor != null && trapDoor.IsOpen)
            {
                result = NodeStates.Success;
            }

            return(result);
        }
Example #8
0
        public override void Undo()
        {
            base.Undo();

            Inventory inventory = Actor.GetComponent <Inventory>();

            if (inventory != null)
            {
                Animator animator = TrapDoor.GetComponent <Animator>();

                if (animator != null)
                {
                    animator.SetBool("IsOpen", false);
                }

                inventory.AddItem(usedItem);
            }
        }
    public void GenerateSubworldCave(Vec2i localEntrance)
    {
        DoubleBed b = new DoubleBed();

        b.SetPosition(localEntrance);
        AddObject(b, true);
        TrapDoor td = new TrapDoor();

        td.SetPosition(localEntrance);
        AddObject(td, true);
        Debug.Log("HERHEHRE");

        CaveDungeonBuilder cdb = new CaveDungeonBuilder(localEntrance + BaseTile, new Vec2i(4, 4));

        cdb.Generate(GenRan);
        Subworld cave = cdb.ToSubworld();

        AddSubworld(td, cave);
    }
Example #10
0
 public void updataTrap(int id)
 {
     if (trapDataObject[trapObject[id]].type == 1)
     {
         TrapDoor trap = trapDataObject[trapObject[id]] as TrapDoor;
         Debug.Log(trap.curLiveEnemy);
         if (trap.curLiveEnemy > 0)
         {
             trapObject[id].GetComponent <BoxCollider>().isTrigger = false;
         }
         else
         {
             trapObject[id].GetComponent <BoxCollider>().isTrigger = true;
         }
     }
     else if (trapDataObject[trapObject[id]].type == 6)
     {
     }
 }
Example #11
0
    private bool generateTrapDoor()
    {
        doorObj = new GameObject("Door" + Room.id);
        doorObj.transform.SetParent(roomObj.transform);
        doorObj.transform.localPosition = Vector3.zero;
        door = doorObj.AddComponent <TrapDoor>();
        door.externalConstructor(new Vector2(dimensions.x, dimensions.z));

        //Generate only +z side of trapdoor
        QuadMesh meshBuilder = new QuadMesh();
        Vector3  bottomLeft, topLeft, topRight, bottomRight;

        float upperHeight = 0f;
        float lowerHeight = -RoomTools.trapDoorThickness;

        //upper plane
        bottomLeft  = new Vector3(-dimensions.x / 2, upperHeight, 0f);
        topLeft     = new Vector3(-dimensions.x / 2, upperHeight, dimensions.z / 2);
        topRight    = new Vector3(dimensions.x / 2, upperHeight, dimensions.z / 2);
        bottomRight = new Vector3(dimensions.x / 2, upperHeight, 0f);
        meshBuilder.addQuad(bottomLeft, topLeft, topRight, bottomRight);

        //lower plane
        bottomLeft  = new Vector3(-dimensions.x / 2, lowerHeight, dimensions.z / 2);
        topLeft     = new Vector3(-dimensions.x / 2, lowerHeight, 0f);
        topRight    = new Vector3(dimensions.x / 2, lowerHeight, 0f);
        bottomRight = new Vector3(dimensions.x / 2, lowerHeight, dimensions.z / 2);
        meshBuilder.addQuad(bottomLeft, topLeft, topRight, bottomRight);

        //mid plane
        bottomLeft  = new Vector3(-dimensions.x / 2, lowerHeight, 0f);
        topLeft     = new Vector3(-dimensions.x / 2, upperHeight, 0f);
        topRight    = new Vector3(dimensions.x / 2, upperHeight, 0f);
        bottomRight = new Vector3(dimensions.x / 2, lowerHeight, 0f);
        meshBuilder.addQuad(bottomLeft, topLeft, topRight, bottomRight);

        Mesh doorMesh = meshBuilder.getMesh();

        door.setDoorMesh(doorMesh);
        return(true);
    }
Example #12
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.TryGetComponent(out DialogueTrigger dialogueTrigger))
     {
         _isOnDialogueTrigger = true;
         _dialogue            = dialogueTrigger.GetDialogue();
         Vector2 dialoguePromptPosition = dialogueTrigger.GetDialoguePromptPosition();
         _playerUI.DialogueUI.SetPrompt(true, dialoguePromptPosition);
     }
     if (other.gameObject.TryGetComponent(out TrapDoor trapDoor))
     {
         _trapDoor = trapDoor;
         Vector2 promptPosition = new Vector2(transform.position.x, transform.position.y - 2.5f);
         _playerUI.InteractUI.SetPrompt(true, promptPosition);
     }
     if (other.gameObject.TryGetComponent(out Lever lever))
     {
         _lever = lever;
         Vector2 promptPosition = _lever.GetPromptPosition();
         _playerUI.InteractUI.SetPrompt(true, promptPosition);
     }
 }
Example #13
0
 void Start()
 {
     trapDoor = transform.parent.parent.GetComponent <TrapDoor> ();
     trapInfo = transform.parent.parent.GetComponent <Trap> ();
 }
Example #14
0
	void Start () {
		trapScript = connectedTrap.gameObject.GetComponent<TrapDoor> ();
	}
Example #15
0
 void Start()
 {
     trapDoor = transform.parent.parent.GetComponent<TrapDoor> ();
     trapInfo = transform.parent.parent.GetComponent<Trap> ();
 }
Example #16
0
 // Use this for initialization
 void Start()
 {
     parentDoor = this.transform.parent.GetComponent<TrapDoor>();
     spawner = this.GetComponent<StartSpawning>().spawnEnemiesGO;
 }
Example #17
0
        private void OverlayEntities(MapElement entities, Bitmap map, VirtualMap <char> solids, bool background)
        {
            CassetteBlock.Blocks.Clear();

            using (Graphics g = Graphics.FromImage(map)) {
                List <Entity> ents = new List <Entity>();
                for (int i = entities.Children.Count - 1; i >= 0; i--)
                {
                    MapElement child = entities.Children[i];

                    Entity entity = null;
                    if (child.Name.IndexOf("spikes", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        entity = background ? Spikes.FromElement(child) : null;
                    }
                    else if (child.Name.IndexOf("triggerSpikes", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        entity = background ? TriggerSpikes.FromElement(child) : null;
                    }
                    else if (child.Name.IndexOf("strawberry", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        entity = background ? Strawberry.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("goldenBerry", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Strawberry.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("redBlocks", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ClutterBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("greenBlocks", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ClutterBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("yellowBlocks", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ClutterBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("clutterCabinet", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ClutterCabinet.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("introCar", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? IntroCar.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("clothesLine", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ClothesLine.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("colorSwitch", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ColorSwitch.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("memorialTextController", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Strawberry.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("bonfire", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Bonfire.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("trapDoor", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? TrapDoor.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("movingPlatform", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? MovingPlatform.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("sinkingPlatform", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? SinkingPlatform.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("clutterDoor", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ClutterDoor.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("bridge", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Bridge.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("bridgeFixed", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? BridgeFixed.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("jumpThru", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? JumpThru.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("door", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Door.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("blockField", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? BlockField.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("lamp", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Lamp.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("hahaha", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Haha.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("waterFall", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? WaterFall.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("water", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Water.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("key", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Key.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("resortLantern", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ResortLantern.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("bird", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Bird.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("memorial", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Memorial.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("player", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? PlayerSpawn.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("zipMover", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ZipMover.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("wire", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Wire.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("crumbleBlock", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? CrumbleBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("refill", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Refill.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("spring", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Spring.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("fakeWall", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? FakeWall.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("exitBlock", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? FakeWall.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("lightBeam", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? LightBeam.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("cobweb", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Cobweb.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("cassette", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Cassette.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("flutterBird", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? FlutterBird.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("checkpoint", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Checkpoint.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("fallingBlock", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? FallingBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("introCrusher", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? FallingBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("cassetteBlock", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? CassetteBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("dashBlock", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? DashBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("coverupWall", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? CoverupWall.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("npc", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? NPC.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("birdForsakenCityGem", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? ForsakenCityGem.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("soundSource", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? SoundSource.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("friendlyGhost", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? FriendlyGhost.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("floatingDebris", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? FloatingDebris.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("hangingLamp", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? HangingLamp.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("lockBlock", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? LockBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("heartGem", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? HeartGem.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("blackGem", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? HeartGem.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("dreamMirror", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? DreamMirror.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("darkChaser", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? DarkChaser.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("dreamBlock", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? DreamBlock.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("touchSwitch", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? TouchSwitch.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("switchGate", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? SwitchGate.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("invisibleBarrier", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? InvisibleBarrier.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("payphone", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Payphone.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("spinner", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? Spinner.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("rotateSpinner", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? RotateSpinner.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("trackSpinner", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? TrackSpinner.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("towerViewer", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = background ? TowerViewer.FromElement(child) : null;
                    }
                    else if (child.Name.Equals("foregroundDebris", StringComparison.OrdinalIgnoreCase))
                    {
                        entity = !background?ForegroundDebris.FromElement(child) : null;
                    }
                    else if (background)
                    {
                        Console.WriteLine(child.Name);
                    }
                    if (entity != null)
                    {
                        ents.Add(entity);
                    }
                }

                ents.Sort(delegate(Entity one, Entity two) {
                    int comp = two.Depth.CompareTo(one.Depth);
                    return(comp == 0 ? one.ID.CompareTo(two.ID) : comp);
                });

                for (int i = 0; i < ents.Count; i++)
                {
                    Entity entity = ents[i];
                    entity.Render(g, solids);
                }
            }
        }
Example #18
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);
        }
Example #19
0
    // Use this for initialization
    void Start()
    {
        nextTrapId = 1;
        addListener(Notice.TrapCtrl_Vector, (string s, List <Vector3> v3) =>
        {
            string[] arr = s.Split('=');

            if (arr[1] == "4")
            {
                CubeTrap trap = trapDataObject[trapObject[int.Parse(arr[0])]] as CubeTrap;

                if (trap.AtkType == 1)
                {
                    MapManager.Instance.diaoluo(v3);
                }
                else if (trap.AtkType == 2)
                {
                }
            }
        });


        addListener(Notice.TrapCtrl, (string s) =>
        {
            string[] arr = s.Split('=');
            if (arr[1] == "1")
            {
                TrapDoor trap = trapDataObject[trapObject[int.Parse(arr[0])]] as TrapDoor;
                //trapDataObject[list[i].id] = trap;
                if (arr[2] == "trigger")
                {
                    if (trapObject[int.Parse(arr[0])].transform.position.y < 0)
                    {
                        trapObject[int.Parse(arr[0])].transform.Translate(new Vector3(0, 50, 0));

                        foreach (Transform child in trapObject[int.Parse(arr[0])].transform)
                        {
                            if (child.GetComponent <TrapCollisoon>())
                            {
                                if (child.GetComponent <TrapCollisoon>().use == "trigger")
                                {
                                    Destroy(child.gameObject);
                                }
                                else
                                {
                                    child.transform.Translate(new Vector3(0, -child.transform.position.y + 1, 0));
                                }
                            }
                        }
                    }
                }
                else if (arr[2] == "close")
                {
                    trap.curLiveEnemy++;
                    updataTrap(int.Parse(arr[0]));
                }
                else if (arr[2] == "open")
                {
                    trap.curLiveEnemy--;
                    updataTrap(int.Parse(arr[0]));
                }
            }
            else if (arr[1] == "4")
            {
                CubeTrap trap = trapDataObject[trapObject[int.Parse(arr[0])]] as CubeTrap;
                if (trap.AtkType == 2)
                {
                    if (arr[2] == "add")
                    {
                        GameMain.Instance.player.GetComponent <plyaer>().pushForceVector(arr[0], new Vector3(20, 0, 0));
                    }
                    else if (arr[2] == "remove")
                    {
                        GameMain.Instance.player.GetComponent <plyaer>().removeForceVector(arr[0]);
                    }
                }
            }
            else if (arr[1] == "5")
            {
                if (trapObject[int.Parse(arr[0])].transform.parent.gameObject == trapparent)
                {
                    if (trapObject[int.Parse(arr[0])].transform.position.ToString() == arr[2])
                    {
                        foreach (Transform child in trapObject[int.Parse(arr[0])].transform)
                        {
                            Vector3 v3 = child.position;
                            v3.y      += .8001f;
                            GameMain.Instance.initPlayerPostion(v3);
                        }
                    }
                }
            }
            else if (arr[1] == "6")
            {
                if (arr[2] == "trigger")
                {
                    foreach (Transform child in trapObject[int.Parse(arr[0])].transform)
                    {
                        //if (child.GetComponent<TrapCollisoon>())
                        //{
                        //if (child.GetComponent<TrapCollisoon>().use == "trigger")
                        //{
                        Destroy(child.gameObject);
                        // }
                        // }
                    }
                    tirggerArr = arr;
                    Invoke("tirggerTrap", 0.5f);
                    removeTargetTrap = trapObject[int.Parse(arr[0])];
                    Invoke("removeTrap", 2f);
                }
                else if (arr[2] == "atk")
                {
                    Notice.TrapCollision.broadcast("");
                }
            }
            else if (arr[1] == "7")
            {
                TrapSpring trap = trapDataObject[trapObject[int.Parse(arr[0])]] as TrapSpring;
                if (arr[2] == "trigger")
                {
                    if (trap.curRange != -1)
                    {
                        return;
                    }

                    trap.curRange = 1;

                    GameObject obj1           = GameObject.Instantiate(placeGameObject, trap.v3, placeGameObject.transform.rotation);
                    obj1.transform.localScale = new Vector3(1, .8f, 1);
                    obj1.transform.Translate(new Vector3(-trap.curRange / 2 + .5f, .45f, 0));
                    obj1.GetComponent <TrapCollisoon>().id   = int.Parse(arr[0]);
                    obj1.GetComponent <TrapCollisoon>().type = 7;
                    obj1.GetComponent <TrapCollisoon>().use  = "atk";
                    obj1.transform.SetParent(trapObject[int.Parse(arr[0])].transform);

                    obj1.transform.Rotate(0, trap.rotiony, 0);
                }
                else if (arr[2] == "atk" && trap.isshrink == false)
                {
                    Vector3 v3;

                    if (trap.rotiony == 90)
                    {
                        v3 = new Vector3(0, 0, 1);
                    }
                    else if (trap.rotiony == 180)
                    {
                        v3 = new Vector3(1, 0, 0);
                    }
                    else if (trap.rotiony == 270)
                    {
                        v3 = new Vector3(0, 0, -1);
                    }
                    else
                    {
                        v3 = new Vector3(-1, 0, 0);
                    }


                    GameMain.Instance.initPlayerForce(v3 * 400);
                    //Notice.TrapCollision.broadcast("");
                }
            }
        });
    }
Example #20
0
    public void inittrap(List <TrapVo> list)
    {
        for (int i = 0; i < list.Count; i++)
        {
            list[i].id = nextTrapId;
            nextTrapId++;
            if (list[i].type == 1)
            {
                TrapDoor trap = list[i] as TrapDoor;
                trap.curLiveEnemy = 0;
                GameObject obj = GameObject.Instantiate(trapListPre[0], trap.v3, trapListPre[0].transform.rotation);
                trapObject[list[i].id] = obj;
                trapDataObject[trapObject[list[i].id]] = trap;
                obj.transform.SetParent(trapparent.transform);
                if (trap.triggerPList.Count > 0)
                {
                    obj.transform.Translate(new Vector3(0, -50, 0));
                }

                for (int j = 0; j < trap.triggerPList.Count; j++)
                {
                    GameObject obj1 = GameObject.Instantiate(placeGameObject, trap.triggerPList[j], placeGameObject.transform.rotation);
                    obj1.transform.localScale = trap.triggerRList[j];
                    obj1.GetComponent <TrapCollisoon>().id   = list[i].id;
                    obj1.GetComponent <TrapCollisoon>().type = 1;
                    obj1.GetComponent <TrapCollisoon>().use  = "trigger";
                    obj1.transform.SetParent(obj.transform);
                }

                for (int j = 0; j < trap.clearPList.Count; j++)
                {
                    GameObject obj1 = GameObject.Instantiate(placeGameObject, trap.clearPList[j], placeGameObject.transform.rotation);
                    obj1.transform.localScale = trap.clearRList[j];
                    obj1.GetComponent <TrapCollisoon>().id   = list[i].id;
                    obj1.GetComponent <TrapCollisoon>().type = 1;
                    obj1.GetComponent <TrapCollisoon>().use  = "clear";
                    obj1.transform.SetParent(obj.transform);
                }
                updataTrap(nextTrapId - 1);
            }
            else if (list[i].type == 2)
            {
                MonsterRefreshVo trap = list[i] as MonsterRefreshVo;
                trap.curLiveEnemy    = 0;
                trap.currefreshindex = 0;
                GameObject obj = GameObject.Instantiate(trapListPre[1], trap.v3, trapListPre[1].transform.rotation);
                trapObject[list[i].id] = obj;
                trapDataObject[trapObject[list[i].id]] = trap;
                obj.transform.SetParent(trapparent.transform);
            }
            else if (list[i].type == 3)
            {
                AtkOffice  trap = list[i] as AtkOffice;
                GameObject obj  = GameObject.Instantiate(trapListPre[2], trap.v3, trapListPre[1].transform.rotation);
                trapObject[list[i].id] = obj;
                trapDataObject[trapObject[list[i].id]] = trap;
                obj.transform.SetParent(trapparent.transform);
            }
            else if (list[i].type == 4)
            {
                CubeTrap   trap = list[i] as CubeTrap;
                GameObject obj  = GameObject.Instantiate(placeGameObject, trap.v3, trapListPre[1].transform.rotation);
                obj.transform.localScale = trap.sv3;
                obj.GetComponent <TrapCollisoon>().id   = list[i].id;
                obj.GetComponent <TrapCollisoon>().type = 4;
                obj.GetComponent <TrapCollisoon>().use  = "atk" + trap.AtkType;
                trapObject[list[i].id] = obj;
                trapDataObject[trapObject[list[i].id]] = trap;
                obj.transform.SetParent(trapparent.transform);
            }
            else if (list[i].type == 5)
            {
                Transfer   trap = list[i] as Transfer;
                GameObject obj  = GameObject.Instantiate(trapListPre[3], trap.v3, trapListPre[3].transform.rotation);
                obj.AddComponent <TrapCollisoon>().id   = list[i].id;
                obj.GetComponent <TrapCollisoon>().type = 5;
                trapObject[list[i].id] = obj;
                trapDataObject[trapObject[list[i].id]] = trap;
                obj.transform.SetParent(trapparent.transform);

                GameObject obj1 = GameObject.Instantiate(trapListPre[3], trap.tv3, trapListPre[3].transform.rotation);
                obj1.AddComponent <TrapCollisoon>().id   = list[i].id;
                obj1.GetComponent <TrapCollisoon>().type = 5;
                obj1.transform.SetParent(obj.transform);
            }
            else if (list[i].type == 6)
            {
                TrapLandmine trap = list[i] as TrapLandmine;
                trap.curLiveEnemy = 0;
                GameObject obj = GameObject.Instantiate(trapListPre[5], trap.v3, trapListPre[0].transform.rotation);
                trapObject[list[i].id] = obj;
                trapDataObject[trapObject[list[i].id]] = trap;
                obj.transform.SetParent(trapparent.transform);


                for (int j = 0; j < trap.triggerPList.Count; j++)
                {
                    GameObject obj1 = GameObject.Instantiate(placeGameObject, trap.triggerPList[j], placeGameObject.transform.rotation);
                    obj1.transform.localScale = trap.triggerRList[j];
                    obj1.GetComponent <TrapCollisoon>().id   = list[i].id;
                    obj1.GetComponent <TrapCollisoon>().type = 6;
                    obj1.GetComponent <TrapCollisoon>().use  = "trigger";
                    obj1.transform.SetParent(obj.transform);
                }


                // updataTrap(nextTrapId - 1);
            }
            else if (list[i].type == 7)
            {
                TrapSpring trap = list[i] as TrapSpring;
                GameObject obj  = GameObject.Instantiate(trapListPre[5], trap.v3, trapListPre[0].transform.rotation);
                trapObject[list[i].id] = obj;
                trapDataObject[trapObject[list[i].id]] = trap;
                obj.transform.SetParent(trapparent.transform);

                GameObject obj1 = GameObject.Instantiate(placeGameObject, trap.v3, placeGameObject.transform.rotation);
                obj1.transform.localScale = new Vector3(trap.range, 0.1f, 1);
                obj1.transform.Translate(new Vector3(-trap.range / 2 + .5f, 0, 0));
                obj1.GetComponent <TrapCollisoon>().id   = list[i].id;
                obj1.GetComponent <TrapCollisoon>().type = 7;
                obj1.GetComponent <TrapCollisoon>().use  = "trigger";
                obj1.transform.SetParent(obj.transform);

                obj.transform.Rotate(0, trap.rotiony, 0);


                Debug.Log(trap.rotiony);
            }
        }
        //Timer time = new Timer(13, () => { Debug.Log("alwaysDo");
        // }, () => { Debug.Log("stopTimer1")};
    }