Updates Combat Packets & Moves Tracking to Content (#298)

- [X] Changes outgoing combat packets
- [X] Moves quest arrow to PlayerMobile and moves quest arrow packets to content.

Bumps release version
This commit is contained in:
Kamron Batman 2020-11-01 21:33:01 -08:00 committed by GitHub
parent 55935d30b4
commit 6f5cb00cdd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 373 additions and 319 deletions

View file

@ -744,10 +744,7 @@ namespace Server.Items
{
attacker.DisruptiveAction();
if (attacker.NetState != null)
{
attacker.Send(new Swing(attacker.Serial, defender.Serial));
}
attacker.NetState?.SendSwing(attacker.Serial, defender.Serial);
if (attacker is BaseCreature bc)
{

View file

@ -60,8 +60,7 @@ namespace Server.Items
// WeaponAbility a = WeaponAbility.GetCurrentAbility( attacker );
// Make sure we've been standing still for .25/.5/1 second depending on Era
if (Core.TickCount - attacker.LastMoveTime >= (Core.SE ? 250 :
Core.AOS ? 500 : 1000) ||
if (Core.TickCount - attacker.LastMoveTime >= (Core.SE ? 250 : Core.AOS ? 500 : 1000) ||
Core.AOS && WeaponAbility.GetCurrentAbility(attacker) is MovingShot)
{
var canSwing = true;
@ -84,7 +83,7 @@ namespace Server.Items
if (canSwing && attacker.HarmfulCheck(defender))
{
attacker.DisruptiveAction();
attacker.Send(new Swing(attacker.Serial, defender.Serial));
attacker.NetState?.SendSwing(attacker.Serial, defender.Serial);
if (OnFired(attacker, defender))
{

View file

@ -196,14 +196,16 @@ namespace Server.Mobiles
private bool m_NoDeltaRecursion;
private int
m_NonAutoreinsuredItems; // number of items that could not be automatically reinsured because gold in bank was not enough
// number of items that could not be automatically reinsured because gold in bank was not enough
private int m_NonAutoreinsuredItems;
private DateTime m_SavagePaintExpiration;
private TimeSpan m_ShortTermElapse;
private DateTime[] m_StuckMenuUses;
private QuestArrow m_QuestArrow;
public PlayerMobile()
{
AutoStabled = new List<Mobile>();
@ -794,6 +796,23 @@ namespace Server.Mobiles
public HonorContext ReceivedHonorContext { get; set; }
public QuestArrow QuestArrow
{
get => m_QuestArrow;
set
{
if (m_QuestArrow != value)
{
m_QuestArrow?.Stop();
m_QuestArrow = value;
}
}
}
public void ClearQuestArrow() => m_QuestArrow = null;
public override void ToggleFlying()
{
if (Race != Race.Gargoyle)
@ -1627,6 +1646,7 @@ namespace Server.Mobiles
pm.Quest?.StopTimer();
pm.SpeechLog = null;
pm.ClearQuestArrow();
pm.LastOnline = DateTime.UtcNow;
}

View file

@ -0,0 +1,61 @@
/*************************************************************************
* ModernUO *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: OutgoingArrowPackets.cs *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
using System.Buffers;
using System.Runtime.CompilerServices;
namespace Server.Network
{
public static class OutgoingArrowPackets
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SendCancelArrow(this NetState ns, int x, int y, Serial s) => ns.SendArrow(0, x, y, s);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SendSetArrow(this NetState ns, int x, int y, Serial s) => ns.SendArrow(1, x, y, s);
public static void SendArrow(this NetState ns, byte command, int x, int y, Serial s)
{
if (ns == null || !ns.GetSendBuffer(out var buffer))
{
return;
}
var writer = new CircularBufferWriter(buffer);
writer.Write((byte)0xBA); // Packet ID
writer.Write(command);
if (ns.HighSeas)
{
writer.Write((short)x);
writer.Write((short)y);
writer.Write(s);
}
else if (command == 1)
{
writer.Write((short)x);
writer.Write((short)y);
}
else
{
writer.Write((short)-1);
writer.Write((short)-1);
}
ns.Send(ref buffer, writer.Position);
}
}
}

View file

@ -0,0 +1,68 @@
using Server.Mobiles;
using Server.Network;
namespace Server
{
public class QuestArrow
{
public QuestArrow(PlayerMobile m, Mobile t)
{
Running = true;
Mobile = m;
Target = t;
}
public QuestArrow(PlayerMobile m, Mobile t, int x, int y) : this(m, t)
{
Update(x, y);
}
public PlayerMobile Mobile { get; }
public Mobile Target { get; }
public bool Running { get; private set; }
public void Update()
{
Update(Target.X, Target.Y);
}
public void Update(int x, int y)
{
if (!Running)
{
return;
}
Mobile.NetState?.SendSetArrow(x, y, Target.Serial);
}
public void Stop()
{
Stop(Target.X, Target.Y);
}
public void Stop(int x, int y)
{
if (!Running)
{
return;
}
Mobile.ClearQuestArrow();
Mobile.NetState?.SendCancelArrow(x, y, Target.Serial);
Running = false;
OnStop();
}
public virtual void OnStop()
{
}
public virtual void OnClick(bool rightClick)
{
}
}
}

View file

@ -0,0 +1,41 @@
using Server.Mobiles;
namespace Server.SkillHandlers
{
public class TrackArrow : QuestArrow
{
private readonly Timer m_Timer;
private Mobile m_From;
public TrackArrow(PlayerMobile from, Mobile target, int range) : base(from, target)
{
m_From = from;
m_Timer = new TrackTimer(from, target, range, this);
m_Timer.Start();
}
public override void OnClick(bool rightClick)
{
if (rightClick)
{
Tracking.ClearTrackingInfo(m_From);
m_From = null;
Stop();
}
}
public override void OnStop()
{
m_Timer.Stop();
if (m_From != null)
{
Tracking.ClearTrackingInfo(m_From);
m_From.SendLocalizedMessage(503177); // You have lost your quarry.
}
}
}
}

View file

@ -0,0 +1,50 @@
using System;
namespace Server.SkillHandlers
{
public class TrackTimer : Timer
{
private readonly QuestArrow m_Arrow;
private readonly Mobile m_From;
private readonly int m_Range;
private readonly Mobile m_Target;
private int m_LastX, m_LastY;
public TrackTimer(Mobile from, Mobile target, int range, QuestArrow arrow) : base(
TimeSpan.FromSeconds(0.25),
TimeSpan.FromSeconds(2.5)
)
{
m_From = from;
m_Target = target;
m_Range = range;
m_Arrow = arrow;
}
protected override void OnTick()
{
if (!m_Arrow.Running)
{
Stop();
return;
}
if (m_From.NetState == null || m_From.Deleted || m_Target.Deleted || m_From.Map != m_Target.Map ||
!m_From.InRange(m_Target, m_Range) || m_Target.Hidden && m_Target.AccessLevel > m_From.AccessLevel)
{
m_Arrow.Stop();
Stop();
return;
}
if (m_LastX != m_Target.X || m_LastY != m_Target.Y)
{
m_LastX = m_Target.X;
m_LastY = m_Target.Y;
m_Arrow.Update();
}
}
}
}

View file

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Server.Gumps;
using Server.Mobiles;
using Server.Network;
using Server.Spells;
using Server.Spells.Necromancy;
@ -12,18 +13,32 @@ namespace Server.SkillHandlers
{
private static readonly Dictionary<Mobile, TrackingInfo> m_Table = new Dictionary<Mobile, TrackingInfo>();
public static void Initialize()
public static void Configure()
{
IncomingExtendedCommandPackets.RegisterExtended(0x07, true, QuestArrow);
SkillInfo.Table[(int)SkillName.Tracking].Callback = OnUse;
}
public static void QuestArrow(NetState state, CircularBufferReader reader)
{
if (state.Mobile is PlayerMobile from)
{
var rightClick = reader.ReadBoolean();
from.QuestArrow?.OnClick(rightClick);
}
}
public static TimeSpan OnUse(Mobile m)
{
m.SendLocalizedMessage(1011350); // What do you wish to track?
if (m is PlayerMobile pm)
{
m.SendLocalizedMessage(1011350); // What do you wish to track?
m.CloseGump<TrackWhatGump>();
m.CloseGump<TrackWhoGump>();
m.SendGump(new TrackWhatGump(m));
m.CloseGump<TrackWhatGump>();
m.CloseGump<TrackWhoGump>();
m.SendGump(new TrackWhatGump(pm));
}
return TimeSpan.FromSeconds(10.0); // 10 second delay before being able to re-use a skill
}
@ -73,10 +88,10 @@ namespace Server.SkillHandlers
public class TrackWhatGump : Gump
{
private readonly Mobile m_From;
private readonly PlayerMobile m_From;
private readonly bool m_Success;
public TrackWhatGump(Mobile from) : base(20, 30)
public TrackWhatGump(PlayerMobile from) : base(20, 30)
{
m_From = from;
m_Success = from.CheckSkill(SkillName.Tracking, 0.0, 21.1);
@ -126,12 +141,12 @@ namespace Server.SkillHandlers
IsPlayer
};
private readonly Mobile m_From;
private readonly PlayerMobile m_From;
private readonly List<Mobile> m_List;
private readonly int m_Range;
private TrackWhoGump(Mobile from, List<Mobile> list, int range) : base(20, 30)
private TrackWhoGump(PlayerMobile from, List<Mobile> list, int range) : base(20, 30)
{
m_From = from;
m_List = list;
@ -174,7 +189,7 @@ namespace Server.SkillHandlers
}
}
public static void DisplayTo(bool success, Mobile from, int type)
public static void DisplayTo(bool success, PlayerMobile from, int type)
{
if (!success)
{
@ -333,87 +348,4 @@ namespace Server.SkillHandlers
}
}
}
public class TrackArrow : QuestArrow
{
private readonly Timer m_Timer;
private Mobile m_From;
public TrackArrow(Mobile from, Mobile target, int range) : base(from, target)
{
m_From = from;
m_Timer = new TrackTimer(from, target, range, this);
m_Timer.Start();
}
public override void OnClick(bool rightClick)
{
if (rightClick)
{
Tracking.ClearTrackingInfo(m_From);
m_From = null;
Stop();
}
}
public override void OnStop()
{
m_Timer.Stop();
if (m_From != null)
{
Tracking.ClearTrackingInfo(m_From);
m_From.SendLocalizedMessage(503177); // You have lost your quarry.
}
}
}
public class TrackTimer : Timer
{
private readonly QuestArrow m_Arrow;
private readonly Mobile m_From;
private readonly int m_Range;
private readonly Mobile m_Target;
private int m_LastX, m_LastY;
public TrackTimer(Mobile from, Mobile target, int range, QuestArrow arrow) : base(
TimeSpan.FromSeconds(0.25),
TimeSpan.FromSeconds(2.5)
)
{
m_From = from;
m_Target = target;
m_Range = range;
m_Arrow = arrow;
}
protected override void OnTick()
{
if (!m_Arrow.Running)
{
Stop();
return;
}
if (m_From.NetState == null || m_From.Deleted || m_Target.Deleted || m_From.Map != m_Target.Map ||
!m_From.InRange(m_Target, m_Range) || m_Target.Hidden && m_Target.AccessLevel > m_From.AccessLevel)
{
m_Arrow.Stop();
Stop();
return;
}
if (m_LastX != m_Target.X || m_LastY != m_Target.Y)
{
m_LastX = m_Target.X;
m_LastY = m_Target.Y;
m_Arrow.Update();
}
}
}
}