public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.Value is string) { return(AssetLocation.Create(reader.Value as string, domain)); } return(null); }
public virtual void LoadConfig(JsonObject taskConfig, JsonObject aiConfig) { this.priority = taskConfig["priority"].AsFloat(); this.priorityForCancel = taskConfig["priorityForCancel"].AsFloat(priority); this.Id = taskConfig["id"].AsString(); this.slot = (int)taskConfig["slot"]?.AsInt(0); this.mincooldown = (int)taskConfig["mincooldown"]?.AsInt(0); this.maxcooldown = (int)taskConfig["maxcooldown"]?.AsInt(100); this.mincooldownHours = (double)taskConfig["mincooldownHours"]?.AsDouble(0); this.maxcooldownHours = (double)taskConfig["maxcooldownHours"]?.AsDouble(0); int initialmincooldown = (int)taskConfig["initialMinCoolDown"]?.AsInt(mincooldown); int initialmaxcooldown = (int)taskConfig["initialMaxCoolDown"]?.AsInt(maxcooldown); if (taskConfig["animation"].Exists) { animMeta = new AnimationMetaData() { Code = taskConfig["animation"].AsString()?.ToLowerInvariant(), Animation = taskConfig["animation"].AsString()?.ToLowerInvariant(), AnimationSpeed = taskConfig["animationSpeed"].AsFloat(1f) }.Init(); } this.whenInEmotionState = taskConfig["whenInEmotionState"].AsString(); this.whenNotInEmotionState = taskConfig["whenNotInEmotionState"].AsString(); if (taskConfig["sound"].Exists) { sound = AssetLocation.Create(taskConfig["sound"].AsString(), entity.Code.Domain).WithPathPrefixOnce("sounds/"); soundRange = taskConfig["soundRange"].AsFloat(16); soundStartMs = taskConfig["soundStartMs"].AsInt(0); soundRepeatMs = taskConfig["soundRepeatMs"].AsInt(0); } cooldownUntilMs = entity.World.ElapsedMilliseconds + initialmincooldown + entity.World.Rand.Next(initialmaxcooldown - initialmincooldown); }