补全部分 EventComponent 设计
This commit is contained in:
@@ -31,6 +31,21 @@ namespace GeometryTD.Factory
|
||||
case EventEffectType.AddRandomComps:
|
||||
{
|
||||
int count = GetInt(param, "Count");
|
||||
bool hasMinRarity = TryGetString(param, "MinRarity", out string minRarityRaw);
|
||||
bool hasMaxRarity = TryGetString(param, "MaxRarity", out string maxRarityRaw);
|
||||
if (hasMinRarity || hasMaxRarity)
|
||||
{
|
||||
if (!hasMinRarity || !hasMaxRarity)
|
||||
{
|
||||
throw new System.InvalidOperationException(
|
||||
"AddRandomComps requires both MinRarity and MaxRarity when using ranged rarity config.");
|
||||
}
|
||||
|
||||
RarityType minRarity = EnumUtility<RarityType>.Get(minRarityRaw);
|
||||
RarityType maxRarity = EnumUtility<RarityType>.Get(maxRarityRaw);
|
||||
return new AddRandomCompsEffect(new AddRandomCompsParam(count, minRarity, maxRarity), probability);
|
||||
}
|
||||
|
||||
RarityType rarity = EnumUtility<RarityType>.Get(GetString(param, "Rarity"));
|
||||
return new AddRandomCompsEffect(new AddRandomCompsParam(count, rarity), probability);
|
||||
}
|
||||
@@ -73,5 +88,17 @@ namespace GeometryTD.Factory
|
||||
|
||||
return token.Value<string>();
|
||||
}
|
||||
|
||||
private static bool TryGetString(JObject param, string key, out string value)
|
||||
{
|
||||
value = string.Empty;
|
||||
if (param == null || !param.TryGetValue(key, out JToken token) || token.Type == JTokenType.Null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
value = token.Value<string>();
|
||||
return !string.IsNullOrWhiteSpace(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user