Code cleanup (#188)
This commit is contained in:
parent
df53c16620
commit
010fd9402a
185 changed files with 1052 additions and 1271 deletions
|
|
@ -40,7 +40,7 @@ namespace Server.Diagnostics
|
|||
|
||||
public long Count { get; private set; }
|
||||
|
||||
public TimeSpan AverageTime => TimeSpan.FromTicks(TotalTime.Ticks / Math.Max(1, Count));
|
||||
public TimeSpan AverageTime => TimeSpan.FromTicks(TotalTime.Ticks / Math.Max(Count, 1));
|
||||
|
||||
public TimeSpan PeakTime { get; private set; }
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ namespace Server.Diagnostics
|
|||
|
||||
public long TotalLength { get; private set; }
|
||||
|
||||
public double AverageLength => (double)TotalLength / Math.Max(1, Count);
|
||||
public double AverageLength => (double)TotalLength / Math.Max(Count, 1);
|
||||
|
||||
public void Finish(long length)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -39,10 +39,10 @@ namespace Server.Guilds
|
|||
|
||||
protected BaseGuild(uint id) // serialization ctor
|
||||
{
|
||||
this.Serial = id;
|
||||
List.Add(this.Serial, this);
|
||||
if (this.Serial + 1 > m_NextID)
|
||||
m_NextID = this.Serial + 1;
|
||||
Serial = id;
|
||||
List.Add(Serial, this);
|
||||
if (Serial + 1 > m_NextID)
|
||||
m_NextID = Serial + 1;
|
||||
m_SaveBuffer = new BufferWriter(true);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ namespace Server
|
|||
int MaxRange { get; }
|
||||
void OnBeforeSwing(Mobile attacker, Mobile defender);
|
||||
TimeSpan OnSwing(Mobile attacker, Mobile defender);
|
||||
TimeSpan OnSwing(Mobile attacker, Mobile defender, double damageBonus);
|
||||
void GetStatusDamage(Mobile from, out int min, out int max);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2550,7 +2550,7 @@ namespace Server
|
|||
}
|
||||
|
||||
if (HeldBy != null)
|
||||
Timer.DelayCall(TimeSpan.Zero, FixHolding_Sandbox);
|
||||
Timer.DelayCall(FixHolding_Sandbox);
|
||||
|
||||
// if (version < 9)
|
||||
VerifyCompactInfo();
|
||||
|
|
@ -3070,18 +3070,12 @@ namespace Server
|
|||
if (checkTop == checkZ && !id.Surface)
|
||||
++checkTop;
|
||||
|
||||
var zStart = checkZ - z;
|
||||
var zEnd = checkTop - z;
|
||||
var zStart = Math.Max(checkZ - z, 0);
|
||||
var zEnd = Math.Min(checkTop - z, 19);
|
||||
|
||||
if (zStart >= 20 || zEnd < 0)
|
||||
continue;
|
||||
|
||||
if (zStart < 0)
|
||||
zStart = 0;
|
||||
|
||||
if (zEnd > 19)
|
||||
zEnd = 19;
|
||||
|
||||
var bitCount = zEnd - zStart;
|
||||
|
||||
m_OpenSlots &= ~(((1 << bitCount) - 1) << zStart);
|
||||
|
|
@ -3098,18 +3092,12 @@ namespace Server
|
|||
if (checkTop == checkZ && !id.Surface)
|
||||
++checkTop;
|
||||
|
||||
var zStart = checkZ - z;
|
||||
var zEnd = checkTop - z;
|
||||
var zStart = Math.Max(checkZ - z, 0);
|
||||
var zEnd = Math.Min(checkTop - z, 19);
|
||||
|
||||
if (zStart >= 20 || zEnd < 0)
|
||||
continue;
|
||||
|
||||
if (zStart < 0)
|
||||
zStart = 0;
|
||||
|
||||
if (zEnd > 19)
|
||||
zEnd = 19;
|
||||
|
||||
var bitCount = zEnd - zStart;
|
||||
|
||||
m_OpenSlots &= ~(((1 << bitCount) - 1) << zStart);
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
|
|
|||
|
|
@ -655,34 +655,14 @@ namespace Server
|
|||
|
||||
public void Bound(int x, int y, out int newX, out int newY)
|
||||
{
|
||||
if (x < 0)
|
||||
newX = 0;
|
||||
else if (x >= Width)
|
||||
newX = Width - 1;
|
||||
else
|
||||
newX = x;
|
||||
|
||||
if (y < 0)
|
||||
newY = 0;
|
||||
else if (y >= Height)
|
||||
newY = Height - 1;
|
||||
else
|
||||
newY = y;
|
||||
newX = Math.Clamp(x, 0, Width - 1);
|
||||
newY = Math.Clamp(y, 0, Height - 1);
|
||||
}
|
||||
|
||||
public Point2D Bound(Point2D p)
|
||||
{
|
||||
int x = p.m_X, y = p.m_Y;
|
||||
|
||||
if (x < 0)
|
||||
x = 0;
|
||||
else if (x >= Width)
|
||||
x = Width - 1;
|
||||
|
||||
if (y < 0)
|
||||
y = 0;
|
||||
else if (y >= Height)
|
||||
y = Height - 1;
|
||||
int x = Math.Clamp(p.m_X, 0, Width - 1);
|
||||
int y = Math.Clamp(p.m_Y, 0, Height - 1);
|
||||
|
||||
return new Point2D(x, y);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1486,7 +1486,7 @@ namespace Server
|
|||
AddToBackpack(item.Items[j]);
|
||||
}
|
||||
|
||||
Timer.DelayCall(TimeSpan.Zero, item.Delete);
|
||||
Timer.DelayCall(item.Delete);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1811,10 +1811,7 @@ namespace Server
|
|||
|
||||
if (m_Kills != value)
|
||||
{
|
||||
m_Kills = value;
|
||||
|
||||
if (m_Kills < 0)
|
||||
m_Kills = 0;
|
||||
m_Kills = Math.Max(value, 0);
|
||||
|
||||
if (oldValue >= 5 != m_Kills >= 5)
|
||||
{
|
||||
|
|
@ -1834,12 +1831,7 @@ namespace Server
|
|||
set
|
||||
{
|
||||
if (m_ShortTermMurders != value)
|
||||
{
|
||||
m_ShortTermMurders = value;
|
||||
|
||||
if (m_ShortTermMurders < 0)
|
||||
m_ShortTermMurders = 0;
|
||||
}
|
||||
m_ShortTermMurders = Math.Max(value, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -5250,9 +5242,8 @@ namespace Server
|
|||
|
||||
OnDamage(amount, from, newHits < 0);
|
||||
|
||||
var m = Mount;
|
||||
if (m != null && informMount)
|
||||
m.OnRiderDamaged(amount, from, newHits < 0);
|
||||
if (informMount)
|
||||
Mount?.OnRiderDamaged(amount, from, newHits < 0);
|
||||
|
||||
if (newHits < 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -501,8 +501,7 @@ namespace Server.Network
|
|||
var vendor = World.FindMobile(pvSrc.ReadUInt32());
|
||||
var flag = pvSrc.ReadByte();
|
||||
|
||||
if (vendor == null)
|
||||
return;
|
||||
if (vendor == null) return;
|
||||
|
||||
if (vendor.Deleted || !Utility.RangeCheck(vendor.Location, state.Mobile.Location, 10))
|
||||
{
|
||||
|
|
@ -840,8 +839,7 @@ namespace Server.Network
|
|||
var beholder = state.Mobile;
|
||||
var beheld = World.FindMobile(serial);
|
||||
|
||||
if (beheld == null)
|
||||
return;
|
||||
if (beheld == null) return;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
|
|
@ -1014,8 +1012,7 @@ namespace Server.Network
|
|||
|
||||
var t = from.Target;
|
||||
|
||||
if (t == null)
|
||||
return;
|
||||
if (t == null) return;
|
||||
|
||||
var prof = TargetProfile.Acquire(t.GetType());
|
||||
prof?.Start();
|
||||
|
|
@ -1640,45 +1637,41 @@ namespace Server.Network
|
|||
|
||||
public static void PartyMessage_AddMember(NetState state, PacketReader pvSrc)
|
||||
{
|
||||
if (PartyCommands.Handler != null)
|
||||
PartyCommands.Handler.OnAdd(state.Mobile);
|
||||
PartyCommands.Handler?.OnAdd(state.Mobile);
|
||||
}
|
||||
|
||||
public static void PartyMessage_RemoveMember(NetState state, PacketReader pvSrc)
|
||||
{
|
||||
if (PartyCommands.Handler != null)
|
||||
PartyCommands.Handler.OnRemove(state.Mobile, World.FindMobile(pvSrc.ReadUInt32()));
|
||||
PartyCommands.Handler?.OnRemove(state.Mobile, World.FindMobile(pvSrc.ReadUInt32()));
|
||||
}
|
||||
|
||||
public static void PartyMessage_PrivateMessage(NetState state, PacketReader pvSrc)
|
||||
{
|
||||
if (PartyCommands.Handler != null)
|
||||
PartyCommands.Handler.OnPrivateMessage(state.Mobile, World.FindMobile(pvSrc.ReadUInt32()),
|
||||
pvSrc.ReadUnicodeStringSafe());
|
||||
PartyCommands.Handler?.OnPrivateMessage(
|
||||
state.Mobile,
|
||||
World.FindMobile(pvSrc.ReadUInt32()),
|
||||
pvSrc.ReadUnicodeStringSafe()
|
||||
);
|
||||
}
|
||||
|
||||
public static void PartyMessage_PublicMessage(NetState state, PacketReader pvSrc)
|
||||
{
|
||||
if (PartyCommands.Handler != null)
|
||||
PartyCommands.Handler.OnPublicMessage(state.Mobile, pvSrc.ReadUnicodeStringSafe());
|
||||
PartyCommands.Handler?.OnPublicMessage(state.Mobile, pvSrc.ReadUnicodeStringSafe());
|
||||
}
|
||||
|
||||
public static void PartyMessage_SetCanLoot(NetState state, PacketReader pvSrc)
|
||||
{
|
||||
if (PartyCommands.Handler != null)
|
||||
PartyCommands.Handler.OnSetCanLoot(state.Mobile, pvSrc.ReadBoolean());
|
||||
PartyCommands.Handler?.OnSetCanLoot(state.Mobile, pvSrc.ReadBoolean());
|
||||
}
|
||||
|
||||
public static void PartyMessage_Accept(NetState state, PacketReader pvSrc)
|
||||
{
|
||||
if (PartyCommands.Handler != null)
|
||||
PartyCommands.Handler.OnAccept(state.Mobile, World.FindMobile(pvSrc.ReadUInt32()));
|
||||
PartyCommands.Handler?.OnAccept(state.Mobile, World.FindMobile(pvSrc.ReadUInt32()));
|
||||
}
|
||||
|
||||
public static void PartyMessage_Decline(NetState state, PacketReader pvSrc)
|
||||
{
|
||||
if (PartyCommands.Handler != null)
|
||||
PartyCommands.Handler.OnDecline(state.Mobile, World.FindMobile(pvSrc.ReadUInt32()));
|
||||
PartyCommands.Handler?.OnDecline(state.Mobile, World.FindMobile(pvSrc.ReadUInt32()));
|
||||
}
|
||||
|
||||
public static void StunRequest(NetState state, PacketReader pvSrc)
|
||||
|
|
@ -1725,41 +1718,40 @@ namespace Server.Network
|
|||
{
|
||||
var from = state.Mobile;
|
||||
|
||||
if (from != null)
|
||||
if (from == null) return;
|
||||
|
||||
var menu = from.ContextMenu;
|
||||
|
||||
from.ContextMenu = null;
|
||||
|
||||
if (menu != null && from == menu.From)
|
||||
{
|
||||
var menu = from.ContextMenu;
|
||||
var entity = World.FindEntity(pvSrc.ReadUInt32());
|
||||
|
||||
from.ContextMenu = null;
|
||||
|
||||
if (menu != null && from == menu.From)
|
||||
if (entity != null && entity == menu.Target && from.CanSee(entity))
|
||||
{
|
||||
var entity = World.FindEntity(pvSrc.ReadUInt32());
|
||||
Point3D p;
|
||||
|
||||
if (entity != null && entity == menu.Target && from.CanSee(entity))
|
||||
if (entity is Mobile)
|
||||
p = entity.Location;
|
||||
else if (entity is Item item)
|
||||
p = item.GetWorldLocation();
|
||||
else
|
||||
return;
|
||||
|
||||
int index = pvSrc.ReadUInt16();
|
||||
|
||||
if (index >= 0 && index < menu.Entries.Length)
|
||||
{
|
||||
Point3D p;
|
||||
var e = menu.Entries[index];
|
||||
|
||||
if (entity is Mobile)
|
||||
p = entity.Location;
|
||||
else if (entity is Item item)
|
||||
p = item.GetWorldLocation();
|
||||
else
|
||||
return;
|
||||
var range = e.Range;
|
||||
|
||||
int index = pvSrc.ReadUInt16();
|
||||
if (range == -1)
|
||||
range = 18;
|
||||
|
||||
if (index >= 0 && index < menu.Entries.Length)
|
||||
{
|
||||
var e = menu.Entries[index];
|
||||
|
||||
var range = e.Range;
|
||||
|
||||
if (range == -1)
|
||||
range = 18;
|
||||
|
||||
if (e.Enabled && from.InRange(p, range))
|
||||
e.OnClick();
|
||||
}
|
||||
if (e.Enabled && from.InRange(p, range))
|
||||
e.OnClick();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
public sealed class DamagePacketOld : Packet
|
||||
|
|
@ -30,12 +32,7 @@ namespace Server.Network
|
|||
Stream.Write((byte)1);
|
||||
Stream.Write(mobile);
|
||||
|
||||
if (amount > 255)
|
||||
amount = 255;
|
||||
else if (amount < 0)
|
||||
amount = 0;
|
||||
|
||||
Stream.Write((byte)amount);
|
||||
Stream.Write((byte)Math.Clamp(amount, 0, 255));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -45,12 +42,7 @@ namespace Server.Network
|
|||
{
|
||||
Stream.Write(mobile);
|
||||
|
||||
if (amount > 0xFFFF)
|
||||
amount = 0xFFFF;
|
||||
else if (amount < 0)
|
||||
amount = 0;
|
||||
|
||||
Stream.Write((ushort)amount);
|
||||
Stream.Write((ushort)Math.Clamp(amount, 0, 0xFFFF));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ namespace Server
|
|||
fileStream = FileOperations.OpenSequentialStream(path, FileMode.Create, FileAccess.Write, FileShare.None);
|
||||
|
||||
fileQueue = new FileQueue(
|
||||
Math.Max(1, FileOperations.Concurrency),
|
||||
Math.Max(FileOperations.Concurrency, 1),
|
||||
FileCallback);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using Server.Json;
|
||||
using Server.Utilities;
|
||||
|
||||
|
|
|
|||
|
|
@ -183,12 +183,7 @@ namespace Server
|
|||
get => m_Base;
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
value = 0;
|
||||
else if (value >= 0x10000)
|
||||
value = 0xFFFF;
|
||||
|
||||
var sv = (ushort)value;
|
||||
var sv = (ushort)Math.Clamp(value, 0, 0xFFFF);
|
||||
|
||||
int oldBase = m_Base;
|
||||
|
||||
|
|
@ -219,12 +214,7 @@ namespace Server
|
|||
get => m_Cap;
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
value = 0;
|
||||
else if (value >= 0x10000)
|
||||
value = 0xFFFF;
|
||||
|
||||
var sv = (ushort)value;
|
||||
var sv = (ushort)Math.Clamp(value, 0, 0xFFFF);
|
||||
|
||||
if (m_Cap != sv)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Server
|
||||
|
|
|
|||
|
|
@ -39,11 +39,7 @@ namespace Server
|
|||
OneMinute
|
||||
}
|
||||
|
||||
public delegate void TimerCallback();
|
||||
|
||||
public delegate void TimerStateCallback<in T>(T state);
|
||||
|
||||
public class Timer
|
||||
public partial class Timer
|
||||
{
|
||||
private static readonly Queue<Timer> m_Queue = new Queue<Timer>();
|
||||
|
||||
|
|
@ -464,90 +460,6 @@ namespace Server
|
|||
}
|
||||
}
|
||||
|
||||
public static Timer DelayCall(TimerCallback callback) => DelayCall(TimeSpan.Zero, TimeSpan.Zero, 1, callback);
|
||||
|
||||
public static Timer DelayCall(TimeSpan delay, TimerCallback callback) => DelayCall(delay, TimeSpan.Zero, 1, callback);
|
||||
|
||||
public static Timer DelayCall(TimeSpan delay, TimeSpan interval, TimerCallback callback) =>
|
||||
DelayCall(delay, interval, 0, callback);
|
||||
|
||||
public static Timer DelayCall(TimeSpan delay, TimeSpan interval, int count, TimerCallback callback)
|
||||
{
|
||||
Timer t = new DelayCallTimer(delay, interval, count, callback);
|
||||
|
||||
t.Priority = ComputePriority(count == 1 ? delay : interval);
|
||||
t.Start();
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
public static Timer DelayCall<T>(TimerStateCallback<T> callback, T state) =>
|
||||
DelayCall(TimeSpan.Zero, TimeSpan.Zero, 1, callback, state);
|
||||
|
||||
public static Timer DelayCall<T>(TimeSpan delay, TimerStateCallback<T> callback, T state) =>
|
||||
DelayCall(delay, TimeSpan.Zero, 1, callback, state);
|
||||
|
||||
public static Timer DelayCall<T>(TimeSpan delay, TimeSpan interval, TimerStateCallback<T> callback, T state) =>
|
||||
DelayCall(delay, interval, 0, callback, state);
|
||||
|
||||
public static Timer DelayCall<T>(TimeSpan delay, TimeSpan interval, int count, TimerStateCallback<T> callback,
|
||||
T state)
|
||||
{
|
||||
Timer t = new DelayStateCallTimer<T>(delay, interval, count, callback, state);
|
||||
|
||||
t.Priority = ComputePriority(count == 1 ? delay : interval);
|
||||
|
||||
t.Start();
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
private class DelayCallTimer : Timer
|
||||
{
|
||||
public DelayCallTimer(TimeSpan delay, TimeSpan interval, int count, TimerCallback callback) : base(delay,
|
||||
interval, count)
|
||||
{
|
||||
Callback = callback;
|
||||
RegCreation();
|
||||
}
|
||||
|
||||
public TimerCallback Callback { get; }
|
||||
|
||||
public override bool DefRegCreation => false;
|
||||
|
||||
protected override void OnTick()
|
||||
{
|
||||
Callback?.Invoke();
|
||||
}
|
||||
|
||||
public override string ToString() => $"DelayCallTimer[{FormatDelegate(Callback)}]";
|
||||
}
|
||||
|
||||
private class DelayStateCallTimer<T> : Timer
|
||||
{
|
||||
private readonly T m_State;
|
||||
|
||||
public DelayStateCallTimer(TimeSpan delay, TimeSpan interval, int count, TimerStateCallback<T> callback, T state)
|
||||
: base(delay, interval, count)
|
||||
{
|
||||
Callback = callback;
|
||||
m_State = state;
|
||||
|
||||
RegCreation();
|
||||
}
|
||||
|
||||
public TimerStateCallback<T> Callback { get; }
|
||||
|
||||
public override bool DefRegCreation => false;
|
||||
|
||||
protected override void OnTick()
|
||||
{
|
||||
Callback?.Invoke(m_State);
|
||||
}
|
||||
|
||||
public override string ToString() => $"DelayStateCall[{FormatDelegate(Callback)}]";
|
||||
}
|
||||
|
||||
private class DelayTaskTimer : Timer
|
||||
{
|
||||
private readonly TaskCompletionSource<DelayTaskTimer> m_TaskCompleter;
|
||||
268
Projects/Server/Timer/TimerDelayCalls.cs
Normal file
268
Projects/Server/Timer/TimerDelayCalls.cs
Normal file
|
|
@ -0,0 +1,268 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: TimerDelayCalls.cs - Created: 2020/07/31 - Updated: 2020/07/31 *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* 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;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public delegate void TimerCallback();
|
||||
public delegate void TimerStateCallback<in T>(T state);
|
||||
public delegate void TimerStateCallback<in T1, in T2>(T1 t1, T2 t2);
|
||||
public delegate void TimerStateCallback<in T1, in T2, in T3>(T1 t1, T2 t2, T3 t3);
|
||||
public delegate void TimerStateCallback<in T1, in T2, in T3, in T4>(T1 t1, T2 t2, T3 t3, T4 t4);
|
||||
|
||||
public partial class Timer
|
||||
{
|
||||
public static Timer DelayCall(TimerCallback callback) => DelayCall(TimeSpan.Zero, TimeSpan.Zero, 1, callback);
|
||||
|
||||
public static Timer DelayCall(TimeSpan delay, TimerCallback callback) => DelayCall(delay, TimeSpan.Zero, 1, callback);
|
||||
|
||||
public static Timer DelayCall(TimeSpan delay, TimeSpan interval, TimerCallback callback) =>
|
||||
DelayCall(delay, interval, 0, callback);
|
||||
|
||||
public static Timer DelayCall(TimeSpan delay, TimeSpan interval, int count, TimerCallback callback)
|
||||
{
|
||||
Timer t = new DelayCallTimer(delay, interval, count, callback);
|
||||
|
||||
t.Priority = ComputePriority(count == 1 ? delay : interval);
|
||||
t.Start();
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
private class DelayCallTimer : Timer
|
||||
{
|
||||
public DelayCallTimer(TimeSpan delay, TimeSpan interval, int count, TimerCallback callback) : base(delay,
|
||||
interval, count)
|
||||
{
|
||||
Callback = callback;
|
||||
RegCreation();
|
||||
}
|
||||
|
||||
public TimerCallback Callback { get; }
|
||||
|
||||
public override bool DefRegCreation => false;
|
||||
|
||||
protected override void OnTick()
|
||||
{
|
||||
Callback?.Invoke();
|
||||
}
|
||||
|
||||
public override string ToString() => $"DelayCallTimer[{FormatDelegate(Callback)}]";
|
||||
}
|
||||
|
||||
public static Timer DelayCall<T>(TimerStateCallback<T> callback, T state) =>
|
||||
DelayCall(TimeSpan.Zero, TimeSpan.Zero, 1, callback, state);
|
||||
|
||||
public static Timer DelayCall<T>(TimeSpan delay, TimerStateCallback<T> callback, T state) =>
|
||||
DelayCall(delay, TimeSpan.Zero, 1, callback, state);
|
||||
|
||||
public static Timer DelayCall<T>(TimeSpan delay, TimeSpan interval, TimerStateCallback<T> callback, T state) =>
|
||||
DelayCall(delay, interval, 0, callback, state);
|
||||
|
||||
public static Timer DelayCall<T>(TimeSpan delay, TimeSpan interval, int count, TimerStateCallback<T> callback,
|
||||
T state)
|
||||
{
|
||||
Timer t = new DelayStateCallTimer<T>(delay, interval, count, callback, state);
|
||||
|
||||
t.Priority = ComputePriority(count == 1 ? delay : interval);
|
||||
|
||||
t.Start();
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
private class DelayStateCallTimer<T> : Timer
|
||||
{
|
||||
private readonly T m_State;
|
||||
|
||||
public DelayStateCallTimer(TimeSpan delay, TimeSpan interval, int count, TimerStateCallback<T> callback, T state)
|
||||
: base(delay, interval, count)
|
||||
{
|
||||
Callback = callback;
|
||||
m_State = state;
|
||||
|
||||
RegCreation();
|
||||
}
|
||||
|
||||
public TimerStateCallback<T> Callback { get; }
|
||||
|
||||
public override bool DefRegCreation => false;
|
||||
|
||||
protected override void OnTick()
|
||||
{
|
||||
Callback?.Invoke(m_State);
|
||||
}
|
||||
|
||||
public override string ToString() => $"DelayStateCall[{FormatDelegate(Callback)}]";
|
||||
}
|
||||
|
||||
public static Timer DelayCall<T1, T2>(TimerStateCallback<T1, T2> callback, T1 t1, T2 t2) =>
|
||||
DelayCall(TimeSpan.Zero, TimeSpan.Zero, 1, callback, t1, t2);
|
||||
|
||||
public static Timer DelayCall<T1, T2>(TimeSpan delay, TimerStateCallback<T1, T2> callback, T1 t1, T2 t2) =>
|
||||
DelayCall(delay, TimeSpan.Zero, 1, callback, t1, t2);
|
||||
|
||||
public static Timer DelayCall<T1, T2>(TimeSpan delay, TimeSpan interval, TimerStateCallback<T1, T2> callback,
|
||||
T1 t1, T2 t2) => DelayCall(delay, interval, 0, callback, t1, t2);
|
||||
|
||||
public static Timer DelayCall<T1, T2>(TimeSpan delay, TimeSpan interval, int count, TimerStateCallback<T1, T2> callback,
|
||||
T1 t1, T2 t2)
|
||||
{
|
||||
Timer t = new DelayStateCallTimer<T1, T2>(delay, interval, count, callback, t1, t2);
|
||||
|
||||
t.Priority = ComputePriority(count == 1 ? delay : interval);
|
||||
|
||||
t.Start();
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
private class DelayStateCallTimer<T1, T2> : Timer
|
||||
{
|
||||
private readonly T1 m_T1;
|
||||
private readonly T2 m_T2;
|
||||
|
||||
public DelayStateCallTimer(TimeSpan delay, TimeSpan interval, int count, TimerStateCallback<T1, T2> callback,
|
||||
T1 t1, T2 t2) : base(delay, interval, count)
|
||||
{
|
||||
Callback = callback;
|
||||
m_T1 = t1;
|
||||
m_T2 = t2;
|
||||
|
||||
RegCreation();
|
||||
}
|
||||
|
||||
public TimerStateCallback<T1, T2> Callback { get; }
|
||||
|
||||
public override bool DefRegCreation => false;
|
||||
|
||||
protected override void OnTick()
|
||||
{
|
||||
Callback?.Invoke(m_T1, m_T2);
|
||||
}
|
||||
|
||||
public override string ToString() => $"DelayStateCall[{FormatDelegate(Callback)}]";
|
||||
}
|
||||
|
||||
public static Timer DelayCall<T1, T2, T3>(TimerStateCallback<T1, T2, T3> callback, T1 t1, T2 t2, T3 t3) =>
|
||||
DelayCall(TimeSpan.Zero, TimeSpan.Zero, 1, callback, t1, t2, t3);
|
||||
|
||||
public static Timer DelayCall<T1, T2, T3>(TimeSpan delay, TimerStateCallback<T1, T2, T3> callback, T1 t1, T2 t2, T3 t3) =>
|
||||
DelayCall(delay, TimeSpan.Zero, 1, callback, t1, t2, t3);
|
||||
|
||||
public static Timer DelayCall<T1, T2, T3>(TimeSpan delay, TimeSpan interval, TimerStateCallback<T1, T2, T3> callback,
|
||||
T1 t1, T2 t2, T3 t3) => DelayCall(delay, interval, 0, callback, t1, t2, t3);
|
||||
|
||||
public static Timer DelayCall<T1, T2, T3>(TimeSpan delay, TimeSpan interval, int count,
|
||||
TimerStateCallback<T1, T2, T3> callback, T1 t1, T2 t2, T3 t3)
|
||||
{
|
||||
Timer t = new DelayStateCallTimer<T1, T2, T3>(delay, interval, count, callback, t1, t2, t3);
|
||||
|
||||
t.Priority = ComputePriority(count == 1 ? delay : interval);
|
||||
|
||||
t.Start();
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
private class DelayStateCallTimer<T1, T2, T3> : Timer
|
||||
{
|
||||
private readonly T1 m_T1;
|
||||
private readonly T2 m_T2;
|
||||
private readonly T3 m_T3;
|
||||
|
||||
public DelayStateCallTimer(TimeSpan delay, TimeSpan interval, int count, TimerStateCallback<T1, T2, T3> callback,
|
||||
T1 t1, T2 t2, T3 t3) : base(delay, interval, count)
|
||||
{
|
||||
Callback = callback;
|
||||
m_T1 = t1;
|
||||
m_T2 = t2;
|
||||
m_T3 = t3;
|
||||
|
||||
RegCreation();
|
||||
}
|
||||
|
||||
public TimerStateCallback<T1, T2, T3> Callback { get; }
|
||||
|
||||
public override bool DefRegCreation => false;
|
||||
|
||||
protected override void OnTick()
|
||||
{
|
||||
Callback?.Invoke(m_T1, m_T2, m_T3);
|
||||
}
|
||||
|
||||
public override string ToString() => $"DelayStateCall[{FormatDelegate(Callback)}]";
|
||||
}
|
||||
|
||||
public static Timer DelayCall<T1, T2, T3, T4>(TimerStateCallback<T1, T2, T3, T4> callback, T1 t1, T2 t2, T3 t3, T4 t4) =>
|
||||
DelayCall(TimeSpan.Zero, TimeSpan.Zero, 1, callback, t1, t2, t3, t4);
|
||||
|
||||
public static Timer DelayCall<T1, T2, T3, T4>(TimeSpan delay, TimerStateCallback<T1, T2, T3, T4> callback,
|
||||
T1 t1, T2 t2, T3 t3, T4 t4) => DelayCall(delay, TimeSpan.Zero, 1, callback, t1, t2, t3, t4);
|
||||
|
||||
public static Timer DelayCall<T1, T2, T3, T4>(TimeSpan delay, TimeSpan interval,
|
||||
TimerStateCallback<T1, T2, T3, T4> callback, T1 t1, T2 t2, T3 t3, T4 t4) =>
|
||||
DelayCall(delay, interval, 0, callback, t1, t2, t3, t4);
|
||||
|
||||
public static Timer DelayCall<T1, T2, T3, T4>(TimeSpan delay, TimeSpan interval, int count,
|
||||
TimerStateCallback<T1, T2, T3, T4> callback, T1 t1, T2 t2, T3 t3, T4 t4)
|
||||
{
|
||||
Timer t = new DelayStateCallTimer<T1, T2, T3, T4>(delay, interval, count, callback, t1, t2, t3, t4);
|
||||
|
||||
t.Priority = ComputePriority(count == 1 ? delay : interval);
|
||||
|
||||
t.Start();
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
private class DelayStateCallTimer<T1, T2, T3, T4> : Timer
|
||||
{
|
||||
private readonly T1 m_T1;
|
||||
private readonly T2 m_T2;
|
||||
private readonly T3 m_T3;
|
||||
private readonly T4 m_T4;
|
||||
|
||||
public DelayStateCallTimer(TimeSpan delay, TimeSpan interval, int count, TimerStateCallback<T1, T2, T3, T4> callback,
|
||||
T1 t1, T2 t2, T3 t3, T4 t4) : base(delay, interval, count)
|
||||
{
|
||||
Callback = callback;
|
||||
m_T1 = t1;
|
||||
m_T2 = t2;
|
||||
m_T3 = t3;
|
||||
m_T4 = t4;
|
||||
|
||||
RegCreation();
|
||||
}
|
||||
|
||||
public TimerStateCallback<T1, T2, T3, T4> Callback { get; }
|
||||
|
||||
public override bool DefRegCreation => false;
|
||||
|
||||
protected override void OnTick()
|
||||
{
|
||||
Callback?.Invoke(m_T1, m_T2, m_T3, m_T4);
|
||||
}
|
||||
|
||||
public override string ToString() => $"DelayStateCall[{FormatDelegate(Callback)}]";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,23 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: ActivatorUtil.cs - Created: 2020/02/19 - Updated: 2020/07/30 *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* 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;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,23 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: RefPool.cs - Created: 2020/02/20 - Updated: 2020/07/30 *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* 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;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
|
|
|||
|
|
@ -493,19 +493,8 @@ namespace Server
|
|||
return dy > 0 ? Direction.Left : Direction.Up;
|
||||
}
|
||||
|
||||
public static object GetArrayCap(Array array, int index, object emptyValue = null)
|
||||
{
|
||||
if (array.Length > 0)
|
||||
{
|
||||
if (index < 0)
|
||||
index = 0;
|
||||
else if (index >= array.Length) index = array.Length - 1;
|
||||
|
||||
return array.GetValue(index);
|
||||
}
|
||||
|
||||
return emptyValue;
|
||||
}
|
||||
public static object GetArrayCap(Array array, int index, object emptyValue = null) =>
|
||||
array.Length > 0 ? array.GetValue(Math.Clamp(index, 0, array.Length - 1)) : emptyValue;
|
||||
|
||||
public static SkillName RandomSkill() =>
|
||||
m_AllSkills[Random(m_AllSkills.Length - (Core.ML ? 0 : Core.SE ? 1 : Core.AOS ? 3 : 6))];
|
||||
|
|
@ -1002,5 +991,12 @@ namespace Server
|
|||
/// </summary>
|
||||
public static int RandomBrightHue() =>
|
||||
RandomDouble() < 0.1 ? RandomList(0x62, 0x71) : RandomList(0x03, 0x0D, 0x13, 0x1C, 0x21, 0x30, 0x37, 0x3A, 0x44, 0x59);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static T Clamp<T>(this T val, T min, T max) where T : IComparable<T> =>
|
||||
val.CompareTo(min) < 0 ? min : val.CompareTo(max) > 0 ? max : val;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static TimeSpan Max(this TimeSpan val, TimeSpan max) => val > max ? max : val;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue