Selection issues, model issues, ability bug
This commit is contained in:
@@ -696,6 +696,7 @@ func _merge_unit_delta(unit: Dictionary, ud: Dictionary) -> void:
|
||||
if ud.has("Art2dUrl") and ud["Art2dUrl"] != null: unit["Art2dUrl"] = ud["Art2dUrl"]
|
||||
if ud.has("modelUrl") and ud["modelUrl"] != null: unit["modelUrl"] = ud["modelUrl"]
|
||||
if ud.has("ModelUrl") and ud["ModelUrl"] != null: unit["ModelUrl"] = ud["ModelUrl"]
|
||||
if ud.has("modelurl") and ud["modelurl"] != null: unit["modelurl"] = ud["modelurl"]
|
||||
|
||||
|
||||
func _on_server_push(type: String, payload: Variant) -> void:
|
||||
|
||||
@@ -326,8 +326,10 @@ func add_unit_mesh(unit: Dictionary, team_color: Color, is_enemy: bool = false,
|
||||
_prime_unit_sfx(def)
|
||||
var model_asset: Dictionary = find_model3d_asset(def)
|
||||
var model_url: String = _first_clean_optional_url(unit,
|
||||
["modelUrl", "ModelUrl", "modelURL", "ModelURL", "model_url"])
|
||||
["modelUrl", "ModelUrl", "modelURL", "ModelURL", "model_url", "modelurl"])
|
||||
var model_etag: String = ""
|
||||
if model_url.is_empty():
|
||||
model_url = _find_summon_token_model_url(unit)
|
||||
if model_url.is_empty():
|
||||
model_url = _clean_optional_url(model_asset.get("cdnUrl", ""))
|
||||
model_etag = _clean_optional_url(model_asset.get("contentETag", ""))
|
||||
@@ -1197,6 +1199,89 @@ func _first_clean_optional_url(source: Dictionary, keys: Array[String]) -> Strin
|
||||
return ""
|
||||
|
||||
|
||||
func _dict_get_any(source: Dictionary, keys: Array, fallback: Variant = null) -> Variant:
|
||||
for key: Variant in keys:
|
||||
if source.has(key):
|
||||
return source[key]
|
||||
return fallback
|
||||
|
||||
|
||||
func _find_summon_token_model_url(unit: Dictionary) -> String:
|
||||
var direct: String = _find_matching_token_model_url_in_value(unit, unit)
|
||||
if not direct.is_empty():
|
||||
return direct
|
||||
|
||||
for player: Dictionary in Game.state.get("players", []):
|
||||
var sources: Array = []
|
||||
var arch: Dictionary = unit_registry.safe_arch(player) if unit_registry != null else player.get("archSpirit", {})
|
||||
if not arch.is_empty():
|
||||
sources.append(arch)
|
||||
sources.append_array(player.get("field", []))
|
||||
|
||||
for source: Dictionary in sources:
|
||||
var raw_abilities: Variant = source.get("abilitiesJson", source.get("AbilitiesJson", null))
|
||||
if raw_abilities == null:
|
||||
continue
|
||||
var parsed: Variant = JSON.parse_string(str(raw_abilities))
|
||||
if parsed == null:
|
||||
continue
|
||||
var url: String = _find_matching_token_model_url_in_value(parsed, unit)
|
||||
if not url.is_empty():
|
||||
return url
|
||||
return ""
|
||||
|
||||
|
||||
func _find_matching_token_model_url_in_value(value: Variant, unit: Dictionary) -> String:
|
||||
if value is Dictionary:
|
||||
var dict: Dictionary = value as Dictionary
|
||||
var token_value: Variant = _dict_get_any(dict,
|
||||
["TokenDefJson", "tokenDefJson", "tokendefjson"], null)
|
||||
var token_def: Dictionary = {}
|
||||
if token_value is Dictionary:
|
||||
token_def = token_value as Dictionary
|
||||
elif token_value != null:
|
||||
var token_json: String = str(token_value).strip_edges()
|
||||
if not token_json.is_empty():
|
||||
var parsed_token: Variant = JSON.parse_string(token_json)
|
||||
if parsed_token is Dictionary:
|
||||
token_def = parsed_token as Dictionary
|
||||
if not token_def.is_empty() and _token_def_matches_unit(token_def, unit):
|
||||
var url: String = _first_clean_optional_url(token_def,
|
||||
["modelUrl", "ModelUrl", "modelURL", "ModelURL", "model_url", "modelurl"])
|
||||
if not url.is_empty():
|
||||
return url
|
||||
|
||||
for key: Variant in dict.keys():
|
||||
var nested_url: String = _find_matching_token_model_url_in_value(dict[key], unit)
|
||||
if not nested_url.is_empty():
|
||||
return nested_url
|
||||
elif value is Array:
|
||||
for item: Variant in value:
|
||||
var nested_url: String = _find_matching_token_model_url_in_value(item, unit)
|
||||
if not nested_url.is_empty():
|
||||
return nested_url
|
||||
return ""
|
||||
|
||||
|
||||
func _token_def_matches_unit(token_def: Dictionary, unit: Dictionary) -> bool:
|
||||
var matched: bool = false
|
||||
var token_name: String = str(_dict_get_any(token_def, ["Name", "name"], "")).strip_edges().to_lower()
|
||||
var unit_name: String = str(_dict_get_any(unit, ["name", "Name"], "")).strip_edges().to_lower()
|
||||
if not token_name.is_empty() and not unit_name.is_empty():
|
||||
if token_name != unit_name:
|
||||
return false
|
||||
matched = true
|
||||
|
||||
var token_affinity: String = str(_dict_get_any(token_def, ["Affinity", "affinity"], "")).strip_edges().to_lower()
|
||||
var unit_affinity: String = str(_dict_get_any(unit, ["affinity", "Affinity"], "")).strip_edges().to_lower()
|
||||
if not token_affinity.is_empty() and not unit_affinity.is_empty():
|
||||
if token_affinity != unit_affinity:
|
||||
return false
|
||||
matched = true
|
||||
|
||||
return matched
|
||||
|
||||
|
||||
## Returns the first Model3D asset dict for a card definition, or {} if none.
|
||||
func find_model3d_asset(def: Dictionary) -> Dictionary:
|
||||
for asset: Variant in def.get("assets", []):
|
||||
|
||||
@@ -218,15 +218,32 @@ public static class AbilitySystem
|
||||
|
||||
foreach (var effect in action.Effects)
|
||||
{
|
||||
if (effect is not SummonTokenEffect ste || ste.TileFilter is not { Length: > 0 }) continue;
|
||||
if (effect is not SummonTokenEffect ste) continue;
|
||||
|
||||
var ct = clientTargets.FirstOrDefault(t => t.ActionIndex == ai && t.Coord is not null);
|
||||
if (ct is null) continue;
|
||||
|
||||
var coord = new Coord(ct.Coord!.X, ct.Coord!.Y);
|
||||
var tile = ctx.State.Board.GetTile(coord);
|
||||
if (tile is null || !TileMatchesFilters(ste.TileFilter, tile, ctx))
|
||||
|
||||
// Tile must exist and be empty for a SummonToken.
|
||||
if (tile is null || !tile.IsEmpty)
|
||||
throw new GameException("INVALID_TILE");
|
||||
|
||||
// Explicit TileFilter (e.g. TileAffinityMatches).
|
||||
if (ste.TileFilter is { Length: > 0 } && !TileMatchesFilters(ste.TileFilter, tile, ctx))
|
||||
throw new GameException("INVALID_TILE");
|
||||
|
||||
// Validate the token's own affinity against the tile.
|
||||
if (!string.IsNullOrEmpty(ste.TokenDefJson))
|
||||
{
|
||||
var proto = JsonSerializer.Deserialize<CardInstance>(ste.TokenDefJson, _jsonOpts);
|
||||
if (proto is not null
|
||||
&& !string.IsNullOrEmpty(proto.Affinity) && proto.Affinity != "Void"
|
||||
&& Enum.TryParse<Affinity>(proto.Affinity, out var tokenAffinity)
|
||||
&& !AffinitySystem.IsAffinityValid(tile, tokenAffinity))
|
||||
throw new GameException("INVALID_TILE");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user