fix: Fixes the limitation on static tiles for harvesting (#1396)

* fix: Fixes the limitation on static tiles for harvesting

* Fixes dirt targeting
This commit is contained in:
Kamron Batman 2023-04-22 09:14:42 -07:00 committed by GitHub
parent 79c6f0375c
commit ba4c4627c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 103 additions and 78 deletions

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Server.Items;
using Server.Random;
namespace Server.Engines.Harvest
@ -16,7 +17,9 @@ namespace Server.Engines.Harvest
public int MaxTotal { get; set; }
public int[] Tiles { get; set; }
public int[] LandTiles { get; set; }
public int[] StaticTiles { get; set; }
public bool RangedTiles { get; set; }
@ -183,13 +186,14 @@ namespace Server.Engines.Harvest
return null;
}
public bool Validate(int tileID)
public bool Validate(int tileID, bool isLand)
{
var tiles = isLand ? LandTiles : StaticTiles;
if (RangedTiles)
{
for (var i = 0; i < Tiles.Length; i += 2)
for (var i = 0; i < tiles.Length; i += 2)
{
if (tileID >= Tiles[i] && tileID <= Tiles[i + 1])
if (tileID >= tiles[i] && tileID <= tiles[i + 1])
{
return true;
}
@ -198,9 +202,9 @@ namespace Server.Engines.Harvest
return false;
}
for (var i = 0; i < Tiles.Length; ++i)
for (var i = 0; i < tiles.Length; ++i)
{
if (Tiles[i] == tileID)
if (tiles[i] == tileID)
{
return true;
}

View file

@ -85,13 +85,13 @@ namespace Server.Engines.Harvest
return;
}
if (!GetHarvestDetails(from, tool, toHarvest, out var tileID, out var map, out var loc))
if (!GetHarvestDetails(from, tool, toHarvest, out var tileID, out var map, out var loc, out var isLand))
{
OnBadHarvestTarget(from, tool, toHarvest);
return;
}
if (!def.Validate(tileID))
if (!def.Validate(tileID, isLand))
{
OnBadHarvestTarget(from, tool, toHarvest);
return;
@ -367,14 +367,14 @@ namespace Server.Engines.Harvest
return false;
}
if (!GetHarvestDetails(from, tool, toHarvest, out var tileID, out var map, out var loc))
if (!GetHarvestDetails(from, tool, toHarvest, out var tileID, out var map, out var loc, out var isLand))
{
from.EndAction(locked);
OnBadHarvestTarget(from, tool, toHarvest);
return false;
}
if (!def.Validate(tileID))
if (!def.Validate(tileID, isLand))
{
from.EndAction(locked);
OnBadHarvestTarget(from, tool, toHarvest);
@ -423,13 +423,13 @@ namespace Server.Engines.Harvest
public virtual HarvestDefinition GetDefinition() => Definitions[0];
public virtual HarvestDefinition GetDefinition(int tileID)
public virtual HarvestDefinition GetDefinition(int tileID, bool isLand)
{
for (var i = 0; i < Definitions.Length; i++)
{
var check = Definitions[i];
if (check.Validate(tileID))
if (check.Validate(tileID, isLand))
{
return check;
}
@ -445,13 +445,13 @@ namespace Server.Engines.Harvest
return;
}
if (!GetHarvestDetails(from, tool, toHarvest, out var tileID, out var map, out var loc))
if (!GetHarvestDetails(from, tool, toHarvest, out var tileID, out var map, out var loc, out var isLand))
{
OnBadHarvestTarget(from, tool, toHarvest);
return;
}
var def = GetDefinition(tileID);
var def = GetDefinition(tileID, isLand);
if (def == null)
{
@ -487,33 +487,36 @@ namespace Server.Engines.Harvest
}
public virtual bool GetHarvestDetails(
Mobile from, Item tool, object toHarvest, out int tileID, out Map map,
out Point3D loc
Mobile from, Item tool, object toHarvest, out int tileID, out Map map, out Point3D loc, out bool isLand
)
{
if (toHarvest is Static staticObj && !staticObj.Movable)
if (toHarvest is Static { Movable: false } staticObj)
{
tileID = (staticObj.ItemID & 0x3FFF) | 0x4000;
tileID = staticObj.ItemID;
map = staticObj.Map;
loc = staticObj.GetWorldLocation();
isLand = false;
}
else if (toHarvest is StaticTarget staticTarget)
{
tileID = (staticTarget.ItemID & 0x3FFF) | 0x4000;
tileID = staticTarget.ItemID;
map = from.Map;
loc = staticTarget.Location;
isLand = false;
}
else if (toHarvest is LandTarget landTarget)
{
tileID = landTarget.TileID;
map = from.Map;
loc = landTarget.Location;
isLand = true;
}
else
{
tileID = 0;
map = null;
loc = Point3D.Zero;
isLand = false;
return false;
}

View file

@ -10,9 +10,9 @@ namespace Server.Engines.Harvest
{
public class Fishing : HarvestSystem
{
private static Fishing m_System;
private static Fishing _system;
private static readonly MutateEntry[] m_MutateTable =
private static readonly MutateEntry[] _mutateTable =
{
new(80.0, 80.0, 4080.0, true, typeof(SpecialFishingNet)),
new(80.0, 80.0, 4080.0, true, typeof(BigFish)),
@ -32,14 +32,18 @@ namespace Server.Engines.Harvest
new(0.0, 200.0, -200.0, false, new Type[] { null })
};
private static readonly int[] m_WaterTiles =
private static readonly int[] _waterLandTiles =
{
0x00A8, 0x00AB,
0x0136, 0x0137,
0x5797, 0x579C,
0x746E, 0x7485,
0x7490, 0x74AB,
0x74B5, 0x75D5
0x0136, 0x0137
};
private static readonly int[] waterStaticTiles =
{
0x1797, 0x179C,
0x346E, 0x3485,
0x3490, 0x34AB,
0x34B5, 0x35D5
};
private Fishing()
@ -53,7 +57,8 @@ namespace Server.Engines.Harvest
MinRespawn = TimeSpan.FromMinutes(10.0),
MaxRespawn = TimeSpan.FromMinutes(20.0),
Skill = SkillName.Fishing,
Tiles = m_WaterTiles,
LandTiles = _waterLandTiles,
StaticTiles = waterStaticTiles,
RangedTiles = true,
MaxRange = 4,
ConsumedPerHarvest = 1,
@ -96,7 +101,7 @@ namespace Server.Engines.Harvest
Definitions = new[] { fish };
}
public static Fishing System => m_System ?? (m_System = new Fishing());
public static Fishing System => _system ?? (_system = new Fishing());
public override void OnConcurrentHarvest(Mobile from, Item tool, HarvestDefinition def, object toHarvest)
{
@ -145,9 +150,9 @@ namespace Server.Engines.Harvest
var skillBase = from.Skills.Fishing.Base;
var skillValue = from.Skills.Fishing.Value;
for (var i = 0; i < m_MutateTable.Length; ++i)
for (var i = 0; i < _mutateTable.Length; ++i)
{
var entry = m_MutateTable[i];
var entry = _mutateTable[i];
if (!deepWater && entry.m_DeepWater)
{
@ -479,7 +484,7 @@ namespace Server.Engines.Harvest
{
base.OnHarvestStarted(from, tool, def, toHarvest);
if (GetHarvestDetails(from, tool, toHarvest, out _, out var map, out var loc))
if (GetHarvestDetails(from, tool, toHarvest, out _, out var map, out var loc, out _))
{
Timer.StartTimer(
TimeSpan.FromSeconds(1.5),

View file

@ -10,27 +10,27 @@ namespace Server.Engines.Harvest
private static readonly int[] m_TreeTiles =
{
0x4CCA, 0x4CCB, 0x4CCC, 0x4CCD, 0x4CD0, 0x4CD3, 0x4CD6, 0x4CD8,
0x4CDA, 0x4CDD, 0x4CE0, 0x4CE3, 0x4CE6, 0x4CF8, 0x4CFB, 0x4CFE,
0x4D01, 0x4D41, 0x4D42, 0x4D43, 0x4D44, 0x4D57, 0x4D58, 0x4D59,
0x4D5A, 0x4D5B, 0x4D6E, 0x4D6F, 0x4D70, 0x4D71, 0x4D72, 0x4D84,
0x4D85, 0x4D86, 0x52B5, 0x52B6, 0x52B7, 0x52B8, 0x52B9, 0x52BA,
0x52BB, 0x52BC, 0x52BD,
0x0CCA, 0x0CCB, 0x0CCC, 0x0CCD, 0x0CD0, 0x0CD3, 0x0CD6, 0x0CD8,
0x0CDA, 0x0CDD, 0x0CE0, 0x0CE3, 0x0CE6, 0x0CF8, 0x0CFB, 0x0CFE,
0x0D01, 0x0D41, 0x0D42, 0x0D43, 0x0D44, 0x0D57, 0x0D58, 0x0D59,
0x0D5A, 0x0D5B, 0x0D6E, 0x0D6F, 0x0D70, 0x0D71, 0x0D72, 0x0D84,
0x0D85, 0x0D86, 0x12B5, 0x12B6, 0x12B7, 0x12B8, 0x12B9, 0x12BA,
0x12BB, 0x12BC, 0x12BD,
0x4CCE, 0x4CCF, 0x4CD1, 0x4CD2, 0x4CD4, 0x4CD5, 0x4CD7, 0x4CD9,
0x4CDB, 0x4CDC, 0x4CDE, 0x4CDF, 0x4CE1, 0x4CE2, 0x4CE4, 0x4CE5,
0x4CE7, 0x4CE8, 0x4CF9, 0x4CFA, 0x4CFC, 0x4CFD, 0x4CFF, 0x4D00,
0x4D02, 0x4D03, 0x4D45, 0x4D46, 0x4D47, 0x4D48, 0x4D49, 0x4D4A,
0x4D4B, 0x4D4C,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7C, 0x0D7D, 0x0D7E, 0x0D7F, 0x0D87, 0x0D88, 0x0D89, 0x0D8A,
0x0D8B, 0x0D8C, 0x0D8D, 0x0D8E, 0x0D8F, 0x0D90, 0x0D95, 0x0D96,
0x0D97, 0x0D99, 0x0D9A, 0x0D9B, 0x0D9D, 0x0D9E, 0x0D9F, 0x0DA1,
0x0DA2, 0x0DA3, 0x0DA5, 0x0DA6, 0x0DA7, 0x0DA9, 0x0DAA, 0x0DAB,
0x12BE, 0x12BF, 0x12C0, 0x12C1, 0x12C2, 0x12C3, 0x12C4, 0x12C5,
0x12C6, 0x12C7
};
private Lumberjacking()
@ -47,7 +47,8 @@ namespace Server.Engines.Harvest
MinRespawn = TimeSpan.FromMinutes(20.0),
MaxRespawn = TimeSpan.FromMinutes(30.0),
Skill = SkillName.Lumberjacking,
Tiles = m_TreeTiles,
LandTiles = Array.Empty<int>(),
StaticTiles = m_TreeTiles,
MaxRange = 2,
ConsumedPerHarvest = 10,
ConsumedPerFeluccaHarvest = 20,
@ -157,12 +158,8 @@ namespace Server.Engines.Harvest
{
if (toHarvest is Mobile mobile)
{
mobile.PrivateOverheadMessage(
MessageType.Regular,
0x3B2,
500450, // You can only skin dead creatures.
from.NetState
);
// You can only skin dead creatures.
mobile.PrivateOverheadMessage(MessageType.Regular, 0x3B2, 500450, from.NetState);
}
else if (toHarvest is Item item)
{

View file

@ -8,9 +8,9 @@ namespace Server.Engines.Harvest
{
public class Mining : HarvestSystem
{
private static Mining m_System;
private static Mining _system;
private static readonly int[] m_Offsets =
private static readonly int[] _offsets =
{
-1, -1,
-1, 0,
@ -47,9 +47,12 @@ namespace Server.Engines.Harvest
0x3F39, 0x3F74,
0x3F82, 0x3F8F,
0x3F91, 0x3FCF,
0x3F91, 0x3FCF
};
0x453B, 0x454F,
private static readonly int[] _mountainCaveStaticTiles =
{
0x053B, 0x054F,
};
private static readonly int[] _sandTiles =
@ -88,7 +91,8 @@ namespace Server.Engines.Harvest
MinRespawn = TimeSpan.FromMinutes(10.0),
MaxRespawn = TimeSpan.FromMinutes(20.0),
Skill = SkillName.Mining,
Tiles = _mountainCaveTiles,
LandTiles = _mountainCaveTiles,
StaticTiles = _mountainCaveStaticTiles,
RangedTiles = true,
MaxRange = 2,
ConsumedPerHarvest = 1,
@ -226,7 +230,8 @@ namespace Server.Engines.Harvest
MinRespawn = TimeSpan.FromMinutes(10.0),
MaxRespawn = TimeSpan.FromMinutes(20.0),
Skill = SkillName.Mining,
Tiles = _sandTiles,
LandTiles = _sandTiles,
StaticTiles = Array.Empty<int>(),
RangedTiles = true,
MaxRange = 2,
ConsumedPerHarvest = 1,
@ -261,7 +266,7 @@ namespace Server.Engines.Harvest
Definitions = new[] { OreAndStone, Sand };
}
public static Mining System => m_System ?? (m_System = new Mining());
public static Mining System => _system ?? (_system = new Mining());
public HarvestDefinition OreAndStone { get; }
@ -395,10 +400,10 @@ namespace Server.Engines.Harvest
{
var offset = Utility.Random(8) * 2;
for (var i = 0; i < m_Offsets.Length; i += 2)
for (var i = 0; i < _offsets.Length; i += 2)
{
var x = from.X + m_Offsets[(offset + i) % m_Offsets.Length];
var y = from.Y + m_Offsets[(offset + i + 1) % m_Offsets.Length];
var x = from.X + _offsets[(offset + i) % _offsets.Length];
var y = from.Y + _offsets[(offset + i + 1) % _offsets.Length];
if (map.CanSpawnMobile(x, y, from.Z))
{

View file

@ -5,7 +5,7 @@ namespace Server.Engines.Plants
{
public class PlantBowl : Item
{
private static readonly int[] m_DirtPatchTiles =
private static readonly int[] _dirtPatchLandTiles =
{
0x9, 0x15,
0x71, 0x7C,
@ -46,6 +46,13 @@ namespace Server.Engines.Plants
0x72C9, 0x72CA
};
private static readonly int[] _dirtPatchStaticTiles =
{
0x1B27, 0x1B3E,
0x31F4, 0x31FB,
0x32C9, 0x32CA
};
[Constructible]
public PlantBowl() : base(0x15FD) => Weight = 1.0;
@ -84,18 +91,22 @@ namespace Server.Engines.Plants
public static bool IsDirtPatch(object obj)
{
int tileID;
int[] tiles;
if (obj is Static staticObj && !staticObj.Movable)
{
tileID = (staticObj.ItemID & 0x3FFF) | 0x4000;
tileID = staticObj.ItemID;
tiles = _dirtPatchStaticTiles;
}
else if (obj is StaticTarget staticTarget)
{
tileID = (staticTarget.ItemID & 0x3FFF) | 0x4000;
tileID = staticTarget.ItemID;
tiles = _dirtPatchStaticTiles;
}
else if (obj is LandTarget landTarget)
{
tileID = landTarget.TileID;
tiles = _dirtPatchLandTiles;
}
else
{
@ -104,9 +115,9 @@ namespace Server.Engines.Plants
var contains = false;
for (var i = 0; !contains && i < m_DirtPatchTiles.Length; i += 2)
for (var i = 0; !contains && i < tiles.Length; i += 2)
{
contains = tileID >= m_DirtPatchTiles[i] && tileID <= m_DirtPatchTiles[i + 1];
contains = tileID >= tiles[i] && tileID <= tiles[i + 1];
}
return contains;

View file

@ -63,13 +63,13 @@ public partial class ProspectorsTool : BaseBashing, IUsesRemaining
HarvestSystem system = Mining.System;
if (!system.GetHarvestDetails(from, this, toProspect, out var tileID, out var map, out var loc))
if (!system.GetHarvestDetails(from, this, toProspect, out var tileID, out var map, out var loc, out var isLand))
{
from.SendLocalizedMessage(1049048); // You cannot use your prospector tool on that.
return;
}
var def = system.GetDefinition(tileID);
var def = system.GetDefinition(tileID, isLand);
if (def == null || def.Veins.Length <= 1)
{

View file

@ -74,11 +74,11 @@ namespace Server.Targets
HarvestSystem system = Lumberjacking.System;
var def = system.GetDefinition();
if (!system.GetHarvestDetails(from, m_Item, targeted, out var tileID, out var map, out var loc))
if (!system.GetHarvestDetails(from, m_Item, targeted, out var tileID, out var map, out var loc, out var isLand))
{
from.SendLocalizedMessage(500494); // You can't use a bladed item on that!
}
else if (!def.Validate(tileID))
else if (!def.Validate(tileID, isLand))
{
from.SendLocalizedMessage(500494); // You can't use a bladed item on that!
}