Example #1
0
def add_item(event, context):
    logger.debug(f'Event received: {json.dumps(event)}')
    char_id = event['pathParameters']['id']

    print(event.get('body'))

    data = json.loads(event.get('body'))

    character = CharacterModel.get(char_id)

    if character is None:
        raise Exception('No character found')

    character.add_item(
        InventoryItemMap(id=data['id'],
                         equipped=False,
                         inv_id=str(uuid4()),
                         slot=data['slot'],
                         slot_name=data['slot_name'],
                         damage=data['damage'],
                         stamina=data['stamina'],
                         crit_chance=data['crit_chance']))

    response = {
        'statusCode': 200,
        'body': json.dumps(character, cls=ModelEncoder),
        'headers': {
            'Access-Control-Allow-Origin': '*'
        }
    }

    logger.debug(f'Response: {json.dumps(event)}')

    return response
Example #2
0
def get(event, context):
    logger.debug(f'Event received: {json.dumps(event)}')
    char_id = event['pathParameters']['id']

    character = CharacterModel.get(char_id)

    response = {
        'statusCode': 200,
        'body': json.dumps(character, cls=ModelEncoder),
        'headers': {
            'Access-Control-Allow-Origin': '*'
        }
    }

    return response
Example #3
0
def equip_item(event, context):
    logger.debug((f'Event received: {json.dumps(event)}'))
    char_id = event['pathParameters']['id']

    data = json.loads(event.get('body'))

    character = CharacterModel.get(char_id)

    inv_id = data['inv_id']

    character.equip_item(inv_id)

    response = {
        'statusCode': 200,
        'body': json.dumps(character, cls=ModelEncoder),
        'headers': {
            'Access-Control-Allow-Origin': '*'
        }
    }

    logger.debug(f'Response: {json.dumps(response)}')

    return response
Example #4
0
def unequip_item(event, context):
    logger.debug(f'Event received: {json.dumps(event)}')
    char_id = event['pathParameters']['id']
    data = json.loads(event.get('body'))

    character = CharacterModel.get(char_id)

    if character is None:
        raise Exception('No character found')

    character.unequip_item(data.get('inv_id'))

    response = {
        'statusCode': 200,
        'body': json.dumps(character, cls=ModelEncoder),
        'headers': {
            'Access-Control-Allow-Origin': '*'
        }
    }

    logger.debug(f'Response: {json.dumps(event)}')

    return response
Example #5
0
def handler(event, context):
    logger.debug(f'Event received: {json.dumps(event)}')
    data = json.loads(event.get('body'))

    char_id = event['pathParameters']['id']

    character = CharacterModel.get(char_id)

    for item in character.inventory:
        item.inv_id = str(uuid4())

    character.save()

    response = {
        'statusCode': 200,
        'body': json.dumps(character, cls=ModelEncoder),
        'headers': {
            'Access-Control-Allow-Origin': '*'
        }
    }

    logger.debug(f'Response: {json.dumps(response)}')

    return response