summaryrefslogtreecommitdiff
path: root/game/units.rpy
blob: 82fc83448709cf2e8eb24eca350a00a3b697f15c (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
########################################################################################
#     This file is part of Spheres.
#     Copyright (C) 2019  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
########################################################################################
# Units upgrade and evolution
init python:
    def evocheck(level, unit):
        # Does an evolved form exist?
        #print("evocheck lv %d" % level)
        try:
            nu=unit["unit_id"]+1
            #print("nu is: %d" % int(nu))
            next_name=allunits[nu]["name"]
            #print("next name: %s" % next_name)
        except:
            return False

        # Level requeriment
        return level == unit["max_level"]

screen upgrade_char():
    vbox:
        xalign 0.5
        yalign 0.3

        # The unit
        hbox:
            add unitsquare(unit["unit_id"], czoom_70)
            null width 10
            label _("{size=32}{color=#fff}%s{/color}{/size}" % (unit["name"]))

        null height 20
        $i=0
        hbox:
            for ignored in enumerate(material):
                if i < 4:
                    imagebutton:
                        if material[i] >= 0:
                            idle unitsquare(Player["inv"][material[i]]["unit_id"], czoom_70)
                        else:
                            idle At("gfx/square/bg.png", czoom_70)
                        action Return(i)
                    $i+=1

        null height 20
        hbox:
            for ignored in enumerate(material):
                if i < 8:
                    imagebutton:
                        if material[i] >= 0:
                            idle unitsquare(Player["inv"][material[i]]["unit_id"], czoom_70)
                        else:
                            idle At("gfx/square/bg.png", czoom_70)
                        action Return(i)
                    $i+=1

        null height 80
        # The close button returns -1 and comes last (TODO)
        hbox:
            textbutton _("Merge") action Return(-2)
            null width 80
            textbutton _("Leave") action Return(-1)


screen evolve_char():
    vbox:
        xalign 0.5
        yalign 0.3

        # The unit
        hbox:
            add unitsquare(unit["unit_id"], czoom_70)
            null width 10
            add At("gfx/evol.png", czoom_70)
            null width 10
            add unitsquare(next["unit_id"], czoom_70)
            #label _("{size=32}{color=#fff}%s\n↓\n%s{/color}{/size}" % (unit["name"], next["name"]))

        null height 120
        $i=0
        hbox:
            xalign 0.5
            spacing 150
            for ignored in enumerate(material):
                if i < 2:
                    imagebutton:
                        if material[i] >= 0:
                            idle unitsquare(Player["inv"][material[i]]["unit_id"], czoom_70)
                        else:
                            idle At("gfx/square/bg.png", czoom_70)
                        action Return(i)
                    $i+=1

        null height 80
        # The close button returns -1 and comes last (TODO)
        hbox:
            xalign 0.5
            spacing 80
            textbutton _("Evolve") action [SensitiveIf(material[0]>=0 and material[1]>=0), Return(-2)]
            textbutton _("Cancel") action Return(-1)

label upgrade_pre:
    # who -> index. Set beforehand
    if who < 0:
        call screen msgbox("Error: Invalid upgrade parameters passed")
        return

    $ unit = allunits[Player["inv"][who]["unit_id"]]
    $ material = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]

    # Try to update inventory
    $ inv=get_inventory()
    python:
        try:
            renpy.call_screen("msgbox", "Error: %d" % int(inv))
        except:
            Player["inv"]=dlist()
            for a in inv:
                Player["inv"].append(a)

    jump upgrade

label upgrade:
    call screen upgrade_char()
    $message=_return
    if (message == -1):
        $who=-1
        return
        #jump restore
    if (message == -2):
        # TODO
        python:
            mats=list(set(material))
            mats.insert(0, who)
            if -1 in mats:
                mats.remove(-1)
            stdout(str(mats))
            ret=None
            ret=renpy.call_screen("confirm", "Are you sure you want to merge these units?", Return(True), Return(False))
            if ret:
                # TODO: DISPLAY ANIMATION
                message=send_packet("upgrade", str(mats))
                message=json_decode(message)
                try:
                    lv=Player["inv"][who]["level"]
                    narrator("Level up! %d -> %d" % (lv, int(message)+lv))
                except:
                    narrator("An error occured.\n\nError code: %s" % str(message))
                renpy.jump("upgrade_pre")
    else:
        $ cand=renpy.call_screen("inventory", True)
        if cand in material and cand >= 0:
            "This unit is already to be merged!"
        elif cand == who:
            "Cannot merge unit with itself!"
        else:
            # TODO: Check for party
            #"Trying to fuse [cand], must check if in party, duplicate, etc."
            $ material[message]=cand
        $ del cand

    # WIP
    jump upgrade


label evolve_pre:
    # who -> index. Set beforehand
    if who < 0:
        call screen msgbox("Error: Invalid upgrade parameters passed")
        return

    $ unit = allunits[Player["inv"][who]["unit_id"]]
    $ next = allunits[Player["inv"][who]["unit_id"]+1]
    $ material = [-1, -1]

    # Try to update inventory
    $ inv=get_inventory()
    python:
        try:
            renpy.call_screen("msgbox", "Error: %d" % int(inv))
        except:
            Player["inv"]=dlist()
            for a in inv:
                Player["inv"].append(a)

    #$renpy.call_screen("msgbox", "Feature not yet available\n%s" % next["name"])
    $renpy.hide("unit_"+str(unit["unit_id"]))
    jump evolve


label evolve:
    call screen evolve_char()
    $message=_return
    if (message == -1):
        $who=-1
        return
        #jump restore
    if (message == -2):
        # TODO
        python:
            mats=list(set(material))
            mats.insert(0, who)
            stdout(str(mats))
            ret=None
            ret=renpy.call_screen("confirm", "Are you sure you want to evolve this units?\nReagents will be lost forever!", Return(True), Return(False))
            if ret:
                message=send_packet("evolve", str(mats))
                message=json_decode(message)
                if message in ["200", 200]:
                    # TODO: DISPLAY ANIMATION
                    narrator("Evolution SUCCESS!")
                else:
                    narrator("Error code: 101!\n\n%s" % str(message))
                renpy.jump("inventory")
    else:
        $ cand=renpy.call_screen("inventory", True, 'alu["rare"] == %d and\
(\
 (alu["unit_id"] == %s) or\
 (alu["flags"] & UF_EVOMAT and alu["attribute"] == %d) or\
 (alu["flags"] & UF_SUPEREVO) )' % (unit["rare"], unit["unit_id"], unit["attribute"]))
        if cand in material and cand >= 0:
            "This unit is already to be used as material!"
        elif cand == who:
            "That's the unit being evolved!"
        else:
            # TODO: Check for party
            #"Trying to fuse [cand], must check if in party, duplicate, etc."
            $ material[message]=cand
        $ del cand

    # WIP
    jump evolve