-
Notifications
You must be signed in to change notification settings - Fork 6
/
Character.cs
2794 lines (2552 loc) · 88.7 KB
/
Character.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace Noxico
{
public enum Gender
{
RollDice, Male, Female, Herm, Neuter, Invisible
}
public enum MorphReportLevel
{
NoReports, PlayerOnly, Anyone
}
public enum TeamBehaviorClass
{
Attacking, Flocking
}
public enum TeamBehaviorAction
{
Nothing, Attack, PreferentialAttack, Avoid, Flock, FlockAlike,
CloseByAttack = 8, ThiefingPlayer
}
public enum Posture
{
Upright, Prone, Seated
}
public partial class Character : TokenCarrier
{
public static Dictionary<string, List<string>> Powers;
public static List<Token> Bodyplans;
public static StringBuilder MorphBuffer = new StringBuilder();
public static string[] StatNames;
public Name Name { get; set; }
public BoardChar BoardChar { get; set; }
public SpeechFilter SpeechFilter { get; set; }
public Culture Culture
{
get
{
return (!HasToken("culture")) ?
Culture.DefaultCulture :
Culture.FindCultureByName(GetToken("culture").Text);
}
set
{
if (!HasToken("culture")) AddToken("culture");
GetToken("culture").Text = value.ToString();
}
}
public string Title
{
get
{
if (!HasToken("title")) AddToken("title").Text = "thing";
return GetToken("title").Text;
}
set
{
if (!HasToken("title")) AddToken("title").Text = "thing";
GetToken("title").Text = value;
}
}
public bool IsProperNamed
{
get
{
if (!HasToken("ispropernamed"))
AddToken("ispropernamed").Text = "false";
return (GetToken("ispropernamed").Text == "true") ? true : false;
}
set
{
if (!HasToken("ispropernamed"))
AddToken("ispropernamed").Text = "false";
GetToken("ispropernamed").Text = value.ToString().ToLower();
}
}
public string A
{
get
{
if (!HasToken("a")) AddToken("a").Text = "a";
return GetToken("a").Text;
}
set
{
if (!HasToken("a")) AddToken("a").Text = "a";
GetToken("a").Text = value;
}
}
public float Capacity
{
get
{
if (!HasToken("capacity")) AddToken("capacity").Value = 0;
return GetToken("capacity").Value;
}
private set
{
if (!HasToken("capacity")) AddToken("capacity").Value = 0;
GetToken("capacity").Value = value;
}
}
public float Carried
{
get
{
if (!HasToken("carried")) AddToken("carried").Value = 0;
return GetToken("carried").Value;
}
private set
{
if (!HasToken("carried")) AddToken("carried").Value = 0;
GetToken("carried").Value = value;
}
}
public string ID
{
get
{
if (HasToken("player"))
return "\xF4EF" + Name.ToID() + "#" + GetToken("player").IntValue;
if (string.IsNullOrEmpty(Name.FirstName))
return Title.ToID();
return Name.ToID();
}
}
public string OriginalID
{
get
{
if (HasToken("originalID"))
return GetToken("originalID").Text;
return ID;
}
}
/// <summary>
/// Returns the full name of the character with title, or just the title.
/// </summary>
public override string ToString()
{
var ret = Title;
if (HasToken("title"))
ret = GetToken("title").Text;
else if (IsProperNamed)
{
return i18n.GetString("lookat_character_tostring").Viewpoint(this);
}
return ret;
}
public string GetKnownName(bool fullName = false, bool appendTitle = false, bool the = false, bool initialCaps = false)
{
//TODO: i18n
if (HasToken("player") || HasToken("special"))
return Name.ToString(fullName);
if (HasToken("beast"))
return string.Format("{0} {1}", initialCaps ? (the ? "The" : A.ToUpperInvariant()) : (the ? "the" : A), Title); //Path("terms/generic").Text);
var player = NoxicoGame.Me.Player.Character;
//TODO: logic duplicated from UpdateTitle()
if (player != null && player.Path("ships/" + ID) != null)
{
if (appendTitle)
return string.Format("{0}, {1} {2}",
Name.ToString(fullName),
(the ? "the" : A),
Title);
return Name.ToString(fullName);
}
return string.Format("{0} {1}", initialCaps ? (the ? "The" : A.ToUpperInvariant()) : (the ? "the" : A), Title);
}
/// <summary>
/// Returns the character's title.
/// </summary>
public string GetTheTitle()
{
if (HasToken("title"))
return GetToken("title").Text;
return string.Format("{0} {1}", A, Title);
}
public Gender Gender
{
get
{
if (HasToken("penis") && HasToken("vagina"))
return Gender.Herm;
else if (HasToken("penis"))
return Gender.Male;
else if (HasToken("vagina"))
return Gender.Female;
return Gender.Neuter;
}
}
public Gender BiologicalGender
{
get
{
return Gender;
}
}
/// <summary>
/// Returns the character's visible gender according to body parts.
/// </summary>
public Gender PercievedGender
{
get
{
if (HasToken("beast"))
return Gender.Neuter;
if (HasToken("player"))
return (Gender)(PreferredGender);
//TODO: detect a relationship token and return the preferred gender if known.
var pants = GetEquippedItemBySlot("pants");
var underpants = GetEquippedItemBySlot("underpants");
var pantsCT = (pants == null) ? true : pants.CanSeeThrough(this);
var underpantsCT = (underpants == null) ? true : underpants.CanSeeThrough(this);
var crotchVisible = (pantsCT && underpantsCT);
var dickSize = GetPenisSize(false);
if (dickSize < 4 && !crotchVisible)
dickSize = 0; //hide tiny dicks with clothing on.
var scoreM = 0.0f; // note scores not capped at 1.0
var scoreF = 0.0f;
// calibrated using felin min. penis size
// size 13 or more guarantees masculine looks
scoreM += dickSize * 0.0425f;
// calibrated using human min. breast size
// size 2 or more breaks the feminine looks threshold
scoreF += GetBreastSize() * 0.51f;
// visible vagina implies feminine looks
if (HasToken("vagina") && crotchVisible)
scoreF += 0.51f;
// hair > 11 makes for feminine looks - even if you got nothing else
if (HasToken("hair"))
scoreF += this.Path("hair/length").Value * 0.046f;
// TODO: consider hips & waist
// decide what to return based on quadrants
// currently not good with flat chested fela and long haired male naga, however,
// since nagas are not invisible or explicit gender, they'll just get called "naga", so that's ok for them
var decision = Noxico.Gender.Female; // default. never trust floating point
if (scoreM > 0.5f && scoreF > 0.5f) decision = Gender.Herm;
if (scoreM < 0.5f && scoreF < 0.5f) decision = Gender.Neuter;
if (scoreM > 0.5f && scoreF < 0.5f) decision = Gender.Male;
if (scoreM < 0.5f && scoreF > 0.5f) decision = Gender.Female;
// felin are invisiblegender and more of a problem.
// fela get an exception because I can't think of a better way to do it
if (decision == Gender.Neuter && HasToken("culture") && GetToken("culture").Text == "felin")
decision = Gender.Female;
return decision;
}
}
public Gender PreferredGender
{
get
{
if (HasToken("preferredgender"))
{
var token = GetToken("preferredgender");
if (token.Text.IsBlank())
return (Gender)((int)GetToken("preferredgender").Value);
else
return (Gender)Enum.Parse(typeof(Gender), token.Text, true);
}
return BiologicalGender; //stopgap
}
}
public Posture Posture { get { return BoardChar.Posture; } set { BoardChar.Posture = value; } }
public void UpdateTitle()
{
// enums (being ints in disguise) compare better than strings. -- K
// yeah, I know that, it was like that when I got here -- sparks
//The ORIGINAL plan:
// Neither: "felin"
// Explicit: "male felin"
// Invisible: "felir"
// -- K
//Okay fuck this, new rule. If we have a terms token, it must contain all four options spelled out verbatim.
//Alternatively, if it *only* contains a generic, we use that.
var pg = PercievedGender; //cache the value -- K
Title = null; // start fresh
var terms = GetToken("terms");
if (terms.HasToken("generic"))
Title = terms.GetToken("generic").Text;
else
Title = terms.GetToken(pg.ToString().ToLowerInvariant()).Text;
if (HasToken("prefixes")) // add prefixes, 'vorpal', 'dire' etc
{
foreach (var prefix in GetToken("prefixes").Tokens)
Title = prefix.Name + " " + Title;
}
A = HasToken("_a") ? GetToken("_a").Text : Title.GetArticle();
}
public string HeSheIt(bool lower = false)
{
var rets = i18n.GetArray("hesheshiit");
return lower ? rets[(int)PercievedGender].ToLowerInvariant() : rets[(int)PercievedGender];
}
public string HisHerIts(bool lower = false)
{
var rets = i18n.GetArray("hisherhirits");
return lower ? rets[(int)PercievedGender].ToLowerInvariant() : rets[(int)PercievedGender];
}
public string HimHerIt(bool lower = false)
{
var rets = i18n.GetArray("himherhirit");
return lower ? rets[(int)PercievedGender].ToLowerInvariant() : rets[(int)PercievedGender];
}
public float MaximumHealth
{
get
{
return GetStat("body") * 2 + 50 + (HasToken("healthbonus") ? GetToken("healthbonus").Value : 0);
}
}
public float Health
{
get
{
return GetToken("health").Value;
}
set
{
GetToken("health").Value = Math.Min(MaximumHealth, value);
}
}
public void Heal(float amount)
{
Health += amount;
}
public Character()
{
}
public void FixBoobs()
{
//moved from FixBroken() since FixBoobs() may need to be called from within FixBroken() and it's best to avoid an infinite loop.
if (!this.HasToken("breasts"))
{
var boob = this.AddToken("breasts");
boob.AddToken("amount", 2);
boob.AddToken("size", 0);
}
}
public void FixBroken()
{
//Fix legs
if (!this.HasToken("legs") && !this.HasToken("snaketail") && !this.HasToken("slimeblob"))
{
if (this.HasToken("oldlegs"))
this.GetToken("oldlegs").Name = "legs";
else
//TODO: Make this determine the proper sort of legs for the character to have and add them.
/* KAWA SEZ: how 'bout a small lookup mapping faces to legs? If the current face is
* not in the list, do the same with skintypes. If that fails, use human legs.
*/
//throw new NotImplementedException();
// for now, you get bestial legs, mutant! :-) -sparks
this.AddToken("legs").AddToken("genbeast");
}
else if ((this.HasToken("snaketail") || this.HasToken("slimeblob")) && this.HasToken("legs"))
{
this.GetToken("legs").Name = "oldlegs";
}
//Fix hips and waist
if (!this.HasToken("taur") && !this.HasToken("quadruped"))
{
if (!this.HasToken("hips"))
{
if (this.HasToken("oldhips"))
this.GetToken("oldhips").Name = "hips";
else
{
if (this.HasToken("waist"))
this.AddToken("hips", this.GetToken("waist").Value);
else
this.AddToken("hips", 4); //chosen by fair dice roll
}
}
if (!this.HasToken("waist"))
{
if (this.HasToken("oldwaist"))
this.GetToken("oldwaist").Name = "waist";
else
if (this.HasToken("hips"))
this.AddToken("waist", this.GetToken("hips").Value);
else
this.AddToken("waist", 4); //guaranteed to be random
}
}
else
{
//character does have "taur" or "quadruped" token
if (this.HasToken("hips"))
this.GetToken("hips").Name = "oldhips";
if (this.HasToken("waist"))
this.GetToken("waist").Name = "oldwaist";
}
//fix negative-sized or negative-valued tokens
List<Token> toRemove = new List<Token>();
foreach (Token toFix in this.Tokens)
{
if ((toFix.HasToken("count") && toFix.GetToken("count").Value <= 0) ||
(toFix.HasToken("amount") && toFix.GetToken("amount").Value <= 0) ||
(toFix.HasToken("size") && toFix.GetToken("size").Value < 0) ||
(toFix.HasToken("sizefromprevious")))
toRemove.Add(toFix);
}
foreach (var t in this.Tokens.Where(t => t.Name == "breastrow"))
{
t.Name = "breasts";
}
//Remove superfluous genitalia
if (this.Tokens.Count(t => t.Name == "penis") > 2)
{
this.GetToken("penis").AddToken("dual");
toRemove.AddRange(this.Tokens.Where(t => t.Name == "penis").Skip(1));
}
if (this.Tokens.Count(t => t.Name == "vagina") > 2)
{
this.GetToken("vagina").AddToken("dual");
toRemove.AddRange(this.Tokens.Where(t => t.Name == "vagina").Skip(1));
}
if (this.Tokens.Count(t => t.Name == "breasts") > 1)
{
toRemove.AddRange(this.Tokens.Where(t => t.Name == "breasts").Skip(1));
}
foreach (Token removeMe in toRemove)
{
this.Tokens.Remove(removeMe);
}
this.FixBoobs();
}
public static Character GetUnique(string id)
{
var uniques = Mix.GetTokenTree("uniques.tml", true);
var newChar = new Character();
var planSource = uniques.FirstOrDefault(t => t.Name == "character" && (t.Text == id));
if (planSource == null)
throw new FileNotFoundException(string.Format("Could not find a unique bodyplan with id \"{0}\" to generate.", id));
newChar.AddToken("originalID", id);
newChar.AddSet(planSource.Tokens);
newChar.AddToken("lootset_id", 0, id);
if (newChar.HasToken("_n"))
newChar.Name = new Name(newChar.GetToken("_n").Text);
else
newChar.Name = new Name(id.Replace('_', ' ').Titlecase());
newChar.RemoveToken("_n");
newChar.IsProperNamed = char.IsUpper(newChar.Name.ToString()[0]);
var gender = Gender.Neuter;
if (newChar.HasToken("penis") && !newChar.HasToken("vagina"))
gender = Gender.Male;
else if (!newChar.HasToken("penis") && newChar.HasToken("vagina"))
gender = Gender.Female;
else if (newChar.HasToken("penis") && newChar.HasToken("vagina"))
gender = Gender.Herm;
if (gender == Gender.Female)
newChar.Name.Female = true;
else if (gender == Gender.Herm || gender == Gender.Neuter)
newChar.Name.Female = Random.NextDouble() > 0.5;
newChar.ResolveMetaTokens();
newChar.EnsureDefaultTokens();
newChar.StripInvalidItems();
newChar.CheckHasteSlow();
newChar.UpdateTitle();
newChar.ApplyCostume();
foreach (var item in newChar.GetToken("items").Tokens)
item.AddToken("owner", 0, newChar.ID);
newChar.Culture = Culture.DefaultCulture;
if (newChar.HasToken("culture"))
{
var culture = newChar.GetToken("culture").Text;
if (Culture.Cultures.ContainsKey(culture))
newChar.Culture = Culture.Cultures[culture];
}
newChar.UpdatePowers();
Program.WriteLine("Retrieved unique character {0}.", newChar);
return newChar;
}
private void ResolveMetaTokens()
{
while (HasToken("_either"))
{
var either = GetToken("_either");
var eitherChoice = Random.Next(-1, either.Tokens.Count);
if (eitherChoice > -1)
AddToken(either.Tokens[eitherChoice]);
RemoveToken(either);
}
var removeThese = new List<Token>();
foreach (Token token in Tokens)
{
if (token.HasToken("_maybe"))
{
float value = token.GetToken("_maybe").Value;
if ((int)value == 0)
value = 0.5f;
if (Random.NextDouble() >= value)
removeThese.Add(token);
token.RemoveToken("_maybe");
}
}
foreach (Token token in removeThese)
RemoveToken(token);
while (HasToken("_copy"))
{
string path = GetToken("_copy").Text;
RemoveToken("_copy");
var source = Path(path);
if (source == null)
continue;
AddToken(source.Clone(true));
}
}
public static Character Generate(string bodyPlan, Gender bioGender, Gender idGender = Gender.RollDice, Realms world = Realms.Nox)
{
var newChar = new Character();
var planSource = Bodyplans.FirstOrDefault(t => t.Name == "bodyplan" && t.Text == bodyPlan);
if (planSource == null)
throw new ArgumentOutOfRangeException(string.Format("Could not find a bodyplan with id \"{0}\" to generate.", bodyPlan));
newChar.AddToken("originalID", bodyPlan);
newChar.AddSet(planSource.Tokens);
newChar.Name = new Name();
if (newChar.HasToken("editable"))
newChar.RemoveToken("editable");
newChar.HandleSelectTokens(); //by PillowShout
newChar.ResolveRolls(); // moved rolls to after select, that way we can do rolls within selects
if (newChar.HasToken("femaleonly"))
bioGender = Gender.Female;
else if (newChar.HasToken("maleonly"))
bioGender = Gender.Male;
else if (newChar.HasToken("hermonly"))
bioGender = Gender.Herm;
else if (newChar.HasToken("neuteronly"))
bioGender = Gender.Neuter;
if (bioGender == Gender.RollDice)
{
var min = 1;
var max = 4;
if (newChar.HasToken("normalgenders"))
max = 2;
else if (newChar.HasToken("neverneuter"))
max = 3;
var g = Random.Next(min, max + 1);
bioGender = (Gender)g;
}
if (idGender == Gender.RollDice)
idGender = bioGender;
if (bioGender != Gender.Female && newChar.HasToken("femaleonly"))
throw new Exception(string.Format("Cannot generate a non-female {0}.", bodyPlan));
if (bioGender != Gender.Male && newChar.HasToken("maleonly"))
throw new Exception(string.Format("Cannot generate a non-male {0}.", bodyPlan));
if (bioGender == Gender.Male || bioGender == Gender.Neuter)
{
newChar.RemoveToken("womb");
while (newChar.HasToken("vagina"))
newChar.RemoveToken("vagina");
foreach (var boob in newChar.Tokens.Where(t => t.Name == "breasts" && t.HasToken("size")))
boob.GetToken("size").Value = 0;
}
if (bioGender == Gender.Female || bioGender == Gender.Neuter)
{
while (newChar.HasToken("penis"))
newChar.RemoveToken("penis");
newChar.RemoveToken("balls");
}
if (newChar.HasToken("snaketail") && newChar.HasToken("legs"))
newChar.RemoveToken("legs");
if (!newChar.HasToken("beast"))
{
if (newChar.HasToken("namegen"))
{
var namegen = newChar.GetToken("namegen").Text;
if (Culture.NameGens.ContainsKey(namegen))
newChar.Name.NameGen = namegen;
}
if (idGender == Gender.Female)
newChar.Name.Female = true;
newChar.Name.Regenerate();
var patFather = new Name() { NameGen = newChar.Name.NameGen, Female = false };
var patMother = new Name() { NameGen = newChar.Name.NameGen, Female = true };
patFather.Regenerate();
patMother.Regenerate();
newChar.Name.ResolvePatronym(patFather, patMother);
newChar.IsProperNamed = true;
}
newChar.AddToken("preferredgender", 0, idGender.ToString());
newChar.EnsureDefaultTokens();
newChar.UpdateTitle();
newChar.ApplyCostume();
foreach (var item in newChar.GetToken("items").Tokens)
item.AddToken("owner", 0, newChar.ID);
newChar.Culture = Culture.DefaultCulture;
if (newChar.HasToken("culture"))
{
var culture = newChar.GetToken("culture").Text;
if (Culture.Cultures.ContainsKey(culture))
newChar.Culture = Culture.Cultures[culture];
}
if (newChar.HasToken("beast") && !newChar.HasToken("neverprefix")) // && Random.Flip())
{
var prefixes = new[] { "vorpal", "venomous", "infectious", "dire", "underfed", "burning" };
var chosen = prefixes.PickOne();
if (chosen == "burning" && Random.Flip())
chosen = string.Empty;
if (!newChar.HasToken("infectswith"))
while (chosen == "infectious")
chosen = prefixes.PickOne();
if (chosen != string.Empty)
{
var p = newChar.Path("prefixes") ?? newChar.AddToken("prefixes");
p.AddToken(chosen);
}
newChar.UpdateTitle();
}
if (newChar.HasToken("femalesmaller"))
{
if (bioGender == Gender.Female)
newChar.GetToken("tallness").Value -= Random.Next(5, 10);
else if (bioGender == Gender.Herm)
newChar.GetToken("tallness").Value -= Random.Next(1, 6);
}
//Prevent a semi-common generation bug from triggering in LookAt.
if (newChar.Path("skin/pattern") != null && newChar.Path("skin/pattern").Text.IsBlank())
newChar.GetToken("skin").RemoveToken("pattern");
newChar.ResolveMetaTokens();
newChar.StripInvalidItems();
newChar.CheckHasteSlow();
newChar.UpdatePowers();
/* Disabled for now pending Mutate rewrite.
// because: "why the hell did I pick a male human and get herm centaur?"
if (!newChar.HasToken("beast") && !newChar.HasToken("player") && world == Realms.Seradevari)
newChar.Mutate(2, 20);
*/
return newChar;
}
private void EnsureDefaultTokens()
{
var metaTokens = new[] { "playable", "femalesmaller", "costume", "neverneuter", "hermonly", "maleonly", "femaleonly" };
foreach (var t in metaTokens)
this.RemoveAll(t);
//if (!this.HasToken("beast"))
// this.RemoveAll("bestiary");
if (this.HasToken("ass"))
{
if (this.Path("ass/looseness") == null)
this.GetToken("ass").AddToken("looseness");
if (this.Path("ass/wetness") == null)
this.GetToken("ass").AddToken("wetness");
}
var prefabTokens = new[]
{
"items", /*"health",*/ "perks", "skills", "sexpreference",
"money", "ships",
//TODO: have the ___bonus tokens only appear when first set.
/* "charismabonus", "pleasurebonus", "mindbonus", "vicebonus",
"excitementbonus", "libidobonus", "speedbonus", "bodybonus", */
};
var prefabTokenValues = new[]
{
0, /*10,*/ 0, 0, (Random.Flip() ? 2 : Random.Next(0, 3)),
/*10, 0, 10, 0,
10, 10, 10, 15,*/
100, 0,
/* 0, 0, 0, 0,
0, 0, 0, 0, */
};
for (var i = 0; i < prefabTokens.Length; i++)
if (!HasToken(prefabTokens[i]))
AddToken(prefabTokens[i], prefabTokenValues[i]);
var stats = Lua.Environment.stats;
foreach (var stat in stats)
{
var s = (Neo.IronLua.LuaTable)stat.Value;
var n = s["name"].ToString().ToLowerInvariant();
float d = (s["default"] is int) ? (float)((int)s["default"]) : (float)s["default"];
if (!HasToken(n))
AddToken(n, d);
}
//names.Add(((Neo.IronLua.LuaTable)stat.Value)["name"].ToString().ToLowerInvariant());
if (!HasToken("posture")) AddToken("posture", 0);
Health = MaximumHealth;
}
public void SaveToFile(BinaryWriter stream)
{
Toolkit.SaveExpectation(stream, "CHAR");
Name.SaveToFile(stream);
stream.Write(IsProperNamed);
stream.Write(A ?? "a");
stream.Write(Culture.ID);
Toolkit.SaveExpectation(stream, "TOKS");
stream.Write(Tokens.Count);
Tokens.ForEach(x => x.SaveToFile(stream));
ResetEquipmentCarries();
}
public static Character LoadFromFile(BinaryReader stream)
{
var newChar = new Character();
Toolkit.ExpectFromFile(stream, "CHAR", "character");
newChar.Name = Name.LoadFromFile(stream);
/* newChar.IsProperNamed = */
stream.ReadBoolean();
/* newChar.A = */
stream.ReadString();
/* var culture = */
stream.ReadString();
/* newChar.Culture = Culture.DefaultCulture;
if (Culture.Cultures.ContainsKey(culture))
newChar.Culture = Culture.Cultures[culture]; */
Toolkit.ExpectFromFile(stream, "TOKS", "character token tree");
var numTokens = stream.ReadInt32();
for (var i = 0; i < numTokens; i++)
newChar.Tokens.Add(Token.LoadFromFile(stream));
newChar.UpdateTitle();
newChar.UpdatePowers();
if (!newChar.HasToken("posture")) newChar.AddToken("posture", 0);
return newChar;
}
public void ApplyCostume()
{
if (HasToken("costume"))
RemoveToken("costume");
if (HasToken("beast"))
return;
if (!HasToken("lootset_id"))
AddToken("lootset_id", 0, ID.ToLowerInvariant());
var filters = new Dictionary<string, string>
{
{ "gender", PreferredGender.ToString().ToLowerInvariant() },
{ "board", Board.HackishBoardTypeThing },
{ "culture", this.HasToken("culture") ? this.GetToken("culture").Text : string.Empty },
{ "name", this.Name.ToString(true) },
{ "id", this.GetToken("lootset_id").Text },
{ "bodymatch", this.GetClosestBodyplanMatch() },
{ "biome", BiomeData.Biomes[DungeonGenerator.DungeonGeneratorBiome].Name.ToLowerInvariant() } //AcetheSuperVillain suggests a biome key.
};
var inventory = this.GetToken("items");
var clothing = new List<Token>();
clothing.AddRange(DungeonGenerator.GetRandomLoot("npc", "underwear", filters));
clothing.AddRange(DungeonGenerator.GetRandomLoot("npc", "clothing", filters));
clothing.AddRange(DungeonGenerator.GetRandomLoot("npc", "accessories", filters));
var check = new Func<Token, bool>(x =>
{
var ki = NoxicoGame.KnownItems.FirstOrDefault(i => i.ID == x.Name);
return ki != null;
});
if (HasToken("taur") || HasToken("quadruped"))
check = new Func<Token, bool>(x =>
{
var ki = NoxicoGame.KnownItems.FirstOrDefault(i => i.ID == x.Name);
if (ki == null)
return false;
if (ki.Path("equipable/underpants") != null)
return ki.Path("equipable/undershirt") != null;
if (ki.Path("equipable/pants") != null)
return ki.Path("equipable/shirt") != null;
return true;
});
if (HasToken("snaketail"))
check = new Func<Token, bool>(x =>
{
var ki = NoxicoGame.KnownItems.FirstOrDefault(i => i.ID == x.Name);
if (ki == null)
return false;
if (ki.Path("equipable/socks") != null || ki.Path("equipable/shoes") != null)
return false;
if ((ki.Path("equipable/pants") != null || ki.Path("equipable/underpants") != null) && !ki.HasToken("nolegs"))
return false;
return true;
});
foreach (var item in clothing)
{
if (check(item))
inventory.AddToken(item).AddToken("equipped");
}
var armedOne = false;
foreach (var item in DungeonGenerator.GetRandomLoot("npc", "arms", filters))
{
var arm = inventory.AddToken(item);
if (!armedOne)
{
armedOne = true;
arm.AddToken("equipped");
}
}
foreach (var item in DungeonGenerator.GetRandomLoot("npc", "food", filters))
inventory.AddToken(item);
this.RemoveToken("lootset_id");
}
public void StripInvalidItems()
{
if (!HasToken("items"))
return;
var toDelete = new List<Token>();
foreach (var carriedItem in GetToken("items").Tokens)
{
var find = NoxicoGame.KnownItems.Find(x => x.ID == carriedItem.Name);
if (find == null)
toDelete.Add(carriedItem);
}
if (toDelete.Count > 0)
{
Program.WriteLine("Had to remove {0} inventory item(s) from {1}: {2}", toDelete.Count, Name, toDelete.Join());
GetToken("items").RemoveSet(toDelete);
}
}
public void AddSet(List<Token> otherSet)
{
foreach (var toAdd in otherSet)
{
var newToken = new Token(toAdd.Name, toAdd.Value, toAdd.Text);
if (toAdd.Tokens.Count > 0)
newToken.AddSet(toAdd.Tokens);
this.Tokens.Add(newToken);
}
}
public void IncreaseSkill(string skill)
{
var skills = GetToken("skills");
if (!skills.HasToken(skill))
skills.AddToken(skill);
var s = skills.GetToken(skill);
var l = (int)s.Value;
var i = 0.0349f / (1 + (l / 2f));
s.Value += i;
}
public float CumAmount
{
get
{
var ret = 0.0f;
var size = HasToken("balls") && GetToken("balls").HasToken("size") ? GetToken("balls").GetToken("size").Value + 1 : 1.25f;
var amount = HasToken("balls") && GetToken("balls").HasToken("amount") ? GetToken("balls").GetToken("amount").Value : 2f;
var multiplier = HasToken("cummultiplier") ? GetToken("cummultiplier").Value : 1;
var hours = 1;
var excitement = GetStat("excitement");
ret = (size * amount * multiplier * 2 * (excitement + 50) / 10 * (hours + 10) / 24) / 10;
if (GetToken("perks").HasToken("messyorgasms"))
ret *= 1.5f;
return ret;
}
}
public float MilkAmount
{
get
{
var size = GetBreastSize();
var amount = GetBreastAmount();
if ((int)amount == 0)
return 0;
var effectiveAmount = size * amount;
if (this.GetToken("breasts").HasToken("lactation"))
effectiveAmount *= 5;
if (GetToken("perks").HasToken("messyorgasms"))
effectiveAmount *= 1.5f;
return effectiveAmount;
}
}
private static void Columnize(Action<string> print, List<string> col1, List<string> col2, string header1, string header2)
{
var pad = 36;
var totalRows = Math.Max(col1.Count, col2.Count);
print(i18n.GetString(header1).PadEffective(pad) + i18n.GetString(header2) + "\n");
for (var i = 0; i < totalRows; i++)
{
if (i < col1.Count)
print(((i < col1.Count - 1 ? "\xC3 " : "\xC0 ") + (i18n.GetString(col1[i], false)).Lowercase()).PadEffective(pad));
else
print(string.Empty.PadEffective(pad));
if (i < col2.Count)
print((i < col2.Count - 1 ? "\xC3 " : "\xC0 ") + (i18n.GetString(col2[i], false).Lowercase()));
print("\n");
}
print("\n");
}
#region LookAt submethods
private void LookAtEquipment1(Entity pa, Action<string> print, ref List<InventoryItem> carried, ref List<string> worn, ref List<InventoryItem> hands, ref List<InventoryItem> fingers, ref bool breastsVisible, ref bool crotchVisible)
{
InventoryItem underpants = null;
InventoryItem undershirt = null;
InventoryItem shirt = null;
InventoryItem pants = null;
InventoryItem socks = null;
InventoryItem jacket = null;
InventoryItem cloak = null;
InventoryItem shoes = null;
InventoryItem hat = null;
InventoryItem goggles = null;
InventoryItem mask = null;
InventoryItem neck = null;
var carriedItems = this.GetToken("items");
for (var i = 0; i < carriedItems.Tokens.Count; i++)
{
var carriedItem = carriedItems.Item(i);
var foundItem = NoxicoGame.KnownItems.Find(y => y.ID == carriedItem.Name);