summaryrefslogtreecommitdiff
path: root/game/party.rpy
blob: 4d7cdcc4fa75ec3bde72cdce8db557e1feeb4214 (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
########################################################################################
#     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
########################################################################################
# Player data displays
init python:
    # Function which list all unit id on party
    def party_dupcheck(pid):
        ar=[]
        for unt in Player["party_%s" % pid]:
            ar.append(unt["unit_id"])
        return ar

    def get_party(pid, internal=False):
        raw=send_packet("get_party", str(pid))

        pt=json_decode(raw)
        if (pt == ERR_JSONDECODER):
            return ERR_JSONDECODER

        Player["party_%d" % pid]=pt
        if (internal):
            return False

        allmem=""
        for member in pt:
            # Skip'invalid members
            if member["unit_id"] <= 0:
                continue

            # TODO: show image
            rfc=Player["inv"][member["inv_id"]]

            allmem+="%d★ %s (Lv %d, %d exp)\n" % (allunits[member["unit_id"]]["rare"], allunits[member["unit_id"]]["name"], rfc["level"], rfc["exp"])
            #Player["party_1"].append(member)

        renpy.call_screen("msgbox", "Party %d\n %s" % (pid, allmem))
        return True

    def set_party(pid, members):
        raw=send_packet("set_party", """{"party_id": %d, "formation": %s}""" % (pid, str(members)))

        pt=json_decode(raw)
        if (pt == ERR_JSONDECODER):
            return ERR_JSONDECODER

        return True

    def party_update(pid, pix):
        newindex=renpy.call_screen("inventory", True)

        # We only need inventory id's
        # So make a Party variable with this
        Party=dlist()
        for une in Player["party_%d" % pid]:
            Party.append(une["inv_id"])

        if debug:
            print(str(Party))

        # Add unit, but only if no duplicates are found
        # Exception: If it is -1, then we can add
        if newindex != -1:
            dupcheck=party_dupcheck(pid)
            dupid=Player["inv"][newindex]["unit_id"]
            if dupid in dupcheck:
                renpy.notify(_("You cannot add duplicate party members!"))
            else:
                Party[pix]=newindex
        else:
            Party[pix]=newindex

        if debug:
            print(str(Party))

        # Set party
        set_party(pid, Party)
        return True

screen party_main():
    default party = 1
    vbox:
        xalign 0.5
        yalign 0.3
        label _("{size=32}{color=#fff}Party %d{/color}{/size}" % (party))
        null height 20
        hbox:
            for i, item in enumerate(Player["party_%d" % party]):
                imagebutton:
                    if item["unit_id"] > 0:
                        idle unitsquare(item["unit_id"], czoom_70)
                    else:
                        idle At("gfx/square/bg.png", czoom_70)
                    action Return([party, i])
        null height 80
        # The close button returns -1 and comes last (TODO)
        imagebutton:
                idle At("gfx/square/back_idle.png", czoom_75)
                hover At("gfx/square/back_hover.png", czoom_75)
                action Return(-1)

label party_lobby:

    call screen party_main

    # Return to town
    if _return == -1:
        jump restore

    # Update party index
    $party_update(_return[0], _return[1])
    $ get_party(_return[0], True)

    jump party_lobby



label party_lobby_enter:
    play music MUSIC_PARTY.id() fadein 0.5
    $ hud_clear()

    # 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)

    # FIXME
    $ get_party(1, True)
    jump party_lobby