private void onMenuChanged(object sender, MenuChangedEventArgs e) // Handle when the player changes their appearance at the shrine of illusions { if (changingAppearance) { changingAppearance = false; OnSaveLoaded(null, null); lastItem = null; } if (Game1.activeClickableMenu is StardewValley.Menus.CharacterCustomization) { changingAppearance = true; drawUmbrella = false; drawRegularFarmer = true; fullRedraw = true; redrawFarmer(); } if (e.NewMenu is ShopMenu menu && menu != null) { // Add umbrellas to the hat mouse shop if (menu.potraitPersonDialogue == Game1.parseText(Game1.content.LoadString("Strings\\StringsFromCSFiles:ShopMenu.cs.11494"), Game1.dialogueFont, Game1.tileSize * 5 - Game1.pixelZoom * 4)) { foreach (string umbrellaName in umbrellaNames) { if (umbrellaName != "Tattered Umbrella") { var o = new MeleeWeapon(spriteIndex: JsonAssets.GetWeaponId(name: umbrellaName)); menu.itemPriceAndStock.Add(o, new[] { (int)1000, int.MaxValue }); menu.forSale.Insert(menu.forSale.Count, o); } } } } if (e.OldMenu is LetterViewerMenu letterClosed && letterClosed.isMail && e.NewMenu == null) { if (letterClosed.mailTitle == "lewis_umbrella") //thanks bbblueberry for the below snippet { Game1.player.completelyStopAnimatingOrDoingAction(); DelayedAction.playSoundAfterDelay("getNewSpecialItem", 750); Game1.player.faceDirection(2); Game1.player.freezePause = 4000; Game1.player.FarmerSprite.animateOnce(new FarmerSprite.AnimationFrame[3] { new FarmerSprite.AnimationFrame(57, 0), new FarmerSprite.AnimationFrame(57, 2500, secondaryArm: false, flip: false, Farmer.showHoldingItem), new FarmerSprite.AnimationFrame((short)Game1.player.FarmerSprite.CurrentFrame, 500, secondaryArm: false, flip: false) }); Game1.player.mostRecentlyGrabbedItem = new MeleeWeapon(spriteIndex: JsonAssets.GetWeaponId(name: "Tattered Umbrella")); Game1.player.canMove = false; AddItem(new MeleeWeapon(spriteIndex: JsonAssets.GetWeaponId(name: "Tattered Umbrella"))); } } }
private string[] Token_WeaponId(ITokenString input) { if (input == null) { return(ja.GetAllWeaponIds().Values.Select((i) => i.ToString()).ToArray <string>()); } var str = input.Value; int id = ja.GetWeaponId(str); if (id == -1) { return new string[] { } } ; return(new[] { id.ToString() }); } }
public void LoadAdvancedMeleeWeapons() { advancedMeleeWeapons.Clear(); advancedMeleeWeaponsByType[1].Clear(); advancedMeleeWeaponsByType[2].Clear(); advancedMeleeWeaponsByType[3].Clear(); foreach (IContentPack contentPack in Helper.ContentPacks.GetOwned()) { Monitor.Log($"Reading content pack: {contentPack.Manifest.Name} {contentPack.Manifest.Version} from {contentPack.DirectoryPath}", LogLevel.Debug); try { AdvancedMeleeWeaponData json = contentPack.ReadJsonFile <AdvancedMeleeWeaponData>("content.json") ?? null; WeaponPackConfigData config = contentPack.ReadJsonFile <WeaponPackConfigData>("config.json") ?? new WeaponPackConfigData(); if (json != null) { if (json.weapons != null && json.weapons.Count > 0) { foreach (AdvancedMeleeWeapon weapon in json.weapons) { foreach (KeyValuePair <string, string> kvp in weapon.config) { FieldInfo fi = weapon.GetType().GetField(kvp.Key); if (fi == null) { Monitor.Log($"Error getting field {kvp.Key} in AdvancedMeleeWeapon class.", LogLevel.Error); continue; } if (config.variables.ContainsKey(kvp.Value)) { var val = config.variables[kvp.Value]; if (val.GetType() == typeof(Int64)) { fi.SetValue(weapon, Convert.ToInt32(config.variables[kvp.Value])); } else { fi.SetValue(weapon, config.variables[kvp.Value]); } } else { config.variables.Add(kvp.Value, fi.GetValue(weapon)); } } foreach (MeleeActionFrame frame in weapon.frames) { foreach (KeyValuePair <string, string> kvp in frame.config) { FieldInfo fi = frame.GetType().GetField(kvp.Key); if (fi == null) { Monitor.Log($"Error getting field {kvp.Key} in MeleeActionFrame class.", LogLevel.Error); continue; } if (config.variables.ContainsKey(kvp.Value)) { fi.SetValue(frame, config.variables[kvp.Value]); } else { config.variables.Add(kvp.Value, fi.GetValue(frame)); } } foreach (AdvancedWeaponProjectile entry in frame.projectiles) { foreach (KeyValuePair <string, string> kvp in entry.config) { FieldInfo fi = entry.GetType().GetField(kvp.Key); if (fi == null) { Monitor.Log($"Error getting field {kvp.Key} in AdvancedWeaponProjectile class.", LogLevel.Error); continue; } if (config.variables.ContainsKey(kvp.Value)) { fi.SetValue(entry, config.variables[kvp.Value]); } else { config.variables.Add(kvp.Value, fi.GetValue(entry)); } } } if (frame.special != null) { foreach (KeyValuePair <string, string> kvp in frame.special.config) { if (!frame.special.parameters.ContainsKey(kvp.Key)) { Monitor.Log($"Error getting key {kvp.Key} in SpecialEffects.parameters", LogLevel.Error); continue; } if (config.variables.ContainsKey(kvp.Value)) { frame.special.parameters[kvp.Key] = config.variables[kvp.Value].ToString(); } else { config.variables.Add(kvp.Value, frame.special.parameters[kvp.Key]); } } } } foreach (AdvancedEnchantmentData entry in weapon.enchantments) { int count = 0; foreach (KeyValuePair <string, string> kvp in entry.config) { if (!entry.parameters.ContainsKey(kvp.Key)) { Monitor.Log($"Error getting key {kvp.Key} in AdvancedEnchantmentData.parameters", LogLevel.Error); continue; } if (config.variables.ContainsKey(kvp.Value)) { entry.parameters[kvp.Key] = config.variables[kvp.Value].ToString(); } else { config.variables.Add(kvp.Value, entry.parameters[kvp.Key]); } } advancedEnchantments[entry.name] = entry; count++; } if (config.variables.Any()) { contentPack.WriteJsonFile("config.json", config); } if (weapon.type == 0) { Monitor.Log($"Adding specific weapon {weapon.id}"); if (!int.TryParse(weapon.id, out int id)) { Monitor.Log($"Got name instead of id {weapon.id}"); try { id = Helper.Content.Load <Dictionary <int, string> >("Data/weapons", ContentSource.GameContent).First(p => p.Value.StartsWith($"{weapon.id}/")).Key; Monitor.Log($"Got name-based id {id}"); } catch (Exception ex) { if (mJsonAssets != null) { id = mJsonAssets.GetWeaponId(weapon.id); if (id == -1) { Monitor.Log($"error getting JSON Assets weapon {weapon.id}\n{ex}", LogLevel.Error); continue; } Monitor.Log($"Added JA weapon {weapon.id}, id {id}"); } else { Monitor.Log($"error getting weapon {weapon.id}\n{ex}", LogLevel.Error); continue; } } } if (!advancedMeleeWeapons.ContainsKey(id)) { advancedMeleeWeapons[id] = new List <AdvancedMeleeWeapon>(); } advancedMeleeWeapons[id].Add(weapon); } else { advancedMeleeWeaponsByType[weapon.type].Add(weapon); } } } } } catch (Exception ex) { Monitor.Log($"error reading content.json file in content pack {contentPack.Manifest.Name}.\r\n{ex}", LogLevel.Error); } } Monitor.Log($"Total advanced melee weapons: {advancedMeleeWeapons.Count}", LogLevel.Debug); Monitor.Log($"Total advanced melee dagger attacks: {advancedMeleeWeaponsByType[1].Count}", LogLevel.Debug); Monitor.Log($"Total advanced melee club attacks: {advancedMeleeWeaponsByType[2].Count}", LogLevel.Debug); Monitor.Log($"Total advanced melee sword attacks: {advancedMeleeWeaponsByType[3].Count}", LogLevel.Debug); }
//get the ID for the sword from JA into the game private void GameLoop_SaveLoaded (object sender, SaveLoadedEventArgs e){ if (JsonAssets != null) { linkSwordID = JsonAssets.GetWeaponId("linkSword");} if (linkSwordID == -1) { Monitor.Log("jsonAssts linkSwordID failed", LogLevel.Warn); } this.player = Game1.player; //grab the player for calls later }