File size: 5,120 Bytes
15ba985
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from flask import Flask, request
import random

app = Flask(__name__)

# In-memory storage for each player's game state.
game_states = {}

# Helper to ensure responses never exceed 400 characters.
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,         # self-revives used
        "ammo": 100,
        "armor": 100,
        "inventory": [],
        "in_gulag": False
    }

@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"), 400
    game_states[user] = init_game(user, loadout)
    resp = (f"Game started for {user}! Players:150, Bonus:{game_states[user]['bonus']:.1f}. "
            "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"), 400
    state = game_states[user]
    if state["status"] != "active":
        return limit_response(f"Game over. Final Kills: {state['kills']}."), 400
    state["round"] += 1
    r = state["round"]
    event = random.choice(["fight", "loot", "buy", "ambush"])
    resp = f"R{r}: "
    if event == "fight":
        roll = random.random() * state["bonus"]
        if 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"Fought & got {kills} kill(s)! "
        elif roll > 0.5:
            resp += "Enemy fled! "
        else:
            if random.random() < 0.3 and state["revives"] < 1:
                state["revives"] += 1
                resp += "Downed but self-revived! "
            else:
                state["in_gulag"] = True
                state["status"] = "gulag"
                return limit_response(resp + "Downed! Now in Gulag. Use !gulag.")
    elif event == "loot":
        loot = random.choice(["weapon", "ammo", "armor"])
        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"Found {wpn}. "
        elif loot == "ammo":
            add_ammo = random.randint(10,30)
            state["ammo"] += add_ammo
            resp += f"Found {add_ammo} ammo. "
        else:
            add_arm = random.randint(5,20)
            state["armor"] += add_arm
            resp += f"Found {add_arm} armor. "
    elif event == "buy":
        item = random.choice(["UAV", "Air Strike", "Cluster Strike", "Armor Box"])
        if item == "Armor Box":
            state["armor"] += 10
        else:
            state["bonus"] += 0.15
        resp += f"Bought {item}. "
    elif event == "ambush":
        resp += "Ambushed! "
        amb = random.choice(["escaped", "lost ammo", "got a kill"])
        if amb == "escaped":
            resp += "Escaped. "
        elif amb == "lost ammo":
            lost = random.randint(10,20)
            state["ammo"] = max(state["ammo"] - lost, 0)
            resp += f"Lost {lost} ammo. "
        else:
            kills = random.randint(1,2)
            state["kills"] += kills
            state["players"] = max(state["players"] - kills, 1)
            resp += f"Got {kills} kill(s)! "
    # Natural eliminations
    nat = random.randint(5,15)
    state["players"] = max(state["players"] - nat, 1)
    resp += f"Nat:{nat}. "
    if state["players"] <= 1:
        state["status"] = "won"
        resp += f"Victory! Final Kills: {state['kills']}."
    else:
        resp += f"Left:{state['players']}, Kills:{state['kills']}."
    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"), 400
    state = game_states[user]
    if not state.get("in_gulag"):
        return limit_response("Not in Gulag."), 400
    if random.random() < (0.6 + state["bonus"] * 0.05):
        state["status"] = "active"
        state["in_gulag"] = False
        state["players"] = max(state["players"] - 5, 1)
        resp = "Won Gulag fight! Back in action. Use !fight next."
    else:
        state["status"] = "eliminated"
        resp = f"Lost Gulag fight. Game over. Final Kills: {state['kills']}."
    return limit_response(resp)

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