forked from GlyphGryph/kobold-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kobold.py
7691 lines (7192 loc) · 282 KB
/
kobold.py
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
import asyncio
import json
import math
import operator
import os
import random
import re
import shelve
import time
import traceback
import discord
from dotenv import load_dotenv
from src.creature import Creature
from src.dummy_message import DummyMessage
from src.encounter import Encounter
from src.item import Item
from src.kobold import Kobold
from src.party import Party
from src.tile import Tile
from src.tribe import Tribe
from src.world import World
BOT_NAME = 'Lulurnbus#1506'
STATS = ["str", "dex", "con", "int", "wis", "cha"]
STAT_COLOR = {"str": "red", "dex": "white", "con": "black",
"int": "blue", "wis": "green", "cha": "yellow"}
COLOR_STAT = {"red": "str", "white": "dex", "black": "con",
"blue": "int", "green": "wis", "yellow": "cha"}
OPP_DIR = {"n": "s", "s": "n", "w": "e", "e": "w"}
OPP_DIR2 = {"n": "s", "s": "n", "w": "e", "e": "w", "u": "d", "d": "u"}
DIR_FULL = {"n": "north", "e": "east", "w": "west", "s": "south"}
GENOME = {"red": [False, False],
"yellow": [False, False],
"green": [False, False],
"blue": [False, False],
"black": [False, False],
"white": [False, False]}
ROLENAMES = {"brown": "Mudscale", "red": "Bloodscale", "yellow": "Goldscale", "green": "Jadescale", "blue": "Silkscale",
"white": "Marblescale", "black": "Coalscale", "orange": "Copperscale", "purple": "Violetscale", "silver": "Silverscale"}
# ADVANCE_TOTALS=[4,8,12,16,20,24]
def get_q_desc(q):
qs = ["Abysmal", "Awful", "Crude", "Poor", "Normal",
"Decent", "Good", "Excellent", "Masterwork", "Legendary"]
q += 4
if q > 9:
return "Divine"
if q < 0:
return "Broken"
return qs[q]
def kobold_name():
vowels = ['a', 'i', 'o', 'u', 'e']
penvowels = ['a', 'o', 'u', 'ay', 'ee', 'i']
frontcluster = ['b', 'br', 'bl', 'd', 'dr', 'dl', 'st', 'str', 'stl', 'shl', 'k', 'p',
'l', 'lr', 'sh', 'j', 'jr', 'thl', 'g', 'f', 'gl', 'gr', 'fl', 'fr', 'x', 'z', 'zr', 'r']
cluster = ['b', 'd', 'l', 'f', 'g', 'k', 'p', 'n', 'm', 's', 'v']
fincluster = ['m', 'r', 'ng', 'b', 'rb', 'mb', 'g', 'lg',
'l', 'lb', 'lm', 'rg', 'k', 'rk', 'lk', 'rv', 'v']
finsyl = ['is', 'us', 'ex1', 'ex2', 'al', 'a', 'ex3']
first = 1
syl = random.randint(0, 2)+1
firstname = ""
vowel = choice(vowels)
while syl > 0:
if syl == 1:
vowel = choice(penvowels)
if first == 1 or syl == 1:
firstname = firstname + choice(frontcluster)
first = 0
else:
firstname = firstname + choice(cluster)
firstname = firstname + vowel
syl = syl - 1
firstname = firstname + choice(fincluster)
fin = choice(finsyl)
if vowel in ['o', 'ay', 'u', 'a']:
if fin == 'ex1':
fin = choice(['er', 'ar'])
elif fin == 'ex2':
fin = choice(['in', 'an'])
elif fin == 'ex3':
fin = 'i'
elif 'ex' in fin:
fin = choice(['is', 'us', 'al', 'a'])
firstname = firstname + fin
return firstname.capitalize()
def tribe_name():
try:
f = open('data/tribe_names.txt')
except:
console_print('ERROR: Cannot find tribe name list')
return "Erroneously-named Tribe"
temp_names = []
for line in f:
nam = line.strip('\n')
nam = nam.capitalize()
temp_names.append(nam)
n = choice(temp_names)+" "+choice(temp_names)
f.close()
return n
# def alpha_str(str):
def choice(ch):
if len(ch) == 0:
return None
else:
return random.choice(ch)
def chance(ch):
if ch <= 0:
return False
c = random.randint(1, 100)
console_print("CHANCE: looking for "+str(ch)+" or less, got "+str(c))
if c <= abs(ch):
return True
else:
return False
def get_json(fname):
try:
f = open(fname)
stuff = json.load(f)
f.close()
except IOError as e:
console_print('There was a problem loading '+fname+':\n'+e.args[0])
return None
except ValueError as e:
console_print('There was a problem parsing '+fname+':\n'+e.args[0])
return None
return stuff
def has_item(self, name, q=1):
#console_print("has item for "+name)
if name[0] == "*":
cat = name.replace("*", "")
else:
cat = None
for i in self.items:
if (cat and i.name in item_cats[cat]) or (not cat and i.name == name):
#console_print(i.name+" fits the bill")
if i.num >= q:
return i
else:
q -= i.num
return None
def consume_item(self, name, q=1):
while q > 0:
i = self.has_item(name)
qq = q
q -= i.num
i.num -= qq
if i.num <= 0:
i.destroy("Consumed")
def check_req(self, req, k=None):
good = "good"
if k:
place = k.get_place()
else:
place = self
for q in req:
if q[0] == "research":
if isinstance(self, Tribe) and q[1] in self.research:
#console_print("research req good because in tribe research")
continue
#console_print(k.get_name()+" fam with "+q[1]+" = "+str(k.familiar(q[1])))
if k and k.familiar(q[1]) > 0:
#console_print("research req good because initiator is familiar")
continue
fam = False
if k:
for l in k.world.kobold_list:
if l.get_place() == place and l.familiar(q[1]) >= 2:
fam = True
break
if fam:
#console_print("research req good because kobold with familiarity here")
continue
if place == self:
good = "Research missing: "+q[1]
else:
good = "Unfamiliar research: "+q[1]
elif q[0] == "item":
g = "Item missing: "+q[1]
if place.has_item(q[1]):
g = "good"
if k and k.has_item(q[1]):
g = "good"
good = g
elif q[0] == "tool":
g = "Tool missing: "+q[1]
for i in place.items:
if i.tool == q[1]:
g = "good"
if k:
for i in k.items:
if i.tool == q[1]:
g = "good"
if good == "good":
good = g
elif q[0] == "building":
if not isinstance(place, Tribe):
good = "Can't be done in the overworld."
elif not place.has_building(q[1]):
good = "Building missing: "+q[1]
elif q[0] == "landmark":
if isinstance(place, Tribe):
tile = place.world.get_tile(place.x, place.y, place.z)
else:
tile = place
if q[1] not in tile.special:
good = "Landmark missing: "+q[1]
elif q[0] == "minlevel":
if k:
z = k.z
else:
z = self.z
if q[1] > z:
good = "Must be done at level "+str(q[1])+" or lower."
elif q[0] == "maxlevel":
if k:
z = k.z
else:
z = self.z
if q[1] < z:
good = "Must be done at level "+str(q[1])+" or lower."
elif q[0] == "tribe":
if isinstance(place, Tribe):
t = place
else:
t = place.get_tribe()
if t and not q[1]:
good = "You cannot do that in a tile with a den."
if not t and q[1]:
good = "Must be done in a tile with a den."
elif q[0] == "liquid":
if isinstance(place, Tribe):
tile = place.world.get_tile(place.x, place.y, place.z)
else:
tile = place
g = "Liquid source missing: "+q[1]
for l in tile.special:
if landmark_data[l].get("liquid_source", "none") == q[1]:
g = "good"
if good == "good":
good = g
return good
def get_tri_distance(x1, y1, x2, y2):
xdist = abs(x1-x2)
ydist = abs(y1-y2)
return (min(xdist, ydist)*1.4)+abs(xdist-ydist)
def get_dir(ct, k):
if abs(ct.x-k.x) > abs(ct.y-k.y):
if ct.x < k.x:
return "west"
elif ct.x > k.x:
return "east"
else:
if ct.y < k.y:
return "north"
elif ct.y > k.y:
return "south"
else:
return "same"
def attack_roll(self, target, bonus=0, guarding=False, sparring=False):
chan = target.get_chan()
if target.has_trait("protected") and len(target.encounter.creatures) > 1 and chance(75):
guards = list(target.encounter.creatures)
if target in guards:
guards.remove(target)
ot = target
target = choice(guards)
game_print(target.display() +
" jumps in the way to protect "+ot.display()+"!", chan)
game_print(self.display()+" attacks "+target.display()+".", chan)
adv = 0
if self.has_trait("greased"):
if self.save("dex") < 11:
game_print(self.display() +
" slips on the grease and falls prone!", chan)
return 0
else:
game_print(self.display() +
" manages to work their way out of the grease.", chan)
self.del_trait("greased")
for t in target.traits:
if trait_data[t].get("target_adv", 0) != 0:
adv += trait_data[t]["target_adv"]
for t in self.traits:
if trait_data[t].get("attack_adv", 0) != 0:
adv += trait_data[t]["attack_adv"]
if self.has_trait("oneeye") and self.equip and self.equip.type == "ranged":
adv -= 1
if isinstance(self, Kobold) and not self.shaded:
adv -= 1
roll = droll(1, 20, adv)
roll += self.tohit
if roll >= target.ac or roll == self.tohit+20: # hits, roll damage
dmg = self.dmg[2]
if roll == self.tohit+20 and target.ac-self.tohit < 20:
game_print("Critical hit!", chan)
dmg *= 2
for x in range(self.dmg[0]):
dmg += random.randint(1, self.dmg[1])
if self.dmgtype not in ["bludgeoning", "piercing", "slashing"] and self.wearing_nonmage_equipment():
dmg = math.ceil(dmg/2)
if guarding and target.save("con") > 13:
dmg -= random.randint(1, max(1, target.smod("con")+1))
dmg = max(1, dmg) # no hitting 0's or negative numbers
if not sparring:
target.hp_tax(dmg, "Killed by "+self.display(), self, self.dmgtype)
if target.has_trait("barrier"):
reflect = random.randint(0, math.ceil(dmg/4))
if reflect > 0:
self.hp_tax(reflect, "Taste of own medicine",
target, "force")
else:
if self.equip and self.equip.type == "ranged":
sk = "marksman"
elif self.equip and self.equip.type == "magic":
sk = "sorcery"
else:
sk = "melee"
if chance((dmg-self.skmod(sk))*5):
self.p("[n] accidentally hits "+target.display() +
" with more force than intended!")
target.hp_tax(random.randint(1, dmg),
"Sparring accident", dmgtype=self.dmgtype)
else:
self.p("[n] holds back, but would have dealt " +
str(dmg)+" damage.")
target.gain_xp("resilience", dmg*4)
if self.has_trait("poisoner"):
if target.save("con") < 11:
game_print(target.display()+" has been poisoned!", chan)
target.add_trait("poisoned")
if self.has_trait("paralyzer"):
if target.save("con") < 8:
game_print(target.display()+" has been paralyzed!", chan)
target.add_trait("paralyzed")
else:
game_print("The attack missed.", chan)
if sparring:
target.gain_xp("resilience", roll+10)
dmg = 0
if dmg > 0:
if target.has_trait("corroder"):
if self.equip:
self.equip.lower_durability(3)
else:
self.hp_tax(1, "Acid burn", dmgtype="acid")
trs = list(self.traits)
for t in trs:
if trait_data[t].get("attack_reset", False):
self.del_trait(t)
return dmg
def droll(dice, sides, adv=0):
roll = []
if adv != 0:
rolls = 2
else:
rolls = 1
for q in range(rolls):
r = 0
for d in range(dice):
r += random.randint(1, sides)
roll.append(r)
if adv == 1:
return max(roll)
else:
return min(roll)
def spawn_item(name, place, num=1, force=False, quality=None):
i = None
while num > 0:
i = Item(name, num)
if isinstance(place, Kobold) or isinstance(place, Creature):
bag = False
if i.inv_size > 0:
for h in place.items:
if h.inv_size > 0:
bag = True
if (bag or len(place.items) >= place.inv_size) and not force:
place.p("[n]'s inventory is full. Some items were dropped.")
place = place.get_place() # inventory full
elif isinstance(place, Creature) and "haul" not in place.training:
place.p("[n] doesn't have haul training, so it dropped the item.")
place = place.get_place() # inventory full
num -= i.num
i.move(place)
console_print("Spawned: "+name+" x "+str(i.num))
return i
def make_baby(male, female):
baby = Kobold(female.tribe)
baby.age = 0
if baby in male.world.kobold_list:
male.world.kobold_list.remove(baby)
pr = ""
for g in GENOME:
if chance(50):
baby.genome[g][0] = male.genome[g][0]
else:
baby.genome[g][0] = male.genome[g][1]
if chance(50):
baby.genome[g][1] = female.genome[g][0]
else:
baby.genome[g][1] = female.genome[g][1]
pr += g+":["+str(baby.genome[g][0])+","+str(baby.genome[g][1])+"]; "
console_print(pr)
pure = "none"
purecount = 0
orange = 0
purple = 0
for g in baby.genome:
if g not in STAT_COLOR.values():
continue
if not (baby.genome[g][0] or baby.genome[g][1]):
console_print("baby has pure "+g+" genomes")
purecount += 1
if g in ["red", "white", "black"]:
orange += 1
elif g in ["blue", "green", "yellow"]:
purple += 1
if pure == "none":
pure = g
else:
pure = "brown"
if purecount >= 5:
pure = "silver"
elif orange > purple+1:
pure = "orange"
elif purple > orange+1:
pure = "purple"
if pure not in ["none", "brown"]:
baby.color = pure
baby.parents = [male.get_name(), female.get_name()]
return baby
def spell_generic_trait(spell, words, me, target):
if not target.has_trait(spell["grant_trait"]):
target.add_trait(spell["grant_trait"])
return True
else:
me.p("That kobold already has " +
trait_data[spell["grant_trait"]].get("display", spell["grant_trait"])+".")
return False
def spell_sleep(spell, words, me, target):
targets = list(target.encounter.creatures)
spellsave = 6+me.smod("int")+me.skmod("sorcery")
for t in targets:
if t.save("wis") < spellsave:
t.add_trait("sleep")
target.encounter.pac_check()
return True
def spell_fireball(spell, words, me, target):
targets = list(target.encounter.creatures)
spellsave = 6+me.smod("int")+me.skmod("sorcery")
dmg = spell["dmg"][2]
for x in range(spell["dmg"][0]):
dmg += random.randint(1, spell["dmg"][1])
if me.wearing_nonmage_equipment():
dmg = math.ceil(dmg/2)
for t in targets:
bdmg = dmg
if t.save("dex") >= spellsave:
bdmg = math.floor(dmg/2)
t.hp_tax(bdmg, spell["name"], me, "fire")
return True
def spell_tremor(spell, words, me, target):
targets = list(target.encounter.creatures)
spellsave = 6+me.smod("int")+me.skmod("sorcery")
dmg = spell["dmg"][2]
for x in range(spell["dmg"][0]):
dmg += random.randint(1, spell["dmg"][1])
p = me.get_place()
if p.z == 0 and not me.dungeon:
dmg = math.ceil(dmg/2)
else:
p.stability -= 5
p.cave_in(party.owner)
if me.wearing_nonmage_equipment():
dmg = math.ceil(dmg/2)
for t in targets:
bdmg = dmg
if t.save("dex") >= spellsave:
bdmg = math.floor(dmg/2)
t.hp_tax(bdmg, spell["name"], me, "bludgeoning")
return True
def spell_freeze(spell, words, me, t):
spellsave = 6+me.smod("int")+me.skmod("sorcery")
dmg = spell["dmg"][2]
for x in range(spell["dmg"][0]):
dmg += random.randint(1, spell["dmg"][1])
if me.wearing_nonmage_equipment():
dmg = math.ceil(dmg/2)
if t.save("con") >= spellsave:
dmg = math.floor(dmg/2)
else:
t.add_trait("frozen")
t.hp_tax(dmg, spell["name"], me, "cold")
return True
def spell_grease(spell, words, me, t):
spellsave = 4+me.smod("int")+me.skmod("sorcery")
for c in t.encounter.creatures:
if c.save("dex") >= spellsave:
me.p(c.display()+" was unaffected.")
else:
me.p(c.display()+" is greased!")
c.add_trait("greased")
return True
def spell_sparkle(spell, words, me, t):
spellsave = 6+me.smod("int")+me.skmod("sorcery")
if t.save("dex") >= spellsave:
me.p(t.display()+" was unaffected.")
else:
me.p(t.display()+" is blinded!")
t.add_trait("blinded")
return True
def spell_charm(spell, words, me, t):
if t.tribe:
me.p("You can only cast that on a tribeless kobold.")
return False
spellsave = 6+me.smod("int")+me.skmod("sorcery")
if t.save("cha") >= spellsave:
me.p(t.display()+" was unaffected.")
else:
me.p(t.display()+" is charmed!")
t.add_trait("charmed")
return True
def spell_missile(spell, words, me, t):
dmg = spell["dmg"][2]
for x in range(spell["dmg"][0]):
dmg += random.randint(1, spell["dmg"][1])
if me.wearing_nonmage_equipment():
dmg = math.ceil(dmg/2)
t.hp_tax(dmg, spell["name"], me, "force")
return True
def spell_lifesteal(spell, words, me, t):
me.tohit = me.smod("int")+math.floor(me.skmod("sorcery")/2)
me.dmg = list(spell["dmg"])
me.dmgtype = spell["dmgtype"]
dmg = attack_roll(me, t)
if dmg > 0:
me.hp_gain(math.ceil(dmg/2))
return True
def spell_generic_attack(spell, words, me, t):
me.tohit = me.smod("int")+math.floor(me.skmod("sorcery")/2)
me.dmg = list(spell["dmg"])
me.dmgtype = spell["dmgtype"]
attack_roll(me, t)
return True
def spell_scout(spell, words, k, target):
if len(words) > 2 and words[2][0] in DIR_FULL:
d = words[2][0]
else:
k.p("That is not a valid direction.")
return False
k.p("[n] sees a vision from the "+DIR_FULL[d]+"...")
p = k.get_place()
if isinstance(p, Tribe):
tile = k.world.get_tile(k.x, k.y, k.z)
else:
tile = p
place = tile.get_border(d)
if k.party:
for e in k.world.encounters:
if e.place == place:
e.examine(k)
place.examine(k)
return True
def spell_brace(spell, words, k, target):
if k.z == 0 and not k.dungeon:
k.p("There's no point in casting this on the surface.")
return False
s = k.spell_strength(spell)
p = k.get_place()
if isinstance(p, Tribe):
p = k.world.get_tile(k.x, k.y, k.z)
p.stability += s
k.p("The cavern's stability increases.")
return True
def spell_prospect(spell, words, k, target):
if len(words) < 3:
k.p("Please specify a mineral to prospect for.")
return False
if k.z == 0 and not k.dungeon:
k.p("There is nothing to prospect for on this level.")
return False
mineral = None
for i in item_data:
if i.get("minelevel", 0) > 0 and words[2].lower() in i["name"].lower():
mineral = i["name"]
break
if not mineral:
k.p("No such mineral '"+words[2]+"'.")
return False
ct = k.world.find_tile_feature(10, k, mineral, "resources", gen=True)
if ct:
dir = "none"
if abs(ct.x-k.x) > abs(ct.y-k.y):
if ct.x < k.x:
dir = "to the west."
elif ct.x > k.x:
dir = "to the east."
else:
if ct.y < k.y:
dir = "to the north."
elif ct.y > k.y:
dir = "to the south."
else:
dir = "right under their nose."
k.p("[n] senses a node of "+mineral+" "+dir)
else:
k.p("[n] doesn't sense any "+mineral+" nearby.")
return True
def spell_wellness(spell, words, me, target):
for t in target.traits:
if trait_data[t].get("heal_save_to_cure", False):
me.p(target.display()+" has been cured of their " +
trait_data[t].get("display", t)+" condition!")
target.del_trait(t)
break
return True
def spell_regen(spell, words, me, target):
s = me.spell_strength(spell)
for t in target.traits:
if trait_data[t].get("regenerate", False):
s -= 5
me.p(target.display()+"'s lost flesh is restored!")
target.del_trait(t)
break
target.hp_gain(max(1, s))
return True
def spell_heal(spell, words, me, target):
s = me.spell_strength(spell)
target.hp_gain(s)
return True
def spell_energy(spell, words, me, target):
s = spell["strength"]
if target.has_trait("overworked"):
target.p(
"[n] has already been energized today. Any more and their body might give out...")
return False
else:
target.ap_gain(s)
target.add_trait("overworked")
return True
def spell_transfusion(spell, words, me, target):
blood = False
for i in me.items:
if i.liquid and "Blood" in i.liquid and i.liquid_units > 0:
blood = True
i.liquid_units -= 1
if not blood and me.hp <= 1:
me.p("You have no life to give right now.")
return False
s = min(5, me.hp-1, target.max_hp-target.hp)
if s > 0:
if not blood:
me.hp_tax(s, "Gave their life away", dmgtype="arcane")
target.hp_gain(s)
return True
else:
me.p("That won't have any effect.")
return False
def spell_soulbind(spell, words, me, target):
if len(words) == 2:
if me.bound and me.bound.bound == me:
if me.mp_tax(2):
me.bound.move(me)
me.p("[n] holds out their hand, and green light converges within it forming the shape of a " +
me.bound.display()+". The green light fades, and the item remains in their grasp.")
else:
me.p(
"Nothing happens. [n] must not have a soulbound item in this plane of existence...")
else:
target = find_item(words[2], me)
if target:
if target.stack > 1 or target.type == "corpse":
me.p("Can't soulbind the "+target.display()+".")
elif target.bound:
me.p(target.display()+" is already bound to " +
target.bound.display()+"'s soul.")
elif me.mp_tax(10):
target.bound = me
me.bound = target
me.p("The "+target.display() +
" glows a soft green in [n]'s hands and then fades. [n] feels it as though it is a part of themselves.")
return True
else:
me.p("Target '"+words[2]+"' not found.")
return False
def spell_rupture(spell, words, me, target):
me.tohit = me.smod("int")+math.floor(me.skmod("sorcery")/2)
me.dmg = list(spell["dmg"])
me.dmgtype = spell["dmgtype"]
dmg = attack_roll(me, target)
if dmg > 0:
if isinstance(target, Kobold):
liq = "Kobold Blood"
else:
liq = "Blood"
for i in me.items:
if i.liquid_capacity > i.liquid_units and (i.liquid is None or i.liquid == liq):
target.liquid = liq
target.liquid_units += 1
me.p("The "+target.display()+" fills with "+liq+".")
break
return True
def spell_condensate(spell, words, me, target):
if target.liquid_capacity > target.liquid_units and (target.liquid is None or target.liquid == "Water"):
target.liquid = "Water"
target.liquid_units += 1
me.p("The "+target.display()+" fills with water.")
return True
else:
me.p("Target must be a container that can hold 1 additional unit of water.")
return False
def spell_dislocate(spell, words, me, target):
if me.z > 0 and not me.dungeon:
p = me.world.get_tile(me.x, me.y, me.z)
d = words[2][0].lower()
if d not in list(DIR_FULL.keys()):
me.p("Invalid direction '"+words[2]+"'")
return False
if p.mined[d] >= 0 and p.resources[d]:
res = p.resources[d]
else:
res = "Stone Chunk"
n = 1
for z in item_data:
if z["name"] == res:
n = random.randint(1, z.get("stack", 1))
m = spawn_item(res, me.get_place(), n)
me.p(m.display()+" manifests on the ground.")
p.mined[d] += m.veinsize
if p.mined[d] == 0 and p.resources[d]:
k.p("[n] has revealed a node of "+p.resources[d]+"!")
elif res != "Stone Chunk" and chance(p.mined[d]*5):
k.p("The "+res+" vein is depleted.")
p.resources[d] = None
p.stability -= 5
p.cave_in(me, d)
return True
else:
me.p("There's nothing to dislocate here.")
return False
def spell_enchant(spell, words, me, target):
s = max(1, me.spell_strength(spell))+3
if target.quality < s:
target.quality += 1
else:
me.p("[n]'s Sorcery isn't strong enough to increase the quality any further.")
return False
me.p("[n]'s magic has enhanced the "+target.display() +
" to "+get_q_desc(target.quality)+" quality.")
return True
def spell_hotfix(spell, words, me, target):
if target.durability > 0:
target.durability = target.max_durability
target.dura_loss += 1
me.p("[n] performs a quick and dirty fix on the "+target.display() +
", making it like new - but abusing the item in the process.")
return True
else:
me.p("That cannot be hotfixed.")
return False
def spell_mending(spell, words, me, target):
if target.durability > 0:
s = me.spell_strength(spell)
target.durability += s
if target.durability > target.max_durability:
target.durability = target.max_durability
me.p("[n] fixes the wear and tear in the "+target.display() +
", adding "+str(s)+" points of durability.")
return True
else:
me.p("That cannot be mended.")
return False
def spell_goodberry(spell, words, me, target):
s = max(me.spell_strength(spell), 1)
me.p(str(s)+" Goodberries materialize in the palm of [n]'s hand.")
spawn_item("Goodberry", me, s)
return True
def spell_blade(spell, words, me, target):
me.p("A blade of magical force materializes in [n]'s hands.")
spawn_item("Spectral Blade", me)
return True
def spell_arrow(spell, words, me, target):
me.p("A bow and arrows of magical force materialize in [n]'s hands.")
spawn_item("Spectral Bow", me)
spawn_item("Spectral Arrow", me, 20)
return True
def spell_bloodscry(spell, words, me, target):
target.hp_tax(1, "Blood sampled", me, dmgtype="arcane")
genes = []
for g in target.genome:
text = g+": "
for x in range(2):
if target.genome[g][x]:
text += g[0].capitalize()
else:
text += g[0].lower()
genes.append(text)
target.p("[n] feels a jolt of pain as their blood is extracted and scattered through the air. " +
me.display()+" interprets the patterns it makes...\n[n]'s genomes: "+"; ".join(genes))
return True
def spell_ageup(spell, words, me, target):
if target.age < 6:
target.age_up()
target.age += 1
target.p("[n] rapidly ages. It's disorienting, but they feel more mature now.")
return True
def spell_color(spell, words, me, target):
oldcolor = target.color
if len(words) > 3:
gems = {"red": "Ruby", "yellow": "Topaz", "green": "Emerald",
"blue": "Sapphire", "white": "Opal", "black": "Onyx", "brown": "Quartz"}
c = words[3].lower()
if c in gems:
if target.color != c:
if me.has_item(gems[c], 5):
me.consume_item(gems[c], 5)
me.p("[n] arranges the "+gems[c] +
" gems in a pentagram around "+target.display()+".")
target.color = c
else:
me.p("You need 5 " +
gems[c]+" gems to change the target to that color.")
return False
else:
me.p(target.display()+" is already "+c+".")
return False
else:
me.p("Invalid color '"+words[3]+"'.")
return False
else:
colors = list(ROLENAMES.keys())
if target.color in colors:
colors.remove(target.color)
target.color = choice(colors)
if target.color != "brown":
target.genome[target.color] = [False, False]
if oldcolor != "brown":
if chance(50):
target.genome[oldcolor][0] = True
else:
target.genome[oldcolor][1] = True
else:
for g in target.genome:
if g in COLOR_STAT and g != target.color and (not target.genome[g][0] and not target.genome[g][1]):
if chance(50):
target.genome[g][0] = True
else:
target.genome[g][1] = True
action_queue.append(["delrole", ROLENAMES[oldcolor], target.d_user_id])
action_queue.append(["addrole", ROLENAMES[target.color], target.d_user_id])
target.p("[n]'s scales change color before their eyes.")
return True
def spell_sexchange(spell, words, me, target):
if len(target.eggs) == 0:
if target.has_trait("nonbinary"):
me.p("This won't have any effect; " +
target.display()+" is non-binary.")
return False
else:
if target.male:
target.male = False
else:
target.male = True
target.p("[n] feels a bit strange...")
return True
else:
me.p("Can't cast this on a pregnant kobold.")
return False
def spell_message(spell, words, me, target):
if len(words) < 4:
me.p("Please enter a message.")
return False
if len(words[3]) > 250:
me.p("Your message must be 250 characters or less.")
return False
target = find_kobold(words[2], w=me.world)
if target:
me.p("[n] sends a message to "+target.display()+": \""+words[3]+"\"")
if target.nick:
target.p("<@!"+str(target.d_user_id) +
"> receives a telepathic message from "+me.display()+": \""+words[3]+"\"")
else:
target.p("[n] receives a telepathic message from " +
me.display()+": \""+words[3]+"\"")
return True
else:
me.p("Can't find a kobold in the world by that name.")
return False
def spell_recall(spell, words, me, target):
if not me.tribe:
me.p("You do not have a home den to recall to.")
return False
elif me.get_place() == me.tribe:
me.p("You are already in your den.")
return False
cost = len(me.party.members)
if me.mp_tax(cost):