fix: Consolidates properties code (#785)

* Consolidates the property logic between properties and add.
* Fixes a bug with setting properties
This commit is contained in:
Kamron Batman 2021-09-15 21:48:30 -07:00 • committed by GitHub
parent ec785e6f07
commit bba5346a92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 123 additions and 168 deletions

View file

@ -149,46 +149,16 @@ namespace Server.Commands
for (var i = 0; i < realProps.Length; ++i)
{
PropertyInfo thisProp = null;
var propName = props[i, 0];
var thisProp = Properties.GetPropertyInfoByName(from, allProps, propName, PropertyAccess.Write, out var failReason);
for (var j = 0; thisProp == null && j < allProps.Length; ++j)
if (failReason == null)
{
if (propName.InsensitiveEquals(allProps[j].Name))
{
thisProp = allProps[j];
}
}
if (thisProp == null)
{
from.SendMessage("Property not found: {0}", propName);
realProps[i] = thisProp;
}
else
{
var attr = GetCPA(thisProp);
if (attr == null)
{
from.SendMessage("Property ({0}) not found.", propName);
}
else if (from.AccessLevel < attr.WriteLevel)
{
from.SendMessage(
"Setting this property ({0}) requires at least {1} access level.",
propName,
Mobile.GetAccessLevelName(attr.WriteLevel)
);
}
else if (!thisProp.CanWrite || attr.ReadOnly)
{
from.SendMessage("Property ({0}) is read only.", propName);
}
else
{
realProps[i] = thisProp;
}
from.SendMessage(failReason);
}
}
}