Ejemplo n.º 1
0
def apply_properties(person_data={}, world_data={}, properties_data={}, generated_items=list()):
    # Sample properties:
    # "lifespan": "1d6-3",
    # "reroll": "true",
    #   "message": "Born while traveling to [country]"
    # }
    message = ""
    for key, val in properties_data.items():
        if key == "message":
            message = val
            #TODO: Build func to parse out names and subnames
            for item in generated_items:
                name = item.get("name", "")
                nickname = item.get("nickname", "item")
                if name:
                    message = message.replace("[" + nickname + "]", name)

                    #TODO: parse in text from generated_items
        elif key.startswith("world."):
            #TODO: have this work for multiple-level settings
            key = key[6:]
            math_helpers.add_or_increment_dict_val(world_data, key, val)
        else:
            val = math_helpers.roll_dice(val, use_numpy=True)
            math_helpers.add_or_increment_dict_val(person_data, key, val)
            message += key + " was adjusted " + str(val)

    return message
Ejemplo n.º 2
0
def apply_properties(person_data={}, world_data={}, properties_data={}, generated_items=list()):
    # Sample properties:
    # "lifespan": "1d6-3",
    # "reroll": "true",
    #   "message": "Born while traveling to [country]"
    # }
    message = ""
    for key, val in properties_data.items():
        if key == "message":
            message = val
            # TODO: Build func to parse out names and subnames
            for item in generated_items:
                name = item.get("name", "")
                nickname = item.get("nickname", "item")
                if name:
                    message = message.replace("[" + nickname + "]", name)

                    # TODO: parse in text from generated_items
        elif key.startswith("world."):
            # TODO: have this work for multiple-level settings
            key = key[6:]
            math_helpers.add_or_increment_dict_val(world_data, key, val)
        else:
            val = math_helpers.roll_dice(val, use_numpy=True)
            math_helpers.add_or_increment_dict_val(person_data, key, val)
            message += key + " was adjusted " + str(val)

    return message
Ejemplo n.º 3
0
def generate_object(generator='person', world_data={}, item_template={}, power=1, tags='', role='friend', years=4):
    end_date = world_data.get("year", 1100)
    years = math_helpers.roll_dice(years, use_numpy=True)
    try:
        if end_date:
            end_date = int(end_date)
        else:
            end_date = 1100

        if years:
            years = int(years)
        else:
            years = 4
        end_date = end_date + years
    except ValueError:
        end_date = None
    generated = {"type": role, "power": power, "tags": tags, "name": generator, "end_date": end_date}

    # TODO: Expand this

    return generated
Ejemplo n.º 4
0
def generate_object(generator="person", world_data={}, item_template={}, power=1, tags="", role="friend", years=4):
    end_date = world_data.get("year", 1100)
    years = math_helpers.roll_dice(years, use_numpy=True)
    try:
        if end_date:
            end_date = int(end_date)
        else:
            end_date = 1100

        if years:
            years = int(years)
        else:
            years = 4
        end_date = end_date + years
    except ValueError:
        end_date = None
    generated = {"type": role, "power": power, "tags": tags, "name": generator, "end_date": end_date}

    # TODO: Expand this

    return generated
Ejemplo n.º 5
0
def apply_effects(person_data={}, world_data={}, effect_data={}, tag_manager={}):
    # Sample events:
    # pay = good, father.leave, disease = infection, pay = low-fair, blessing, family.blessing,
    # cost = poor, disease = mutation, "gain [weapon], gain [armor]"

    # Sample Generators:
    #     generator =   # barmaid, country, wizard, sailor, horse, creature, scholar, royalty, "weapon, armor"
    #     power/refresh =  # 2
    #     years =  # 1d6
    #     role =   # caretaker, mount, pet, familiar

    tags = math_helpers.flatten_tags(tag_manager)
    items = person_data.get("children", [])
    qualities = person_data.get("qualities", {})

    generated_items = []
    if "generator" in effect_data:
        generator_list = effect_data.get("generator", "")
        if generator_list:
            power = effect_data.get("refresh", None) or effect_data.get("power", 1)
            years = effect_data.get("years", 4)
            role = effect_data.get("role", "friend")
            override = effect_data.get("override", "")
            override = math_helpers.convert_string_to_properties_object(override)

            effect_data.pop("generator", None)
            effect_data.pop("refresh", None)
            effect_data.pop("power", None)
            effect_data.pop("years", None)
            effect_data.pop("role", None)
            effect_data.pop("override", None)

            generators = generator_list.split(",")
            generators = [g.strip() for g in generators]
            for generator in generators:
                created = create_random_item(world_data=world_data, override=override, pattern=generator, tags=tags)
                generated = generate_object(generator=generator, world_data=world_data, item_template=created,
                                            power=power, tags=tags, role=role, years=years)

                data = generated.get("data", {})
                data["role"] = role
                years = effect_data.get("years", 1)
                years = math_helpers.roll_dice(years, use_numpy=True)
                data["years"] = years

                generated_items.append(generated)

                if role:
                    finished_year = int(world_data.get("year", 1100)) + int(years)
                    items.append({"type": role, "finished": finished_year, "active": True, "data": generated})

    family = person_data.get("family", {})
    father = family.get("father", {})
    mother = family.get("mother", {})
    year = world_data.get("year", 1100)

    for effect, variable in effect_data.items():
        # pay = good, father.leave, disease = infection, pay = low-fair, blessing, family.blessing,
        #  cost = poor, disease = mutation, "gain [weapon], gain [armor]"

        #TODO: All other non-generators, run functions
        if effect == "pay":
            if not variable:
                #TODO: Dynamically calculate difficulty
                variable = 5.0
            elif variable == 'exists':
                variable = 5.0
            if isinstance(variable, basestring):
                variable = 5.0
            math_helpers.add_or_increment_dict_val(person_data, "money", variable)

        elif effect == "father.leave":
            father["leave"] = year
            #TODO: reduce family income
            pass
        elif effect == "mother.leave":
            mother["leave"] = year
            #TODO: reduce family income
            pass

        elif effect == "disease":
            if not variable:
                variable = 3.0
            elif variable == 'exists':
                variable = 3.0
            if isinstance(variable, basestring):
                variable = 3.0
            math_helpers.add_or_increment_dict_val(qualities, 'lifespan', -variable)
            generated_items.append({"type": "disease", "name": "rickets"})  #TODO: Make a disease lookup table

        elif effect == "pay":
            if not variable:
                variable = 5.0
            elif variable == 'exists':
                variable = 5.0
            if isinstance(variable, basestring):
                variable = 5.0
            math_helpers.add_or_increment_dict_val(person_data, "money", variable)

        elif effect == "blessing":
            if not variable:
                variable = 3.0
            elif variable == 'exists':
                variable = 3.0
            if isinstance(variable, basestring):
                variable = 3.0
            math_helpers.add_or_increment_dict_val(qualities, 'lifespan', variable)
            generated_items.append({"type": "blessing", "name": "lucky"})

        elif effect == "family.blessing":
            if not variable:
                variable = 3.0
            elif variable == 'exists':
                variable = 3.0
            if isinstance(variable, basestring):
                variable = 3.0
            math_helpers.add_or_increment_dict_val(qualities, 'lifespan', -variable)
            generated_items.append({"type": "family blessing", "name": "wealth"})

        elif effect == "cost":
            if not variable:
                variable = 5.0
            elif variable == 'exists':
                variable = 5.0
            if isinstance(variable, basestring):
                variable = 5.0
            math_helpers.add_or_increment_dict_val(person_data, "money", -variable)

        elif effect == "gain":
            pass

    return generated_items
Ejemplo n.º 6
0
def apply_effects(person_data={}, world_data={}, effect_data={}, tag_manager={}):
    # Sample events:
    # pay = good, father.leave, disease = infection, pay = low-fair, blessing, family.blessing,
    # cost = poor, disease = mutation, "gain [weapon], gain [armor]"

    # Sample Generators:
    #     generator =   # barmaid, country, wizard, sailor, horse, creature, scholar, royalty, "weapon, armor"
    #     power/refresh =  # 2
    #     years =  # 1d6
    #     role =   # caretaker, mount, pet, familiar

    tags = math_helpers.flatten_tags(tag_manager)
    items = person_data.get("children", [])
    qualities = person_data.get("qualities", {})

    generated_items = []
    if "generator" in effect_data:
        generator_list = effect_data.get("generator", "")
        if generator_list:
            power = effect_data.get("refresh", None) or effect_data.get("power", 1)
            years = effect_data.get("years", 4)
            role = effect_data.get("role", "friend")
            override = effect_data.get("override", "")
            override = math_helpers.convert_string_to_properties_object(override)

            effect_data.pop("generator", None)
            effect_data.pop("refresh", None)
            effect_data.pop("power", None)
            effect_data.pop("years", None)
            effect_data.pop("role", None)
            effect_data.pop("override", None)

            generators = generator_list.split(",")
            generators = [g.strip() for g in generators]
            for generator in generators:
                created = create_random_item(world_data=world_data, override=override, pattern=generator, tags=tags)
                generated = generate_object(
                    generator=generator,
                    world_data=world_data,
                    item_template=created,
                    power=power,
                    tags=tags,
                    role=role,
                    years=years,
                )

                data = generated.get("data", {})
                data["role"] = role
                years = effect_data.get("years", 1)
                years = math_helpers.roll_dice(years, use_numpy=True)
                data["years"] = years

                generated_items.append(generated)

                if role:
                    finished_year = int(world_data.get("year", 1100)) + int(years)
                    items.append({"type": role, "finished": finished_year, "active": True, "data": generated})

    family = person_data.get("family", {})
    father = family.get("father", {})
    mother = family.get("mother", {})
    year = world_data.get("year", 1100)

    for effect, variable in effect_data.items():
        # pay = good, father.leave, disease = infection, pay = low-fair, blessing, family.blessing,
        #  cost = poor, disease = mutation, "gain [weapon], gain [armor]"

        # TODO: All other non-generators, run functions
        if effect == "pay":
            if not variable:
                # TODO: Dynamically calculate difficulty
                variable = 5.0
            elif variable == "exists":
                variable = 5.0
            if isinstance(variable, basestring):
                variable = 5.0
            math_helpers.add_or_increment_dict_val(person_data, "money", variable)

        elif effect == "father.leave":
            father["leave"] = year
            # TODO: reduce family income
            pass
        elif effect == "mother.leave":
            mother["leave"] = year
            # TODO: reduce family income
            pass

        elif effect == "disease":
            if not variable:
                variable = 3.0
            elif variable == "exists":
                variable = 3.0
            if isinstance(variable, basestring):
                variable = 3.0
            math_helpers.add_or_increment_dict_val(qualities, "lifespan", -variable)
            generated_items.append({"type": "disease", "name": "rickets"})  # TODO: Make a disease lookup table

        elif effect == "pay":
            if not variable:
                variable = 5.0
            elif variable == "exists":
                variable = 5.0
            if isinstance(variable, basestring):
                variable = 5.0
            math_helpers.add_or_increment_dict_val(person_data, "money", variable)

        elif effect == "blessing":
            if not variable:
                variable = 3.0
            elif variable == "exists":
                variable = 3.0
            if isinstance(variable, basestring):
                variable = 3.0
            math_helpers.add_or_increment_dict_val(qualities, "lifespan", variable)
            generated_items.append({"type": "blessing", "name": "lucky"})

        elif effect == "family.blessing":
            if not variable:
                variable = 3.0
            elif variable == "exists":
                variable = 3.0
            if isinstance(variable, basestring):
                variable = 3.0
            math_helpers.add_or_increment_dict_val(qualities, "lifespan", -variable)
            generated_items.append({"type": "family blessing", "name": "wealth"})

        elif effect == "cost":
            if not variable:
                variable = 5.0
            elif variable == "exists":
                variable = 5.0
            if isinstance(variable, basestring):
                variable = 5.0
            math_helpers.add_or_increment_dict_val(person_data, "money", -variable)

        elif effect == "gain":
            pass

    return generated_items