Game world controller for controlling references and various global activities
Inheritance: UWEBase
    public override string ToChatString(GameWorldController gameWorldController)
    {
        MobData mobData = gameWorldController.Model.GetMobData(MobId);
        MobType mobType = MobTypeManager.GetMobTypeByName(mobData.mob_type_name);

        return base.ToChatString(gameWorldController) + " "+mobType.Name+" died";
    }
    public override void ApplyEvent(GameWorldController gameWorldController, GameEvent.OnEventCompleteDelegate onComplete)
    {
        RoomData currentRoom = gameWorldController.Model.CurrentGame.CurrentRoom;

        base.ApplyEvent(gameWorldController, onComplete);

        if (currentRoom.RoomKey.Equals(m_mobState.CurrentRoomKey))
        {
            // Add the mob state to the current game state
            currentRoom.SetMobById(m_mobState.mob_id, m_mobState);

            // Create a new mob entity using the mob data just set in the game state
            {
                MobEntity mobEntity = new MobEntity(m_mobState.mob_id);

                mobEntity.AddToGameWorld(gameWorldController);
            }
        }

        // Completes immediately
        if (onComplete != null)
        {
            onComplete();
        }
    }
    public override void ApplyEvent(GameWorldController gameWorldController, GameEvent.OnEventCompleteDelegate onComplete)
    {
        base.ApplyEvent(gameWorldController, onComplete);

        EnergyTankEntity energyTankEntity = gameWorldController.Model.GetEnergyTankEntity(EnergyTankId);

        energyTankEntity.Energy = (uint)Math.Max((int)energyTankEntity.Energy - EnergyDrained, 0);

        if (DrainerFaction == GameConstants.eFaction.ai)
        {
            MobEntity mobEntity = gameWorldController.Model.GetMobEntity(DrainerId);

            mobEntity.Energy = mobEntity.Energy + EnergyDrained;
        }
        else if (DrainerFaction == GameConstants.eFaction.player)
        {
            CharacterEntity characterEntity = gameWorldController.Model.GetCharacterEntity(DrainerId);

            characterEntity.Energy = characterEntity.Energy + EnergyDrained;
        }

        // Completes immediately
        if (onComplete != null)
        {
            onComplete();
        }
    }
    public override void ApplyEvent(GameWorldController gameWorldController, GameEvent.OnEventCompleteDelegate onComplete)
    {
        GameData currentGame = gameWorldController.Model.CurrentGame;

        if (currentGame.CharacterID != _characterState.character_id)
        {
            base.ApplyEvent(gameWorldController, onComplete);

            // Add the character state to the current game state
            currentGame.SetCharacterById(_characterState.character_id, _characterState);

            // Create a new character entity using the character data just set in the game state
            {
                CharacterEntity characterEntity = new CharacterEntity(_characterState.character_id);

                characterEntity.AddToGameWorld(gameWorldController);
            }
        }
        else
        {
            Debug.Log("Ignoring apply CharacterJoinedGame event for primary character_id=" + _characterState.character_id);
        }

        // Completes immediately
        if (onComplete != null)
        {
            onComplete();
        }
    }
    public override void ApplyEvent(GameWorldController gameWorldController, GameEvent.OnEventCompleteDelegate onComplete)
    {
        GameData currentGame = gameWorldController.Model.CurrentGame;

        if (currentGame.CharacterID != _characterState.character_id)
        {
            base.ApplyEvent(gameWorldController, onComplete);

            // Clean up the entity
            {
                CharacterEntity characterEntity = gameWorldController.Model.GetCharacterEntity(_characterState.character_id);

                characterEntity.RemoveFromGameWorld(gameWorldController);
            }

            // Remove the character data from the current game state
            currentGame.SetCharacterById(_characterState.character_id, null);
        }
        else
        {
            Debug.Log("Ignoring apply CharacterLeftGame event for primary character_id=" + _characterState.character_id);
        }

        // Completes immediately
        if (onComplete != null)
        {
            onComplete();
        }
    }
    public override string ToChatString(GameWorldController gameWorldController)
    {
        MobData mobData= gameWorldController.Model.GetMobData(MobId);
        MobType mobType = MobTypeManager.GetMobTypeByName(mobData.mob_type_name);

        // TODO: Display what the mob ID attacked
        return base.ToChatString(gameWorldController)+" "+mobType.Name+" attacked";
    }
    public override string ToChatString(GameWorldController gameWorldController)
    {
        MobData mobData = gameWorldController.Model.GetMobData(MobId);
        MobType mobType= MobTypeManager.GetMobTypeByName(mobData.mob_type_name);
        string characterName = gameWorldController.Model.GetCharacterData(CharacterID).character_name;

        return base.ToChatString(gameWorldController) + mobType.Name + " lost track of " + characterName;
    }
    public override void ApplyEvent(GameWorldController gameWorldController, OnEventCompleteDelegate onComplete)
    {
        base.ApplyEvent(gameWorldController, onComplete);

        CharacterData character = gameWorldController.Model.GetCharacterData(CharacterID);

        // Update the room key and position on the character that changed rooms
        character.room_x = ToRoomKey.x;
        character.room_y = ToRoomKey.y;
        character.room_z = ToRoomKey.z;
        character.x = ToPosition.x;
        character.y = ToPosition.y;
        character.z = ToPosition.z;

        // Character is the current game character
        if (CharacterID == gameWorldController.Model.CurrentCharacterID)
        {
            // Request the static room data for the room the character is portal-ing to
            // event application won't advance while waiting on room data to load from the server.
            // Once we get the new room data we rebuild everything.
            gameWorldController.Model.RequestRoomData(ToRoomKey, onComplete);
        }
        // Character is some other game character
        else
        {
            // Get the character entity for the character id, if any exists
            CharacterEntity entity = gameWorldController.Model.GetCharacterEntity(CharacterID);

            // Character portal-ed to the current room.
            // Make sure the character exists and is at the correct location.
            if (gameWorldController.Model.CurrentGame.CurrentRoomKey.Equals(ToRoomKey))
            {
                if (entity == null)
                {
                    entity = new CharacterEntity(CharacterID);
                    entity.AddToGameWorld(gameWorldController);
                }

                entity.SnapTo(ToPosition, ToAngle);
            }
            // Character left the current room.
            // Make sure the character entity is cleaned up.
            else
            {
                if (entity != null)
                {
                    entity.RemoveFromGameWorld(gameWorldController);
                }
            }

            if (onComplete != null)
            {
                onComplete();
            }
        }
    }
    public override string ToChatString(GameWorldController gameWorldController)
    {
        MobData mobData = gameWorldController.Model.GetMobData(MobId);
        MobType mobType= MobTypeManager.GetMobTypeByName(mobData.mob_type_name);

        MobData spottedMobData = gameWorldController.Model.GetMobData(SpottedMobID);
        MobType spottedMobType = MobTypeManager.GetMobTypeByName(spottedMobData.mob_type_name);

        return base.ToChatString(gameWorldController) + mobType.Name + " spotted " + spottedMobType.Name;
    }
    public override void ApplyEvent(GameWorldController gameWorldController, GameEvent.OnEventCompleteDelegate onComplete)
    {
        base.ApplyEvent(gameWorldController, onComplete);

        // Completes immediately
        if (onComplete != null)
        {
            onComplete();
        }
    }
Example #11
0
    public GameWorldDebug(GameWorldController gameWorldController)
    {
        _gameWorldController = gameWorldController;
        _pathComputer = new PathComputer();

        DebugRegistry.SetToggle("entity.pathfinding.render_debug_path", false);
        DebugRegistry.SetToggle("entity.pathfinding.render_nav_mesh", false);
        DebugRegistry.SetToggle("entity.pathfinding.render_visibility", false);
        DebugRegistry.SetToggle("ui.outline_hover_widget", false);
        DebugRegistry.SetToggle("ui.show_cursor_position", false);
    }
    public override string ToChatString(GameWorldController gameWorldController)
    {
        string speakerName = "";

        MobData mobData = gameWorldController.Model.GetMobData(MobId);
        MobType mobType= MobTypeManager.GetMobTypeByName(mobData.mob_type_name);

        speakerName = mobType.Name;

        return base.ToChatString(gameWorldController) + speakerName + " said \"" + Dialog + "\"";
    }
    public override void ApplyEvent(GameWorldController gameWorldController, GameEvent.OnEventCompleteDelegate onComplete)
    {
        base.ApplyEvent(gameWorldController, onComplete);

        // TODO: Actually de-spawn the mob sprite

        // Completes immediately
        if (onComplete != null)
        {
            onComplete();
        }
    }
    public override void ApplyEvent(GameWorldController gameWorldController, GameEvent.OnEventCompleteDelegate onComplete)
    {
        base.ApplyEvent(gameWorldController, onComplete);

        //TODO: Spawn "spotted" effect on energy tank

        // Completes immediately
        if (onComplete != null)
        {
            onComplete();
        }
    }
    public override void ApplyEvent(GameWorldController gameWorldController, GameEvent.OnEventCompleteDelegate onComplete)
    {
        base.ApplyEvent(gameWorldController, onComplete);

        EnergyTankEntity energyTankEntity = gameWorldController.Model.GetEnergyTankEntity(EnergyTankId);

        energyTankEntity.Ownership = EnergyTankFaction;

        // Completes immediately
        if (onComplete != null)
        {
            onComplete();
        }
    }
    public override void ApplyEvent(GameWorldController gameWorldController, GameEvent.OnEventCompleteDelegate onComplete)
    {
        base.ApplyEvent(gameWorldController, onComplete);

        MobEntity entity = gameWorldController.Model.GetMobEntity(MobId);

        entity.PostDialogEvent(Dialog);

        // Completes immediately
        if (onComplete != null)
        {
            onComplete();
        }
    }
    public override void UndoEvent(GameWorldController gameWorldController)
    {
        RoomData currentRoom = gameWorldController.Model.CurrentGame.CurrentRoom;

        if (currentRoom.RoomKey.Equals(m_mobState.CurrentRoomKey))
        {
            MobEntity mobEntity = gameWorldController.Model.GetMobEntity(m_mobState.mob_id);

            // Clean up the entity
            mobEntity.RemoveFromGameWorld(gameWorldController);

            // Remove the mob data from the current game state
            currentRoom.SetMobById(m_mobState.mob_id, null);
        }

        base.UndoEvent(gameWorldController);
    }
    public override string ToChatString(GameWorldController gameWorldController)
    {
        string resultString = "";
        CharacterData characterData = gameWorldController.Model.GetCharacterData(CharacterID);

        if (characterData != null)
        {
            string characterName = characterData.character_name;

            resultString = base.ToChatString(gameWorldController) + characterName + " updated";
        }
        else
        {
            resultString = base.ToChatString(gameWorldController) + "another player updated";
        }

        return resultString;
    }
    public override string ToChatString(GameWorldController gameWorldController)
    {
        string hackerName = "";

        if (HackerFaction == GameConstants.eFaction.ai)
        {
            MobData mobData = gameWorldController.Model.GetMobData(HackerId);
            MobType mobType = MobTypeManager.GetMobTypeByName(mobData.mob_type_name);

            hackerName = mobType.Name;
        }
        else if (HackerFaction == GameConstants.eFaction.player)
        {
            hackerName = gameWorldController.Model.GetCharacterData(HackerId).character_name;
        }

        return base.ToChatString(gameWorldController) + " Energy Tank hacked by " + hackerName;
    }
Example #20
0
    private Dictionary<int, MobEntity> m_mobEntities; // mob_id -> MobEntity

    #endregion Fields

    #region Constructors

    public GameWorldModel(GameWorldController gameWorldController)
    {
        m_gameWorldController = gameWorldController;

        EventPlaybackMode = eGameEventMode.paused;
        IsWaitingForEventCompletion = false;

        m_characterEntities= new Dictionary<int, CharacterEntity>();
        m_mobEntities = new Dictionary<int, MobEntity>();
        m_energyTankEntities= new Dictionary<int, EnergyTankEntity>();

        IsFullGameStateRequestPending= false;
        IsRoomDataRequestPending= false;
        IsCharacterMoveRequestPending= false;
        IsCharacterPingRequestPending= false;
        IsCharacterPortalRequestPending= false;
        IsHackEnergyTankRequestPending= false;
        IsDrainEnergyTankRequestPending= false;
        IsLogoutRequestPending = false;
    }
    public override void UndoEvent(GameWorldController gameWorldController)
    {
        GameData currentGame = gameWorldController.Model.CurrentGame;

        if (currentGame.CharacterID != _characterState.character_id)
        {
            CharacterEntity characterEntity = gameWorldController.Model.GetCharacterEntity(_characterState.character_id);

            // Clean up the entity
            characterEntity.RemoveFromGameWorld(gameWorldController);

            // Remove the character data from the current game state
            currentGame.SetCharacterById(_characterState.character_id, null);

            base.UndoEvent(gameWorldController);
        }
        else
        {
            Debug.Log("Ignoring undo CharacterJoinedGame event for primary character_id=" + _characterState.character_id);
        }
    }
    public override void UndoEvent(GameWorldController gameWorldController)
    {
        GameData currentGame = gameWorldController.Model.CurrentGame;

        if (currentGame.CharacterID != _characterState.character_id)
        {
            // Add the character state back into to the current game state
            gameWorldController.Model.CurrentGame.SetCharacterById(_characterState.character_id, _characterState);

            // Create a new character entity using the character data just set in the game state
            {
                CharacterEntity characterEntity = new CharacterEntity(_characterState.character_id);

                characterEntity.AddToGameWorld(gameWorldController);
            }

            base.UndoEvent(gameWorldController);
        }
        else
        {
            Debug.Log("Ignoring undo CharacterLeftGame event for primary character_id=" + _characterState.character_id);
        }
    }
    public override void ApplyEvent(GameWorldController gameWorldController, OnEventCompleteDelegate onComplete)
    {
        base.ApplyEvent(gameWorldController, onComplete);

        CharacterEntity entity = gameWorldController.Model.GetCharacterEntity(CharacterID);

        if (onComplete != null)
        {
            entity.RequestMoveTo(ToPosition, ToAngle, (PathComputer.eResult resultCode) =>
            {
                if (resultCode != PathComputer.eResult.success)
                {
                    Debug.Log("GameEvent_CharacterMoved:apply_event - Failed to compute path to event target, ResultCode=" + resultCode);
                    entity.SnapTo(ToPosition, ToAngle);
                }

                onComplete();
            });
        }
        else
        {
            entity.SnapTo(ToPosition, ToAngle);
        }
    }
    /// <summary>
    /// Applies the armour damage to the players armour (random piece)
    /// If no piece is in the slot picked then no damage is applied
    /// </summary>
    public void ApplyArmourDamage(short armourDamage)
    {
        int[] slots         = { 0, 1, 2, 3, 4, 7, 8 };
        int   PieceToDamage = slots[Random.Range(0, slots.GetUpperBound(0))];

        PieceToDamage = 2;                      //test
        GameObject obj = GetGameObjectAtSlot(PieceToDamage);

        if (obj != null)
        {
            switch (PieceToDamage)
            {
            case 0:                    //Helm
            case 1:                    //Chest
            case 2:                    //Leggings
            case 3:                    //Boots
            case 4:                    //Gloves
                if (obj.gameObject.GetComponent <Armour>() != null)
                {
                    short durability = obj.gameObject.GetComponent <Armour>().getDurability();
                    if (durability <= 30)
                    {
                        obj.gameObject.GetComponent <Armour>().SelfDamage((short)(Mathf.Max(0, armourDamage - durability)));
                        if (obj.gameObject.GetComponent <ObjectInteraction>().quality <= 0)
                        {
                            playerUW.playerInventory.ClearSlot((short)PieceToDamage);
                            obj.transform.parent   = GameWorldController.instance.LevelMarker().transform;
                            obj.transform.position = playerUW.transform.position;
                            GameWorldController.MoveToWorld(obj.GetComponent <ObjectInteraction>());
                            GameWorldController.UnFreezeMovement(obj);
                            playerUW.playerInventory.Refresh();
                        }
                    }
                }
                break;

            case 7:                    //HandRight
                if (!UWCharacter.Instance.isLefty)
                {
                    if (obj.gameObject.GetComponent <Shield>() != null)
                    {
                        short durability = obj.gameObject.GetComponent <Shield>().getDurability();
                        if (durability <= 30)
                        {
                            obj.gameObject.GetComponent <Shield>().SelfDamage((short)(Mathf.Max(0, armourDamage - durability)));
                            if (obj.gameObject.GetComponent <ObjectInteraction>().quality <= 0)
                            {
                                playerUW.playerInventory.Refresh();
                            }
                        }
                    }
                }
                break;

            case 8:                    //HandLeft
                if (UWCharacter.Instance.isLefty)
                {
                    if (obj.gameObject.GetComponent <Shield>() != null)
                    {
                        short durability = obj.gameObject.GetComponent <Shield>().getDurability();
                        if (durability <= 30)
                        {
                            obj.gameObject.GetComponent <Shield>().SelfDamage((short)(Mathf.Max(0, armourDamage - durability)));
                            if (obj.gameObject.GetComponent <ObjectInteraction>().quality <= 0)
                            {
                                playerUW.playerInventory.Refresh();
                            }
                        }
                    }
                }
                break;
            }
        }
    }
Example #25
0
    public void SpillContents()
    {
        TileMap tm = GameWorldController.instance.currentTileMap();                        //GameObject.Find("Tilemap").GetComponent<TileMap>();

        GameWorldController.FreezeMovement(this.gameObject);
        ObjectInteraction objInt = this.gameObject.GetComponent <ObjectInteraction>();

        objInt.UpdatePosition();
        objInt.SetWorldDisplay(objInt.GetEquipDisplay());
        objInt.link = 0;                       //So items in world will not create infinitly lopping references
        for (short i = 0; i <= MaxCapacity(); i++)
        {
            GameObject Spilled = GetGameObjectAt(i);                                    //GameObject.Find (GetItemAt (i));
            if (Spilled != null)
            {
                if (Spilled.GetComponent <trigger_base>() != null)
                {
                    Spilled.GetComponent <trigger_base>().Activate(this.gameObject);
                }
                else
                {
                    ObjectInteraction objSpilled = Spilled.GetComponent <ObjectInteraction>();
                    Spilled.transform.position = this.transform.position;
                    objSpilled.UpdatePosition();
                    switch (tm.Tiles[objInt.tileX, objInt.tileY].tileType)
                    {
                    case TileMap.TILE_OPEN:
                    case TileMap.TILE_SLOPE_N:
                    case TileMap.TILE_SLOPE_S:
                    case TileMap.TILE_SLOPE_E:
                    case TileMap.TILE_SLOPE_W:
                        objSpilled.x = (short)Random.Range(1, 7);
                        objSpilled.y = (short)Random.Range(1, 7);
                        break;

                    case TileMap.TILE_DIAG_SE:
                        objSpilled.x = (short)Random.Range(1, 7);
                        objSpilled.y = (short)Random.Range(0, objSpilled.x);
                        break;

                    case TileMap.TILE_DIAG_SW:
                        objSpilled.x = (short)Random.Range(1, 7);
                        objSpilled.y = (short)Random.Range(1, 7 - objSpilled.x);
                        break;

                    case TileMap.TILE_DIAG_NE:
                        objSpilled.x = (short)Random.Range(1, 7);
                        objSpilled.y = (short)Random.Range(8 - objSpilled.x, 8);
                        break;

                    case TileMap.TILE_DIAG_NW:
                        objSpilled.x = (short)Random.Range(1, 7);
                        objSpilled.y = (short)Random.Range(objSpilled.x, 8);
                        break;
                    }
                    objSpilled.zpos = (short)(tm.Tiles[objInt.tileX, objInt.tileY].floorHeight * 4);
                    objSpilled.objectloaderinfo.x    = objSpilled.x;
                    objSpilled.objectloaderinfo.y    = objSpilled.y;
                    objSpilled.objectloaderinfo.zpos = objSpilled.zpos;
                    objSpilled.transform.position    = ObjectLoader.CalcObjectXYZ(_RES, tm, tm.Tiles, GameWorldController.instance.CurrentObjectList().objInfo, objSpilled.objectloaderinfo.index, this.objInt().objectloaderinfo.tileX, this.objInt().objectloaderinfo.tileY, 0);
                    RemoveItemFromContainer(i);
                    Spilled.GetComponent <ObjectInteraction>().PickedUp = false;
                    GameWorldController.UnFreezeMovement(Spilled);
                }
            }
        }
    }
    /*protected override void AppendParameters(JsonData parameters)
    {
        base.AppendParameters(parameters);

        parameters["character_state"] = _characterState.ToObject();
    }*/
    public override string ToChatString(GameWorldController gameWorldController)
    {
        return base.ToChatString(gameWorldController) + _characterState.character_name + " joined the game";
    }
Example #27
0
 /// <summary>
 /// Constructor for GameState
 /// </summary>
 /// <param name="frame">Frame for hooking up User Iterface Events.</param>
 public GameState()
 {
     GameController = new GameWorldController();
 }
    /// <summary>
    /// Throws the object in hand along a vector in the 3d view.
    /// </summary>
    protected override void ThrowObjectInHand()
    {
        base.ThrowObjectInHand();
        if (UWCharacter.Instance.playerInventory.GetObjectInHand() != "")
        {                                                                   //The player is holding something
            if (UWCharacter.Instance.playerInventory.JustPickedup == false) //To prevent the click event dropping an object immediately after pickup
            {
                //Determine what is directly in front of the player via a raycast
                //If something is in the way then cancel the drop
                //Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                Ray ray;
                if (UWCharacter.Instance.MouseLookEnabled == true)
                {
                    ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
                }
                else
                {
                    ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                }


                RaycastHit hit       = new RaycastHit();
                float      dropRange = 0.5f;
                if (!Physics.Raycast(ray, out hit, dropRange))
                {                                                //No object interferes with the drop
                    //Calculate the force based on how high the mouse is
                    float force = Input.mousePosition.y / Camera.main.pixelHeight * 200;
                    //float force = Camera.main.ViewportToWorldPoint(Input.mousePosition).y/Camera.main.pixelHeight *200;


                    //Get the object being dropped and moved towards the end of the ray

                    GameObject droppedItem = UWCharacter.Instance.playerInventory.GetGameObjectInHand();                                                             //GameObject.Find(UWCharacter.Instance.playerInventory.ObjectInHand);


                    droppedItem.GetComponent <ObjectInteraction>().PickedUp = false;                                                            //Back in the real world
                    droppedItem.GetComponent <ObjectInteraction>().Drop();
                    droppedItem.GetComponent <ObjectInteraction>().UpdateAnimation();

                    if (droppedItem.GetComponent <Container>() != null)
                    {                                                            //Set the picked up flag recursively for container items.
                        Container.SetPickedUpFlag(droppedItem.GetComponent <Container>(), false);
                        Container.SetItemsParent(droppedItem.GetComponent <Container>(), GameWorldController.instance.LevelMarker());
                        Container.SetItemsPosition(droppedItem.GetComponent <Container>(), UWCharacter.Instance.playerInventory.InventoryMarker.transform.position);
                    }
                    droppedItem.transform.position = ray.GetPoint(dropRange - 0.1f);                                                        //UWCharacter.Instance.transform.position;

                    droppedItem.transform.parent = GameWorldController.instance.LevelMarker();
                    GameWorldController.MoveToWorld(droppedItem);

                    GameWorldController.UnFreezeMovement(droppedItem);
                    if (Camera.main.ScreenToViewportPoint(Input.mousePosition).y > 0.4f)
                    {                                                            //throw if above a certain point in the view port.
                        Vector3 ThrowDir = ray.GetPoint(dropRange) - ray.origin;
                        //Apply the force along the direction.
                        droppedItem.GetComponent <Rigidbody>().AddForce(ThrowDir * force);
                    }

                    //Clear the object and reset the cursor
                    UWHUD.instance.CursorIcon = UWHUD.instance.CursorIconDefault;
                    UWCharacter.Instance.playerInventory.SetObjectInHand("");
                }
            }
            else
            {
                UWCharacter.Instance.playerInventory.JustPickedup = false;                                              //The next click event will allow dropping.
            }
        }
    }
Example #29
0
 public virtual void UndoEvent(GameWorldController gameWorldController)
 {
     // Nothing to do in the base class
 }
Example #30
0
    private void MusicInstrumentInteaction()
    {
        if (Input.GetKeyDown("1"))
        {
            PlayNote(1);
        }
        if (Input.GetKeyDown("2"))
        {
            PlayNote(2);
        }
        if (Input.GetKeyDown("3"))
        {
            PlayNote(3);
        }
        if (Input.GetKeyDown("4"))
        {
            PlayNote(4);
        }
        if (Input.GetKeyDown("5"))
        {
            PlayNote(5);
        }
        if (Input.GetKeyDown("6"))
        {
            PlayNote(6);
        }
        if (Input.GetKeyDown("7"))
        {
            PlayNote(7);
        }
        if (Input.GetKeyDown("8"))
        {
            PlayNote(8);
        }
        if (Input.GetKeyDown("9"))
        {
            PlayNote(9);
        }
        if (Input.GetKeyDown("0"))
        {
            PlayNote(10);
        }
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            //000~001~251~You put the instrument down.
            PlayingInstrument = false;
            CurrentInstrument = "";
            WindowDetectUW.WaitingForInput           = false;
            UWCharacter.Instance.playerMotor.enabled = true;
            UWHUD.instance.MessageScroll.Add(StringController.instance.GetString(1, StringController.str_you_put_the_instrument_down_));
            GameWorldController.instance.getMus().Resume();
            //354237875
            if (_RES == GAME_UW1)
            {
                if ((NoteRecord == "354237875") && (objInt().item_id == 292))            //Flute only
                {
                    //UWHUD.instance.MessageScroll.Add ("Eyesnack would be proud of your playing");
                    if ((GameWorldController.instance.LevelNo == 2) && (Quest.instance.isCupFound == false) && (objInt().item_id == 292))
                    {
                        int tileX = TileMap.visitTileX;
                        int tileY = TileMap.visitTileY;
                        if (((tileX >= 23) && (tileX <= 27)) && ((tileY >= 43) && (tileY <= 45)))
                        {
                            //create the cup of wonder.

                            ObjectLoaderInfo newobjt = ObjectLoader.newObject(174, 0, 0, 0, 256);
                            GameObject       cup     = ObjectInteraction.CreateNewObject(GameWorldController.instance.currentTileMap(), newobjt, GameWorldController.instance.CurrentObjectList().objInfo, GameWorldController.instance.InventoryMarker.gameObject, GameWorldController.instance.InventoryMarker.transform.position).gameObject;
                            GameWorldController.MoveToInventory(cup);
                            ObjectInteraction myObjInt = cup.GetComponent <ObjectInteraction>();

                            /*	ObjectInteraction myObjInt = ObjectInteraction.CreateNewObject(174);
                             * myObjInt.gameObject.transform.parent=GameWorldController.instance.InventoryMarker.transform;
                             * GameWorldController.MoveToInventory(myObjInt.gameObject);*/
                            UWCharacter.Instance.playerInventory.ObjectInHand = myObjInt.name;
                            UWHUD.instance.CursorIcon        = myObjInt.GetInventoryDisplay().texture;
                            UWCharacter.InteractionMode      = UWCharacter.InteractionModePickup;
                            InteractionModeControl.UpdateNow = true;
                            Quest.instance.isCupFound        = true;
                            //An object appears in the air and falls into your hands
                            UWHUD.instance.MessageScroll.Add(StringController.instance.GetString(1, 136));
                        }
                    }
                }
            }
        }
    }
    public override void UndoEvent(GameWorldController gameWorldController)
    {
        base.UndoEvent(gameWorldController);

        CharacterEntity entity = gameWorldController.Model.GetCharacterEntity(CharacterID);

        entity.SnapTo(FromPosition, FromAngle);
    }
Example #32
0
 /// <summary>
 /// Constructor for GameState
 /// </summary>
 /// <param name="frame">Frame for hooking up User Iterface Events.</param>
 public ClientState()
 {
     GameController = new GameWorldController();
 }
 public ContextOverlayController(GameWorldController gameWorldController)
 {
     m_gameWorldController = gameWorldController;
     m_contextOverlayModel = new ContextOverlayModel(this);
     m_contextOverlayView  = new ContextOverlayView(this);
 }
/*
 * A change terrain trap changes a tile from one type to another. It works over a range of tiles that are set by the traps
 * x,y values. In Underworld these are set by the the relative position of the trap within the tile.
 * The tile it acts on is controlled by the trigger.
 *
 * Examples of it's usage
 * The Moonstone room on Level2
 * The path to the sword hilt on Level3
 *
 */

    public override void ExecuteTrap(object_base src, int triggerX, int triggerY, int State)
    {
        //Debug.Log (this.name);
        int textureQuality = (objInt().quality >> 1) & 0xf;

        for (short x = 0; x <= objInt().x; x++)
        {
            for (short y = 0; y <= objInt().y; y++)
            {
                short      tileXToChange = (short)(x + triggerX);
                short      tileYToChange = (short)(y + triggerY);
                GameObject tile          = GameWorldController.FindTile(tileXToChange, tileYToChange, TileMap.SURFACE_FLOOR);
                if (tile != null)
                {
                    TileInfo tileToChange = GameWorldController.instance.currentTileMap().Tiles[tileXToChange, tileYToChange];
                    //Destroy (tile);

                    switch (_RES)
                    {                            //I will probably have to change this again!
                    //case GAME_UW2:
                    //	tileToChange.floorTexture=textureQuality;
                    //	break;
                    default:
                        if (textureQuality < 10)
                        {
                            tileToChange.floorTexture = (short)textureQuality;                                  //+48;
                            //tileToChange.floorTexture=GameWorldController.instance.currentTileMap().texture_map[textureQuality+48];
                        }
                        break;
                    }

                    //currobj.zpos >> 2
                    //(objList[k].zpos >> 2);
                    tileToChange.Render = true;
                    for (int v = 0; v < 6; v++)
                    {
                        tileToChange.VisibleFaces[v] = true;
                    }
                    short tileTypeToChangeTo = (short)(objInt().quality & 0x01);
                    short newTileHeight;         // = (short)(objInt().zpos>>2);
                    if (objInt().zpos == 120)
                    {                            //If at this height use the trigger zpos for height instead.
                        newTileHeight = (short)(src.objInt().zpos >> 2);
                    }
                    else
                    {
                        newTileHeight = (short)(objInt().zpos >> 2);
                    }
                    short newWallTexture = tileToChange.wallTexture;
                    if (_RES == GAME_UW2)
                    {                            //Also the owner can be used to change wall texture. This means changing it's neighours.
                        if (objInt().owner < 63)
                        {
                            newWallTexture = objInt().owner;
                        }
                    }

                    //tileToChange.tileType=tileTypeToChangeTo;
                    tileToChange.DimX = 1;
                    tileToChange.DimY = 1;

                    ////tileToChange.floorHeight=newTileHeight;
                    //tileToChange.floorHeight=tileToChange.floorHeight;//DOUBLE CHECK THIS
                    tileToChange.isWater = TileMap.isTextureWater(GameWorldController.instance.currentTileMap().texture_map[tileToChange.floorTexture]);
                    //TileMapRenderer.RenderTile(GameWorldController.instance.LevelModel,tileXToChange,tileYToChange,tileToChange,tileToChange.isWater,false,false,true);
                    tileToChange.TileNeedsUpdate();
                    TileMapRenderer.UpdateTile(tileXToChange, tileYToChange, tileTypeToChangeTo, newTileHeight, tileToChange.floorTexture, newWallTexture, false);
                    Destroy(tile);

                    if (tileToChange.isDoor)
                    {                            //The door may be rendered
                        GameObject door = GameWorldController.findDoor(tileToChange.tileX, tileToChange.tileY);
                        if (door != null)
                        {
                            string doorname = ObjectLoader.UniqueObjectName(door.GetComponent <ObjectInteraction>().objectloaderinfo);
                            DestroyDoorPortion("front_leftside_" + doorname);
                            DestroyDoorPortion("front_over_" + doorname);
                            DestroyDoorPortion("front_rightside_" + doorname);
                            DestroyDoorPortion("side1_filler_" + doorname);
                            DestroyDoorPortion("over_filler_" + doorname);
                            DestroyDoorPortion("side2_filler_" + doorname);
                            DestroyDoorPortion("front_filler_" + doorname);
                            DestroyDoorPortion("rear_leftside_" + doorname);
                            DestroyDoorPortion("rear_over_" + doorname);
                            DestroyDoorPortion("rear_rightside_" + doorname);
                            DestroyDoorPortion(doorname);
                            TileMapRenderer.RenderDoor(
                                GameWorldController.instance.DynamicObjectMarker().gameObject,
                                GameWorldController.instance.currentTileMap(),
                                GameWorldController.instance.CurrentObjectList(),
                                door.GetComponent <ObjectInteraction>().objectloaderinfo.index);

/*								TileMapRenderer.RenderDoorwayFront(
 *                                                              GameWorldController.instance.LevelModel,
 *                                                                                                      GameWorldController.instance.currentTileMap(),
 *                                                                                                      GameWorldController.instance.CurrentObjectList(),
 *                                                                                                      door.GetComponent<ObjectInteraction>().objectloaderinfo
 *                                                                                                      );
 *                                                              TileMapRenderer.RenderDoorwayRear(
 *                                                                                              GameWorldController.instance.LevelModel,
 *                                                                                              GameWorldController.instance.currentTileMap(),
 *                                                                                              GameWorldController.instance.CurrentObjectList(),
 *                                                                                              door.GetComponent<ObjectInteraction>().objectloaderinfo
 *                                                                                                      );*/
                            Vector3 objPos = door.transform.position;
                            ObjectInteraction.CreateNewObject(GameWorldController.instance.currentTileMap(),
                                                              door.GetComponent <ObjectInteraction>().objectloaderinfo,
                                                              GameWorldController.instance.CurrentObjectList().objInfo,
                                                              GameWorldController.instance.LevelModel, objPos
                                                              );
                        }
                    }
                }
                else
                {
                    Debug.Log(this.name + " Unable to find tile for change terrain trap " + tileXToChange + " " + tileYToChange);
                }
            }
        }

        GameWorldController.WorldReRenderPending = true;

        //	if ((objInt().owner<63) && (_RES==GAME_UW2))
        //	{
        //Now force re-render the tiles and their neighbours
        for (int x = -1; x <= objInt().x + 1; x++)
        {
            for (int y = -1; y <= objInt().y + 1; y++)
            {
                int tileXToChange = x + triggerX;
                int tileYToChange = y + triggerY;

                GameObject tile = GameWorldController.FindTile(tileXToChange, tileYToChange, TileMap.SURFACE_FLOOR);
                if (tile != null)
                {
                    Destroy(tile);
                }
                if ((tileXToChange >= 0) && (tileXToChange <= 63) && (tileYToChange >= 0) && (tileYToChange <= 63))
                {
                    TileInfo tileToChange = GameWorldController.instance.currentTileMap().Tiles[tileXToChange, tileYToChange];
                    tileToChange.Render = true;
                    for (int v = 0; v < 6; v++)
                    {
                        tileToChange.VisibleFaces[v] = true;
                    }
                    tileToChange.isWater = TileMap.isTextureWater(GameWorldController.instance.currentTileMap().texture_map[tileToChange.floorTexture]);
                    //TileMapRenderer.RenderTile(GameWorldController.instance.LevelModel,tileXToChange,tileYToChange,tileToChange,tileToChange.isWater,false,false,true);
                    tileToChange.TileNeedsUpdate();
                }
            }
        }
        //}
    }
    public void OnSubmitPickup(int quant)
    {
        InputField inputctrl = UWHUD.instance.InputControl;

        inputctrl.text = "";
        inputctrl.gameObject.SetActive(false);
        WindowDetect.WaitingForInput = false;
        ConversationVM.EnteringQty   = false;
        if (ConversationVM.InConversation == false)
        {
            UWHUD.instance.MessageScroll.Clear();
            Time.timeScale = 1.0f;
        }
        else
        {
            UWHUD.instance.MessageScroll.NewUIOUt.text = InventorySlot.TempLookAt;//Restore original text
        }

        if (quant == 0)
        {//cancel
            QuantityObj = null;
        }
        if (QuantityObj != null)
        {//Just do a normal pickup.
            if (quant >= QuantityObj.GetComponent <ObjectInteraction>().link)
            {
                CurrentObjectInHand = QuantityObj;
                //UWHUD.instance.CursorIcon= QuantityObj.GetComponent<ObjectInteraction>().GetInventoryDisplay().texture;
                if (this.slotIndex >= 11)
                {
                    UWCharacter.Instance.playerInventory.GetCurrentContainer().RemoveItemFromContainer(UWCharacter.Instance.playerInventory.ContainerOffset + this.slotIndex - 11);
                }
                UWCharacter.Instance.playerInventory.ClearSlot(this.slotIndex);
            }
            else
            {
                //split the obj.
                ObjectInteraction objI = QuantityObj.GetComponent <ObjectInteraction>();
                objI.link = objI.link - quant;
                ObjectLoaderInfo newObj = ObjectLoader.newObject(objI.item_id, objI.quality, objI.owner, quant, -1);
                newObj.is_quant = 1;
                ObjectInteraction NewObjI = ObjectInteraction.CreateNewObject(CurrentTileMap(), newObj, CurrentObjectList().objInfo, GameWorldController.instance.InventoryMarker, GameWorldController.instance.InventoryMarker.transform.position);
                GameWorldController.MoveToInventory(NewObjI);
                CurrentObjectInHand = NewObjI;
                //UWHUD.instance.CursorIcon=NewObjI.GetInventoryDisplay().texture;
                ObjectInteraction.Split(objI, NewObjI);
                UWCharacter.Instance.playerInventory.Refresh();
                QuantityObj = null;


                /*	GameObject Split = Instantiate(QuantityObj);//What we are picking up.
                 *  Split.GetComponent<ObjectInteraction>().link =quant;
                 *  Split.name = Split.name+"_"+UWCharacter.Instance.summonCount++;
                 *  Split.transform.parent=UWCharacter.Instance.playerInventory.InventoryMarker.transform;//this.transform.parent;
                 *  QuantityObj.GetComponent<ObjectInteraction>().link=QuantityObj.GetComponent<ObjectInteraction>().link-quant;
                 *  CurrentObjectInHand= Split.name;
                 *  UWHUD.instance.CursorIcon= Split.GetComponent<ObjectInteraction>().GetInventoryDisplay().texture;
                 *  ObjectInteraction.Split (Split.GetComponent<ObjectInteraction>(),QuantityObj.GetComponent<ObjectInteraction>());
                 *  UWCharacter.Instance.playerInventory.Refresh (slotIndex);
                 *  QuantityObj=null;//Clear out to avoid weirdness.*/
            }
        }
    }
Example #36
0
 public virtual string ToChatString(GameWorldController gameWorldController)
 {
     return("[" + Timestamp.ToShortTimeString() + "] ");
 }
 public override void UndoEvent(GameWorldController gameWorldController)
 {
     base.UndoEvent(gameWorldController);
 }
    public override string ToChatString(GameWorldController gameWorldController)
    {
        string characterName = gameWorldController.Model.GetCharacterData(CharacterID).character_name;
        float distance = (Point3d.Distance(FromPosition, ToPosition));
        MathConstants.eDirection direction = MathConstants.GetDirectionForAngle(ToAngle);
        string facing = "";

        switch(direction)
        {
        case MathConstants.eDirection.none:
            facing = "South";
            break;
        case MathConstants.eDirection.right:
            facing = "East";
            break;
        case MathConstants.eDirection.up:
            facing = "North";
            break;
        case MathConstants.eDirection.left:
            facing = "West";
            break;
        case MathConstants.eDirection.down:
            facing = "South";
            break;
        }

        return base.ToChatString(gameWorldController) + characterName + " moved "+distance.ToString("F1")+" feet, now facing "+facing;
    }
    /*protected override void appendParameters(JsonData parameters)
     * {
     *      base.AppendParameters(parameters);
     *
     *      parameters["character_state"] = _characterState.ToObject();
     * }*/

    public override string ToChatString(GameWorldController gameWorldController)
    {
        return(base.ToChatString(gameWorldController) + _characterState.character_name + " left the game");
    }
    public override void ExecuteTrap(object_base src, int triggerX, int triggerY, int State)
    {
        Vector3 spawn = CurrentTileMap().getTileVector(ObjectTileX, ObjectTileY);

        spawn = new Vector3(spawn.x, 4.4f, spawn.z);
        int ItemStringIndex = 0;
        int Price           = 0;

        //Pick the item to sell and get its price
        switch (Quest.instance.variables[owner])
        {
        case 0:    //fish
            ItemStringIndex = 182;
            Price           = 3;
            break;

        case 1:    //meat
            ItemStringIndex = 176;
            Price           = 3;
            break;

        case 2:    //ale
            ItemStringIndex = 187;
            Price           = 4;
            break;

        case 3:    //leeches
            ItemStringIndex = 293;
            Price           = 4;
            break;

        case 4:    //water
            ItemStringIndex = 188;
            Price           = 3;
            break;

        case 5:    //dagger
            ItemStringIndex = 3;
            Price           = 11;
            break;

        case 6:    //lockpick
            ItemStringIndex = 257;
            Price           = 6;
            break;

        case 7:    //torch
            ItemStringIndex = 145;
            Price           = 4;
            break;

        default:
            return;
        }

        if (CheckPrice(Price, ObjectTileX, ObjectTileY))
        {//price check
            ObjectLoaderInfo newobjt = ObjectLoader.newWorldObject(ItemStringIndex, 40, 0, 0, 256);
            newobjt.InUseFlag = 1;
            UnFreezeMovement(GameWorldController.MoveToWorld(ObjectInteraction.CreateNewObject(CurrentTileMap(), newobjt, CurrentObjectList().objInfo, GameWorldController.instance.DynamicObjectMarker().gameObject, spawn)).gameObject);
        }
    }
Example #41
0
    public void PlayerSlotLeftClick()
    {
        if (TradeSlot.Locked)
        {
            return;
        }
        ObjectInteraction objIntAtSlot = GetGameObjectInteraction();

        if (CurrentObjectInHand != null)
        {
            //put the object in hand in this slot.
            if (objectInSlot == null)
            {            //Empty slot
                if (CurrentObjectInHand != null)
                {
                    if (CurrentObjectInHand.transform.parent != GameWorldController.instance.DynamicObjectMarker())
                    {                    //Object needs to be moved to world
                        GameWorldController.MoveToWorld(CurrentObjectInHand);
                        ConversationVM.BuildObjectList();
                    }
                    objectInSlot        = CurrentObjectInHand;
                    SlotImage.texture   = UWHUD.instance.CursorIcon;
                    CurrentObjectInHand = null;
                    Selected            = true;
                }
            }
            else
            {            //Swap the objects
                if (objIntAtSlot != null)
                {
                    objIntAtSlot.transform.parent = GameWorldController.instance.InventoryMarker.transform;
                    GameWorldController.MoveToInventory(objIntAtSlot);                    //This will call rebuild list
                }
                if (CurrentObjectInHand != null)
                {
                    if (CurrentObjectInHand.transform.parent != GameWorldController.instance.DynamicObjectMarker())
                    {                    //Object needs to be moved to world
                        GameWorldController.MoveToWorld(CurrentObjectInHand);
                    }
                }
                objectInSlot        = CurrentObjectInHand;
                SlotImage.texture   = CurrentObjectInHand.GetInventoryDisplay().texture;
                CurrentObjectInHand = objIntAtSlot;
                ConversationVM.BuildObjectList();
                Selected = true;
            }
        }
        else
        {
            if (objectInSlot != null)
            {
                //Pickup the object in the slot
                CurrentObjectInHand = objIntAtSlot;
                objectInSlot        = null;
                SlotImage.texture   = Blank;
                Selected            = false;
                if (CurrentObjectInHand != null)
                {
                    CurrentObjectInHand.transform.parent = GameWorldController.instance.InventoryMarker.transform;
                    GameWorldController.MoveToInventory(CurrentObjectInHand);                    //This will call rebuild list
                    CurrentObjectInHand.GetComponent <object_base>().PickupEvent();
                }
            }
        }
        if (objectInSlot == null)
        {
            Quantity.text = "";
        }
        else
        {
            int qty = GetGameObjectInteraction().GetQty();
            if (qty <= 1)
            {
                Quantity.text = "";
            }
            else
            {
                Quantity.text = qty.ToString();
            }
        }
    }
Example #42
0
    public override string ToChatString(GameWorldController gameWorldController)
    {
        MobType mobType = MobTypeManager.GetMobTypeByName(m_mobState.mob_type_name);

        return(base.ToChatString(gameWorldController) + mobType.Name + " spawned");
    }
Example #43
0
 public bool AdvanceCurrentEvent(GameWorldController gameWorldController)
 {
     // null complete callback tells the event to immediately jump to the result
     return CurrentGame.AdvanceEventCursor(gameWorldController, null);
 }
    /// <summary>
    /// Launchs the ammo.
    /// </summary>
    /// <returns><c>true</c>, if ammo was launched, <c>false</c> otherwise.</returns>
    bool LaunchAmmo(float charge)
    {
        if (currentAmmo != null)
        {
            Ray ray;
            if (UWCharacter.Instance.MouseLookEnabled == true)
            {
                ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
            }
            else
            {
                ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            }

            RaycastHit hit       = new RaycastHit();
            float      dropRange = 0.5f;
            if (!Physics.Raycast(ray, out hit, dropRange))
            {            ///Checks No object interferes with the launch
                float      force = 1000.0f * (charge / 100.0f);
                GameObject launchedItem;
                if (currentAmmo.GetQty() == 1)
                {
                    launchedItem = currentAmmo.gameObject;
                    UWCharacter.Instance.playerInventory.RemoveItem(currentAmmo.name);
                    launchedItem.transform.parent = GameWorldController.instance.LevelMarker();
                    GameWorldController.MoveToWorld(launchedItem);
                    launchedItem.transform.position = ray.GetPoint(dropRange - 0.1f);
                    launchedItem.GetComponent <ObjectInteraction>().PickedUp = false;                   //Back in the real world
                }
                else
                {                //reduce this quantity by one and create a copy in the world
                    ObjectLoaderInfo newobjt = ObjectLoader.newObject(currWeaponRanged.AmmoType(), 40, 0, 1, 256);
                    launchedItem = ObjectInteraction.CreateNewObject(GameWorldController.instance.currentTileMap(), newobjt, GameWorldController.instance.LevelMarker().gameObject, ray.GetPoint(dropRange - 0.1f)).gameObject;
                    currentAmmo.consumeObject();
                }
                launchedItem.GetComponent <ObjectInteraction>().isquant = 1;
                GameWorldController.UnFreezeMovement(launchedItem);
                Vector3 ThrowDir = ray.GetPoint(dropRange) - ray.origin;

                ///Apply the force along the direction of the ray that the player has targetted along.
                launchedItem.GetComponent <Rigidbody>().AddForce(ThrowDir * force);
                GameObject myObjChild = new GameObject(launchedItem.name + "_damage");
                myObjChild.transform.position = launchedItem.transform.position;
                myObjChild.transform.parent   = launchedItem.transform;
                ///Appends ProjectileDamage to the projectile to act as the damage delivery method.
                ProjectileDamage pd = myObjChild.AddComponent <ProjectileDamage>();
                pd.Source       = UWCharacter.Instance.gameObject;
                pd.Damage       = (short)currWeaponRanged.Damage();          //   (short)(10.0f*(Charge/100.0f));
                pd.AttackCharge = charge;
                pd.AttackScore  = UWCharacter.Instance.PlayerSkills.GetSkill(Skills.SkillAttack) / 2 + UWCharacter.Instance.PlayerSkills.GetSkill(Skills.SkillMissile);
                return(true);
            }
            else
            {
                return(false);
            }
        }
        else
        {        //No ammo?? Should not happen
            return(false);
        }
    }
Example #45
0
 public bool ReverseCurrentEvent(GameWorldController gameWorldController)
 {
     return CurrentGame.ReverseEventCursor(gameWorldController);
 }
Example #46
0
 override public void UndoEvent(GameWorldController gameWorldController)
 {
     base.UndoEvent(gameWorldController);
 }
Example #47
0
 public virtual void ApplyEvent(GameWorldController gameWorldController, OnEventCompleteDelegate onComplete)
 {
     // Nothing to do in the base class
 }
Example #48
0
    public void RemoveFromGameWorld(GameWorldController gameWorldController)
    {
        gameWorldController.Model.RemoveMobEntity(this);
        gameWorldController.View.RemoveMobWidget(m_mobWidget);

        m_mobWidget = null;
        m_pathfindingComponent = null;
        m_steeringComponent = null;
    }
 public override void UndoEvent(GameWorldController gameWorldController)
 {
     // Nothing to do
     base.UndoEvent(gameWorldController);
 }
Example #50
0
    public override void ExecuteTrap(object_base src, int triggerX, int triggerY, int State)
    {
        //Debug.Log (this.name);
        GameObject door = GameWorldController.findDoor(triggerX, triggerY);

        if (door != null)
        {
            DoorControl DC = door.GetComponent <DoorControl>();

            switch (objInt().quality)
            {
            case 0:            //Just lock
                //Copy the lock object at the link to use on this door
                if (objInt().link != 0)
                {                //link to a lock
                    if (ObjectLoader.GetItemTypeAt(objInt().link) == ObjectInteraction.LOCK)
                    {
                        ObjectInteraction lockToCopy = ObjectLoader.getObjectIntAt(objInt().link);
                        ObjectLoaderInfo  newobjt    = ObjectLoader.newObject(lockToCopy.item_id, lockToCopy.quality, lockToCopy.owner, lockToCopy.link, 256);
                        newobjt.flags       = lockToCopy.flags;
                        newobjt.doordir     = lockToCopy.doordir;
                        newobjt.invis       = lockToCopy.invis;
                        newobjt.enchantment = lockToCopy.enchantment;
                        newobjt.zpos        = lockToCopy.zpos;
                        newobjt.x           = lockToCopy.x;
                        newobjt.y           = lockToCopy.y;
                        newobjt.next        = DC.objInt().link;               //To allow proper triggering of traps
                        newobjt.InUseFlag   = 1;
                        GameObject Created = ObjectInteraction.CreateNewObject(GameWorldController.instance.currentTileMap(), newobjt, GameWorldController.instance.CurrentObjectList().objInfo, GameWorldController.instance.InventoryMarker.gameObject, GameWorldController.instance.InventoryMarker.transform.position).gameObject;
                        DC.objInt().link   = newobjt.index;                     //Point the lock at this new lock
                    }
                }
                else
                {                //unlink the lock and tie the locks next back to the door as it's link
                    ObjectInteraction linkedObj = ObjectLoader.getObjectIntAt(DC.objInt().link);
                    if (linkedObj != null)
                    {
                        DC.objInt().link = linkedObj.next;
                        linkedObj.objectloaderinfo.InUseFlag = 0;
                        Destroy(linkedObj);
                    }
                }


                break;

            case 1:            //try open
                if (TriggerInstantly)
                {
                    DC.UnlockDoor(false);
                    DC.OpenDoor(0f);
                }
                else
                {
                    DC.UnlockDoor(false);
                    DC.OpenDoor(DoorControl.DefaultDoorTravelTime);
                }

                break;

            case 2:            //try close
                if (TriggerInstantly)
                {
                    DC.CloseDoor(0f);
                    DC.LockDoor();
                }
                else
                {
                    DC.CloseDoor(DoorControl.DefaultDoorTravelTime);
                    DC.LockDoor();
                }

                break;

            case 3:            //try toggle
                //TODO:check if toggle respects unlocked status. (door trap 1001 on level 3)
                if (TriggerInstantly)
                {
                    DC.ToggleDoor(0, false);
                }
                else
                {
                    DC.ToggleDoor(DoorControl.DefaultDoorTravelTime, false);
                }
                break;
            }
        }
        else
        {
            Debug.Log("Door not found!");
        }
    }