summaryrefslogtreecommitdiff
path: root/game/misc.rpy
blob: f8b377e930e200945f6290c3d3c8415d442aa4e0 (plain) (blame)
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
########################################################################################
#     This file is part of Castle.
#     Copyright (C) 2015  Jesusalva

#     This library is free software; you can redistribute it and/or
#     modify it under the terms of the GNU Lesser General Public
#     License as published by the Free Software Foundation; either
#     version 2.1 of the License, or (at your option) any later version.

#     This library 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
#     Lesser General Public License for more details.

#     You should have received a copy of the GNU Lesser General Public
#     License along with this library; if not, write to the Free Software
#     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
########################################################################################
# Miscellaneous functions from another game, also under LGPL

init python:
    # Core processing to be on a while loop
    def hit_verbose(someone, damage, counting, dmgfactor, fixfactor):
        someone["hp"]  -= dmgfactor
        counting += dmgfactor
        if counting+fixfactor == damage:
            someone["hp"]-=(fixfactor)
            counting+=fixfactor
        # TODO: What if something went wrong?
        renpy.pause(0.001)    
        return someone, damage, counting, dmgfactor, fixfactor

    # Main hit verbose function
    def hit_someone_verbose(someone, damage, fast=False):
        counting = 0

        # We can use dmgfactor
        if ((damage > 10) or (damage < 10)) and (not persistent.SkipHPAnimation) and (not fast):
            fixfactor=damage%10
            dmgfactor=int(damage/10)
            dbg_interactions=0
            dbg_srchp=0+someone["hp"]

            # Which loop to use?
            if damage > 0:
                while counting < damage:
                    someone, damage, counting, dmgfactor, fixfactor=hit_verbose(someone, damage, counting, dmgfactor, fixfactor)
                    someone["hp"]=int(someone["hp"])
                    dbg_interactions+=1

                    # Something went wrong
                    if dbg_interactions > 15:
                        raise Exception("WARNING 15 interactions or more happened without hit_verbose concluding.\n\nBy all means report this bug\nBUG ID: HSV FAILED on hpbar_handler with params unit_id, damage, counting, dmgfactor, fixfactor being %s,%d,%d,%d.\n\nClick \"Ignore\" to continue." % (someone["unit_id"], damage, counting, dmgfactor, fixfactor))
                        counting=damage
                        someone["hp"]=dbg_srchp-damage

            # So, healing it is
            else:
                while counting > damage:
                    someone, damage, counting, dmgfactor, fixfactor=hit_verbose(someone, damage, counting, dmgfactor, fixfactor)
                    someone["hp"]=int(someone["hp"])
                    dbg_interactions+=1

                    # Something went wrong
                    if dbg_interactions > 15:
                        raise Exception("WARNING 15 interactions or more happened without hit_verbose concluding.\n\nBy all means report this bug\nBUG ID: HSV FAILED on hpbar_handler with params unit_id, damage, counting, dmgfactor, fixfactor being %s,%d,%d,%d.\n\nClick \"Ignore\" to continue." % (someone["unit_id"], damage, counting, dmgfactor, fixfactor))
                        counting=damage
                        someone["hp"]=dbg_srchp-damage

        # We cannot use dmgfactor
        else:
            someone["hp"]  -= damage

        if (someone["hp"] > someone["max_hp"]):
            someone["hp"]=int(someone["max_hp"])   # Apply some corrections. TODO possible alias?
        renpy.block_rollback()              # No rollback from there.







































    """
    https://grandsphere.fandom.com/wiki/Champion_Challenge
    

    # Priority: Story.json option to call label instead (story.rpy - SQ<id>_)

    # Priority: Summon Button
    # Priority: Move "system header" to overlay, and hide during fights
    # Priority: Tavern Persiana
    # And also: Calculate chance for units (adding czoom_25) on draws
    # Don't forget to quote price etc.
    # Priority: Tavern: We could determine if a tavern is on/off in tavern.py
    # Specially if we make "high ranking knight taverns", we could even use
    # them during events, returning "107: Selected tavern is not yet open"
    # But how can the client know about this and when to display?
    # Eval() is not really safe. We could use persiana for this, though.
    # Priority: charge GP for upgrade
    # Priority: Unit Selling
    # Priority: Daily Quest (Fairies and Mana Eggs)
    # Priority: Daily Login reward screen
    # Priority: Token rewrite
    # Priority: Skill system
    # Priority: Card swapping (Move cards sideways)
    # Priority: AP potions

    # Notes
    #    renpy.invoke_in_thread(?)
    # raise KeyboardException → renpy.reload_script() or renpy.quit(relaunch=True)
    # if (renpy.android) use androidID, but we could get MAC at server?
    # or (renpy.mobile)

    # TODO
    # Login with already valid token: Currently, it returns the data associated
    # to the token, instead of executing login sequence.
    # Tokens are still a safety concern, specially with multi-device.
    # salted MD5 is not exactly safe. It does the trick, but isn't safe.
    # Maybe we should salt this further with account ID?

    # Future Improvement:
    # Server Protocol Version (compatibility for legacy clients/servers ?)
    # Or just check in the client packet?
    # 
    # Result[token] and Battle[token]
    # Result[token] contains operation history, loot, gp
    # Send two packages: update_battle at final
    # battle retrieves Result[token]
    # Result loot in icons

    # Weekly event switcher (Raids, etc. → events.py)

    # SSL ciphers from urllib3
    DEFAULT_CIPHERS = ":".join(
        [
            "ECDHE+AESGCM",
            "ECDHE+CHACHA20",
            "DHE+AESGCM",
            "DHE+CHACHA20",
            "ECDH+AESGCM",
            "DH+AESGCM",
            "ECDH+AES",
            "DH+AES",
            "RSA+AESGCM",
            "RSA+AES",
            "!aNULL",
            "!eNULL",
            "!MD5",
            "!DSS",
        ]
    )

    # Some old code using Queues
    q = Queue.Queue()
    t = threading.Thread(target=lambda w, packet, ags: w.put(send_packet_now(packet, ags)), args=(q, packet, args))
    t.start()
    t.join(3.0)
    print "getting value"
    # We either received a reply or timeout:
    # In case of a timeout, keep trying
    while (t.isAlive()):
        renpy.call_screen("msgbox", "Error Code: %d\n\nApplication timeout, click to try again" % (ERR_TIMEOUT))
        t.join(3.0)
        #return ERR_TIMEOUT
    val=q.get()

    """

label clear_all:
    python:
        # Your version is no longer valid
        if (HOST != persistent.host):
            persistent.version=1
            # TODO: Clear cache

        # Update host and delete password
        HOST=persistent.host
        renpy.notify("Deleting password: %s" % persistent.password)
        persistent.password=None

    "Spheres" "Server data purged, we'll update game data next time you start the game."
    $renpy.full_restart()
    jump start

label clear_cache:
    python:
        import os

        # Your version is no longer valid
        if persistent.host != "localhost":
            persistent.version=1

        # Find path to cached files
        if renpy.android:
            root=get_path("")
        else:
            root=get_path("extra/")

        # Remove cached files
        for file in os.listdir(root):
            if file.endswith('.png') or file.endswith('.mp3') or file.endswith('.jpg') or file.endswith('.webp') or file.endswith('.ogg'):
                try:
                    os.remove(get_path(root+file))
                    stdout("[CC] Removing %s" % get_path(root+file))
                except:
                    stdout("[CC] Removing %s... FAILED" % get_path(root+file))
                    os.remove(root+file)
                    stdout("[CC] Removing %s" % get_path(root+file))
            continue

        # Erase file memory
        persistent.allfiles=[]
        allfiles=[]

    "Spheres" "Cache deleted. Space was freed!"
    $renpy.full_restart()
    jump start

image spinner:
    "gfx/spinner.png"
    rotate 30.0
    pause 0.05
    "gfx/spinner.png"
    rotate 60.0
    pause 0.05
    "gfx/spinner.png"
    rotate 90.0
    pause 0.05
    "gfx/spinner.png"
    rotate 120.0
    pause 0.05
    "gfx/spinner.png"
    rotate 150.0
    pause 0.05
    "gfx/spinner.png"
    rotate 180.0
    pause 0.05
    "gfx/spinner.png"
    rotate 210.0
    pause 0.05
    "gfx/spinner.png"
    rotate 240.0
    pause 0.05
    "gfx/spinner.png"
    rotate 270.0
    pause 0.05
    "gfx/spinner.png"
    rotate 300.0
    pause 0.05
    "gfx/spinner.png"
    rotate 330.0
    pause 0.05
    "gfx/spinner.png"
    #rotate 360.0
    pause 0.05
    repeat