Пример #1
0
    public IEnumerator TakesTest2()
    {
        SceneManager.LoadScene("Game");
        yield return(null);

        GameObject.Find("Game Manager").SendMessage("AddGameTask", "player create 2 'Gold'");
        GameObject.Find("Game Manager").SendMessage("AddGameTask", "player puts 2 'Gold' 'Inn Floor 1 Room 1' 'Bar Front'");
        GameObject.Find("Game Manager").SendMessage("AddGameTask", "hamen create 2 'Silver'");
        GameObject.Find("Game Manager").SendMessage("AddGameTask", "hamen puts 2 'Silver' 'Inn Floor 1 Room 1' 'Bar Front'");
        yield return(new WaitForSeconds(10.0f));

        GameObject.Find("Game Manager").SendMessage("AddGameTask", "player takes 1 'Gold' 'Inn Floor 1 Room 1' 'Bar Front'");
        GameObject.Find("Game Manager").SendMessage("AddGameTask", "player takes 1 'Silver' 'Inn Floor 1 Room 1' 'Bar Front'");
        GameObject.Find("Game Manager").SendMessage("AddGameTask", "hamen takes 1 'Silver' 'Inn Floor 1 Room 1' 'Bar Front'");
        GameObject.Find("Game Manager").SendMessage("AddGameTask", "hamen takes 1 'Gold' 'Inn Floor 1 Room 1' 'Bar Front'");
        yield return(new WaitForSeconds(10.0f));

        GameObject.Find("Game Manager").SendMessage("AddGameTask", "player puts 1 'Gold' 'Inn Floor 1 Room 1' 'Bar Front'");
        GameObject.Find("Game Manager").SendMessage("AddGameTask", "player puts 1 'Silver' 'Inn Floor 1 Room 1' 'Bar Front'");
        GameObject.Find("Game Manager").SendMessage("AddGameTask", "hamen puts 1 'Silver' 'Inn Floor 1 Room 1' 'Bar Front'");
        GameObject.Find("Game Manager").SendMessage("AddGameTask", "hamen puts 1 'Gold' 'Inn Floor 1 Room 1' 'Bar Front'");
        yield return(new WaitForSeconds(10.0f));

        GameObject.Find("Game Manager").SendMessage("AddGameTask", "player takes 2 'Gold' 'Inn Floor 1 Room 1' 'Bar Front'");
        GameObject.Find("Game Manager").SendMessage("AddGameTask", "hamen takes 2 'Silver' 'Inn Floor 1 Room 1' 'Bar Front'");
        yield return(new WaitForSeconds(10.0f));

        GameObject   barFront = GameObject.Find("Bar Front");
        PixelStorage storage  = barFront.GetComponent <PixelStorage>();

        Assert.False(storage.HasObject("Gold", 1));
        Assert.False(storage.HasObject("Silver", 1));
    }
Пример #2
0
    public IEnumerator TakesTest1()
    {
        yield return(PutTest1());

        GameObject.Find("Game Manager").SendMessage("AddGameTask", "player takes 4 'Gold' 'Inn Floor 1 Room 1' 'Bar Front'");
        yield return(new WaitForSeconds(10.0f));

        GameObject   barFront = GameObject.Find("Bar Front");
        PixelStorage storage  = barFront.GetComponent <PixelStorage>();

        Assert.False(storage.HasObject("Gold", 4));
    }
Пример #3
0
    public IEnumerator PutTest2()
    {
        SceneManager.LoadScene("Game");
        yield return(null);

        GameObject.Find("Game Manager").SendMessage("AddGameTask", "hamen create 4 'Silver'");
        yield return(new WaitForSeconds(1.0f));

        GameObject.Find("Game Manager").SendMessage("AddGameTask", "hamen puts 4 'Silver' 'Inn Floor 1 Room 1' 'Bar Front'");
        yield return(new WaitForSeconds(10.0f));

        GameObject   barFront = GameObject.Find("Bar Front");
        PixelStorage storage  = barFront.GetComponent <PixelStorage>();

        Assert.True(storage.HasObject("Silver", 4));
    }
Пример #4
0
        public void Puts(int number, string item, PixelStorage pixelStorage)
        {
            CharacterInventory inv = GetComponentInChildren <CharacterInventory>();

            Debug.Assert(inv != null);

            bool hasItem = inv.HasItem(item, number);

            if (!hasItem)
            {
                Debug.LogWarning(this.gameObject.name + " does not have " + number + " " + item);
                return;
            }

            Debug.Assert(number >= 1 && number <= 24);
            for (int i = 0; i < number; ++i)
            {
                GameObject obj = inv.GetItem(item);
                pixelStorage.AddObject(obj);
            }

            animator.SetTrigger(Animator.StringToHash("IsInteract"));
        }
Пример #5
0
        public void Takes(int number, string item, PixelStorage pixelStorage)
        {
            CharacterInventory inv = GetComponentInChildren <CharacterInventory>();

            Debug.Assert(inv != null);

            bool hasItem = pixelStorage.HasObject(item, number);

            if (!hasItem)
            {
                Debug.LogWarning(pixelStorage.name + " does not have " + number + " " + item);
                return;
            }

            Debug.Assert(number >= 1 && number <= 24);
            for (int i = 0; i < number; ++i)
            {
                GameObject obj = pixelStorage.TakeObject(item);
                if (obj == null)
                {
                    break;
                }
                PixelItem pixelItem = obj.GetComponent <PixelItem>();
                Debug.Assert(pixelItem != null);

                bool succeed = inv.AddItem(pixelItem);

                if (succeed)
                {
                    //animator.SetTrigger(Animator.StringToHash("IsPickup"));
                    pixelItem.gameObject.SetActive(false);
                    pixelItem.transform.parent = inv.transform;
                }
            }

            animator.SetTrigger(Animator.StringToHash("IsInteract"));
        }
Пример #6
0
    public static List <GameTask> CreateGameTasks(string actionString)
    {
        List <GameTask> gameTasks     = new List <GameTask>();
        List <string>   actionStrings = BreakUpString(actionString);

        Character taskCharacter;
        TaskType  type = IdentifyTaskType(actionStrings, out taskCharacter);

        if (type == TaskType.NAVIGATE)
        {
            GameTask gameTask = new GameTask();
            gameTask.taskType = TaskType.NAVIGATE;
            Debug.Assert(taskCharacter != null);

            if (actionStrings.Count == 3)
            {
                PixelCollider pc       = taskCharacter.GetComponentInChildren <PixelCollider>();
                string        roomName = pc.GetPixelRoom().name;
                actionStrings.Insert(2, roomName);
            }

            string    locationString = actionStrings[2];
            PixelRoom room           = GetObjectOfType <PixelRoom>(locationString);
            gameTask.arguments.Add(room);

            string        objectString  = actionStrings[3];
            PixelCollider pixelCollider = GetObjectOfType <PixelCollider>(objectString, room.transform);
            gameTask.arguments.Add(pixelCollider);
            gameTask.character = taskCharacter;

            Direction direction = Direction.All;
            if (actionStrings.Count > 4)
            {
                string directionString = actionStrings[4];
                if (directionString == "NE")
                {
                    direction = Direction.NE;
                }
                if (directionString == "SE")
                {
                    direction = Direction.SE;
                }
                if (directionString == "SW")
                {
                    direction = Direction.SW;
                }
                if (directionString == "NW")
                {
                    direction = Direction.NW;
                }
            }

            GameTask faceTask = new GameTask();
            faceTask.taskType = TaskType.FACEDIRECTION;
            faceTask.duration = 0.1f;
            faceTask.arguments.Add(direction);
            faceTask.character = taskCharacter;

            gameTasks.Add(gameTask);
            gameTasks.Add(faceTask);
        }
        else if (type == TaskType.CREATE)
        {
            GameTask createItemTask = new GameTask();
            createItemTask.taskType = TaskType.CREATE;
            createItemTask.duration = 0.0f;

            GameObject itemObj = null;

            int  number    = 1;
            bool hasNumber = int.TryParse(actionStrings[2], out number);
            if (!hasNumber)
            {
                number = 1;
                actionStrings.Insert(2, number.ToString());
            }

            Debug.Assert(number >= 1 && number <= 4);
            itemObj = Resources.Load("Items/" + actionStrings[3]) as GameObject;
            if (itemObj == null)
            {
                Debug.LogWarning(actionStrings[3] + " is not an item");
            }

            Debug.Assert(itemObj != null);
            createItemTask.arguments.Add(number);
            createItemTask.arguments.Add(itemObj);
            createItemTask.character = taskCharacter;

            gameTasks.Add(createItemTask);
        }
        else if (type == TaskType.PUTS || type == TaskType.TAKES)
        {
            // Navigate first
            int  number    = 1;
            bool hasNumber = int.TryParse(actionStrings[2], out number);

            if (!hasNumber)
            {
                number = 1;
                actionStrings.Insert(2, "1");
            }

            if (actionStrings.Count == 5)
            {
                PixelCollider pc       = taskCharacter.GetComponentInChildren <PixelCollider>();
                string        roomName = pc.GetPixelRoom().name;
                actionStrings.Insert(4, roomName);
            }

            PixelInventory inv = taskCharacter.GetComponentInChildren <PixelInventory>();
            Debug.Assert(inv != null);

            string    locationString = actionStrings[4];
            PixelRoom room           = GetObjectOfType <PixelRoom>(locationString);

            string        objectString  = actionStrings[5];
            PixelCollider pixelCollider = GetObjectOfType <PixelCollider>(objectString, room.transform);

            PixelStorage storage = pixelCollider.transform.parent.GetComponent <PixelStorage>();
            if (storage == null)
            {
                Debug.LogWarning("Cannot Place Item in " + actionStrings[5]);
                return(gameTasks);
            }

            // Navigate First
            GameTask navigateTask = new GameTask();
            navigateTask.taskType  = TaskType.NAVIGATE;
            navigateTask.character = taskCharacter;
            navigateTask.arguments.Add(room);
            navigateTask.arguments.Add(pixelCollider);
            gameTasks.Add(navigateTask);

            // Then Put
            GameTask putsItemTask = new GameTask();
            putsItemTask.taskType = type;
            putsItemTask.arguments.Add(number);
            putsItemTask.arguments.Add(actionStrings[3]);
            putsItemTask.arguments.Add(storage);
            putsItemTask.character = taskCharacter;
            gameTasks.Add(putsItemTask);
        }
        else if (type == TaskType.GIVES || type == TaskType.STEALS)         // player gives hamen key
        {
            string    characterName = actionStrings[2];
            Character toCharacter   = GetCharacter(characterName);
            if (toCharacter == null)
            {
                Debug.LogWarning("Character: " + toCharacter.name + " does not exist");
            }

            PixelInventory fromInventory = taskCharacter.GetComponentInChildren <PixelInventory>();
            PixelInventory toInventory   = toCharacter.GetComponentInChildren <PixelInventory>();
            Debug.Assert(fromInventory != null && toInventory != null);

            PixelCollider toCharacterCollider = toCharacter.GetComponentInChildren <PixelCollider>();
            PixelRoom     room = toCharacterCollider.GetPixelRoom();
            Debug.Assert(toCharacterCollider != null && room != null);

            int  count     = 1;
            bool hasNumber = int.TryParse(actionStrings[3], out count);
            if (!hasNumber)
            {
                count = 1;
                actionStrings.Insert(3, "1");
            }

            string itemName = actionStrings[4];

            // Navigate to the player
            GameTask navigateTask = new GameTask();
            navigateTask.taskType  = TaskType.NAVIGATE;
            navigateTask.character = taskCharacter;
            navigateTask.arguments.Add(room);
            navigateTask.arguments.Add(toCharacterCollider);
            gameTasks.Add(navigateTask);

            // Then Gives
            GameTask givesItemTask = new GameTask();
            givesItemTask.taskType = type;
            givesItemTask.arguments.Add(count);
            givesItemTask.arguments.Add(itemName);
            givesItemTask.arguments.Add(toCharacter);
            givesItemTask.character = taskCharacter;
            gameTasks.Add(givesItemTask);
        }
        else if (type == TaskType.MOUNT)         // player gives hamen key
        {
            // TODO 1. create a gametask for mounting an object. Must pass in the correct arguments in the gametask that
            // gets passed into the character task
        }
        return(gameTasks);
    }
Пример #7
0
 public EmbeddedImage(Image image, PixelStorage pixelStorage)
 {
     _image        = image;
     _pixelStorage = pixelStorage;
 }