File size: 14,827 Bytes
15ba985
 
 
 
 
10e661f
ff3362c
 
b22a8b4
ff3362c
 
7651bc4
 
10e661f
 
15ba985
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ff9c579
8a9ab6d
15ba985
 
 
fa1eca1
8a9ab6d
 
606c546
fa1eca1
 
15ba985
 
548b390
 
7651bc4
548b390
15ba985
 
 
 
 
8a9ab6d
15ba985
8a9ab6d
ff9c579
15ba985
 
 
 
 
 
8a9ab6d
15ba985
ff3362c
8a9ab6d
606c546
 
ff9c579
606c546
 
 
ff9c579
8a9ab6d
 
 
15ba985
 
8a9ab6d
15ba985
 
ff9c579
15ba985
10e661f
ff9c579
15ba985
 
ff9c579
4c554c4
 
15ba985
ff9c579
4c554c4
ff9c579
 
4c554c4
 
ff9c579
 
 
 
4c554c4
ff9c579
 
4c554c4
ff9c579
 
4c554c4
ff9c579
 
4c554c4
 
ff9c579
4c554c4
ff9c579
 
4c554c4
ff9c579
4c554c4
 
ff9c579
4c554c4
ff9c579
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4c554c4
ff9c579
4c554c4
 
 
ff9c579
10e661f
ff9c579
 
 
 
10e661f
ff9c579
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15faf61
15ba985
606c546
15ba985
 
 
 
 
4c554c4
15ba985
8a9ab6d
15ba985
4c554c4
8a9ab6d
b22a8b4
15ba985
4c554c4
606c546
8a9ab6d
 
 
4c554c4
8a9ab6d
 
606c546
4c554c4
 
 
 
 
15faf61
15ba985
606c546
15faf61
 
8a9ab6d
4c554c4
15faf61
15ba985
4c554c4
8a9ab6d
15ba985
8a9ab6d
 
 
 
 
 
 
606c546
 
4c554c4
 
 
 
7651bc4
15faf61
15ba985
 
 
8a9ab6d
15ba985
15faf61
8a9ab6d
15faf61
 
606c546
15faf61
ff9c579
15ba985
8a9ab6d
15ba985
ff9c579
15ba985
8a9ab6d
15ba985
 
4c554c4
ff9c579
ff3362c
15ba985
8a9ab6d
ff9c579
15ba985
 
606c546
15ba985
606c546
4c554c4
15ba985
 
 
 
 
 
8a9ab6d
15ba985
fa1eca1
 
 
15ba985
8a9ab6d
15faf61
8a9ab6d
4c554c4
10e661f
15ba985
 
4c554c4
 
10e661f
15ba985
fa1eca1
4c554c4
 
 
 
ff9c579
15ba985
 
 
90084e1
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
from flask import Flask, request
import random

app = Flask(__name__)

# ---------------- Configuration ----------------
AIR_STRIKE_CHANCE = 0.85             # Chance to call in an Air Strike if available
SELF_REVIVE_CHANCE = 0.10            # Chance to self-revive when downed
EXTRA_LOST_PLATE_CHANCE = 1.90       # Chance to lose an extra plate from enemy fire
GULAG_WIN_THRESHOLD = 0.45           # In Gulag: outcome <35% = win (return to battle)
GULAG_ELIMINATED_THRESHOLD = 0.55    # In Gulag: outcome >=35% and <65% = eliminated; >=65% = stalemate (lose a plate and try again)
NAT_MIN_DEATHS = 13                   # Minimum natural enemy deaths per round
NAT_MAX_DEATHS = 29                  # Maximum natural enemy deaths per round
# ------------------------------------------------

game_states = {}

def limit_response(text, limit=400):
    return text if len(text) <= limit else text[:limit-3] + "..."

def init_game(username, loadout):
    bonus = 1.0
    if loadout:
        for w in loadout.lower().split(","):
            if w.strip() in ["ak-47", "m4", "mp5", "ar-15"]:
                bonus += 0.2
    return {
        "players": 150,
        "kills": 0,
        "bonus": bonus,
        "round": 0,
        "status": "active",   # active, gulag, eliminated, won
        "revives": 0,
        "ammo": 100,
        "armor": 100,
        "inventory": [],
        "equipment": [],
        "plates": 3,
        "max_plates": 12,
        "in_gulag": False,
        "gulag_count": 0,  
        "gulag_tokens": 0  
    }

@app.route("/")
def home():
    return "Welcome to the Warzone BR game! Use !start, !fight, or !gulag."

@app.route("/start", methods=["GET"])
def start():
    user = request.args.get("user")
    loadout = request.args.get("loadout", "")
    if not user:
        return limit_response("User required")
    game_states[user] = init_game(user, loadout)
    resp = (f"Game started for {user}! Players:150, Bonus:{game_states[user]['bonus']:.1f}, Plates:3. "
            "Brace yourself for intense combat! Use !fight to engage.")
    return limit_response(resp)

@app.route("/fight", methods=["GET"])
def fight():
    user = request.args.get("user")
    if not user or user not in game_states:
        return limit_response("Start game first with !start")
    state = game_states[user]
    
    if state["status"] != "active":
        msg = f"Game over. Final Kills: {state['kills']}. "
        if state["status"] == "won":
            msg += "You emerged victorious! Use !start to play again."
        elif state["status"] == "eliminated":
            msg += "You were eliminated. Use !start to try again."
        elif state["status"] == "gulag":
            msg += "You're in Gulag! Use !gulag to fight your opponent."
        return limit_response(msg)
    
    effective_bonus = state["bonus"] if state["plates"] > 0 else state["bonus"] * 0.7
    state["round"] += 1
    r = state["round"]
    final_round = state["players"] <= 3
    event = random.choice(["fight", "loot", "buy", "ambush"])
    resp = f"R{r}: "
    
    if event == "fight":
        if "Air Strike" in state["equipment"] and random.random() < AIR_STRIKE_CHANCE:
            kills = random.randint(2, 3)
            state["kills"] += kills
            state["players"] = max(state["players"] - kills, 1)
            state["ammo"] = max(state["ammo"] - random.randint(5,10), 0)
            resp += f"You called in an Air Strike! It obliterated {kills} enemies. "
            state["equipment"].remove("Air Strike")
        else:
            scenario = random.randint(1,15)
            gun_used = random.choice(["M4", "AK-47", "Shotgun", "Sniper", "SMG"])
            downed = False
            kills = 0
            if scenario == 1:
                kills = 1
                resp += f"Your precision shot with the {gun_used} downed {kills} foe. "
            elif scenario == 2:
                resp += f"Your {gun_used} jammed at a critical moment, and you were caught off guard—downed! "
                downed = True
            elif scenario == 3:
                kills = 1
                resp += f"You outmaneuvered an enemy with your {gun_used} and secured a kill. "
            elif scenario == 4:
                kills = 1
                resp += f"A burst from your {gun_used} earned you {kills} kill, though you were rattled. "
            elif scenario == 5:
                resp += f"Your attempt to flank with the {gun_used} backfired—you were overwhelmed and downed! "
                downed = True
            elif scenario == 6:
                kills = 1
                resp += f"Your rapid reload with the {gun_used} allowed you to grab a kill. "
            elif scenario == 7:
                resp += f"Disaster! Your {gun_used} misfired and left you exposed—downed! "
                downed = True
            elif scenario == 8:
                resp += f"A stray round from your {gun_used} grazed an enemy, but nothing decisive happened. "
            elif scenario == 9:
                kills = 1
                resp += f"An aggressive assault with your {gun_used} got you {kills} kill. "
            elif scenario == 10:
                kills = 1
                resp += f"A lucky headshot with your {gun_used} secured {kills} kill, but you lost a plate. "
                state["plates"] = max(state["plates"] - 1, 0)
            elif scenario == 11:
                kills = 1
                resp += f"Suppressive fire from your {gun_used} earned you {kills} kill. "
            elif scenario == 12:
                resp += f"In a moment of hesitation, you failed to act and were downed by enemy fire. "
                downed = True
            elif scenario == 13:
                kills = 1
                resp += f"Your {gun_used} shot knocked an enemy out for {kills} kill, but your cover was compromised."
                if random.random() < 0.5:
                    downed = True
                    resp += " You were subsequently overwhelmed. "
            elif scenario == 14:
                kills = 1
                resp += f"Your {gun_used} burst ricocheted, earning {kills} kill but costing you a plate. "
                state["plates"] = max(state["plates"] - 1, 0)
            elif scenario == 15:
                resp += f"In the chaos, you managed no kills and were left vulnerable."
                if random.random() < 0.5:
                    downed = True
            if final_round and not downed and kills == 0:
                kills = 1
                resp += f"Under final round pressure, you managed a desperate 1 kill with your {gun_used}. "
            state["kills"] += kills
            if kills > 0:
                state["players"] = max(state["players"] - kills, 1)
                state["ammo"] = max(state["ammo"] - random.randint(5,10), 0)
            if not downed and random.random() < EXTRA_LOST_PLATE_CHANCE:
                lost = 1
                state["plates"] = max(state["plates"] - lost, 0)
                resp += f"Amid the firefight, you lost {lost} plate from enemy fire. "
            if downed:
                if random.random() < SELF_REVIVE_CHANCE:
                    state["revives"] += 1
                    if state["plates"] > 0:
                        lost_plate = 1
                        state["plates"] = max(state["plates"] - lost_plate, 0)
                        resp += f"Miraculously, you self-revived (lost {lost_plate} plate). "
                    else:
                        resp += "Miraculously, you self-revived despite having no plates. "
                else:
                    lost_plate = random.randint(1, 2)
                    state["plates"] = max(state["plates"] - lost_plate, 0)
                    if state["gulag_count"] == 0:
                        state["gulag_count"] += 1
                        state["in_gulag"] = True
                        state["status"] = "gulag"
                        resp += f"Downed by enemy fire (lost {lost_plate} plate(s))! You've earned a free Gulag chance. Use !gulag."
                        return limit_response(resp)
                    else:
                        if state["gulag_tokens"] > 0:
                            state["gulag_tokens"] -= 1
                            state["gulag_count"] += 1
                            state["in_gulag"] = True
                            state["status"] = "gulag"
                            resp += f"Downed again (lost {lost_plate} plate(s))! You used a Gulag Token for another chance. Use !gulag."
                            return limit_response(resp)
                        else:
                            state["status"] = "eliminated"
                            resp += f"Downed by enemy fire (lost {lost_plate} plate(s))! No Gulag Tokens available. Game over. Final Kills: {state['kills']}. Use !start to play again."
                            return limit_response(resp)
    
    elif event == "loot":
        loot = random.choice(["weapon", "ammo", "armor", "plate", "gulag token"])
        if loot == "weapon":
            wpn = random.choice(["AK-47", "M4", "Shotgun", "Sniper"])
            state["inventory"].append(wpn)
            if wpn.lower() in ["ak-47", "m4", "mp5", "ar-15"]:
                state["bonus"] += 0.2
            resp += f"You scavenged a {wpn} from the wreckage. "
        elif loot == "ammo":
            add_ammo = random.randint(10, 30)
            state["ammo"] += add_ammo
            resp += f"Found {add_ammo} rounds of ammo. "
        elif loot == "armor":
            add_arm = random.randint(1, 3)
            state["armor"] += add_arm
            resp += f"Picked up {add_arm} armor points. "
        elif loot == "plate":
            if state["plates"] < state["max_plates"]:
                new_plates = random.randint(1, 3)
                state["plates"] = min(state["plates"] + new_plates, state["max_plates"])
                resp += f"Discovered {new_plates} extra plate(s)! "
            else:
                resp += "Plates are already maxed out. "
        elif loot == "gulag token":
            if state["gulag_count"] > 0 and state["gulag_tokens"] == 0:
                state["gulag_tokens"] = 1
                resp += "Found a Gulag Token on the battlefield! "
            else:
                resp += "No useful token found. "
    
    elif event == "buy":
        item = random.choice(["UAV", "Air Strike", "Cluster Strike", "Armor Box", "Plates", "Gulag Token"])
        if item in ["UAV", "Air Strike"]:
            state["equipment"].append(item)
            state["bonus"] += 0.3
            resp += f"Purchased {item}, boosting your firepower! "
        elif item == "Armor Box":
            state["armor"] += 10
            resp += "Acquired an Armor Box to reinforce your defenses. "
        elif item == "Cluster Strike":
            state["bonus"] += 0.15
            resp += "Bought a Cluster Strike to thin out the opposition. "
        elif item == "Plates":
            if state["plates"] < state["max_plates"]:
                added = random.randint(1, 3)
                state["plates"] = min(state["plates"] + added, state["max_plates"])
                resp += f"Reinforced your gear with {added} extra plate(s)! "
            else:
                resp += "Your plates are already at maximum. "
        elif item == "Gulag Token":
            if state["gulag_count"] > 0 and state["gulag_tokens"] == 0:
                state["gulag_tokens"] = 1
                resp += "Purchased a Gulag Token for a second chance! "
            else:
                resp += "You found a gulag toke but no need for one so you left it to despawn. "
    
    elif event == "ambush":
        resp += "Ambushed! "
        amb = random.choice(["escaped", "lost ammo", "got a kill"])
        gun_used = random.choice(["M4", "AK-47", "Shotgun", "Sniper", "SMG"])
        if amb == "escaped":
            if final_round:
                kills = random.randint(1, 2)
                state["kills"] += kills
                state["players"] = max(state["players"] - kills, 1)
                resp += f"Ambush escalated into a firefight and you secured {kills} kill(s) with your {gun_used}! "
            else:
                resp += "Managed to evade the ambush, but remain on high alert. "
        elif amb == "lost ammo":
            lost = random.randint(10, 20)
            state["ammo"] = max(state["ammo"] - lost, 0)
            resp += f"Got caught off guard and lost {lost} ammo. "
        else:
            kills = random.randint(1, 2)
            state["kills"] += kills
            state["players"] = max(state["players"] - kills, 1)
            resp += f"Overpowered the ambushers and secured {kills} kill(s) with your {gun_used}! "
    
    nat = random.randint(NAT_MIN_DEATHS, NAT_MAX_DEATHS)
    state["players"] = max(state["players"] - nat, 1)
    resp += f"Additionally, {nat} enemies were eliminated naturally. "
    
    if state["players"] <= 1:
        state["status"] = "won"
        resp += f"Victory! Final Kills: {state['kills']}. You emerged triumphant, warrior! Use !start to play again."
    else:
        resp += (f"Remaining enemies: {state['players']}. Total Kills: {state['kills']}. "
                 f"Plates remaining: {state['plates']}.")
    return limit_response(resp)

@app.route("/gulag", methods=["GET"])
def gulag():
    user = request.args.get("user")
    if not user or user not in game_states:
        return limit_response("Start game first with !start")
    state = game_states[user]
    if state["status"] in ["eliminated", "won"]:
        msg = f"Game over. Final Kills: {state['kills']}. Use !start to play again."
        return limit_response(msg)
    if not state.get("in_gulag"):
        return limit_response("You're not in Gulag. If downed, use !gulag to fight your opponent.")
    
    waiting_msg = "In Gulag: waiting for an opponent... "
    outcome = random.random()
    if outcome < GULAG_WIN_THRESHOLD:
        state["status"] = "active"
        state["in_gulag"] = False
        state["players"] = max(state["players"] - random.randint(2,5), 1)
        resp = waiting_msg + "After a fierce duel, you won the Gulag fight and return to battle. Use !fight to continue."
    elif outcome < GULAG_ELIMINATED_THRESHOLD:
        state["status"] = "eliminated"
        state["in_gulag"] = False
        resp = waiting_msg + f"Your opponent proved too strong. You were eliminated in Gulag. Final Kills: {state['kills']}. Use !start to play again."
    else:
        if state["plates"] > 0:
            state["plates"] = max(state["plates"] - 1, 0)
        resp = waiting_msg + "The Gulag duel ended in a stalemate—you lost a plate and remain in Gulag. Use !gulag to try again."
    return limit_response(resp)

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=7860)