Beispiel #1
0
        public override void Refresh(ObjectData objData)
        {
            var resourceStateData = objData.GetData <ResourceStateData>();

            if (!resourceStateData.isInstantiated)
            {
                return;
            }

            var stressData = objData.GetData <ActorStressData>();

            if (stressData.duration == 0)
            {
                Stop(objData.ObjectId);
                return;
            }

            var actorData = objData.GetData <ActorData>();

            if (!ActorController.CanSkillDefault(actorData.currentState))
            {
                return;
            }

            if ((actorData.currentState & (int)ActorStateType.SkillDefault) == 0 &&
                (actorData.currentState & (int)ActorStateType.SkillCustom) == 0)
            {
                stressData.currentDuration = stressData.duration = 0;
                return;
            }

            var worldMgr = WorldManager.Instance;

            var physics2DData = objData.GetData <Physics2DData>();

            if (stressData.currentDuration == stressData.duration)
            {
                stressData.currentDuration = stressData.duration = 0;
                physics2DData.force.y      = 0;

                if ((actorData.currentState & (int)ActorStateType.SkillDefault) != 0)
                {
                    ActorAnimator.Stop(objData, ActorStateType.SkillDefault);
                }
                else if ((actorData.currentState & (int)ActorStateType.SkillDefault) != 0)
                {
                    ActorAnimator.Stop(objData, ActorStateType.SkillCustom);
                }

                actorData.currentState &= ~(int)ActorStateType.SkillDefault;
                actorData.currentState &= ~(int)ActorStateType.SkillCustom;
                objData.SetDirty(actorData);
            }
            else
            {
                var gameSystemData = worldMgr.GameCore.GetData <GameSystemData>();
                stressData.currentDuration += gameSystemData.unscaleDeltaTime;
                if (stressData.currentDuration >= stressData.duration)
                {
                    stressData.currentDuration = stressData.duration;
                    physics2DData.force.y      = 0;
                }
                else
                {
                    physics2DData.force.y = -physics2DData.mass * Constant.ACTOR_STRESS_RATE_Y;

                    objData.SetDirty(physics2DData);
                }
            }
        }
        public override void Refresh(ObjectData objData)
        {
            var resourceStateData = objData.GetData <ResourceStateData>();

            if (!resourceStateData.isInstantiated)
            {
                return;
            }

            var jumpData = objData.GetData <ActorJumpData>();

            var currentJump = jumpData.currentJump;

            if (currentJump.y == 0 && currentJump.x == 0)
            {
                Stop(objData.ObjectId);
                return;
            }

            var actorData = objData.GetData <ActorData>();

            if (!ActorController.CanJump(actorData.currentState))
            {
                return;
            }

            if ((actorData.currentState & (int)ActorStateType.Jump) == 0)
            {
                jumpData.currentJump = Vector3Int.zero;
                return;
            }

            var physics2DData       = objData.GetData <Physics2DData>();
            var actorControllerData = objData.GetData <ActorController2DData>();

            if (ActorPhysics2D.IsGround(actorControllerData) && jumpData.currentJump.y == 0)
            {
                jumpData.currentJump.x = 0;

                physics2DData.force.x = 0;
                physics2DData.force.y = 0;

                ActorAnimator.JumpGround(objData);
                ActorAnimator.Stop(objData, ActorStateType.Jump);

                actorData.currentState &= ~(int)ActorStateType.Jump;
                objData.SetDirty(actorData);
            }
            else
            {
                jumpData.currentJump.y = currentJump.y - physics2DData.airFriction;
                if (jumpData.currentJump.y < 0)
                {
                    jumpData.currentJump.y = 0;
                    physics2DData.force.y += -physics2DData.airFriction;
                }
                else
                {
                    physics2DData.force.y = currentJump.y;
                }

                physics2DData.force.x = jumpData.currentJump.x;

                objData.SetDirty(physics2DData);
            }
        }
        public override void Refresh(ObjectData objData)
        {
            var resourceStateData = objData.GetData <ResourceStateData>();

            if (!resourceStateData.isInstantiated)
            {
                return;
            }

            var flyData = objData.GetData <ActorFlyData>();

            if (flyData.duration == 0)
            {
                Stop(objData.ObjectId);
                return;
            }

            var actorData = objData.GetData <ActorData>();

            if (!ActorController.CanSkillDefault(actorData.currentState))
            {
                return;
            }

            if ((actorData.currentState & (int)ActorStateType.SkillDefault) == 0 &&
                (actorData.currentState & (int)ActorStateType.SkillCustom) == 0)
            {
                flyData.currentDuration = flyData.duration = 0;
                return;
            }

            var worldMgr = WorldManager.Instance;

            var physics2DData = objData.GetData <Physics2DData>();

            if (flyData.currentDuration == flyData.duration)
            {
                flyData.currentDuration = flyData.duration = 0;

                physics2DData.force.x = 0;
                physics2DData.force.y = 0;

                if ((actorData.currentState & (int)ActorStateType.SkillDefault) != 0)
                {
                    ActorAnimator.Stop(objData, ActorStateType.SkillDefault);
                }
                else if ((actorData.currentState & (int)ActorStateType.SkillDefault) != 0)
                {
                    ActorAnimator.Stop(objData, ActorStateType.SkillCustom);
                }

                actorData.currentState &= ~(int)ActorStateType.SkillDefault;
                actorData.currentState &= ~(int)ActorStateType.SkillCustom;
                objData.SetDirty(actorData);
            }
            else
            {
                var gameSystemData = worldMgr.GameCore.GetData <GameSystemData>();
                flyData.currentDuration += gameSystemData.unscaleDeltaTime;
                if (flyData.currentDuration >= flyData.duration)
                {
                    flyData.currentDuration = flyData.duration;
                    physics2DData.force.y   = 0;
                }
                else
                {
                    var seconds = flyData.currentDuration * Constant.ACTOR_FLY_SHAKE_DURATION / Constant.SECOND_TO_MILLISECOND;
                    if (seconds % 2 == 0)
                    {
                        physics2DData.force.y = Constant.ACTOR_FLY_SHAKE_Y;
                    }
                    else
                    {
                        physics2DData.force.y = -Constant.ACTOR_FLY_SHAKE_Y;
                    }
                }

                physics2DData.force.x = Constant.ACTOR_FLY_SPEED_X;

                objData.SetDirty(physics2DData);
            }
        }
        public override void Refresh(ObjectData objData)
        {
            var resourceStateData = objData.GetData <ResourceStateData>();

            if (!resourceStateData.isInstantiated)
            {
                return;
            }

            var hurtData = objData.GetData <ResourceHurtData>();

            var force = hurtData.force;

            if (force.y == 0 && force.x == 0)
            {
                Stop(objData.ObjectId);
                return;
            }

            var actorData = objData.GetData <ActorData>();

            if (!ActorController.CanHurt(actorData.currentState))
            {
                return;
            }

            if ((actorData.currentState & (int)ActorStateType.Hurt) == 0)
            {
                hurtData.force = Vector3Int.zero;
                return;
            }

            var physics2DData = objData.GetData <Physics2DData>();

            if (hurtData.force.y == 0)
            {
                hurtData.force.x      = 0;
                physics2DData.force.x = 0;
                physics2DData.force.y = 0;

                actorData.currentState &= ~(int)ActorStateType.Hurt;
                objData.SetDirty(actorData);
            }
            else
            {
                hurtData.force.y = force.y - physics2DData.airFriction;
                if (hurtData.force.y < 0)
                {
                    hurtData.force.y       = 0;
                    physics2DData.force.y += -physics2DData.airFriction;
                }
                else
                {
                    physics2DData.force.y = force.y;
                }

                physics2DData.force.x = hurtData.force.x;

                objData.SetDirty(physics2DData);
            }
        }