Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,15 @@ import random
|
|
3 |
|
4 |
app = Flask(__name__)
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
# In-memory storage for each player's game state.
|
7 |
game_states = {}
|
8 |
|
@@ -55,7 +64,7 @@ def fight():
|
|
55 |
return limit_response("Start game first with !start")
|
56 |
state = game_states[user]
|
57 |
|
58 |
-
# If game
|
59 |
if state["status"] != "active":
|
60 |
msg = f"Game over. Final Kills: {state['kills']}. "
|
61 |
if state["status"] == "won":
|
@@ -66,7 +75,7 @@ def fight():
|
|
66 |
msg += "You're 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 |
state["round"] += 1
|
72 |
r = state["round"]
|
@@ -74,10 +83,9 @@ def fight():
|
|
74 |
event = random.choice(["fight", "loot", "buy", "ambush"])
|
75 |
resp = f"R{r}: "
|
76 |
|
77 |
-
# ---- FIGHT EVENT ----
|
78 |
if event == "fight":
|
79 |
-
#
|
80 |
-
if "Air Strike" in state["equipment"] and random.random() <
|
81 |
kills = random.randint(2, 3)
|
82 |
state["kills"] += kills
|
83 |
state["players"] = max(state["players"] - kills, 1)
|
@@ -85,7 +93,7 @@ def fight():
|
|
85 |
resp += f"You called in an Air Strike! It obliterated {kills} enemies. "
|
86 |
state["equipment"].remove("Air Strike")
|
87 |
else:
|
88 |
-
# Select one of 15 gunfight scenarios.
|
89 |
scenario = random.randint(1,15)
|
90 |
gun_used = random.choice(["M4", "AK-47", "Shotgun", "Sniper", "SMG"])
|
91 |
downed = False
|
@@ -142,7 +150,6 @@ def fight():
|
|
142 |
resp += f"In the chaos, you managed no kills and were left vulnerable."
|
143 |
if random.random() < 0.5:
|
144 |
downed = True
|
145 |
-
# In final round, force at least one kill if not downed.
|
146 |
if final_round and not downed and kills == 0:
|
147 |
kills = 1
|
148 |
resp += f"Under final round pressure, you managed a desperate 1 kill with your {gun_used}. "
|
@@ -150,15 +157,14 @@ def fight():
|
|
150 |
if kills > 0:
|
151 |
state["players"] = max(state["players"] - kills, 1)
|
152 |
state["ammo"] = max(state["ammo"] - random.randint(5,10), 0)
|
153 |
-
# Additional chance to lose a plate from
|
154 |
-
if not downed and random.random() <
|
155 |
lost = 1
|
156 |
state["plates"] = max(state["plates"] - lost, 0)
|
157 |
resp += f"Amid the firefight, you lost {lost} plate from enemy fire. "
|
158 |
-
|
159 |
-
# If downed, try self-revive (low chance) or enter Gulag.
|
160 |
if downed:
|
161 |
-
if random.random() <
|
162 |
state["revives"] += 1
|
163 |
if state["plates"] > 0:
|
164 |
lost_plate = 1
|
@@ -169,7 +175,6 @@ def fight():
|
|
169 |
else:
|
170 |
lost_plate = random.randint(1, 2)
|
171 |
state["plates"] = max(state["plates"] - lost_plate, 0)
|
172 |
-
# First downing: free Gulag chance; afterward, need a token.
|
173 |
if state["gulag_count"] == 0:
|
174 |
state["gulag_count"] += 1
|
175 |
state["in_gulag"] = True
|
@@ -189,7 +194,6 @@ def fight():
|
|
189 |
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."
|
190 |
return limit_response(resp)
|
191 |
|
192 |
-
# ---- LOOT EVENT ----
|
193 |
elif event == "loot":
|
194 |
loot = random.choice(["weapon", "ammo", "armor", "plate", "gulag token"])
|
195 |
if loot == "weapon":
|
@@ -214,14 +218,12 @@ def fight():
|
|
214 |
else:
|
215 |
resp += "Plates are already maxed out. "
|
216 |
elif loot == "gulag token":
|
217 |
-
# Only allow picking up if you've been to gulag and don't already have one.
|
218 |
if state["gulag_count"] > 0 and state["gulag_tokens"] == 0:
|
219 |
state["gulag_tokens"] = 1
|
220 |
resp += "Found a Gulag Token on the battlefield! "
|
221 |
else:
|
222 |
resp += "No useful token found. "
|
223 |
|
224 |
-
# ---- BUY EVENT ----
|
225 |
elif event == "buy":
|
226 |
item = random.choice(["UAV", "Air Strike", "Cluster Strike", "Armor Box", "Plates", "Gulag Token"])
|
227 |
if item in ["UAV", "Air Strike"]:
|
@@ -248,7 +250,6 @@ def fight():
|
|
248 |
else:
|
249 |
resp += "No need for a token right now. "
|
250 |
|
251 |
-
# ---- AMBUSH EVENT ----
|
252 |
elif event == "ambush":
|
253 |
resp += "Ambushed! "
|
254 |
amb = random.choice(["escaped", "lost ammo", "got a kill"])
|
@@ -271,12 +272,10 @@ def fight():
|
|
271 |
state["players"] = max(state["players"] - kills, 1)
|
272 |
resp += f"Overpowered the ambushers and secured {kills} kill(s) with your {gun_used}! "
|
273 |
|
274 |
-
# Natural eliminations always occur.
|
275 |
nat = random.randint(5, 15)
|
276 |
state["players"] = max(state["players"] - nat, 1)
|
277 |
resp += f"Additionally, {nat} enemies were eliminated naturally. "
|
278 |
|
279 |
-
# Check for game win.
|
280 |
if state["players"] <= 1:
|
281 |
state["status"] = "won"
|
282 |
resp += f"Victory! Final Kills: {state['kills']}. You emerged triumphant, warrior! Use !start to play again."
|
@@ -296,13 +295,12 @@ def gulag():
|
|
296 |
|
297 |
waiting_msg = "In Gulag: waiting for an opponent... "
|
298 |
outcome = random.random()
|
299 |
-
|
300 |
-
if outcome < 0.35:
|
301 |
state["status"] = "active"
|
302 |
state["in_gulag"] = False
|
303 |
state["players"] = max(state["players"] - random.randint(2,5), 1)
|
304 |
resp = waiting_msg + "After a fierce duel, you won the Gulag fight and return to battle. Use !fight to continue."
|
305 |
-
elif outcome <
|
306 |
state["status"] = "eliminated"
|
307 |
resp = waiting_msg + f"Your opponent proved too strong. You were eliminated in Gulag. Final Kills: {state['kills']}. Use !start to play again."
|
308 |
else:
|
|
|
3 |
|
4 |
app = Flask(__name__)
|
5 |
|
6 |
+
# ---------------- Configuration ----------------
|
7 |
+
# Adjust these values to tune game difficulty:
|
8 |
+
AIR_STRIKE_CHANCE = 0.15 # Chance (15%) to call in an Air Strike if available
|
9 |
+
SELF_REVIVE_CHANCE = 0.10 # Chance (10%) to self-revive when downed
|
10 |
+
EXTRA_LOST_PLATE_CHANCE = 0.30 # Chance (30%) to lose an extra plate from enemy fire
|
11 |
+
GULAG_WIN_THRESHOLD = 0.35 # In Gulag: outcome <35% = win (return to battle)
|
12 |
+
GULAG_ELIMINATED_THRESHOLD = 0.65 # In Gulag: outcome >=35% and <65% = eliminated; >=65% = stalemate (lose a plate and try again)
|
13 |
+
# ------------------------------------------------
|
14 |
+
|
15 |
# In-memory storage for each player's game state.
|
16 |
game_states = {}
|
17 |
|
|
|
64 |
return limit_response("Start game first with !start")
|
65 |
state = game_states[user]
|
66 |
|
67 |
+
# If game is over, display final result.
|
68 |
if state["status"] != "active":
|
69 |
msg = f"Game over. Final Kills: {state['kills']}. "
|
70 |
if state["status"] == "won":
|
|
|
75 |
msg += "You're in Gulag! Use !gulag to fight your opponent."
|
76 |
return limit_response(msg)
|
77 |
|
78 |
+
# Adjust effective bonus if no plates remain.
|
79 |
effective_bonus = state["bonus"] if state["plates"] > 0 else state["bonus"] * 0.7
|
80 |
state["round"] += 1
|
81 |
r = state["round"]
|
|
|
83 |
event = random.choice(["fight", "loot", "buy", "ambush"])
|
84 |
resp = f"R{r}: "
|
85 |
|
|
|
86 |
if event == "fight":
|
87 |
+
# Air Strike branch (if available)
|
88 |
+
if "Air Strike" in state["equipment"] and random.random() < AIR_STRIKE_CHANCE:
|
89 |
kills = random.randint(2, 3)
|
90 |
state["kills"] += kills
|
91 |
state["players"] = max(state["players"] - kills, 1)
|
|
|
93 |
resp += f"You called in an Air Strike! It obliterated {kills} enemies. "
|
94 |
state["equipment"].remove("Air Strike")
|
95 |
else:
|
96 |
+
# Select one of 15 detailed gunfight scenarios.
|
97 |
scenario = random.randint(1,15)
|
98 |
gun_used = random.choice(["M4", "AK-47", "Shotgun", "Sniper", "SMG"])
|
99 |
downed = False
|
|
|
150 |
resp += f"In the chaos, you managed no kills and were left vulnerable."
|
151 |
if random.random() < 0.5:
|
152 |
downed = True
|
|
|
153 |
if final_round and not downed and kills == 0:
|
154 |
kills = 1
|
155 |
resp += f"Under final round pressure, you managed a desperate 1 kill with your {gun_used}. "
|
|
|
157 |
if kills > 0:
|
158 |
state["players"] = max(state["players"] - kills, 1)
|
159 |
state["ammo"] = max(state["ammo"] - random.randint(5,10), 0)
|
160 |
+
# Additional chance to lose a plate from enemy fire.
|
161 |
+
if not downed and random.random() < EXTRA_LOST_PLATE_CHANCE:
|
162 |
lost = 1
|
163 |
state["plates"] = max(state["plates"] - lost, 0)
|
164 |
resp += f"Amid the firefight, you lost {lost} plate from enemy fire. "
|
165 |
+
# If downed, try self-revive; if unsuccessful, enter Gulag.
|
|
|
166 |
if downed:
|
167 |
+
if random.random() < SELF_REVIVE_CHANCE:
|
168 |
state["revives"] += 1
|
169 |
if state["plates"] > 0:
|
170 |
lost_plate = 1
|
|
|
175 |
else:
|
176 |
lost_plate = random.randint(1, 2)
|
177 |
state["plates"] = max(state["plates"] - lost_plate, 0)
|
|
|
178 |
if state["gulag_count"] == 0:
|
179 |
state["gulag_count"] += 1
|
180 |
state["in_gulag"] = True
|
|
|
194 |
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."
|
195 |
return limit_response(resp)
|
196 |
|
|
|
197 |
elif event == "loot":
|
198 |
loot = random.choice(["weapon", "ammo", "armor", "plate", "gulag token"])
|
199 |
if loot == "weapon":
|
|
|
218 |
else:
|
219 |
resp += "Plates are already maxed out. "
|
220 |
elif loot == "gulag token":
|
|
|
221 |
if state["gulag_count"] > 0 and state["gulag_tokens"] == 0:
|
222 |
state["gulag_tokens"] = 1
|
223 |
resp += "Found a Gulag Token on the battlefield! "
|
224 |
else:
|
225 |
resp += "No useful token found. "
|
226 |
|
|
|
227 |
elif event == "buy":
|
228 |
item = random.choice(["UAV", "Air Strike", "Cluster Strike", "Armor Box", "Plates", "Gulag Token"])
|
229 |
if item in ["UAV", "Air Strike"]:
|
|
|
250 |
else:
|
251 |
resp += "No need for a token right now. "
|
252 |
|
|
|
253 |
elif event == "ambush":
|
254 |
resp += "Ambushed! "
|
255 |
amb = random.choice(["escaped", "lost ammo", "got a kill"])
|
|
|
272 |
state["players"] = max(state["players"] - kills, 1)
|
273 |
resp += f"Overpowered the ambushers and secured {kills} kill(s) with your {gun_used}! "
|
274 |
|
|
|
275 |
nat = random.randint(5, 15)
|
276 |
state["players"] = max(state["players"] - nat, 1)
|
277 |
resp += f"Additionally, {nat} enemies were eliminated naturally. "
|
278 |
|
|
|
279 |
if state["players"] <= 1:
|
280 |
state["status"] = "won"
|
281 |
resp += f"Victory! Final Kills: {state['kills']}. You emerged triumphant, warrior! Use !start to play again."
|
|
|
295 |
|
296 |
waiting_msg = "In Gulag: waiting for an opponent... "
|
297 |
outcome = random.random()
|
298 |
+
if outcome < GULAG_WIN_THRESHOLD:
|
|
|
299 |
state["status"] = "active"
|
300 |
state["in_gulag"] = False
|
301 |
state["players"] = max(state["players"] - random.randint(2,5), 1)
|
302 |
resp = waiting_msg + "After a fierce duel, you won the Gulag fight and return to battle. Use !fight to continue."
|
303 |
+
elif outcome < GULAG_ELIMINATED_THRESHOLD:
|
304 |
state["status"] = "eliminated"
|
305 |
resp = waiting_msg + f"Your opponent proved too strong. You were eliminated in Gulag. Final Kills: {state['kills']}. Use !start to play again."
|
306 |
else:
|