mirror of
https://github.com/evgen-app/chess_rpg_backend.git
synced 2024-11-10 19:57:12 +03:00
fixed player's deck create
This commit is contained in:
parent
7e48242780
commit
002f5a6783
|
@ -168,6 +168,7 @@ class HeroInDeck(models.Model):
|
|||
verbose_name = "Hero in deck"
|
||||
verbose_name_plural = "Heroes in decks"
|
||||
ordering = ["y", "x"]
|
||||
unique_together = ["deck", "x", "y"]
|
||||
|
||||
|
||||
class PlayerAuthSession(models.Model):
|
||||
|
|
|
@ -7,18 +7,15 @@ def create_first_deck(player: Player):
|
|||
deck = Deck.objects.create(player=player)
|
||||
positions = []
|
||||
|
||||
for x in range(8):
|
||||
for y in range(2):
|
||||
for x in range(1, 9):
|
||||
for y in range(1, 3):
|
||||
positions.append((x, y))
|
||||
positions.remove((3, 0))
|
||||
positions.remove((4, 0))
|
||||
positions.remove((4, 1))
|
||||
positions.remove((5, 1))
|
||||
random.shuffle(positions)
|
||||
|
||||
types = (
|
||||
["KING", "WIZARD"]
|
||||
+ ["ARCHER" for _ in range(4)]
|
||||
+ ["WARRIOR" for _ in range(6)]
|
||||
)
|
||||
types = ["KING", "WIZARD"] + ["ARCHER" for _ in range(4)] + ["WARRIOR" for _ in range(6)]
|
||||
|
||||
for _ in range(4):
|
||||
t = random.choice(HeroTypes.choices[:3])[0]
|
||||
if t == "WIZARD" and types.count("WIZARD") > 1:
|
||||
|
@ -33,11 +30,11 @@ def create_first_deck(player: Player):
|
|||
|
||||
# set random position on deck for heroes
|
||||
if t == "KING":
|
||||
pos_x = 4
|
||||
pos_y = 0
|
||||
pos_x = 5
|
||||
pos_y = 1
|
||||
elif t == "WIZARD":
|
||||
pos_x = 3
|
||||
pos_y = 0
|
||||
pos_x = 4
|
||||
pos_y = 1
|
||||
else:
|
||||
pos_x = positions[counter][0]
|
||||
pos_y = positions[counter][1]
|
||||
|
@ -49,4 +46,4 @@ def create_first_deck(player: Player):
|
|||
hero.speed = random.randint(0, 10)
|
||||
|
||||
hero.save()
|
||||
HeroInDeck.objects.create(deck=deck, hero=hero, x=pos_x + 1, y=pos_y + 1)
|
||||
HeroInDeck.objects.create(deck=deck, hero=hero, x=pos_x, y=pos_y)
|
||||
|
|
|
@ -76,3 +76,6 @@ class HeroInGame(models.Model):
|
|||
self.health = self.hero.health
|
||||
|
||||
super().save(force_insert, force_update, using, update_fields)
|
||||
|
||||
class Meta:
|
||||
unique_together = ["x", "y", "room"]
|
||||
|
|
|
@ -56,7 +56,7 @@ def _validate_hero_movement(
|
|||
|
||||
|
||||
def _print_board(room: Room):
|
||||
for y in range(1, 8):
|
||||
for y in range(1, 9):
|
||||
for x in range(1, 9):
|
||||
try:
|
||||
hero = HeroInGame.objects.get(x=x, y=y, room=room)
|
||||
|
|
|
@ -55,7 +55,7 @@ def sync_create_room(
|
|||
player=p,
|
||||
room=room,
|
||||
x=hero_in_deck.x,
|
||||
y=8 - hero_in_deck.y,
|
||||
y=8 if hero_in_deck.y == 1 else 7,
|
||||
)
|
||||
return room.slug
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user