-
Notifications
You must be signed in to change notification settings - Fork 0
/
item.go
1305 lines (1197 loc) · 30.2 KB
/
item.go
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
/*
* item.go
* Rescape
*
* Created by Chad Pierce on 1/16/2022.
* Copyright 2022. All rights reserved.
*
* This file is part of Rescape.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package main
import (
"fmt"
"github.com/gdamore/tcell/v2"
)
type itemCategory int
const (
Potion itemCategory = iota
Scroll
Book
Weapon
Armor
Amulet
Ring
Tool
Wand
Ammo
Shield
Buckler
NoCategory
AllItems
)
type itemSlot int
const (
NoSlot itemSlot = iota
OneHand
TwoHand
OneHandRanged
TwoHandRanged
Head
Chest
Hands
Feet
Back
Neck
Finger
)
const (
gPotion = '!'
gScroll = '?'
gBook = '+'
gWeapon = ')'
gArmor = '['
gAmulet = '"'
gRing = '='
gTool = '('
gWand = '/'
gAmmo = ')'
gNoGlyph = 'X'
)
type itemName int
const (
VorpalBlade itemName = iota
BattleAxe
WeapSwordShort
WeapFlailDire
WeapDart
WeapShortBow
WeapCrossbow
AmmoBolt
AmmoArrow
InfiniteJest
BookRage
RingStrength
PotHeal
PotConf
PotMega
ArmorChestLeather
ArmorBootsLeather
ArmorBootsIron
ScrollBlink
ShieldSmall
ShieldLarge
ShieldBuckler
BlankItem
WeapDexMod
)
type itemBrand int
const (
NoBrand itemBrand = iota
//Chopping
Flaming
Freezing
Electrocution
Venom
Vorpal //extra dmg (if head pop it off?)
Speed
//Antimagic //? maybe
)
type itemDmgRoll int
const (
R1d2 itemDmgRoll = iota
R1d4
R2d4
R3d4
R4d4
R1d6
R2d6
R3d6
R4d6
R1d8
R2d8
R3d8
R4d8
R1d10
R2d10
R3d10
R4d10
R1d12
R2d12
R3d12
R4d12
R1d20
R2d20
R1d100
NoDamage
)
type BUCStatus int
const (
Uncursed BUCStatus = iota
Blessed
Cursed
)
func (g *Game) discovery(i *Item) {
for _, d := range g.disc {
if d.name == i.pname { i.name = i.pname}
}
}
func (g *Game) makeItem(item itemName, items *[]Item, x, y int) {
var i Item
switch item {
case VorpalBlade: i = makeVorpalBlade(x, y)
case BattleAxe: i = makeBattleAxe(x, y)
case WeapSwordShort: i = makeWeapSwordShort(x, y)
case WeapFlailDire: i = makeWeapFlailDire(x, y)
case WeapDart: i = makeWeapDart(x, y)
case WeapShortBow: i = makeWeapShortBow(x, y)
case WeapCrossbow: i = makeWeapCrossbow(x, y)
case AmmoArrow: i = makeAmmoArrow(x, y)
case InfiniteJest: i = makeInfiniteJest(x, y)
case BookRage: i = makeBookRage(x, y)
case RingStrength: i = makeRingStrength(x, y)
case PotHeal: i = g.makePotHeal(x, y)
case PotConf: i = g.makePotConf(x, y)
case PotMega: i = g.makePotMega(x, y)
case ArmorChestLeather: i = makeArmorChestLeather(x, y)
case ArmorBootsLeather: i = makeArmorBootsLeather(x, y)
case ArmorBootsIron: i = g.makeArmorBootsIron(x, y)
case ShieldBuckler: i = makeShieldBuckler(x, y)
case ShieldSmall: i = makeShieldSmall(x, y)
case ShieldLarge: i = makeShieldLarge(x, y)
case ScrollBlink: i = g.makeScrollBlink(x, y)
default: return } //TODO make error here
//g.hero.addItemInv(i)
*items = append(*items, i)
}
func (a *Actor) useItem(id int, g *Game, s tcell.Screen) bool {
isU := false
switch (g.hero.inv)[id].item.category {
case Weapon: isU = a.useWeapon(id, g)
case Ring: isU = a.useRing(id, g)
case Potion: isU = a.usePotion(id, g)
case Armor: isU = a.useArmor(id, g)
case Scroll: isU = a.useScroll(id, g)
case Book: isU = a.useBook(id, g, s)
case Shield, Buckler: isU = a.useShield(id, g)
}
return isU
}
func (a *Actor) throwItem(id int, g *Game, s tcell.Screen) bool {
isU := false
var targetID int
tPos := a.projectileTarget(s, g)
for id, t := range g.floors[g.cur].actors {
if t.pos == tPos {
targetID = id
}
}
switch (a.inv)[id].item.category {
//case Weapon: isU = a.throwWeapon(id tPos g)
case Potion: isU = a.throwPotion(id, targetID, g)
}
return isU
}
func getInvPositionForSlotID(slotID int, inv []Inventory) int {
for j, i := range inv {
if i.slot == slotID { return j }
}
return -1
}
func (a *Actor) quiverItem(slotId int, g *Game) bool {
isU := false
invID := getInvPositionForSlotID(slotId, a.inv)
if a.quiver != -1 {
a.inv[invID].item.quivered = false
}
a.quiver = slotId
a.inv[invID].item.quivered = true
msgStr := fmt.Sprintf("%v ready to fire", a.inv[invID].item.name)
g.addMessage(msgStr, tcell.ColorDefault)
return isU
}
func (a *Actor) quiverEmpty(id int, g *Game) bool {
isU := false
if a.quiver == -1 {
g.addMessage("Your quiver is already empty", tcell.ColorDefault)
} else {
a.quiver = -1
a.inv[getInvPositionForSlotID(id, a.inv)].item.quivered = false
g.addMessage("Your quiver has been emptied", tcell.ColorDefault)
}
return isU
}
func (i *Item) updateBUC(buc BUCStatus) {
switch buc {
case Cursed: i.BUC = Cursed
case Uncursed: i.BUC = Uncursed
case Blessed: i.BUC = Blessed
}
i.BUC = Cursed
}
func (i *Item) addBrand(b itemBrand) {
switch b {
case Flaming: i.brand = Flaming
case Freezing: i.brand = Freezing
case Electrocution: i.brand = Electrocution
case Venom: i.brand = Venom
case Vorpal: i.brand = Vorpal
case Speed: i.brand = Speed
}
}
func (i *Item) addEnchant(n int) {
i.enchant += n
}
func (i *Item) updatePname(n string) {
i.pname = n
}
///////////////////////////////////////////////////////////////////////////////
// WEAPONS
func (i *Item) isDexMod() bool {
dexWeapons := []itemName{VorpalBlade,WeapDart,WeapDexMod}
for _, d := range dexWeapons {
if d == i.iname { return true }
}
return false
}
func (i *Item) isWeapBow() bool {
w := []itemName{WeapShortBow}
for _, d := range w {
if d == i.iname { return true }
}
return false
}
func (i *Item) isWeapCrossbow() bool {
w := []itemName{WeapCrossbow}
for _, d := range w {
if d == i.iname { return true }
}
return false
}
func (i *Item) isWeapRanged() bool {
if i.isWeapBow() || i.isWeapCrossbow() {
return true
} else {
return false
}
}
func (a *Actor) fireWeapon(s tcell.Screen, g *Game) bool {
isTurn := false
var targetID int
if a.quiver == -1 {
g.addMessage("You have nothing at the ready", tcell.ColorDefault)
return false
}
tPos := a.projectileTarget(s, g)
cancel := Point { -1, -1 }
if tPos == cancel { g.dbg("cancell");return isTurn}
for id, t := range g.floors[g.cur].actors {
if t.pos == tPos {
targetID = id
dmg := a.rangedAttack(&g.floors[g.cur].actors[targetID], tPos, g)
g.addMessage(fmt.Sprintf("ranged attack for %v", fmt.Sprint(dmg)), tcell.ColorDefault)
return true
}
}
weaponInvID := getInvPositionForSlotID(a.weapon, a.inv)
quiverInvID := getInvPositionForSlotID(a.quiver, a.inv)
if a.inv[quiverInvID].item.category == Ammo {
if a.weapon == -1 {
g.addMessage("You can't use that without the proper weapon", tcell.ColorDefault)
return isTurn
} else if a.inv[weaponInvID].item.iname == AmmoArrow {
if !a.inv[weaponInvID].item.isWeapBow() {
g.addMessage("You need a bow to fire arrows", tcell.ColorDefault)
return isTurn
}
} else if a.inv[quiverInvID].item.iname == AmmoBolt {
if !a.inv[quiverInvID].item.isWeapCrossbow() {
g.addMessage("You need a crossbow to fire bolts", tcell.ColorDefault)
return isTurn
}
}
}
a.dropProjectile(a.inv[getInvPositionForSlotID(a.quiver, a.inv)].item, tPos, g)
isTurn = true
a.energy -= SpeedCost
return isTurn
}
func (a *Actor) useWeapon(id int, g *Game) bool {
if a.inv[id].item.equipped {
a.inv[id].item.equipped = false
a.weapon = -1
a.useWhichWeapon(id, g)
return true
} else {
if a.canWield(id) {
a.inv[id].item.equipped = true
a.weapon = a.inv[id].slot
a.useWhichWeapon(id, g)
g.itemDiscovery(a.inv[id].item)
return true
} else {
g.addMessage("Your cannot wield that", tcell.ColorDefault)
return false
}
}
}
// func (a *Actor) useWhichWeapon(id int, g *Game) {
// switch a.inv[id].item.pname {
// case "Battle Axe": a.useBattleAxe(id, g)
// case "Vorpal Blade": a.useVorpalBlade(id, g)
// case "Dire Flail": a.useWeapFlailDire(id, g)
// }
// }
func (a *Actor) useWhichWeapon(id int, g *Game) {
switch a.inv[id].item.iname {
case BattleAxe: a.useBattleAxe(id, g)
case VorpalBlade: a.useVorpalBlade(id, g)
case WeapSwordShort: a.useWeapSwordShort(id, g)
case WeapFlailDire: a.useWeapFlailDire(id, g)
}
}
func makeVorpalBlade(x, y int) Item {
i := makeItem(x, y)
i.iname = VorpalBlade
i.name = "Vorpal Blade"
i.pname = "Vorpal Blade"
i.glyph = gWeapon
i.fg = tcell.ColorChartreuse
i.category = Weapon
i.slot = TwoHand
i.equipable = true
i.dmg = R1d8
i.weight = 10
//g.discovery(&i)
return i
}
func (a *Actor) useVorpalBlade(id int, g *Game) {
if a.inv[id].item.equipped {
g.addMessage("You feel the urge to pop off some heads", tcell.ColorDefault)
} else {
g.addMessage("You regain your calm", tcell.ColorDefault)
}
}
func makeBattleAxe(x, y int) Item {
i := makeItem(x, y)
i.iname = BattleAxe
i.name = "Battle Axe"
i.pname = "Battle Axe"
i.glyph = gWeapon
i.fg = tcell.ColorYellow
i.category = Weapon
i.slot = TwoHand
i.equipable = true
i.dmg = R2d12
i.weight = 12
return i
}
func (a *Actor) useBattleAxe(id int, g *Game) {
if a.inv[id].item.equipped {
g.addMessage("Chop Chop", tcell.ColorDefault)
} else {
g.addMessage("No more chopping", tcell.ColorDefault)
}
}
func makeWeapSwordShort(x, y int) Item {
i := makeItem(x, y)
i.iname = WeapSwordShort
i.name = "Short Sword"
i.pname = "Short Sword"
i.glyph = gWeapon
i.fg = tcell.ColorPink
i.category = Weapon
i.slot = OneHand
i.equipable = true
i.dmg = R1d8
i.weight = 6
return i
}
func (a *Actor) useWeapSwordShort(id int, g *Game) {
if a.inv[id].item.equipped {
g.addMessage("You equip the short sword", tcell.ColorDefault)
} else {
g.addMessage("You sheath your short sword", tcell.ColorDefault)
}
}
func makeWeapFlailDire(x, y int) Item {
i := makeItem(x, y)
i.iname = WeapFlailDire
i.name = "Dire Flail"
i.pname = "Dire Flail"
i.glyph = gWeapon
i.fg = tcell.ColorYellow
i.category = Weapon
i.slot = TwoHand
i.equipable = true
i.dmg = R4d12
i.weight = 14
return i
}
func (a *Actor) useWeapFlailDire(id int, g *Game) {
if a.inv[id].item.equipped {
g.addMessage("This is one big flail", tcell.ColorDefault)
} else {
g.addMessage("Your arms feel lighter", tcell.ColorDefault)
}
}
func makeWeapDart(x, y int) Item {
i := makeItem(x, y)
i.iname = WeapDart
i.name = "Dart"
i.pname = "Dart"
i.glyph = gWeapon
i.stackable = true
i.fg = tcell.ColorYellow
i.category = Weapon
i.slot = OneHand
i.equipable = true
i.charges = 5
i.dmg = R1d8
i.weight = 2
return i
}
func (a *Actor) useWeapDart(id int, g *Game) {
if a.inv[id].item.equipped {
g.addMessage("Bullseye", tcell.ColorDefault)
} else {
g.addMessage("You put the darts away", tcell.ColorDefault)
}
}
func makeWeapShortBow(x, y int) Item {
i := makeItem(x, y)
i.iname = WeapShortBow
i.name = "+5 Short Bow"
i.pname = "+5 Short Bow"
i.glyph = gWeapon
i.fg = tcell.ColorYellow
i.category = Weapon
i.slot = TwoHand
i.equipable = true
i.dmg = R1d10
i.weight = 6
return i
}
func (a *Actor) useWeapShortBow(id int, g *Game) {
if a.inv[id].item.equipped {
g.addMessage("Hawkeye", tcell.ColorDefault)
} else {
g.addMessage("You put the bow away", tcell.ColorDefault)
}
}
func makeWeapCrossbow(x, y int) Item {
i := makeItem(x, y)
i.iname = WeapCrossbow
i.name = "Crossbow"
i.pname = "Crossbow"
i.glyph = gWeapon
i.fg = tcell.ColorYellow
i.category = Weapon
i.slot = TwoHandRanged
i.equipable = true
i.dmg = R1d10
i.weight = 10
return i
}
func (a *Actor) useWeapCrossbow(id int, g *Game) {
if a.inv[id].item.equipped {
g.addMessage("Crossbow at the ready", tcell.ColorDefault)
} else {
g.addMessage("You put the crossbow away", tcell.ColorDefault)
}
}
///////////////////////////////////////////////////////////////////////////////
// AMMO
func makeAmmoArrow(x, y int) Item {
i := makeItem(x, y)
i.iname = AmmoArrow
i.name = "Arrow"
i.pname = "Arrow"
i.glyph = gWeapon
i.stackable = true
i.fg = tcell.ColorYellow
i.category = Ammo
i.charges = 10
i.enchant = 1
i.dmg = R1d2
return i
}
///////////////////////////////////////////////////////////////////////////////
// BOOKS
func (a *Actor) checkBookClass(bookClass, actorClass ActorClass) (bool, string) {
var msg string
if bookClass == actorClass {
return true, ""
} else {
switch bookClass {
case ClassFighter: msg = "You must be skilled in the arts of fighting to use this"
case ClassRogue: msg = "You must be skilled in the shadow arts to use this"
case ClassWizard: msg = "You must be skilled in the arcane to use this"
}
return false, msg
}
}
func (a *Actor) useBook(id int, g *Game, s tcell.Screen) bool {
isTurn := false
g.itemDiscovery(a.inv[id].item)
sids, spells, bname, bdesc := a.useWhichBook(id, g)
if sids == nil {
return isTurn
} else {
for _, known := range a.spells {
for i, sid := range sids {
if known == sid { spells[i] = spells[i] + " [known]"}
}
}
g.drawSpellBook(s, spells, bname, bdesc)
ev := s.PollEvent()
switch ev := ev.(type) {
case *tcell.EventResize:
s.Sync()
case *tcell.EventKey:
switch ev.Rune() {
case 'a': if len(spells) > 0 { isTurn = a.memorizeSpell(sids[0], g, s) }
case 'b': if len(spells) > 1 { isTurn = a.memorizeSpell(sids[1], g, s) }
case 'c': if len(spells) > 2 { isTurn = a.memorizeSpell(sids[2], g, s) }
case 'd': if len(spells) > 3 { isTurn = a.memorizeSpell(sids[3], g, s) }
case 'e': if len(spells) > 4 { isTurn = a.memorizeSpell(sids[4], g, s) }
case 'f': if len(spells) > 5 { isTurn = a.memorizeSpell(sids[5], g, s) }
}
switch ev.Key() { case tcell.KeyEscape: isTurn = false }
}
return isTurn
}
}
func (a *Actor) useWhichBook(id int, g *Game) ([]SpellID, []string, string, string) {
var spells []string; var sids []SpellID; var bdesc string
switch a.inv[id].item.iname {
case InfiniteJest: sids, spells, bdesc = a.useInfiniteJest(id, g)
case BookRage: sids, spells, bdesc = a.useBookRage(id, g)
}
return sids, spells, a.inv[id].item.pname, bdesc
}
func makeInfiniteJest(x, y int) Item {
i := makeItem(x, y)
i.iname = InfiniteJest
i.name = "Infinite Jest"
i.pname = "Infinite Jest"
i.glyph = gBook
i.fg = tcell.ColorYellow
i.category = Book
return i
}
func (a *Actor) useInfiniteJest(id int, g *Game) ([]SpellID, []string, string) {
canReadThis, msg := g.hero.checkBookClass(ClassWizard, g.class)
if !canReadThis { g.addMessage(msg, tcell.ColorDefault) ; return nil, nil, ""}
var spells []string
var spellID []SpellID
bookDesc := "Mostly footnotes."
spells = append(spells, "Blink"); spellID = append(spellID, Blink)
spells = append(spells, "Zap"); spellID = append(spellID, Zap)
return spellID, spells, bookDesc
}
func makeBookRage(x, y int) Item {
i := makeItem(x, y)
i.iname = BookRage
i.name = "Book of Rage"
i.pname = "Book of Rage"
i.glyph = gBook
i.fg = tcell.ColorYellow
i.category = Book
return i
}
func (a *Actor) useBookRage(id int, g *Game) ([]SpellID, []string, string) {
canReadThis, msg := g.hero.checkBookClass(ClassFighter, g.class)
if !canReadThis { g.addMessage(msg, tcell.ColorDefault) ; return nil, nil, ""}
var spells []string
var spellID []SpellID
bookDesc := "The Book of Rage is short and to the point. It enables\n"
bookDesc += "one who is skilled in the art of fighting to become enraged for a\n"
bookDesc += "short time increasing strength and speed. When the effect wears off\n"
bookDesc += "there will be a period of fatigue."
spells = append(spells, "Berserk"); spellID = append(spellID, FighterBerserk)
return spellID, spells, bookDesc
}
///////////////////////////////////////////////////////////////////////////////
// RINGS
func (a *Actor) useRing(id int, g *Game) bool {
if a.inv[id].item.equipped {
a.energy -= SpeedCost
a.inv[id].item.equipped = false
a.useWhichRing(id, g)
g.addMessage("Your pull the ring off your finger", tcell.ColorDefault)
return true
} else {
if a.canPutOnRing(id) {
a.energy -= SpeedCost
a.inv[id].item.equipped = true
g.itemDiscovery(a.inv[id].item)
a.useWhichRing(id, g)
return true
} else {
g.addMessage("You feel too gaudy", tcell.ColorDefault)
return false
}
}
}
func (a *Actor) useWhichRing(id int, g *Game) bool {
isU := false
switch a.inv[id].item.pname {
case "Ring of Strength": isU = a.useRingStrength(id, g)
}
return isU
}
func makeRingStrength(x, y int) Item {
i := makeItem(x, y)
i.iname = RingStrength
i.name = "Ring of htgnertS"
i.pname = "Ring of Strength"
i.glyph = gRing
i.fg = tcell.ColorChartreuse
i.category = Ring
return i
}
func (a *Actor) useRingStrength(id int, g *Game) bool {
strgBonus := 1 + a.inv[id].item.enchant
if a.inv[id].item.equipped {
a.strg += strgBonus
g.addMessage("You feel stronger...", tcell.ColorDefault)
// TODO if enchanted change message 'you feel much stronger' etc
} else {
a.strg -= strgBonus
g.addMessage("You feel weaker...", tcell.ColorDefault)
}
return true
}
///////////////////////////////////////////////////////////////////////////////
// POTIONS
func (a *Actor) throwPotion(id, tid int, g *Game) bool {
if a == &g.hero { g.itemDiscovery(a.inv[id].item) }
g.floors[g.cur].actors[tid].useWhichPotion(id, a.inv[id].item.iname, a.inv[id].item.BUC, g)
(a.inv)[id].item.charges--
if (a.inv)[id].item.charges <= 0 {
copy((a.inv)[id:], (a.inv)[id+1:])
a.inv[len(a.inv)-1] = Inventory{}
a.inv = (a.inv)[:len(a.inv)-1]
}
return true
}
func (a *Actor) usePotion(id int, g *Game) bool {
if a == &g.hero { g.itemDiscovery(a.inv[id].item) }
a.useWhichPotion(id, a.inv[id].item.iname, a.inv[id].item.BUC, g)
(a.inv)[id].item.charges--
if (a.inv)[id].item.charges <= 0 {
copy((a.inv)[id:], (a.inv)[id+1:])
a.inv[len(a.inv)-1] = Inventory{}
a.inv = (a.inv)[:len(a.inv)-1]
}
a.energy -= 0.5 * SpeedCost
return true
}
func (a *Actor) useWhichPotion(id int, potName itemName, buc BUCStatus, g *Game) {
switch potName {
case PotHeal: a.usePotHeal(buc, g)
case PotConf: a.usePotConf(buc, g)
case PotMega: a.usePotMega(buc, g)
}
}
func (g *Game) makePotHeal(x, y int) Item {
i := makeItem(x, y)
i.iname = PotHeal
i.name = "Potion of gnilaeH"
i.pname = "Potion of Healing"
i.glyph = gPotion
i.stackable = true
i.fg = tcell.ColorPink
i.category = Potion
i.charges = 5
g.discovery(&i)
return i
}
func (a *Actor) usePotHeal(buc BUCStatus, g *Game) {
switch buc {
case Uncursed:
a.hp += 11
if a == &g.hero {
g.addMessage("Drank a Potion of Healing", tcell.ColorDefault)
} else {
g.addMessage("Threw a Potion of Healing", tcell.ColorDefault)
}
case Blessed:
a.maxHP += 11
if a == &g.hero {
g.addMessage("Drank a Blessed Potion of Healing", tcell.ColorGreen)
} else {
g.addMessage("Threw a Blessed Potion of Healing", tcell.ColorGreen)
}
case Cursed:
a.hp -= 11
if a == &g.hero {
g.addMessage("Drank a Cursed Potion of Healing", tcell.ColorRed)
} else {
g.addMessage("Threw a Cursed Potion of Healing", tcell.ColorRed)
}
}
}
func (g *Game) makePotConf(x, y int) Item {
i := makeItem(x, y)
i.iname = PotConf
i.name = "Potion of Fuseconsion"
i.pname = "Potion of Confusion"
i.glyph = gPotion
i.stackable = true
i.fg = tcell.ColorAqua
i.category = Potion
i.charges = 5
g.discovery(&i)
return i
}
func (a *Actor) usePotConf(buc BUCStatus, g *Game) {
switch buc {
case Uncursed:
a.ai = ConfusedAI
a.addActorEvent(EventBasicAI, g.tick + 5)
if a == &g.hero {
g.addMessage("Drank a Potion of Confusion", tcell.ColorDefault)
} else {
g.addMessage("Threw a Potion of Confusion", tcell.ColorDefault)
}
case Blessed:
a.ai = ConfusedAI
if a == &g.hero {
g.addMessage("Drank a Blessed Potion of Confusion", tcell.ColorGreen)
} else {
g.addMessage("Threw a Blessed Potion of Confusion", tcell.ColorGreen)
}
case Cursed:
a.ai = ConfusedAI
if a == &g.hero {
g.addMessage("Drank a Cursed Potion of Confusion", tcell.ColorRed)
} else {
g.addMessage("Threw a Cursed Potion of Confusion", tcell.ColorRed)
}
}
}
func (g *Game) makePotMega(x, y int) Item {
i := makeItem(x, y)
i.iname = PotMega
i.name = "Potion of MegaGood"
i.pname = "Potion of MegaGood"
i.glyph = gPotion
i.stackable = true
i.fg = tcell.ColorLightBlue
i.category = Potion
i.charges = 5
g.discovery(&i)
return i
}
func (a *Actor) usePotMega(buc BUCStatus, g *Game) {
switch buc {
case Uncursed:
a.maxHP += 5
a.hp = a.maxHP
a.maxMana += 5
a.mana = a.maxMana
a.strg += 1
a.intel += 1
a.dex += 1
//a.addActorEvent(EventBasicAI, g.tick + 5)
if a == &g.hero {
g.addMessage("Drank a Potion of MEGA", tcell.ColorDefault)
} else {
g.addMessage("Threw a Potion of MEGA", tcell.ColorDefault)
}
case Blessed:
a.ai = ConfusedAI
if a == &g.hero {
g.addMessage("Drank a Blessed Potion of MEGA", tcell.ColorGreen)
} else {
g.addMessage("Threw a Blessed Potion of MEGA", tcell.ColorGreen)
}
case Cursed:
a.ai = ConfusedAI
if a == &g.hero {
g.addMessage("Drank a Cursed Potion of MEGA", tcell.ColorRed)
} else {
g.addMessage("Threw a Cursed Potion of MEGA", tcell.ColorRed)
}
}
}
///////////////////////////////////////////////////////////////////////////////
// SCROLLS
func (a *Actor) useScroll(id int, g *Game) bool {
g.itemDiscovery(a.inv[id].item)
a.useWhichScroll(id, g)
(g.hero.inv)[id].item.charges--
if (g.hero.inv)[id].item.charges <= 0 {
copy((g.hero.inv)[id:], (g.hero.inv)[id+1:])
g.hero.inv[len(g.hero.inv)-1] = Inventory{}
g.hero.inv = (g.hero.inv)[:len(g.hero.inv)-1]
}
a.energy -= SpeedCost // TODO use int as speed multiplier?
return true
}
func (a *Actor) useWhichScroll(id int, g *Game) bool {
isU := false
switch a.inv[id].item.pname {
case "Scroll of Blinking": isU = a.useScrollBlink(id, g)
}
return isU
}
func (g *Game) makeScrollBlink(x, y int) Item {
i := makeItem(x, y)
i.iname = ScrollBlink
i.name = "Scroll of Aoekghd"
i.pname = "Scroll of Blinking"
i.glyph = gScroll
i.stackable = true
i.fg = tcell.ColorOrange
i.category = Scroll
i.charges = 3
g.discovery(&i)
return i
}
func (a *Actor) useScrollBlink(id int, g *Game) bool {
switch (a.inv)[id].item.BUC {
case Uncursed:
a.spellBlink(g)
g.addMessage("You blink.", tcell.ColorDefault)
case Blessed:
a.spellBlink(g)
g.addMessage("You blink.", tcell.ColorDefault)
case Cursed:
a.spellBlink(g)
g.addMessage("You blink.", tcell.ColorDefault)
}
return true
}
///////////////////////////////////////////////////////////////////////////////
// ARMOR
func (a *Actor) useArmor(id int, g *Game) bool {
if a.inv[id].item.equipped {
a.energy -= SpeedCost // TODO for armor this should be moved to item and based on 'weight'
a.inv[id].item.equipped = false
a.useWhichArmor(id, g)
g.addMessage("You take it off", tcell.ColorDefault)
return true
} else {
if a.canEquipArmor(id) {
a.energy -= SpeedCost
a.inv[id].item.equipped = true
g.itemDiscovery(a.inv[id].item)
a.useWhichArmor(id, g)
return true
} else {
g.addMessage("You are already wearing something.", tcell.ColorDefault)
return false
}
}
}
func (a *Actor) useWhichArmor(id int, g *Game) bool {
isU := false
switch a.inv[id].item.iname {
case ArmorChestLeather: isU = a.useArmorChestLeather(id, g)
case ArmorBootsLeather: isU = a.useArmorBootsLeather(id, g)
case ArmorBootsIron: isU = a.useArmorBootsIron(id, g)
//case "SpecialArmor1" - so many special items per game
}
return isU
}
func makeArmorChestLeather(x, y int) Item {
i := makeItem(x, y)
i.iname = ArmorChestLeather
i.name = "Leather Armor"
i.pname = "Leather Armor"
i.glyph = gArmor
i.fg = tcell.ColorTan