Guest User

Untitled

a guest
Nov 9th, 2024
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.85 KB | Gaming | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using MoreSuitsMod.Model.Factories.Interfaces;
  5. using MoreSuitsMod.Model.Suit;
  6. using UnityEngine;
  7.  
  8. namespace MoreSuitsMod.Model.Factories;
  9.  
  10. /// <summary>
  11. /// Factory that creates a list of Unlockable Items that represents of all the Modded Unlockable Suits within the game.
  12. /// </summary>
  13. public class UnlockableSuitFactory : MonoBehaviour, IUnlockableSuitFactory
  14. {
  15.     /// <inheritdoc/>
  16.     public List<ISuit> CustomSuits { get; set; }
  17.    
  18.     /// <inheritdoc/>
  19.     public UnlockableItem OriginalSuit { get; set; }
  20.    
  21.     /// <summary>
  22.     /// Creates the list of Custom Unlockable Suits.
  23.     /// </summary>
  24.     /// <returns>The Unlockable Suits list.</returns>
  25.     public List<UnlockableItem> Create()
  26.     {
  27.         List<UnlockableItem> unlockableItems = [];
  28.        
  29.         foreach (var customSuit in CustomSuits)
  30.         {
  31.             unlockableItems.Add(InitSuit (customSuit, unlockableItems.Count));
  32.         }
  33.         return unlockableItems;
  34.     }
  35.  
  36.     /// <summary>
  37.     /// Initializes a Custom Unlockable Suit, via the data within a Custom Suit instance.
  38.     /// </summary>
  39.     /// <param name="suit">The suit to create the Custom Unlockable Suit instance from.</param>
  40.     /// <returns>The created Custom Unlockable Suit.</returns>
  41.     private UnlockableItem InitSuit(ISuit suit, int id)
  42.     {
  43.         var unlockableSuit = suit.IsDefault ? OriginalSuit :
  44.             JsonUtility.FromJson<UnlockableItem>(JsonUtility.ToJson(OriginalSuit));
  45.  
  46.         unlockableSuit.suitMaterial = suit.SuitMaterial;
  47.         unlockableSuit.unlockableName = suit.UnlockableName;
  48.         return !suit.Price.Equals(0) ? MoreSuits.MoreSuitsMod
  49.             .StartOfRoundPatch
  50.             .AddSuitToShop(unlockableSuit, suit.Price, id) :
  51.             unlockableSuit;
  52.     }
  53.    
  54.    
  55.  
  56.    
  57. }
Advertisement
Add Comment
Please, Sign In to add comment