private void GameLoop_DayStarted(object sender, DayStartedEventArgs e) { // Purge old easter eggs when Summer begins if (Game1.dayOfMonth == 1 && Game1.currentSeason == "summer") { const string itemToPurge = EasterEggItem; var itemToAddId = JsonAssets.GetObjectId(ChocolateBarItem); foreach (var chest in Game1.locations.SelectMany( l => l.Objects.SelectMany(dict => dict.Values.Where( o => o is Chest c && c.items.Any(i => i.Name == itemToPurge)))).Cast <Chest>()) { var stack = 0; foreach (var item in chest.items.Where(i => i.Name == itemToPurge)) { // TODO: TEST: Easter egg expiration on Summer 1 stack += item.Stack; chest.items[chest.items.IndexOf(item)] = null; } if (itemToAddId > 0) { chest.items.Add(new Object(itemToAddId, stack)); } } } }
private static Object GetObjectFromID(string id, int amount, int quality) { SMonitor.Log($"Trying to get object {id}, DGA {apiDGA != null}, JA {apiJA != null}"); Object obj = null; try { if (int.TryParse(id, out int index)) { SMonitor.Log($"Spawning object with index {id}"); return(new Object(index, amount, false, -1, quality)); } else { var dict = SHelper.Content.Load <Dictionary <int, string> >("Data/ObjectInformation", ContentSource.GameContent); foreach (var kvp in dict) { if (kvp.Value.StartsWith(id + "/")) { return(new Object(kvp.Key, amount, false, -1, quality)); } } } if (apiDGA != null && id.Contains("/")) { object o = apiDGA.SpawnDGAItem(id); if (o is Object) { SMonitor.Log($"Spawning DGA object {id}"); (o as Object).Stack = amount; (o as Object).Quality = quality; return(o as Object); } } if (apiJA != null) { int idx = apiJA.GetObjectId(id); if (idx != -1) { SMonitor.Log($"Spawning JA object {id}"); return(new Object(idx, amount, false, -1, quality)); } } } catch (Exception ex) { SMonitor.Log($"Exception: {ex}", LogLevel.Error); } SMonitor.Log($"Couldn't find item with id {id}"); return(obj); }
private void OnGameLaunched(object sender, GameLaunchedEventArgs e) { // load Json Assets API this.JsonAssets = this.Helper.ModRegistry.GetApi <IJsonAssetsApi>("spacechase0.JsonAssets"); if (this.JsonAssets == null) { this.Monitor.Log("Can't access the Json Assets API. Is the mod installed correctly?", LogLevel.Error); return; } // inject Json Assets content pack this.JsonAssets.LoadAssets(Path.Combine(this.Helper.DirectoryPath, "assets")); giftID = JsonAssets.GetObjectId("Gift"); }
private void IdsAssigned(object sender, EventArgs e) { // Get the ring IDs loaded in by JA from our owned content packs foreach (var ring in RingManager.rings) { int objectID = _jsonAssetsApi.GetObjectId(ring.Name); if (objectID == -1) { continue; } ring.ObjectID = objectID; } }
private void SaveLoaded(object sender, SaveLoadedEventArgs e) { if (JA != null) //Check if JsonAssets Api is present { RopeID = JA.GetObjectId("Escape Rope"); //Get the id for the Escape Rope if (RopeID == -1) //If the Escape Rope doesn't have an id the console alerts the player { Monitor.Log($"Failed loading Object JA.Escape_Rope", LogLevel.Warn); } } else //Alert the player if JsonAssets Api isn't present { Monitor.Log($"Failed Loading Json Assets API", LogLevel.Warn); } }
private string[] Token_ObjectId(ITokenString input) { if (input == null) { return(ja.GetAllObjectIds().Values.Select((i) => i.ToString()).ToArray <string>()); } var str = input.Value; int id = ja.GetObjectId(str); if (id == -1) { return new string[] { } } ; return(new[] { id.ToString() }); }
private static Object GetObjectFromID(string id) { SMonitor.Log($"Trying to get object {id}, DGA {apiDGA != null}, JA {apiJA != null}"); Object obj = null; try { if (int.TryParse(id, out int index)) { return(new Object(index, 1, false, -1, 0)); } else { var dict = SHelper.Content.Load <Dictionary <int, string> >("Data/ObjectInformation", ContentSource.GameContent); foreach (var kvp in dict) { if (kvp.Value.StartsWith(id + "/")) { return(new Object(kvp.Key, 1, false, -1, 0)); } } } if (apiDGA != null && id.Contains("/")) { object o = apiDGA.SpawnDGAItem(id); if (o is Object) { return(obj); } } if (apiJA != null) { int idx = apiJA.GetObjectId(id); if (idx != -1) { return(new Object(idx, 1, false, -1, 0)); } } } catch { } SMonitor.Log($"Couldn't find item with id {id}"); return(obj); }
private void DayStarted(object sender, DayStartedEventArgs e) { showBubble = true; giftID = JsonAssets.GetObjectId("Gift"); ScanAllSigns(); }