예제 #1
0
    public void printCurrentRoomEntryText(float seconds)
    {
        string roomText = currentRoom.runtimeRoomEntryText;

        if (System.String.IsNullOrEmpty(roomText))
        {
            StartCoroutine(textPrompt.printTextAfterDelay("(You forgot to add Room Entry Text for this room)", seconds));
        }
        else
        {
            StartCoroutine(textPrompt.printTextAfterDelay(roomText, seconds));
        }
    }
예제 #2
0
    /// <summary>
    /// Execute one action.
    /// </summary>
    /// <param name="obj">The parent object</param>
    /// <param name="action">The action to execute</param>
    public void executeOneAction(Object obj, RoomObject.EditorVariables action)
    {
        // executeActions happens twice. Once to execute the actions normally, and once to execute delayed actions.
        // This method happens the first time, to add the actions marked as delayed to delayedActions.
        if (checkDelayed)
        {
            if (action.isDelayed)
            {
                delayedActions.Add(action);
                return;
            }
        }

        RoomObject.ActionCategory category = action.actionCategory;

        // Execute player actions
        if (category == RoomObject.ActionCategory.PlayerActions)
        {
            RoomObject.PlayerAction playerAction = action.playerAction;

            RoomObject targetObject = action.varsToChange.targetObject;

            switch (playerAction)
            {
            case RoomObject.PlayerAction.KillPlayer:
                textPrompt.killPlayer();
                // The delay for printText is so the flavor text is printed first before death/win text.
                StartCoroutine(textPrompt.printTextAfterDelay(defaultValues.deathText, 0.1f));
                break;

            case RoomObject.PlayerAction.WinGame:
                textPrompt.winGame();
                // The delay for printText is so the flavor text is printed first before death/win text.
                StartCoroutine(textPrompt.printTextAfterDelay(defaultValues.winText, 0.1f));
                break;

            case RoomObject.PlayerAction.AddToInventory:
                player.addItemToInventory(targetObject);
                break;

            case RoomObject.PlayerAction.RemoveFromInventory:
                player.removeItemFromInventory(targetObject);
                break;

            case RoomObject.PlayerAction.EquipItem:
                player.equipItem(targetObject);
                break;

            case RoomObject.PlayerAction.RemoveEquippedItem:
                player.removeEquippedItem(targetObject);
                break;

            default:
                Debug.Log($"Unknown PlayerAction enum at {obj.name}: you forgot to add what to do in ActionHandler!");
                break;
            }
        }
        else if (category == RoomObject.ActionCategory.ObjectActions)
        {
            RoomObject.ObjectAction objectAction = action.objectAction;

            RoomObject targetObject = action.varsToChange.targetObject;

            if (targetObject == null)
            {
                Debug.Log($"{obj.name}: There's an object that wasn't set in an action");
                return;
            }

            // Execute object actions
            switch (objectAction)
            {
            case RoomObject.ObjectAction.DestroyObject:
                player.removeItemFromInventory(targetObject);
                player.removeEquippedItem(targetObject);
                roomTracker.getCurrentRoom().removeRoomObject(targetObject);
                break;

            case RoomObject.ObjectAction.SetIsEdible:
                targetObject.runtimeIsEdible = action.varsToChange.isEdible;
                break;

            case RoomObject.ObjectAction.SetIsDrinkable:
                targetObject.runtimeIsDrinkable = action.varsToChange.isDrinkable;
                break;

            case RoomObject.ObjectAction.SetIsTalkable:
                targetObject.runtimeIsTalkable = action.varsToChange.isTalkable;
                break;

            case RoomObject.ObjectAction.SetIsKillable:
                targetObject.runtimeIsKillable = action.varsToChange.isKillable;
                break;

            case RoomObject.ObjectAction.SetIsBreakable:
                targetObject.runtimeIsBreakable = action.varsToChange.isBreakable;
                break;

            case RoomObject.ObjectAction.SetIsSittable:
                targetObject.runtimeIsSittable = action.varsToChange.isSittable;
                break;

            case RoomObject.ObjectAction.SetIsUsable:
                targetObject.runtimeIsUsable = action.varsToChange.isUsable;
                break;

            case RoomObject.ObjectAction.SetIsPickupable:
                targetObject.runtimeIsPickupable = action.varsToChange.isPickupable;
                break;

            case RoomObject.ObjectAction.SetIsWearable:
                targetObject.runtimeIsWearable = action.varsToChange.isWearable;
                break;

            case RoomObject.ObjectAction.SetIsOpenable:
                targetObject.runtimeIsOpenable = action.varsToChange.isOpenable;
                break;


            case RoomObject.ObjectAction.ChangeEdibleFlavorText:
                targetObject.runtimeEdibleFlavorText = action.varsToChange.edibleFlavorText;
                break;

            case RoomObject.ObjectAction.ChangeDrinkableFlavorText:
                targetObject.runtimeDrinkableFlavorText = action.varsToChange.drinkableFlavorText;
                break;

            case RoomObject.ObjectAction.ChangeKillableFlavorText:
                targetObject.runtimeKillableFlavorText = action.varsToChange.killableFlavorText;
                break;

            case RoomObject.ObjectAction.ChangeBreakableFlavorText:
                targetObject.runtimeBreakableFlavorText = action.varsToChange.breakableFlavorText;
                break;

            case RoomObject.ObjectAction.ChangePickupableFlavorText:
                targetObject.runtimePickupableFlavorText = action.varsToChange.pickupableFlavorText;
                break;

            case RoomObject.ObjectAction.ChangeSittableFlavorText:
                targetObject.runtimeSittableFlavorText = action.varsToChange.sittableFlavorText;
                break;

            case RoomObject.ObjectAction.ChangeTalkableFlavorText:
                targetObject.runtimeTalkableFlavorText = action.varsToChange.talkableFlavorText;
                break;

            case RoomObject.ObjectAction.ChangeUsableFlavorText:
                targetObject.runtimeUsableFlavorText = action.varsToChange.usableFlavorText;
                break;

            case RoomObject.ObjectAction.ChangeWearableFlavorText:
                targetObject.runtimeWearableFlavorText = action.varsToChange.wearableFlavorText;
                break;

            case RoomObject.ObjectAction.ChangeOpenableFlavorText:
                targetObject.runtimeOpenableFlavorText = action.varsToChange.openableFlavorText;
                break;

            case RoomObject.ObjectAction.ChangeLookAtFlavorText:
                targetObject.runtimeLookAtFlavorText = action.varsToChange.lookAtFlavorText;
                break;

            default:
                Debug.Log($"Unknown ObjectAction enum at {obj.name}: you forgot to add what to do in ActionHandler!");
                break;
            }
        }
        else if (category == RoomObject.ActionCategory.RoomActions)
        {
            RoomObject.RoomAction roomAction = action.roomAction;
            Room targetRoom = action.varsToChange.targetRoom;

            switch (roomAction)
            {
            case RoomObject.RoomAction.AddObjectToRoom:
                if (action.varsToChange.targetObject.isInitialized == false)
                {
                    action.varsToChange.targetObject.initializeRuntimeVariables();
                }
                roomTracker.getCurrentRoom().addRoomObject(action.varsToChange.targetObject);
                break;

            case RoomObject.RoomAction.RemoveObjectFromRoom:
                roomTracker.getCurrentRoom().removeRoomObject(action.varsToChange.targetObject);
                break;

            case RoomObject.RoomAction.SwitchRooms:
                roomTracker.forceChangeRoom(action.varsToChange.targetRoom);
                break;

            case RoomObject.RoomAction.ChangeRoomEntryText:
                targetRoom.runtimeRoomEntryText = action.varsToChange.roomEntryText;
                break;

            case RoomObject.RoomAction.ChangeRoomLookText:
                targetRoom.runtimeLookText = action.varsToChange.roomLookText;
                break;

            case RoomObject.RoomAction.ActivateRoomConnection:
                setActiveRoomConnection(action.varsToChange.targetRoom, action.varsToChange.targetRoomConnection, true);
                break;

            case RoomObject.RoomAction.DisableRoomConnection:
                setActiveRoomConnection(action.varsToChange.targetRoom, action.varsToChange.targetRoomConnection, false);
                break;

            default:
                Debug.Log($"Unknown RoomAction enum at {obj.name}: you forgot to add what to do in ActionHandler!");
                break;
            }
        }
    }