## MAJOR CHANGE (API BREAKING) Moved the virtues to it's own system _VirtueSystem_. This should make it easier to extend or remove the virtue system. Virtues will be saved to a new folder called _Virtues_. ### Motivation The motivation was also two-fold, performance/stability, and to fix bugs. First, virtues is the second system (first is murders), that has a pre-world-save check on _every mobile in the game_ to atrophy virtue stats. This is taxing since it freexes the world and makes world saves take longer. Every mobile had Gain/Loss dates for each virtue, whether they needed them or not. Most players don't even use the virtue system, so this will increase performance considerably. Second, when I tried to optimize/refactor the code, I found several bugs that needed to be fixed. ### Major API Changes - [X] The properties on players related to virtues are gone. Use `pm.GetVirtues()?.<PropertyName>` instead. - [X] Virtues were removed from non-player Mobiles. - [X] `pm.JusticeProtectors` was removed. Use `JusticeVirtue.GetProtector()` or `JusticeVirtue.GetProtected()` instead. ### Screenshots <img width="221" alt="Props-1" src="https://github.com/modernuo/ModernUO/assets/3953314/5c09cb83-b8d5-44a2-b899-a7ed7cd736ac"> <img width="220" alt="props-2" src="https://github.com/modernuo/ModernUO/assets/3953314/aeade4d3-8df0-47bd-955a-a864d0946cf7">
215 lines
5.5 KiB
C#
215 lines
5.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.CompilerServices;
|
|
using Server.Random;
|
|
|
|
namespace Server.Engines.Harvest
|
|
{
|
|
public class HarvestDefinition
|
|
{
|
|
private HarvestVein[] m_Veins;
|
|
public int BankWidth { get; set; }
|
|
|
|
public int BankHeight { get; set; }
|
|
|
|
public int MinTotal { get; set; }
|
|
|
|
public int MaxTotal { get; set; }
|
|
|
|
public int[] LandTiles { get; set; }
|
|
|
|
public int[] StaticTiles { get; set; }
|
|
|
|
public bool RangedTiles { get; set; }
|
|
|
|
public TimeSpan MinRespawn { get; set; }
|
|
|
|
public TimeSpan MaxRespawn { get; set; }
|
|
|
|
public int MaxRange { get; set; }
|
|
|
|
public int ConsumedPerHarvest { get; set; }
|
|
|
|
public int ConsumedPerFeluccaHarvest { get; set; }
|
|
|
|
public bool PlaceAtFeetIfFull { get; set; }
|
|
|
|
public SkillName Skill { get; set; }
|
|
|
|
public int[] EffectActions { get; set; }
|
|
|
|
public int[] EffectCounts { get; set; }
|
|
|
|
public int[] EffectSounds { get; set; }
|
|
|
|
public TimeSpan EffectSoundDelay { get; set; }
|
|
|
|
public TimeSpan EffectDelay { get; set; }
|
|
|
|
public TextDefinition NoResourcesMessage { get; set; }
|
|
|
|
public TextDefinition OutOfRangeMessage { get; set; }
|
|
|
|
public TextDefinition TimedOutOfRangeMessage { get; set; }
|
|
|
|
public TextDefinition DoubleHarvestMessage { get; set; }
|
|
|
|
public TextDefinition FailMessage { get; set; }
|
|
|
|
public TextDefinition PackFullMessage { get; set; }
|
|
|
|
public TextDefinition ToolBrokeMessage { get; set; }
|
|
|
|
public HarvestResource[] Resources { get; set; }
|
|
|
|
public HarvestVein[] Veins
|
|
{
|
|
get => m_Veins;
|
|
set
|
|
{
|
|
m_Veins = value;
|
|
var totalWeight = 0u;
|
|
for (var i = 0; i < m_Veins.Length; i++)
|
|
{
|
|
totalWeight += m_Veins[i].VeinChance;
|
|
}
|
|
|
|
VeinWeights = totalWeight;
|
|
}
|
|
}
|
|
|
|
public BonusHarvestResource[] BonusResources { get; set; }
|
|
|
|
public bool RaceBonus { get; set; }
|
|
|
|
public bool RandomizeVeins { get; set; }
|
|
|
|
public uint VeinWeights { get; private set; }
|
|
|
|
public Dictionary<Map, Dictionary<Point2D, HarvestBank>> Banks { get; } = new();
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public void SendMessageTo(Mobile from, TextDefinition message)
|
|
{
|
|
if (message?.Number > 0)
|
|
{
|
|
from.SendLocalizedMessage(message.Number);
|
|
}
|
|
else if (!string.IsNullOrWhiteSpace(message))
|
|
{
|
|
from.SendMessage(message);
|
|
}
|
|
}
|
|
|
|
public HarvestBank GetBank(Map map, int x, int y)
|
|
{
|
|
if (map == null || map == Map.Internal)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
x /= BankWidth;
|
|
y /= BankHeight;
|
|
|
|
if (!Banks.TryGetValue(map, out var banks))
|
|
{
|
|
Banks[map] = banks = new Dictionary<Point2D, HarvestBank>();
|
|
}
|
|
|
|
var key = new Point2D(x, y);
|
|
|
|
if (!banks.TryGetValue(key, out var bank))
|
|
{
|
|
banks[key] = bank = new HarvestBank(this, GetVeinAt(map, x, y));
|
|
}
|
|
|
|
return bank;
|
|
}
|
|
|
|
public HarvestVein GetVeinAt(Map map, int x, int y)
|
|
{
|
|
if (Veins.Length == 1)
|
|
{
|
|
return Veins[0];
|
|
}
|
|
|
|
if (RandomizeVeins)
|
|
{
|
|
return GetVeinFrom(Utility.Random(1000u));
|
|
}
|
|
|
|
// TODO: Introduce pulling primes from a config and writing them if they don't exist to the config
|
|
var random = new Xoshiro256PlusPlus((ulong)(x * 17 + y * 11 + map.MapID * 3));
|
|
return GetVeinFrom(random.Next(VeinWeights));
|
|
}
|
|
|
|
public HarvestVein GetVeinFrom(uint randomValue)
|
|
{
|
|
if (Veins.Length == 1)
|
|
{
|
|
return Veins[0];
|
|
}
|
|
|
|
for (var i = 0; i < Veins.Length; ++i)
|
|
{
|
|
if (randomValue <= Veins[i].VeinChance)
|
|
{
|
|
return Veins[i];
|
|
}
|
|
|
|
randomValue -= Veins[i].VeinChance;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public BonusHarvestResource GetBonusResource()
|
|
{
|
|
if (BonusResources == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var randomValue = Utility.RandomDouble() * 100;
|
|
|
|
for (var i = 0; i < BonusResources.Length; ++i)
|
|
{
|
|
if (randomValue <= BonusResources[i].Chance)
|
|
{
|
|
return BonusResources[i];
|
|
}
|
|
|
|
randomValue -= BonusResources[i].Chance;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public bool Validate(int tileID, bool isLand)
|
|
{
|
|
var tiles = isLand ? LandTiles : StaticTiles;
|
|
if (RangedTiles)
|
|
{
|
|
for (var i = 0; i < tiles.Length; i += 2)
|
|
{
|
|
if (tileID >= tiles[i] && tileID <= tiles[i + 1])
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
for (var i = 0; i < tiles.Length; ++i)
|
|
{
|
|
if (tiles[i] == tileID)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|