-
Notifications
You must be signed in to change notification settings - Fork 1
/
Adventurer_Update.cs
1914 lines (1689 loc) · 75.9 KB
/
Adventurer_Update.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; //General C# functions
using System.Collections.Generic; //So I can use List
using System.Drawing; //The colors, man
using System.IO; //Mainly used for reading and writing files
using System.Linq;
using System.Runtime.InteropServices; //For use in wrangling pointers in their place
using System.Threading;
using Tao.Sdl;
using KalaGame;
namespace Adventurer
{
public partial class Adventurer
{
#region Variables
public static Sdl.SDL_Event keyEvent; //To tell whether a key was pressed or lifted
public static Sdl.SDL_Event oldKeyEvent; //For telling if a key was just pressed
public static bool[] keys = new bool[255]; //An array to see which keys are down.
public static bool shift = false; //Whether the shift key is down
public static bool[] pressList = new bool[10];
#endregion
static void Update()
{
switch (gameState)
{
case GameState.OpeningMenu:
Update_OpeningMenu();
break;
case GameState.MainGame:
Update_MainGame();
break;
case GameState.EscapeMenu:
Update_EscapeMenu();
break;
case GameState.HealthMenu:
Update_HealthMenu();
break;
case GameState.HelpMenu:
Update_HelpMenu();
break;
case GameState.InventoryMenu:
Update_InventoryMenu();
break;
}
}
static void Update_OpeningMenu()
{
switch (Update_GetKey())
{
#region Directions
case "2": //If down was pressed
pressList[2] = true;
if (selectionCursor < 3) //If down was pressed...
selectionCursor++; //...move the cursor down one, if possible.
else
selectionCursor = 1; //Loop over if needed
break;
case "8": //If up was pressed
if (selectionCursor > 1)
selectionCursor--;
else
selectionCursor = 3;
break;
#endregion
#region Enter
case "Enter": //If enter aka "271" or "13" was pressed
if (selectionCursor == 1) //If "New Game"
{
worldSeed = (int)DateTime.Now.Ticks; //Set the world seed
gameState = GameState.NameSelect; //Yup, name selection
Draw(); //Draw the name select menu
Update_GetSessionStr();
if (Directory.Exists("Saves/" + sessionName))
{
try
{
FileL_ImportUniverse(sessionName); //Load it if we've got it
}
catch
{
Sdl.SDL_FillRect(screen, ref screenArea, 0); //Clear for next draw cycle
screenData = (Sdl.SDL_Surface)Marshal.PtrToStructure(screen, typeof(Sdl.SDL_Surface)); //Put the screen data in its place
DrawText(veraSmall, "Loading of {" + sessionName + "} has failed.",
new Point2D(windowSizeX / 2 - 130, windowSizeY / 2));
DrawText(veraSmall, "You can either clear it and start a new game, or save it and quit.",
new Point2D(windowSizeX / 2 - 130, windowSizeY / 2 + 15));
DrawText(veraSmall, "Delete corrupted data? [y/n]",
new Point2D(windowSizeX / 2 - 130, windowSizeY / 2 + 30));
Sdl.SDL_Flip(screen);
if (Update_GetKey() == "y")
{
Directory.Delete("Saves/" + sessionName, true);
string[] lines = File.ReadAllLines("Saves/SaveStockpile.txt"); //Read in the list of sessions
List<string> newData = new List<string>();
for (int n = 0; n < lines.Length; n++) //Loop through the lines
{
if (lines[n].StartsWith("[NAME] " + sessionName))
{
n += 2;
if (n >= lines.Length)
break;
}
newData.Add(lines[n]);
}
File.WriteAllLines("Saves/SaveStockpile.txt", newData.ToArray());
NewGame();
}
else
{
run = false;
return;
}
}
}
else
{
NewGame();
}
gameState = GameState.MainGame;
}
else if (selectionCursor == 2) //If "Help"
gameState = GameState.HelpMenu;
else if (selectionCursor == 4) //If "Load Game"
{
string[] saves = Directory.GetDirectories("Saves/");
if (saves.Length > 0) //If there's a save game
{
using (StreamReader read = new StreamReader(saves[0] + "/WorldData.txt")) //Open up the world data file
{
string line = read.ReadLine(); //Read the seed in
line = line.Remove(0, 7); //Remove "[SEED] "
worldSeed = int.Parse(line); //Seed the world
line = read.ReadLine(); //Read in the player position
}
gameState = GameState.MainGame;
}
}
else if (selectionCursor == 3) //If "Quit"
run = false;
break;
#endregion
}
}
static void Update_MainGame()
{
for (int n = 0; n < CurrentLevel.creatures.Count; n++) //For every creature
{
#region All Creatures
if (CurrentLevel.creatures[n].status_paralyzed > 0)
{
break;
}
if (CurrentLevel.creatures[n].turn_energy >= TURN_THRESHOLD) //If a creature's turn
{
if (n == 0)
{
if (!Update_Player(CurrentLevel.creatures[0])) //If skipped turn
{
return;
}
}
else
{
Update_Creature(CurrentLevel.creatures[n]);
}
Update_PostTurn(CurrentLevel.creatures[n]);
}
CurrentLevel.creatures[n].turn_energy += CurrentLevel.creatures[n].speed; //Every cycle, add to energy
#endregion
}
Update_World();
}
static void Update_HealthMenu()
{
switch (Update_GetKey())
{
case "Escape":
case "Space":
gameState = GameState.MainGame;
break;
}
}
static void Update_HelpMenu()
{
switch(Update_GetKey())
{
case "Space":
case "Escape":
gameState = GameState.OpeningMenu;
return;
}
}
static void Update_EscapeMenu()
{
switch (Update_GetKey())
{
case "Space":
case "Escape":
gameState = GameState.MainGame;
break;
case "2": //If down was pressed
if (selectionCursor < 2) //If down was pressed...
selectionCursor++; //...move the cursor down one, if possible.
else
selectionCursor = 1; //Loop over if needed
break;
case "8": //If up was pressed
if (selectionCursor > 1)
selectionCursor--;
else
selectionCursor = 2;
break;
case "Enter": //If enter aka "271" was pressed
if (selectionCursor == 1) //If "Return to game"
gameState = GameState.MainGame;
else if (selectionCursor == 2) //If "Quit and Save"
{
FileS_World();
run = false;
}
break;
}
}
static void Update_InventoryMenu()
{
if (inventorySelect <= 0) //If at the outer menu
{
Inv_Outer();
}
else //If within an item
{
if (inventorySelect > CurrentLevel.creatures[0].inventory.Count) //If the item is nonexistent
inventorySelect = 0; //Revert
if (inventoryMode == 0) //If we're just looking at an item
{
Inv_Main();
}
else if (inventoryMode == 1) //If in crafting mode
{
Inv_CombCraft();
}
inventorySelect = 0; //Revert
inventoryMode = 0;
}
}
static void Inv_Outer()
{
bool done = false;
while(!done)
{
string input = Update_GetKey();
switch (input)
{
case "Space":
case "Enter":
gameState = GameState.MainGame;
return;
}
inventorySelect = LetterIndexToNumber(input); //Set to letter input, if any
if (inventorySelect > CurrentLevel.creatures[0].inventory.Count || inventorySelect <= 0)
inventorySelect = 0;
else // If a valid selection
{
Inv_Main();
gameState = GameState.MainGame;
done = true;
}
}
}
static void Inv_Main()
{
Item thisItem = CurrentLevel.creatures[0].inventory[inventorySelect - 1];
Creature player = CurrentLevel.creatures[0];
Draw();
while (true)
{
switch (Update_GetKey())
{
case "Space":
case "Enter":
case "Backspace":
case "Escape":
inventorySelect = 0; //Nothing selected anymore
Draw(); //Update the screen for backing out of menu
return;
case "b": //Break down item
CurrentLevel.creatures[0].BreakDownItem(CurrentLevel, thisItem); //Break down said item
inventorySelect = 0;
gameState = GameState.MainGame;
return;
case "c":
#region Enter Combine Craft Mode
if (CurrentLevel.creatures[0].isDextrous)
{
craftableItems = CurrentLevel.creatures[0].FindValidRecipe( //Find list of items
thisItem, CurrentLevel.content.items.ToList()); //that can be made
inventoryMode = 1; //Crafting mode with item
Inv_CombCraft();
return;
}
else
{
CurrentLevel.creatures[0].message.Add("Your limbs are too clumsy to make tools.");
inventorySelect = 0; //Back out of menu
gameState = GameState.MainGame;
}
#endregion
return;
case "d":
CurrentLevel.creatures[0].Drop(CurrentLevel, thisItem); //Drop said item
inventorySelect = 0; //Back out of menu
gameState = GameState.MainGame;
return;
case "e":
#region Eat Item
if (thisItem.name.StartsWith(CurrentLevel.creatures[0].name)) //Aka, goblin eating goblin corpse
{
if (CurrentLevel.creatures[0].food > 2500)
{
CurrentLevel.creatures[0].message.Add("You nauseate yourself - you cannot bring yourself to eat one of your own kind");
break;
}
else
{
CurrentLevel.creatures[0].message.Add("It really is a matter of starvation or cannibalism.");
}
}
CurrentLevel.creatures[0].Eat(CurrentLevel, thisItem); //Eat said item
inventorySelect = 0; //Back out of menu
gameState = GameState.MainGame;
#endregion
return;
case "f":
#region Fire Item
Point2D targetPos = Update_GetPosition();
//currentLevel.tileArray[targetPos.X, targetPos.Y].itemList.Add(firedItem); //It ends up on selected tile
//currentLevel.creatureList[0].inventory.RemoveAt(inventorySelect - 1); //Remove item from inventory
CurrentLevel.creatures[0].message.Add("You send the " + thisItem.name + " flying.");
for (int i = 0; i < CurrentLevel.creatures.Count; i++)
{
Creature c = CurrentLevel.creatures[i];
if (c.pos == targetPos)
{
CurrentLevel.creatures[0].RangeAttack(CurrentLevel, c, thisItem);
}
}
inventorySelect = 0; //Back out of menu
gameState = GameState.MainGame;
#endregion
return;
case "u":
Inv_Main_UseItem();
return;
case "w":
#region Wield Item
Item w;
w = CurrentLevel.creatures[0].inventory[inventorySelect - 1];
if (CurrentLevel.creatures[0].CanWield(w))
{
CurrentLevel.creatures[0].Wield(w);
gameState = GameState.MainGame;
}
else
{
CurrentLevel.creatures[0].message.Add("The " + w.name + " slips from your grip");
}
inventorySelect = 0; //Back out of menu
gameState = GameState.MainGame;
#endregion
return;
case "W":
#region Wear Item
if (thisItem is Armor)
{
Armor thisArmor = (Armor)thisItem;
if (CurrentLevel.creatures[0].CanWear(thisArmor))
{
CurrentLevel.creatures[0].Wear(thisArmor);//If it's armor, wear it.
gameState = GameState.MainGame;
}
}
else if (thisItem is Amulet)
{
Amulet thisAmulet = (Amulet)thisItem;
if (player.amulet == null)
{
player.Wear(new Amulet(thisAmulet), CurrentLevel);
}
else
{
player.inventory.Add(new Amulet(player.amulet)); //Copy amulet
player.amulet = new Amulet(thisAmulet); //Overwrite amulet
}
}
else
CurrentLevel.creatures[0].message.Add("That's not armor.");
inventorySelect = 0; //Back out of menu
gameState = GameState.MainGame;
#endregion
return;
}
}
}
static void Inv_Main_UseItem()
{
if (!CurrentLevel.creatures[0].isDextrous) //Check to see if these can be used
{
CurrentLevel.creatures[0].message.Add("Your limbs are too clumsy to use this");
}
else if (CurrentLevel.creatures[0].inventory[inventorySelect - 1].use.Count > 1) //If it has multple uses
{
//inventoryMode = 2; //Switch to Use mode with item WIP
}
else if (CurrentLevel.creatures[0].inventory[inventorySelect - 1].use.Count == 1)
{
//Do the use for the item
if (CurrentLevel.creatures[0].inventory[inventorySelect - 1].use[0] == "dig")
{
#region Dig
Point2D pos = CurrentLevel.creatures[0].pos;
if (CurrentLevel.tileArray[pos.X, pos.Y].hasBeenDug) //If it's been dug
{
Creature player = CurrentLevel.creatures[0];
player.message.Add("You break through the floor, and fall all the way to the next level down.");
player.TakeDamage(5);
player.message.Add("You land with a painful thud.");
mapPos.Z++;
GenLevel("dungeon", true);
while (!CurrentLevel.tileArray[player.pos.X, player.pos.Y].isPassable) //Keep going until we can move
{
player.pos.X = (short)rng.Next(1, Level.GRIDW);
player.pos.Y = (short)rng.Next(1, Level.GRIDH);
}
CurrentLevel.creatures[0] = player;
Item dirtChunk = new Item(100f, 100f, "dirt chunk", Color.FromArgb(157, 144, 118), new List<Item>(), new List<string>()); //Chunk of dirt
CurrentLevel.tileArray[player.pos.X, player.pos.Y].itemList.Add(new Item(dirtChunk)); //Put the dirt chunk there
}
else
{
Item dirtChunk = new Item(100f, 100f, "dirt chunk", Color.FromArgb(157, 144, 118), new List<Item>(), new List<string>()); //Chunk of dirt
CurrentLevel.tileArray[pos.X, pos.Y].itemList.Add(new Item(dirtChunk)); //Put the dirt chunk there
CurrentLevel.tileArray[pos.X, pos.Y].hasBeenDug = true; //We've dug a pit here.
CurrentLevel.creatures[0].message.Add("You dig a hole, unearthing some dirt.");
}
#endregion
}
else if (CurrentLevel.creatures[0].inventory[inventorySelect - 1].use[0] == "mine")
{
#region Mine
CurrentLevel.creatures[0].message.Add("Choose a direction to dig.");
gameState = GameState.MainGame;
string input = Update_GetKey();
Point2D playerPos = CurrentLevel.creatures[0].pos;
Point2D radius = new Point2D(playerPos.X, playerPos.Y);
if (input == "1")
radius = new Point2D(playerPos.X - 1, playerPos.Y + 1);
else if (input == "2")
radius = new Point2D(playerPos.X - 0, playerPos.Y + 1);
else if (input == "3")
radius = new Point2D(playerPos.X + 1, playerPos.Y + 1);
else if (input == "4")
radius = new Point2D(playerPos.X - 1, playerPos.Y - 0);
else if (input == "6")
radius = new Point2D(playerPos.X + 1, playerPos.Y - 0);
else if (input == "7")
radius = new Point2D(playerPos.X - 1, playerPos.Y - 1);
else if (input == "8")
radius = new Point2D(playerPos.X - 0, playerPos.Y - 1);
else if (input == "9")
radius = new Point2D(playerPos.X + 1, playerPos.Y - 1);
else
{
CurrentLevel.creatures[0].message.Add("Dig cancelled");
return;
}
if (CurrentLevel.tileArray[radius.X, radius.Y].fixtureLibrary.Count > 0)
{
if (CurrentLevel.tileArray[radius.X, radius.Y].fixtureLibrary[0] is Door)
{
if (rngDie.Roll(2) == 1) // 1/2 chance
{
CurrentLevel.creatures[0].message.Add("Your swing bounces wildly off the door");
}
else
{
CurrentLevel.creatures[0].message.Add("You break right through the door");
CurrentLevel.tileArray[radius.X, radius.Y].MakeOpen(); //Clear out adjacent tile
}
}
else if (CurrentLevel.tileArray[radius.X, radius.Y].fixtureLibrary[0] is Tree)
{
if (rngDie.Roll(100) == 1) // 1% chance
{
CurrentLevel.creatures[0].message.Add("You somehow hit a weak point and topple the tree!");
Tree thisTree = (Tree)CurrentLevel.tileArray[radius.X, radius.Y].fixtureLibrary[0];
CurrentLevel.tileArray[radius.X, radius.Y].itemList.Add(new Item(500f, 500f, CapitalizeFirst(thisTree.species) + " log", Color.Brown, new List<Item>(), new List<string>()));
CurrentLevel.creatures[0].message.Add("You cut down the " + thisTree.species + " tree.");
CurrentLevel.tileArray[radius.X, radius.Y].fixtureLibrary.RemoveAt(0);
}
else // 99% chance
{
CurrentLevel.creatures[0].message.Add("You chip off only sawdust");
CurrentLevel.tileArray[radius.X, radius.Y].MakeOpen(); //Clear out adjacent tile
}
}
else
{
CurrentLevel.tileArray[radius.X, radius.Y].MakeOpen(); //Clear out adjacent tile
}
}
else
{
CurrentLevel.tileArray[radius.X, radius.Y].MakeOpen(); //Clear out the adjacent tile
}
#endregion
}
else if (CurrentLevel.creatures[0].inventory[inventorySelect - 1].use[0] == "tripwire")
{
#region Tripwire
Point2D playerPos = CurrentLevel.creatures[0].pos;
if (CurrentLevel.tileArray[playerPos.X, playerPos.Y].fixtureLibrary.Count <= 0)
{
Trap thisTrap = new Trap(new Effect(rngDie.Roll(5), "tripwire"));
thisTrap.visible = true; //The player made it, so they can see it
CurrentLevel.tileArray[playerPos.X, playerPos.Y].fixtureLibrary.Add(thisTrap);
CurrentLevel.creatures[0].inventory.RemoveAt(inventorySelect - 1); //Rope is now in trap
CurrentLevel.creatures[0].message.Add("You make a tripwire from the rope.");
}
else
{
CurrentLevel.creatures[0].message.Add("There is already a " +
CurrentLevel.tileArray[playerPos.X, playerPos.Y].fixtureLibrary[0].type + " here.");
}
#endregion
}
else if (CurrentLevel.creatures[0].inventory[inventorySelect - 1].use[0] == "chop")
{
#region Chop
CurrentLevel.creatures[0].message.Add("Choose a direction to chop.");
gameState = GameState.MainGame;
string input = Update_GetKey();
Point2D playerPos = CurrentLevel.creatures[0].pos;
Point2D radius = new Point2D(playerPos.X, playerPos.Y);
if (input == "1")
radius = new Point2D(playerPos.X - 1, playerPos.Y + 1);
else if (input == "2")
radius = new Point2D(playerPos.X - 0, playerPos.Y + 1);
else if (input == "3")
radius = new Point2D(playerPos.X + 1, playerPos.Y + 1);
else if (input == "4")
radius = new Point2D(playerPos.X - 1, playerPos.Y - 0);
else if (input == "6")
radius = new Point2D(playerPos.X + 1, playerPos.Y - 0);
else if (input == "7")
radius = new Point2D(playerPos.X - 1, playerPos.Y - 1);
else if (input == "8")
radius = new Point2D(playerPos.X - 0, playerPos.Y - 1);
else if (input == "9")
radius = new Point2D(playerPos.X + 1, playerPos.Y - 1);
else
{
CurrentLevel.creatures[0].message.Add("Chop cancelled");
return;
}
bool creatureThere = false;
foreach (Creature c in CurrentLevel.creatures)
{
if (c.pos == radius) //If a creature is there.
{
creatureThere = true;
}
}
if (creatureThere) //Stupid foreach limitations
CurrentLevel.creatures[0].MeleeAttack(CurrentLevel, Direction.Parse(input));
else
{
if (CurrentLevel.tileArray[radius.X, radius.Y].fixtureLibrary.Count > 0)
{
if (CurrentLevel.tileArray[radius.X, radius.Y].fixtureLibrary[0] is Tree)
{
Tree thisTree = (Tree)CurrentLevel.tileArray[radius.X, radius.Y].fixtureLibrary[0];
CurrentLevel.tileArray[radius.X, radius.Y].itemList.Add(new Item(500f, 500f, CapitalizeFirst(thisTree.species) + " log", Color.Brown, new List<Item>(), new List<string>()));
CurrentLevel.creatures[0].message.Add("You cut down the " + thisTree.species + " tree.");
CurrentLevel.tileArray[radius.X, radius.Y].fixtureLibrary.RemoveAt(0);
}
else if (CurrentLevel.tileArray[radius.X, radius.Y].fixtureLibrary[0] is Door)
{
Item stick = new Item(100f, 100f, "stick", Color.Brown, new List<Item>(), new List<string>());
CurrentLevel.tileArray[radius.X, radius.Y].itemList.Add(new Item(stick));
CurrentLevel.tileArray[radius.X, radius.Y].itemList.Add(new Item(stick));
CurrentLevel.tileArray[radius.X, radius.Y].itemList.Add(new Item(stick));
CurrentLevel.tileArray[radius.X, radius.Y].fixtureLibrary.RemoveAt(0);
CurrentLevel.tileArray[radius.X, radius.Y].isPassable = true;
CurrentLevel.tileArray[radius.X, radius.Y].isTransparent = true;
CurrentLevel.tileArray[radius.X, radius.Y].isDoor = false;
CurrentLevel.creatures[0].message.Add("You chop the door to pieces");
}
}
}
#endregion
}
}
else
{
CurrentLevel.creatures[0].message.Add("You can't think of an obvious use for it at the moment.");
}
gameState = GameState.MainGame;
inventorySelect = 0;
inventoryMode = 0;
}
static void Inv_CombCraft()
{
Draw();
while(true)
{
string input = Update_GetKey();
switch(input)
{
case "Escape":
case "Space":
case "Backspace":
gameState = GameState.MainGame;
inventoryMode = 0;
inventorySelect = 0;
return;
}
int selection = LetterIndexToNumber(input);
Queue<Item> items = new Queue<Item>();
foreach (Item item in craftableItems) //Get a queue of all the craftable items
{
items.Enqueue(item);
if (items.Count >= 24)
{
items.Dequeue(); //Don't let there be more than 24 in the queue
}
}
int count = items.Count;
for (int c = 1; c <= count; c++) //Pretty much a foreach, but allows deletion
{
if (c == selection) //If we've selected this item
{
CurrentLevel.creatures[0].CombineItem(CurrentLevel.creatures[0].inventory[inventorySelect - 1],
items.Dequeue());
inventorySelect = 0; //Back out of menu
inventoryMode = 0;
gameState = GameState.MainGame;
return;
}
else
{
items.Dequeue();
}
}
items.Clear();
}
}
static void Inv_Use()
{
}
static bool Update_Player(Creature c)
{
if (CurrentLevel.playerDiedHere)
{
if (c.revive > 0) //If extra life
{
c.revive = 0; //Not anymore, sukka
if (c.amulet.effect.type == "revive")
{
c.message.Add("Your " + c.amulet.name + " disintegrates.");
c.amulet = null;
}
c.hp = c.hpMax; //Full heal
c.food = 15000; //Full food
c.message.Add("You have a near death experience");
c.constitution--;
CurrentLevel.playerDiedHere = false;
}
else
{
c.message.Add("You have died from " + CurrentLevel.causeOfDeath);
c.message.Add("This happened because " + CurrentLevel.mannerOfDeath);
c.message.Add("You have slain " + CurrentLevel.creatures[0].killCount + " foes");
c.message.Add("You lived to see " + exploredLevels + " areas in your world");
Draw();
while (Update_GetKey() != "Enter") { }; //Wait for Enter
FileD_World();
run = false;
gameState = GameState.OpeningMenu;
return false;
}
}
bool wait = true;
Point2D radius;
while (wait)
{
Draw();
string input = Update_GetKey();
#region Process Input
switch (input)
{
case "1":
case "2":
case "3":
case "4":
case "6":
case "7":
case "8":
case "9":
return Update_Move(CurrentLevel.creatures[0],
Direction.Parse(input));
case "5":
case ".":
case "s":
return true; //Wait a turn
case ">":
#region [S] Adventurer: Descend
if (CurrentLevel.tileArray[c.pos.X, c.pos.Y].fixtureLibrary.Count > 0)
{ //If there's a fixture here
if (CurrentLevel.tileArray[c.pos.X, c.pos.Y].fixtureLibrary[0] is Stairs)
{ //If that fixture is stairs
Stairs stairs = (Stairs)CurrentLevel.tileArray[c.pos.X, c.pos.Y].fixtureLibrary[0]; //Stairs
if (stairs.isDown)
{ //If those stairs are down stairs
mapPos.Z++; //Go down a level
c = new Creature(c); //Break reference link
GenLevel("dungeon", true);
c.pos = CurrentLevel.creatures[0].pos; //Place the player at the new up stairs position
CurrentLevel.creatures[0] = c;
wait = true;
}
else
{
c.message.Add("How does one go down up stairs?");
}
}
}
break;
#endregion
case "<":
#region [S] Adventurer: Ascend
if (CurrentLevel.tileArray[c.pos.X, c.pos.Y].fixtureLibrary.Count > 0)
{
if (CurrentLevel.tileArray[c.pos.X, c.pos.Y].fixtureLibrary[0] is Stairs)
{
Stairs stairs = (Stairs)CurrentLevel.tileArray[c.pos.X, c.pos.Y].fixtureLibrary[0]; //Stairs
if (!stairs.isDown)
{
mapPos.Z--; //Go up a level
c = new Creature(c); //Break reference link
if (mapPos.Z < 1)
{
Random thisLevelRNG = new Random(levelSeed[mapPos.X, mapPos.Y, mapPos.Z]); //This level's generator
if (thisLevelRNG.Next(0, 100) < 20)
{
GenLevel("village", true);
}
else
{
GenLevel("forest", true);
}
}
else
GenLevel("dungeon", true);
for (int y = 0; y < Level.GRIDH; y++)
for (int x = 0; x < Level.GRIDW; x++)
if (CurrentLevel.tileArray[x, y].fixtureLibrary.Count > 0)
if (CurrentLevel.tileArray[x, y].fixtureLibrary[0].type == "stairs")
{
stairs = (Stairs)CurrentLevel.tileArray[x, y].fixtureLibrary[0];
if (stairs.isDown)
c.pos = new Point2D(x, y); //Place on down stairs
}
CurrentLevel.creatures[0] = c;
}
else
{
c.message.Add("How does one go up down stairs?");
}
}
}
break;
#endregion
case "Escape":
gameState = GameState.EscapeMenu;
return false;
case ",":
#region Pick Up
c.PickUp(CurrentLevel);
while (c.inventory.Count > 25)
{
c.message.Add("You drop your " + c.inventory[25] + " to make room.");
c.Drop(CurrentLevel, c.inventory[25]); //Drop item
}
wait = false;
break;
#endregion
case "c":
#region Close
Point2D[] position = new Point2D[10];
position[1] = new Point2D((int)c.pos.X - 1, (int)c.pos.Y + 1);
position[2] = new Point2D((int)c.pos.X , (int)c.pos.Y + 1);
position[3] = new Point2D((int)c.pos.X + 1, (int)c.pos.Y + 1);
position[4] = new Point2D((int)c.pos.X - 1, (int)c.pos.Y );
position[6] = new Point2D((int)c.pos.X + 1, (int)c.pos.Y );
position[7] = new Point2D((int)c.pos.X - 1, (int)c.pos.Y - 1);
position[8] = new Point2D((int)c.pos.X , (int)c.pos.Y - 1);
position[9] = new Point2D((int)c.pos.X + 1, (int)c.pos.Y - 1);
for (int dir = 1; dir <= 9; dir++)
{
if (dir == 5)
dir++; //Skip 5
foreach (Fixture f in CurrentLevel.tileArray[(int)position[dir].X, (int)position[dir].Y].fixtureLibrary)
{
if (f.type == "door")
{
Door door = (Door)f;
if (door.isOpen)
{
c.CloseDoor(CurrentLevel.tileArray[
(int)position[dir].X, (int)position[dir].Y], CurrentLevel);
}
}
}
}
break;
#endregion
case "e":
CurrentLevel.tileArray[c.pos.X, c.pos.Y].engraving = Update_GetString(); //Engrave
wait = false;
break;
case "h":
#region Hax dig
if (debugMode)
{
c.message.Add("Choose a direction to dig.");
string s = Update_GetKey();
radius = new Point2D(c.pos.X, c.pos.Y);
if (s == "1")
radius = new Point2D(c.pos.X - 5, c.pos.Y + 5);
else if (s == "2")
radius = new Point2D(c.pos.X - 0, c.pos.Y + 5);
else if (s == "3")
radius = new Point2D(c.pos.X + 5, c.pos.Y + 5);
else if (s == "4")
radius = new Point2D(c.pos.X - 5, c.pos.Y - 0);
else if (s == "6")
radius = new Point2D(c.pos.X + 5, c.pos.Y - 0);
else if (s == "7")
radius = new Point2D(c.pos.X - 5, c.pos.Y - 5);
else if (s == "8")
radius = new Point2D(c.pos.X - 0, c.pos.Y - 5);
else if (s == "9")
radius = new Point2D(c.pos.X + 5, c.pos.Y - 5);
else
{
c.message.Add("Dig cancelled");
break;
}
c.message.Add("You release a blast of unnatural energy, tearing through the walls of the dungeon.");
CurrentLevel.DigLine(c.pos, radius);
wait = false;
}
wait = true;
break;
#endregion
case "i":
gameState = GameState.InventoryMenu; //Gamestate is now the Inventory Menu
return false;
case "k":
#region Kick/Break
c.message.Add("Choose a direction.");
input = Update_GetKey();
radius = new Point2D(c.pos.X, c.pos.Y);
if (input == "1")
radius = new Point2D(c.pos.X - 1, c.pos.Y + 1);
else if (input == "2")
radius = new Point2D(c.pos.X - 0, c.pos.Y + 1);
else if (input == "3")
radius = new Point2D(c.pos.X + 1, c.pos.Y + 1);
else if (input == "4")
radius = new Point2D(c.pos.X - 1, c.pos.Y - 0);
else if (input == "6")
radius = new Point2D(c.pos.X + 1, c.pos.Y - 0);
else if (input == "7")
radius = new Point2D(c.pos.X - 1, c.pos.Y - 1);
else if (input == "8")
radius = new Point2D(c.pos.X - 0, c.pos.Y - 1);
else if (input == "9")
radius = new Point2D(c.pos.X + 1, c.pos.Y - 1);
else
{
c.message.Add("Cancelled");
break;
}
bool creatureThere = false;
foreach (Creature d in CurrentLevel.creatures)
{
if (d.pos == radius) //If a creature is there.
{
creatureThere = true;
}
}
if (creatureThere) //Stupid foreach limitations
{