예제 #1
0
        private static void SetFiringAnimation(
            IProtoItemWeapon weaponProto,
            IComponentSkeleton skeletonRenderer,
            byte trackIndex,
            string fireAnimationName,
            double fireAnimationDuration,
            double fireInterval,
            bool mixWithCurrent,
            bool isLooped)
        {
            var currentFireAnimation = skeletonRenderer.GetCurrentAnimationName(trackIndex);

            if (currentFireAnimation == fireAnimationName)
            {
                // the same firing animation is already playing
                Api.Logger.Warning(
                    "Will overwrite current attack animation: "
                    + currentFireAnimation
                    + " - usually it means that the DamageApplyDelaySeconds+FireIntervalSeconds is lower than the attack animation duration for "
                    + weaponProto
                    + " (they must be matching perfectly).");
            }

            if (currentFireAnimation != null)
            {
                if (mixWithCurrent)
                {
                    skeletonRenderer.SetAnimationLoopMode(trackIndex, isLooped: false);
                    skeletonRenderer.RemoveAnimationTrackNextEntries(trackIndex);
                }
                else
                {
                    skeletonRenderer.RemoveAnimationTrack(trackIndex);
                }
            }

            // cooldown is a padding duration which makes animation "stuck" on the last frame for the specified duration
            var cooldownDuration = isLooped
                                            // in looped animation we need to match its total duration to fire interval by using cooldown
                                       ? Math.Max(0, fireInterval - fireAnimationDuration)
                                       : 0; // non-looped animation no cooldown is necessary

            skeletonRenderer.AddAnimation(
                trackIndex,
                animationName: fireAnimationName,
                isLooped: isLooped,
                customDuration: (float)fireAnimationDuration,
                cooldownDuration: (float)cooldownDuration);
        }
예제 #2
0
 protected virtual void ClientSetupSkeletonAnimation(
     bool isActive,
     IItem item,
     ICharacter character,
     IComponentSkeleton skeletonRenderer,
     List <IClientComponent> skeletonComponents)
 {
     if (isActive)
     {
         skeletonRenderer.RemoveAnimationTrack(trackIndex: AnimationTrackIndexes.Extra);
         skeletonRenderer.SetAnimation(
             trackIndex: AnimationTrackIndexes.Extra,
             animationName: this.ActiveLightCharacterAnimationName,
             isLooped: true);
     }
     else if (skeletonRenderer.GetCurrentAnimationName(AnimationTrackIndexes.Extra) != null)
     {
         // TODO: this is a hack - when an empty animation is added latest animation looping is breaking
         //skeletonRenderer.SetAnimationLoopMode(AnimationTrackIndexes.Extra, isLooped: false);
         skeletonRenderer.AddEmptyAnimation(AnimationTrackIndexes.Extra);
     }
 }