-
Notifications
You must be signed in to change notification settings - Fork 24
/
classes - support.rpy
391 lines (332 loc) · 15.4 KB
/
classes - support.rpy
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
# Support classes
init -9 python:
######## Game logic classes ########
class PyTFallWorld(_object):
'''This class will guide all AI/Logic inside of the world that is not controlled by the player.
This really looks like this should be a function at the moment, but we will add more relevant methods in the future.
'''
def __init__(self):
# Maps
# self.maps = xml_to_dict(content_path('db/maps.xml'))
# for key in self.maps:
# if "attr" in self.maps[key]:
# del self.maps[key]["attr"]
self.map_pattern = "content/gfx/bg/locations/map_buttons/gismo/"
self.maps = OnScreenMap()
# GUI
self.city_dropdown = False
self.it = None # Items Transfer
self.sm = SlaveMarket()
self.hp = GuiHeroProfile()
# self.gs = GuiGirlsList()
# Teams
# self.pt = Team(implicit = [hero])
# Exploration
# self.tiles = load_tiles()
# self.forest_1 = object()
# Events:
self.world_events = WorldEventsManager(world_events)
# Quests:
self.world_quests = WorldQuestManager(world_quests)
# Actions:
self.world_actions = WorldActionsManager()
# Runaways:
self.ra = RunawayManager()
# We use this for the message in the main screen:
self.temp_text = list() # We add reports from the game here, that don't fit in the next day reports.
self.ms_text = ""
self.show_text = False
self.todays_first_view = True
def init_shops(self):
# Shops:
self.shops = ['General Store', 'Cafe', 'Work Shop', 'Witches Hut', 'Tailor Store']
self.general_store = GeneralStore('General Store', 18, ['General Store'])
self.cafe = ItemShop('Cafe', 18, ['Cafe'], sells=["food"])
self.workshop = ItemShop('Work Shop', 18, ['Work Shop'], sells=["armor", "dagger", "fists", "rod", "claws", "sword", "bow"])
self.witches_hut = ItemShop('Witches Hut', 18, ['Witches Hut'], sells=["amulet", "restore", "smallweapon"])
self.tailor_store = ItemShop('Tailor Store', 18, ['Tailor Store'], sells=["dress"])
# World AI ----------------------------->
@staticmethod
def restore_all_chars():
"""
Heals, restores AP and MP for non player characters that may have been exposed to world events.
"""
characters = [girl for girl in chars.itervalues() if girl not in hero.girls]
for girl in characters:
girl.health = girl.get_max("health")
girl.mp = girl.get_max("mp")
girl.vitality = girl.get_max("vitality")
# Resets and Counters
girl.restore_ap()
# girl.rt_trait(traits)
girl.item_counter()
girl.img_cache = list()
girl.cache = list()
for key in girl.effects:
if girl.effects[key]['active']:
girl.apply_effects(key)
girl.effects['Food Poisoning']['activation_count'] = 0
# Same for Arena Fighters:
for fighter in pytfall.arena.arena_fighters:
fighter.cache = list()
fighter.health = fighter.get_max("health")
fighter.mp = fighter.get_max("mp")
fighter.vitality = fighter.get_max("vitality")
@staticmethod
def add_random_girls():
l = list(girl for girl in chars.values() if girl.__class__ == rGirl and not girl.arena_active and girl not in hero.girls)
amount = randint(45, 60)
if len(l) < amount:
for __ in xrange((amount+5) - len(l)):
build_rc()
# ----------------------------------------->
def next_day(self):
'''Next day logic for our PyTFall World
'''
self.ms_text = ""
# Shops and SlaveMarket:
self.general_store.next_day()
self.cafe.next_day()
self.workshop.next_day()
self.witches_hut.next_day()
self.tailor_store.next_day()
self.sm.next_day()
self.ra.next_day()
store.jail.next_day()
# Girlsmeets:
# Termination:
cells = gm.girlcells
for cell in cells.keys():
if cells[cell].termination_day <= day:
del cells[cell]
# Arena:
self.arena.next_day()
# Girls, Brothels income and Hero:
for girl in hero.girls:
girl.next_day()
for brothel in hero.brothels:
brothel.nd_log_income()
hero.next_day()
# Restoring world girls:
self.restore_all_chars()
if not day%14:
self.add_random_girls()
# Last we construct the main screen report:
self.ms_text = "\n".join(self.temp_text)
self.temp_text = list()
self.ms_text = self.ms_text + "\n\n"
self.ms_text = self.ms_text + self.arena.daily_report # Arena*
self.todays_first_view = True
class Difficulties(_object):
"""
Adjusts gameplay values based on the difficulty setting.
"""
def __init__(self):
self.difficulty = "normal"
self.easy = dict()
self.normal = dict()
self.hard = dict()
self.easy["income_tax_1000+"] = 5
self.normal["income_tax_1000+"] = 10
self.hard["income_tax_1000+"] = 15
def set_difficulty(self, difficulty):
"""
Sets up difficulty values throughout the game.
"""
self.difficulty = difficulty
for i in self.__dict__[difficulty]:
setattr(self, i, self.__dict__[difficulty][i])
class ListHandler(_object):
# Most of this class is obsolete at this point of development
# Note: We should cut it to it's bare minimum and kill it later :)
def __init__(self):
self.BrtlUpList = ['bar', 'garden', 'stripclub', 'casinofloor', 'viprooms']
self.BrtlAdList = ['sign', 'flyers', 'magazine', 'billboard', 'girl', 'celeb']
self.LocList = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'brothel', "-PyTFall Educators-"]
self.clientCastes = ['None', 'Peasant', 'Merchant', 'Nomad', 'Wealthy Merchant', 'Clerk', 'Noble', 'Royal']
self.battlestats = ['health', 'mp', 'attack', 'magic', 'defence', 'agility', "luck", "charisma"]
self.herostats = ['libido', 'constitution', 'reputation', 'fame', 'charisma', 'sex', 'alignment', 'vitality', 'intelligence', 'luck']
# get a list of all battle tracks:
self.battle_tracks = list()
path = content_path("sfx/music/be")
for track in os.listdir(path):
if track.startswith("battle"):
self.battle_tracks.append("/".join([path, track]))
# Dict for music locations ( :0 )
self.world_music = dict()
class Calendar(object):
'''
Cheers to Rudi for mooncalendar calculations.
'''
def __init__(self, day=1, month=1, year=1, leapyear=False):
"""
Expects day/month/year as they are numbered in normal calender.
If you wish to add leapyear, specify a number of the first Leap year to come.
"""
self.day = day
self.month = month - 1
self.year = year
if not leapyear:
self.leapyear = self.year + 4
else:
self.leapyear = leapyear
self.daycount_from_gamestart = 0
self.days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
self.month_names = ['January', 'February', 'March', 'April', 'May', 'June', 'July',
'August', 'September', 'October', 'November', 'December']
self.days_count = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
self.mooncycle = 29
self.newmoonday = 1
def game_day(self):
"""
Returns amount of days player has spent in game.
Counts first day as day 1.
"""
return self.daycount_from_gamestart + 1
def string(self):
return "%s %d %d"%(self.month_names[self.month], self.day, self.year)
def next(self, days=1):
"""
Next day counter.
Now supports skipping.
"""
global day
self.daycount_from_gamestart += days
day = self.daycount_from_gamestart + 1
while days:
self.day += 1
days -= 1
if self.leapyear == self.year and self.month == 1:
if self.day > self.days_count[self.month] + 1:
self.month += 1
self.day = 1
self.leapyear += 4
elif self.day > self.days_count[self.month]:
self.month += 1
self.day = 1
if self.month > 11:
self.month = 0
self.year += 1
def weekday(self):
'''Returns the name of the current day according to daycount.'''
daylistidx = self.daycount_from_gamestart % len(self.days)
return self.days[daylistidx]
def week(self):
'''Returns the number of weeks, starting at 1 for the first week.
'''
weekidx = self.daycount_from_gamestart / len(self.days)
return weekidx + 1
def lunarprogress(self):
'''Returns the progress in the lunar cycle since new moon as percentage.
'''
newmoonidx = self.newmoonday - 1
dayidx = self.daycount_from_gamestart - newmoonidx
moonidx = dayidx % self.mooncycle
moondays = moonidx + 1
percentage = moondays * 100.0 / self.mooncycle
return int(round(percentage))
def moonphase(self):
'''Returns the lunar phase according to daycount.
Phases:
new moon -> waxing crescent -> first quater -> waxing moon ->
full moon -> waning moon -> last quarter -> waning crescent -> ...
'''
# calculate days into the cycle
newmoonidx = self.newmoonday - 1
dayidx = self.daycount_from_gamestart - newmoonidx
moonidx = dayidx % self.mooncycle
moondays = moonidx + 1
# substract the number of named days
unnamed_days = self.mooncycle - 4
# calculate the days per quarter
quarter = unnamed_days / 4.0
# determine phase
if moonidx<1:
phase = "new moon"
elif moonidx<(quarter+1):
phase = "waxing crescent"
elif moonidx<(quarter+2):
phase = "first quarter"
elif moonidx<(2*quarter+2):
phase = "waxing moon"
elif moonidx<(2*quarter+3):
phase = "full moon"
elif moonidx<(3*quarter+3):
phase = "waning moon"
elif moonidx<(3*quarter+4):
phase = "last quarter"
else:
phase = "waning crescent"
return phase
class Event(_object):
'''Next Day Reports Event Method
The load_image method will always return the same image. If you want to
do another search, you have to set the 'img' attribute to 'None'.
'''
def __init__(self, type='', txt='', img='', girl=None, girlmod={}, loc=None, locmod={}, red_flag=False, green_flag=False, **kwargs):
# describes the type of event
self.type = type
# the description of the event
self.txt = txt
# information on the event image or a displayable
self.img = img
# the character involved in the event (optional)
self.girl = girl
# the location of the event (optional)
self.loc = loc
# stat changes of that girl (optional)
self.girlmod = girlmod.copy()
# stat changes of that location (optional)
self.locmod = locmod.copy()
self.green_flag = green_flag
self.red_flag = red_flag
def load_image(self):
"""
Returns a renpy image showing the event.
The image is selected based on the event type and the character.
"""
# select/load an image according to img
width = 820
height = 705
size = (width, height)
d = self.img
# Try to analyze self.img in order to figure out what it represents:
if isinstance(d, renpy.display.core.Displayable):
return d
if isinstance(d, basestring):
if not d:
raise Exception("Basetring Supplied as img: Ev.type: {}, Ev.loc.name: {}".format(self.type, self.loc.name if self.loc else "Unknown"))
elif "." in d:
return ProportionalScale(d, width, height)
else:
return self.girl.show(self.img, resize=size, cache=True)
devlog.warning("Unknown Image Type: {} Provided to Event (Next Day Events class)".format(self.img))
return ProportionalScale("content/gfx/interface/images/no_image.png", width, height)
class OnScreenMap(_object):
"""
Loads data from JSON, builds a map.
To be used with screens.
It either builds the map from cut out peaces or by placing icons on in.
"""
def __init__(self):
in_file = content_path("db/maps.json")
with open(in_file) as f:
data = json.load(f)
for i in data:
setattr(self, i, data[i])
def __call__(self, map):
return getattr(self, map)
def unlock(self, map, loc):
for l in self(map):
if l["id"] == loc:
l["hidden"] = False
break
else:
notify("Could not find location: {} in map: {} to unlock.".format(map, loc))
def lock(self, map, loc):
for l in self(map):
if l["id"] == loc:
l["hidden"] = True
break
else:
notify("Could not find location: {} in map: {} to lock.".format(map, loc))