tstone87 commited on
Commit
606c546
·
verified ·
1 Parent(s): 8a9ab6d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -32
app.py CHANGED
@@ -20,7 +20,7 @@ def init_game(username, loadout):
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,
@@ -28,7 +28,9 @@ def init_game(username, loadout):
28
  "equipment": [],
29
  "plates": 3,
30
  "max_plates": 12,
31
- "in_gulag": False
 
 
32
  }
33
 
34
  @app.route("/")
@@ -43,7 +45,7 @@ def start():
43
  return limit_response("User required")
44
  game_states[user] = init_game(user, loadout)
45
  resp = (f"Game started for {user}! Players:150, Bonus:{game_states[user]['bonus']:.1f}, Plates:3. "
46
- "Get ready for intense combat! Use !fight to engage.")
47
  return limit_response(resp)
48
 
49
  @app.route("/fight", methods=["GET"])
@@ -52,14 +54,19 @@ def fight():
52
  if not user or user not in game_states:
53
  return limit_response("Start game first with !start")
54
  state = game_states[user]
55
- # If game already ended, show final result.
 
56
  if state["status"] != "active":
57
- msg = f"Game over. Final Kills: {state['kills']}. Please use !start to begin a new game."
58
- if state["status"] == "gulag":
59
- msg = "You are in Gulag waiting for an opponent. Use !gulag to fight."
 
 
 
 
60
  return limit_response(msg)
61
 
62
- # If no plates, reduce effective bonus.
63
  effective_bonus = state["bonus"] if state["plates"] > 0 else state["bonus"] * 0.7
64
 
65
  state["round"] += 1
@@ -71,70 +78,90 @@ def fight():
71
  if event == "fight":
72
  roll = random.random() * effective_bonus
73
  gun_used = random.choice(["M4", "AK-47", "Shotgun", "Sniper", "SMG"])
74
- if final_round or roll > 0.7:
75
  kills = random.randint(1, 3)
76
  state["kills"] += kills
77
  state["players"] = max(state["players"] - kills, 1)
78
  state["ammo"] = max(state["ammo"] - random.randint(5,15), 0)
79
- resp += f"Engaged in a fierce gunfight and got {kills} kill(s)! Enemy downed with a {gun_used}. "
80
- elif roll > 0.5:
81
  if final_round:
82
  kills = random.randint(1, 3)
83
  state["kills"] += kills
84
  state["players"] = max(state["players"] - kills, 1)
85
- resp += f"Final round battle: secured {kills} kill(s) with your {gun_used}! "
86
  else:
87
- resp += f"Enemy retreated from your attack. Your aim is steady, but the battle rages on. "
88
  else:
 
89
  if random.random() < 0.3 and state["revives"] < 1:
90
  state["revives"] += 1
91
  if state["plates"] > 0:
92
  lost_plate = 1
93
  state["plates"] = max(state["plates"] - lost_plate, 0)
94
- resp += f"Downed but you managed a self-revive (lost {lost_plate} plate). Your determination shines through. "
95
  else:
96
- resp += "Downed but self-revived despite having no plates! "
97
  else:
98
  lost_plate = random.randint(1, 2)
99
  state["plates"] = max(state["plates"] - lost_plate, 0)
100
- state["in_gulag"] = True
101
- state["status"] = "gulag"
102
- 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."
103
- return limit_response(resp)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
 
105
  elif event == "loot":
106
- loot = random.choice(["weapon", "ammo", "armor", "plate"])
107
  if loot == "weapon":
108
  wpn = random.choice(["AK-47", "M4", "Shotgun", "Sniper"])
109
  state["inventory"].append(wpn)
110
  if wpn.lower() in ["ak-47", "m4", "mp5", "ar-15"]:
111
  state["bonus"] += 0.2
112
- resp += f"You scavenged a {wpn} from the wreckage. It might just turn the tide of battle. "
113
  elif loot == "ammo":
114
  add_ammo = random.randint(10, 30)
115
  state["ammo"] += add_ammo
116
- resp += f"Found {add_ammo} rounds of ammo on the ground. More firepower is always welcome. "
117
  elif loot == "armor":
118
  add_arm = random.randint(5, 20)
119
  state["armor"] += add_arm
120
- resp += f"Picked up {add_arm} armor points to bolster your defense. Stay protected! "
121
- else: # plate
122
  if state["plates"] < state["max_plates"]:
123
  new_plates = random.randint(1, 3)
124
  state["plates"] = min(state["plates"] + new_plates, state["max_plates"])
125
  resp += f"Discovered {new_plates} extra plate(s)! Your protection increases. "
126
  else:
127
  resp += "Plates are already maxed out. "
 
 
 
128
 
129
  elif event == "buy":
130
- item = random.choice(["UAV", "Air Strike", "Cluster Strike", "Armor Box", "Plates"])
131
  if item in ["UAV", "Air Strike"]:
132
  state["equipment"].append(item)
133
  state["bonus"] += 0.3
134
- resp += f"Purchased {item}, giving you an edge on the battlefield. Your kill potential rises! "
135
  elif item == "Armor Box":
136
  state["armor"] += 10
137
- resp += "Acquired an Armor Box to reinforce your defense. "
138
  elif item == "Cluster Strike":
139
  state["bonus"] += 0.15
140
  resp += "Bought a Cluster Strike to thin out the opposition. "
@@ -144,7 +171,10 @@ def fight():
144
  state["plates"] = min(state["plates"] + added, state["max_plates"])
145
  resp += f"Reinforced your gear with {added} extra plate(s)! "
146
  else:
147
- resp += "Your plates are already maxed. "
 
 
 
148
 
149
  elif event == "ambush":
150
  resp += "Ambushed! "
@@ -155,9 +185,9 @@ def fight():
155
  kills = random.randint(1, 2)
156
  state["kills"] += kills
157
  state["players"] = max(state["players"] - kills, 1)
158
- resp += f"Ambush turned into a firefight and you secured {kills} kill(s) using a {gun_used}! "
159
  else:
160
- resp += "Managed to escape the ambush, but the threat still looms. "
161
  elif amb == "lost ammo":
162
  lost = random.randint(10, 20)
163
  state["ammo"] = max(state["ammo"] - lost, 0)
@@ -174,9 +204,10 @@ def fight():
174
 
175
  if state["players"] <= 1:
176
  state["status"] = "won"
177
- resp += f"Victory! Final Kills: {state['kills']}. Congratulations, warrior! Use !start to play again."
178
  else:
179
- resp += f"Remaining enemies: {state['players']}. Total Kills: {state['kills']}. Plates remaining: {state['plates']}. Stay alert!"
 
180
  return limit_response(resp)
181
 
182
  @app.route("/gulag", methods=["GET"])
 
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,
 
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
  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 battle! 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
+
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 play again."
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
+ # Adjust effective bonus if no plates remain.
70
  effective_bonus = state["bonus"] if state["plates"] > 0 else state["bonus"] * 0.7
71
 
72
  state["round"] += 1
 
78
  if event == "fight":
79
  roll = random.random() * effective_bonus
80
  gun_used = random.choice(["M4", "AK-47", "Shotgun", "Sniper", "SMG"])
81
+ if final_round or roll > 0.8:
82
  kills = random.randint(1, 3)
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"Engaged in a brutal gunfight and secured {kills} kill(s)! Enemy downed with a {gun_used}. "
87
+ elif roll > 0.6:
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
+ # Attempt self-revive
97
  if random.random() < 0.3 and state["revives"] < 1:
98
  state["revives"] += 1
99
  if state["plates"] > 0:
100
  lost_plate = 1
101
  state["plates"] = max(state["plates"] - lost_plate, 0)
102
+ resp += f"Downed but self-revived (lost {lost_plate} plate). Your resolve is unbroken. "
103
  else:
104
+ resp += "Downed but managed a desperate self-revive despite having no plates! "
105
  else:
106
  lost_plate = random.randint(1, 2)
107
  state["plates"] = max(state["plates"] - lost_plate, 0)
108
+ # Check if this is the first Gulag chance
109
+ if state["gulag_count"] == 0:
110
+ state["gulag_count"] += 1
111
+ state["in_gulag"] = True
112
+ state["status"] = "gulag"
113
+ resp += f"Downed by enemy's {gun_used} shot and lost {lost_plate} plate(s)! You've earned a free Gulag chance. Use !gulag."
114
+ return limit_response(resp)
115
+ else:
116
+ # Subsequent downing requires a Gulag Token.
117
+ if state["gulag_tokens"] > 0:
118
+ state["gulag_tokens"] -= 1
119
+ state["gulag_count"] += 1
120
+ state["in_gulag"] = True
121
+ state["status"] = "gulag"
122
+ resp += f"Downed again by enemy's {gun_used} shot and lost {lost_plate} plate(s)! You used a Gulag Token for another chance. Use !gulag."
123
+ return limit_response(resp)
124
+ else:
125
+ state["status"] = "eliminated"
126
+ resp += f"Downed by enemy's {gun_used} shot and lost {lost_plate} plate(s)! No Gulag Tokens available. Game over. Final Kills: {state['kills']}. Use !start to play again."
127
+ return limit_response(resp)
128
 
129
  elif event == "loot":
130
+ loot = random.choice(["weapon", "ammo", "armor", "plate", "gulag token"])
131
  if loot == "weapon":
132
  wpn = random.choice(["AK-47", "M4", "Shotgun", "Sniper"])
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 battlefield. It might change the tide of war. "
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. More firepower at your disposal. "
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 to bolster your defense. "
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)! Your protection increases. "
150
  else:
151
  resp += "Plates are already maxed out. "
152
+ elif loot == "gulag token":
153
+ state["gulag_tokens"] += 1
154
+ resp += "Stumbled upon a Gulag Token on the field! This token can grant you an extra chance in Gulag. "
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 battlefield prowess! "
162
  elif item == "Armor Box":
163
  state["armor"] += 10
164
+ resp += "Acquired an Armor Box to fortify your defenses. "
165
  elif item == "Cluster Strike":
166
  state["bonus"] += 0.15
167
  resp += "Bought a Cluster Strike to thin out the opposition. "
 
171
  state["plates"] = min(state["plates"] + added, state["max_plates"])
172
  resp += f"Reinforced your gear with {added} extra plate(s)! "
173
  else:
174
+ resp += "Your plates are already at maximum. "
175
+ elif item == "Gulag Token":
176
+ state["gulag_tokens"] += 1
177
+ resp += "Purchased a Gulag Token for a second chance in battle! "
178
 
179
  elif event == "ambush":
180
  resp += "Ambushed! "
 
185
  kills = random.randint(1, 2)
186
  state["kills"] += kills
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 the threat still looms. "
191
  elif amb == "lost ammo":
192
  lost = random.randint(10, 20)
193
  state["ammo"] = max(state["ammo"] - lost, 0)
 
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']}. Gulag Tokens: {state['gulag_tokens']}. Stay vigilant!")
211
  return limit_response(resp)
212
 
213
  @app.route("/gulag", methods=["GET"])