########################################################################################
# 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
PORT=persistent.port
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