Elin Decompiled Documentation EA 23.153 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)
50 {
51 if (row.growth.GrowOnLand)
52 {
53 n.AddText("isGrowOnLand");
54 }
55 if (row.growth.GrowUndersea)
56 {
57 n.AddText("isGrowUndersea");
58 }
59 if (row.growth.NeedSunlight)
60 {
61 n.AddText("isNeedSun");
62 }
63 }
64 if (row.growth == null || !row.growth.CanLevelSeed)
65 {
66 n.AddText("isDecoSeed", FontColor.Warning);
67 }
68 }
69
70 public void TrySprout(bool force = false, bool sucker = false, VirtualDate date = null)
71 {
72 Point pos = owner.pos;
73 if (!pos.HasObj && pos.cell.CanGrow(row, date ?? new VirtualDate()))
74 {
75 pos.SetObj(row.id, 1, owner.dir);
77 if (sucker)
78 {
80 }
81 else
82 {
83 owner.Destroy();
84 }
85 }
86 }
87
88 public static Thing MakeSeed(SourceObj.Row obj, PlantData plant = null)
89 {
90 Thing thing = plant?.seed;
92 {
93 thing = null;
94 }
95 Thing thing2 = ThingGen.Create("seed");
96 ApplySeed(thing2, obj.id);
97 if (thing != null && obj.growth != null && obj.growth.CanLevelSeed)
98 {
99 foreach (Element value in thing.elements.dict.Values)
100 {
101 if (value.IsFoodTrait)
102 {
103 thing2.elements.SetTo(value.id, value.Value);
104 }
105 }
106 thing2.SetEncLv(thing.encLV);
107 thing2.elements.SetBase(2, EClass.curve(thing2.encLV, 50, 10, 80));
108 thing2.c_refText = thing.c_refText;
109 thing2.c_seed = thing.c_seed;
110 int num = plant?.water ?? 0;
111 int num2 = plant?.fert ?? 0;
112 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));
114 {
115 num3 = 2 + num3 * 2;
116 }
117 if (EClass.rnd(num3) == 0 && EClass._zone.IsPCFactionOrTent)
118 {
119 int num4 = Mathf.Max(5, EClass.pc.Evalue(286)) - thing2.encLV;
120 if (num4 <= 0)
121 {
123 {
124 Msg.Say("seedLvLimit", thing2);
125 }
126 }
127 else
128 {
129 int num5 = Mathf.Clamp(EClass.rnd(num4) - 5, 1, EClass.player.isAutoFarming ? 3 : 10);
130 LevelSeed(thing2, obj, num5);
131 EClass.pc.PlaySound("seed_level");
132 }
133 }
134 Rand.SetSeed();
135 }
136 thing2.SetBlessedState(BlessedState.Normal);
137 return thing2;
138 }
139
140 public static void LevelSeed(Thing t, SourceObj.Row obj, int num)
141 {
142 if (obj == null || obj.growth == null || !obj.growth.CanLevelSeed)
143 {
144 return;
145 }
146 for (int i = 0; i < num; i++)
147 {
148 if (obj == null || obj.objType == "crop")
149 {
150 if (t.encLV == 0)
151 {
153 }
154 else
155 {
158 }
159 }
160 t.ModEncLv(1);
161 }
162 }
163
164 public static Thing MakeSeed(string idSource)
165 {
166 return MakeSeed(EClass.sources.objs.alias[idSource]);
167 }
168
169 public static Thing ApplySeed(Thing t, int refval)
170 {
171 t.refVal = refval;
172 SourceObj.Row row = EClass.sources.objs.map.TryGetValue(refval);
173 if (row != null && row.vals.Length != 0)
174 {
175 t.idSkin = row.vals[0].ToInt();
176 }
177 return t;
178 }
179
180 public static Thing MakeSeed(SourceObj.Row obj)
181 {
182 Thing thing = ThingGen.Create("seed");
183 ApplySeed(thing, obj.id);
184 return thing;
185 }
186
187 public static Thing MakeRandomSeed(bool enc = false)
188 {
189 Thing thing = ThingGen.Create("seed", null);
190 SourceObj.Row randomSeedObj = GetRandomSeedObj();
191 ApplySeed(thing, randomSeedObj.id);
192 return thing;
193 }
194
196 {
197 if (listSeeds == null)
198 {
199 listSeeds = EClass.sources.objs.rows.Where((SourceObj.Row s) => s.HasTag(CTAG.seed) && !s.HasTag(CTAG.rareSeed)).ToList();
200 }
201 return listSeeds.RandomItemWeighted((SourceObj.Row a) => a.chance);
202 }
203}
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:5566
SoundSource PlaySound(string id, float v=1f, bool spatial=true)
Definition: Card.cs:5776
string c_refText
Definition: Card.cs:1589
int c_seed
Definition: Card.cs:1277
virtual void SetBlessedState(BlessedState s)
Definition: Card.cs:3740
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:3691
void SetEncLv(int a)
Definition: Card.cs:3709
void Destroy()
Definition: Card.cs:4783
virtual Thing Thing
Definition: Card.cs:1994
int Evalue(int ele)
Definition: Card.cs:2507
int dir
Definition: Card.cs:142
int LV
Definition: Card.cs:370
bool CanGrow(SourceObj.Row obj, VirtualDate date)
Definition: Cell.cs:1653
static void AddRandomFoodEnc(Thing t)
Definition: CraftUtil.cs:37
static void ModRandomFoodEnc(Thing t)
Definition: CraftUtil.cs:16
Definition: EClass.cs:5
static int curve(int a, int start, int step, int rate=75)
Definition: EClass.cs:63
static int rnd(int a)
Definition: EClass.cs:58
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:248
int Value
Definition: ELEMENT.cs:290
bool IsFoodTrait
Definition: ELEMENT.cs:362
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:997
Definition: Point.cs:9
void SetObj(int id=0, int value=1, int dir=0)
Definition: Point.cs:908
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:195
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:169
override void WriteNote(UINote n, bool identified)
Definition: TraitSeed.cs:32
static Thing MakeSeed(SourceObj.Row obj, PlantData plant=null)
Definition: TraitSeed.cs:88
override int DefaultStock
Definition: TraitSeed.cs:19
override bool CanChangeHeight
Definition: TraitSeed.cs:15
static Thing MakeSeed(string idSource)
Definition: TraitSeed.cs:164
override bool CanExtendBuild
Definition: TraitSeed.cs:13
static Thing MakeRandomSeed(bool enc=false)
Definition: TraitSeed.cs:187
void TrySprout(bool force=false, bool sucker=false, VirtualDate date=null)
Definition: TraitSeed.cs:70
static void LevelSeed(Thing t, SourceObj.Row obj, int num)
Definition: TraitSeed.cs:140
static List< SourceObj.Row > listSeeds
Definition: TraitSeed.cs:7
static Thing MakeSeed(SourceObj.Row obj)
Definition: TraitSeed.cs:180
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
bool IsPCFactionOrTent
Definition: Zone.cs:469
virtual bool IsUserZone
Definition: Zone.cs:266
static List< Thing > Suckers
Definition: Zone.cs:80