-
Notifications
You must be signed in to change notification settings - Fork 6
/
BoardChar.cs
1648 lines (1526 loc) · 52.3 KB
/
BoardChar.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;
#if DEBUG
using Keys = System.Windows.Forms.Keys;
#endif
namespace Noxico
{
public class BoardChar : Entity
{
private static int blinkRate = 1000;
public string Sector { get; set; }
public string Pairing { get; set; }
public Dijkstra DijkstraMap { get; private set; }
public Character Character { get; set; }
public string OnTick { get; set; }
public string OnLoad { get; set; }
public string OnPlayerBump { get; set; }
public string OnHurt { get; set; }
public string OnPathFinish { get; set; }
public bool ScriptPathing { get; set; }
public Dijkstra ScriptPathTarget { get; private set; }
public int ScriptPathTargetX { get; private set; }
public int ScriptPathTargetY { get; private set; }
public string ScriptPathID { get; set; }
public Dijkstra GuardMap { get; private set; }
public int Eyes { get; private set; }
public int SightRadius { get; private set; }
public char GlowGlyph { get; private set; }
public Posture Posture { get { return (Posture)Character.GetToken("posture").Value; } set { Character.GetToken("posture").Value = (float)value; } }
public BoardChar()
{
this.Glyph = (char)255;
this.ForegroundColor = Color.White;
this.BackgroundColor = Color.Gray;
this.Blocking = true;
if (this.ParentBoard == null)
return;
this.DijkstraMap = new Dijkstra(this.ParentBoard);
this.DijkstraMap.Hotspots.Add(new Point(this.XPosition, this.YPosition));
}
public BoardChar(Character character) : this()
{
ID = character.Name.ToID();
Character = character;
Character.BoardChar = this;
this.Blocking = true;
RestockVendor();
}
public override string ToString()
{
if (Character == null)
return "[Characterless BoardChar]";
return Character.Name.ToString(true);
}
public virtual void AdjustView()
{
var skinColor = Character.Path("skin/color").Text;
ForegroundColor = Color.FromName(skinColor);
BackgroundColor = Toolkit.Darken(ForegroundColor);
if (skinColor.Equals("black", StringComparison.OrdinalIgnoreCase))
ForegroundColor = Color.FromArgb(34, 34, 34);
Token forcedGlyph = Character.Path("glyph") ?? (Character.HasToken("beast") ? Character.Path("bestiary") : null) ?? null;
if (forcedGlyph != null)
{
if (forcedGlyph.HasToken("char"))
Glyph = (int)forcedGlyph.GetToken("char").Value;
if (forcedGlyph.HasToken("fore"))
ForegroundColor = Color.FromName(forcedGlyph.GetToken("fore").Text);
if (forcedGlyph.HasToken("back"))
BackgroundColor = Color.FromName(forcedGlyph.GetToken("back").Text);
}
else
{
var judgment = '\x160';
if (Character.HasToken("tallness") && Character.GetToken("tallness").Value < 140)
judgment = '\x165';
if (Character.HasToken("wings") && !Character.GetToken("wings").HasToken("small"))
judgment = (judgment == '\x165') ? '\x16A' : '\x166';
else if (Character.HasToken("tail"))
judgment = (judgment == '\x166') ? '\x168' : '\x167';
if (Character.HasToken("snaketail"))
judgment = (judgment == '\x166') ? '\x169' : '\x161';
else if (Character.HasToken("slimeblob"))
judgment = '\x164';
else if (Character.HasToken("quadruped"))
judgment = '\x163';
else if (Character.HasToken("taur"))
judgment = '\x162';
else if (Character.GetToken("legs").Text == "bear" && Character.GetToken("ears").Text == "bear")
judgment = '\x171';
Glyph = judgment;
}
Eyes = 0;
SightRadius = 1;
GlowGlyph = ' ';
if (Character.HasToken("eyes"))
{
Eyes = 2;
SightRadius = 10;
GlowGlyph = '\"';
var eyeToken = Character.GetToken("eyes").GetToken("count");
if (eyeToken != null)
Eyes = (int)eyeToken.Value;
if (Eyes == 1)
{
SightRadius = 4;
GlowGlyph = '\'';
}
else if (Eyes > 2)
{
SightRadius = 4 + (int)(Math.Log(Eyes + 3) * 4);
GlowGlyph = '\xF8';
}
if (Character.Path("eyes/glow") != null)
SightRadius *= 2;
}
}
public override object CanMove(Direction targetDirection, SolidityCheck check)
{
var canMove = base.CanMove(targetDirection, check);
if (canMove != null && canMove is bool && !(bool)canMove)
return canMove;
if (!Character.HasToken("hostile") && !ScriptPathing && (Character.HasToken("sectorlock") || Character.HasToken("sectoravoid")))
{
if (!ParentBoard.Sectors.ContainsKey(Sector))
return canMove;
var sect = ParentBoard.Sectors[Sector];
var newX = this.XPosition;
var newY = this.YPosition;
Toolkit.PredictLocation(newX, newY, targetDirection, ref newX, ref newY);
var inRect = (newX >= sect.Left && newX <= sect.Right && newY >= sect.Top && newY <= sect.Bottom);
if (Character.HasToken("sectorlock") && !inRect)
return false;
if (Character.HasToken("sectoravoid") && inRect)
return false;
}
return canMove;
}
public override object CanMove(Direction targetDirection)
{
return CanMove(targetDirection, SolidityCheck.Walker);
}
public override void Move(Direction targetDirection, SolidityCheck check)
{
if (Posture != Posture.Upright)
{
Energy -= Posture == Posture.Seated ? 1200 : 2000;
Posture = Posture.Upright;
return;
}
if (this.DijkstraMap == null)
{
this.DijkstraMap = new Dijkstra(this.ParentBoard);
this.DijkstraMap.Hotspots.Add(new Point(this.XPosition, this.YPosition));
}
if (Character.HasToken("slimeblob"))
ParentBoard.TrailSlime(YPosition, XPosition, ForegroundColor);
if (ParentBoard.IsWater(YPosition, XPosition))
{
if (Character.HasToken("aquatic"))
{
Energy -= 1250;
if (!Character.HasToken("swimming"))
Character.AddToken("swimming", -1);
}
else
{
var swimming = Character.GetToken("swimming");
if (swimming == null)
swimming = Character.AddToken("swimming", 20);
swimming.Value -= 1;
if (swimming.IntValue == 0)
Hurt(9999, "death_drowned", null);
Energy -= 1750;
}
}
else
{
Character.RemoveToken("swimming");
Energy -= 1000;
}
base.Move(targetDirection, check);
}
public override void Move(Direction targetDirection)
{
Move(targetDirection, SolidityCheck.Walker);
}
public override void Draw()
{
var localX = this.XPosition - NoxicoGame.CameraX;
var localY = this.YPosition - NoxicoGame.CameraY;
if (localX >= Program.Cols || localY >= Program.Rows || localX < 0 || localY < 0)
return;
var b = ((MainForm)NoxicoGame.HostForm).IsMultiColor ? TileDefinition.Find(this.ParentBoard.Tilemap[this.XPosition, this.YPosition].Index, true).Background : this.BackgroundColor;
if (ParentBoard.IsLit(this.YPosition, this.XPosition))
{
var c = this.Glyph;
if (NoxicoGame.HostForm.Is437)
{
if (this is Player)
c = '@';
else
{
var title = this.Character.Title;
if (this.Character.IsShort)
c = title.ToLowerInvariant()[0];
else
c = title.ToUpperInvariant()[0];
}
}
if (Environment.TickCount % blinkRate * 2 < blinkRate)
{
if (Character.HasToken("sleeping"))
c = 'Z';
else if (Character.HasToken("flying"))
c = '^';
else if (Character.Path("role/vendor") != null)
c = '$';
}
NoxicoGame.HostForm.SetCell(localY, localX, c, this.ForegroundColor, b);
}
else if (Eyes > 0 && Character.Path("eyes/glow") != null && !Character.HasToken("sleeping"))
NoxicoGame.HostForm.SetCell(localY, localX, GlowGlyph, Color.FromName(Character.Path("eyes").Text), ParentBoard.Tilemap[XPosition, YPosition].Definition.Background.Night());
}
/*
public override bool CanSee(Entity other)
{
if (Character.Path("eyes/glow") == null)
return base.CanSee(other);
//But if we do have glowing eyes, ignore illumination.
foreach (var point in Toolkit.Line(XPosition, YPosition, other.XPosition, other.YPosition))
if (ParentBoard.IsSolid(point.Y, point.X))
return false;
return true;
}
*/
/*
public string Ogle(Character otherChar)
{
if (this.Character.HasToken("sleeping"))
return null;
var stim = this.Character.GetStat("excitement");
var carn = this.Character.GetStat("vice");
var r = Random.Next(4);
if (r == 0)
{
if (otherChar.BiggestBreastrowNumber == -1 || otherChar.GetBreastRowSize(otherChar.BiggestBreastrowNumber) < 3.5)
r = Random.Next(1, 4);
else
{
var breastSize = otherChar.GetBreastRowSize(otherChar.BiggestBreastrowNumber);
if (breastSize < 5)
return "Nice " + Descriptions.BreastRandom(true) + ".";
else if (breastSize < 10)
return "Look at those " + Descriptions.BreastRandom(true) + "...";
else
return "Woah, momma.";
}
}
{
var cha = otherChar.GetStat("charisma");
if (cha > 0)
{
if (cha < 30)
return "Well hello, " + (otherChar.PercievedGender == Gender.Male ? "handsome." : "beautiful.");
else if (cha < 60)
return "Oh my.";
else
return "Woah.";
}
}
return "There are no words.";
}
*/
public void CheckForCriminalScum()
{
if (Character.HasToken("hostile") || Character.HasToken("sleeping"))
return;
var player = NoxicoGame.Me.Player;
if (CanSee(player) && DistanceFrom(player) < 10)
{
var myID = this.Character.ID;
var items = player.Character.GetToken("items").Tokens;
foreach (var item in items)
{
var owner = item.Path("owner");
if (owner != null && owner.Text == myID)
{
if (!this.ParentBoard.HasToken("combat"))
this.ParentBoard.AddToken("combat");
SceneSystem.Engage(player.Character, this.Character, "(criminalscum)");
}
}
}
}
public void CheckForTimedItems()
{
foreach (var carriedItem in this.Character.GetToken("items").Tokens)
{
var timer = carriedItem.Path("timer");
if (timer == null)
continue;
if (timer.Text.IsBlank())
timer.Text = NoxicoGame.InGameTime.ToBinary().ToString(); //continue;
var knownItem = NoxicoGame.KnownItems.Find(x => x.ID == carriedItem.Name);
if (knownItem == null)
continue;
if (knownItem.Path("timer/evenunequipped") == null && !carriedItem.HasToken("equipped"))
continue;
var time = new DateTime(long.Parse(timer.Text));
if (NoxicoGame.InGameTime.Minute == time.Minute)
continue;
if (timer.Value > 0)
{
timer.Value--;
timer.Text = NoxicoGame.InGameTime.ToBinary().ToString();
}
if (timer.Value <= 0)
{
timer.Value = (knownItem.GetToken("timer").IntValue == 0) ? 60 : knownItem.GetToken("timer").Value;
if (knownItem.OnTimer.IsBlank())
{
Program.WriteLine("Warning: {0} has a timer, but no OnTimer script! Timer token removed.", carriedItem.Name);
carriedItem.RemoveToken("timer");
continue;
}
knownItem.RunScript(carriedItem, knownItem.OnTimer, this.Character, this, (m => NoxicoGame.AddMessage(m)));
}
}
}
public void CheckForCopiers()
{
if (Character.HasToken("copier"))
{
var copier = Character.GetToken("copier");
var timeout = copier.GetToken("timeout");
if (timeout != null && timeout.Value > 0)
{
if (!timeout.HasToken("minute"))
timeout.AddToken("minute", NoxicoGame.InGameTime.Minute);
if (timeout.GetToken("minute").IntValue == NoxicoGame.InGameTime.Minute)
return;
timeout.GetToken("minute").Value = NoxicoGame.InGameTime.Minute;
timeout.Value--;
if (timeout.IntValue == 0)
{
copier.RemoveToken(timeout);
if (Character.HasToken("fullCopy") && copier.HasToken("backup"))
{
Character.Copy(null); //force revert
AdjustView();
NoxicoGame.AddMessage(i18n.GetString("x_reverts").Viewpoint(Character));
}
}
}
}
}
public override void Update()
{
if (Character.Health <= 0)
return;
var increase = 200 + (int)Character.GetStat("speed");
if (Character.HasToken("haste"))
increase *= 2;
else if (Character.HasToken("slow"))
increase /= 2;
Energy += increase;
if (Energy < 5000)
return;
else
Energy = 5000;
if (Character.HasToken("helpless"))
{
if (Random.NextDouble() < 0.05)
{
Character.Health += 2;
NoxicoGame.AddMessage(i18n.GetString("x_getsbackup").Viewpoint(Character));
Character.RemoveToken("helpless");
//TODO: Remove hostility? Replace with fear?
//If the team system is used, perhaps switch to a Routed Hostile team.
}
else
return;
}
if (Character.HasToken("waitforplayer") && !(this is Player))
{
if (!NoxicoGame.Me.Player.Character.HasToken("helpless"))
{
Character.RemoveToken("waitforplayer");
Character.AddToken("cooldown", 5);
}
return;
}
if (Character.HasToken("cooldown"))
{
Character.GetToken("cooldown").Value--;
if (Character.GetToken("cooldown").IntValue == 0)
Character.RemoveToken("cooldown");
else
return;
}
Character.TickStats();
if (Character.Path("prefixes/burning") != null)
{
if (!Character.HasToken("fireproof"))
Character.AddToken("fireproof");
if (Random.NextDouble() > 0.80)
this.ParentBoard.Immolate(this.YPosition, this.XPosition);
}
if (!RunScript(OnTick))
return;
CheckForTimedItems();
CheckForCriminalScum();
CheckForCopiers();
if (Character.UpdateSex())
return;
base.Update();
var r = Lua.Environment.EachBoardCharTurn(this, this.Character);
if (!Character.HasToken("fireproof") && ParentBoard.IsBurning(YPosition, XPosition))
if (Hurt(10, "death_burned", null))
return;
if (this.Character.HasToken("sleeping") || Character.HasToken("anchored"))
return;
if (this.Character.HasToken("teambehavior"))
{
NewMove();
return;
}
ActuallyMove();
}
private void NewMove()
{
//var solidity = SolidityCheck.Walker;
//if (Character.IsSlime)
var solidity = SolidityCheck.DryWalker;
if (Character.HasToken("flying"))
solidity = SolidityCheck.Flyer;
if (ScriptPathing)
{
var dir = Direction.North;
ScriptPathTarget.Ignore = DijkstraIgnore.Type;
ScriptPathTarget.IgnoreType = typeof(BoardChar);
if (ScriptPathTarget.RollDown(this.YPosition, this.XPosition, ref dir))
Move(dir, solidity);
if (this.XPosition == ScriptPathTargetX && this.YPosition == ScriptPathTargetY)
{
ScriptPathing = false;
RunScript(OnPathFinish);
}
return;
}
var target = (BoardChar)null;
var preferredTarget = (BoardChar)null;
var action = TeamBehaviorAction.Nothing;
if (Character.HasToken("huntingtarget"))
{
preferredTarget = ParentBoard.Entities.OfType<BoardChar>().FirstOrDefault(x => x.ID == Character.GetToken("huntingtarget").Text);
if (preferredTarget != null && (int)Character.GetToken("huntingtarget").Value > 0)
action = (TeamBehaviorAction)((int)Character.GetToken("huntingtarget").Value);
}
if (preferredTarget == null)
{
foreach (var other in this.ParentBoard.Entities.OfType<BoardChar>())
{
if (other == this)
continue;
if (!CanSee(other) || DistanceFrom(other) > 20)
continue;
var newAction = this.Character.DecideTeamBehavior(other.Character, TeamBehaviorClass.Attacking);
switch (newAction)
{
case TeamBehaviorAction.Nothing:
break;
case TeamBehaviorAction.Attack:
if (preferredTarget == null)
{
target = other;
action = TeamBehaviorAction.Attack;
}
break;
case TeamBehaviorAction.PreferentialAttack:
preferredTarget = target = other;
action = TeamBehaviorAction.Attack;
break;
}
if (action == TeamBehaviorAction.Attack && preferredTarget == null)
continue;
if (action != TeamBehaviorAction.Nothing)
break;
action = this.Character.DecideTeamBehavior(other.Character, TeamBehaviorClass.Flocking);
switch (action)
{
case TeamBehaviorAction.Nothing:
continue;
case TeamBehaviorAction.Avoid:
target = other;
break;
case TeamBehaviorAction.Flock:
//No need to check for FlockAlike -- is collapsed into Attack by DecideTeamBehavior
//case TeamBehaviorAction.FlockAlike:
target = other;
break;
}
if (action != TeamBehaviorAction.Nothing)
break;
}
}
if (target == null && preferredTarget != null)
target = preferredTarget;
if (target == null)
if (Random.Flip())
this.Move((Direction)Random.Next(4), solidity);
//Update our token
if (target == null && preferredTarget == null)
{
Character.RemoveToken("huntingtarget");
return;
}
if (!Character.HasToken("huntingtarget"))
Character.AddToken("huntingtarget", (int)action, target.ID);
else
{
Character.GetToken("huntingtarget").Text = target.ID;
Character.GetToken("huntingtarget").Value = (int)action;
}
//Program.WriteLine("{0}, team {1}, action {2}, target {3}", this.ID, this.Character.Team, action, target != null ? target.ID : "<null>");
var distance = DistanceFrom(target);
if (target is BoardChar && action == TeamBehaviorAction.Attack)
{
var weapon = this.Character.GetEquippedItemBySlot("hand");
if (weapon != null && !weapon.HasToken("weapon"))
weapon = null;
var range = (weapon == null || weapon.Path("weapon/range") == null) ? 1 : (int)weapon.Path("weapon/range").Value;
//Determine best weapon for the job.
if ((distance <= 2 && range > 2) || weapon == null)
{
//Close by, could be better to use short-range weapon, or unarmed.
foreach (var carriedItem in this.Character.GetToken("items").Tokens)
{
if (carriedItem.HasToken("equipped"))
continue;
var find = NoxicoGame.KnownItems.Find(x => x.ID == carriedItem.Name);
if (find == null)
continue;
if (find.HasToken("equipable") && find.HasToken("weapon"))
{
var r = find.Path("weapon/range");
if (r == null || r.IntValue == 1)
{
try
{
if (find.Equip(this.Character, carriedItem))
{
//Program.WriteLine("{0} switches to {1} (SR)", this.Character.Name, find);
Energy -= 1000;
return; //end turn
}
}
catch (ItemException)
{ }
}
}
}
}
if ((distance > 2 && range == 1) || weapon == /* still */ null)
{
//Far away, could be better to use long-range weapon, or unarmed
foreach (var carriedItem in this.Character.GetToken("items").Tokens)
{
if (carriedItem.HasToken("equipped"))
continue;
var find = NoxicoGame.KnownItems.Find(x => x.ID == carriedItem.Name);
if (find == null)
continue;
if (find.HasToken("equipable") && find.HasToken("weapon"))
{
var r = find.Path("weapon/range");
if (r != null && r.Value > 3)
{
try
{
if (find.Equip(this.Character, carriedItem))
{
//Program.WriteLine("{0} switches to {1} (LR)", this.Character.Name, find);
Energy -= 1000;
return; //end turn
}
}
catch (ItemException)
{ }
}
}
}
}
var bcTarget = target as BoardChar;
if (distance <= range && CanSee(bcTarget))
{
//Within attacking range.
if (IniFile.GetValue("misc", "allowrape", false) && distance == 1 && bcTarget.Character.HasToken("helpless") && Character.GetStat("excitement") > 30 && Character.Likes(bcTarget.Character))
{
//WRONG KIND OF ATTACK! ABANDON SHIP!!
Character.AddToken("waitforplayer");
SexManager.Engage(this.Character, bcTarget.Character);
return;
}
if (range == 1 && (target.XPosition == this.XPosition || target.YPosition == this.YPosition))
{
//Melee attacks can only be orthogonal.
MeleeAttack(bcTarget);
if (Character.Path("prefixes/infectious") != null && Random.NextDouble() > 0.25)
bcTarget.Character.Morph(Character.GetToken("infectswith").Text);
return;
}
else if (weapon != null)
{
AimShot(target);
}
}
}
if (!CanSee(target) && Character.HasToken("targetlastpos"))
{
if (ScriptPathTarget == null)
{
var lastPos = Character.GetToken("targetlastpos");
ScriptPathTarget = new Dijkstra(this.ParentBoard, !Character.IsSlime);
ScriptPathTarget.Hotspots.Add(new Point((int)lastPos.GetToken("x").Value, (int)lastPos.GetToken("y").Value));
ScriptPathTarget.Update();
}
//Program.WriteLine("{0} can't see, looks for {1}", this.ID, ScriptPathTarget.Hotspots[0].ToString());
var map = ScriptPathTarget;
var dir = Direction.North;
map.Ignore = DijkstraIgnore.Type;
map.IgnoreType = typeof(BoardChar);
if (map.RollDown(this.YPosition, this.XPosition, ref dir))
{
switch (action)
{
case TeamBehaviorAction.Attack:
this.Move(dir);
break;
case TeamBehaviorAction.Flock:
if (DistanceFrom(target) > 10)
this.Move(dir);
else
this.Move((Direction)Random.Next(4), solidity);
break;
case TeamBehaviorAction.Avoid:
dir = (Direction)(((int)dir + 2) % 4);
this.Move(dir);
break;
}
}
else
{
//Program.WriteLine("{0} couldn't find target at LKP {1}, wandering...", this.ID, ScriptPathTarget.Hotspots[0].ToString());
this.Move((Direction)Random.Next(4), solidity);
}
if (CanSee(target))
{
var lastPos = Character.Path("targetlastpos");
lastPos.GetToken("x").Value = target.XPosition;
lastPos.GetToken("y").Value = target.YPosition;
}
}
else if (distance <= 20 && CanSee(target))
{
var lastPos = Character.Path("targetlastpos");
if (lastPos == null)
{
lastPos = Character.AddToken("targetlastpos");
lastPos.AddToken("x");
lastPos.AddToken("y");
}
lastPos.GetToken("x").Value = target.XPosition;
lastPos.GetToken("y").Value = target.YPosition;
if (ScriptPathTarget == null)
{
ScriptPathTarget = new Dijkstra(this.ParentBoard, !Character.IsSlime);
}
ScriptPathTarget.Hotspots.Clear();
ScriptPathTarget.Hotspots.Add(new Point(target.XPosition, target.YPosition));
ScriptPathTarget.Update();
//Program.WriteLine("{0} updates LKP to {1} (can see)", this.ID, ScriptPathTarget.Hotspots[0].ToString());
//Try to move closer. I WANT TO HIT THEM WITH MY SWORD!
var map = ScriptPathTarget; //target.DijkstraMap;
var dir = Direction.North;
map.Ignore = DijkstraIgnore.Type;
map.IgnoreType = typeof(BoardChar);
if (map.RollDown(this.YPosition, this.XPosition, ref dir))
{
switch (action)
{
case TeamBehaviorAction.Attack:
this.Move(dir);
break;
case TeamBehaviorAction.Flock:
if (DistanceFrom(target) > 10)
this.Move(dir);
else
this.Move((Direction)Random.Next(4), solidity);
break;
case TeamBehaviorAction.Avoid:
dir = (Direction)(((int)dir + 2) % 4);
this.Move(dir);
break;
}
}
}
}
private void ActuallyMove()
{
//var solidity = SolidityCheck.Walker;
//if (Character.IsSlime)
var solidity = SolidityCheck.DryWalker;
if (Character.HasToken("flying"))
solidity = SolidityCheck.Flyer;
if (ScriptPathing)
{
var dir = Direction.North;
ScriptPathTarget.Ignore = DijkstraIgnore.Type;
ScriptPathTarget.IgnoreType = typeof(BoardChar);
if (ScriptPathTarget.RollDown(this.YPosition, this.XPosition, ref dir))
Move(dir, solidity);
if (this.XPosition == ScriptPathTargetX && this.YPosition == ScriptPathTargetY)
{
ScriptPathing = false;
RunScript(OnPathFinish);
}
return;
}
var ally = Character.HasToken("ally");
var hostile = ally ? Character.GetToken("ally") : Character.GetToken("hostile");
var player = NoxicoGame.Me.Player;
if (ParentBoard == player.ParentBoard && hostile != null)
{
var target = (BoardChar)player;
if (ally)
target = ParentBoard.Entities.OfType<BoardChar>().FirstOrDefault(x => !(x is Player) && x != this && x.Character.HasToken("hostile"));
if (hostile.IntValue == 0) //Not actively hunting, but on the lookout.
{
if (target != null && DistanceFrom(target) <= SightRadius && CanSee(target))
{
NoxicoGame.Sound.PlaySound("set://Alert");
hostile.Value = 1; //Switch to active hunting.
Energy -= 500;
if (!ally)
{
if (Character.HasToken("copier"))
{
var copier = Character.GetToken("copier");
if (copier.IntValue == 0 && !copier.HasToken("timeout"))
{
Character.Copy(target.Character);
AdjustView();
NoxicoGame.AddMessage(i18n.Format(Character.HasToken("fullCopy") ? "x_becomes_y" : "x_imitates_y").Viewpoint(Character, target.Character));
Energy -= 2000;
return;
}
}
//If we're gonna rape the target, we'd want them for ourself. Otherwise...
if (Character.GetStat("excitement") < 30)
{
//...we call out to nearby hostiles
var called = 0;
foreach (var other in ParentBoard.Entities.OfType<BoardChar>().Where(x => !(x is Player) && x != this && DistanceFrom(x) < 10 && x.Character.HasToken("hostile")))
{
called++;
other.CallTo(player);
}
if (called > 0)
{
if (!Character.HasToken("beast"))
NoxicoGame.AddMessage(i18n.Format("call_out", Character.GetKnownName(true, true, true, true)).SmartQuote().Viewpoint(this.Character, target.Character), GetEffectiveColor());
else
NoxicoGame.AddMessage(i18n.Format("call_out_animal").Viewpoint(this.Character), GetEffectiveColor());
Program.WriteLine("{0} called {1} others to player's location.", this.Character.Name, called);
Energy -= 2000;
}
}
}
return;
}
}
else if (hostile.IntValue == 1)
{
Hunt();
return;
}
}
if (Character.HasToken("guardspot"))
{
var guardX = this.XPosition;
var guardY = this.YPosition;
if (Character.GetToken("guardspot").Tokens.Count > 0)
{
if (this.GuardMap == null)
{
GuardMap = new Dijkstra(ParentBoard, !Character.IsSlime);
GuardMap.Hotspots.Add(new Point(guardX, guardY));
GuardMap.Update();
GuardMap.Ignore = DijkstraIgnore.Type;
GuardMap.IgnoreType = typeof(BoardChar);
}
}
var dir = Direction.North;
if (this.XPosition != guardX && this.YPosition != guardY)
if (GuardMap.RollDown(this.YPosition, this.XPosition, ref dir))
Move(dir, solidity);
return;
}
if (Random.Flip())
this.Move((Direction)Random.Next(4), solidity);
}
private void Hunt()
{
if (Character.HasToken("helpless"))
return;
if (Character.HasToken("beast"))
Character.SetStat("excitement", 0);
var ally = Character.HasToken("ally");
var hostile = ally ? Character.GetToken("ally") : Character.GetToken("hostile");
if (hostile == null)
return;
Entity target = null;
//If no target is given, assume the player.
if (Character.HasToken("huntingtarget"))
target = ParentBoard.Entities.OfType<BoardChar>().First(x => x.ID == Character.GetToken("huntingtarget").Text);
else if (!ally && NoxicoGame.Me.Player.ParentBoard == this.ParentBoard)
target = NoxicoGame.Me.Player;
if (Character.HasToken("stolenfrom"))
{
var newTarget = ParentBoard.Entities.OfType<DroppedItem>().FirstOrDefault(x => x.Token.HasToken("owner") && x.Token.GetToken("owner").Text == Character.ID);
if (newTarget != null)
target = newTarget;
}
if (target == null)
{
//Intended target isn't on the board. Break off the hunt?
hostile.Value = 0;
return;
}
var distance = DistanceFrom(target);
if (target is BoardChar)
{
var weapon = this.Character.GetEquippedItemBySlot("hand");
if (weapon != null && !weapon.HasToken("weapon"))
weapon = null;
var range = (weapon == null || weapon.Path("weapon/range") == null) ? 1 : (int)weapon.Path("weapon/range").Value;
//Determine best weapon for the job.
if ((distance <= 2 && range > 2) || weapon == null)
{
//Close by, could be better to use short-range weapon, or unarmed.
foreach (var carriedItem in this.Character.GetToken("items").Tokens)
{
if (carriedItem.HasToken("equipped"))
continue;
var find = NoxicoGame.KnownItems.Find(x => x.ID == carriedItem.Name);
if (find == null)
continue;
if (find.HasToken("equipable") && find.HasToken("weapon"))
{
var r = find.Path("weapon/range");
if (r == null || r.IntValue == 1)
{
try
{
if (find.Equip(this.Character, carriedItem))
{
Program.WriteLine("{0} switches to {1} (SR)", this.Character.Name, find);
Energy -= 1000;
return; //end turn
}
}
catch (ItemException)
{ }
}
}
}
}
if ((distance > 2 && range == 1) || weapon == /* still */ null)
{
//Far away, could be better to use long-range weapon, or unarmed
foreach (var carriedItem in this.Character.GetToken("items").Tokens)
{
if (carriedItem.HasToken("equipped"))
continue;
var find = NoxicoGame.KnownItems.Find(x => x.ID == carriedItem.Name);
if (find == null)
continue;
if (find.HasToken("equipable") && find.HasToken("weapon"))
{
var r = find.Path("weapon/range");
if (r != null && r.Value > 3)
{
try
{
if (find.Equip(this.Character, carriedItem))
{
Program.WriteLine("{0} switches to {1} (LR)", this.Character.Name, find);
Energy -= 1000;
return; //end turn
}
}
catch (ItemException)
{ }
}
}
}
}
var bcTarget = target as BoardChar;
if (distance <= range && CanSee(bcTarget))
{
//Within attacking range.
if (IniFile.GetValue("misc", "allowrape", false) && distance == 1 && bcTarget.Character.HasToken("helpless") && Character.GetStat("excitement") > 30 && Character.Likes(bcTarget.Character))
{
//WRONG KIND OF ATTACK! ABANDON SHIP!!
Character.AddToken("waitforplayer");
SexManager.Engage(this.Character, bcTarget.Character);
return;
}
if (range == 1 && (target.XPosition == this.XPosition || target.YPosition == this.YPosition))
{