File size: 12,205 Bytes
15ba985
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4c554c4
8a9ab6d
15ba985
 
 
4c554c4
8a9ab6d
 
606c546
4c554c4
 
15ba985
 
548b390
 
 
 
15ba985
 
 
 
 
8a9ab6d
15ba985
8a9ab6d
4c554c4
15ba985
 
 
 
 
 
8a9ab6d
15ba985
4c554c4
8a9ab6d
606c546
 
4c554c4
606c546
 
 
 
8a9ab6d
 
4c554c4
8a9ab6d
15ba985
 
8a9ab6d
15ba985
 
4c554c4
 
15ba985
4c554c4
 
 
 
15ba985
 
 
4c554c4
 
15ba985
4c554c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15faf61
4c554c4
15ba985
606c546
15ba985
 
 
 
 
4c554c4
15ba985
8a9ab6d
15ba985
4c554c4
8a9ab6d
 
15ba985
4c554c4
606c546
8a9ab6d
 
 
4c554c4
8a9ab6d
 
606c546
4c554c4
 
 
 
 
 
15faf61
4c554c4
15ba985
606c546
15faf61
 
8a9ab6d
4c554c4
15faf61
15ba985
4c554c4
8a9ab6d
15ba985
8a9ab6d
 
 
 
 
 
 
606c546
 
4c554c4
 
 
 
 
 
15faf61
4c554c4
15ba985
 
 
8a9ab6d
15ba985
15faf61
8a9ab6d
15faf61
 
606c546
15faf61
4c554c4
15ba985
8a9ab6d
15ba985
4c554c4
15ba985
8a9ab6d
15ba985
 
4c554c4
 
 
8a9ab6d
15ba985
8a9ab6d
4c554c4
15ba985
 
606c546
15ba985
606c546
4c554c4
15ba985
 
 
 
 
 
8a9ab6d
15ba985
 
8a9ab6d
15faf61
8a9ab6d
4c554c4
 
 
15ba985
 
4c554c4
 
 
15ba985
4c554c4
 
 
 
 
 
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
from flask import Flask, request
import random

app = Flask(__name__)

# In-memory storage for each player's game state.
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": [],   # e.g. "UAV", "Air Strike"
        "plates": 3,
        "max_plates": 12,
        "in_gulag": False,
        "gulag_count": 0,  # number of times you've been downed
        "gulag_tokens": 0  # only obtainable AFTER your first gulag
    }

@app.route("/")
def home():
    return "Welcome to the BR game API! 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. "
            "Prepare for 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 game already ended, return final results.
    if state["status"] != "active":
        msg = f"Game over. Final Kills: {state['kills']}. "
        if state["status"] == "won":
            msg += "You emerged victorious! Use !start to begin a new game."
        elif state["status"] == "eliminated":
            msg += "You were eliminated. Use !start to try again."
        elif state["status"] == "gulag":
            msg += "You are in Gulag! Use !gulag to fight your opponent."
        return limit_response(msg)
    
    # If no plates, effective bonus is reduced.
    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}: "

    # -- FIGHT EVENT --
    if event == "fight":
        # Check for Air Strike usage if available.
        if "Air Strike" in state["equipment"] and random.random() < 0.3:
            # Special air strike outcome.
            kills = random.randint(2, 4)
            state["kills"] += kills
            state["players"] = max(state["players"] - kills, 1)
            state["ammo"] = max(state["ammo"] - random.randint(5,15), 0)
            resp += f"You called in an Air Strike! It obliterated {kills} enemies. "
            state["equipment"].remove("Air Strike")
        else:
            # Choose one of 10 detailed gunfight scenarios.
            scenario = random.randint(1,10)
            gun_used = random.choice(["M4", "AK-47", "Shotgun", "Sniper", "SMG"])
            if scenario == 1:
                kills = random.randint(1,2)
                resp += f"Your precision shot with the {gun_used} downed {kills} foe(s). "
            elif scenario == 2:
                kills = 1
                resp += f"You outmaneuvered an enemy and secured a kill with your {gun_used}. "
            elif scenario == 3:
                resp += f"Your shot missed badly with the {gun_used}! The enemy counterattacked and you lost a plate. "
                state["plates"] = max(state["plates"] - 1, 0)
                kills = 0
            elif scenario == 4:
                kills = random.randint(2,3)
                resp += f"A burst from your {gun_used} decimated multiple foes, earning you {kills} kill(s). "
            elif scenario == 5:
                kills = random.randint(1,3)
                resp += f"Overwhelming firepower from your {gun_used} got {kills} kill(s), but you overexerted and lost a plate. "
                state["plates"] = max(state["plates"] - 1, 0)
            elif scenario == 6:
                kills = 1
                resp += f"An enemy flanked you, but you quickly retaliated with your {gun_used} for 1 kill, losing a plate in the scramble. "
                state["plates"] = max(state["plates"] - 1, 0)
            elif scenario == 7:
                resp += f"Your {gun_used} jammed at a critical moment! You dodged a deadly shot but lost a plate. "
                state["plates"] = max(state["plates"] - 1, 0)
                kills = 0
            elif scenario == 8:
                kills = 1
                resp += f"Your rapid reload with the {gun_used} turned the tide, securing 1 kill at a small ammo cost. "
            elif scenario == 9:
                kills = 1
                resp += f"A lucky shot from your {gun_used} knocked an enemy out; however, you lost a plate in the exchange. "
                state["plates"] = max(state["plates"] - 1, 0)
            elif scenario == 10:
                kills = 0
                resp += f"Your evasive maneuvers with the {gun_used} avoided danger but yielded no kills. "
            # In final round, force at least one kill if outcome would be 0.
            if final_round and kills == 0:
                kills = 1
                resp += f"Final round pressure: you managed to secure 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,15), 0)
        
        # Chance to get additional damage from enemy fire even if you killed enemies.
        if random.random() < 0.2 and state["plates"] > 0:
            lost = 1
            state["plates"] = max(state["plates"] - lost, 0)
            resp += f"In the exchange, you also lost {lost} plate. "
    
    # -- LOOT EVENT --
    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(5, 20)
            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":
            # Only allow picking up a token if you've been in Gulag already and don't already have one.
            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. "
    
    # -- BUY EVENT --
    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":
            # Only allow buying a token if you've been to gulag and don't already have one.
            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 += "No need for a token right now. "
    
    # -- AMBUSH EVENT --
    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 cautious. "
        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 in the chaos. "
        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}! "

    # Natural eliminations occur regardless.
    nat = random.randint(5, 15)
    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 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()
    # Multiple Gulag outcomes:
    if outcome < 0.4:
        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 < 0.7:
        state["status"] = "eliminated"
        resp = waiting_msg + f"Your opponent proved too strong. You were eliminated in Gulag. Final Kills: {state['kills']}. Use !start to play again."
    else:
        # Stalemate: you lose a plate and must fight again in Gulag.
        if state["plates"] > 0:
            state["plates"] = max(state["plates"] - 1, 0)
        resp = waiting_msg + "The Gulag duel is inconclusive—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)