Elin Decompiled Documentation EA 23.321 Nightly Patch 1
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("NoteText_enc", "isHarvestCrop".lang(num.ToString() ?? ""));
43 }
44 n.AddText("NoteText_enc", "isConsumeFertility".lang((0.1f * (float)row.costSoil).ToString() ?? ""));
45 if (row.tag.Contains("flood"))
46 {
47 n.AddText("NoteText_enc", "isWaterCrop");
48 }
49 if (row.tag.Contains("dyeable"))
50 {
51 n.AddText("NoteText_enc", "isDyeableCrop");
52 }
53 if (row.growth != null)
54 {
55 if (row.growth.GrowOnLand)
56 {
57 n.AddText("NoteText_enc", "isGrowOnLand");
58 }
59 if (row.growth.GrowUndersea)
60 {
61 n.AddText("NoteText_enc", "isGrowUndersea");
62 }
63 if (row.growth.NeedSunlight)
64 {
65 n.AddText("NoteText_enc", "isNeedSun");
66 }
67 }
68 if (row.growth == null || !row.growth.CanLevelSeed)
69 {
70 n.AddText("NoteText_enc", "isDecoSeed", FontColor.Warning);
71 }
72 }
73
74 public void TrySprout(bool force = false, bool sucker = false, VirtualDate date = null)
75 {
76 Point pos = owner.pos;
77 if (!pos.HasObj && pos.cell.CanGrow(row, date ?? new VirtualDate()))
78 {
79 pos.SetObj(row.id, 1, owner.dir);
81 if (owner.isDyed && pos.sourceObj.ContainsTag("dyeable"))
82 {
83 pos.cell.isObjDyed = true;
84 pos.cell.objMat = (byte)owner.DyeMat.id;
85 }
86 if (sucker)
87 {
89 }
90 else
91 {
92 owner.Destroy();
93 }
94 }
95 }
96
97 public static Thing MakeRandomSeed(bool enc = false)
98 {
99 Thing thing = ThingGen.Create("seed", null);
100 SourceObj.Row randomSeedObj = GetRandomSeedObj();
101 ApplySeed(thing, randomSeedObj.id);
102 return thing;
103 }
104
105 public static Thing MakeSeed(string idSource)
106 {
107 return MakeSeed(EClass.sources.objs.alias[idSource]);
108 }
109
110 public static Thing MakeSeed(SourceObj.Row obj)
111 {
112 Thing thing = ThingGen.Create("seed");
113 ApplySeed(thing, obj.id);
114 return thing;
115 }
116
117 public static Thing MakeSeed(Cell cell)
118 {
119 Thing thing = MakeSeed(cell.sourceObj, EClass._map.TryGetPlant(cell));
120 if (thing != null && cell.isObjDyed && cell.sourceObj.ContainsTag("dyeable"))
121 {
122 thing.Dye(cell.matObj);
123 }
124 return thing;
125 }
126
127 public static Thing MakeSeed(string id, PlantData plant = null)
128 {
129 return MakeSeed(EClass.sources.objs.alias[id], plant);
130 }
131
132 public static Thing MakeSeed(SourceObj.Row obj, PlantData plant = null)
133 {
134 Thing thing = plant?.seed;
136 {
137 thing = null;
138 }
139 Thing thing2 = ThingGen.Create("seed");
140 ApplySeed(thing2, obj.id);
141 if (thing != null && obj.growth != null && obj.growth.CanLevelSeed)
142 {
143 foreach (Element value in thing.elements.dict.Values)
144 {
145 if (value.IsFoodTrait)
146 {
147 thing2.elements.SetTo(value.id, value.Value);
148 }
149 }
150 thing2.SetEncLv(thing.encLV);
151 thing2.c_refText = thing.c_refText;
152 thing2.c_seed = thing.c_seed;
153 int num = plant?.water ?? 0;
154 int num2 = plant?.fert ?? 0;
155 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));
157 {
158 num3 = 2 + num3 * 2;
159 }
160 if (EClass.rnd(num3) == 0 && EClass._zone.IsPCFactionOrTent)
161 {
162 int num4 = Mathf.Max(5, EClass.pc.Evalue(286)) - thing2.encLV;
163 if (num4 <= 0)
164 {
166 {
167 Msg.Say("seedLvLimit", thing2);
168 }
169 }
170 else
171 {
172 int num5 = Mathf.Clamp(EClass.rnd(num4) - 5, 1, EClass.player.isAutoFarming ? 3 : 10);
173 LevelSeed(thing2, obj, num5);
174 EClass.pc.PlaySound("seed_level");
175 }
176 }
177 thing2.elements.SetBase(2, EClass.curve(thing2.encLV, 50, 10, 80));
178 Rand.SetSeed();
179 }
180 thing2.SetBlessedState(BlessedState.Normal);
181 return thing2;
182 }
183
184 public static void LevelSeed(Thing t, SourceObj.Row obj, int num)
185 {
186 if (obj == null || obj.growth == null || !obj.growth.CanLevelSeed)
187 {
188 return;
189 }
190 for (int i = 0; i < num; i++)
191 {
192 if (obj == null || obj.objType == "crop")
193 {
194 if (t.encLV == 0)
195 {
197 }
198 else
199 {
202 }
203 }
204 t.ModEncLv(1);
205 }
206 }
207
208 public static Thing ApplySeed(Thing t, int refval)
209 {
210 t.refVal = refval;
211 SourceObj.Row row = EClass.sources.objs.map.TryGetValue(refval);
212 if (row != null && row.vals.Length != 0)
213 {
214 t.idSkin = row.vals[0].ToInt();
215 }
216 return t;
217 }
218
220 {
221 if (listSeeds == null)
222 {
223 listSeeds = EClass.sources.objs.rows.Where((SourceObj.Row s) => s.HasTag(CTAG.seed) && !s.HasTag(CTAG.rareSeed) && s.alias != "redpepper").ToList();
224 }
225 return listSeeds.RandomItemWeighted((SourceObj.Row a) => a.chance);
226 }
227}
BlessedState
Definition: BlessedState.cs:2
CTAG
Definition: CTAG.cs:2
@ plant
if(!match.Success)
FontColor
Definition: FontColor.cs:2
void Add(Act a, string s="")
Definition: ActPlan.cs:11
ElementContainerCard elements
Definition: Card.cs:42
string id
Definition: Card.cs:36
SourceMaterial.Row DyeMat
Definition: Card.cs:1992
SoundSource PlaySound(string id, float v=1f, bool spatial=true)
Definition: Card.cs:6578
string c_refText
Definition: Card.cs:1669
int c_seed
Definition: Card.cs:1345
virtual void SetBlessedState(BlessedState s)
Definition: Card.cs:4069
Point pos
Definition: Card.cs:60
void Dye(string idMat)
Definition: Card.cs:6411
int refVal
Definition: Card.cs:209
int encLV
Definition: Card.cs:329
void ModEncLv(int a)
Definition: Card.cs:4020
void SetEncLv(int a)
Definition: Card.cs:4038
bool isDyed
Definition: Card.cs:461
void Destroy()
Definition: Card.cs:5284
virtual Thing Thing
Definition: Card.cs:2110
int Evalue(int ele)
Definition: Card.cs:2704
int dir
Definition: Card.cs:149
bool HasElement(int ele, bool includeNagative=false)
Definition: Card.cs:6320
int LV
Definition: Card.cs:389
Definition: Cell.cs:7
SourceMaterial.Row matObj
Definition: Cell.cs:1046
SourceObj.Row sourceObj
Definition: Cell.cs:1084
bool CanGrow(SourceObj.Row obj, VirtualDate date)
Definition: Cell.cs:1689
bool isObjDyed
Definition: Cell.cs:626
static void AddRandomFoodEnc(Thing t)
Definition: CraftUtil.cs:44
static void ModRandomFoodEnc(Thing t)
Definition: CraftUtil.cs:23
Definition: EClass.cs:6
static int curve(long _a, int start, int step, int rate=75)
Definition: EClass.cs:69
static Zone _zone
Definition: EClass.cs:21
static Map _map
Definition: EClass.cs:19
static int rnd(long a)
Definition: EClass.cs:59
static SourceManager sources
Definition: EClass.cs:43
static Player player
Definition: EClass.cs:13
static Chara pc
Definition: EClass.cs:15
Dictionary< int, Element > dict
void SetTo(int id, int v)
Element SetBase(string alias, int v, int potential=0)
int id
Definition: ELEMENT.cs:257
int Value
Definition: ELEMENT.cs:299
bool IsFoodTrait
Definition: ELEMENT.cs:371
PlantData TryGetPlant(Point p)
Definition: Map.cs:1987
PlantData AddPlant(Point pos, Thing seed)
Definition: Map.cs:1997
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:1251
Definition: Point.cs:9
void SetObj(int id=0, int value=1, int dir=0)
Definition: Point.cs:934
SourceObj.Row sourceObj
Definition: Point.cs:69
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:44
SourceObj objs
string GetName(int id)
Definition: SourceObj.cs:273
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:219
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:208
override void WriteNote(UINote n, bool identified)
Definition: TraitSeed.cs:32
static Thing MakeSeed(SourceObj.Row obj, PlantData plant=null)
Definition: TraitSeed.cs:132
override int DefaultStock
Definition: TraitSeed.cs:19
override bool CanChangeHeight
Definition: TraitSeed.cs:15
static Thing MakeSeed(string idSource)
Definition: TraitSeed.cs:105
override bool CanExtendBuild
Definition: TraitSeed.cs:13
static Thing MakeRandomSeed(bool enc=false)
Definition: TraitSeed.cs:97
void TrySprout(bool force=false, bool sucker=false, VirtualDate date=null)
Definition: TraitSeed.cs:74
static void LevelSeed(Thing t, SourceObj.Row obj, int num)
Definition: TraitSeed.cs:184
static Thing MakeSeed(string id, PlantData plant=null)
Definition: TraitSeed.cs:127
static List< SourceObj.Row > listSeeds
Definition: TraitSeed.cs:7
static Thing MakeSeed(Cell cell)
Definition: TraitSeed.cs:117
static Thing MakeSeed(SourceObj.Row obj)
Definition: TraitSeed.cs:110
SourceObj.Row row
Definition: TraitSeed.cs:9
Definition: Trait.cs:7
Card owner
Definition: Trait.cs:28
Definition: UINote.cs:6
UIItem AddText(string text, FontColor color=FontColor.DontChange)
Definition: UINote.cs:113
Definition: Zone.cs:12
bool IsPCFactionOrTent
Definition: Zone.cs:480
virtual bool IsUserZone
Definition: Zone.cs:275
static List< Thing > Suckers
Definition: Zone.cs:83