-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnpc.go
More file actions
196 lines (186 loc) · 6.37 KB
/
npc.go
File metadata and controls
196 lines (186 loc) · 6.37 KB
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
package main
import (
"fmt"
)
type Npc struct {
Name string
Quests []int
}
func MakeNpc(people *map[int]Npc) {
(*people)[0] = Npc{Name: "Староста", Quests: []int{0, 1, 5}}
(*people)[1] = Npc{Name: "Торговец", Quests: []int{2}}
(*people)[2] = Npc{Name: "Знахарка", Quests: []int{6}}
(*people)[3] = Npc{Name: "Кузнец", Quests: []int{4}}
(*people)[4] = Npc{Name: "Жительница деревни", Quests: []int{7}}
(*people)[5] = Npc{Name: "Раненый солдат", Quests: []int{3}}
}
func chooseNpc(people *map[int]Npc, quests *map[int]Quest, player *Player, goods *map[string]int) {
fmt.Print("\033[H\033[2J")
fmt.Println("-----------------------------------------------------")
showStats(player)
fmt.Println("-----------------------------------------------------")
fmt.Println("С кем Вы хотите поговорить?")
for index, value := range *people {
fmt.Print(index+1, ". ", value.Name)
fmt.Println()
}
var tempAnswer int
fmt.Scanf("%d\n", &tempAnswer)
if tempAnswer <= len(*people) && tempAnswer > 0 {
Talk(tempAnswer-1, people, quests, player, goods)
}
}
func Talk(npc int, people *map[int]Npc, quests *map[int]Quest, player *Player, goods *map[string]int) {
fmt.Print("\033[H\033[2J")
fmt.Println("-----------------------------------------------------")
showStats(player)
fmt.Println("-----------------------------------------------------")
fmt.Println("О чем Вы хотите поговорить?")
for index, value := range (*people)[npc].Quests {
fmt.Print(index+1, ". ", (*quests)[value].title)
fmt.Println()
}
switch npc {
case 1:
fmt.Print(len((*people)[npc].Quests)+1, ". Торговать")
fmt.Println()
fmt.Print(len((*people)[npc].Quests)+2, ". Уйти")
fmt.Println()
case 2:
fmt.Print(len((*people)[npc].Quests)+1, ". Восстановить здоровье")
fmt.Println()
fmt.Print(len((*people)[npc].Quests)+2, ". Уйти")
fmt.Println()
default:
fmt.Print(len((*people)[npc].Quests)+1, ". Уйти")
fmt.Println()
}
var tempAnswer int
fmt.Scanf("%d\n", &tempAnswer)
if tempAnswer > 0 && tempAnswer < len((*people)[npc].Quests)+1 {
QuestDescriptor(npc, tempAnswer, people, quests, player, goods)
} else if npc == 1 && tempAnswer == len((*people)[npc].Quests)+1 {
TradeDescriptor(goods, player)
} else if npc == 2 && tempAnswer == len((*people)[npc].Quests)+1 {
player.currentHealth = player.maxHealth
}
}
func QuestDescriptor(npc int, answer int, people *map[int]Npc, quests *map[int]Quest, player *Player, goods *map[string]int) {
fmt.Print("\033[H\033[2J")
fmt.Println("-----------------------------------------------------")
showStats(player)
fmt.Println("-----------------------------------------------------")
currentQuest := (*quests)[(*people)[npc].Quests[answer-1]]
if currentQuest.done {
fmt.Println("Спасибо! Ты мне очень помог!")
fmt.Println("1. Обращайся")
} else if currentQuest.ready {
fmt.Println(currentQuest.discription)
fmt.Println("1. Я выполнил задание")
} else {
fmt.Println(currentQuest.discription)
fmt.Println("1. Хорошо")
}
var tempAnswer int
fmt.Scanf("%d\n", &tempAnswer)
if tempAnswer == 1 {
if currentQuest.ready && !currentQuest.done {
currentQuest.done = true
(*quests)[(*people)[npc].Quests[answer-1]] = currentQuest
if currentQuest.coinReward > 0 {
player.coins += currentQuest.coinReward
} else {
getReward(currentQuest.otherReward, player)
}
}
Talk(npc, people, quests, player, goods)
} else {
fmt.Println("Выберите из предложенных вариантов ответа...")
fmt.Scanf("%d\n", &tempAnswer)
}
}
func TradeDescriptor(goods *map[string]int, player *Player) {
fmt.Print("\033[H\033[2J")
fmt.Println("-----------------------------------------------------")
showStats(player)
fmt.Println("-----------------------------------------------------")
i := 1
var tempSlice []string
for key, value := range *goods {
fmt.Printf("%d. %s (Цена: %d)\n", i, key, value)
i++
tempSlice = append(tempSlice, key)
}
fmt.Printf("%d. Уйти\n", i)
var tempAnswer int
fmt.Scanf("%d\n", &tempAnswer)
switch {
case tempAnswer == i:
break
case tempAnswer < i && tempAnswer > 0:
switch tempSlice[tempAnswer-1] {
case "Дубина":
if player.currentWeapon.Name == "Меч" {
fmt.Println("Ваше оружие лучше")
} else if player.coins >= (*goods)["Дубина"] {
EquipWeapon(Weapon{"Дубина", 2}, player)
player.coins -= (*goods)["Дубина"]
delete(*goods, "Дубина")
} else {
fmt.Println("Недостаточно денег")
}
case "Куртка":
if player.currentChest.Name == "Кольчуга" {
fmt.Println("Ваш нагрудник лучше")
} else if player.coins >= (*goods)["Куртка"] {
EquipChest(Chest{"Куртка", 5}, player)
player.coins -= (*goods)["Куртка"]
delete(*goods, "Куртка")
} else {
fmt.Println("Недостаточно денег")
}
case "Тапочки":
if player.currentBoots.Name == "Сапоги" {
fmt.Println("Ваша обувь лучше")
} else if player.coins >= (*goods)["Тапочки"] {
EquipBoots(Boots{"Тапочки", 2}, player)
player.coins -= (*goods)["Тапочки"]
delete(*goods, "Тапочки")
} else {
fmt.Println("Недостаточно денег")
}
default:
}
default:
fmt.Println("Выберите из предложенных вариантов ответа...")
fmt.Scanf("%d\n", &tempAnswer)
}
}
func getReward(reward string, player *Player) {
switch reward {
case "Меч":
rewardWeapon := Weapon{Name: "Меч", Attack: 4}
EquipWeapon(rewardWeapon, player)
case "Кольчуга":
rewardChest := Chest{Name: "Кольчуга", Health: 10}
EquipChest(rewardChest, player)
case "Сапоги":
rewardBoots := Boots{Name: "Сапоги", Health: 5}
EquipBoots(rewardBoots, player)
default:
}
}
//0 Староста
//1 Торговец
//2 Знахарка
//3 Кузнец
//4 Жительница
//5 Раненый солдат
//0 Тролль-людоед
//1 Пропажа овец
//2 Телега на кладбище
//3 Потерянная сумка
//4 Новая кольчуга
//5 Шкура медведя
//6 Недостающие ингридиенты
//7 Пропавший ребенок