Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -20,17 +20,17 @@ def init_game(username, loadout):
|
|
20 |
"kills": 0,
|
21 |
"bonus": bonus,
|
22 |
"round": 0,
|
23 |
-
"status": "active",
|
24 |
"revives": 0,
|
25 |
"ammo": 100,
|
26 |
"armor": 100,
|
27 |
"inventory": [],
|
28 |
-
"equipment": [],
|
29 |
"plates": 3,
|
30 |
"max_plates": 12,
|
31 |
"in_gulag": False,
|
32 |
-
"gulag_count": 0,
|
33 |
-
"gulag_tokens": 0
|
34 |
}
|
35 |
|
36 |
@app.route("/")
|
@@ -45,7 +45,7 @@ def start():
|
|
45 |
return limit_response("User required")
|
46 |
game_states[user] = init_game(user, loadout)
|
47 |
resp = (f"Game started for {user}! Players:150, Bonus:{game_states[user]['bonus']:.1f}, Plates:3. "
|
48 |
-
"Prepare for
|
49 |
return limit_response(resp)
|
50 |
|
51 |
@app.route("/fight", methods=["GET"])
|
@@ -54,78 +54,91 @@ def fight():
|
|
54 |
if not user or user not in game_states:
|
55 |
return limit_response("Start game first with !start")
|
56 |
state = game_states[user]
|
57 |
-
|
58 |
-
# If the game is over, just display final results.
|
59 |
if state["status"] != "active":
|
60 |
msg = f"Game over. Final Kills: {state['kills']}. "
|
61 |
if state["status"] == "won":
|
62 |
-
msg += "You emerged victorious! Use !start to
|
63 |
elif state["status"] == "eliminated":
|
64 |
msg += "You were eliminated. Use !start to try again."
|
65 |
elif state["status"] == "gulag":
|
66 |
msg += "You are in Gulag! Use !gulag to fight your opponent."
|
67 |
return limit_response(msg)
|
68 |
|
69 |
-
#
|
70 |
effective_bonus = state["bonus"] if state["plates"] > 0 else state["bonus"] * 0.7
|
71 |
-
|
72 |
state["round"] += 1
|
73 |
r = state["round"]
|
74 |
final_round = state["players"] <= 3
|
75 |
event = random.choice(["fight", "loot", "buy", "ambush"])
|
76 |
resp = f"R{r}: "
|
77 |
-
|
|
|
78 |
if event == "fight":
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
kills = random.randint(
|
83 |
state["kills"] += kills
|
84 |
state["players"] = max(state["players"] - kills, 1)
|
85 |
state["ammo"] = max(state["ammo"] - random.randint(5,15), 0)
|
86 |
-
resp += f"
|
87 |
-
|
88 |
-
if final_round:
|
89 |
-
kills = random.randint(1, 3)
|
90 |
-
state["kills"] += kills
|
91 |
-
state["players"] = max(state["players"] - kills, 1)
|
92 |
-
resp += f"Final showdown: achieved {kills} kill(s) with your {gun_used}! "
|
93 |
-
else:
|
94 |
-
resp += f"Enemy retreated from your precise fire with your {gun_used}. Your focus remains sharp. "
|
95 |
else:
|
96 |
-
#
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
state["plates"] = max(state["plates"] -
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
|
|
|
129 |
elif event == "loot":
|
130 |
loot = random.choice(["weapon", "ammo", "armor", "plate", "gulag token"])
|
131 |
if loot == "weapon":
|
@@ -133,35 +146,40 @@ def fight():
|
|
133 |
state["inventory"].append(wpn)
|
134 |
if wpn.lower() in ["ak-47", "m4", "mp5", "ar-15"]:
|
135 |
state["bonus"] += 0.2
|
136 |
-
resp += f"You scavenged a {wpn} from the
|
137 |
elif loot == "ammo":
|
138 |
add_ammo = random.randint(10, 30)
|
139 |
state["ammo"] += add_ammo
|
140 |
-
resp += f"Found {add_ammo} rounds of ammo.
|
141 |
elif loot == "armor":
|
142 |
add_arm = random.randint(5, 20)
|
143 |
state["armor"] += add_arm
|
144 |
-
resp += f"Picked up {add_arm} armor points
|
145 |
elif loot == "plate":
|
146 |
if state["plates"] < state["max_plates"]:
|
147 |
new_plates = random.randint(1, 3)
|
148 |
state["plates"] = min(state["plates"] + new_plates, state["max_plates"])
|
149 |
-
resp += f"Discovered {new_plates} extra plate(s)!
|
150 |
else:
|
151 |
resp += "Plates are already maxed out. "
|
152 |
elif loot == "gulag token":
|
153 |
-
|
154 |
-
|
|
|
|
|
|
|
|
|
155 |
|
|
|
156 |
elif event == "buy":
|
157 |
item = random.choice(["UAV", "Air Strike", "Cluster Strike", "Armor Box", "Plates", "Gulag Token"])
|
158 |
if item in ["UAV", "Air Strike"]:
|
159 |
state["equipment"].append(item)
|
160 |
state["bonus"] += 0.3
|
161 |
-
resp += f"Purchased {item}, boosting your
|
162 |
elif item == "Armor Box":
|
163 |
state["armor"] += 10
|
164 |
-
resp += "Acquired an Armor Box to
|
165 |
elif item == "Cluster Strike":
|
166 |
state["bonus"] += 0.15
|
167 |
resp += "Bought a Cluster Strike to thin out the opposition. "
|
@@ -173,9 +191,14 @@ def fight():
|
|
173 |
else:
|
174 |
resp += "Your plates are already at maximum. "
|
175 |
elif item == "Gulag Token":
|
176 |
-
|
177 |
-
|
|
|
|
|
|
|
|
|
178 |
|
|
|
179 |
elif event == "ambush":
|
180 |
resp += "Ambushed! "
|
181 |
amb = random.choice(["escaped", "lost ammo", "got a kill"])
|
@@ -187,27 +210,28 @@ def fight():
|
|
187 |
state["players"] = max(state["players"] - kills, 1)
|
188 |
resp += f"Ambush escalated into a firefight and you secured {kills} kill(s) with your {gun_used}! "
|
189 |
else:
|
190 |
-
resp += "Managed to evade the ambush, but
|
191 |
elif amb == "lost ammo":
|
192 |
lost = random.randint(10, 20)
|
193 |
state["ammo"] = max(state["ammo"] - lost, 0)
|
194 |
-
resp += f"Got caught off guard and lost {lost} ammo
|
195 |
else:
|
196 |
kills = random.randint(1, 2)
|
197 |
state["kills"] += kills
|
198 |
state["players"] = max(state["players"] - kills, 1)
|
199 |
-
resp += f"Overpowered the
|
200 |
-
|
|
|
201 |
nat = random.randint(5, 15)
|
202 |
state["players"] = max(state["players"] - nat, 1)
|
203 |
resp += f"Additionally, {nat} enemies were eliminated naturally. "
|
204 |
-
|
205 |
if state["players"] <= 1:
|
206 |
state["status"] = "won"
|
207 |
resp += f"Victory! Final Kills: {state['kills']}. You emerged triumphant, warrior! Use !start to play again."
|
208 |
else:
|
209 |
resp += (f"Remaining enemies: {state['players']}. Total Kills: {state['kills']}. "
|
210 |
-
f"Plates remaining: {state['plates']}.
|
211 |
return limit_response(resp)
|
212 |
|
213 |
@app.route("/gulag", methods=["GET"])
|
@@ -220,14 +244,21 @@ def gulag():
|
|
220 |
return limit_response("You're not in Gulag. If downed, use !gulag to fight your opponent.")
|
221 |
|
222 |
waiting_msg = "In Gulag: waiting for an opponent... "
|
223 |
-
|
|
|
|
|
224 |
state["status"] = "active"
|
225 |
state["in_gulag"] = False
|
226 |
-
state["players"] = max(state["players"] - 5, 1)
|
227 |
-
resp = waiting_msg + "
|
228 |
-
|
229 |
state["status"] = "eliminated"
|
230 |
-
resp = waiting_msg + f"
|
|
|
|
|
|
|
|
|
|
|
231 |
return limit_response(resp)
|
232 |
|
233 |
if __name__ == "__main__":
|
|
|
20 |
"kills": 0,
|
21 |
"bonus": bonus,
|
22 |
"round": 0,
|
23 |
+
"status": "active", # active, gulag, eliminated, won
|
24 |
"revives": 0,
|
25 |
"ammo": 100,
|
26 |
"armor": 100,
|
27 |
"inventory": [],
|
28 |
+
"equipment": [], # e.g. "UAV", "Air Strike"
|
29 |
"plates": 3,
|
30 |
"max_plates": 12,
|
31 |
"in_gulag": False,
|
32 |
+
"gulag_count": 0, # number of times you've been downed
|
33 |
+
"gulag_tokens": 0 # only obtainable AFTER your first gulag
|
34 |
}
|
35 |
|
36 |
@app.route("/")
|
|
|
45 |
return limit_response("User required")
|
46 |
game_states[user] = init_game(user, loadout)
|
47 |
resp = (f"Game started for {user}! Players:150, Bonus:{game_states[user]['bonus']:.1f}, Plates:3. "
|
48 |
+
"Prepare for combat! Use !fight to engage.")
|
49 |
return limit_response(resp)
|
50 |
|
51 |
@app.route("/fight", methods=["GET"])
|
|
|
54 |
if not user or user not in game_states:
|
55 |
return limit_response("Start game first with !start")
|
56 |
state = game_states[user]
|
57 |
+
# If game already ended, return final results.
|
|
|
58 |
if state["status"] != "active":
|
59 |
msg = f"Game over. Final Kills: {state['kills']}. "
|
60 |
if state["status"] == "won":
|
61 |
+
msg += "You emerged victorious! Use !start to begin a new game."
|
62 |
elif state["status"] == "eliminated":
|
63 |
msg += "You were eliminated. Use !start to try again."
|
64 |
elif state["status"] == "gulag":
|
65 |
msg += "You are in Gulag! Use !gulag to fight your opponent."
|
66 |
return limit_response(msg)
|
67 |
|
68 |
+
# If no plates, effective bonus is reduced.
|
69 |
effective_bonus = state["bonus"] if state["plates"] > 0 else state["bonus"] * 0.7
|
|
|
70 |
state["round"] += 1
|
71 |
r = state["round"]
|
72 |
final_round = state["players"] <= 3
|
73 |
event = random.choice(["fight", "loot", "buy", "ambush"])
|
74 |
resp = f"R{r}: "
|
75 |
+
|
76 |
+
# -- FIGHT EVENT --
|
77 |
if event == "fight":
|
78 |
+
# Check for Air Strike usage if available.
|
79 |
+
if "Air Strike" in state["equipment"] and random.random() < 0.3:
|
80 |
+
# Special air strike outcome.
|
81 |
+
kills = random.randint(2, 4)
|
82 |
state["kills"] += kills
|
83 |
state["players"] = max(state["players"] - kills, 1)
|
84 |
state["ammo"] = max(state["ammo"] - random.randint(5,15), 0)
|
85 |
+
resp += f"You called in an Air Strike! It obliterated {kills} enemies. "
|
86 |
+
state["equipment"].remove("Air Strike")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
else:
|
88 |
+
# Choose one of 10 detailed gunfight scenarios.
|
89 |
+
scenario = random.randint(1,10)
|
90 |
+
gun_used = random.choice(["M4", "AK-47", "Shotgun", "Sniper", "SMG"])
|
91 |
+
if scenario == 1:
|
92 |
+
kills = random.randint(1,2)
|
93 |
+
resp += f"Your precision shot with the {gun_used} downed {kills} foe(s). "
|
94 |
+
elif scenario == 2:
|
95 |
+
kills = 1
|
96 |
+
resp += f"You outmaneuvered an enemy and secured a kill with your {gun_used}. "
|
97 |
+
elif scenario == 3:
|
98 |
+
resp += f"Your shot missed badly with the {gun_used}! The enemy counterattacked and you lost a plate. "
|
99 |
+
state["plates"] = max(state["plates"] - 1, 0)
|
100 |
+
kills = 0
|
101 |
+
elif scenario == 4:
|
102 |
+
kills = random.randint(2,3)
|
103 |
+
resp += f"A burst from your {gun_used} decimated multiple foes, earning you {kills} kill(s). "
|
104 |
+
elif scenario == 5:
|
105 |
+
kills = random.randint(1,3)
|
106 |
+
resp += f"Overwhelming firepower from your {gun_used} got {kills} kill(s), but you overexerted and lost a plate. "
|
107 |
+
state["plates"] = max(state["plates"] - 1, 0)
|
108 |
+
elif scenario == 6:
|
109 |
+
kills = 1
|
110 |
+
resp += f"An enemy flanked you, but you quickly retaliated with your {gun_used} for 1 kill, losing a plate in the scramble. "
|
111 |
+
state["plates"] = max(state["plates"] - 1, 0)
|
112 |
+
elif scenario == 7:
|
113 |
+
resp += f"Your {gun_used} jammed at a critical moment! You dodged a deadly shot but lost a plate. "
|
114 |
+
state["plates"] = max(state["plates"] - 1, 0)
|
115 |
+
kills = 0
|
116 |
+
elif scenario == 8:
|
117 |
+
kills = 1
|
118 |
+
resp += f"Your rapid reload with the {gun_used} turned the tide, securing 1 kill at a small ammo cost. "
|
119 |
+
elif scenario == 9:
|
120 |
+
kills = 1
|
121 |
+
resp += f"A lucky shot from your {gun_used} knocked an enemy out; however, you lost a plate in the exchange. "
|
122 |
+
state["plates"] = max(state["plates"] - 1, 0)
|
123 |
+
elif scenario == 10:
|
124 |
+
kills = 0
|
125 |
+
resp += f"Your evasive maneuvers with the {gun_used} avoided danger but yielded no kills. "
|
126 |
+
# In final round, force at least one kill if outcome would be 0.
|
127 |
+
if final_round and kills == 0:
|
128 |
+
kills = 1
|
129 |
+
resp += f"Final round pressure: you managed to secure 1 kill with your {gun_used}. "
|
130 |
+
state["kills"] += kills
|
131 |
+
if kills > 0:
|
132 |
+
state["players"] = max(state["players"] - kills, 1)
|
133 |
+
state["ammo"] = max(state["ammo"] - random.randint(5,15), 0)
|
134 |
+
|
135 |
+
# Chance to get additional damage from enemy fire even if you killed enemies.
|
136 |
+
if random.random() < 0.2 and state["plates"] > 0:
|
137 |
+
lost = 1
|
138 |
+
state["plates"] = max(state["plates"] - lost, 0)
|
139 |
+
resp += f"In the exchange, you also lost {lost} plate. "
|
140 |
|
141 |
+
# -- LOOT EVENT --
|
142 |
elif event == "loot":
|
143 |
loot = random.choice(["weapon", "ammo", "armor", "plate", "gulag token"])
|
144 |
if loot == "weapon":
|
|
|
146 |
state["inventory"].append(wpn)
|
147 |
if wpn.lower() in ["ak-47", "m4", "mp5", "ar-15"]:
|
148 |
state["bonus"] += 0.2
|
149 |
+
resp += f"You scavenged a {wpn} from the wreckage. "
|
150 |
elif loot == "ammo":
|
151 |
add_ammo = random.randint(10, 30)
|
152 |
state["ammo"] += add_ammo
|
153 |
+
resp += f"Found {add_ammo} rounds of ammo. "
|
154 |
elif loot == "armor":
|
155 |
add_arm = random.randint(5, 20)
|
156 |
state["armor"] += add_arm
|
157 |
+
resp += f"Picked up {add_arm} armor points. "
|
158 |
elif loot == "plate":
|
159 |
if state["plates"] < state["max_plates"]:
|
160 |
new_plates = random.randint(1, 3)
|
161 |
state["plates"] = min(state["plates"] + new_plates, state["max_plates"])
|
162 |
+
resp += f"Discovered {new_plates} extra plate(s)! "
|
163 |
else:
|
164 |
resp += "Plates are already maxed out. "
|
165 |
elif loot == "gulag token":
|
166 |
+
# Only allow picking up a token if you've been in Gulag already and don't already have one.
|
167 |
+
if state["gulag_count"] > 0 and state["gulag_tokens"] == 0:
|
168 |
+
state["gulag_tokens"] = 1
|
169 |
+
resp += "Found a Gulag Token on the battlefield! "
|
170 |
+
else:
|
171 |
+
resp += "No useful token found. "
|
172 |
|
173 |
+
# -- BUY EVENT --
|
174 |
elif event == "buy":
|
175 |
item = random.choice(["UAV", "Air Strike", "Cluster Strike", "Armor Box", "Plates", "Gulag Token"])
|
176 |
if item in ["UAV", "Air Strike"]:
|
177 |
state["equipment"].append(item)
|
178 |
state["bonus"] += 0.3
|
179 |
+
resp += f"Purchased {item}, boosting your firepower! "
|
180 |
elif item == "Armor Box":
|
181 |
state["armor"] += 10
|
182 |
+
resp += "Acquired an Armor Box to reinforce your defenses. "
|
183 |
elif item == "Cluster Strike":
|
184 |
state["bonus"] += 0.15
|
185 |
resp += "Bought a Cluster Strike to thin out the opposition. "
|
|
|
191 |
else:
|
192 |
resp += "Your plates are already at maximum. "
|
193 |
elif item == "Gulag Token":
|
194 |
+
# Only allow buying a token if you've been to gulag and don't already have one.
|
195 |
+
if state["gulag_count"] > 0 and state["gulag_tokens"] == 0:
|
196 |
+
state["gulag_tokens"] = 1
|
197 |
+
resp += "Purchased a Gulag Token for a second chance! "
|
198 |
+
else:
|
199 |
+
resp += "No need for a token right now. "
|
200 |
|
201 |
+
# -- AMBUSH EVENT --
|
202 |
elif event == "ambush":
|
203 |
resp += "Ambushed! "
|
204 |
amb = random.choice(["escaped", "lost ammo", "got a kill"])
|
|
|
210 |
state["players"] = max(state["players"] - kills, 1)
|
211 |
resp += f"Ambush escalated into a firefight and you secured {kills} kill(s) with your {gun_used}! "
|
212 |
else:
|
213 |
+
resp += "Managed to evade the ambush, but remain cautious. "
|
214 |
elif amb == "lost ammo":
|
215 |
lost = random.randint(10, 20)
|
216 |
state["ammo"] = max(state["ammo"] - lost, 0)
|
217 |
+
resp += f"Got caught off guard and lost {lost} ammo in the chaos. "
|
218 |
else:
|
219 |
kills = random.randint(1, 2)
|
220 |
state["kills"] += kills
|
221 |
state["players"] = max(state["players"] - kills, 1)
|
222 |
+
resp += f"Overpowered the ambushers and secured {kills} kill(s) with your {gun_used}! "
|
223 |
+
|
224 |
+
# Natural eliminations occur regardless.
|
225 |
nat = random.randint(5, 15)
|
226 |
state["players"] = max(state["players"] - nat, 1)
|
227 |
resp += f"Additionally, {nat} enemies were eliminated naturally. "
|
228 |
+
|
229 |
if state["players"] <= 1:
|
230 |
state["status"] = "won"
|
231 |
resp += f"Victory! Final Kills: {state['kills']}. You emerged triumphant, warrior! Use !start to play again."
|
232 |
else:
|
233 |
resp += (f"Remaining enemies: {state['players']}. Total Kills: {state['kills']}. "
|
234 |
+
f"Plates remaining: {state['plates']}.")
|
235 |
return limit_response(resp)
|
236 |
|
237 |
@app.route("/gulag", methods=["GET"])
|
|
|
244 |
return limit_response("You're not in Gulag. If downed, use !gulag to fight your opponent.")
|
245 |
|
246 |
waiting_msg = "In Gulag: waiting for an opponent... "
|
247 |
+
outcome = random.random()
|
248 |
+
# Multiple Gulag outcomes:
|
249 |
+
if outcome < 0.4:
|
250 |
state["status"] = "active"
|
251 |
state["in_gulag"] = False
|
252 |
+
state["players"] = max(state["players"] - random.randint(2,5), 1)
|
253 |
+
resp = waiting_msg + "After a fierce duel, you won the Gulag fight and return to battle. Use !fight to continue."
|
254 |
+
elif outcome < 0.7:
|
255 |
state["status"] = "eliminated"
|
256 |
+
resp = waiting_msg + f"Your opponent proved too strong. You were eliminated in Gulag. Final Kills: {state['kills']}. Use !start to play again."
|
257 |
+
else:
|
258 |
+
# Stalemate: you lose a plate and must fight again in Gulag.
|
259 |
+
if state["plates"] > 0:
|
260 |
+
state["plates"] = max(state["plates"] - 1, 0)
|
261 |
+
resp = waiting_msg + "The Gulag duel is inconclusive—you lost a plate and remain in Gulag. Use !gulag to try again."
|
262 |
return limit_response(resp)
|
263 |
|
264 |
if __name__ == "__main__":
|