Beispiel #1
0
 internal static MotionRunData CreateMotionRunData(
     MotionCommand motionCommand,
     int? count = null,
     Func<MotionData> func = null)
 {
     func = func ?? (() => null);
     Converter<FSharpOption<int>, FSharpOption<MotionData>> conv = unused =>
         {
             var res = func();
             if (res == null) { return FSharpOption<MotionData>.None; }
             else { return FSharpOption.Create(res); }
         };
     var countOpt = count != null ? FSharpOption.Create(count.Value) : FSharpOption<int>.None;
     return new MotionRunData(
         motionCommand,
         countOpt,
         FSharpFuncUtil.Create(conv));
 }
Beispiel #2
0
 internal static MotionRunData CreateMotionRunData(
     MotionCommand motionCommand,
     int? count = null,
     Func<MotionData> func = null)
 {
     func = func ?? (() => null);
     var countOpt = count != null ? FSharpOption.Create(count.Value) : FSharpOption<int>.None;
     return new MotionRunData(
         motionCommand,
         countOpt,
         FuncUtil.CreateMotionFunc(func));
 }
Beispiel #3
0
 public Motion(WorldObject wo, MotionCommand motion, float speed = 1.0f)
 {
     Stance = wo.CurrentMotionState.Stance;
     SetForwardCommand(motion, speed);
 }
Beispiel #4
0
 public bool RemoveCommand(MotionCommand command, float speed, bool mouse)
 {
     return(false);
 }
Beispiel #5
0
 public static bool IsSubsequent(this MotionCommand motionCommand)
 {
     return(motionCommand >= MotionCommand.AttackHigh2 && motionCommand <= MotionCommand.AttackLow3 ||
            motionCommand >= MotionCommand.AttackHigh4 && motionCommand <= MotionCommand.AttackLow6);
 }
Beispiel #6
0
 public static bool IsMultiStrike(this MotionCommand motionCommand)
 {
     return(motionCommand >= MotionCommand.DoubleSlashLow && motionCommand <= MotionCommand.TripleThrustHigh ||
            motionCommand >= MotionCommand.OffhandDoubleSlashLow && motionCommand <= MotionCommand.OffhandTripleThrustHigh);
 }
Beispiel #7
0
        public static float GetCycleLength(uint motionTableId, MotionStance stance, MotionCommand motion, float speed = 1.0f)
        {
            var motionTable = DatManager.PortalDat.ReadFromDat <DatLoader.FileTypes.MotionTable>(motionTableId);

            return(motionTable.GetCycleLength(stance, motion) / speed);
        }
Beispiel #8
0
        public static List <float> GetAttackFrames(uint motionTableId, MotionStance stance, MotionCommand motion)
        {
            var motionTable = DatManager.PortalDat.ReadFromDat <DatLoader.FileTypes.MotionTable>(motionTableId);

            return(motionTable.GetAttackFrames(motionTableId, stance, motion, null));
        }
Beispiel #9
0
 public void SetTurnCommand(MotionCommand motion, float speed = 1.0f)
 {
     MotionState.TurnCommand = motion;
     MotionState.TurnSpeed   = speed;
 }
Beispiel #10
0
 public void SetSidestepCommand(MotionCommand motion, float speed = 1.0f)
 {
     MotionState.SidestepCommand = motion;
     MotionState.SidestepSpeed   = speed;
 }
Beispiel #11
0
        public ACE.Entity.Position GetAnimationFinalPositionFromStart(ACE.Entity.Position position, float objScale, MotionCommand currentMotionState, MotionStance style, MotionCommand motion)
        {
            float length = 0; // init our length var...will return as 0 if not found

            ACE.Entity.Position finalPosition = new ACE.Entity.Position();

            uint motionHash = ((uint)currentMotionState & 0xFFFFFF) | ((uint)style << 16);

            if (Links.ContainsKey(motionHash))
            {
                Dictionary <uint, MotionData> links = Links[motionHash];

                if (links.ContainsKey((uint)motion))
                {
                    // loop through all that animations to get our total count
                    for (int i = 0; i < links[(uint)motion].Anims.Count; i++)
                    {
                        AnimData anim = links[(uint)motion].Anims[i];

                        uint numFrames;

                        // check if the animation is set to play the whole thing, in which case we need to get the numbers of frames in the raw animation
                        if ((anim.LowFrame == 0) && (anim.HighFrame == -1))
                        {
                            var animation = DatManager.PortalDat.ReadFromDat <Animation>(anim.AnimId);
                            numFrames = animation.NumFrames;

                            if (animation.PosFrames.Count > 0)
                            {
                                finalPosition = position;
                                var origin      = new Vector3(position.PositionX, position.PositionY, position.PositionZ);
                                var orientation = new Quaternion(position.RotationX, position.RotationY, position.RotationZ, position.RotationW);
                                foreach (var posFrame in animation.PosFrames)
                                {
                                    origin += Vector3.Transform(posFrame.Origin, orientation) * objScale;

                                    orientation *= posFrame.Orientation;
                                    orientation  = Quaternion.Normalize(orientation);
                                }

                                finalPosition.PositionX = origin.X;
                                finalPosition.PositionY = origin.Y;
                                finalPosition.PositionZ = origin.Z;

                                finalPosition.RotationW = orientation.W;
                                finalPosition.RotationX = orientation.X;
                                finalPosition.RotationY = orientation.Y;
                                finalPosition.RotationZ = orientation.Z;
                            }
                            else
                            {
                                return(position);
                            }
                        }
                        else
                        {
                            numFrames = (uint)(anim.HighFrame - anim.LowFrame);
                        }

                        length += numFrames / Math.Abs(anim.Framerate); // Framerates can be negative, which tells the client to play in reverse
                    }
                }
            }

            return(finalPosition);
        }
Beispiel #12
0
        public ACE.Entity.Position GetAnimationFinalPositionFromStart(ACE.Entity.Position position, float objScale, MotionCommand motion)
        {
            MotionStance defaultStyle = (MotionStance)DefaultStyle;

            // get the default motion for the default
            MotionCommand defaultMotion = GetDefaultMotion(defaultStyle);

            return(GetAnimationFinalPositionFromStart(position, objScale, defaultMotion, defaultStyle, motion));
        }
Beispiel #13
0
        public List <AnimData> GetAnimData(MotionStance stance, MotionCommand motion, MotionCommand currentMotion)
        {
            var animData = new List <AnimData>();

            uint motionHash = (uint)stance << 16 | (uint)currentMotion & 0xFFFFF;

            Links.TryGetValue(motionHash, out var link);
            if (link == null)
            {
                return(animData);
            }

            link.TryGetValue((uint)motion, out var motionData);
            if (motionData == null)
            {
                motionHash = (uint)stance << 16;
                Links.TryGetValue(motionHash, out link);
                if (link == null)
                {
                    return(animData);
                }
                link.TryGetValue((uint)motion, out motionData);
                if (motionData == null)
                {
                    return(animData);
                }
            }
            return(motionData.Anims);
        }
Beispiel #14
0
        public void BroadcastMovement(MoveToState moveToState)
        {
            var state = moveToState.RawMotionState;

            // update current style
            if ((state.Flags & RawMotionFlags.CurrentStyle) != 0)
            {
                // this lowercase stance field in Player doesn't really seem to be used anywhere
                stance = state.CurrentStyle;
            }

            // update CurrentMotionState here for substates?
            if ((state.Flags & RawMotionFlags.ForwardCommand) != 0)
            {
                if (((uint)state.ForwardCommand & (uint)CommandMask.SubState) != 0)
                {
                    CurrentMotionState.SetForwardCommand(state.ForwardCommand);
                }
            }
            else
            {
                CurrentMotionState.SetForwardCommand(MotionCommand.Ready);
            }

            if (state.CommandListLength > 0)
            {
                if (((uint)state.Commands[0].MotionCommand & (uint)CommandMask.SubState) != 0)
                {
                    CurrentMotionState.SetForwardCommand(state.Commands[0].MotionCommand);
                }
            }

            if (state.HasSoulEmote(false))
            {
                // prevent soul emote spam / bug where client sends multiples
                var soulEmote = state.Commands[0].MotionCommand;
                if (soulEmote == LastSoulEmote && DateTime.UtcNow < LastSoulEmoteEndTime)
                {
                    state.Commands.Clear();
                    state.CommandListLength = 0;
                }
                else
                {
                    var animLength = Physics.Animation.MotionTable.GetAnimationLength(MotionTableId, CurrentMotionState.Stance, soulEmote, state.Commands[0].Speed);

                    LastSoulEmote        = soulEmote;
                    LastSoulEmoteEndTime = DateTime.UtcNow + TimeSpan.FromSeconds(animLength);
                }
            }

            var movementData = new MovementData(this, moveToState);

            // copy some fields to CurrentMotionState?
            // this is a mess, fix this whole architecture.
            CurrentMotionState.MotionState.ForwardCommand  = movementData.Invalid.State.ForwardCommand;
            CurrentMotionState.MotionState.ForwardSpeed    = movementData.Invalid.State.ForwardSpeed;
            CurrentMotionState.MotionState.TurnCommand     = movementData.Invalid.State.TurnCommand;
            CurrentMotionState.MotionState.TurnSpeed       = movementData.Invalid.State.TurnSpeed;
            CurrentMotionState.MotionState.SidestepCommand = movementData.Invalid.State.SidestepCommand;
            CurrentMotionState.MotionState.SidestepSpeed   = movementData.Invalid.State.SidestepSpeed;

            var movementEvent = new GameMessageUpdateMotion(this, movementData);

            EnqueueBroadcast(true, movementEvent);    // shouldn't need to go to originating player?

            // TODO: use real motion / animation system from physics
            //CurrentMotionCommand = movementData.Invalid.State.ForwardCommand;
            CurrentMovementData = movementData;
        }
Beispiel #15
0
 public bool NukeCommand(MotionCommand command, bool start, float speed, bool mouse, bool newHoldRun)
 {
     return(false);
 }
Beispiel #16
0
        public void MovePlayer(MotionCommand command, bool start, float speed, bool mouse, bool newHoldRun)
        {
            if (Player == null || Player.InqInterpretedMotionState() == null)
            {
                return;
            }

            // if vfptr[10] - PlayerIsDead
            if (PlayerIsDead())
            {
                // vfptr[9].OnAction - LoseKeyboardFocus
                LoseKeyboardFocus();
                // vfptr[17](0, 0) - SetAutoRun
                SetAutoRun(false, false);
                return;
            }

            // if !ICIDM::s_cidm->m_UseMouseTurning
            // - goto LABEL_55

            var mvp = new MovementParameters();

            if (mouse)
            {
                // someFlags &= 0xFFFFF7FF;
                // unset bit 11
                mvp.SetHoldKey = false;
                var holdRun = Convert.ToInt32(newHoldRun) + 1;
            }

            var turn     = (MotionCommand)MotionStance.Invalid;
            var sidestep = (MotionCommand)MotionStance.Invalid;

            if (TurnList.Count != 0)
            {
                turn = TurnList.FirstOrDefault().Command;
            }

            if (SidestepList.Count != 0)
            {
                sidestep = SidestepList.FirstOrDefault().Command;
            }

            // vfptr[17].OnLoseFocus - GetMouseLookActive
            var mouselook = GetMouseLookActive();

            bool start_turn_left      = false;
            bool start_turn_right     = false;
            bool start_sidestep_left  = false;
            bool start_sidestep_right = false;

            bool cancel_turn_left      = false;
            bool cancel_turn_right     = false;
            bool cancel_sidestep_left  = false;
            bool cancel_sidestep_right = false;

            MotionCommand cmd1;

            if (!mouse)
            {
                if (!mouselook)
                {
                    cmd1 = command;
                    // goto LABEL_59
                }
                if (command != MotionCommand.TurnRight)
                {
                    if (command != MotionCommand.TurnLeft)
                    {
                        if (start)
                        {
                            cancel_turn_left    = true;
                            start_sidestep_left = true;
                        }
                        else
                        {
                            cancel_sidestep_left = true;
                        }
                    }
                    else
                    {
                        cancel_turn_right = true;
                        cancel_turn_left  = true;
                    }
                    // goto LABEL_38
                }
                if (!start)
                {
                    cancel_sidestep_right = true;
                    // goto LABEL_38
                }
                // LABEL_31:
                cancel_turn_right    = true;
                start_sidestep_right = true;
                // goto LABEL_38
            }

            if (!mouselook)
            {
                if (turn == MotionCommand.TurnRight)
                {
                    cancel_sidestep_right = true;
                    start_turn_right      = true;
                }
                else if (turn == MotionCommand.TurnLeft)
                {
                    cancel_sidestep_left = true;
                    start_turn_left      = true;
                }
                // goto LABEL_38
            }

            if (command != MotionCommand.MouseLook)
            {
                // goto LABEL_38
            }

            if (turn == MotionCommand.TurnRight)
            {
                cancel_turn_right = true;

                if (sidestep == MotionCommand.SideStepLeft)
                {
                    start_sidestep_left = true;
                }
                else
                {
                    start_sidestep_right = true;
                }

                // goto LABEL_38
            }

            if (turn == MotionCommand.TurnLeft)
            {
                if (sidestep != MotionCommand.SideStepRight)
                {
                    cancel_turn_left    = true;
                    start_sidestep_left = true;

                    // goto LABEL_38
                }
                // goto LABEL_31
            }

            if (MouseLeftDown)
            {
                start   = true;
                command = MotionCommand.WalkForward;
            }

            // ============
            // LABEL 38:

            // vfptr[8].OnLoseFocus - TakeControlFromServer
            TakeControlFromServer();

            if (cancel_sidestep_right)
            {
                Player.StopMotion((uint)MotionCommand.SideStepRight, mvp, true);
            }

            if (cancel_sidestep_left)
            {
                Player.StopMotion((uint)MotionCommand.SideStepLeft, mvp, true);
            }

            if (cancel_turn_right)
            {
                Player.StopMotion((uint)MotionCommand.TurnRight, mvp, true);
            }

            if (cancel_turn_left)
            {
                Player.StopMotion((uint)MotionCommand.TurnLeft, mvp, true);
            }

            if (start_turn_right)
            {
                start = true;
                cmd1  = MotionCommand.TurnRight;
            }
            else
            {
                cmd1 = command;
            }

            if (start_turn_left)
            {
                start = true;
                cmd1  = MotionCommand.TurnLeft;
            }

            if (start_sidestep_right)
            {
                start = true;
                cmd1  = MotionCommand.SideStepRight;
                speed = 1.0f;
            }

            if (start_sidestep_left)
            {
                start   = true;
                command = MotionCommand.SideStepLeft;
                speed   = 1.0f;

                // LABEL_55:
                cmd1 = command;
            }

            var holdRunRel1 = 0;

            if (mouse)
            {
                holdRunRel1 = Convert.ToInt32(newHoldRun) + 1;
                // goto LABEL_60
            }

            // LABEL_59:
            holdRunRel1 = 0;

            // LABEL_60:
            if (AutonomyLevel != 0)
            {
                if (start)
                {
                    if (cmd1 != MotionCommand.Jump)
                    {
                        mvp = new MovementParameters();
                        // set 12th flag
                        mvp.Autonomous = true;
                        if (mouse)
                        {
                            mvp.SetHoldKey = false;     // unset 11th flag
                        }
                        if (((uint)cmd1 & (uint)CommandMask.Action) != 0)
                        {
                            // vfptr[15].OnLoseFocus(this)
                        }
                        var werror = Player.DoMotion((uint)cmd1, mvp);
                        switch (werror)
                        {
                        case WeenieError.None:
                            if (((uint)cmd1 & (uint)CommandMask.Action) != 0)
                            {
                                ActionStamp++;
                            }
                            return;

                        case WeenieError.CantCrouchInCombat:
                            break;      // 72

                        case WeenieError.CantSitInCombat:
                            break;      // 73

                        case WeenieError.CantLieDownInCombat:
                            break;      // 73

                        case WeenieError.YouAreTooTiredToDoThat:
                            break;      // 73

                        case WeenieError.CantChatEmoteInCombat:
                            break;      // 73

                        case WeenieError.CantChatEmoteNotStanding:
                            break;

                        default:
                            return;
                        }
                    }
                }
                else if (cmd1 != MotionCommand.Jump)
                {
                    mvp = new MovementParameters();
                    var holdRunRel = 0;
                    if (mouse)
                    {
                        mvp.SetHoldKey = false;
                        holdRunRel     = Convert.ToInt32(newHoldRun) + 1;
                    }
                    Player.StopMotion((uint)cmd1, mvp, true);
                }
            }
            else
            {
                // vfptr[4].OnLoseFocus - NonAutonomous?
                MovePlayer_NonAutonomous(cmd1, start, speed, (HoldKey)holdRunRel1);
            }
        }
Beispiel #17
0
 public MotionItem(MotionCommand animation, float speed)
 {
     Motion = animation;
     Speed  = speed;
 }
Beispiel #18
0
        public static float GetAnimationLength(uint motionTableId, MotionStance style, MotionCommand motion)
        {
            MotionTable mt = ReadFromDat(motionTableId);

            return(mt.GetAnimationLength(style, motion));
        }
Beispiel #19
0
        public static float GetAnimationLength(uint motionTableId, MotionStance stance, MotionCommand currentMotion, MotionCommand motion, float speed = 1.0f)
        {
            var motionTable = DatManager.PortalDat.ReadFromDat <DatLoader.FileTypes.MotionTable>(motionTableId);

            var animLength = 0.0f;

            if (((uint)motion & (uint)CommandMask.Style) != 0 && currentMotion != MotionCommand.Ready)
            {
                animLength   += motionTable.GetAnimationLength(stance, MotionCommand.Ready, currentMotion) / speed;
                currentMotion = MotionCommand.Ready;
            }

            animLength += motionTable.GetAnimationLength(stance, motion, currentMotion) / speed;
            return(animLength);
        }
Beispiel #20
0
 public CommandListElement(MotionCommand command, float speed, bool holdRun)
 {
     Command = command;
     Speed   = speed;
     HoldRun = holdRun;
 }
Beispiel #21
0
        /// <summary>
        /// Method used for the scaling, windup motion, and spell gestures for spell casts
        /// </summary>
        protected static float SpellAttributes(string account, uint spellId, out float castingDelay, out MotionCommand windUpMotion, out MotionCommand spellGesture)
        {
            float scale;

            SpellComponentsTable comps = DatManager.PortalDat.SpellComponentsTable;

            SpellTable spellTable = DatManager.PortalDat.SpellTable;

            if (!spellTable.Spells.ContainsKey(spellId))
            {
                windUpMotion = MotionCommand.Invalid;
                spellGesture = MotionCommand.Invalid;
                castingDelay = 0.0f;
                return(-1.0f);
            }

            SpellBase spell = spellTable.Spells[spellId];

            ////Determine scale of the spell effects and windup animation
            SpellLevel spellLevel = CalculateSpellLevel(spell.Power);

            if (account == null)
            {
                switch (spellLevel)
                {
                case SpellLevel.One:
                    scale = 0.1f;
                    break;

                case SpellLevel.Two:
                    scale = 0.2f;
                    break;

                case SpellLevel.Three:
                    scale = 0.4f;
                    break;

                case SpellLevel.Four:
                    scale = 0.5f;
                    break;

                case SpellLevel.Five:
                    scale = 0.6f;
                    break;

                case SpellLevel.Six:
                    scale = 1.0f;
                    break;

                default:
                    scale = 1.0f;
                    break;
                }

                spellGesture = MotionCommand.Magic;
                windUpMotion = 0;
                castingDelay = 0.0f;
                return(scale);
            }

            switch (spellLevel)
            {
            case SpellLevel.One:
                scale        = 0.1f;
                castingDelay = 1.3f;
                windUpMotion = MotionCommand.MagicPowerUp01;
                break;

            case SpellLevel.Two:
                scale        = 0.2f;
                castingDelay = 1.4f;
                windUpMotion = MotionCommand.MagicPowerUp02;
                break;

            case SpellLevel.Three:
                scale        = 0.4f;
                castingDelay = 1.5f;
                windUpMotion = MotionCommand.MagicPowerUp03;
                break;

            case SpellLevel.Four:
                scale        = 0.5f;
                castingDelay = 1.7f;
                windUpMotion = MotionCommand.MagicPowerUp04;
                break;

            case SpellLevel.Five:
                scale        = 0.6f;
                castingDelay = 1.9f;
                windUpMotion = MotionCommand.MagicPowerUp05;
                break;

            case SpellLevel.Six:
                scale        = 1.0f;
                castingDelay = 2.0f;
                windUpMotion = MotionCommand.MagicPowerUp06;
                break;

            default:
                scale        = 1.0f;
                castingDelay = 2.0f;
                windUpMotion = MotionCommand.MagicPowerUp07Purple;
                break;
            }

            var formula = SpellTable.GetSpellFormula(spellTable, spellId, account);

            spellGesture = (MotionCommand)comps.SpellComponents[formula[formula.Count - 1]].Gesture;

            return(scale);
        }
Beispiel #22
0
        public RawMotionState(MoveToState moveToState, BinaryReader reader)
        {
            MoveToState = moveToState;

            PackedFlags = reader.ReadUInt32();

            // security vulnerability here:
            // untrusted client input sending command list length
            Flags             = (RawMotionFlags)(PackedFlags & 0x7FF);
            CommandListLength = (ushort)(PackedFlags >> 11);

            if ((Flags & RawMotionFlags.CurrentHoldKey) != 0)
            {
                CurrentHoldKey = (HoldKey)reader.ReadUInt32();
            }
            if ((Flags & RawMotionFlags.CurrentStyle) != 0)
            {
                CurrentStyle = (MotionStance)reader.ReadUInt32();
            }
            if ((Flags & RawMotionFlags.ForwardCommand) != 0)
            {
                ForwardCommand = (MotionCommand)reader.ReadUInt32();
            }
            if ((Flags & RawMotionFlags.ForwardHoldKey) != 0)
            {
                ForwardHoldKey = (HoldKey)reader.ReadUInt32();
            }
            if ((Flags & RawMotionFlags.ForwardSpeed) != 0)
            {
                ForwardSpeed = reader.ReadSingle();
            }
            if ((Flags & RawMotionFlags.SideStepCommand) != 0)
            {
                SidestepCommand = (MotionCommand)reader.ReadUInt32();
            }
            if ((Flags & RawMotionFlags.SideStepHoldKey) != 0)
            {
                SidestepHoldKey = (HoldKey)reader.ReadUInt32();
            }
            if ((Flags & RawMotionFlags.SideStepSpeed) != 0)
            {
                SidestepSpeed = reader.ReadSingle();
            }
            if ((Flags & RawMotionFlags.TurnCommand) != 0)
            {
                TurnCommand = (MotionCommand)reader.ReadUInt32();
            }
            if ((Flags & RawMotionFlags.TurnHoldKey) != 0)
            {
                TurnHoldKey = (HoldKey)reader.ReadUInt32();
            }
            if ((Flags & RawMotionFlags.TurnSpeed) != 0)
            {
                TurnSpeed = reader.ReadSingle();
            }

            if (CommandListLength > 0)
            {
                Commands = new List <MotionItem>();
                for (var i = 0; i < CommandListLength; i++)
                {
                    Commands.Add(new MotionItem(moveToState.WorldObject, reader));
                }
            }
        }
Beispiel #23
0
        public static MotionCommand ReduceMultiStrike(this MotionCommand motionCommand)
        {
            if (!motionCommand.IsMultiStrike())
            {
                return(MotionCommand.Invalid);
            }

            switch (motionCommand)
            {
            case MotionCommand.DoubleSlashLow:
            case MotionCommand.TripleSlashLow:
                return(MotionCommand.SlashLow);

            case MotionCommand.DoubleSlashMed:
            case MotionCommand.TripleSlashMed:
                return(MotionCommand.SlashMed);

            case MotionCommand.DoubleSlashHigh:
            case MotionCommand.TripleSlashHigh:
                return(MotionCommand.SlashHigh);

            case MotionCommand.DoubleThrustLow:
            case MotionCommand.TripleThrustLow:
                return(MotionCommand.ThrustLow);

            case MotionCommand.DoubleThrustMed:
            case MotionCommand.TripleThrustMed:
                return(MotionCommand.ThrustMed);

            case MotionCommand.DoubleThrustHigh:
            case MotionCommand.TripleThrustHigh:
                return(MotionCommand.ThrustHigh);

            case MotionCommand.OffhandDoubleSlashLow:
            case MotionCommand.OffhandTripleSlashLow:
                return(MotionCommand.SlashLow);

            case MotionCommand.OffhandDoubleSlashMed:
            case MotionCommand.OffhandTripleSlashMed:
                return(MotionCommand.SlashMed);

            case MotionCommand.OffhandDoubleSlashHigh:
            case MotionCommand.OffhandTripleSlashHigh:
                return(MotionCommand.SlashHigh);

            case MotionCommand.OffhandDoubleThrustLow:
            case MotionCommand.OffhandTripleThrustLow:
                return(MotionCommand.ThrustLow);

            case MotionCommand.OffhandDoubleThrustMed:
            case MotionCommand.OffhandTripleThrustMed:
                return(MotionCommand.ThrustMed);

            case MotionCommand.OffhandDoubleThrustHigh:
            case MotionCommand.OffhandTripleThrustHigh:
                return(MotionCommand.ThrustHigh);

            default:
                return(MotionCommand.Invalid);
            }
        }
 public InterpretedMotionState()
 {
     ForwardCommand = MotionCommand.Ready;
 }
Beispiel #25
0
        private static void HandleHealingRecipe(Player player, WorldObject source, WorldObject target, Recipe recipe)
        {
            ActionChain chain = new ActionChain();

            // skill will be null since the difficulty is calculated manually
            if (recipe.SkillId == null)
            {
                log.Warn($"healing recipe has null skill id (should almost certainly be healing, but who knows).  recipe id {recipe.RecipeGuid}.");
                player.SendUseDoneEvent();
                return;
            }

            if (!(target is Player))
            {
                var message = new GameMessageSystemChat($"The {source.Name} cannot be used on {target.Name}.", ChatMessageType.Craft);
                player.Session.Network.EnqueueSend(message);
                player.SendUseDoneEvent();
                return;
            }

            Player  targetPlayer = (Player)target;
            Ability vital        = (Ability?)recipe.HealingAttribute ?? Ability.Health;

            // there's a skill associated with this
            Skill skillId = (Skill)recipe.SkillId.Value;

            // this shouldn't happen, but sanity check for unexpected nulls
            if (!player.Skills.ContainsKey(skillId))
            {
                log.Warn("Unexpectedly missing skill in Recipe usage");
                player.SendUseDoneEvent();
                return;
            }

            CreatureSkill skill = player.Skills[skillId];

            // at this point, we've validated that the target is a player, and the target is below max health

            if (target.Guid != player.Guid)
            {
                // TODO: validate range
            }

            MotionCommand cmd = MotionCommand.SkillHealSelf;

            if (target.Guid != player.Guid)
            {
                cmd = MotionCommand.Woah; // guess?  nothing else stood out
            }
            // everything pre-validatable is validated.  action will be attempted unless cancelled, so
            // queue up the animation and action
            UniversalMotion motion = new UniversalMotion(MotionStance.Standing, new MotionItem(cmd));

            chain.AddAction(player, () => player.HandleActionMotion(motion));
            chain.AddDelaySeconds(0.5);

            chain.AddAction(player, () =>
            {
                // TODO: revalidate range if other player (they could have moved)

                double difficulty = 2 * (targetPlayer.Vitals[vital].MaxValue - targetPlayer.Vitals[vital].Current);
                if (difficulty <= 0)
                {
                    // target is at max (or higher?) health, do nothing
                    var text = "You are already at full health.";

                    if (target.Guid != player.Guid)
                    {
                        text = $"{target.Name} is already at full health";
                    }

                    player.Session.Network.EnqueueSend(new GameMessageSystemChat(text, ChatMessageType.Craft));
                    player.SendUseDoneEvent();
                    return;
                }

                if (player.CombatMode != CombatMode.NonCombat && player.CombatMode != CombatMode.Undef)
                {
                    difficulty *= 1.1;
                }

                int boost         = source.Boost ?? 0;
                double multiplier = source.HealkitMod ?? 1;

                double playerSkill = skill.ActiveValue + boost;
                if (skill.Status == SkillStatus.Trained)
                {
                    playerSkill *= 1.1;
                }
                else if (skill.Status == SkillStatus.Specialized)
                {
                    playerSkill *= 1.5;
                }

                // usage is inevitable at this point, consume the use
                if ((recipe.ResultFlags & (uint)RecipeResult.SourceItemUsesDecrement) > 0)
                {
                    if (source.Structure <= 1)
                    {
                        player.DestroyInventoryItem(source);
                    }
                    else
                    {
                        source.Structure--;
                        source.SendPartialUpdates(player.Session, _updateStructure);
                    }
                }

                double percentSuccess = CreatureSkill.GetPercentSuccess((uint)playerSkill, (uint)difficulty);

                if (_random.NextDouble() <= percentSuccess)
                {
                    string expertly = "";

                    if (_random.NextDouble() < 0.1d)
                    {
                        expertly    = "expertly ";
                        multiplier *= 1.2;
                    }

                    // calculate amount restored
                    uint maxRestore = targetPlayer.Vitals[vital].MaxValue - targetPlayer.Vitals[vital].Current;

                    // TODO: get actual forumula for healing.  this is COMPLETELY wrong.  this is 60 + random(1-60).
                    double amountRestored = 60d + _random.Next(1, 61);
                    amountRestored       *= multiplier;

                    uint actualRestored = (uint)Math.Min(maxRestore, amountRestored);
                    targetPlayer.Vitals[vital].Current += actualRestored;

                    var updateVital = new GameMessagePrivateUpdateAttribute2ndLevel(player.Session, vital.GetVital(), targetPlayer.Vitals[vital].Current);
                    player.Session.Network.EnqueueSend(updateVital);

                    if (targetPlayer.Guid != player.Guid)
                    {
                        // tell the other player they got healed
                        var updateVitalToTarget = new GameMessagePrivateUpdateAttribute2ndLevel(targetPlayer.Session, vital.GetVital(), targetPlayer.Vitals[vital].Current);
                        targetPlayer.Session.Network.EnqueueSend(updateVitalToTarget);
                    }

                    string name = "yourself";
                    if (targetPlayer.Guid != player.Guid)
                    {
                        name = targetPlayer.Name;
                    }

                    string vitalName = "Health";

                    if (vital == Ability.Stamina)
                    {
                        vitalName = "Stamina";
                    }
                    else if (vital == Ability.Mana)
                    {
                        vitalName = "Mana";
                    }

                    string uses = source.Structure == 1 ? "use" : "uses";

                    var text    = string.Format(recipe.SuccessMessage, expertly, name, actualRestored, vitalName, source.Name, source.Structure, uses);
                    var message = new GameMessageSystemChat(text, ChatMessageType.Craft);
                    player.Session.Network.EnqueueSend(message);

                    if (targetPlayer.Guid != player.Guid)
                    {
                        // send text to the other player too
                        text    = string.Format(recipe.AlternateMessage, player.Name, expertly, actualRestored, vitalName);
                        message = new GameMessageSystemChat(text, ChatMessageType.Craft);
                        targetPlayer.Session.Network.EnqueueSend(message);
                    }
                }

                player.SendUseDoneEvent();
            });

            chain.EnqueueChain();
        }
Beispiel #26
0
    public void Move(MotionCommand motion)
    {
        currentError = null;
        isMoving     = true;
        LinearCommand lin = motion as LinearCommand;

        if (lin != null)
        {
            i = CalculateI(q);
            Position current = CurrentPosition(q);
            currentInterpolation = new LinearInterpolation(
                current,
                lin.target.AsPosition(current),
                lin.velocity * 1000.0f,
                i
                );
        }

        JointCommand jnt = motion as JointCommand;

        if (jnt != null)
        {
            try
            {
                float[] target = jnt.target.AsArray(q);
                VerifySolution(target);

                currentInterpolation = new JointInterpolation(
                    q,
                    jnt.target.AsArray(q),
                    jnt.velocity
                    );
            }
            catch (Exception ex)
            {
                currentError      = ex.Message;
                finishedWithError = true;
            }
        }

        PtpCommand ptp = motion as PtpCommand;

        if (ptp != null)
        {
            try
            {
                i = CalculateI(q);
                float[] sol = Solve(ptp.target.AsPosition(
                                        CurrentPosition(q)),
                                    ptp.target.i0(i[0]),
                                    ptp.target.i1(i[1]),
                                    ptp.target.i2(i[2])
                                    ).AsArray();
                currentInterpolation = new JointInterpolation(
                    q,
                    sol,
                    ptp.velocity
                    );
            }
            catch (Exception ex)
            {
                currentError      = ex.Message;
                finishedWithError = true;
            }
        }
    }
Beispiel #27
0
 public Motion(MotionStance stance, MotionCommand motion, float speed = 1.0f)
 {
     Stance = stance;
     SetForwardCommand(motion, speed);
 }
Beispiel #28
0
 public AttackFrameParams(uint motionTableId, MotionStance stance, MotionCommand motion)
 {
     MotionTableId = motionTableId;
     Stance        = stance;
     Motion        = motion;
 }
Beispiel #29
0
 public void SetForwardCommand(MotionCommand motion, float speed = 1.0f)
 {
     MotionState.ForwardCommand = motion;
     MotionState.ForwardSpeed   = speed;
 }
Beispiel #30
0
        public float GetAnimationLength(MotionCommand currentMotionState, MotionStance style, MotionCommand motion)
        {
            float length = 0; // init our length var...will return as 0 if not found

            uint motionHash = ((uint)currentMotionState & 0xFFFFFF) | ((uint)style << 16);

            if (Links.ContainsKey(motionHash))
            {
                Dictionary <uint, MotionData> links = Links[motionHash];

                if (links.ContainsKey((uint)motion))
                {
                    // loop through all that animations to get our total count
                    for (int i = 0; i < links[(uint)motion].Anims.Count; i++)
                    {
                        AnimData anim = links[(uint)motion].Anims[i];

                        uint numFrames;

                        // check if the animation is set to play the whole thing, in which case we need to get the numbers of frames in the raw animation
                        if ((anim.LowFrame == -1) && (anim.HighFrame == 0))
                        {
                            var animation = DatManager.PortalDat.ReadFromDat <Animation>(anim.AnimId);
                            numFrames = animation.NumFrames;
                        }
                        else
                        {
                            numFrames = (uint)(anim.HighFrame - anim.LowFrame);
                        }

                        length += numFrames / Math.Abs(anim.Framerate); // Framerates can be negative, which tells the client to play in reverse
                    }
                }
            }

            return(length);
        }
Beispiel #31
0
 public MotionItem(MotionCommand animation)
 {
     Motion = animation;
     Speed  = 1.0f;
 }
Beispiel #32
0
        public void HandleKeyboardCommand(CmdStruct cmdStruct, MotionCommand command)
        {
            // vfptr[12] - IsActive
            if (!IsActive())
            {
                return;
            }

            bool start;

            if (cmdStruct.Command == MotionCommand.AutoRun)
            {
                start = Convert.ToBoolean(cmdStruct.Args[cmdStruct.Curr]);
                cmdStruct.Curr++;
                if (cmdStruct.Curr >= cmdStruct.Size)
                {
                    AutoRunSpeed = 1.0f;
                }
                else
                {
                    AutoRunSpeed = BitConverter.ToSingle(BitConverter.GetBytes(cmdStruct.Args[cmdStruct.Curr]));
                    cmdStruct.Curr++;
                }
                // vfptr[16].OnLoseFocus - ToggleAutoRun
                ToggleAutoRun();
                // vfptr[6].OnAction - SendMovementEvent
                SendMovementEvent();
                return;
            }

            if (((uint)cmdStruct.Command & (uint)CommandMask.UI) != 0)
            {
                return;
            }

            start = Convert.ToBoolean(cmdStruct.Args[cmdStruct.Curr]);
            cmdStruct.Curr++;

            var speed = 1.0f;

            if (cmdStruct.Curr < cmdStruct.Size)
            {
                speed = BitConverter.ToSingle(BitConverter.GetBytes(cmdStruct.Args[cmdStruct.Curr]));
                cmdStruct.Curr++;
            }

            if (ControlledByServer && !start)
            {
                // vfptr[1].OnLoseFocus - MovePlayer?
                MovePlayer((MotionCommand)cmdStruct.Command, start, speed, false, false);
                return;
            }

            // vfptr[8].OnLoseFocus(a2) - ACCmdInterp::TakeControlFromServer?
            TakeControlFromServer();

            if (cmdStruct.Command == MotionCommand.HoldRun‬)
            {
                // vfptr[2].OnLoseFocus

                if (!IsStandingStill())
                {
                    SendMovementEvent();
                }

                return;
            }

            if (cmdStruct.Command == MotionCommand.HoldSidestep)
            {
                // vfptr[3]

                if (!IsStandingStill())
                {
                    SendMovementEvent();
                }

                return;
            }

            // vfptr[2] - Bookkeep
            if (!BookkeepCommandAndModifyIfNecessary(cmdStruct.Command, start, speed, false, false))
            {
                SendMovementEvent();
                return;
            }

            // vfptr[4].OnAction - ApplyHoldKeysToCommand
            ApplyHoldKeysToCommand(ref cmdStruct.Command, speed);

            // vfptr[13].OnAction - MovePlayer
            MovePlayer(cmdStruct.Command, start, speed, false, false);

            // vfptr[6].OnAction - SendMovementEvent
            if (cmdStruct.Command != MotionCommand.Jump)
            {
                SendMovementEvent();
            }
        }