public static bool SetNpcNoZone(Action <PgNpcLocation> setter, MapAreaName areaName, string npcId, string parsedFile, string parsedKey, ErrorControl errorControl) { PgNpc ParsedNpc = null !; SpecialNpc NpcEnum = SpecialNpc.Internal_None; string NpcName = string.Empty; PgNpcLocation NpcLocation = new PgNpcLocation(); NpcLocation.NpcId = npcId; if (Inserter <PgNpc> .SetItemByKey((PgNpc valueNpc) => ParsedNpc = valueNpc, npcId, ErrorControl.IgnoreIfNotFound)) { NpcLocation.Npc_Key = ParsedNpc.Key; } else if (StringToEnumConversion <SpecialNpc> .TryParse(npcId, out NpcEnum, ErrorControl.IgnoreIfNotFound)) { NpcLocation.NpcEnum = NpcEnum; } else if (npcId.ToUpper().StartsWith("NPC_")) { NpcLocation.NpcName = npcId.Substring(4); } else { return(Program.ReportFailure(parsedFile, parsedKey, $"'{npcId}' unknown NPC name", errorControl)); } ParsingContext.AddSuplementaryObject(NpcLocation); Debug.Assert(!string.IsNullOrEmpty(NpcLocation.NpcId)); Debug.Assert(NpcLocation.Npc_Key != null || NpcLocation.NpcEnum != SpecialNpc.Internal_None || NpcLocation.NpcName.Length > 0); setter(NpcLocation); return(true); }
private bool FinishItem(PgNpc item, Dictionary <string, object> contentTable, Dictionary <string, Json.Token> contentTypeTable, List <object> itemCollection, Json.Token lastItemType, string parsedFile, string parsedKey) { bool Result = true; foreach (KeyValuePair <string, object> Entry in contentTable) { string Key = Entry.Key; object Value = Entry.Value; switch (Key) { case "Name": Result = SetStringProperty((string valueString) => item.Name = valueString, Value); break; case "AreaName": Result = ParseAreaName(item, Value, parsedFile, parsedKey); break; case "AreaFriendlyName": Result = SetStringProperty((string valueString) => item.AreaFriendlyName = valueString, Value); break; case "Preferences": Result = Inserter <PgNpcPreference> .AddKeylessArray(item.PreferenceList, Value); break; default: Result = Program.ReportFailure(parsedFile, parsedKey, $"Key '{Key}' not handled"); break; } if (!Result) { break; } } if (Result) { if (item.AreaFriendlyName == null) { return(Program.ReportFailure(parsedFile, parsedKey, "No area friendly name")); } item.IconId = PgObject.NpcIconId; } return(Result); }
private bool ParseAreaName(PgNpc item, object value, string parsedFile, string parsedKey) { if (!(value is string ValueKey)) { return(Program.ReportFailure(parsedFile, parsedKey, $"Value '{value}' was expected to be a string")); } if (!ValueKey.StartsWith("Area")) { return(Program.ReportFailure(parsedFile, parsedKey, $"Invalid area name '{ValueKey}'")); } string ValueAreaName = ValueKey.Substring(4); return(StringToEnumConversion <MapAreaName> .SetEnum((MapAreaName valueEnum) => item.AreaName = valueEnum, ValueAreaName)); }