fix: Updates races to properly support gargoyle equipment. (#744)

* Adds `RaceFlag` to the `Race` object. This is `1 << RaceIndex`
* Replaces `RequiredRace`  with `RequiredRaces` for items.
* Adds convenience flags for `RequiredRaces`
  ```cs
  
  public const int AllowAllRaces = 0x7;      // Race.Human.RaceFlag | Race.Elf.RaceFlag | Race.Gargoyle.RaceFlag
  public const int AllowHumanOrElves = 0x3;  // Race.Human.RaceFlag | Race.Elf.RaceFlag
  public const int AllowElvesOnly = 0x2;     // Race.Elf.RaceFlag
  public const int AllowGargoylesOnly = 0x4; // Race.Gargoyle.RaceFlag
  ```
* Example usage on an item:
  ```cs
  public override int RequiredRaces => Race.AllowHumanOrElves;
  ```
* Adds Wood and Stone armor material types
* Updates Woodland armor to Wood
* Adds proper messaging for race restrictions
* Adds gargoyle only for object properties
* Adds `CheckRace` functions for validating if a race or mobile can use the item:
  ```cs
  bool CheckRace(Race race);
  bool CheckRace(Mobile from, bool message = true);
  ```
This commit is contained in:
Kamron Batman 2021-08-29 00:43:55 -07:00 committed by GitHub
parent bf20800382
commit 8ffd5a5bd0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
58 changed files with 147 additions and 125 deletions

View file

@ -2104,6 +2104,47 @@ namespace Server
public virtual bool CheckConflictingLayer(Mobile m, Item item, Layer layer) => m_Layer == layer;
// Uses Race.RaceFlag
public virtual int RequiredRaces => Race.AllowAllRaces;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool CheckRace(Race race) => Race.IsAllowedRace(race, RequiredRaces);
public bool CheckRace(Mobile from, bool message = true)
{
var race = from.Race;
var requiredRaces = RequiredRaces;
if (Race.IsAllowedRace(race, requiredRaces))
{
return true;
}
if (!message)
{
return false;
}
if (race == Race.Gargoyle)
{
from.LocalOverheadMessage(MessageType.Regular, 0x3B2, 1111708); // Gargoyles can't wear this.
}
else if (requiredRaces == Race.AllowGargoylesOnly)
{
from.LocalOverheadMessage(Network.MessageType.Regular, 0x3B2, 1111707); // Only gargoyles can wear this.
}
else if (race != Race.Elf)
{
from.SendLocalizedMessage(1072203); // Only Elves may use this.
}
else if (race != Race.Human)
{
from.SendMessage($"Only {race.PluralName} may use this.");
}
return false;
}
public virtual bool CanEquip(Mobile m) => m_Layer != Layer.Invalid && m.FindItemOnLayer(m_Layer) == null;
public virtual void GetChildContextMenuEntries(Mobile from, List<ContextMenuEntry> list, Item item)

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace Server
{
@ -16,6 +17,7 @@ namespace Server
{
RaceID = raceID;
RaceIndex = raceIndex;
RaceFlag = 1 << raceIndex;
Name = name;
@ -38,6 +40,11 @@ namespace Server
public static List<Race> AllRaces { get; } = new();
public const int AllowAllRaces = 0x7; // Race.Human.RaceFlag | Race.Elf.RaceFlag | Race.Gargoyle.RaceFlag
public const int AllowHumanOrElves = 0x3; // Race.Human.RaceFlag | Race.Elf.RaceFlag
public const int AllowElvesOnly = 0x2; // Race.Elf.RaceFlag
public const int AllowGargoylesOnly = 0x4; // Race.Gargoyle.RaceFlag
public Expansion RequiredExpansion { get; }
public int MaleBody { get; }
@ -52,10 +59,15 @@ namespace Server
public int RaceIndex { get; }
public int RaceFlag { get; }
public string Name { get; set; }
public string PluralName { get; set; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsAllowedRace(Race race, int allowedRaceFlags) => (allowedRaceFlags & race.RaceFlag) != 0;
public static string[] GetRaceNames()
{
CheckNamesAndValues();