Fixes for Last Moved (#194)
This commit is contained in:
parent
3a081d5322
commit
b476bcfd24
28 changed files with 155 additions and 398 deletions
|
|
@ -935,8 +935,8 @@ namespace Server
|
|||
|
||||
m_Map = value;
|
||||
|
||||
if (m_Map != null && m_Parent == null)
|
||||
m_Map.OnEnter(this);
|
||||
if (m_Parent == null)
|
||||
m_Map?.OnEnter(this);
|
||||
|
||||
Delta(ItemDelta.Update);
|
||||
|
||||
|
|
@ -1262,26 +1262,9 @@ namespace Server
|
|||
var ticks = LastMoved.Ticks;
|
||||
var now = DateTime.UtcNow.Ticks;
|
||||
|
||||
TimeSpan d;
|
||||
var minutes = new TimeSpan(now - ticks).TotalMinutes;
|
||||
|
||||
try
|
||||
{
|
||||
d = new TimeSpan(ticks - now);
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (ticks < now) d = TimeSpan.MaxValue;
|
||||
else d = TimeSpan.MaxValue;
|
||||
}
|
||||
|
||||
var minutes = -d.TotalMinutes;
|
||||
|
||||
if (minutes < int.MinValue)
|
||||
minutes = int.MinValue;
|
||||
else if (minutes > int.MaxValue)
|
||||
minutes = int.MaxValue;
|
||||
|
||||
writer.WriteEncodedInt((int)minutes);
|
||||
writer.WriteEncodedInt((int)Math.Clamp(minutes, int.MinValue, int.MaxValue));
|
||||
/* end */
|
||||
|
||||
if (GetSaveFlag(flags, SaveFlag.Direction))
|
||||
|
|
@ -1967,7 +1950,7 @@ namespace Server
|
|||
|
||||
public virtual bool OnDragDrop(Mobile from, Item dropped)
|
||||
{
|
||||
var success = (Parent is Container container && container.OnStackAttempt(from, this, dropped)) ||
|
||||
var success = Parent is Container container && container.OnStackAttempt(from, this, dropped) ||
|
||||
StackWith(from, dropped);
|
||||
|
||||
if (success && Spawner != null)
|
||||
|
|
@ -2125,39 +2108,24 @@ namespace Server
|
|||
{
|
||||
var map = m_Map;
|
||||
|
||||
if (map == null)
|
||||
return Map.NullEnumerable<Item>.Instance;
|
||||
|
||||
if (m_Parent == null)
|
||||
return map.GetItemsInRange(m_Location, range);
|
||||
|
||||
return map.GetItemsInRange(GetWorldLocation(), range);
|
||||
return map?.GetItemsInRange(m_Parent == null ? m_Location : GetWorldLocation(), range)
|
||||
?? Map.NullEnumerable<Item>.Instance;
|
||||
}
|
||||
|
||||
public IPooledEnumerable<Mobile> GetMobilesInRange(int range)
|
||||
{
|
||||
var map = m_Map;
|
||||
|
||||
if (map == null)
|
||||
return Map.NullEnumerable<Mobile>.Instance;
|
||||
|
||||
if (m_Parent == null)
|
||||
return map.GetMobilesInRange(m_Location, range);
|
||||
|
||||
return map.GetMobilesInRange(GetWorldLocation(), range);
|
||||
return map?.GetMobilesInRange(m_Parent == null ? m_Location : GetWorldLocation(), range)
|
||||
?? Map.NullEnumerable<Mobile>.Instance;
|
||||
}
|
||||
|
||||
public IPooledEnumerable<NetState> GetClientsInRange(int range)
|
||||
{
|
||||
var map = m_Map;
|
||||
|
||||
if (map == null)
|
||||
return Map.NullEnumerable<NetState>.Instance;
|
||||
|
||||
if (m_Parent == null)
|
||||
return map.GetClientsInRange(m_Location, range);
|
||||
|
||||
return map.GetClientsInRange(GetWorldLocation(), range);
|
||||
return map.GetClientsInRange(m_Parent == null ? m_Location : GetWorldLocation(), range)
|
||||
?? Map.NullEnumerable<NetState>.Instance;
|
||||
}
|
||||
|
||||
public bool GetTempFlag(int flag) => ((LookupCompactInfo()?.m_TempFlags ?? 0) & flag) != 0;
|
||||
|
|
@ -2265,10 +2233,7 @@ namespace Server
|
|||
if (GetSaveFlag(flags, SaveFlag.Hue))
|
||||
m_Hue = reader.ReadEncodedInt();
|
||||
|
||||
if (GetSaveFlag(flags, SaveFlag.Amount))
|
||||
m_Amount = reader.ReadEncodedInt();
|
||||
else
|
||||
m_Amount = 1;
|
||||
m_Amount = GetSaveFlag(flags, SaveFlag.Amount) ? reader.ReadEncodedInt() : 1;
|
||||
|
||||
if (GetSaveFlag(flags, SaveFlag.Layer))
|
||||
m_Layer = (Layer)reader.ReadByte();
|
||||
|
|
@ -2377,10 +2342,7 @@ namespace Server
|
|||
if (GetSaveFlag(flags, SaveFlag.Hue))
|
||||
m_Hue = reader.ReadInt();
|
||||
|
||||
if (GetSaveFlag(flags, SaveFlag.Amount))
|
||||
m_Amount = reader.ReadInt();
|
||||
else
|
||||
m_Amount = 1;
|
||||
m_Amount = GetSaveFlag(flags, SaveFlag.Amount) ? reader.ReadInt() : 1;
|
||||
|
||||
if (GetSaveFlag(flags, SaveFlag.Layer))
|
||||
m_Layer = (Layer)reader.ReadByte();
|
||||
|
|
@ -2437,15 +2399,8 @@ namespace Server
|
|||
else
|
||||
m_Map = Map.Internal;
|
||||
|
||||
if (GetSaveFlag(flags, SaveFlag.Visible))
|
||||
SetFlag(ImplFlag.Visible, reader.ReadBool());
|
||||
else
|
||||
SetFlag(ImplFlag.Visible, true);
|
||||
|
||||
if (GetSaveFlag(flags, SaveFlag.Movable))
|
||||
SetFlag(ImplFlag.Movable, reader.ReadBool());
|
||||
else
|
||||
SetFlag(ImplFlag.Movable, true);
|
||||
SetFlag(ImplFlag.Visible, !GetSaveFlag(flags, SaveFlag.Visible) || reader.ReadBool());
|
||||
SetFlag(ImplFlag.Movable, !GetSaveFlag(flags, SaveFlag.Movable) || reader.ReadBool());
|
||||
|
||||
if (GetSaveFlag(flags, SaveFlag.Stackable))
|
||||
SetFlag(ImplFlag.Stackable, reader.ReadBool());
|
||||
|
|
@ -3324,15 +3279,13 @@ namespace Server
|
|||
parentMobile.OnSubItemBounceCleared(item);
|
||||
}
|
||||
|
||||
public virtual bool CheckTarget(Mobile from, Target targ, object targeted)
|
||||
{
|
||||
if (m_Parent is Item item)
|
||||
return item.CheckTarget(from, targ, targeted);
|
||||
if (m_Parent is Mobile mobile)
|
||||
return mobile.CheckTarget(from, targ, targeted);
|
||||
|
||||
return true;
|
||||
}
|
||||
public virtual bool CheckTarget(Mobile from, Target targ, object targeted) =>
|
||||
m_Parent switch
|
||||
{
|
||||
Item item => item.CheckTarget(from, targ, targeted),
|
||||
Mobile mobile => mobile.CheckTarget(from, targ, targeted),
|
||||
_ => true
|
||||
};
|
||||
|
||||
public virtual bool IsAccessibleTo(Mobile check)
|
||||
{
|
||||
|
|
@ -3387,14 +3340,13 @@ namespace Server
|
|||
|
||||
public bool CheckItemUse(Mobile from) => CheckItemUse(from, this);
|
||||
|
||||
public virtual bool CheckItemUse(Mobile from, Item item)
|
||||
{
|
||||
if (m_Parent is Item parentItem)
|
||||
return parentItem.CheckItemUse(from, item);
|
||||
if (m_Parent is Mobile parentMobile)
|
||||
return parentMobile.CheckItemUse(from, item);
|
||||
return true;
|
||||
}
|
||||
public virtual bool CheckItemUse(Mobile from, Item item) =>
|
||||
m_Parent switch
|
||||
{
|
||||
Item parentItem => parentItem.CheckItemUse(from, item),
|
||||
Mobile parentMobile => parentMobile.CheckItemUse(from, item),
|
||||
_ => true
|
||||
};
|
||||
|
||||
public virtual void OnItemLifted(Mobile from, Item item)
|
||||
{
|
||||
|
|
@ -3411,21 +3363,18 @@ namespace Server
|
|||
return CheckLift(from, this, ref reject);
|
||||
}
|
||||
|
||||
public virtual bool CheckLift(Mobile from, Item item, ref LRReason reject)
|
||||
{
|
||||
if (m_Parent is Item parentItem)
|
||||
return parentItem.CheckLift(from, item, ref reject);
|
||||
|
||||
if (m_Parent is Mobile parentMobile)
|
||||
return parentMobile.CheckLift(from, item, ref reject);
|
||||
|
||||
return true;
|
||||
}
|
||||
public virtual bool CheckLift(Mobile from, Item item, ref LRReason reject) =>
|
||||
m_Parent switch
|
||||
{
|
||||
Item parentItem => parentItem.CheckLift(from, item, ref reject),
|
||||
Mobile parentMobile => parentMobile.CheckLift(from, item, ref reject),
|
||||
_ => true
|
||||
};
|
||||
|
||||
public virtual void OnSingleClickContained(Mobile from, Item item)
|
||||
{
|
||||
if (m_Parent is Item item1)
|
||||
item1.OnSingleClickContained(from, item);
|
||||
if (m_Parent is Item parentItem)
|
||||
parentItem.OnSingleClickContained(from, item);
|
||||
}
|
||||
|
||||
public virtual void OnAosSingleClick(Mobile from)
|
||||
|
|
@ -3529,26 +3478,13 @@ namespace Server
|
|||
Delete();
|
||||
}
|
||||
|
||||
public virtual bool CheckBlessed(Mobile m)
|
||||
{
|
||||
if (m_LootType == LootType.Blessed || (Mobile.InsuranceEnabled && Insured))
|
||||
return true;
|
||||
|
||||
return m != null && m == BlessedFor;
|
||||
}
|
||||
public virtual bool CheckBlessed(Mobile m) =>
|
||||
m_LootType == LootType.Blessed || Mobile.InsuranceEnabled && Insured || m != null && m == BlessedFor;
|
||||
|
||||
public virtual bool CheckNewbied() => m_LootType == LootType.Newbied;
|
||||
|
||||
public virtual bool IsStandardLoot()
|
||||
{
|
||||
if (Mobile.InsuranceEnabled && Insured)
|
||||
return false;
|
||||
|
||||
if (BlessedFor != null)
|
||||
return false;
|
||||
|
||||
return m_LootType == LootType.Regular;
|
||||
}
|
||||
public virtual bool IsStandardLoot() =>
|
||||
(!Mobile.InsuranceEnabled || !Insured) && BlessedFor == null && m_LootType == LootType.Regular;
|
||||
|
||||
public override string ToString() => $"0x{Serial.Value:X} \"{GetType().Name}\"";
|
||||
|
||||
|
|
|
|||
|
|
@ -8545,14 +8545,10 @@ namespace Server
|
|||
if (Deleted)
|
||||
return;
|
||||
|
||||
if (value < 0)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
else if (value >= HitsMax)
|
||||
{
|
||||
value = HitsMax;
|
||||
value = Math.Clamp(value, 0, HitsMax);
|
||||
|
||||
if (value == HitsMax)
|
||||
{
|
||||
m_HitsTimer?.Stop();
|
||||
|
||||
for (var i = 0; i < Aggressors.Count; i++) // reset reports on full HP
|
||||
|
|
@ -8561,8 +8557,7 @@ namespace Server
|
|||
if (DamageEntries.Count > 0)
|
||||
DamageEntries.Clear(); // reset damage entries on full HP
|
||||
}
|
||||
|
||||
if (value < HitsMax)
|
||||
else
|
||||
{
|
||||
if (CanRegenHits)
|
||||
{
|
||||
|
|
@ -8604,18 +8599,13 @@ namespace Server
|
|||
if (Deleted)
|
||||
return;
|
||||
|
||||
if (value < 0)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
else if (value >= StamMax)
|
||||
{
|
||||
value = StamMax;
|
||||
value = Math.Clamp(value, 0, StamMax);
|
||||
|
||||
if (value == StamMax)
|
||||
{
|
||||
m_StamTimer?.Stop();
|
||||
}
|
||||
|
||||
if (value < StamMax)
|
||||
else
|
||||
{
|
||||
if (CanRegenStam)
|
||||
{
|
||||
|
|
@ -8660,14 +8650,10 @@ namespace Server
|
|||
if (Deleted)
|
||||
return;
|
||||
|
||||
if (value < 0)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
else if (value >= ManaMax)
|
||||
{
|
||||
value = ManaMax;
|
||||
value = Math.Clamp(value, 0, ManaMax);
|
||||
|
||||
if (value == ManaMax)
|
||||
{
|
||||
m_ManaTimer?.Stop();
|
||||
|
||||
if (Meditating)
|
||||
|
|
@ -8676,8 +8662,7 @@ namespace Server
|
|||
SendLocalizedMessage(501846); // You are at peace.
|
||||
}
|
||||
}
|
||||
|
||||
if (value < ManaMax)
|
||||
else
|
||||
{
|
||||
if (CanRegenMana)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -178,7 +178,7 @@ namespace Server.Network
|
|||
var s = skills[i];
|
||||
|
||||
var v = s.NonRacialValue;
|
||||
var uv = Utility.Coerce((int)(v * 10), 0, 0xFFFF);
|
||||
var uv = Math.Clamp((int)(v * 10), 0, 0xFFFF);
|
||||
|
||||
Stream.Write((ushort)(s.Info.SkillID + 1));
|
||||
Stream.Write((ushort)uv);
|
||||
|
|
@ -206,7 +206,7 @@ namespace Server.Network
|
|||
EnsureCapacity(13);
|
||||
|
||||
var v = skill.NonRacialValue;
|
||||
var uv = Utility.Coerce((int)(v * 10), 0, 0xFFFF);
|
||||
var uv = Math.Clamp((int)(v * 10), 0, 0xFFFF);
|
||||
|
||||
Stream.Write((byte)0xDF); // type: delta, capped
|
||||
Stream.Write((ushort)skill.Info.SkillID);
|
||||
|
|
|
|||
|
|
@ -121,8 +121,8 @@ namespace Server
|
|||
|
||||
private static readonly Stack<ConsoleColor> m_ConsoleColors = new Stack<ConsoleColor>();
|
||||
|
||||
public static Encoding UTF8 => m_UTF8 ?? (m_UTF8 = new UTF8Encoding(false, false));
|
||||
public static Encoding UTF8WithEncoding => m_UTF8WithEncoding ?? (m_UTF8WithEncoding = new UTF8Encoding(true, false));
|
||||
public static Encoding UTF8 => m_UTF8 ??= new UTF8Encoding(false, false);
|
||||
public static Encoding UTF8WithEncoding => m_UTF8WithEncoding ??= new UTF8Encoding(true, false);
|
||||
|
||||
public static void Separate(StringBuilder sb, string value, string separator)
|
||||
{
|
||||
|
|
@ -139,6 +139,9 @@ namespace Server
|
|||
str = Intern(str);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static string IsNullOrDefault(this string value, string def) => value?.Length > 0 ? value : def;
|
||||
|
||||
public static IPAddress Intern(IPAddress ipAddress)
|
||||
{
|
||||
_ipAddressTable ??= new Dictionary<IPAddress, IPAddress>();
|
||||
|
|
@ -835,9 +838,6 @@ namespace Server
|
|||
&& p1.Y >= p2.Y - 18
|
||||
&& p1.Y <= p2.Y + 18;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int Coerce(int number, int min, int max) => number < min ? min : number > max ? max : number;
|
||||
|
||||
// 4d6+8 would be: Utility.Dice( 4, 6, 8 )
|
||||
public static int Dice(uint amount, uint sides, int bonus)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue