Exemple #1
0
async def new_initiative_effect(sid, data):
    sid_data = state.sid_map[sid]
    user = sid_data["user"]
    room = sid_data["room"]
    location = sid_data["location"]

    if room.creator != user and not ShapeOwner.get_or_none(shape=shape,
                                                           user=user):
        logger.warning(
            f"{user.name} attempted to create a new initiative effect")
        return

    InitiativeEffect.create(
        initiative=data["actor"],
        uuid=data["effect"]["uuid"],
        name=data["effect"]["name"],
        turns=data["effect"]["turns"],
    )

    await sio.emit(
        "Initiative.Effect.New",
        data,
        room=location.get_path(),
        skip_sid=sid,
        namespace="/planarally",
    )
Exemple #2
0
async def update_initiative_turn(sid: int, data: Dict[str, Any]):
    pr: PlayerRoom = game_state.get(sid)

    if pr.role != Role.DM:
        logger.warning(
            f"{pr.player.name} attempted to advance the initiative tracker")
        return

    location_data = InitiativeLocationData.get(location=pr.active_location)
    with db.atomic():
        location_data.turn = data
        location_data.save()

        effects = (InitiativeEffect.select().join(Initiative).where(
            Initiative.uuid == data))
        for effect in effects:
            if effect.turns <= 0:
                effect.delete_instance()
            else:
                effect.turns -= 1
            effect.save()

    await sio.emit(
        "Initiative.Turn.Update",
        data,
        room=pr.active_location.get_path(),
        skip_sid=sid,
        namespace=GAME_NS,
    )
Exemple #3
0
async def update_initiative_turn(sid, data):
    sid_data = state.sid_map[sid]
    user = sid_data["user"]
    room = sid_data["room"]
    location = sid_data["location"]

    if room.creator != user:
        logger.warning(
            f"{user.name} attempted to advance the initiative tracker")
        return

    location_data = InitiativeLocationData.get(location=location)
    with db.atomic():
        location_data.turn = data
        location_data.save()

        effects = (InitiativeEffect.select().join(Initiative).where(
            Initiative.uuid == data))
        for effect in effects:
            if effect.turns <= 0:
                effect.delete_instance()
            else:
                effect.turns -= 1
            effect.save()

    await sio.emit(
        "Initiative.Turn.Update",
        data,
        room=location.get_path(),
        skip_sid=sid,
        namespace="/planarally",
    )
Exemple #4
0
async def update_initiative_turn(sid: str, data: str):
    pr: PlayerRoom = game_state.get(sid)

    if pr.role != Role.DM:
        logger.warning(
            f"{pr.player.name} attempted to advance the initiative tracker")
        return

    location_data = InitiativeLocationData.get(location=pr.active_location)
    with db.atomic():
        location_data.turn = data
        location_data.save()

        effects = (InitiativeEffect.select().join(Initiative).where(
            Initiative.uuid == data))
        for effect in effects:
            try:
                turns = int(effect.turns)
                if turns <= 0:
                    effect.delete_instance()
                else:
                    effect.turns = str(turns - 1)
            except ValueError:
                # For non-number inputs do not update the effect
                pass
            effect.save()

    await sio.emit(
        "Initiative.Turn.Update",
        data,
        room=pr.active_location.get_path(),
        skip_sid=sid,
        namespace=GAME_NS,
    )
Exemple #5
0
async def new_initiative_effect(sid: int, data: Dict[str, Any]):
    pr: PlayerRoom = game_state.get(sid)

    if not has_ownership(Shape.get_or_none(uuid=data["actor"]), pr):
        logger.warning(
            f"{pr.player.name} attempted to create a new initiative effect")
        return

    InitiativeEffect.create(
        initiative=data["actor"],
        uuid=data["effect"]["uuid"],
        name=data["effect"]["name"],
        turns=data["effect"]["turns"],
    )

    await sio.emit(
        "Initiative.Effect.New",
        data,
        room=pr.active_location.get_path(),
        skip_sid=sid,
        namespace=GAME_NS,
    )
Exemple #6
0
async def remove_initiative_effect(sid: str,
                                   data: ServerInitiativeEffectActor):
    pr: PlayerRoom = game_state.get(sid)

    if not has_ownership(Shape.get_or_none(uuid=data["actor"]), pr):
        logger.warning(
            f"{pr.player.name} attempted to remove an initiative effect")
        return

    with db.atomic():
        effect = InitiativeEffect.get(uuid=data["effect"]["uuid"])
        effect.delete_instance()

    await sio.emit(
        "Initiative.Effect.Remove",
        data,
        room=pr.active_location.get_path(),
        skip_sid=sid,
        namespace=GAME_NS,
    )
Exemple #7
0
async def update_initiative_effect(sid: int, data: Dict[str, Any]):
    pr: PlayerRoom = game_state.get(sid)

    if not has_ownership(Shape.get_or_none(uuid=data["actor"]), pr):
        logger.warning(
            f"{pr.player.name} attempted to update an initiative effect")
        return

    with db.atomic():
        effect = InitiativeEffect.get(uuid=data["effect"]["uuid"])
        update_model_from_dict(
            effect, reduce_data_to_model(InitiativeEffect, data["effect"]))
        effect.save()

    await sio.emit(
        "Initiative.Effect.Update",
        data,
        room=pr.active_location.get_path(),
        skip_sid=sid,
        namespace=GAME_NS,
    )
Exemple #8
0
async def update_initiative_effect(sid, data):
    sid_data = state.sid_map[sid]
    user = sid_data["user"]
    room = sid_data["room"]
    location = sid_data["location"]

    if room.creator != user and not ShapeOwner.get_or_none(shape=shape,
                                                           user=user):
        logger.warning(f"{user.name} attempted to update an initiative effect")
        return

    with db.atomic():
        effect = InitiativeEffect.get(uuid=data["effect"]["uuid"])
        update_model_from_dict(
            effect, reduce_data_to_model(InitiativeEffect, data["effect"]))
        effect.save()

    await sio.emit(
        "Initiative.Effect.Update",
        data,
        room=location.get_path(),
        skip_sid=sid,
        namespace="/planarally",
    )