/// <summary> /// Add the card to the card pools with given IDs. /// </summary> /// <param name="rewardNodeData">RewardNodeData to be added to the pools</param> /// <param name="mapNodePoolIDs">List of map node pool IDs to add the reward node to</param> public static void RegisterCustomRewardNode(RewardNodeData rewardNodeData, List <string> mapNodePoolIDs) { var mapNodeDatas = (List <MapNodeData>)AccessTools.Field(typeof(AllGameData), "mapNodeDatas").GetValue(ProviderManager.SaveManager.GetAllGameData()); mapNodeDatas.Add(rewardNodeData); foreach (string mapNodePoolID in mapNodePoolIDs) { if (!CustomRewardNodeData.ContainsKey(mapNodePoolID)) { CustomRewardNodeData[mapNodePoolID] = new List <RewardNodeData>(); } CustomRewardNodeData[mapNodePoolID].Add(rewardNodeData); } }
/// <summary> /// Builds the RewardNodeData represented by this builder's parameters recursively; /// all Builders represented in this class's various fields will also be built. /// </summary> /// <returns>The newly created RewardNodeData</returns> public RewardNodeData Build() { foreach (var builder in this.RewardBuilders) { this.Rewards.Add(builder.Build()); } RewardNodeData rewardNodeData = ScriptableObject.CreateInstance <RewardNodeData>(); AccessTools.Field(typeof(GameData), "id").SetValue(rewardNodeData, this.RewardNodeID); AccessTools.Field(typeof(MapNodeData), "ignoreIfNodesPresent").SetValue(rewardNodeData, this.IgnoreIfNodesPresent); AccessTools.Field(typeof(MapNodeData), "mapIcon").SetValue(rewardNodeData, CustomAssetManager.LoadSpriteFromPath(this.BaseAssetPath + "/" + this.MapIconPath)); if (this.MapIconPrefab == null) { // These are too complicated to create from scratch, so by default we copy from an existing game banner and apply our sprites to it RewardNodeData copyBanner = (ProviderManager.SaveManager.GetAllGameData().FindMapNodeData("5f35b7b7-75d1-4957-9f78-7d2072237038") as RewardNodeData); this.MapIconPrefab = GameObject.Instantiate(copyBanner.GetMapIconPrefab()); this.MapIconPrefab.transform.parent = null; this.MapIconPrefab.name = this.RewardNodeID; GameObject.DontDestroyOnLoad(this.MapIconPrefab); var images = this.MapIconPrefab.GetComponentsInChildren <Image>(true); List <string> spritePaths = new List <string> { // This is the order they're listed on the prefab this.ControllerSelectedOutline, this.EnabledSpritePath, this.EnabledVisitedSpritePath, this.DisabledVisitedSpritePath, this.DisabledSpritePath, this.FrozenSpritePath }; for (int i = 0; i < images.Length; i++) { // This method of modifying the image's sprite has the unfortunate side-effect of removing the white mouse-over outline var sprite = CustomAssetManager.LoadSpriteFromPath(this.BaseAssetPath + "/" + spritePaths[i]); if (sprite != null) { images[i].sprite = sprite; images[i].material = null; } } } AccessTools.Field(typeof(MapNodeData), "mapIconPrefab").SetValue(rewardNodeData, this.MapIconPrefab); AccessTools.Field(typeof(MapNodeData), "minimapIcon").SetValue(rewardNodeData, CustomAssetManager.LoadSpriteFromPath(this.BaseAssetPath + "/" + this.MinimapIconPath)); AccessTools.Field(typeof(MapNodeData), "nodeSelectedSfxCue").SetValue(rewardNodeData, this.NodeSelectedSfxCue); AccessTools.Field(typeof(MapNodeData), "skipCheckSettings").SetValue(rewardNodeData, SkipCheckSettings); if (this.Description != null) { this.TooltipBodyKey = "RewardNodeData_" + this.RewardNodeID + "_TooltipBodyKey"; // Use Description field for all languages // This should be changed in the future to add proper localization support to custom content CustomLocalizationManager.ImportSingleLocalization(this.TooltipBodyKey, "Text", "", "", "", "", this.Description, this.Description, this.Description, this.Description, this.Description, this.Description); } AccessTools.Field(typeof(MapNodeData), "tooltipBodyKey").SetValue(rewardNodeData, this.TooltipBodyKey); if (this.Name != null) { this.TooltipTitleKey = "RewardNodeData_" + this.RewardNodeID + "_TooltipTitleKey"; // Use Name field for all languages // This should be changed in the future to add proper localization support to custom content CustomLocalizationManager.ImportSingleLocalization(this.TooltipTitleKey, "Text", "", "", "", "", this.Name, this.Name, this.Name, this.Name, this.Name, this.Name); } AccessTools.Field(typeof(MapNodeData), "tooltipTitleKey").SetValue(rewardNodeData, this.TooltipTitleKey); AccessTools.Field(typeof(RewardNodeData), "grantImmediately").SetValue(rewardNodeData, this.GrantImmediately); AccessTools.Field(typeof(RewardNodeData), "OverrideTooltipTitleBody").SetValue(rewardNodeData, this.OverrideTooltipTitleBody); AccessTools.Field(typeof(RewardNodeData), "requiredClass").SetValue(rewardNodeData, this.RequiredClass); AccessTools.Field(typeof(RewardNodeData), "rewards").SetValue(rewardNodeData, this.Rewards); return(rewardNodeData); }