Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
TraitSeed.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.Linq;
3using UnityEngine;
4
5public class TraitSeed : Trait
6{
7 public static List<SourceObj.Row> listSeeds;
8
10
11 public override int InstallBottomPriority => 10000;
12
13 public override bool CanExtendBuild => true;
14
15 public override bool CanChangeHeight => false;
16
17 public override bool CanName => true;
18
19 public override int DefaultStock => 3 + EClass.rnd(10);
20
21 public override void OnCreate(int lv)
22 {
24 owner.c_seed = EClass.rnd(10000);
25 }
26
27 public override void SetName(ref string s)
28 {
29 s = "_of".lang(row.GetName(), s);
30 }
31
32 public override void WriteNote(UINote n, bool identified)
33 {
34 base.WriteNote(n, identified);
35 int num = 1;
36 if (!row._growth.IsEmpty() && row._growth.Length >= 4)
37 {
38 if (row._growth.Length >= 5)
39 {
40 num = row._growth[4].ToInt();
41 }
42 n.AddText("isHarvestCrop".lang(num.ToString() ?? ""));
43 }
44 n.AddText("isConsumeFertility".lang((0.1f * (float)row.costSoil).ToString() ?? ""));
45 if (row.tag.Contains("flood"))
46 {
47 n.AddText("isWaterCrop");
48 }
49 if (row.growth != null && row.growth.NeedSunlight)
50 {
51 n.AddText("isNeedSun");
52 }
53 if (row.growth == null || !row.growth.CanLevelSeed)
54 {
55 n.AddText("isDecoSeed", FontColor.Warning);
56 }
57 }
58
59 public void TrySprout(bool force = false, bool sucker = false, VirtualDate date = null)
60 {
61 Point pos = owner.pos;
62 if (!pos.HasObj && pos.cell.CanGrow(row, date ?? new VirtualDate()))
63 {
64 pos.SetObj(row.id, 1, owner.dir);
66 if (sucker)
67 {
69 }
70 else
71 {
72 owner.Destroy();
73 }
74 }
75 }
76
77 public static Thing MakeSeed(SourceObj.Row obj, PlantData plant = null)
78 {
79 Thing thing = plant?.seed;
81 {
82 thing = null;
83 }
84 Thing thing2 = ThingGen.Create("seed");
85 ApplySeed(thing2, obj.id);
86 if (thing != null && obj.growth != null && obj.growth.CanLevelSeed)
87 {
88 foreach (Element value in thing.elements.dict.Values)
89 {
90 if (value.IsFoodTrait)
91 {
92 thing2.elements.SetTo(value.id, value.Value);
93 }
94 }
95 thing2.SetEncLv(thing.encLV);
96 thing2.elements.SetBase(2, EClass.curve(thing2.encLV, 50, 10, 80));
97 thing2.c_refText = thing.c_refText;
98 thing2.c_seed = thing.c_seed;
99 int num = plant?.water ?? 0;
100 int num2 = plant?.fert ?? 0;
101 int num3 = 220 / (Mathf.Clamp(EClass.pc.Evalue(286) - thing.LV, 0, 50) * 2 + 10 + num * 2 + ((num2 > 0) ? 20 : 0) + (EClass.pc.HasElement(1325) ? 25 : 0));
103 {
104 num3 = 2 + num3 * 2;
105 }
106 if (EClass.rnd(num3) == 0)
107 {
108 int num4 = Mathf.Max(5, EClass.pc.Evalue(286)) - thing2.encLV;
109 if (num4 <= 0)
110 {
112 {
113 Msg.Say("seedLvLimit", thing2);
114 }
115 }
116 else
117 {
118 int num5 = Mathf.Clamp(EClass.rnd(num4) - 5, 1, EClass.player.isAutoFarming ? 3 : 10);
119 LevelSeed(thing2, obj, num5);
120 EClass.pc.PlaySound("seed_level");
121 }
122 }
123 Rand.SetSeed();
124 }
125 thing2.SetBlessedState(BlessedState.Normal);
126 return thing2;
127 }
128
129 public static void LevelSeed(Thing t, SourceObj.Row obj, int num)
130 {
131 if (obj == null || obj.growth == null || !obj.growth.CanLevelSeed)
132 {
133 return;
134 }
135 for (int i = 0; i < num; i++)
136 {
137 if (obj == null || obj.objType == "crop")
138 {
139 if (t.encLV == 0)
140 {
142 }
143 else
144 {
147 }
148 }
149 t.ModEncLv(1);
150 }
151 }
152
153 public static Thing MakeSeed(string idSource)
154 {
155 return MakeSeed(EClass.sources.objs.alias[idSource]);
156 }
157
158 public static Thing ApplySeed(Thing t, int refval)
159 {
160 t.refVal = refval;
161 SourceObj.Row row = EClass.sources.objs.map.TryGetValue(refval);
162 if (row != null && row.vals.Length != 0)
163 {
164 t.idSkin = row.vals[0].ToInt();
165 }
166 return t;
167 }
168
169 public static Thing MakeSeed(SourceObj.Row obj)
170 {
171 Thing thing = ThingGen.Create("seed");
172 ApplySeed(thing, obj.id);
173 return thing;
174 }
175
176 public static Thing MakeRandomSeed(bool enc = false)
177 {
178 Thing thing = ThingGen.Create("seed", null);
179 SourceObj.Row randomSeedObj = GetRandomSeedObj();
180 ApplySeed(thing, randomSeedObj.id);
181 return thing;
182 }
183
185 {
186 if (listSeeds == null)
187 {
188 listSeeds = EClass.sources.objs.rows.Where((SourceObj.Row s) => s.HasTag(CTAG.seed) && !s.HasTag(CTAG.rareSeed)).ToList();
189 }
190 return listSeeds.RandomItemWeighted((SourceObj.Row a) => a.chance);
191 }
192}
BlessedState
Definition: BlessedState.cs:2
CTAG
Definition: CTAG.cs:2
FontColor
Definition: FontColor.cs:2
if(item3.idFile==idFirstFile &&item3.id==idFirstTopic)
Definition: UIBook.cs:627
void Add(Act a, string s="")
Definition: ActPlan.cs:11
ElementContainerCard elements
Definition: Card.cs:37
string id
Definition: Card.cs:31
bool HasElement(int ele, int req=1)
Definition: Card.cs:5214
SoundSource PlaySound(string id, float v=1f, bool spatial=true)
Definition: Card.cs:5404
string c_refText
Definition: Card.cs:1529
int c_seed
Definition: Card.cs:1241
virtual void SetBlessedState(BlessedState s)
Definition: Card.cs:3572
Point pos
Definition: Card.cs:55
int refVal
Definition: Card.cs:190
int encLV
Definition: Card.cs:310
void ModEncLv(int a)
Definition: Card.cs:3549
void SetEncLv(int a)
Definition: Card.cs:3567
void Destroy()
Definition: Card.cs:4538
virtual Thing Thing
Definition: Card.cs:1934
int Evalue(int ele)
Definition: Card.cs:2431
int dir
Definition: Card.cs:142
int LV
Definition: Card.cs:370
bool CanGrow(SourceObj.Row obj, VirtualDate date)
Definition: Cell.cs:1649
static void AddRandomFoodEnc(Thing t)
Definition: CraftUtil.cs:36
static void ModRandomFoodEnc(Thing t)
Definition: CraftUtil.cs:15
Definition: EClass.cs:5
static int curve(int a, int start, int step, int rate=75)
Definition: EClass.cs:55
static int rnd(int a)
Definition: EClass.cs:50
static Zone _zone
Definition: EClass.cs:20
static Map _map
Definition: EClass.cs:18
static SourceManager sources
Definition: EClass.cs:42
static Player player
Definition: EClass.cs:12
static Chara pc
Definition: EClass.cs:14
Dictionary< int, Element > dict
void SetTo(int id, int v)
Element SetBase(string alias, int v, int potential=0)
int id
Definition: ELEMENT.cs:240
int Value
Definition: ELEMENT.cs:282
bool IsFoodTrait
Definition: ELEMENT.cs:354
PlantData AddPlant(Point pos, Thing seed)
Definition: Map.cs:1930
Definition: Msg.cs:5
static string Say(string idLang, string ref1, string ref2=null, string ref3=null, string ref4=null)
Definition: Msg.cs:58
bool isAutoFarming
Definition: Player.cs:982
Definition: Point.cs:9
void SetObj(int id=0, int value=1, int dir=0)
Definition: Point.cs:892
bool HasObj
Definition: Point.cs:137
Cell cell
Definition: Point.cs:51
Definition: Rand.cs:4
static void SetSeed(int a=-1)
Definition: Rand.cs:37
SourceObj objs
string GetName(int id)
Definition: SourceObj.cs:149
static Thing Create(string id, int idMat=-1, int lv=-1)
Definition: ThingGen.cs:53
Definition: Thing.cs:8
int id
Definition: TileRow.cs:8
static SourceObj.Row GetRandomSeedObj()
Definition: TraitSeed.cs:184
override void SetName(ref string s)
Definition: TraitSeed.cs:27
override void OnCreate(int lv)
Definition: TraitSeed.cs:21
override int InstallBottomPriority
Definition: TraitSeed.cs:11
override bool CanName
Definition: TraitSeed.cs:17
static Thing ApplySeed(Thing t, int refval)
Definition: TraitSeed.cs:158
override void WriteNote(UINote n, bool identified)
Definition: TraitSeed.cs:32
static Thing MakeSeed(SourceObj.Row obj, PlantData plant=null)
Definition: TraitSeed.cs:77
override int DefaultStock
Definition: TraitSeed.cs:19
override bool CanChangeHeight
Definition: TraitSeed.cs:15
static Thing MakeSeed(string idSource)
Definition: TraitSeed.cs:153
override bool CanExtendBuild
Definition: TraitSeed.cs:13
static Thing MakeRandomSeed(bool enc=false)
Definition: TraitSeed.cs:176
void TrySprout(bool force=false, bool sucker=false, VirtualDate date=null)
Definition: TraitSeed.cs:59
static void LevelSeed(Thing t, SourceObj.Row obj, int num)
Definition: TraitSeed.cs:129
static List< SourceObj.Row > listSeeds
Definition: TraitSeed.cs:7
static Thing MakeSeed(SourceObj.Row obj)
Definition: TraitSeed.cs:169
SourceObj.Row row
Definition: TraitSeed.cs:9
Definition: Trait.cs:7
Card owner
Definition: Trait.cs:26
Definition: UINote.cs:6
UIItem AddText(string text, FontColor color=FontColor.DontChange)
Definition: UINote.cs:113
Definition: Zone.cs:12
virtual bool IsUserZone
Definition: Zone.cs:264
static List< Thing > Suckers
Definition: Zone.cs:80