Elin Decompiled Documentation EA 23.342.1 Nightly
Loading...
Searching...
No Matches
CustomMerchantStock.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using Newtonsoft.Json;
5using UnityEngine;
6
7[JsonObject(MemberSerialization.OptOut)]
9{
10 public List<CustomThingContent> items = new List<CustomThingContent>();
11
12 public List<Thing> Generate(Card owner)
13 {
14 Load();
15 List<Thing> list = new List<Thing>();
16 int createLv = owner?.trait?.ShopLv ?? (-1);
17 foreach (CustomThingContent item in items)
18 {
19 try
20 {
21 Thing thing = item.Create(createLv);
22 if (thing != null)
23 {
24 list.Add(thing);
25 continue;
26 }
27 ModUtil.LogModError("can't create stock item '" + item.id + "' in '" + base.ContentId + "'", base.Owner);
28 }
29 catch (Exception ex)
30 {
31 ModUtil.LogModError("can't create stock item '" + item.id + "' in '" + base.ContentId + "'\n" + ex.Message, base.Owner);
32 Debug.LogException(ex);
33 }
34 }
35 return list;
36 }
37
38 public static CustomMerchantStock CreateFromId(string stockId, ModPackage owner = null)
39 {
40 var (fileInfo, eMod) = PackageIterator.GetFilesEx("Data/stock_" + stockId + ".json").LastOrDefault();
41 if (fileInfo == null)
42 {
43 return null;
44 }
45 if (owner == null)
46 {
47 owner = eMod as ModPackage;
48 }
49 return new CustomMerchantStock
50 {
51 ContentId = "MerchantStock/" + stockId,
52 Owner = owner,
53 File = fileInfo
54 };
55 }
56
57 protected override void LoadContent()
58 {
59 CustomMerchantStock customMerchantStock = IO.LoadFile<CustomMerchantStock>(base.File.FullName);
60 items = customMerchantStock.items;
61 }
62
63 public override string ToString()
64 {
65 return $"{base.ContentId}/items({items.Count})";
66 }
67}
Definition: Card.cs:11
Trait trait
Definition: Card.cs:54
string ContentId
Definition: CustomContent.cs:6
static CustomMerchantStock CreateFromId(string stockId, ModPackage owner=null)
override string ToString()
List< Thing > Generate(Card owner)
override void LoadContent()
List< CustomThingContent > items
Definition: Thing.cs:8
virtual int ShopLv
Definition: Trait.cs:525