Clean up: Bugs, LINQ, constructors, default values, and null checks (#18)

This commit is contained in:
Kamron Batman 2019-03-11 14:29:59 -07:00 • committed by GitHub
parent e748af4430
commit 513e54f70e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1094 changed files with 15913 additions and 21892 deletions

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Server.Items;
using Server.Targeting;
@ -16,7 +17,7 @@ namespace Server.Engines.Harvest
public virtual bool CheckTool(Mobile from, Item tool)
{
bool wornOut = tool == null || tool.Deleted || tool is IUsesRemaining remaining && remaining.UsesRemaining <= 0;
bool wornOut = tool?.Deleted != false || tool is IUsesRemaining remaining && remaining.UsesRemaining <= 0;
if (wornOut)
from.SendLocalizedMessage(1044038); // You have worn out your tool!
@ -47,7 +48,7 @@ namespace Server.Engines.Harvest
public virtual bool CheckResources(Mobile from, Item tool, HarvestDefinition def, Map map, Point3D loc, bool timed)
{
HarvestBank bank = def.GetBank(map, loc.X, loc.Y);
bool available = bank != null && bank.Current >= def.ConsumedPerHarvest;
bool available = bank?.Current >= def.ConsumedPerHarvest;
if (!available)
def.SendMessageTo(from, timed ? def.DoubleHarvestMessage : def.NoResourcesMessage);
@ -136,7 +137,7 @@ namespace Server.Engines.Harvest
HarvestResource resource = MutateResource(from, tool, def, map, loc, vein, primary, fallback);
double skillBase = from.Skills[def.Skill].Base;
double skillValue = from.Skills[def.Skill].Value;
// double skillValue = from.Skills[def.Skill].Value;
Type type = null;
@ -194,7 +195,7 @@ namespace Server.Engines.Harvest
BonusHarvestResource bonus = def.GetBonusResource();
if (bonus != null && bonus.Type != null && skillBase >= bonus.ReqSkill)
if (bonus?.Type != null && skillBase >= bonus.ReqSkill)
{
Item bonusItem = Construct(bonus.Type, from);
@ -279,18 +280,8 @@ namespace Server.Engines.Harvest
if (map == null)
return false;
List<Item> atFeet = new List<Item>();
foreach (Item obj in m.GetItemsInRange(0))
atFeet.Add(obj);
for (int i = 0; i < atFeet.Count; ++i)
{
Item check = atFeet[i];
if (check.StackWith(m, item, false))
return true;
}
if (m.GetItemsInRange(0).Any(t => t.StackWith(m, item, false)))
return true;
item.MoveToWorld(m.Location, map);
return true;
@ -305,10 +296,7 @@ namespace Server.Engines.Harvest
public virtual Type GetResourceType(Mobile from, Item tool, HarvestDefinition def, Map map, Point3D loc,
HarvestResource resource)
{
if (resource.Types.Length > 0)
return resource.Types[Utility.Random(resource.Types.Length)];
return null;
return resource.Types.Length > 0 ? resource.Types[Utility.Random(resource.Types.Length)] : null;
}
public virtual HarvestResource MutateResource(Mobile from, Item tool, HarvestDefinition def, Map map, Point3D loc,
@ -391,17 +379,7 @@ namespace Server.Engines.Harvest
public virtual HarvestDefinition GetDefinition(int tileID)
{
HarvestDefinition def = null;
for (int i = 0; def == null && i < Definitions.Count; ++i)
{
HarvestDefinition check = Definitions[i];
if (check.Validate(tileID))
def = check;
}
return def;
return Definitions.FirstOrDefault(check => check.Validate(tileID));
}
public virtual void StartHarvesting(Mobile from, Item tool, object toHarvest)
@ -488,7 +466,7 @@ namespace Server
{
public static bool Check(Item item)
{
return item != null && item.GetType().IsDefined(typeof(FurnitureAttribute), false);
return item?.GetType().IsDefined(typeof(FurnitureAttribute), false) == true;
}
}
}
}

View file

@ -38,60 +38,38 @@ namespace Server.Engines.Harvest
private Fishing()
{
HarvestResource[] res;
HarvestVein[] veins;
#region Fishing
HarvestDefinition fish = new HarvestDefinition();
// Resource banks are every 8x8 tiles
fish.BankWidth = 8;
fish.BankHeight = 8;
// Every bank holds from 5 to 15 fish
fish.MinTotal = 5;
fish.MaxTotal = 15;
// A resource bank will respawn its content every 10 to 20 minutes
fish.MinRespawn = TimeSpan.FromMinutes(10.0);
fish.MaxRespawn = TimeSpan.FromMinutes(20.0);
// Skill checking is done on the Fishing skill
fish.Skill = SkillName.Fishing;
// Set the list of harvestable tiles
fish.Tiles = m_WaterTiles;
fish.RangedTiles = true;
// Players must be within 4 tiles to harvest
fish.MaxRange = 4;
// One fish per harvest action
fish.ConsumedPerHarvest = 1;
fish.ConsumedPerFeluccaHarvest = 1;
// The fishing
fish.EffectActions = new[] { 12 };
fish.EffectSounds = new int[0];
fish.EffectCounts = new[] { 1 };
fish.EffectDelay = TimeSpan.Zero;
fish.EffectSoundDelay = TimeSpan.FromSeconds(8.0);
fish.NoResourcesMessage = 503172; // The fish don't seem to be biting here.
fish.FailMessage = 503171; // You fish a while, but fail to catch anything.
fish.TimedOutOfRangeMessage = 500976; // You need to be closer to the water to fish!
fish.OutOfRangeMessage = 500976; // You need to be closer to the water to fish!
fish.PackFullMessage = 503176; // You do not have room in your backpack for a fish.
fish.ToolBrokeMessage = 503174; // You broke your fishing pole.
res = new[]
HarvestDefinition fish = new HarvestDefinition
{
BankWidth = 8,
BankHeight = 8,
MinTotal = 5,
MaxTotal = 15,
MinRespawn = TimeSpan.FromMinutes(10.0),
MaxRespawn = TimeSpan.FromMinutes(20.0),
Skill = SkillName.Fishing,
Tiles = m_WaterTiles,
RangedTiles = true,
MaxRange = 4,
ConsumedPerHarvest = 1,
ConsumedPerFeluccaHarvest = 1,
EffectActions = new[] { 12 },
EffectSounds = new int[0],
EffectCounts = new[] { 1 },
EffectDelay = TimeSpan.Zero,
EffectSoundDelay = TimeSpan.FromSeconds(8.0),
NoResourcesMessage = 503172, // The fish don't seem to be biting here.
FailMessage = 503171, // You fish a while, but fail to catch anything.
TimedOutOfRangeMessage = 500976, // You need to be closer to the water to fish!
OutOfRangeMessage = 500976, // You need to be closer to the water to fish!
PackFullMessage = 503176, // You do not have room in your backpack for a fish.
ToolBrokeMessage = 503174 // You broke your fishing pole.
};
HarvestResource[] res = {
new HarvestResource(00.0, 00.0, 100.0, 1043297, typeof(Fish))
};
veins = new[]
{
HarvestVein[] veins = {
new HarvestVein(100.0, 0.0, res[0], null)
};
@ -107,20 +85,9 @@ namespace Server.Engines.Harvest
Definition = fish;
Definitions.Add(fish);
#endregion
}
public static Fishing System
{
get
{
if (m_System == null)
m_System = new Fishing();
return m_System;
}
}
public static Fishing System => m_System ?? (m_System = new Fishing());
public HarvestDefinition Definition{ get; }
@ -191,10 +158,7 @@ namespace Server.Engines.Harvest
private static Map SafeMap(Map map)
{
if (map == null || map == Map.Internal)
return Map.Trammel;
return map;
return map == null || map == Map.Internal ? Map.Trammel : map;
}
public override bool CheckResources(Mobile from, Item tool, HarvestDefinition def, Map map, Point3D loc, bool timed)
@ -324,10 +288,7 @@ namespace Server.Engines.Harvest
TreasureMapChest.Fill(chest, Math.Max(1, Math.Min(4, sos.Level)));
if (sos.IsAncient)
chest.DropItem(new FabledFishingNet());
else
chest.DropItem(new SpecialFishingNet());
chest.DropItem(sos.IsAncient ? new FabledFishingNet() : new SpecialFishingNet());
chest.Movable = true;
chest.Locked = false;
@ -388,10 +349,7 @@ namespace Server.Engines.Harvest
return true; // we don't want to give the item to the player, it's on the serpent
}
if (item is BigFish || item is WoodenChest || item is MetalGoldenChest)
placeAtFeet = true;
return base.Give(m, item, placeAtFeet);
return base.Give(m, item, placeAtFeet || item is BigFish || item is WoodenChest || item is MetalGoldenChest);
}
public override void SendSuccessTo(Mobile from, Item item, HarvestResource resource)
@ -547,4 +505,4 @@ namespace Server.Engines.Harvest
}
}
}
}
}

View file

@ -43,47 +43,30 @@ namespace Server.Engines.Harvest
HarvestResource[] res;
HarvestVein[] veins;
#region Lumberjacking
HarvestDefinition lumber = new HarvestDefinition();
// Resource banks are every 4x3 tiles
lumber.BankWidth = 4;
lumber.BankHeight = 3;
// Every bank holds from 20 to 45 logs
lumber.MinTotal = 20;
lumber.MaxTotal = 45;
// A resource bank will respawn its content every 20 to 30 minutes
lumber.MinRespawn = TimeSpan.FromMinutes(20.0);
lumber.MaxRespawn = TimeSpan.FromMinutes(30.0);
// Skill checking is done on the Lumberjacking skill
lumber.Skill = SkillName.Lumberjacking;
// Set the list of harvestable tiles
lumber.Tiles = m_TreeTiles;
// Players must be within 2 tiles to harvest
lumber.MaxRange = 2;
// Ten logs per harvest action
lumber.ConsumedPerHarvest = 10;
lumber.ConsumedPerFeluccaHarvest = 20;
// The chopping effect
lumber.EffectActions = new[] { 13 };
lumber.EffectSounds = new[] { 0x13E };
lumber.EffectCounts = Core.AOS ? new[] { 1 } : new[] { 1, 2, 2, 2, 3 };
lumber.EffectDelay = TimeSpan.FromSeconds(1.6);
lumber.EffectSoundDelay = TimeSpan.FromSeconds(0.9);
lumber.NoResourcesMessage = 500493; // There's not enough wood here to harvest.
lumber.FailMessage = 500495; // You hack at the tree for a while, but fail to produce any useable wood.
lumber.OutOfRangeMessage = 500446; // That is too far away.
lumber.PackFullMessage = 500497; // You can't place any wood into your backpack!
lumber.ToolBrokeMessage = 500499; // You broke your axe.
HarvestDefinition lumber = new HarvestDefinition
{
BankWidth = 4,
BankHeight = 3,
MinTotal = 20,
MaxTotal = 45,
MinRespawn = TimeSpan.FromMinutes(20.0),
MaxRespawn = TimeSpan.FromMinutes(30.0),
Skill = SkillName.Lumberjacking,
Tiles = m_TreeTiles,
MaxRange = 2,
ConsumedPerHarvest = 10,
ConsumedPerFeluccaHarvest = 20,
EffectActions = new[] { 13 },
EffectSounds = new[] { 0x13E },
EffectCounts = Core.AOS ? new[] { 1 } : new[] { 1, 2, 2, 2, 3 },
EffectDelay = TimeSpan.FromSeconds(1.6),
EffectSoundDelay = TimeSpan.FromSeconds(0.9),
NoResourcesMessage = 500493, // There's not enough wood here to harvest.
FailMessage = 500495, // You hack at the tree for a while, but fail to produce any useable wood.
OutOfRangeMessage = 500446, // That is too far away.
PackFullMessage = 500497, // You can't place any wood into your backpack!
ToolBrokeMessage = 500499 // You broke your axe.
};
if (Core.ML)
{
@ -141,20 +124,9 @@ namespace Server.Engines.Harvest
Definition = lumber;
Definitions.Add(lumber);
#endregion
}
public static Lumberjacking System
{
get
{
if (m_System == null)
m_System = new Lumberjacking();
return m_System;
}
}
public static Lumberjacking System => m_System ?? (m_System = new Lumberjacking());
public HarvestDefinition Definition{ get; }
@ -212,4 +184,4 @@ namespace Server.Engines.Harvest
Array.Sort(m_TreeTiles);
}
}
}
}

View file

@ -23,55 +23,36 @@ namespace Server.Engines.Harvest
private Mining()
{
HarvestResource[] res;
HarvestVein[] veins;
#region Mining for ore and stone
HarvestDefinition oreAndStone = OreAndStone = new HarvestDefinition();
// Resource banks are every 8x8 tiles
oreAndStone.BankWidth = 8;
oreAndStone.BankHeight = 8;
// Every bank holds from 10 to 34 ore
oreAndStone.MinTotal = 10;
oreAndStone.MaxTotal = 34;
// A resource bank will respawn its content every 10 to 20 minutes
oreAndStone.MinRespawn = TimeSpan.FromMinutes(10.0);
oreAndStone.MaxRespawn = TimeSpan.FromMinutes(20.0);
// Skill checking is done on the Mining skill
oreAndStone.Skill = SkillName.Mining;
// Set the list of harvestable tiles
oreAndStone.Tiles = m_MountainAndCaveTiles;
// Players must be within 2 tiles to harvest
oreAndStone.MaxRange = 2;
// One ore per harvest action
oreAndStone.ConsumedPerHarvest = 1;
oreAndStone.ConsumedPerFeluccaHarvest = 2;
// The digging effect
oreAndStone.EffectActions = new[] { 11 };
oreAndStone.EffectSounds = new[] { 0x125, 0x126 };
oreAndStone.EffectCounts = new[] { 1 };
oreAndStone.EffectDelay = TimeSpan.FromSeconds(1.6);
oreAndStone.EffectSoundDelay = TimeSpan.FromSeconds(0.9);
oreAndStone.NoResourcesMessage = 503040; // There is no metal here to mine.
oreAndStone.DoubleHarvestMessage = 503042; // Someone has gotten to the metal before you.
oreAndStone.TimedOutOfRangeMessage = 503041; // You have moved too far away to continue mining.
oreAndStone.OutOfRangeMessage = 500446; // That is too far away.
oreAndStone.FailMessage = 503043; // You loosen some rocks but fail to find any useable ore.
oreAndStone.PackFullMessage = 1010481; // Your backpack is full, so the ore you mined is lost.
oreAndStone.ToolBrokeMessage = 1044038; // You have worn out your tool!
res = new[]
OreAndStone = new HarvestDefinition
{
BankWidth = 8,
BankHeight = 8,
MinTotal = 10,
MaxTotal = 34,
MinRespawn = TimeSpan.FromMinutes(10.0),
MaxRespawn = TimeSpan.FromMinutes(20.0),
Skill = SkillName.Mining,
Tiles = m_MountainAndCaveTiles,
MaxRange = 2,
ConsumedPerHarvest = 1,
ConsumedPerFeluccaHarvest = 2,
EffectActions = new[] { 11 },
EffectSounds = new[] { 0x125, 0x126 },
EffectCounts = new[] { 1 },
EffectDelay = TimeSpan.FromSeconds(1.6),
EffectSoundDelay = TimeSpan.FromSeconds(0.9),
NoResourcesMessage = 503040, // There is no metal here to mine.
DoubleHarvestMessage = 503042, // Someone has gotten to the metal before you.
TimedOutOfRangeMessage = 503041, // You have moved too far away to continue mining.
OutOfRangeMessage = 500446, // That is too far away.
FailMessage = 503043, // You loosen some rocks but fail to find any useable ore.
PackFullMessage = 1010481, // Your backpack is full, so the ore you mined is lost.
ToolBrokeMessage = 1044038 // You have worn out your tool!
};
HarvestResource[] res = {
new HarvestResource(00.0, 00.0, 100.0, 1007072, typeof(IronOre), typeof(Granite)),
new HarvestResource(65.0, 25.0, 105.0, 1007073, typeof(DullCopperOre), typeof(DullCopperGranite),
typeof(DullCopperElemental)),
@ -91,8 +72,7 @@ namespace Server.Engines.Harvest
typeof(ValoriteElemental))
};
veins = new[]
{
HarvestVein[] veins = {
new HarvestVein(49.6, 0.0, res[0], null), // Iron
new HarvestVein(11.2, 0.5, res[1], res[0]), // Dull Copper
new HarvestVein(09.8, 0.5, res[2], res[0]), // Shadow Iron
@ -104,11 +84,11 @@ namespace Server.Engines.Harvest
new HarvestVein(01.4, 0.5, res[8], res[0]) // Valorite
};
oreAndStone.Resources = res;
oreAndStone.Veins = veins;
OreAndStone.Resources = res;
OreAndStone.Veins = veins;
if (Core.ML)
oreAndStone.BonusResources = new[]
OreAndStone.BonusResources = new[]
{
new BonusHarvestResource(0, 99.4, null, null), //Nothing
new BonusHarvestResource(100, .1, 1072562, typeof(BlueDiamond)),
@ -119,56 +99,41 @@ namespace Server.Engines.Harvest
new BonusHarvestResource(100, .1, 1072568, typeof(Turquoise))
};
oreAndStone.RaceBonus = Core.ML;
oreAndStone.RandomizeVeins = Core.ML;
OreAndStone.RaceBonus = Core.ML;
OreAndStone.RandomizeVeins = Core.ML;
Definitions.Add(oreAndStone);
Definitions.Add(OreAndStone);
#endregion
#region Mining for sand
HarvestDefinition sand = Sand = new HarvestDefinition();
// Resource banks are every 8x8 tiles
sand.BankWidth = 8;
sand.BankHeight = 8;
// Every bank holds from 6 to 12 sand
sand.MinTotal = 6;
sand.MaxTotal = 12;
// A resource bank will respawn its content every 10 to 20 minutes
sand.MinRespawn = TimeSpan.FromMinutes(10.0);
sand.MaxRespawn = TimeSpan.FromMinutes(20.0);
// Skill checking is done on the Mining skill
sand.Skill = SkillName.Mining;
// Set the list of harvestable tiles
sand.Tiles = m_SandTiles;
// Players must be within 2 tiles to harvest
sand.MaxRange = 2;
// One sand per harvest action
sand.ConsumedPerHarvest = 1;
sand.ConsumedPerFeluccaHarvest = 1;
// The digging effect
sand.EffectActions = new[] { 11 };
sand.EffectSounds = new[] { 0x125, 0x126 };
sand.EffectCounts = new[] { 6 };
sand.EffectDelay = TimeSpan.FromSeconds(1.6);
sand.EffectSoundDelay = TimeSpan.FromSeconds(0.9);
sand.NoResourcesMessage = 1044629; // There is no sand here to mine.
sand.DoubleHarvestMessage = 1044629; // There is no sand here to mine.
sand.TimedOutOfRangeMessage = 503041; // You have moved too far away to continue mining.
sand.OutOfRangeMessage = 500446; // That is too far away.
sand.FailMessage = 1044630; // You dig for a while but fail to find any of sufficient quality for glassblowing.
sand.PackFullMessage = 1044632; // Your backpack can't hold the sand, and it is lost!
sand.ToolBrokeMessage = 1044038; // You have worn out your tool!
Sand = new HarvestDefinition
{
BankWidth = 8,
BankHeight = 8,
MinTotal = 6,
MaxTotal = 12,
MinRespawn = TimeSpan.FromMinutes(10.0),
MaxRespawn = TimeSpan.FromMinutes(20.0),
Skill = SkillName.Mining,
Tiles = m_SandTiles,
MaxRange = 2,
ConsumedPerHarvest = 1,
ConsumedPerFeluccaHarvest = 1,
EffectActions = new[] { 11 },
EffectSounds = new[] { 0x125, 0x126 },
EffectCounts = new[] { 6 },
EffectDelay = TimeSpan.FromSeconds(1.6),
EffectSoundDelay = TimeSpan.FromSeconds(0.9),
NoResourcesMessage = 1044629, // There is no sand here to mine.
DoubleHarvestMessage = 1044629, // There is no sand here to mine.
TimedOutOfRangeMessage = 503041, // You have moved too far away to continue mining.
OutOfRangeMessage = 500446, // That is too far away.
FailMessage = 1044630, // You dig for a while but fail to find any of sufficient quality for glassblowing.
PackFullMessage = 1044632, // Your backpack can't hold the sand, and it is lost!
ToolBrokeMessage = 1044038 // You have worn out your tool!
};
res = new[]
{
@ -180,24 +145,15 @@ namespace Server.Engines.Harvest
new HarvestVein(100.0, 0.0, res[0], null)
};
sand.Resources = res;
sand.Veins = veins;
Sand.Resources = res;
Sand.Veins = veins;
Definitions.Add(sand);
Definitions.Add(Sand);
#endregion
}
public static Mining System
{
get
{
if (m_System == null)
m_System = new Mining();
return m_System;
}
}
public static Mining System => m_System ?? (m_System = new Mining());
public HarvestDefinition OreAndStone{ get; }
@ -206,16 +162,16 @@ namespace Server.Engines.Harvest
public override Type GetResourceType(Mobile from, Item tool, HarvestDefinition def, Map map, Point3D loc,
HarvestResource resource)
{
if (def == OreAndStone)
{
if (from is PlayerMobile pm && pm.StoneMining && pm.ToggleMiningStone &&
from.Skills.Mining.Base >= 100.0 && 0.1 > Utility.RandomDouble())
return resource.Types[1];
if (def != OreAndStone)
return base.GetResourceType(from, tool, def, map, loc, resource);
return resource.Types[0];
}
return base.GetResourceType(from, tool, def, map, loc, resource);
if (from.Skills.Mining.Base >= 100.0 && from is PlayerMobile pm && pm.StoneMining && pm.ToggleMiningStone
&& 0.1 > Utility.RandomDouble())
return resource.Types[1];
return resource.Types[0];
}
public override bool CheckHarvest(Mobile from, Item tool)
@ -337,6 +293,7 @@ namespace Server.Engines.Harvest
}
catch
{
// ignored
}
}
}
@ -434,4 +391,4 @@ namespace Server.Engines.Harvest
#endregion
}
}
}