Beispiel #1
0
        /// <summary>
        ///     Plays the draw animation and activates fight mode
        /// </summary>
        public void DoDrawFists()
        {
            ScriptAniJob drawAniJob;

            if (Movement == NPCMovement.Stand && !Environment.InAir && Environment.WaterLevel < 0.4f)
            {
                drawAniJob = AniCatalog.DrawFists.Draw;
            }
            else
            {
                drawAniJob = AniCatalog.DrawFists.DrawWhileRunning;
            }

            if (drawAniJob == null)
            {
                return;
            }

            if (!ModelInst.TryGetAniFromJob(drawAniJob, out ScriptAni ani))
            {
                return;
            }

            if (!ani.TryGetSpecialFrame(0, out float drawFrame))
            {
                drawFrame = float.MaxValue;
            }

            ModelInst.StartAniJob(drawAniJob, new FrameActionPair(drawFrame, () => SetFightMode(true)));
        }
Beispiel #2
0
        private void CheckUnconsciousness()
        {
            if (!IsUnconscious || Environment.InAir)
            {
                return;
            }

            var cat     = AniCatalog.Unconscious;
            var dropJob = _Uncon == Unconsciousness.Front ? cat.DropFront : cat.DropBack;

            if (dropJob == null)
            {
                return;
            }

            var aa = ModelInst.GetActiveAniFromLayer(1);

            if (aa != null)
            {
                var job = (ScriptAniJob)aa.AniJob.ScriptObject;
                if (job == dropJob || job == dropJob.NextAni)
                {
                    return;
                }

                var standJob = _Uncon == Unconsciousness.Front ? cat.StandUpFront : cat.StandUpBack;
                if (standJob != null && standJob == job)
                {
                    return;
                }
            }

            ModelInst.StartAniJob(dropJob);
        }
Beispiel #3
0
        public void DropUnconscious(long duration = -1, bool toFront = true)
        {
            var          cat = AniCatalog.Unconscious;
            ScriptAniJob job = toFront ? cat.DropFront : cat.DropBack;

            if (job != null)
            {
                ModelInst.StartAniJob(job);
            }

            _Uncon = toFront ? Unconsciousness.Front : Unconsciousness.Back;

            var strm = BaseInst.GetScriptVobStream();

            strm.Write((byte)ScriptVobMessageIDs.Uncon);
            strm.Write((byte)_Uncon);
            BaseInst.SendScriptVobStream(strm);

            if (duration >= 0)
            {
                if (unconTimer == null)
                {
                    unconTimer = new GUCTimer(LiftUnconsciousness);
                }

                unconTimer.SetInterval(duration);
                unconTimer.Start();
            }

            OnUnconChange?.Invoke(this);
        }
Beispiel #4
0
        public void DoUndrawWeapon(ItemInst item)
        {
            NPCCatalog.DrawWeaponAnis catalog;
            switch (item.ItemType)
            {
            default:
            case ItemTypes.Wep1H:
                catalog = AniCatalog.Draw1H;
                break;

            case ItemTypes.Wep2H:
                catalog = AniCatalog.Draw2H;
                break;

            case ItemTypes.WepBow:
                catalog = AniCatalog.DrawBow;
                break;

            case ItemTypes.WepXBow:
                catalog = AniCatalog.DrawXBow;
                break;

            case ItemTypes.Rune:
            case ItemTypes.Scroll:
                catalog = AniCatalog.DrawMagic;
                break;
            }

            if (GetDrawnWeapon() == null)
            {
            }
            else
            {
                ScriptAniJob job = Movement == NPCMovement.Stand && !Environment.InAir
                    ? catalog.Undraw
                    : catalog.UndrawWhileRunning;
                if (job == null || !ModelInst.TryGetAniFromJob(job, out ScriptAni ani)) // no animation
                {
                    UndrawWeapon(item);
                }
                else
                {
                    if (!ani.TryGetSpecialFrame(SpecialFrame.Draw, out float drawFrame))
                    {
                        drawFrame = 0;
                    }

                    ModelInst.StartAniJob(job, new FrameActionPair(drawFrame, () => UndrawWeapon(item)));
                }
            }
        }
Beispiel #5
0
        public void DoUnaim()
        {
            var          drawnWeapon = GetDrawnWeapon();
            ScriptAniJob job         = drawnWeapon != null && drawnWeapon.ItemType == ItemTypes.WepXBow
                ? AniCatalog.FightXBow.Unaim
                : AniCatalog.FightBow.Unaim;

            if (job == null || !ModelInst.TryGetAniFromJob(job, out ScriptAni ani))
            {
            }
            else
            {
                ModelInst.StartAniJob(job);
            }
        }
Beispiel #6
0
        public void DoTakeItem(ItemInst item)
        {
            ScriptAniJob job = AniCatalog?.ItemHandling.TakeItem;

            if (job != null && ModelInst.TryGetAniFromJob(job, out ScriptAni ani))
            {
                if (!ani.TryGetSpecialFrame(SpecialFrame.ItemHandle, out float frame))
                {
                    frame = float.MaxValue;
                }

                var pair = new FrameActionPair(frame, () => TakeItem(item));
                ModelInst.StartAniJob(job, 0.8f, 0, pair);
                return;
            }

            TakeItem(item);
        }
Beispiel #7
0
        private void DoAttack(ScriptAniJob job, FightMoves move, int fwdCombo = 0)
        {
            if (job == null)
            {
                return;
            }

            if (!ModelInst.TryGetAniFromJob(job, out ScriptAni ani))
            {
                return;
            }

            // combo window
            if (!ani.TryGetSpecialFrame(SpecialFrame.Combo, out float comboFrame))
            {
                comboFrame = ani.EndFrame;
            }

            var comboPair = new FrameActionPair(comboFrame, () => OpenCombo());

            // hit frame
            if (!ani.TryGetSpecialFrame(SpecialFrame.Hit, out float hitFrame))
            {
                hitFrame = comboFrame;
            }

            if (hitFrame > comboFrame)
            {
                hitFrame = comboFrame;
            }

            var hitPair = new FrameActionPair(hitFrame, () => CalcHit());

            // end of animation
            var endPair = FrameActionPair.OnEnd(() => EndFightAni());

            // start ani first, because the OnEnd-Callback from the former attack resets the fight stance
            FightAnimation   = ModelInst.StartAniJob(job, comboPair, hitPair, endPair);
            CurrentFightMove = move;
            CanCombo         = false;
            ComboNum         = fwdCombo;
        }
Beispiel #8
0
        private void DoDodge(ScriptAniJob job)
        {
            if (job == null)
            {
                return;
            }

            if (!ModelInst.TryGetAniFromJob(job, out ScriptAni ani))
            {
                return;
            }

            // end of animation
            var endPair = FrameActionPair.OnEnd(() => EndFightAni());

            FightAnimation   = ModelInst.StartAniJob(job, endPair);
            CurrentFightMove = FightMoves.Dodge;
            CanCombo         = false;
            ComboNum         = 0;
        }
Beispiel #9
0
        public void DoDropItem(ItemInst item, int amount, Vec3f position, Angles angles)
        {
            item = item.Split(amount);

            ScriptAniJob job = AniCatalog?.ItemHandling.DropItem;

            if (job != null && ModelInst.TryGetAniFromJob(job, out ScriptAni ani))
            {
                if (!ani.TryGetSpecialFrame(SpecialFrame.ItemHandle, out float frame))
                {
                    frame = float.MaxValue;
                }

                var pair = new FrameActionPair(frame, () => DropItem(item, position, angles));
                ModelInst.StartAniJob(job, 0.8f, 0, pair);
                return;
            }

            DropItem(item, position, angles);
        }
Beispiel #10
0
        public void DoClimb(ClimbMoves move, NPC.ClimbingLedge ledge)
        {
            ScriptAniJob job;

            switch (move)
            {
            case ClimbMoves.High:
                job = AniCatalog.Climbs.High;
                break;

            case ClimbMoves.Mid:
                job = AniCatalog.Climbs.Mid;
                break;

            case ClimbMoves.Low:
                job = AniCatalog.Climbs.Low;
                break;

            default:
                Logger.Log("Not existing climb move: " + move);
                return;
            }

            if (job == null)
            {
                return;
            }


            var stream = BaseInst.GetScriptVobStream();

            stream.Write((byte)ScriptVobMessageIDs.Climb);
            ledge.WriteStream(stream);
            BaseInst.SendScriptVobStream(stream);

            IsClimbing = true;
            ModelInst.StartAniJob(job, () => IsClimbing = false);
        }
Beispiel #11
0
        public void UseItem(ItemInst item)
        {
            if (item.ItemType != ItemTypes.Drinkable)
            {
                return;
            }

            ScriptAniJob job = AniCatalog?.ItemHandling.DrinkPotion;

            if (job != null && ModelInst.TryGetAniFromJob(job, out ScriptAni ani))
            {
                if (!ani.TryGetSpecialFrame(SpecialFrame.ItemHandle, out float frame))
                {
                    frame = float.MaxValue;
                }

                EquipItem(NPCSlots.RightHand, item);
                var pair = new FrameActionPair(frame, () => ChugPotion(item));
                ModelInst.StartAniJob(job, pair);
                return;
            }

            ChugPotion(item);
        }
Beispiel #12
0
        public void LiftUnconsciousness()
        {
            if (!IsUnconscious)
            {
                return;
            }

            var          cat = AniCatalog.Unconscious;
            ScriptAniJob job = _Uncon == Unconsciousness.Front ? cat.StandUpFront : cat.StandUpBack;

            if (job != null)
            {
                ModelInst.StartAniJob(job, DoLiftUncon);
            }
            else
            {
                DoLiftUncon();
            }

            if (unconTimer != null && unconTimer.Started)
            {
                unconTimer.Stop();
            }
        }
Beispiel #13
0
        public void DoShoot(Vec3f start, Vec3f end, ProjInst proj)
        {
            proj.Destination = end;
            proj.Shooter     = this;

            Angles rotation = Angles.FromAtVector(end - start);
            var    p        = rotation.Pitch; // rotate arrow correctly

            rotation.Pitch = rotation.Roll;
            rotation.Yaw  -= Angles.PI / 2;
            rotation.Roll  = p;

            proj.Spawn(World, start, rotation);

            var          drawnWeapon = GetDrawnWeapon();
            ScriptAniJob job         = drawnWeapon != null && drawnWeapon.ItemType == ItemTypes.WepXBow
                ? AniCatalog.FightXBow.Reload
                : AniCatalog.FightBow.Reload;

            if (job != null && ModelInst.TryGetAniFromJob(job, out ScriptAni ani))
            {
                ModelInst.StartAniJob(job);
            }
        }
Beispiel #14
0
        public void DoDrawWeapon(ItemInst item)
        {
            NPCCatalog.DrawWeaponAnis catalog;
            switch (item.ItemType)
            {
            default:
            case ItemTypes.Wep1H:
                catalog = AniCatalog.Draw1H;
                break;

            case ItemTypes.Wep2H:
                catalog = AniCatalog.Draw2H;
                break;

            case ItemTypes.WepBow:
                catalog = AniCatalog.DrawBow;
                break;

            case ItemTypes.WepXBow:
                catalog = AniCatalog.DrawXBow;
                break;

            case ItemTypes.Rune:
            case ItemTypes.Scroll:
                catalog = AniCatalog.DrawMagic;
                break;
            }

            if (IsInFightMode || GetDrawnWeapon() != null)
            {
                /*if (this.DrawnWeapon != null)
                 * {
                 *  ItemInst weapon = this.DrawnWeapon;
                 *  catalog = GetDrawWeaponCatalog(weapon.ItemType);
                 *  // weapon draw while running or when standing
                 *  if (this.Movement == NPCMovement.Forward || this.Movement == NPCMovement.Left || this.Movement == NPCMovement.Right)
                 *  {
                 *      this.ModelInst.StartAniJob(catalog.UndrawWhileRunning, 0.1f, () =>
                 *      {
                 *          this.UnequipItem(weapon); // take weapon from hand
                 *          this.EquipItem(weapon); // place weapon into parking slot
                 *      });
                 *  }
                 *  else
                 *  {
                 *      this.ModelInst.StartAniJob(catalog.Undraw, 0.1f, () =>
                 *      {
                 *          this.UnequipItem(weapon); // take weapon from hand
                 *          this.EquipItem(weapon); // place weapon into parking slot
                 *      });
                 *  }
                 * }
                 * this.SetFightMode(false);*/
            }
            else
            {
                ScriptAniJob job = Movement == NPCMovement.Stand && !Environment.InAir
                    ? catalog.Draw
                    : catalog.DrawWhileRunning;
                if (job == null || !ModelInst.TryGetAniFromJob(job, out ScriptAni ani)) // no animation
                {
                    DrawWeapon(item);
                }
                else
                {
                    if (!ani.TryGetSpecialFrame(SpecialFrame.Draw, out float drawFrame))
                    {
                        drawFrame = 0;
                    }

                    ModelInst.StartAniJob(job, new FrameActionPair(drawFrame, () => DrawWeapon(item)));
                }
            }
        }