Fixes for Last Moved (#194)

This commit is contained in:
Kamron Batman 2020-08-16 06:58:16 -07:00 committed by GitHub
parent 3a081d5322
commit b476bcfd24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 155 additions and 398 deletions

View file

@ -223,7 +223,7 @@ namespace Server.Tests.Network.Packets
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);
expectedData.Write(ref pos, (ushort)(s.Info.SkillID + 1));
expectedData.Write(ref pos, (ushort)uv);
@ -276,7 +276,7 @@ namespace Server.Tests.Network.Packets
expectedData.Write(ref pos, (byte)0xDF); // type: delta, capped
var v = skill.NonRacialValue;
var uv = Utility.Coerce((int)(v * 10), 0, 0xFFFF);
var uv = Math.Clamp((int)(v * 10), 0, 0xFFFF);
expectedData.Write(ref pos, (ushort)skill.Info.SkillID);
expectedData.Write(ref pos, (ushort)uv);

View file

@ -0,0 +1,18 @@
using Xunit;
namespace Server.Tests
{
public class TestStringHelpers
{
[Theory]
[InlineData(null, "default value", "default value")]
[InlineData("", "default value", "default value")]
[InlineData("this is a valid string", "default value", "this is a valid string")]
public void TestIsNullOrDefault(string value, string defaultValue, string expected)
{
string actual = value.IsNullOrDefault(defaultValue);
Assert.Equal(expected, actual);
}
}
}

View file

@ -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}\"";

View file

@ -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)
{

View file

@ -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);

View file

@ -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)
{

View file

@ -39,20 +39,7 @@ namespace Server.Engines.Chat
public string Password
{
get => m_Password;
set
{
string newValue = null;
if (value != null)
{
newValue = value.Trim();
if (string.IsNullOrEmpty(newValue))
newValue = null;
}
m_Password = newValue;
}
set => m_Password = value?.Trim().IsNullOrDefault(null);
}
public bool VoiceRestricted

View file

@ -239,12 +239,9 @@ namespace Server.Engines.ConPVP
if (m_Counter >= m_Hill.ScoreInterval)
{
string hill = m_Hill.Name;
string hill = m_Hill.Name.IsNullOrDefault("the hill");
string king = m_Hill.King.Name ?? "";
if (string.IsNullOrEmpty(hill))
hill = "the hill";
m_Hill.Game.Alert("{0} ({1}) is king of {2}!", king, ti.Name, hill);
m_Hill.PublicOverheadMessage(MessageType.Regular, 0x0481, false, "Capture!");

View file

@ -33,11 +33,10 @@ namespace Server
{
int v = from.Virtues.GetValue((int)virtue);
int vl;
int vmax = GetMaxAmount(virtue);
if (v < 4000)
vl = 0;
else if (v >= vmax)
else if (v >= GetMaxAmount(virtue))
vl = 3;
else
vl = (v + 9999) / 10000;
@ -45,16 +44,13 @@ namespace Server
return (VirtueLevel)vl;
}
public static int GetMaxAmount(VirtueName virtue)
{
if (virtue == VirtueName.Honor)
return 20000;
if (virtue == VirtueName.Sacrifice)
return 22000;
return 21000;
}
public static int GetMaxAmount(VirtueName virtue) =>
virtue switch
{
VirtueName.Honor => 20000,
VirtueName.Sacrifice => 22000,
_ => 21000
};
public static bool Award(Mobile from, VirtueName virtue, int amount, ref bool gainedPath)
{
@ -142,4 +138,4 @@ namespace Server
}
}
}
}
}

View file

@ -54,17 +54,14 @@ namespace Server.Guilds
AddImageTiled(65, 196, 480, 4, 0x238D);
string s = guild.Charter;
if (string.IsNullOrEmpty(s))
s = "The guild leader has not yet set the guild charter.";
string s = guild.Charter.IsNullOrDefault("The guild leader has not yet set the guild charter.");
AddHtml(65, 216, 480, 80, s, true, true);
if (isLeader)
AddButton(40, 251, 0x4B9, 0x4BA, 4); // Charter Edit button
s = guild.Website;
if (string.IsNullOrEmpty(s))
s = "Guild website not yet set.";
s = guild.Website.IsNullOrDefault("Guild website not yet set.");
AddHtml(65, 306, 480, 30, s, true);
if (isLeader)
AddButton(40, 313, 0x4B9, 0x4BA, 5); // Website Edit button

View file

@ -545,10 +545,7 @@ namespace Server.Items
toKill.RemoveAt(kill);
amount -= 1;
LiveCreatures -= 1;
if (LiveCreatures < 0)
LiveCreatures = 0;
LiveCreatures = Math.Max(LiveCreatures - 1, 0);
Events.Add(1074366); // An unfortunate accident has left a creature floating upside-down. It is starting to smell.
}
@ -598,8 +595,8 @@ namespace Server.Items
if (OptimalState && LiveCreatures < MaxLiveCreatures)
if (Utility.RandomDouble() < 0.005 * LiveCreatures)
{
BaseFish fish = null;
int message = 0;
BaseFish fish;
int message;
switch (Utility.Random(6))
{
@ -745,7 +742,7 @@ namespace Server.Items
public virtual bool RemoveItem(Mobile from, int at)
{
if (at < 0 && at >= Items.Count)
if (at < 0 || at >= Items.Count)
return false;
Item item = Items[at];

View file

@ -136,7 +136,7 @@ namespace Server.Engines.Mahjong
int hand = tile.Dimensions.GetHandArea();
if (hand < 0 || players.IsPublic(hand) || players.GetPlayer(hand) == to ||
(game.SpectatorVision && players.IsSpectator(to)))
game.SpectatorVision && players.IsSpectator(to))
Stream.Write((byte)tile.Value);
else
Stream.Write((byte)0);
@ -176,7 +176,7 @@ namespace Server.Engines.Mahjong
int hand = tile.Dimensions.GetHandArea();
if (hand < 0 || players.IsPublic(hand) || players.GetPlayer(hand) == to ||
(game.SpectatorVision && players.IsSpectator(to)))
game.SpectatorVision && players.IsSpectator(to))
Stream.Write((byte)tile.Value);
else
Stream.Write((byte)0);
@ -206,4 +206,4 @@ namespace Server.Engines.Mahjong
Stream.Write((byte)0x1A);
}
}
}
}

View file

@ -368,12 +368,7 @@ namespace Server.Items
from.Send(new PlaySound(0x42, GetWorldLocation()));
string desc = rune.Description;
if (desc == null || (desc = desc.Trim()).Length == 0)
desc = "(indescript)";
from.SendMessage(desc);
from.SendMessage(rune.Description?.Trim().IsNullOrDefault("(indescript)"));
return true;
}

View file

@ -138,10 +138,7 @@ namespace Server.Items
check = m.FindItemOnLayer(Layer.TwoHanded);
if (check is BaseTool && check != tool && !(check is AncientSmithyHammer))
return false;
return true;
return !(check is BaseTool) || check == tool || check is AncientSmithyHammer;
}
public override void OnSingleClick(Mobile from)
@ -159,16 +156,11 @@ namespace Server.Items
int num = system.CanCraft(from, this, null);
if (num > 0 && (num != 1044267 || !Core.SE)) // Blacksmithing shows the gump regardless of proximity of an anvil and forge after SE
{
// Blacksmithing shows the gump regardless of proximity of an anvil and forge after SE
if (num > 0 && (num != 1044267 || !Core.SE))
from.SendLocalizedMessage(num);
}
else
{
CraftContext context = system.GetContext(from);
from.SendGump(new CraftGump(from, system, this, null));
}
}
else
{

View file

@ -31,10 +31,7 @@ namespace Server.Regions
BankBox bank = from.FindBankNoCreate();
if (bank != null && ContainsDeed(bank))
return true;
return false;
return bank != null && ContainsDeed(bank);
}
private bool ContainsDeed(Container cont)
@ -53,4 +50,4 @@ namespace Server.Regions
return base.OnTarget(m, t, o);
}
}
}
}

View file

@ -68,13 +68,7 @@ namespace Server.Items
get => m_Charges;
set
{
if (value > MaxCharges)
m_Charges = MaxCharges;
else if (value < 0)
m_Charges = 0;
else
m_Charges = value;
m_Charges = Math.Clamp(value, 0, MaxCharges);
InvalidateProperties();
}
}
@ -85,13 +79,7 @@ namespace Server.Items
get => m_Recharges;
set
{
if (value > MaxRecharges)
m_Recharges = MaxRecharges;
else if (value < 0)
m_Recharges = 0;
else
m_Recharges = value;
m_Recharges = Math.Clamp(value, 0, MaxRecharges);
InvalidateProperties();
}
}
@ -278,4 +266,4 @@ namespace Server.Items
}
}
}
}
}

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Server.ContextMenus;
using Server.Engines.ConPVP;
using Server.Mobiles;
@ -61,13 +62,7 @@ namespace Server.Items
get => m_Charges;
set
{
if (value > MaxCharges)
m_Charges = MaxCharges;
else if (value < 0)
m_Charges = 0;
else
m_Charges = value;
m_Charges = Math.Clamp(value, 0, MaxCharges);
InvalidateProperties();
}
}
@ -78,13 +73,7 @@ namespace Server.Items
get => m_Recharges;
set
{
if (value > MaxRecharges)
m_Recharges = MaxRecharges;
else if (value < 0)
m_Recharges = 0;
else
m_Recharges = value;
m_Recharges = Math.Clamp(value, 0, MaxRecharges);
InvalidateProperties();
}
}
@ -100,17 +89,13 @@ namespace Server.Items
public override void AddNameProperty(ObjectPropertyList list)
{
list.Add(1054131,
m_Charges + (PetName.Length == 0
? "\t "
: $"\t{PetName}")); // a crystal ball of pet summoning: [charges: ~1_charges~] : [linked pet: ~2_petName~]
$"{m_Charges}\t{PetName.IsNullOrDefault(" ")}"); // a crystal ball of pet summoning: [charges: ~1_charges~] : [linked pet: ~2_petName~]
}
public override void OnSingleClick(Mobile from)
{
LabelTo(from, 1054131,
m_Charges + (PetName.Length == 0
? "\t "
: $"\t{PetName}")); // a crystal ball of pet summoning: [charges: ~1_charges~] : [linked pet: ~2_petName~]
$"{m_Charges}\t{PetName.IsNullOrDefault(" ")}"); // a crystal ball of pet summoning: [charges: ~1_charges~] : [linked pet: ~2_petName~]
}
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list)
@ -415,13 +400,8 @@ namespace Server.Items
Disturb(DisturbType.Hurt, false);
}
public override bool CheckDisturb(DisturbType type, bool checkFirst, bool resistable)
{
if (type == DisturbType.EquipRequest || type == DisturbType.UseRequest /* || type == DisturbType.Hurt*/)
return false;
return true;
}
public override bool CheckDisturb(DisturbType type, bool checkFirst, bool resistable) =>
type != DisturbType.EquipRequest && type != DisturbType.UseRequest;
public override void DoHurtFizzle()
{

View file

@ -63,13 +63,7 @@ namespace Server.Items
get => m_Charges;
set
{
if (value > MaxCharges)
m_Charges = MaxCharges;
else if (value < 0)
m_Charges = 0;
else
m_Charges = value;
m_Charges = Math.Clamp(value, 0, MaxCharges);
InvalidateProperties();
}
}
@ -80,13 +74,7 @@ namespace Server.Items
get => m_Recharges;
set
{
if (value > MaxRecharges)
m_Recharges = MaxRecharges;
else if (value < 0)
m_Recharges = 0;
else
m_Recharges = value;
m_Recharges = Math.Clamp(value, 0, MaxRecharges);
InvalidateProperties();
}
}
@ -102,17 +90,13 @@ namespace Server.Items
public override void AddNameProperty(ObjectPropertyList list)
{
list.Add(1054000,
m_Charges + (m_Inscription.Length == 0
? "\t "
: $" :\t{m_Inscription}")); // a bracelet of binding : ~1_val~ ~2_val~
$"{m_Charges}\t{m_Inscription.IsNullOrDefault(" ")}"); // a bracelet of binding : ~1_val~ ~2_val~
}
public override void OnSingleClick(Mobile from)
{
LabelTo(from, 1054000,
m_Charges + (m_Inscription.Length == 0
? "\t "
: $" :\t{m_Inscription}")); // a bracelet of binding : ~1_val~ ~2_val~
$"{m_Charges}\t{m_Inscription.IsNullOrDefault(" ")}"); // a bracelet of binding : ~1_val~ ~2_val~
}
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list)

View file

@ -138,7 +138,7 @@ namespace Server.Items
protected virtual bool CheckUse(Mobile from)
{
DateTime now = DateTime.UtcNow;
// DateTime now = DateTime.UtcNow;
PlayerMobile pm = from as PlayerMobile;

View file

@ -171,10 +171,7 @@ namespace Server.Misc
if (from.Meditating)
rate *= 0.5;
if (rate < 0.5)
rate = 0.5;
else if (rate > 7.0)
rate = 7.0;
rate = Math.Clamp(rate, 0.5, 7.0);
}
return TimeSpan.FromSeconds(rate);

View file

@ -1553,7 +1553,7 @@ namespace Server.Mobiles
else if (TransferItem.IsInCombat(m_Mobile))
{
from.SendMessage("You may not transfer a pet that has recently been in combat.");
to.SendMessage("The pet may not be transfered to you because it has recently been in combat.");
to.SendMessage("The pet may not be transferred to you because it has recently been in combat.");
}
else
{
@ -2596,7 +2596,7 @@ namespace Server.Mobiles
else if (accepted && IsInCombat(m_Creature))
{
from.SendMessage("You may not transfer a pet that has recently been in combat.");
to.SendMessage("The pet may not be transfered to you because it has recently been in combat.");
to.SendMessage("The pet may not be transferred to you because it has recently been in combat.");
return false;
}

View file

@ -695,22 +695,16 @@ namespace Server.Mobiles
public override int GetMinResistance(ResistanceType type)
{
int magicResist = (int)(Skills.MagicResist.Value * 10);
int min = int.MinValue;
int min;
if (magicResist >= 1000)
min = 40 + (magicResist - 1000) / 50;
else if (magicResist >= 400)
min = (magicResist - 400) / 15;
else
min = int.MinValue;
if (min > MaxPlayerResistance)
min = MaxPlayerResistance;
int baseMin = base.GetMinResistance(type);
if (min < baseMin)
min = baseMin;
return min;
return Math.Clamp(min, base.GetMinResistance(type), MaxPlayerResistance);
}
public override void OnManaChange(int oldValue)
@ -1612,27 +1606,17 @@ namespace Server.Mobiles
m_NoRecursion = false;
}
public override bool OnMoveOver(Mobile m)
{
if (m is BaseCreature creature && !creature.Controlled)
return !Alive || !creature.Alive || IsDeadBondedPet || creature.IsDeadBondedPet ||
Hidden && AccessLevel > AccessLevel.Player;
public override bool OnMoveOver(Mobile m) =>
m is BaseCreature creature && !creature.Controlled
? !Alive || !creature.Alive || IsDeadBondedPet || creature.IsDeadBondedPet ||
Hidden && AccessLevel > AccessLevel.Player
: Region.IsPartOf<SafeZone>() && m is PlayerMobile pm &&
(pm.DuelContext == null || pm.DuelPlayer == null || !pm.DuelContext.Started || pm.DuelContext.Finished ||
pm.DuelPlayer.Eliminated) || base.OnMoveOver(m);
if (Region.IsPartOf<SafeZone>() && m is PlayerMobile pm)
if (pm.DuelContext == null || pm.DuelPlayer == null || !pm.DuelContext.Started || pm.DuelContext.Finished ||
pm.DuelPlayer.Eliminated)
return true;
return base.OnMoveOver(m);
}
public override bool CheckShove(Mobile shoved)
{
if (m_IgnoreMobiles || TransformationSpellHelper.UnderTransformation(shoved, typeof(WraithFormSpell)))
return true;
return base.CheckShove(shoved);
}
public override bool CheckShove(Mobile shoved) =>
m_IgnoreMobiles || TransformationSpellHelper.UnderTransformation(shoved, typeof(WraithFormSpell)) ||
base.CheckShove(shoved);
protected override void OnMapChange(Map oldMap)
{
@ -3210,10 +3194,7 @@ namespace Server.Mobiles
if (item.Layer == Layer.Mount)
return false;
if (item.LootType == LootType.Blessed || item.LootType == LootType.Newbied || item.BlessedFor == this)
return false;
return true;
return item.LootType != LootType.Blessed && item.LootType != LootType.Newbied && item.BlessedFor != this;
}
private void ToggleItemInsurance_Callback(Mobile from, object obj)
@ -3694,13 +3675,8 @@ namespace Server.Mobiles
return result;
}
public override bool CheckPoisonImmunity(Mobile from, Poison poison)
{
if (Young && (DuelContext?.Started != true || DuelContext.Finished))
return true;
return base.CheckPoisonImmunity(from, poison);
}
public override bool CheckPoisonImmunity(Mobile from, Poison poison) =>
Young && (DuelContext?.Started != true || DuelContext.Finished) || base.CheckPoisonImmunity(from, poison);
public override void OnPoisonImmunity(Mobile from, Poison poison)
{
@ -3997,13 +3973,7 @@ namespace Server.Mobiles
public override string ApplyNameSuffix(string suffix)
{
if (Young)
{
if (suffix.Length == 0)
suffix = "(Young)";
else
suffix = $"{suffix} (Young)";
}
if (Young) suffix = suffix.Length == 0 ? "(Young)" : $"{suffix} (Young)";
if (EthicPlayer != null)
{
@ -4020,10 +3990,7 @@ namespace Server.Mobiles
if (faction != null)
{
string adjunct = $"[{faction.Definition.Abbreviation}]";
if (suffix.Length == 0)
suffix = adjunct;
else
suffix = $"{suffix} {adjunct}";
suffix = suffix.Length == 0 ? adjunct : $"{suffix} {adjunct}";
}
}

View file

@ -838,23 +838,14 @@ namespace Server.Mobiles
if (vi == null)
return;
string name;
if (!string.IsNullOrEmpty(item.Name))
name = item.Name;
else
name = $"#{item.LabelNumber}";
string name = item.Name.IsNullOrDefault($"#{item.LabelNumber}");
from.SendLocalizedMessage(1043303, name); // Type in a price and description for ~1_ITEM~ (ESC=not for sale)
from.Prompt = new VendorPricePrompt(this, vi);
}
public override bool AllowEquipFrom(Mobile from)
{
if (BaseHouse.NewVendorSystem && IsOwner(from))
return true;
return base.AllowEquipFrom(from);
}
public override bool AllowEquipFrom(Mobile from) =>
BaseHouse.NewVendorSystem && IsOwner(from) || base.AllowEquipFrom(from);
public override bool CheckNonlocalLift(Mobile from, Item item)
{

View file

@ -35,12 +35,7 @@ namespace Server.SkillHandlers
{
if (weap.MaxHitPoints != 0)
{
int hp = (int)(weap.HitPoints / (double)weap.MaxHitPoints * 10);
if (hp < 0)
hp = 0;
else if (hp > 9)
hp = 9;
int hp = Math.Clamp((int)(weap.HitPoints / (double)weap.MaxHitPoints * 10), 0, 9);
from.SendLocalizedMessage(1038285 + hp);
}
@ -52,20 +47,6 @@ namespace Server.SkillHandlers
damage = 0;
else
damage = (int)Math.Ceiling(Math.Min(damage, 30) / 5.0);
/*
else if (damage < 6)
damage = 1;
else if (damage < 11)
damage = 2;
else if (damage < 16)
damage = 3;
else if (damage < 21)
damage = 4;
else if (damage < 26)
damage = 5;
else
damage = 6;
* */
WeaponType type = weap.Type;
@ -94,35 +75,12 @@ namespace Server.SkillHandlers
{
if (arm.MaxHitPoints != 0)
{
int hp = (int)(arm.HitPoints / (double)arm.MaxHitPoints * 10);
if (hp < 0)
hp = 0;
else if (hp > 9)
hp = 9;
int hp = Math.Clamp((int)(arm.HitPoints / (double)arm.MaxHitPoints * 10), 0, 9);
from.SendLocalizedMessage(1038285 + hp);
}
from.SendLocalizedMessage(1038295 + (int)Math.Ceiling(Math.Min(arm.ArmorRating, 35) / 5.0));
/*
if (arm.ArmorRating < 1)
from.SendLocalizedMessage( 1038295 ); // This armor offers no defense against attackers.
else if (arm.ArmorRating < 6)
from.SendLocalizedMessage( 1038296 ); // This armor provides almost no protection.
else if (arm.ArmorRating < 11)
from.SendLocalizedMessage( 1038297 ); // This armor provides very little protection.
else if (arm.ArmorRating < 16)
from.SendLocalizedMessage( 1038298 ); // This armor offers some protection against blows.
else if (arm.ArmorRating < 21)
from.SendLocalizedMessage( 1038299 ); // This armor serves as sturdy protection.
else if (arm.ArmorRating < 26)
from.SendLocalizedMessage( 1038300 ); // This armor is a superior defense against attack.
else if (arm.ArmorRating < 31)
from.SendLocalizedMessage( 1038301 ); // This armor offers excellent protection.
else
from.SendLocalizedMessage( 1038302 ); // This armor is superbly crafted to provide maximum protection.
* */
}
else
{

View file

@ -251,12 +251,7 @@ namespace Server.SkillHandlers
{
if (toSteal.Stackable && toSteal.Amount > 1)
{
int maxAmount = (int)(m_Thief.Skills.Stealing.Value / 10.0 / toSteal.Weight);
if (maxAmount < 1)
maxAmount = 1;
else if (maxAmount > toSteal.Amount)
maxAmount = toSteal.Amount;
int maxAmount = Math.Clamp((int)(m_Thief.Skills.Stealing.Value / 10.0 / toSteal.Weight), 1, toSteal.Amount);
int amount = Utility.RandomMinMax(1, maxAmount);

View file

@ -65,7 +65,7 @@ namespace Server.Spells
{
if (m.Skills[MoveSkill].Value < RequiredSkill)
{
string args = $"{RequiredSkill.ToString("F1")}\t{MoveSkill.ToString()}\t ";
string args = $"{RequiredSkill:F1}\t{MoveSkill.ToString()}\t ";
m.SendLocalizedMessage(1063013,
args); // You need at least ~1_SKILL_REQUIREMENT~ ~2_SKILL_NAME~ skill to use that ability.
return false;

View file

@ -52,7 +52,7 @@ namespace Server.Spells.Mysticism
if (Caster.Skills[CastSkill].Value < RequiredSkill)
{
Caster.SendLocalizedMessage(1063013,
$"{RequiredSkill.ToString("F1")}\t{CastSkill.ToString()}\t "); // You need at least ~1_SKILL_REQUIREMENT~ ~2_SKILL_NAME~ skill to use that ability.
$"{RequiredSkill:F1}\t{CastSkill.ToString()}\t "); // You need at least ~1_SKILL_REQUIREMENT~ ~2_SKILL_NAME~ skill to use that ability.
return false;
}
@ -75,4 +75,4 @@ namespace Server.Spells.Mysticism
public static double GetBoostSkill(Mobile m) => Math.Max(m.Skills.Imbuing.Value, m.Skills.Focus.Value);
}
}
}

View file

@ -41,7 +41,7 @@ namespace Server.Spells.Ninjitsu
if (Caster.Skills[CastSkill].Value < RequiredSkill)
{
string args = $"{RequiredSkill.ToString("F1")}\t{CastSkill.ToString()}\t ";
string args = $"{RequiredSkill:F1}\t{CastSkill.ToString()}\t ";
Caster.SendLocalizedMessage(1063013,
args); // You need at least ~1_SKILL_REQUIREMENT~ ~2_SKILL_NAME~ skill to use that ability.
return false;