-
Notifications
You must be signed in to change notification settings - Fork 1
/
Base.py
149 lines (133 loc) · 4.34 KB
/
Base.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
'''
Author: Lomnom
Lisence: MIT lisence
Description: Common actions called by every tile
'''
from RpgClass import *
def setGames(game):
global games
games=game
async def pmap(game):
dprint(game,game.map.getProjection(game.player))
await dflush(game)
async def w(game):
await game.map.goto(game,game.player.x,game.player.y-1)
dprint(game,game.map.getProjection(game.player))
await dflush(game)
async def s(game):
await game.map.goto(game,game.player.x,game.player.y+1)
dprint(game,game.map.getProjection(game.player))
await dflush(game)
async def a(game):
await game.map.goto(game,game.player.x-1,game.player.y)
dprint(game,game.map.getProjection(game.player))
await dflush(game)
async def d(game):
await game.map.goto(game,game.player.x+1,game.player.y)
dprint(game,game.map.getProjection(game.player))
await dflush(game)
async def move(game):
args=list(await dinput(game,"enter directions to move in! eg. wwwssddsd"))
for direction in args:
if direction=="w":
await game.map.goto(game,game.player.x,game.player.y-1)
elif direction=="a":
await game.map.goto(game,game.player.x-1,game.player.y)
elif direction=="s":
await game.map.goto(game,game.player.x,game.player.y+1)
elif direction=="d":
await game.map.goto(game,game.player.x+1,game.player.y)
else:
dprint(game,"{} is not w,a,s or d".format(direction))
dprint(game,game.map.getProjection(game.player))
await dflush(game)
async def use(game):
try:
itemIndex=int(await dinput(game,"enter item index to use! eg. 0"))
item=game.player.items[itemIndex]
except:
dprint(game,"item number not valid!")
await dflush(game)
return
await item.use(game)
if item.durability<=0:
dprint(game,game.player.items[itemIndex].name+" was used up!")
game.player.items.pop(itemIndex)
dprint(game,getbackpackstr(game))
await dflush(game)
def getbackpackstr(game):
backpackStr="Items:\n"
for item in range(len(game.player.items)):
itemObj=game.player.items[item]
backpackStr+=" {}: {} ({}/{})\n".format(item,itemObj.name,itemObj.durability,itemObj.fullDurability)
return backpackStr
async def backpack(game):
dprint(game,getbackpackstr(game))
await dflush(game)
async def drop(game):
try:
itemIndex=int(await dinput(game,"enter item index to drop! eg. 0"))
item=game.player.items[itemIndex]
except:
dprint(game,"item number not valid!")
await dflush(game)
return
dprint(game,"dropped {}".format(game.player.items[itemIndex].name))
game.player.items.pop(itemIndex)
dprint(game,getbackpackstr(game))
await dflush(game)
async def swap(game):
try:
itemIndex=[
int(await dinput(game,"enter first item index to swap! eg. 0")),
int(await dinput(game,"enter second item index to swap! eg. 1"))
]
except:
dprint(game,"item numbers not valid!")
await dflush(game)
return
dprint(game,"swapped {} ({}) with {} ({})".format( game.player.items[itemIndex[0]].name, itemIndex[0], game.player.items[itemIndex[1]].name, itemIndex[1]))
item1=game.player.items[itemIndex[0]]
game.player.items[itemIndex[0]]=game.player.items[itemIndex[1]]
game.player.items[itemIndex[1]]=item1
dprint(game,getbackpackstr(game))
await dflush(game)
async def info(game):
try:
itemIndex=int(await dinput(game,"enter item index to get info on! eg. 0"))
item=game.player.items[itemIndex]
except:
dprint(game,"item number not valid!")
await dflush(game)
return
dprint(game,item.description)
await dflush(game)
async def give(game):
try:
user=int((await dinput(game,"Who to give to? eg. @Dalithop"))[3:-1])
except ValueError:
dprint(game,"Mention was not valid!")
await dflush(game)
return
try:
otherGame=games[user]
except KeyError:
dprint(game,"The other person needs to run $rpg first! ({}}".format(user))
await dflush(game)
return
try:
otherGame.player.items+=[game.player.items.pop(int(await dinput(game,"Enter the item index! eg. 0")))]
dprint(game,"sent!")
await dflush(game)
except IndexError:
dprint(game,"item index invalid!")
await dflush(game)
baseActions={"⬆️":w,"⬇️":s,"⬅️":a,"➡️":d,"⏭":move,"🗺":pmap,"🎒":backpack,"⚔️":use,"🗑":drop,"🔁":swap,"❓":info,"🎁":give}
# 🍴
async def err(game,message): #invalid action
dprint(game,"you cant do {}".format(message))
await dflush(game)
async def errMov(game,error): #cant move
dprint(game,"You cant move there! ({})".format(error))
def withBase(dict1):
return dict(baseActions,**dict1)