IEnumerator play(PlayableModel playable)
 {
     while (commandQueues[playable].Any())
     {
         yield return(StartCoroutine(playOneStep(playable)));
     }
 }
        IEnumerator playOneStep(PlayableModel playable)
        {
            var command = getCommandFromLogFile(playable, "reverted.json", "executed.json");

            if (command)
            {
                yield return(new WaitForSeconds(commandSystems[command.Major].Execute(command)));

                yield break;
            }

            while (commandQueues[playable].Any() && commandQueues[playable][0] is CommandGroupModel)
            {
                processCommand(playable);
            }

            if (!commandQueues[playable].Any())
            {
                yield break;
            }

            yield return(new WaitForSeconds(processCommand(playable) + 0.3f));

            roundTransformValueToInt(playable);
        }
        float processCommand(PlayableModel playable)
        {
            var command = commandQueues[playable][0];

            commandQueues[playable].RemoveAt(0);

            PuzzlePlayLogSystem.Instance.FileName = "executed.json";
            PuzzlePlayLogSystem.Instance.Log(command);

            if (command is SingleCommandModel)
            {
                if (commandSystems[command.Major].IsExecutable(command))
                {
                    //Debug.Log(command.Major + " command was executed!");
                    return(commandSystems[command.Major].Execute(command));
                }

                //Debug.Log(command.Major + "command is not executable!");
                return(0.0f);
            }

            var commands = commandGroupSystems[command.Major].GetCommands(command);

            if (commands == null)// {
            // Debug.Log(command.Major + " group's commands sequence is empty!");
            {
                return(0.0f);
            }
            //}

            commandQueues[playable].InsertRange(0, commands);
            // Debug.Log(command.Major + " group's commands sequence is inserted!");

            return(0.0f);
        }
Exemple #4
0
        public float ActionReverse(PlayableModel character, PuzzleEntityModel polluted_tile)
        {
            if (!polluted_tile)
            {
                return(0.0f);
            }

            var cleanable = polluted_tile.GetComponent <CleanableModel>();

            if (cleanable.IsClean)
            {
                return(0.0f);
            }

            for (int i = 0; i < character.transform.childCount; ++i)
            {
                character.transform.GetChild(i).GetComponent <Animator>().speed = -1;
                character.transform.GetChild(i).GetComponent <Animator>().CrossFade("spell", 0.0f, -1, 0);
            }

            cleanable.IsClean = true;

            CoroutineUtility.Instance.DelayAction(1.5f, () => {
                cleanable.Plague.SetActive(false);
            });

            return(character.transform.GetChild(0).GetComponent <Animator>().GetCurrentAnimatorClipInfo(0).Length);
        }
        public void PlayBackOneStep(PlayableModel playable = null)
        {
            if (playable)
            {
                coroutines[playable] = StartCoroutine(playBackOneStep(playable));
                return;
            }

            StartCoroutine(playBackOneStep());
        }
Exemple #6
0
        public float Action(PlayableModel playable, PuzzleEntityModel entity_1)
        {
            PlaySystem.Instance.Pause();

            // 카메라 회전.
            // 로봇 클리어 애니메이션 재생.

            SceneManager.LoadScene("MissionClearScene");

            return(0.0f);
        }
        private void roundTransformValueToInt(PlayableModel playable)
        {
            var position = playable.transform.position;
            var rotation = playable.transform.eulerAngles;

            playable.transform.position = new Vector3(Mathf.RoundToInt(position.x),
                                                      Mathf.RoundToInt(position.y),
                                                      Mathf.RoundToInt(position.z));
            playable.transform.rotation = Quaternion.Euler(Mathf.RoundToInt(rotation.x),
                                                           Mathf.RoundToInt(rotation.y),
                                                           Mathf.RoundToInt(rotation.z));
        }
Exemple #8
0
        public float ActionReverse(PlayableModel entity, PuzzleEntityModel behind_up_tile)
        {
            entity.GetComponent <Animator>().SetFloat("Speed", -1);
            entity.GetComponent <Animator>().Play("jump_down", -1, 1);
            for (int i = 0; i < entity.transform.childCount; ++i)
            {
                entity.transform.GetChild(i).GetComponent <Animator>().SetFloat("Speed", 1);
                entity.transform.GetChild(i).GetComponent <Animator>().CrossFade("jump_down", 0.1f, -1, 1);
            }

            return(2.0f);
        }
Exemple #9
0
        public float ActionReverse(PlayableModel entity, PuzzleEntityModel behind_tile)
        {
            entity.GetComponent <Animator>().SetFloat("Speed", -1);
            entity.GetComponent <Animator>().Play("walk", -1, 1);
            for (int i = 0; i < entity.transform.childCount; ++i)
            {
                entity.transform.GetChild(i).GetComponent <Animator>().SetFloat("Speed", -1);
                entity.transform.GetChild(i).GetComponent <Animator>().CrossFade("walk", 0.1f, -1, 1);
            }

            return(entity.transform.GetChild(0).GetComponent <Animator>().GetCurrentAnimatorClipInfo(0).Length);
        }
Exemple #10
0
        public PuzzleEntityModel FindNeighbourTile(PlayableModel playable, Direction direction)
        {
            var transform = playable.transform;
            var position  = transform.position + new Vector3(0, -1, 0);

            switch (direction)
            {
            case Direction.Current:
                return(getTile(position));

            case Direction.FrontUp:
                return(getTile(position + transform.forward + transform.up));

            case Direction.Front:
            {
                var front_up = getTile(position + transform.forward + transform.up);
                if (transform.position.x == 1 && front_up)
                {
                    Debug.Log(position + transform.forward + transform.up);
                }
                return(front_up == null?getTile(position + transform.forward) : null);
            }

            case Direction.FrontDown:
            {
                var forward  = getTile(position + transform.forward);
                var front_up = getTile(position + transform.forward + transform.up);

                return((forward == null && front_up == null) ? getTile(position + transform.forward - transform.up) : null);
            }

            case Direction.BehindUp:
                return(getTile(position - transform.forward + transform.up));

            case Direction.Behind:
            {
                var behind_up = getTile(position - transform.forward + transform.up);
                return(behind_up == null?getTile(position - transform.forward) : null);
            }

            case Direction.BehindDown:
            {
                var behind    = getTile(position - transform.forward);
                var behind_up = getTile(position - transform.forward + transform.up);

                return((behind == null && behind_up == null) ? getTile(position - transform.forward - transform.up) : null);
            }

            default:
                return(null);
            }
        }
        public void PlayOneStep(PlayableModel playable = null)
        {
            if (playable)
            {
                coroutines[playable] = StartCoroutine(playOneStep(playable));
                return;
            }

            foreach (var key in commandQueues.Keys)
            {
                coroutines[key] = StartCoroutine(playOneStep(key));
            }
        }
Exemple #12
0
        public float Action(PlayableModel entity, PuzzleEntityModel dummy)
        {
            entity.GetComponent <Animator>().SetFloat("Speed", 1);
            entity.GetComponent <Animator>().Play("turn_right", -1, 0);

            for (int i = 0; i < entity.transform.childCount; ++i)
            {
                entity.transform.GetChild(i).GetComponent <Animator>().SetFloat("Speed", 1);
                entity.transform.GetChild(i).GetComponent <Animator>().CrossFade("turn_right", 0.3f, -1, 0);
            }

            return(entity.transform.GetChild(0).GetComponent <Animator>().GetCurrentAnimatorClipInfo(0).Length);
        }
        IEnumerator playBackOneStep(PlayableModel playable)
        {
            var command = getCommandFromLogFile(playable, "executed.json", "reverted.json");

            if (!command)
            {
                yield break;
            }

            var major = command.Major;

            yield return(new WaitForSeconds(commandSystems[major].Revert(command)));

            roundTransformValueToInt(playable);
        }
        private CommandModel getCommandFromLogFile(PlayableModel playable, string file_name_to_parse, string file_name_to_save)
        {
            var stream = new FileStream(Application.dataPath + "/Resources/" + file_name_to_parse, FileMode.OpenOrCreate, FileAccess.Read);
            var reader = new StreamReader(stream, System.Text.Encoding.Unicode);
            var json   = JSON.Parse(reader.ReadToEnd());

            reader.Close();
            stream.Close();

            if (json == null)
            {
                return(null);
            }

            var command_ids = json["commands"].AsArray;
            var result      = from command in GameObject.FindObjectsOfType <SingleCommandModel>()
                              where command.Playable.GetComponent <PuzzleEntityModel>().ID == playable.GetComponent <PuzzleEntityModel>().ID
                              select command;

            var single_commands = result.ToDictionary(x => x.GetComponent <SingleCommandModel>().ID);
            int count           = command_ids.Count - 1;

            while (count > -1 && !single_commands.ContainsKey(command_ids[count].AsInt))
            {
                count--;
            }

            if (count == -1)
            {
                return(null);
            }

            var return_value = single_commands[command_ids[count].AsInt];

            command_ids.Remove(command_ids[count]);

            PuzzlePlayLogSystem.Instance.FileName = file_name_to_parse;
            PuzzlePlayLogSystem.Instance.Log(json.ToString(4));

            PuzzlePlayLogSystem.Instance.FileName = file_name_to_save;
            PuzzlePlayLogSystem.Instance.Log(return_value);

            return(return_value);
        }
Exemple #15
0
        public float Action(PlayableModel attacker, PuzzleEntityModel front_tile)
        {
            if (!front_tile)
            {
                return(0.0f);
            }

            var target = front_tile.GetComponent <TileModel>().PuzzleEntity;

            var actionable = attacker.GetComponent <ActionableModel>();
            var damageable = target.GetComponent <DamageableModel>();

            if (!actionable || !damageable)
            {
                return(0.0f);
            }

            front_tile.GetComponent <TileModel>().PuzzleEntity = null;

            for (int i = 0; i < attacker.transform.childCount; ++i)
            {
                attacker.transform.GetChild(i).GetComponent <Animator>().CrossFade("attack", 0.1f, -1, 0);
            }

            damageable.HP -= actionable.Power;

            if (damageable.HP <= 0)
            {
            }

            float time = actionable.transform.GetChild(0).GetComponent <Animator>().GetCurrentAnimatorClipInfo(0).Length;

            CoroutineUtility.Instance.DelayAction(time * 0.8f, () => {
                damageable.GetComponent <Animator>().CrossFade("damaged", 0.1f, -1, 0);
                CoroutineUtility.Instance.DelayAction(3f, () => {
                    damageable.gameObject.SetActive(false);
                });
            });

            return(actionable.transform.GetChild(0).GetComponent <Animator>().GetCurrentAnimatorClipInfo(0).Length);
        }
        public void Pause(PlayableModel playable = null)
        {
            if (playable)
            {
                if (coroutines[playable] != null)
                {
                    StopCoroutine(coroutines[playable]);
                }
                return;
            }

            foreach (var pair in coroutines)
            {
                var coroutine = pair.Value;
                if (coroutine != null)
                {
                    StopCoroutine(coroutine);
                }

                roundTransformValueToInt(pair.Key);
            }
        }
Exemple #17
0
        public float Action(PlayableModel entity, PuzzleEntityModel front_down_tile)
        {
            if (!front_down_tile)
            {
                return(0.0f);
            }

            var cleanable = front_down_tile.GetComponent <CleanableModel>();

            if (cleanable && !cleanable.IsClean)
            {
                return(0.0f);
            }

            entity.GetComponent <Animator>().SetFloat("Speed", 1);
            entity.GetComponent <Animator>().Play("jump_down", -1, 0);
            for (int i = 0; i < entity.transform.childCount; ++i)
            {
                entity.transform.GetChild(i).GetComponent <Animator>().SetFloat("Speed", 1);
                entity.transform.GetChild(i).GetComponent <Animator>().CrossFade("jump_down", 0.1f, -1, 0);
            }

            return(2.0f);
        }
Exemple #18
0
        public float Action(PlayableModel character, PuzzleEntityModel warpable_tile)
        {
            if (!warpable_tile)
            {
                return(0.0f);
            }

            var warpable         = warpable_tile.GetComponent <WarpableModel>();
            int random_index     = Random.Range(0, warpable.Neighbour.Count);
            var destination_tile = warpable.Neighbour[random_index];

            var cleanable = destination_tile.GetComponent <CleanableModel>();

            if (cleanable && !cleanable.IsClean)
            {
                return(0.0f);
            }

            // Warp Animation 재생

            character.transform.position = destination_tile.transform.position;

            return(character.transform.GetChild(0).GetComponent <Animator>().GetCurrentAnimatorClipInfo(0).Length);
        }
Exemple #19
0
 public void Init(int condition, PlayableModel playable)
 {
     Condition = condition;
     Playable  = playable;
 }
Exemple #20
0
 public float ActionReverse(PlayableModel playable, PuzzleEntityModel entity_1)
 {
     return(0.0f);
 }
Exemple #21
0
 public void Init(int condition, PlayableModel playable, SingleCommandModel conditional_command = null)
 {
     base.Init(condition, playable);
     ConditionalCommand = conditional_command;
 }
Exemple #22
0
 public float ActionReverse(PlayableModel attacker, PuzzleEntityModel front_tile)
 {
     return(0.0f);
 }