tstone87 commited on
Commit
6c9df0b
·
verified ·
1 Parent(s): b22a8b4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -64
app.py CHANGED
@@ -4,13 +4,13 @@ import random
4
  app = Flask(__name__)
5
 
6
  # ---------------- Configuration ----------------
7
- AIR_STRIKE_CHANCE = 0.85 # Chance to call in an Air Strike if available
8
  SELF_REVIVE_CHANCE = 0.10 # Chance to self-revive when downed
9
- EXTRA_LOST_PLATE_CHANCE = 1.90 # Chance to lose an extra plate from enemy fire
10
- GULAG_WIN_THRESHOLD = 0.45 # In Gulag: outcome <35% = win (return to battle)
11
- GULAG_ELIMINATED_THRESHOLD = 0.55 # In Gulag: outcome >=35% and <65% = eliminated; >=65% = stalemate (lose a plate and try again)
12
- NAT_MIN_DEATHS = 13 # Minimum natural enemy deaths per round
13
- NAT_MAX_DEATHS = 29 # Maximum natural enemy deaths per round
14
  # ------------------------------------------------
15
 
16
  game_states = {}
@@ -34,17 +34,17 @@ def init_game(username, loadout):
34
  "ammo": 100,
35
  "armor": 100,
36
  "inventory": [],
37
- "equipment": [],
38
  "plates": 3,
39
  "max_plates": 12,
40
  "in_gulag": False,
41
- "gulag_count": 0,
42
- "gulag_tokens": 0
43
  }
44
 
45
  @app.route("/")
46
  def home():
47
- return "Welcome to the Warzone BR game! Use !start, !fight, or !gulag."
48
 
49
  @app.route("/start", methods=["GET"])
50
  def start():
@@ -63,7 +63,6 @@ def fight():
63
  if not user or user not in game_states:
64
  return limit_response("Start game first with !start")
65
  state = game_states[user]
66
-
67
  if state["status"] != "active":
68
  msg = f"Game over. Final Kills: {state['kills']}. "
69
  if state["status"] == "won":
@@ -74,6 +73,7 @@ def fight():
74
  msg += "You're in Gulag! Use !gulag to fight your opponent."
75
  return limit_response(msg)
76
 
 
77
  effective_bonus = state["bonus"] if state["plates"] > 0 else state["bonus"] * 0.7
78
  state["round"] += 1
79
  r = state["round"]
@@ -82,6 +82,7 @@ def fight():
82
  resp = f"R{r}: "
83
 
84
  if event == "fight":
 
85
  if "Air Strike" in state["equipment"] and random.random() < AIR_STRIKE_CHANCE:
86
  kills = random.randint(2, 3)
87
  state["kills"] += kills
@@ -90,60 +91,28 @@ def fight():
90
  resp += f"You called in an Air Strike! It obliterated {kills} enemies. "
91
  state["equipment"].remove("Air Strike")
92
  else:
93
- scenario = random.randint(1,15)
 
94
  gun_used = random.choice(["M4", "AK-47", "Shotgun", "Sniper", "SMG"])
95
  downed = False
96
  kills = 0
97
- if scenario == 1:
98
- kills = 1
99
- resp += f"Your precision shot with the {gun_used} downed {kills} foe. "
100
- elif scenario == 2:
101
- resp += f"Your {gun_used} jammed at a critical moment, and you were caught off guard—downed! "
102
- downed = True
103
- elif scenario == 3:
104
- kills = 1
105
- resp += f"You outmaneuvered an enemy with your {gun_used} and secured a kill. "
106
- elif scenario == 4:
107
- kills = 1
108
- resp += f"A burst from your {gun_used} earned you {kills} kill, though you were rattled. "
109
- elif scenario == 5:
110
- resp += f"Your attempt to flank with the {gun_used} backfired—you were overwhelmed and downed! "
111
- downed = True
112
- elif scenario == 6:
113
- kills = 1
114
- resp += f"Your rapid reload with the {gun_used} allowed you to grab a kill. "
115
- elif scenario == 7:
116
- resp += f"Disaster! Your {gun_used} misfired and left you exposed—downed! "
117
- downed = True
118
- elif scenario == 8:
119
- resp += f"A stray round from your {gun_used} grazed an enemy, but nothing decisive happened. "
120
- elif scenario == 9:
121
- kills = 1
122
- resp += f"An aggressive assault with your {gun_used} got you {kills} kill. "
123
- elif scenario == 10:
124
- kills = 1
125
- resp += f"A lucky headshot with your {gun_used} secured {kills} kill, but you lost a plate. "
126
- state["plates"] = max(state["plates"] - 1, 0)
127
- elif scenario == 11:
128
- kills = 1
129
- resp += f"Suppressive fire from your {gun_used} earned you {kills} kill. "
130
- elif scenario == 12:
131
- resp += f"In a moment of hesitation, you failed to act and were downed by enemy fire. "
132
  downed = True
133
- elif scenario == 13:
134
- kills = 1
135
- resp += f"Your {gun_used} shot knocked an enemy out for {kills} kill, but your cover was compromised."
136
- if random.random() < 0.5:
137
- downed = True
138
- resp += " You were subsequently overwhelmed. "
139
- elif scenario == 14:
140
- kills = 1
141
- resp += f"Your {gun_used} burst ricocheted, earning {kills} kill but costing you a plate. "
142
- state["plates"] = max(state["plates"] - 1, 0)
143
- elif scenario == 15:
144
- resp += f"In the chaos, you managed no kills and were left vulnerable."
145
- if random.random() < 0.5:
146
- downed = True
147
  if final_round and not downed and kills == 0:
148
  kills = 1
149
  resp += f"Under final round pressure, you managed a desperate 1 kill with your {gun_used}. "
@@ -151,10 +120,13 @@ def fight():
151
  if kills > 0:
152
  state["players"] = max(state["players"] - kills, 1)
153
  state["ammo"] = max(state["ammo"] - random.randint(5,10), 0)
 
154
  if not downed and random.random() < EXTRA_LOST_PLATE_CHANCE:
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
  if downed:
159
  if random.random() < SELF_REVIVE_CHANCE:
160
  state["revives"] += 1
@@ -165,7 +137,7 @@ def fight():
165
  else:
166
  resp += "Miraculously, you self-revived despite having no plates. "
167
  else:
168
- lost_plate = random.randint(1, 2)
169
  state["plates"] = max(state["plates"] - lost_plate, 0)
170
  if state["gulag_count"] == 0:
171
  state["gulag_count"] += 1
@@ -199,7 +171,7 @@ def fight():
199
  state["ammo"] += add_ammo
200
  resp += f"Found {add_ammo} rounds of ammo. "
201
  elif loot == "armor":
202
- add_arm = random.randint(1, 3)
203
  state["armor"] += add_arm
204
  resp += f"Picked up {add_arm} armor points. "
205
  elif loot == "plate":
@@ -240,7 +212,7 @@ def fight():
240
  state["gulag_tokens"] = 1
241
  resp += "Purchased a Gulag Token for a second chance! "
242
  else:
243
- resp += "You found a gulag toke but no need for one so you left it to despawn. "
244
 
245
  elif event == "ambush":
246
  resp += "Ambushed! "
 
4
  app = Flask(__name__)
5
 
6
  # ---------------- Configuration ----------------
7
+ AIR_STRIKE_CHANCE = 0.15 # Chance to call in an Air Strike if available
8
  SELF_REVIVE_CHANCE = 0.10 # Chance to self-revive when downed
9
+ EXTRA_LOST_PLATE_CHANCE = 0.30 # Chance to lose an extra plate from enemy fire
10
+ GULAG_WIN_THRESHOLD = 0.35 # In Gulag: outcome <35% = win (return to battle)
11
+ GULAG_ELIMINATED_THRESHOLD = 0.65 # In Gulag: outcome >=35% and <65% = eliminated; >=65% = stalemate (lose a plate and try again)
12
+ NAT_MIN_DEATHS = 3 # Minimum natural enemy deaths per round (lower = harder game)
13
+ NAT_MAX_DEATHS = 7 # Maximum natural enemy deaths per round
14
  # ------------------------------------------------
15
 
16
  game_states = {}
 
34
  "ammo": 100,
35
  "armor": 100,
36
  "inventory": [],
37
+ "equipment": [], # e.g. "UAV", "Air Strike"
38
  "plates": 3,
39
  "max_plates": 12,
40
  "in_gulag": False,
41
+ "gulag_count": 0, # number of times downed
42
+ "gulag_tokens": 0 # only obtainable AFTER first gulag
43
  }
44
 
45
  @app.route("/")
46
  def home():
47
+ return "Welcome to the BR game API! Use /start, /fight, or /gulag."
48
 
49
  @app.route("/start", methods=["GET"])
50
  def start():
 
63
  if not user or user not in game_states:
64
  return limit_response("Start game first with !start")
65
  state = game_states[user]
 
66
  if state["status"] != "active":
67
  msg = f"Game over. Final Kills: {state['kills']}. "
68
  if state["status"] == "won":
 
73
  msg += "You're in Gulag! Use !gulag to fight your opponent."
74
  return limit_response(msg)
75
 
76
+ # If no plates, reduce effective bonus.
77
  effective_bonus = state["bonus"] if state["plates"] > 0 else state["bonus"] * 0.7
78
  state["round"] += 1
79
  r = state["round"]
 
82
  resp = f"R{r}: "
83
 
84
  if event == "fight":
85
+ # Air Strike branch remains unchanged.
86
  if "Air Strike" in state["equipment"] and random.random() < AIR_STRIKE_CHANCE:
87
  kills = random.randint(2, 3)
88
  state["kills"] += kills
 
91
  resp += f"You called in an Air Strike! It obliterated {kills} enemies. "
92
  state["equipment"].remove("Air Strike")
93
  else:
94
+ # Use a scenario from 1 to 20 to determine the fight outcome.
95
+ scenario = random.randint(1,20)
96
  gun_used = random.choice(["M4", "AK-47", "Shotgun", "Sniper", "SMG"])
97
  downed = False
98
  kills = 0
99
+ if scenario <= 4:
100
+ # Favorable outcome (20% chance)
101
+ kills = random.randint(1,2)
102
+ resp += f"Your precise shot with the {gun_used} downed {kills} foe(s). "
103
+ elif scenario <= 12:
104
+ # Unfavorable outcome (40% chance): you get little or no kills and are downed.
105
+ kills = random.randint(0,1)
106
+ if kills == 0:
107
+ resp += f"Your {gun_used} malfunctioned, leaving you exposed—you were downed! "
108
+ else:
109
+ resp += f"Your {gun_used} fired erratically, securing {kills} kill(s) but leaving you vulnerable—you were downed! "
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  downed = True
111
+ else:
112
+ # Mixed outcome (40% chance): you get a kill counterattack.
113
+ kills = random.randint(1,2)
114
+ resp += f"In a desperate counterattack with your {gun_used}, you secured {kills} kill(s). "
115
+ # In final round, force at least one kill if not downed.
 
 
 
 
 
 
 
 
 
116
  if final_round and not downed and kills == 0:
117
  kills = 1
118
  resp += f"Under final round pressure, you managed a desperate 1 kill with your {gun_used}. "
 
120
  if kills > 0:
121
  state["players"] = max(state["players"] - kills, 1)
122
  state["ammo"] = max(state["ammo"] - random.randint(5,10), 0)
123
+ # Chance to lose an extra plate from enemy fire.
124
  if not downed and random.random() < EXTRA_LOST_PLATE_CHANCE:
125
  lost = 1
126
  state["plates"] = max(state["plates"] - lost, 0)
127
  resp += f"Amid the firefight, you lost {lost} plate from enemy fire. "
128
+
129
+ # If downed, attempt self-revive; if that fails, enter Gulag.
130
  if downed:
131
  if random.random() < SELF_REVIVE_CHANCE:
132
  state["revives"] += 1
 
137
  else:
138
  resp += "Miraculously, you self-revived despite having no plates. "
139
  else:
140
+ lost_plate = random.randint(1,2)
141
  state["plates"] = max(state["plates"] - lost_plate, 0)
142
  if state["gulag_count"] == 0:
143
  state["gulag_count"] += 1
 
171
  state["ammo"] += add_ammo
172
  resp += f"Found {add_ammo} rounds of ammo. "
173
  elif loot == "armor":
174
+ add_arm = random.randint(5, 20)
175
  state["armor"] += add_arm
176
  resp += f"Picked up {add_arm} armor points. "
177
  elif loot == "plate":
 
212
  state["gulag_tokens"] = 1
213
  resp += "Purchased a Gulag Token for a second chance! "
214
  else:
215
+ resp += "No need for a token right now. "
216
 
217
  elif event == "ambush":
218
  resp += "Ambushed! "