File size: 8,965 Bytes
15ba985
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8a9ab6d
 
15ba985
 
 
8a9ab6d
 
 
15ba985
 
 
548b390
 
 
 
15ba985
 
 
 
 
8a9ab6d
15ba985
8a9ab6d
 
15ba985
 
 
 
 
 
8a9ab6d
15ba985
8a9ab6d
 
 
 
 
 
 
 
 
 
15ba985
 
8a9ab6d
15ba985
 
15faf61
15ba985
8a9ab6d
 
15faf61
15ba985
 
 
 
8a9ab6d
15ba985
15faf61
 
 
 
8a9ab6d
15faf61
8a9ab6d
15ba985
 
 
8a9ab6d
 
 
 
 
 
15ba985
8a9ab6d
 
15ba985
 
8a9ab6d
 
15faf61
15ba985
8a9ab6d
15ba985
 
 
 
 
8a9ab6d
15ba985
8a9ab6d
15ba985
8a9ab6d
 
 
15ba985
8a9ab6d
 
 
 
 
 
 
 
15faf61
15ba985
8a9ab6d
15faf61
 
8a9ab6d
 
15faf61
15ba985
8a9ab6d
 
15ba985
8a9ab6d
 
 
 
 
 
 
 
15faf61
15ba985
 
 
8a9ab6d
15ba985
15faf61
8a9ab6d
15faf61
 
8a9ab6d
15faf61
8a9ab6d
15ba985
8a9ab6d
15ba985
8a9ab6d
15ba985
8a9ab6d
15ba985
 
8a9ab6d
15faf61
8a9ab6d
15ba985
8a9ab6d
 
15ba985
 
8a9ab6d
15ba985
8a9ab6d
15ba985
 
 
 
 
 
8a9ab6d
15ba985
 
8a9ab6d
15faf61
8a9ab6d
15ba985
 
 
 
8a9ab6d
15ba985
 
8a9ab6d
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
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": [],
        "plates": 3,
        "max_plates": 12,
        "in_gulag": False
    }

@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. "
            "Get ready 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 game already ended, show final result.
    if state["status"] != "active":
        msg = f"Game over. Final Kills: {state['kills']}. Please use !start to begin a new game."
        if state["status"] == "gulag":
            msg = "You are in Gulag waiting for an opponent. Use !gulag to fight."
        return limit_response(msg)
    
    # If no plates, reduce effective bonus.
    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":
        roll = random.random() * effective_bonus
        gun_used = random.choice(["M4", "AK-47", "Shotgun", "Sniper", "SMG"])
        if final_round or roll > 0.7:
            kills = random.randint(1, 3)
            state["kills"] += kills
            state["players"] = max(state["players"] - kills, 1)
            state["ammo"] = max(state["ammo"] - random.randint(5,15), 0)
            resp += f"Engaged in a fierce gunfight and got {kills} kill(s)! Enemy downed with a {gun_used}. "
        elif roll > 0.5:
            if final_round:
                kills = random.randint(1, 3)
                state["kills"] += kills
                state["players"] = max(state["players"] - kills, 1)
                resp += f"Final round battle: secured {kills} kill(s) with your {gun_used}! "
            else:
                resp += f"Enemy retreated from your attack. Your aim is steady, but the battle rages on. "
        else:
            if random.random() < 0.3 and state["revives"] < 1:
                state["revives"] += 1
                if state["plates"] > 0:
                    lost_plate = 1
                    state["plates"] = max(state["plates"] - lost_plate, 0)
                    resp += f"Downed but you managed a self-revive (lost {lost_plate} plate). Your determination shines through. "
                else:
                    resp += "Downed but self-revived despite having no plates! "
            else:
                lost_plate = random.randint(1, 2)
                state["plates"] = max(state["plates"] - lost_plate, 0)
                state["in_gulag"] = True
                state["status"] = "gulag"
                resp += f"Downed by enemy's {gun_used} shot and lost {lost_plate} plate(s)! You're now in Gulag. Use !gulag to fight your opponent."
                return limit_response(resp)
    
    elif event == "loot":
        loot = random.choice(["weapon", "ammo", "armor", "plate"])
        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. It might just turn the tide of battle. "
        elif loot == "ammo":
            add_ammo = random.randint(10, 30)
            state["ammo"] += add_ammo
            resp += f"Found {add_ammo} rounds of ammo on the ground. More firepower is always welcome. "
        elif loot == "armor":
            add_arm = random.randint(5, 20)
            state["armor"] += add_arm
            resp += f"Picked up {add_arm} armor points to bolster your defense. Stay protected! "
        else:  # 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)! Your protection increases. "
            else:
                resp += "Plates are already maxed out. "
    
    elif event == "buy":
        item = random.choice(["UAV", "Air Strike", "Cluster Strike", "Armor Box", "Plates"])
        if item in ["UAV", "Air Strike"]:
            state["equipment"].append(item)
            state["bonus"] += 0.3
            resp += f"Purchased {item}, giving you an edge on the battlefield. Your kill potential rises! "
        elif item == "Armor Box":
            state["armor"] += 10
            resp += "Acquired an Armor Box to reinforce your defense. "
        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 maxed. "
    
    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 turned into a firefight and you secured {kills} kill(s) using a {gun_used}! "
            else:
                resp += "Managed to escape the ambush, but the threat still looms. "
        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 during the ambush. "
        else:
            kills = random.randint(1, 2)
            state["kills"] += kills
            state["players"] = max(state["players"] - kills, 1)
            resp += f"Overpowered the ambush and got {kills} kill(s) with your {gun_used}! "
    
    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']}. Congratulations, warrior! Use !start to play again."
    else:
        resp += f"Remaining enemies: {state['players']}. Total Kills: {state['kills']}. Plates remaining: {state['plates']}. Stay alert!"
    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... "
    if random.random() < (0.6 + state["bonus"] * 0.05):
        state["status"] = "active"
        state["in_gulag"] = False
        state["players"] = max(state["players"] - 5, 1)
        resp = waiting_msg + "Opponent engaged! You won the Gulag fight and are back in action. Use !fight to continue."
    else:
        state["status"] = "eliminated"
        resp = waiting_msg + f"Opponent overpowered you. Game over. Final Kills: {state['kills']}. Use !start to begin a new game."
    return limit_response(resp)

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