-
Notifications
You must be signed in to change notification settings - Fork 4
/
monster.py
743 lines (606 loc) · 31.8 KB
/
monster.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
import random
from Status import StatusDescriptionBar
from actor import DoNothingActor
from animation import animate_flight
from attacker import Dodger, DamageTypes, ArmorChecker, ResistanceChecker, FireImmunity, PoisonImmunity, PushBackAttacker, UnarmedAttacker, ThrowRockAttacker
from cloud import new_fire_cloud, new_dust_cloud
from compositecommon import EntityShareTileEffect
from compositecore import Composite, Leaf, Component
import constants
import direction
from dungeonfeature import new_spider_web
from dungeonmask import DungeonMask, Path
from entityeffect import EffectQueue, AddSpoofChild, EffectStackID, UndodgeableDamagAndBlockSameEffect, HealthRegain
import geometry
from graphic import CharPrinter, GraphicChar
from health import Health, HealthModifier, BleedWhenDamaged
from inventory import Inventory
import messenger
from missileaction import MonsterThrowStoneAction, MonsterThrowRockAction, SpiritMissile, MonsterHealTargetEntityEffect, MonsterTripTargetEffect, \
ParalyzeOnStare
from monsteractor import ChasePlayerActor, MonsterActorState, HuntPlayerIfHurtMe, KeepPlayerAtDistanceActor, MonsterWeightedStepAction, \
StartHuntOnAttack
from monsterspells import SummonEntityMonsterAction
from mover import Mover, Stepper, SlimeCanShareTileEntityMover, CautiousStepper, TolerateDamage
from ondeath import PrintDeathMessageOnDeath, LeaveCorpseOnDeath, RemoveEntityOnDeath, LeaveCorpseTurnIntoEntityOnDeath
from position import Position, DungeonLevel
import rng
from stats import Flag, DataPoint, DataTypes, Factions, IntelligenceLevel, Immunities
from stats import GamePieceTypes
from statusflags import StatusFlags
from text import Description, EntityMessages
from util import entity_skip_turn, entity_skip_step
from vision import Vision, AwarenessChecker
import colors
from equipment import Equipment
import gametime
import icon
from equipmenteffect import PoisonAttackEffect
def set_monster_components(monster, game_state):
monster.set_child(DataPoint(DataTypes.ENERGY, -gametime.single_turn))
monster.set_child(DataPoint(DataTypes.GAME_PIECE_TYPE, GamePieceTypes.ENTITY))
#monster.set_child(DataPoint(DataTypes.CRIT_CHANCE, 0.15))
monster.set_child(DataPoint(DataTypes.UNARMED_CRIT_CHANCE, 0.15))
monster.set_child(DataPoint(DataTypes.MOVEMENT_SPEED, gametime.single_turn))
monster.set_child(DataPoint(DataTypes.MELEE_SPEED, gametime.single_turn))
monster.set_child(DataPoint(DataTypes.THROW_SPEED, gametime.single_turn))
monster.set_child(DataPoint(DataTypes.SHOOT_SPEED, gametime.single_turn))
monster.set_child(DataPoint(DataTypes.SIGHT_RADIUS, constants.COMMON_SIGHT_RADIUS))
monster.set_child(DataPoint(DataTypes.FACTION, Factions.MONSTER))
monster.set_child(DataPoint(DataTypes.GAME_STATE, game_state))
monster.set_child(DataPoint(DataTypes.INTELLIGENCE, IntelligenceLevel.NORMAL))
monster.set_child(DataPoint(DataTypes.SKIP_ACTION_CHANCE, IntelligenceLevel.NORMAL))
monster.set_child(Position())
monster.set_child(CharPrinter())
monster.set_child(DungeonLevel())
monster.set_child(StatusDescriptionBar())
monster.set_child(Mover())
monster.set_child(CautiousStepper())
monster.set_child(HealthModifier())
monster.set_child(Dodger())
monster.set_child(ArmorChecker())
monster.set_child(ResistanceChecker())
monster.set_child(AwarenessChecker())
monster.set_child(DungeonMask())
monster.set_child(Vision())
monster.set_child(Path())
monster.set_child(ChasePlayerActor())
monster.set_child(MonsterActorState())
monster.set_child(HuntPlayerIfHurtMe())
monster.set_child(StartHuntOnAttack())
monster.set_child(Equipment())
monster.set_child(Inventory())
monster.set_child(EffectQueue())
monster.set_child(UnarmedAttacker())
monster.set_child(RemoveEntityOnDeath())
monster.set_child(PrintDeathMessageOnDeath())
monster.set_child(MonsterWeightedStepAction(100))
monster.set_child(StatusFlags([]))
def set_humanoid_components(composite):
composite.set_child(BleedWhenDamaged())
composite.set_child(StatusFlags([StatusFlags.CAN_OPEN_DOORS,
StatusFlags.IS_ALIVE, StatusFlags.HAS_HEART]))
composite.set_child(LeaveCorpseOnDeath())
def set_skeleton_components(composite):
composite.set_child(StatusFlags([StatusFlags.CAN_OPEN_DOORS]))
composite.set_child(PoisonImmunity())
composite.set_child(TolerateDamage(DamageTypes.POISON))
def new_training_dummy(gamestate):
monster = Composite()
set_monster_components(monster, gamestate)
monster.set_child(Description("Training Dummy", "A Man hybrid, it looks hostile."))
monster.set_child(EntityMessages("The monster looks at you.", "The monster falls dead."))
monster.set_child(GraphicChar(None, colors.CHAMPAGNE, icon.STATUE))
monster.set_child(Health(80))
monster.set_child(DataPoint(DataTypes.STRENGTH, 3))
monster.set_child(DataPoint(DataTypes.EVASION, 8))
monster.set_child(DataPoint(DataTypes.ACCURACY, 13))
monster.set_child(DataPoint(DataTypes.ARMOR, 100))
monster.set_child(DataPoint(DataTypes.AWARENESS, 5))
monster.set_child(DataPoint(DataTypes.MINIMUM_DEPTH, 99999))
monster.set_child(DoNothingActor())
return monster
def new_ratman(gamestate):
ratman = Composite()
set_monster_components(ratman, gamestate)
set_humanoid_components(ratman)
ratman.set_child(Description("Ratman", "A Rat/Man hybrid, it looks hostile."))
ratman.set_child(EntityMessages("The ratman looks at you.", "The ratman falls dead."))
ratman.set_child(GraphicChar(None, colors.ORANGE, icon.RATMAN))
ratman.set_child(Health(10))
ratman.set_child(DataPoint(DataTypes.STRENGTH, 3))
ratman.set_child(DataPoint(DataTypes.EVASION, 10))
ratman.set_child(DataPoint(DataTypes.ACCURACY, 6))
ratman.set_child(DataPoint(DataTypes.ARMOR, 4))
ratman.set_child(DataPoint(DataTypes.AWARENESS, 5))
ratman.set_child(MonsterThrowStoneAction(20))
ratman.set_child(ThrowRockAttacker())
ratman.set_child(DataPoint(DataTypes.MINIMUM_DEPTH, 1))
return ratman
def new_ratman_mystic(gamestate):
ratman = Composite()
set_monster_components(ratman, gamestate)
set_humanoid_components(ratman)
ratman.set_child(Description("Ratman Mystic", "A Rat/Man hybrid, it looks hostile."))
ratman.set_child(EntityMessages("The ratman looks at you.", "The ratman falls dead."))
ratman.set_child(GraphicChar(None, colors.PURPLE, icon.RATMAN))
ratman.set_child(Health(7))
ratman.set_child(DataPoint(DataTypes.STRENGTH, 2))
ratman.set_child(DataPoint(DataTypes.EVASION, 10))
ratman.set_child(DataPoint(DataTypes.ACCURACY, 8))
ratman.set_child(DataPoint(DataTypes.ARMOR, 3))
ratman.set_child(DataPoint(DataTypes.AWARENESS, 6))
ratman.set_child(SpiritMissile(15))
ratman.set_child(SummonEntityMonsterAction(new_worm, 5, 20))
ratman.set_child(DataPoint(DataTypes.MOVEMENT_SPEED, gametime.single_turn + gametime.quarter_turn))
ratman.set_child(KeepPlayerAtDistanceActor(4))
ratman.set_child(DataPoint(DataTypes.MINIMUM_DEPTH, 3))
return ratman
def new_worm(gamestate):
worm = Composite()
set_monster_components(worm, gamestate)
worm.set_child(Description("Worm", "It's a giant earth worm."))
worm.set_child(EntityMessages("The worm wiggles at you.", "The worm stops moving."))
worm.set_child(GraphicChar(None, colors.PINK, icon.BLOOD7 + 4))
worm.set_child(Health(4))
worm.set_child(DataPoint(DataTypes.STRENGTH, 3))
worm.set_child(DataPoint(DataTypes.EVASION, 6))
worm.set_child(DataPoint(DataTypes.ACCURACY, 5))
worm.set_child(DataPoint(DataTypes.ARMOR, 2))
worm.set_child(DataPoint(DataTypes.AWARENESS, 3))
worm.set_child(DataPoint(DataTypes.MOVEMENT_SPEED, gametime.one_and_half_turn))
return worm
def new_skeleton(gamestate):
skeleton = Composite()
set_monster_components(skeleton, gamestate)
set_skeleton_components(skeleton)
skeleton.set_child(LeaveCorpseTurnIntoEntityOnDeath(new_skeleton, 0.5))
skeleton.set_child(Description("Skeleton", "An undead skeleton it looks hostile."))
skeleton.set_child(EntityMessages("The skeleton turns to you.", "The skeleton falls in a pile of bones."))
skeleton.set_child(GraphicChar(None, colors.WHITE, icon.SKELETON_WARRIOR))
skeleton.set_child(Health(10))
skeleton.set_child(DataPoint(DataTypes.STRENGTH, 6))
skeleton.set_child(DataPoint(DataTypes.EVASION, 11))
skeleton.set_child(DataPoint(DataTypes.ACCURACY, 10))
skeleton.set_child(DataPoint(DataTypes.ARMOR, 12))
skeleton.set_child(DataPoint(DataTypes.AWARENESS, 4))
skeleton.set_child(DataPoint(DataTypes.MINIMUM_DEPTH, 4))
return skeleton
def set_beast_components(composite):
composite.set_child(StatusFlags([StatusFlags.IS_ALIVE]))
composite.set_child(DataPoint(DataTypes.INTELLIGENCE, IntelligenceLevel.ANIMAL))
composite.set_child(LeaveCorpseOnDeath())
composite.set_child(BleedWhenDamaged())
def set_insect_components(composite):
composite.set_child(StatusFlags([StatusFlags.IS_ALIVE]))
composite.set_child(DataPoint(DataTypes.INTELLIGENCE, IntelligenceLevel.ANIMAL))
def new_spider(gamestate):
spider = Composite()
set_monster_components(spider, gamestate)
set_insect_components(spider)
spider.set_child(Description("Spider", "A giant spider, its attacks are poisonous."))
spider.set_child(EntityMessages("The spider looks at you.", "The spider stops moving."))
spider.set_child(GraphicChar(None, colors.CHAMPAGNE_D, icon.SPIDER))
spider.set_child(Health(9))
spider.set_child(DataPoint(DataTypes.STRENGTH, 1))
spider.set_child(DataPoint(DataTypes.EVASION, 8))
spider.set_child(DataPoint(DataTypes.ACCURACY, 5))
spider.set_child(DataPoint(DataTypes.ARMOR, 7))
spider.set_child(DataPoint(DataTypes.AWARENESS, 5))
spider.set_child(MakeSpiderWebs())
spider.set_child(Flag(Immunities.SPIDER_WEB))
#spider.set_child(UnArmedHitTargetEntityEffectFactory(PoisonEntityEffectFactory(spider, random.randrange(4, 8), 2, 20)))
spider.set_child(PoisonAttackEffect(1.0))
spider.set_child(DataPoint(DataTypes.MINIMUM_DEPTH, 3))
return spider
def new_dust_demon(gamestate):
demon = Composite()
set_monster_components(demon, gamestate)
set_humanoid_components(demon)
demon.set_child(Description("Dust Demon", "The demon constantly creates dust clouds."))
demon.set_child(EntityMessages("The dust demon notices you.", "The demon falls to the ground."))
demon.set_child(GraphicChar(None, colors.GRAY, icon.DEMON))
demon.set_child(Health(12))
demon.set_child(DataPoint(DataTypes.STRENGTH, 5))
demon.set_child(DataPoint(DataTypes.EVASION, 8))
demon.set_child(DataPoint(DataTypes.ACCURACY, 10))
demon.set_child(DataPoint(DataTypes.ARMOR, 8))
demon.set_child(DataPoint(DataTypes.AWARENESS, 4))
demon.set_child(MakeDustClouds())
demon.set_child(DataPoint(DataTypes.MINIMUM_DEPTH, 4))
return demon
def new_armored_beetle(gamestate):
beetle = Composite()
set_insect_components(beetle)
set_monster_components(beetle, gamestate)
beetle.set_child(
Description("Armored Beetle", "A giant armored beetle, it looks like it wouldn't budge for anything."))
beetle.set_child(EntityMessages("The armored beetle notices you.", "The armored beetle is dead."))
beetle.set_child(GraphicChar(None, colors.PURPLE, icon.BEETLE))
beetle.set_child(Health(17))
beetle.set_child(DataPoint(DataTypes.STRENGTH, 2))
beetle.set_child(DataPoint(DataTypes.EVASION, 5))
beetle.set_child(DataPoint(DataTypes.ACCURACY, 12))
beetle.set_child(DataPoint(DataTypes.ARMOR, 15))
beetle.set_child(DataPoint(DataTypes.AWARENESS, 2))
beetle.set_child(DataPoint(DataTypes.MOVEMENT_SPEED, gametime.single_turn + gametime.one_third_turn))
beetle.set_child(DataPoint(DataTypes.MINIMUM_DEPTH, 4))
beetle.set_child(PushBackAttacker())
return beetle
def set_insect_components(composite):
composite.set_child(StatusFlags([StatusFlags.IS_ALIVE]))
composite.set_child(DataPoint(DataTypes.INTELLIGENCE, IntelligenceLevel.ANIMAL))
def new_salamander(gamestate):
salamander = Composite()
set_monster_components(salamander, gamestate)
set_beast_components(salamander)
salamander.set_child(Description("Salamander", "A salamander, it can start small fires."))
salamander.set_child(EntityMessages("The salamander looks at you.", "The salamander stops moving."))
salamander.set_child(GraphicChar(None, colors.RED, icon.SALAMANDER))
salamander.set_child(Health(20))
salamander.set_child(DataPoint(DataTypes.STRENGTH, 3))
salamander.set_child(DataPoint(DataTypes.EVASION, 8))
salamander.set_child(DataPoint(DataTypes.ACCURACY, 10))
salamander.set_child(DataPoint(DataTypes.ARMOR, 4))
salamander.set_child(DataPoint(DataTypes.AWARENESS, 5))
salamander.set_child(NaturalHealthRegain())
salamander.set_child(PutAdjacentTilesOnFire())
salamander.set_child(FireImmunity())
salamander.set_child(TolerateDamage(DamageTypes.FIRE))
salamander.set_child(DataPoint(DataTypes.MINIMUM_DEPTH, 4))
return salamander
def new_cyclops(game_state):
cyclops = Composite()
set_monster_components(cyclops, game_state)
set_humanoid_components(cyclops)
cyclops.set_child(EntityMessages("The eye of the cyclops watches at you.",
"The cyclops is dead."))
cyclops.set_child(Description("Cyclops",
"A Giant with a single disgusting eye, it's looking for prey."))
cyclops.set_child(GraphicChar(None, colors.LIGHT_ORANGE, icon.CYCLOPS))
cyclops.set_child(Health(45))
cyclops.set_child(DataPoint(DataTypes.MOVEMENT_SPEED, gametime.single_turn))
cyclops.set_child(DataPoint(DataTypes.THROW_SPEED, gametime.double_turn))
cyclops.set_child(DataPoint(DataTypes.STRENGTH, 21))
cyclops.set_child(DataPoint(DataTypes.EVASION, 7))
cyclops.set_child(DataPoint(DataTypes.ACCURACY, 9))
cyclops.set_child(DataPoint(DataTypes.ARMOR, 6))
cyclops.set_child(DataPoint(DataTypes.AWARENESS, 3))
cyclops.set_child(DataPoint(DataTypes.MOVEMENT_SPEED, gametime.one_and_half_turn))
cyclops.set_child(DataPoint(DataTypes.THROW_SPEED, gametime.double_turn))
cyclops.set_child(DataPoint(DataTypes.MELEE_DAMAGE_MULTIPLIER, 0.5))
cyclops.set_child(ThrowRockAttacker())
cyclops.set_child(MonsterThrowRockAction(900))
cyclops.set_child(DataPoint(DataTypes.MINIMUM_DEPTH, 5))
return cyclops
def new_jericho(gamestate):
jericho = new_ratman(gamestate)
jericho.description.name = "Jericho"
jericho.entity_messages.death_message = "Jericho the quick is no more."
jericho.set_child(Flag("is_named"))
jericho.graphic_char.color_fg = colors.YELLOW
jericho.actor.energy_recovery = gametime.double_energy_gain
return jericho
def set_ghost_components(composite):
composite.set_child(StatusFlags([StatusFlags.CAN_OPEN_DOORS, StatusFlags.FLYING]))
composite.set_child(PoisonImmunity())
composite.set_child(TolerateDamage(DamageTypes.POISON))
composite.set_child(TolerateDamage(DamageTypes.BLEED))
def new_ghost(gamestate):
ghost = Composite()
set_monster_components(ghost, gamestate)
set_ghost_components(ghost)
ghost.set_child(EntityMessages("The ghost sees you.", "The ghost fades away."))
ghost.set_child(Description("Ghost", "A spirit of a hunted creature."))
ghost.set_child(GraphicChar(None, colors.LIGHT_BLUE, icon.GHOST))
ghost.set_child(Health(1))
ghost.set_child(DataPoint(DataTypes.STRENGTH, 2))
ghost.set_child(DataPoint(DataTypes.EVASION, 14))
ghost.set_child(DataPoint(DataTypes.ACCURACY, 9))
ghost.set_child(DataPoint(DataTypes.ARMOR, 0))
ghost.set_child(DataPoint(DataTypes.MOVEMENT_SPEED, gametime.single_turn + gametime.one_third_turn))
ghost.set_child(DataPoint(DataTypes.AWARENESS, 8))
ghost.set_child(KeepPlayerAtDistanceActor(4))
ghost.set_child(SpiritMissile(150))
ghost.set_child(AddGhostReviveToSeenEntities())
ghost.set_child(DataPoint(DataTypes.MINIMUM_DEPTH, 2))
return ghost
def new_pixie(gamestate):
pixie = Composite()
set_monster_components(pixie, gamestate)
set_humanoid_components(pixie)
pixie.set_child(StatusFlags([StatusFlags.CAN_OPEN_DOORS, StatusFlags.FLYING,
StatusFlags.IS_ALIVE, StatusFlags.HAS_HEART]))
pixie.set_child(EntityMessages("The pixie sees you.", "The pixie falls."))
pixie.set_child(Description("Pixie", "A small humanoid with insect wings."))
pixie.set_child(GraphicChar(None, colors.PINK, icon.PIXIE))
pixie.set_child(Health(12))
pixie.set_child(DataPoint(DataTypes.STRENGTH, 2))
pixie.set_child(DataPoint(DataTypes.EVASION, 12))
pixie.set_child(DataPoint(DataTypes.ACCURACY, 10))
pixie.set_child(DataPoint(DataTypes.ARMOR, 2))
pixie.set_child(DataPoint(DataTypes.MOVEMENT_SPEED, gametime.two_thirds_turn))
pixie.set_child(DataPoint(DataTypes.AWARENESS, 8))
pixie.set_child(KeepPlayerAtDistanceActor(4))
pixie.set_child(MonsterHealTargetEntityEffect(50))
pixie.set_child(MonsterTripTargetEffect(50))
pixie.set_child(DataPoint(DataTypes.MINIMUM_DEPTH, 6))
return pixie
def set_slime_components(slime):
slime.set_child(StatusFlags([StatusFlags.IS_ALIVE]))
slime.set_child(DataPoint(DataTypes.INTELLIGENCE, IntelligenceLevel.PLANT))
slime.set_child(DataPoint(DataTypes.MOVEMENT_SPEED, gametime.single_turn + gametime.one_third_turn))
slime.set_child(Flag("is_slime"))
slime.remove_component_of_type("melee_attacker")
def new_slime(game_state):
slime = Composite()
set_monster_components(slime, game_state)
set_slime_components(slime)
slime.set_child(SlimeCanShareTileEntityMover())
slime.set_child(DissolveEntitySlimeShareTileEffect())
slime.set_child(EntityMessages("The slime seems to wobble with happiness.", "The slime melts away."))
slime.set_child(Description("Slime",
"Slime, slime, slime. Ugh, I hate Slimes." "The slime seem to sense at you..."))
slime.set_child(GraphicChar(None, colors.GREEN, icon.SLIME))
slime.set_child(Health(35))
slime.set_child(DataPoint(DataTypes.STRENGTH, 2))
slime.set_child(DataPoint(DataTypes.EVASION, 6))
slime.set_child(DataPoint(DataTypes.ACCURACY, 12))
slime.set_child(DataPoint(DataTypes.ARMOR, 3))
slime.set_child(DataPoint(DataTypes.AWARENESS, 5))
slime.set_child(DataPoint(DataTypes.MINIMUM_DEPTH, 3))
slime.set_child(DataPoint(DataTypes.CLONE_FUNCTION, new_slime))
return slime
def new_dark_slime(game_state):
slime = Composite()
set_monster_components(slime, game_state)
set_slime_components(slime)
slime.set_child(SlimeCanShareTileEntityMover())
slime.set_child(DissolveEntitySlimeShareTileEffect())
slime.set_child(BlockVisionShareTileEffect())
slime.set_child(EntityMessages("The dark slime seems to wobble with happiness.", "The dark slime melts away."))
slime.set_child(Description("Dark Slime",
"Slime, slime, slime. Ugh, I hate Slimes." "The dark slime seem to sense at you..."))
slime.set_child(GraphicChar(None, colors.BLUE, icon.SLIME))
slime.set_child(Health(45))
slime.set_child(DataPoint(DataTypes.STRENGTH, 2))
slime.set_child(DataPoint(DataTypes.EVASION, 7))
slime.set_child(DataPoint(DataTypes.ACCURACY, 12))
slime.set_child(DataPoint(DataTypes.ARMOR, 3))
slime.set_child(DataPoint(DataTypes.AWARENESS, 6))
slime.set_child(DataPoint(DataTypes.MINIMUM_DEPTH, 3))
slime.set_child(DataPoint(DataTypes.CLONE_FUNCTION, new_dark_slime))
return slime
def new_floating_eye(game_state):
c = Composite()
set_monster_components(c, game_state)
c.set_child(StatusFlags([StatusFlags.IS_ALIVE, StatusFlags.FLYING]))
c.set_child(DataPoint(DataTypes.INTELLIGENCE, IntelligenceLevel.PLANT))
c.set_child(EntityMessages("The eye looks intently.", "The eye falls to the ground."))
c.set_child(Description("Floating Eye",
"A giant eye floating in mid-air How is this even possible?"
"The eye stairs at you..."))
c.set_child(GraphicChar(None, colors.WHITE, icon.EYE))
c.set_child(Health(20))
c.set_child(DataPoint(DataTypes.STRENGTH, 4))
c.set_child(DataPoint(DataTypes.EVASION, 8))
c.set_child(DataPoint(DataTypes.ACCURACY, 12))
c.set_child(DataPoint(DataTypes.ARMOR, 0))
c.set_child(DataPoint(DataTypes.MOVEMENT_SPEED, gametime.one_and_half_turn))
c.set_child(DataPoint(DataTypes.AWARENESS, 10))
c.set_child(ParalyzeOnStare(0, c.sight_radius.value, 100))
c.set_child(KeepPlayerAtDistanceActor(3))
return c
def new_giant_amoeba(game_state):
amoeba = Composite()
set_monster_components(amoeba, game_state)
amoeba.set_child(StatusFlags([StatusFlags.IS_ALIVE]))
amoeba.set_child(DataPoint(DataTypes.INTELLIGENCE, IntelligenceLevel.PLANT))
amoeba.set_child(EntityMessages("The amoeba seems to wobble with happiness.", "The amoeba melts away."))
amoeba.set_child(Description("Giant Amoeba",
"A giant amoeba... How is this even possible?"
"The amoeba seems to wobble in your direction..."))
amoeba.set_child(GraphicChar(None, colors.LIGHT_GREEN, "0"))
amoeba.set_child(Health(20))
amoeba.set_child(DataPoint(DataTypes.STRENGTH, 4))
amoeba.set_child(DataPoint(DataTypes.EVASION, 5))
amoeba.set_child(DataPoint(DataTypes.ACCURACY, 12))
amoeba.set_child(DataPoint(DataTypes.ARMOR, 4))
amoeba.set_child(DataPoint(DataTypes.MOVEMENT_SPEED, gametime.single_turn + gametime.one_third_turn))
amoeba.set_child(DataPoint(DataTypes.AWARENESS, 5))
amoeba.set_child(DataPoint(DataTypes.CLONE_FUNCTION, new_giant_amoeba))
amoeba.set_child(NaturalHealthRegain())
amoeba.set_child(SplitAtFullHealth())
return amoeba
class MakeDustClouds(Leaf):
def __init__(self):
super(MakeDustClouds, self).__init__()
self.component_type = "make_dust_clouds"
self.time_interval = gametime.double_turn
self.time_to_next_attempt = self.time_interval
def before_tick(self, time):
self.time_to_next_attempt -= time
if self.time_to_next_attempt > 0:
return
self._spawn_dust_cloud()
self.time_to_next_attempt = self.time_interval
def _spawn_dust_cloud(self):
my_position = self.parent.position.value
dungeon_level = self.parent.dungeon_level.value
dust = new_dust_cloud(self.parent.game_state.value, 12)
dust.mover.replace_move(my_position, dungeon_level)
class MakeSpiderWebs(Leaf):
def __init__(self):
super(MakeSpiderWebs, self).__init__()
self.component_type = "make_spider_webs"
self.web_chance_per_turn = 0.6
self.time_interval = gametime.single_turn
self.time_to_next_attempt = self.time_interval
def after_tick(self, time):
self.time_to_next_attempt -= time
if self.time_to_next_attempt > 0:
return
my_position = self.parent.position.value
chance = self.web_chance_per_turn / float(len(direction.DIRECTIONS))
dungeon_level = self.parent.dungeon_level.value
for d in direction.DIRECTIONS:
point = geometry.add_2d(my_position, d)
if (random.random() < chance and dungeon_level and
len(dungeon_level.get_tile_or_unknown(point).get_entities()) == 0 and
self.position_can_have_web(dungeon_level, point)):
web = new_spider_web()
web.mover.try_move(point, dungeon_level)
self.time_to_next_attempt = self.time_interval
def position_can_have_web(self, dungeon_level, position):
surrounding_tiles = [dungeon_level.get_tile_or_unknown(geometry.add_2d(position, d))
for d in direction.DIRECTIONS]
surrounding_solid_terrains = len([tile for tile in surrounding_tiles
if tile.get_terrain().has("is_solid")])
surrounding_dungeon_features = len([tile for tile in surrounding_tiles
if tile.get_dungeon_feature()])
return surrounding_dungeon_features + surrounding_solid_terrains > 2
class PutAdjacentTilesOnFire(Leaf):
def __init__(self):
super(PutAdjacentTilesOnFire, self).__init__()
self.component_type = "put_adjacent_tiles_on_fire"
self.fire_chance_per_turn = 0.5
self.time_interval = gametime.single_turn
self.time_to_next_burn_attempt = self.time_interval
def after_tick(self, time):
self.time_to_next_burn_attempt -= time
if self.time_to_next_burn_attempt > 0:
return
my_position = self.parent.position.value
chance = self.fire_chance_per_turn / float(len(direction.DIRECTIONS))
for d in direction.DIRECTIONS:
point = geometry.add_2d(my_position, d)
dungeon_level = self.parent.dungeon_level.value
if not dungeon_level:
break
fire = new_fire_cloud(self.parent.game_state.value, random.randrange(6, 10))
if (random.random() < chance and len(dungeon_level.get_tile_or_unknown(point).get_entities()) == 0 and
fire.mover.can_move(point, dungeon_level)):
animate_flight(self.parent.game_state.value, [my_position, point],
fire.graphic_char.icon, fire.graphic_char.color_fg)
fire.mover.try_move(point, dungeon_level)
self.time_to_next_burn_attempt = self.time_interval
class NaturalHealthRegain(Leaf):
def __init__(self):
super(NaturalHealthRegain, self).__init__()
self.component_type = "natural_health_regain"
def before_tick(self, time):
health_regain = HealthRegain(self.parent, 3, 4, float("inf"), meld_id="natural_health_regain")
self.parent.effect_queue.add(health_regain)
self.parent.remove_component(self)
class AddGhostReviveToSeenEntities(Leaf):
"""
Revive other living creatures as ghosts.
"""
def __init__(self):
super(AddGhostReviveToSeenEntities, self).__init__()
self.component_type = "add_ghost_revive_to_seen_entities"
def before_tick(self, time):
seen_entities = self.parent.vision.get_seen_entities()
for entity in seen_entities:
if (entity.status_flags.has_status(StatusFlags.IS_ALIVE) and
entity.intelligence.value >= IntelligenceLevel.NORMAL and
not entity.has("is_player")):
effect = ReviveAsGhostOnDeath(self.parent)
entity.effect_queue.add(AddSpoofChild(self.parent, effect, 1))
class ReviveAsGhostOnDeath(Leaf):
"""
Will remove the parent from the dungeon when parent Entity dies.
"""
def __init__(self, source_entity):
super(ReviveAsGhostOnDeath, self).__init__()
self.component_type = "revive_as_ghost_on_death"
self.source_entity = source_entity
def on_tick(self, time):
if self.parent.health.is_dead():
ghost = new_ghost(self.parent.game_state.value)
ghost.mover.replace_move(self.parent.position.value, self.parent.dungeon_level.value)
self._animate(ghost)
self._send_revive_message()
entity_skip_step(ghost, ghost)
def _animate(self, ghost):
ghost.char_printer.append_default_graphic_frame()
ghost.char_printer.append_graphic_char_temporary_frames([self.parent.graphic_char])
def _send_revive_message(self):
messenger.msg.send_visual_message(
messenger.HAUNT_MESSAGE % {"source_entity": self.source_entity.description.name,
"target_entity": self.parent.description.name},
self.parent.position.value)
class SplitAtFullHealth(Component):
def __init__(self):
super(SplitAtFullHealth, self).__init__()
self.component_type = "split_at_full_health"
def after_tick(self, time):
if self.parent.health.hp.is_full():
new_entity = self.parent.clone_function.value(self.parent.game_state.value)
if new_entity.mover.try_move_roll_over(self.parent.position.value, self.parent.dungeon_level.value):
self.parent.health.hp.decrease(self.parent.health.hp.max_value / 2)
new_entity.health.hp.decrease(self.parent.health.hp.max_value / 2)
class DissolveEntitySlimeShareTileEffect(EntityShareTileEffect):
def __init__(self):
super(DissolveEntitySlimeShareTileEffect, self).__init__()
self.component_type = "dissolve_entity_slime_share_tile_effect"
def effect(self, **kwargs):
target_entity = kwargs["target_entity"]
source_entity = kwargs["source_entity"]
strength = source_entity.strength.value
damage = rng.random_variance(strength, 1)
if not target_entity.has("effect_queue"):
return
if len(target_entity.get_children_with_tag("entity_share_tile_effect")) > 0:
#Merge with other slime.
return
#self.parent.health_modifier.increases_max_hp(target_entity.health.hp.max_value / 2)
#self.parent.health_modifier.heal(target_entity.health.hp.value / 2)
#target_entity.health_modifier.kill(self.parent)
else:
#Damage other creature.
dissolve_effect = UndodgeableDamagAndBlockSameEffect(source_entity, damage, [DamageTypes.ACID],
messenger.DISSOLVE_MESSAGE,
meld_id=EffectStackID.SLIME_DISSOLVE,
time_to_live=gametime.single_turn)
target_entity.effect_queue.add(dissolve_effect)
stuck_in_slime_step_spoof = StuckInSlimeStepperSpoof(source_entity)
add_spoof_effect = AddSpoofChild(source_entity, stuck_in_slime_step_spoof, time_to_live=1)
target_entity.effect_queue.add(add_spoof_effect)
class StuckInSlimeStepperSpoof(Stepper):
def __init__(self, slime):
super(StuckInSlimeStepperSpoof, self).__init__()
self.component_type = "stepper"
self._slime = slime
def try_move_or_bump(self, position):
my_strength = self.parent.strength.value
slime_strength = self._slime.strength.value
if self.has_sibling("melee_attacker"):
self.parent.melee_attacker.hit(self._slime)
if rng.stat_check(my_strength, slime_strength + 8):
self._split_slime(geometry.sub_2d(self._slime.position.value, position))
entity_skip_turn(self.parent, self._slime)
entity_skip_step(self.parent, self._slime)
return self.next.try_move_or_bump(position)
return self.parent.movement_speed.value
def _split_slime(self, split_direction):
if self._slime.health.hp.value < 3:
return
new_slime = self._slime.clone_function.value(self._slime.game_state.value)
if new_slime.mover.try_move_roll_over(geometry.add_2d(self._slime.position.value, split_direction),
self._slime.dungeon_level.value):
health = self._slime.health.hp.value / 2
self._slime.health.hp.value = health
new_slime.health.hp.value = health
new_slime.monster_actor_state.value = MonsterActorState.HUNTING
class BlockVisionShareTileEffect(EntityShareTileEffect):
def __init__(self):
super(BlockVisionShareTileEffect, self).__init__()
self.component_type = "block_vision_share_tile_effect"
def effect(self, **kwargs):
target_entity = kwargs["target_entity"]
source_entity = kwargs["source_entity"]
if target_entity.has("effect_queue"):
sight_radius_spoof = DataPoint(DataTypes.SIGHT_RADIUS, 1)
darkness_effect = AddSpoofChild(source_entity, sight_radius_spoof, time_to_live=1)
target_entity.effect_queue.add(darkness_effect)