mirror of
https://github.com/evgen-app/chess_rpg_backend.git
synced 2024-11-22 17:47:11 +03:00
updated hero placement for room create
This commit is contained in:
parent
eeb564930d
commit
7812e982b0
|
@ -92,7 +92,7 @@ class Hero(models.Model):
|
||||||
self, force_insert=False, force_update=False, using=None, update_fields=None
|
self, force_insert=False, force_update=False, using=None, update_fields=None
|
||||||
):
|
):
|
||||||
self.model_f = random.choice(HeroModelSet.objects.filter(hero_type=self.type))
|
self.model_f = random.choice(HeroModelSet.objects.filter(hero_type=self.type))
|
||||||
super(Hero, self).save()
|
super(Hero, self).save(force_insert, force_update, using, update_fields)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
indexes = [models.Index(fields=["uuid"])]
|
indexes = [models.Index(fields=["uuid"])]
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
from django.db.models.signals import post_save
|
from django.db.models.signals import post_save
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from .models import Deck, Player, PlayerAuthSession
|
from .models import Player, PlayerAuthSession
|
||||||
from .services.deck_handler import create_first_deck
|
from .services.deck_handler import create_first_deck
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=Player)
|
@receiver(post_save, sender=Player)
|
||||||
def create_player(sender, instance, created, **kwargs):
|
def create_player(sender, instance, created, **kwargs):
|
||||||
if created:
|
if created:
|
||||||
print("bebr")
|
|
||||||
PlayerAuthSession.objects.create(player=instance)
|
PlayerAuthSession.objects.create(player=instance)
|
||||||
create_first_deck(instance)
|
create_first_deck(instance)
|
||||||
|
|
|
@ -2,8 +2,8 @@ from asgiref.sync import sync_to_async
|
||||||
from random import randint
|
from random import randint
|
||||||
|
|
||||||
from common.generators import generate_charset
|
from common.generators import generate_charset
|
||||||
from game.models import Player
|
from game.models import Player, Deck
|
||||||
from room.models import Room, PlayerInRoom, GameState
|
from room.models import Room, PlayerInRoom, GameState, HeroInGame
|
||||||
|
|
||||||
|
|
||||||
@sync_to_async
|
@sync_to_async
|
||||||
|
@ -21,7 +21,7 @@ def create_room(
|
||||||
|
|
||||||
first_player = randint(1, 2)
|
first_player = randint(1, 2)
|
||||||
|
|
||||||
PlayerInRoom.objects.create(
|
p1 = PlayerInRoom.objects.create(
|
||||||
player=player_1,
|
player=player_1,
|
||||||
room=room,
|
room=room,
|
||||||
score=player_score_1,
|
score=player_score_1,
|
||||||
|
@ -29,17 +29,22 @@ def create_room(
|
||||||
first=first_player == 1,
|
first=first_player == 1,
|
||||||
)
|
)
|
||||||
|
|
||||||
PlayerInRoom.objects.create(
|
p2 = PlayerInRoom.objects.create(
|
||||||
player=player_2,
|
player=player_2,
|
||||||
room=room,
|
room=room,
|
||||||
score=player_score_2,
|
score=player_score_2,
|
||||||
deck_id=deck_id_2,
|
deck_id=deck_id_2,
|
||||||
first=first_player == 2,
|
first=first_player == 2,
|
||||||
)
|
)
|
||||||
GameState.objects.create(
|
for p, d_id in [(p1, deck_id_1), (p2, deck_id_2)]:
|
||||||
room=room, player=player_1, round=0, message="Game started"
|
GameState.objects.create(room=room, player=p, round=0, message="Game started")
|
||||||
)
|
for hero in Deck.objects.get(id=d_id).heroes.all():
|
||||||
GameState.objects.create(
|
if p.first:
|
||||||
room=room, player=player_2, round=0, message="Game started"
|
HeroInGame.objects.create(
|
||||||
)
|
hero=hero, player=p, room=room, x=hero.x, y=hero.y
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
HeroInGame.objects.create(
|
||||||
|
hero=hero, player=p, room=room, x=hero.x, y=8 - hero.y
|
||||||
|
)
|
||||||
return room.slug
|
return room.slug
|
||||||
|
|
Loading…
Reference in New Issue
Block a user