Esempio n. 1
0
        public override bool TryQueryingState(out MainModifierState value, out bool justChanged)
        {
            switch (state)
            {
            case State.Peaking:
            case State.Floating:
            case State.Grounding:
                value       = MainModifierState.Air;
                justChanged = this.justChanged;
                return(true);

            case State.Lying:
                value       = MainModifierState.Ground;
                justChanged = this.justChanged;
                return(true);

            case State.LieToIdle:
                value       = MainModifierState.LieToIdle;
                justChanged = this.justChanged;
                return(true);
            }

            return(base.TryQueryingState(out value, out justChanged));
        }
Esempio n. 2
0
 public virtual bool TryQueryingState(out MainModifierState value, out bool justChanged)
 {
     value       = MainModifierState.Ground;
     justChanged = false;
     return(false);
 }
Esempio n. 3
0
        public bool OnAttachAsSub(Character target)
        {
            attachType = ModifierAttachType.Sub;
            bool attachSuccess = false;

            try {
                Modifier           highest     = target.FindModifierOfHighestRank();
                MType              highestType = (MType)(int)highest.Type();
                MType              thisType    = (MType)(int)Type();
                List <Interaction> inters      = modifierInteractionCollection.Find(highestType, thisType);
                if (inters.Count < 1)
                {
                    return(attachSuccess);
                }

                Interaction       inter = inters[0];
                bool              isStateQuerySuccess = false;
                MainModifierState mainState           = MainModifierState.Ground;
                if (highest is BaseModifier)
                {
                    bool justChanged;
                    isStateQuerySuccess = ((BaseModifier)highest).TryQueryingState(out mainState, out justChanged);
                }

                if (!isStateQuerySuccess)
                {
                    mainState = target.IsOnGround()
                                                ? MainModifierState.Ground
                                                : MainModifierState.Air;
                }

                List <ActionDetails> actions = inter.FindActions(mainState);
                if (actions.Count < 1)
                {
                    return(attachSuccess);
                }

                for (int i = 0; i < actions.Count; i++)
                {
                    ActionDetails ad = actions[i];
                    switch (ad.ShowActionType())
                    {
                    case InteractionActionType.DoNothing:
                        attachSuccess = false;
                        break;

                    case InteractionActionType.Vibrate:
                        VibrateActionDetails vad = (VibrateActionDetails)ad;
                        VibrateTarget(
                            vad.xAmplitude, vad.duration, vad.frequency, vad.shouldDecay,
                            vad.decayConstant, targetGameObject, () => subLifetime.End()
                            );
                        attachSuccess = true;
                        break;

                    case InteractionActionType.PlayAnimation:
                        PlayAnimationActionDetails paad = (PlayAnimationActionDetails)ad;
                        if (targetAnimation.CurrentAnimationNames().Contains(paad.name))
                        {
                            targetAnimation.Stop();
                        }

                        targetAnimation.PlayAnimation(paad.name);
                        targetAnimation.JumpToFrame(paad.startFrame);
                        if (highest is StunModifier)
                        {
                            ((StunModifier)highest).OnAnimationPlayedBySubModifier(paad.name);
                        }
                        subLifetime.End();
                        attachSuccess = true;
                        break;

                    case InteractionActionType.Jump:
                        JumpActionDetails jad = (JumpActionDetails)ad;
                        movingJumpRequest = new MovingJumpRequest(
                            jad.height, jad.timeToPeak, jad.timeToGround, jad.timeToFloat, jad.distance
                            );
                        targetEntity.GetComponent <MovementComponent>().AddMovementRequest(
                            movingJumpRequest
                            );
                        attachSuccess = true;
                        break;

                    case InteractionActionType.Dash:
                        MovementComponent casterMc     = casterEntity.GetComponent <MovementComponent>();
                        Direction         casterFacing = casterMc.FacingDirection;
                        DashActionDetails dad          = (DashActionDetails)ad;
                        dashRequest = new DashRequest(
                            casterFacing, dad.distance, dad.duration, 0, dad.constantSpeed
                            );
                        targetEntity.GetComponent <MovementComponent>().AddMovementRequest(
                            dashRequest
                            );
                        attachSuccess = true;
                        break;

                    case InteractionActionType.OverrideMainModifier:
                        attachType = ModifierAttachType.Main;
                        target.RemoveModifier(highest);
                        OnAttachAsMain(target);
                        attachSuccess = true;
                        break;

                    case InteractionActionType.IncreaseLyingDuration:
                        StunInfo si = (StunInfo)info;
                        increaseLyingDuration = new IncreaseLyingDuration(
                            subLifetime, si.ShowDuration(), targetEntity
                            );
                        attachSuccess = true;
                        break;

                    default:
                        throw new Exception(
                                  "Missing logic to handle SubModifier of ActionType " + ad.ShowActionType()
                                  );
                    }
                }

                return(attachSuccess);
            }
            catch (Exception e) {
                DLog.LogError(e);
                return(attachSuccess);
            }
        }
Esempio n. 4
0
 public override bool TryQueryingState(out MainModifierState value, out bool justChanged)
 {
     value       = state;
     justChanged = this.justChanged;
     return(true);
 }
Esempio n. 5
0
        protected override void OnUpdate(float dt)
        {
            justChanged = false;
            if (IsFinish())
            {
                return;
            }

            elapsed += dt;

            if (elapsed >= timeUntilReturnToIdle && !isReturnToIdleStarted)
            {
                isReturnToIdleStarted = true;
                if (targetEntity.GetComponent <HealthComponent>().IsAlive())
                {
                    targetAnimation.Animation.PlayAnimation(
                        animProfile.LieToIdle(), 1, PlayMethod.Crossfade, .1f
                        );
                    targetAnimation.Animation.PlayAnimation(
                        AnimationName.IDLE, 1, PlayMethod.Queue, 0
                        );
                }
                //DLog.Log("Return to idle");
            }

            if (elapsed >= timeUntilFall)
            {
                if (!isOnGroundAnimationPlayed)
                {
                    justChanged = true;
                    state       = MainModifierState.Air;
                    //DLog.Log("RagdollModifier: state: " + state);
                    isOnGroundAnimationPlayed = true;
                    JointHierarchyAdjustment jha = targetGo.GetComponentInChildren <JointHierarchyAdjustment>();
                    if (jha != null)
                    {
                        jha.UndoAdjustment();
                    }
                    targetAnimation.Animation.UnpauseAnimation();
                    targetAnimation.Animation.PlayAnimation(animProfile.FallLoop());
                    SetEnableDynamicBones(false);

                    MovementComponent targetMc = targetEntity.GetComponent <MovementComponent>();
                    targetMc.UpdateGround();
                    float s       = targetMc.Position.y;
                    float t       = info.RagdollModifierConfig.timeToFall;
                    float v0      = info.RagdollModifierConfig.initSpeedOfFall;
                    float gravity = 2 * (s - v0 * t) / (t * t);
                    fallRequest = new FallRequest(gravity);
                    targetMc.AbortAllRequests();
                    targetMc.AddMovementRequest(fallRequest);
                    //DLog.Log("Fall");
                }
            }

            if (elapsed >= timeUntilGround && !isGrounded)
            {
                justChanged = true;
                state       = MainModifierState.Ground;
                //DLog.Log("RagdollModifier: state: " + state);
                isGrounded = true;
                targetAnimation.Animation.PlayAnimation(animProfile.FallToLie());
                targetAnimation.Animation.JumpToFrame(info.RagdollModifierConfig.onGroundAnimationStartFrame);
                targetAnimation.Animation.QueueAnimation(animProfile.LieLoop());
                //DLog.Log("Lie");
            }

            if (fallRequest != null)
            {
                if (fallRequest.IsCompleted())
                {
                    if (!isEventTriggered)
                    {
                        isEventTriggered = true;
                        TriggerEvents();
                    }
                }
            }

            if (vfxLogic != null)
            {
                vfxLogic.Update(dt);
            }

            if (elapsed >= duration)
            {
                lifetime.End();
            }
        }