Exemplo n.º 1
0
    /// <summary>
    /// 当前关卡完成
    /// </summary>
    /// <returns></returns>
    IEnumerator LevelComplete()
    {
        //激活慢动作效果
        if (activateSlowMotionOnLastHit)
        {
            CameraSlowMotion csm = Camera.main.GetComponent <CameraSlowMotion>();
            if (csm != null)
            {
                csm.StartSlowMotionDelay(effectDuration);
                yield return(new WaitForSeconds(effectDuration));
            }
        }

        //进入下一关等待时间
        yield return(new WaitForSeconds(1f));

        //完成关卡后调用UI

        UIManager UI = GameObject.FindObjectOfType <UIManager>();

        if (UI != null)
        {
            UI.UI_fader.Fade(UIFader.FADE.FadeOut, 2f, 0);
            yield return(new WaitForSeconds(2f));
        }

        GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
        foreach (GameObject p in players)
        {
            Destroy(p);
        }

        //进入下一关
        if (loadNewLevel)
        {
            if (levelName != "")
            {
                SceneManager.LoadScene(levelName);
            }
        }
        else
        {
            //展示游戏结束界面
            if (UI != null)
            {
                UI.DisableAllScreens();
                UI.ShowMenu("LevelComplete");
            }
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// 被击中
    /// </summary>
    /// <param name="d"></param>
    public void Hit(DamageObject d)
    {
        if (HitableStates.Contains(enemyState))
        {
            //只在敌人被击倒时才允许地面攻击击中
            if (enemyState == PLAYERSTATE.KNOCKDOWNGROUNDED && !d.isGroundAttack)
            {
                return;
            }

            CancelInvoke();
            StopAllCoroutines();
            playerAnimator.StopAllCoroutines();
            Move(Vector3.zero, 0f);

            //增加攻击时间,使玩家被击中后无法立即攻击
            lastAttackTime = Time.time;

            //当敌人在空中时不能被击中
            if ((enemyState == PLAYERSTATE.KNOCKDOWNGROUNDED || enemyState == PLAYERSTATE.GROUNDHIT) && !d.isGroundAttack)
            {
                return;
            }

            //防御
            if (!d.DefenceOverride && defendableStates.Contains(enemyState))
            {
                int rand = Random.Range(0, 100);
                if (rand < defendChance)
                {
                    Defend();
                    return;
                }
            }

            //受伤音效
            GlobalAudioPlayer.PlaySFXAtPosition(d.hitSFX, transform.position);

            //被命中后展示特效
            ShowHitEffectAtPosition(new Vector3(transform.position.x, d.inflictor.transform.position.y + d.collHeight, transform.position.z));

            //相机抖动
            CameraShake camShake = Camera.main.GetComponent <CameraShake>();
            if (camShake != null)
            {
                camShake.Shake(0.1f);
            }

            //激活慢动作相机
            if (d.slowMotionEffect)
            {
                CameraSlowMotion cmd = Camera.main.GetComponent <CameraSlowMotion>();
                if (cmd != null)
                {
                    cmd.StartSlowMotionDelay(.2f);
                }
            }

            //减少生命值
            HealthSystem hs = GetComponent <HealthSystem>();
            if (hs != null)
            {
                hs.SubstractHealth(d.damageCount);
                if (hs.CurrentHp == 0)
                {
                    return;
                }
            }

            //地面攻击
            if (enemyState == PLAYERSTATE.KNOCKDOWNGROUNDED)
            {
                StopAllCoroutines();
                enemyState = PLAYERSTATE.GROUNDHIT;
                StartCoroutine(GroundHit());
                return;
            }

            //转向攻击来袭的方向
            int dir = d.inflictor.transform.position.x > transform.position.x ? 1 : -1;
            TurnToDir((DIRECTION)dir);

            //检查是否被击倒
            if (d.knockDown)
            {
                StartCoroutine(KnockDownSequence(d.inflictor));
                return;
            }
            else
            {
                //默认攻击
                int rand = Random.Range(1, 3);
                playerAnimator.SetAnimatorTrigger("Hit" + rand);
                enemyState = PLAYERSTATE.HIT;

                //从冲击中增加很小的力量
                LookAtTarget(d.inflictor.transform);
                playerAnimator.AddForce(-KnockbackForce);

                //受到攻击时将敌人的状态从被动变为主动
                if (enemyTactic != ENEMYTACTIC.ENGAGE)
                {
                    EnemyManager.SetAgressive(gameObject);
                }

                Invoke("Ready", hitRecoveryTime);
                return;
            }
        }
    }
Exemplo n.º 3
0
        public Loopable Produce(Character caster, Skill skill, SkillId skillId, BaseEvent baseEvent,
                                SkillCastingSource skillCastingSource, TemplateArgs args)
        {
            BaseAction ba         = baseEvent.ShowAction();
            ActionType actionType = ba.ShowActionType();
            Loopable   loopable   = null;

            switch (actionType)
            {
            case ActionType.Camera:
                CameraAction        ca     = (CameraAction)ba;
                CameraAction.BaseFx bf     = ca.fx;
                CameraAction.FxType fxType = bf.ShowFxType();
                switch (fxType)
                {
                case CameraAction.FxType.Shake:
                    CameraAction.ShakeFx sf = (CameraAction.ShakeFx)bf;
                    loopable = new CameraShake(environment, sf);
                    break;

                case CameraAction.FxType.Fade:
                    loopable = new CameraFade(environment, baseEvent);
                    break;

                case CameraAction.FxType.CinematicZoomToSelf:
                    loopable = new CameraCinematicZoomToSelf(environment, baseEvent, caster);
                    break;

                case CameraAction.FxType.SlowMotion:
                    loopable = new CameraSlowMotion(environment, baseEvent);
                    break;

                case CameraAction.FxType.AddTarget:
                    loopable = new CameraAddTarget(environment, baseEvent, caster);
                    break;

                default:
                    throw new Exception("Missing logic to handle camera fx of type " + fxType);
                }
                break;

            case ActionType.Dash:
                Dash dash = new Dash(baseEvent, caster, skill.IgnoreMinSpeedOnAirForDashes(), skill, environment);
                loopable = dash;
                break;

            case ActionType.Jump:
                bool jumpOverDistance = true;
                if (args != null)
                {
                    bool found;
                    jumpOverDistance = args.TryGetEntry <bool>(TemplateArgsName.JumpSkill_JumpOverDistance, out found);
                    if (!found)
                    {
                        jumpOverDistance = true;
                    }
                }
                Jump jump = new Jump(baseEvent, caster, skill, environment, jumpOverDistance);
                loopable = jump;
                break;

            case ActionType.Vfx:
                Vfxs.Vfx vfx = new Vfxs.Vfx(
                    baseEvent, environment, caster, skillCastingSource, skill, args
                    );
                loopable = vfx;
                break;

            case ActionType.Modifier:
                ModifierAction     ma       = (ModifierAction)ba;
                BaseModifierConfig bmc      = ma.modifierConfig;
                ModifierInfo       mi       = modifierInfoFactory.CreateFrom(skill, bmc, environment);
                EntityReference    er       = caster.GameObject().GetComponent <EntityReference>();
                Modifier           modifier = DamageSystem.Instance.CreateModifier(
                    mi, er.Entity, er.Entity, caster.Position(),
                    caster.Position(), skill, skillId, 0
                    );
                if (modifier != null)
                {
                    caster.AddModifier(modifier);
                }
                loopable = new ModifierLoopable(modifier);
                break;

            case ActionType.Animation:
                loopable = new AnimationPlayback(baseEvent, caster);
                break;

            case ActionType.Teleport:
                TeleportAction          ta   = (TeleportAction)baseEvent.action;
                TeleportAction.ModeName mode = ta.mode.ShowModeName();
                switch (mode)
                {
                case TeleportAction.ModeName.PredefinedPositionOnMap:
                    new Teleport(baseEvent, caster, environment);
                    loopable = new ImmediatelyFinishedLoopable();
                    break;

                case TeleportAction.ModeName.KeepDistance:
                    TeleportAction.KeepDistanceMode kdm = (TeleportAction.KeepDistanceMode)ta.mode;
                    loopable = new TeleportKeepDistanceLogic(kdm, skill, environment, caster);
                    break;

                case TeleportAction.ModeName.AroundTarget:
                    TeleportAction.AroundTargetMode atm = (TeleportAction.AroundTargetMode)ta.mode;
                    loopable = new TeleportAroundTargetLogic(atm, caster, environment, skill);
                    break;

                case TeleportAction.ModeName.AroundTeamMate:
                    TeleportAction.AroundTeamMateMode atmm = (TeleportAction.AroundTeamMateMode)ta.mode;
                    loopable = new TeleportAroundTeamMate(atmm, caster, environment, skill);
                    break;

                default:
                    throw new Exception("Cannot create teleport of type " + mode);
                }
                break;

            case ActionType.FacingDirection:
                loopable = new FacingDirection(baseEvent, caster, environment);
                break;

            case ActionType.DashTowardTarget:
                DashTowardTarget dtt = new DashTowardTarget(baseEvent, caster, environment);
                loopable = dtt;
                break;

            case ActionType.JumpTowardTarget:
                loopable = new JumpTowardTarget(baseEvent, caster, environment);
                break;

            case ActionType.SpawnCharacter:
                SpawnCharacterAction sca = (SpawnCharacterAction)ba;
                loopable = new SpawnCharacter(sca, entitySpawner, caster, args, environment, skillId, hamc);
                break;

            case ActionType.Rotation:
                loopable = new Rotation(baseEvent, caster, environment);
                break;

            case ActionType.Timer:
                loopable = new Timer(baseEvent, skill);
                break;

            case ActionType.Sound:
                loopable = new AudioClipPlayback(baseEvent, environment);
                break;

            case ActionType.PassiveSkillOnOff:
                loopable = new PassiveSkillOnOff(baseEvent, caster);
                break;

            case ActionType.DistanceTracker:
                loopable = new DistanceTracker(baseEvent, skill, caster);
                break;

            case ActionType.SelfDamageDealing:
                loopable = new SelfDamageDealing(baseEvent, caster, skill, skillId);
                break;

            case ActionType.SwitchPhase:
                loopable = new SwitchPhase(skill);
                break;

            case ActionType.Movable:
                Entity        casterEntity  = caster.GameObject().GetComponent <EntityReference>().Entity;
                UserInput     userInput     = casterEntity.GetComponent <HeroStateMachineComponent>().UserInput;
                MovableAction movableAction = (MovableAction)ba;
                loopable = new Movable(movableAction, skill, caster.FacingDirection(), userInput, caster);
                break;

            case ActionType.Input:
                casterEntity = caster.GameObject().GetComponent <EntityReference>().Entity;
                userInput    = casterEntity.GetComponent <HeroStateMachineComponent>().UserInput;
                InputAction ia = (InputAction)ba;
                loopable = new InputSimulation(ia, (DefaultUserInput)userInput);
                break;

#if UNITY_EDITOR
            case ActionType.Macro:
                loopable = new Macro(baseEvent, caster);
                break;
#endif
            default:
                DLog.Log("Missing logic to handle action of type " + actionType);
                break;
            }

            return(loopable);
        }