-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcombat.py
68 lines (62 loc) · 2.03 KB
/
combat.py
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
from aiohttp import web
async def basic_combat(request):
data = await request.json()
attacker = data.get('attacker')
defender = data.get('defender')
attacker_tokens = int(attacker.get('tokens'))
defender_tokens = int(defender.get('tokens'))
result = defender_tokens - attacker_tokens
success = True
defender_current_owner = attacker.get('player_id')
defender_current_tokens = attacker_tokens
defender_lost_tokens = defender_tokens
attacker_current_tokens = attacker_tokens
attacker_lost_tokens = 0
if result > 0:
attacker_current_tokens = 0
attacker_lost_tokens = attacker_tokens
success = False
defender_current_owner = defender.get('player_id')
defender_current_tokens = result
defender_lost_tokens = attacker_tokens
combat_report = report(
success,
attacker.get('hex_id'),
attacker.get('player_id'),
attacker_current_tokens,
attacker_lost_tokens,
defender.get('hex_id'),
defender_current_owner,
defender_current_tokens,
defender_lost_tokens,
)
return web.json_response(combat_report)
def report(
success,
attacking_id,
attacker_owner,
attacker_current_tokens,
attacker_lost_tokens,
defending_id,
defender_owner,
defender_current_tokens,
defender_lost_tokens,
):
report = {
"combatReport": {
"success": success,
},
"attackingTIle": {
"id": attacking_id,
"owner": attacker_owner,
"currentTokens": attacker_current_tokens,
"lostTokens": attacker_lost_tokens,
},
"defendingTile": {
"id": defending_id,
"owner": defender_owner,
"currentTokens": defender_current_tokens,
"lostTokens": defender_lost_tokens
}
}
return report