private void stopCharacter(EnemyColliderModel mainColliderModel)
 {
     if (mainColliderModel != null && mainColliderModel.view.isMove)
     {
         mainColliderModel.setState(CharacterStates.IDLE);
     }
 }
 public void forceExitPlayerTrigger(EnemyColliderModel mainColliderModel)
 {
     if (mainColliderModel != null)
     {
         mainColliderModel.isPlayerTrigger = false;
         mainColliderModel.setState(CharacterStates.MOVE);
     }
 }
        public void setState(string mainKey, CharacterStates state)
        {
            EnemyColliderModel mainColliderModel = getColliderModel(mainKey);

            if (mainColliderModel != null)
            {
                mainColliderModel.setState(state);
            }
        }
        public void forceExitPlayerTrigger(string mainKey)
        {
            EnemyColliderModel mainColliderModel = getColliderModel(mainKey);

            if (mainColliderModel != null)
            {
                mainColliderModel.isPlayerTrigger = false;
                mainColliderModel.setState(CharacterStates.MOVE);
            }
        }
 private void removeKey(string colliderKey, string deleteKey)
 {
     if (colliderKey != null && deleteKey != null)
     {
         EnemyColliderModel colliderModel = getColliderModel(colliderKey);
         if (colliderModel != null)
         {
             colliderModel.removeKey(deleteKey);
         }
     }
 }
        public CharacterStates getState(string mainKey)
        {
            EnemyColliderModel mainColliderModel = getColliderModel(mainKey);

            if (mainColliderModel != null)
            {
                return(mainColliderModel.state);
            }

            return(CharacterStates.NUL);
        }
        public void removeEnemy(string enemyKey, bool isForce = false)
        {
            EnemyColliderModel mainColliderModel = getColliderModel(enemyKey);

            if (mainColliderModel != null && !isForce)
            {
                removeKey(mainColliderModel.triggerKeyAfter, enemyKey);
                removeKey(mainColliderModel.triggerKeyBefore, enemyKey);
            }

            if (_list.ContainsKey(enemyKey))
            {
                _list.Remove(enemyKey);
            }
        }
        public void addEnemyView(EnemyView enemyView, IRoutineRunner routineRunner)
        {
            EnemyColliderModel colliderModel = new EnemyColliderModel(enemyView, this);

            if (colliderModel != null && !_list.ContainsKey(colliderModel.name))
            {
                colliderModel.routineRunner = routineRunner;
                colliderModel.setState(CharacterStates.MOVE);
                _list.Add(colliderModel.name, colliderModel);
            }
            else
            {
                Debug.LogWarning("EnemyManager.addEnemyView. An element with the same key = " + colliderModel.name + " already exists in the dictionary!");
            }
        }
        public void addTrigger(string mainKey, string colliderKey = null)
        {
            bool isPlayer = (colliderKey == null);

            Debug.Log("addTriger. isPlayer = " + isPlayer.ToString() + ". mainkey = " + mainKey + ". otherKey = " + colliderKey);
            EnemyColliderModel mainColliderModel = getColliderModel(mainKey);

            if (mainColliderModel != null && mainColliderModel.view)
            {
                if (isPlayer)
                {
                    /*if (mainColliderModel.triggerKeyAfter != null || mainColliderModel.triggerKeyBefore != null && mainColliderModel.state != CharacterStates.MOVE) {
                     *      mainColliderModel.view.flip ();
                     *      mainColliderModel.setState (CharacterStates.MOVE);
                     * } else {*/
                    stopCharacter(mainColliderModel);
                    mainColliderModel.isPlayerTrigger = true;
                    mainColliderModel.setState(CharacterStates.HIT);
                    //}
                }
                else
                {
                    EnemyColliderModel otherColliderModel = getColliderModel(colliderKey);
                    if (otherColliderModel != null)
                    {
                        stopCharacter(mainColliderModel);
                        bool isMainBefore = isFirstBefore(mainColliderModel.view, otherColliderModel.view);
                        if (isMainBefore)
                        {
                            mainColliderModel.triggerKeyAfter = colliderKey;
                        }
                        else
                        {
                            mainColliderModel.triggerKeyBefore = colliderKey;
                        }

                        if (!mainColliderModel.isPlayerTrigger)
                        {
                            mainColliderModel.setState(CharacterStates.BEFORE_ENEMY);
                        }
                    }
                }
            }
        }
        public void exitTrigger(string mainKey, GameObject enemyGO)
        {
            bool   isPlayer    = false;
            string colliderKey = null;

            if (enemyGO != null)
            {
                if (enemyGO.tag == PlayerView.ID)
                {
                    isPlayer = true;
                }
                else
                {
                    colliderKey = enemyGO.name;
                }
            }

            Debug.Log("exitTrigger. isPlayer = " + isPlayer.ToString() + ". mainkey = " + mainKey + ". otherKey = " + colliderKey);
            EnemyColliderModel mainColliderModel = getColliderModel(mainKey);

            if (mainColliderModel != null && mainColliderModel.view != null)
            {
                if (isPlayer)
                {
                    mainColliderModel.isPlayerTrigger = false;
                    if (!mainColliderModel.view.isMove && mainColliderModel.view.currentState != CharacterStates.HIT)
                    {
                        mainColliderModel.setState(CharacterStates.MOVE);
                    }
                }
                else if (colliderKey != null)
                {
                    EnemyColliderModel colliderModel = getColliderModel(colliderKey);
                    if (colliderModel != null && colliderModel.view != null)
                    {
                        bool isMainBefore = isFirstBefore(mainColliderModel.view, colliderModel.view);
                        mainColliderModel.removeKey(colliderKey, isMainBefore);
                        colliderModel.removeKey(mainKey, !isMainBefore);
                    }
                }
            }
        }
        public bool checkBeforeHit(string mainKey)
        {
            bool result = false;
            bool isMove = false;
            EnemyColliderModel mainColliderModel = getColliderModel(mainKey);

            if (mainColliderModel != null)
            {
                isMove = mainColliderModel.view.isMove;
                if (!isCollisionOut(mainColliderModel.collider) && isPlayerBefore(mainColliderModel.view.gameObject))
                {
                    result = true;
                }
            }

            Debug.Log("EnemyTriggerManager.name = " + mainKey + ". checkEnemyToHit = " + result + ". isMove = " + isMove.ToString());
            if (!result)
            {
                forceExitPlayerTrigger(mainColliderModel);
            }

            return(result);
        }