<commit_before>﻿using Newtonsoft.Json.Linq;
using System.IO;
using System.Linq;

namespace GreatTextAdventures.Items.Weapons
{
	public class RandomWeapon : Weapon
	{	

		public RandomWeapon(string name, string nameModifier, int attack, int attackModifier)
		{
			this.baseName = name;
			this.nameModifier = nameModifier;
			this.baseAttack = attack;
			this.attackModifier = attackModifier;
		}

		public static RandomWeapon Generate(int level)
		{
			JObject weapons = JObject.Parse(File.ReadAllText(@"Items\Weapons\Weapons.json"));
			JArray names = (JArray)weapons["Names"];
			JArray modifiers = (JArray)weapons["Modifiers"];

			JArray chosenModifier = (JArray)modifiers.OrderBy(x => GameSystem.RNG.Next()).First();
			string chosenName = (string)names.OrderBy(x => GameSystem.RNG.Next()).First();

			return new RandomWeapon(chosenName, (string)chosenModifier[0], GameSystem.RNG.Next(level * 5, level * 10), (int)chosenModifier[1]);
		}
	}
}<commit_msg>Add a cache to RandomWeapon containing all weapons<commit_after>﻿using Newtonsoft.Json.Linq;
using System.IO;
using System.Linq;

namespace GreatTextAdventures.Items.Weapons
{
	public class RandomWeapon : Weapon
	{	
		public static JObject AllWeapons { get; private set; }

		protected RandomWeapon(string name, string nameMod, int attack, int attackMod)
		{
			baseName = name;
			nameModifier = nameMod;
			baseAttack = attack;
			attackModifier = attackMod;
		}

		public static RandomWeapon Generate(int level)
		{
			if (AllWeapons == null)
				AllWeapons = JObject.Parse(File.ReadAllText(@"Items\Weapons\Weapons.json"));

			JArray names = (JArray)AllWeapons["Names"];
			JArray modifiers = (JArray)AllWeapons["Modifiers"];

			JArray chosenModifier = (JArray)modifiers.OrderBy(x => GameSystem.RNG.Next()).First();
			string chosenName = (string)names.OrderBy(x => GameSystem.RNG.Next()).First();

			return new RandomWeapon(chosenName, (string)chosenModifier[0], GameSystem.RNG.Next(level * 5, level * 10), (int)chosenModifier[1]);
		}
	}
}
{'fraction_non_alphanumeric': 0.12556053811659193, 'fraction_numerical': 0.004982561036372696, 'mean_word_length': 4.958456973293768, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4325854', 'n_tokens_mistral': 732, 'n_tokens_neox': 660, 'n_words': 136}