This repository has been archived by the owner on Jul 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
shop.go
127 lines (112 loc) · 3.47 KB
/
shop.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
package p1nto
import (
"github.com/bwmarrin/discordgo"
"strconv"
"fmt"
"strings"
)
func ShopHandle(s *discordgo.Session, m *discordgo.MessageCreate) {
content := strings.Split(m.Content, " ")
if len(content) < 2 {
s.ChannelMessageSend(m.ChannelID, "You must provide a shelf number")
return
}
if len(content) > 2 {
s.ChannelMessageSend(m.ChannelID, "Too many arguments")
return
}
shelf, err := strconv.Atoi(content[1])
if err != nil {
s.ChannelMessageSend(m.ChannelID, "Wrong Format")
fmt.Println(err)
return
}
total := len(items)
var (
left int = 5*shelf
right int = Min(5*shelf + 5, total)
)
if left >= total {
s.ChannelMessageSend(m.ChannelID, "We don't have that much items")
return
}
temp := "```Welcome to the shop"
for i := left; i < right; i++ {
temp = temp + "\n\nItem ID:" + strconv.Itoa(i) + " Price: $" + strconv.Itoa(items[i].Price)
temp = temp + "\n" + items[i].Name + " | Equip Slot:" + strconv.Itoa(items[i].SlotID) + " | "
if items[i].Hp > 0 {
temp = temp + "Hp+" + strconv.Itoa(items[i].Hp) + ", "
}
if items[i].Atk > 0 {
temp = temp + "Attack+" + strconv.Itoa(items[i].Atk) + ", "
}
if items[i].Def > 0 {
temp = temp + "Defense+" + strconv.Itoa(items[i].Def) + ", "
}
if items[i].Evasion > 0 {
temp = temp + "Evasion+" + strconv.Itoa(items[i].Evasion) + "%, "
}
if items[i].CritChance > 0 {
temp = temp + "Critical Chance+" + strconv.Itoa(items[i].CritChance) + "%, "
}
temp = temp[0:len(temp)-2]
}
temp += "```"
s.ChannelMessageSend(m.ChannelID, temp)
}
func BuyHandle(s *discordgo.Session, m *discordgo.MessageCreate) {
content := strings.Split(m.Content, " ")
if len(content) < 2 {
s.ChannelMessageSend(m.ChannelID, "You must provide an item ID showed in the shop!")
return
}
if len(content) > 2 {
s.ChannelMessageSend(m.ChannelID, "Too many arguments")
return
}
itemID, err := strconv.Atoi(content[1])
if err != nil {
s.ChannelMessageSend(m.ChannelID, "Wrong Format")
fmt.Println(err)
return
}
u := m.Author
CheckPlayer(u)
if itemID >= len(items) || itemID < 0 {
s.ChannelMessageSend(m.ChannelID, "There is no such item!")
} else if items[itemID].Price > players[u.ID].Money {
s.ChannelMessageSend(m.ChannelID, "Not enough money you poor litte shit :smirk: !")
} else {
players[u.ID].Inventory = append(players[u.ID].Inventory, itemID)
players[u.ID].Money -= items[itemID].Price
s.ChannelMessageSend(m.ChannelID, items[itemID].Name + " has been added to your Inventory !")
}
}
func SellHandle(s *discordgo.Session, m *discordgo.MessageCreate) {
content := strings.Split(m.Content, " ")
if len(content) < 2 {
s.ChannelMessageSend(m.ChannelID, "You must provide an ID in Inventory in the shop!")
return
}
if len(content) > 2 {
s.ChannelMessageSend(m.ChannelID, "Too many arguments")
return
}
invID, err := strconv.Atoi(content[1])
if err != nil {
s.ChannelMessageSend(m.ChannelID, "Wrong Format")
fmt.Println(err)
return
}
u := m.Author
CheckPlayer(u)
if invID >= len(players[u.ID].Inventory) || invID < 0 {
s.ChannelMessageSend(m.ChannelID, "There is no such item!")
} else {
players[u.ID].Money += items[players[u.ID].Inventory[invID]].Price
temp := items[players[u.ID].Inventory[invID]].Name + "is sold!\n"
temp += "You get " + strconv.Itoa(items[players[u.ID].Inventory[invID]].Price) + "$ back"
s.ChannelMessageSend(m.ChannelID, temp)
players[u.ID].Inventory = append(players[u.ID].Inventory[:invID], players[u.ID].Inventory[invID+1:]...)
}
}