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
|
#################################################################################
# This file is part of Spheres.
# Copyright (C) 2019 Jesusalva
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program 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 General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#################################################################################
# Battle Module - Summons
import json
from utils import (compress, allsummons, stdout, dl_search,
Player, Battle)
from consts import (ERR_ERR, ERR_BAD)
from battle.skills import skill_core
from battle.common import conditions
#from battle.main import advance_wave, battle_endturn, get_result
def handle_summon(token, summon):
global Battle, Player
try:
# Summon strength is based on player rank
force=summon["strength"]*Player[token]["level"]
# Cast the skill, return error 500 on exception
skill_core(token, summon["type"], force, summon["attribute"])
except:
return ERR_ERR
stdout("Summon: Victory/Defeat Check")
# HOLD THAT! Handle victory/defeat conditions
check = conditions(token, Battle[token]["spheres"])
if check is not None:
return check
# The check is: if not ERR_ERR or ERR_BAD, then reload battle/result
sjson=compress(Battle[token])
return sjson
def summon(args, token):
# Data validation
try:
stdout("Summon: %s" % args)
ss=json.loads(args)
# [summon_id]
# Validation
summon_id=int(ss[0])
# Create summon object
summon=dl_search(allsummons, "summon_id", summon_id)
if summon == "ERROR":
stdout("ERROR, INVALID SUMMON ID %d" % summon_id)
raise Exception("Invalid summon")
# Verify the cost
if Battle[token]["bp"] < summon["cost"]:
stdout("Cannot summon \"%s\": Insufficient BP (%d/%d)" % (summon["name"], Battle[token]["bp"], summon["cost"]))
raise Exception("Insufficient BP")
stdout("All fine thus far")
except:
# Invalid data
return ERR_BAD
# Already summoned (reverse logic)
try:
Battle["s"]+=1
Battle["s"]-=1
return ERR_BAD
except:
pass
Battle[token]["bp"]-=summon["cost"]
Battle["s"]=1
return handle_summon(token, summon)
#################################################
# Handles CI false positives in a lame way
def pyflakes():
return Player
|