Ejemplo n.º 1
0
def func(self,
         mainActor,
         state=None,
         participants=None,
         victims=None,
         sponsors=None):

    eventPeople = [mainActor] + participants
    numItems = random.randint(1, 2)
    itemsFound = [
        ItemInstance.takeOrMakeInstance(v)
        for v in random.sample(list(state['items'].values()), 2)
    ]
    descList = eventPeople + itemsFound
    fightDesc, fightDead, allKillers, lootDict, injuries, destroyedList = self.fight(
        eventPeople, state["allRelationships"], preexistingLoot=itemsFound)
    if fightDesc is None:
        return None
    desc = Event.englishList(
        eventPeople) + " stumbled across " + Event.englishList(
            itemsFound) + " at the same time. A fight broke out. " + fightDesc

    return EventOutput(desc,
                       descList, [x.name for x in fightDead],
                       allKillers,
                       loot_table=lootDict,
                       injuries=injuries,
                       list_killers=True,
                       destroyed_loot_table=destroyedList)
def func(self,
         mainActor,
         state=None,
         participants=None,
         victims=None,
         sponsors=None):
    # Random relationship boost
    state["allRelationships"].IncreaseFriendLevel(mainActor, participants[0],
                                                  random.randint(1, 2))
    state["allRelationships"].IncreaseLoveLevel(mainActor, participants[0],
                                                random.randint(2, 3))
    state["allRelationships"].IncreaseFriendLevel(participants[0], mainActor,
                                                  random.randint(1, 2))
    state["allRelationships"].IncreaseLoveLevel(participants[0], mainActor,
                                                random.randint(2, 3))
    desc = mainActor.name + ' and ' + \
        participants[0].name + ' had an intimate conversation.'

    # This leans on the fact that if they _are_ in love, this event will only trigger for the right person.
    if not mainActor.hasThing("Love"):
        confused = []
        if mainActor.gender == participants[0].gender:
            if not random.randint(0, 2):
                confused.append(mainActor)
                mainActor.permStatChange({'stability': -2})
            if not random.randint(0, 2):
                confused.append(participants[0])
                participants[0].permStatChange({'stability': -2})
        if len(confused) == 2:
            desc += ' ' + Event.englishList(confused) + \
                ' found themselves confused by their feelings.'
            weight = 10
        elif len(confused) == 1:
            desc += ' ' + Event.englishList(
                confused) + ' found ' + Event.parseGenderReflexive(
                    confused[0]
                ) + ' confused by ' + Event.parseGenderPossessive(
                    confused[0]) + ' feelings.'
            weight = 20
        if confused:
            eventHandler = IndividualEventHandler(state)
            eventHandler.banEventForSingleContestant(
                "ShareIntimateConversation", mainActor.name)
            eventHandler.banEventForSingleContestant(
                "ShareIntimateConversation", participants[0].name)
            for person in confused:
                eventHandler.bindRoleForContestantAndEvent(
                    "participants",
                    [mainActor if person != mainActor else participants[0]],
                    person, "ResolvesFeelingConfusion")
                eventHandler.setEventWeightForSingleContestant(
                    "ResolvesFeelingConfusion", person.name, weight, state)
            self.eventStore[mainActor.name] = eventHandler
            self.eventStore[
                participants[0].name] = eventHandler  # Yes, two copies
        # Second entry is the contestants or items named in desc, in desired display. Third is anyone who died. This is in strings.
    return (desc, [mainActor, participants[0]], [])
Ejemplo n.º 3
0
def cornucopiaEndPhaseCallback(thisPhase, PRINTHTML, state):
    if thisPhase == "Cornucopia":
        state["events"]["DoNothing"].eventStore.setdefault(
            "CornucopiaDoNothing", [])
        skippers = state["events"]["DoNothing"].eventStore[
            "CornucopiaDoNothing"]
        if skippers:
            thisWriter = state.get("thisWriter")
            if thisWriter is not None:
                state["thisWriter"].addEvent(
                    "The following contestants chose to skip the Cornucopia: "
                    + Event.englishList(skippers), skippers)
            else:
                print(
                    "The following contestants chose to skip the Cornucopia: "
                    + Event.englishList(skippers))
            skippers.clear()
Ejemplo n.º 4
0
def killWrite(state):
    from Objs.Events.Event import Event
    killWriter = HTMLWriter(state["statuses"])
    killWriter.addTitle("Day " + str(state["turnNumber"][0]) + " Kills")
    for contestant, kills in state["callbackStore"]["killCounter"].items():
        desc = html.escape(str(contestant)) + '<br/>Kills: ' + str(
            len(kills)) + '<br/>' + html.escape(Event.englishList(
                kills, False))
        descContestant = state["contestants"][contestant]
        if not descContestant.alive:
            desc = '(DEAD) ' + desc
        killWriter.addEvent(desc, [descContestant], escape=False)
    killWriter.finalWrite(
        os.path.join("Assets",
                     str(state["turnNumber"][0]) + " Kills.html"), state)
    return False
Ejemplo n.º 5
0
def func(self,
         mainActor,
         state=None,
         participants=None,
         victims=None,
         sponsors=None):
    if self.eventStore["trapCounter"] == 0:
        return None
    everyone = [mainActor] + participants
    # First determine who this trap belongs to.
    trapSource = weightedDictRandom(self.eventStore["trapMakerCounter"])[0]
    desc = Event.englishList(
        everyone
    ) + " stumbled into an explosive trap set by " + trapSource + ", "
    # If the maker of this trap is anywhere in the group, chance that they warn the group.
    found = False
    for person in everyone:
        if str(person) == trapSource:
            found = True
            notBeingStupidRatio = (mainActor.stats["stability"] +
                                   mainActor.stats["cleverness"] * 3) / 40
            if random.random() < notBeingStupidRatio:
                if len(everyone) > 1:
                    desc += " but they were able to escape thanks to " + str(
                        person) + "'s warning!"
                else:
                    desc += " but excaped from " + Event.parseGenderPossessive(
                        mainActor) + " own trap."
                return (desc, everyone, [])
        break
    desc += " and they all died in the ensuing detonation!" if (
        len(everyone) > 1) else " and " + Event.parseGenderSubject(
            mainActor) + " died in the ensuing detonation!"
    for person in everyone:
        person.kill()
    self.eventStore["trapCounter"] -= 1
    self.eventStore["trapMakerCounter"][trapSource] -= 1
    descList = [mainActor] + participants
    if not found:
        descList.append(state["contestants"][trapSource])
    return (desc, descList, [str(x) for x in everyone],
            {str(x): trapSource
             for x in everyone}, everyone)
Ejemplo n.º 6
0
def medkitHealing(thisPhase, printHTML, state):
    if thisPhase != "Evening":
        return
    for contestant in state["contestants"].values():
        if contestant.alive and contestant.hasThing("Medical Kit"):
            removedStatuses = set()
            if contestant.removeStatus(
                    "Injury"
            ):  # If this is False, they never had it to start with.
                removedStatuses.add(state["statuses"]["Injury"])
            if contestant.removeStatus(
                    "Fever"
            ):  # If this is False, they never had it to start with.
                removedStatuses.add(state["statuses"]["Fever"])
            if removedStatuses and printHTML:
                desc = contestant.name + " used their Medical Kit to heal their " + Event.englishList(
                    removedStatuses) + "."
                descContestants = [contestant, *removedStatuses]
                state['thisWriter'].addEvent(desc, descContestants)
Ejemplo n.º 7
0
def func(self,
         mainActor,
         state=None,
         participants=None,
         victims=None,
         sponsors=None):
    attackers = [mainActor] + participants
    desc = Event.englishList(
        attackers
    ) + " worked together to ambush and attack " + victims[0].name + "."
    descList = attackers + victims
    fightDesc, fightDead, allKillers, lootDict, injuries, destroyedList = self.factionFight(
        attackers, victims, state["allRelationships"])
    # Second entry is the contestants or items named in desc, in desired display. Third is anyone who died. This is in strings.
    return EventOutput(desc + fightDesc,
                       descList,
                       sorted([x.name for x in fightDead]),
                       allKillers,
                       loot_table=lootDict,
                       injuries=injuries,
                       destroyed_loot_table=destroyedList)
Ejemplo n.º 8
0
def ContestantStatWrite(state):
    from Objs.Events.Event import Event

    statWriter = HTMLWriter(state["statuses"])
    statWriter.addTitle("Contestant Summary")
    for contestant in state["contestants"].values():
        if not contestant.alive:
            continue
        # Construct stats and items line
        eventLine = html.escape(str(contestant)) + "<br/>" + \
            html.escape(Event.englishList(contestant.inventory + contestant.statuses))
        for statname, curstat in contestant.stats.items():
            origstat = contestant.originalStats[statname]
            eventLine += "<br/>" + statname + ": " + str(origstat)
            diff = curstat - origstat
            if diff > 0:
                eventLine += " " + HTMLWriter.wrap("+" + str(diff), "positive")
            elif diff < 0:
                eventLine += " " + HTMLWriter.wrap("-" + str(-diff),
                                                   "negative")
        statWriter.addEvent(eventLine, [contestant], escape=False)
    statWriter.finalWrite(
        os.path.join("Assets",
                     str(state["turnNumber"][0]) + " Stats.html"), state)
Ejemplo n.º 9
0
def func(self,
         mainActor,
         state=None,
         participants=None,
         victims=None,
         sponsors=None):
    eventPeople = [mainActor] + participants
    relationships = state["allRelationships"]
    while True:
        whatHappens = random.randint(0, 2)  # 0 is empty, 1 is loot, 2 is trap
        descList = eventPeople.copy()
        desc = Event.englishList(
            eventPeople) + ' found an abandoned building, '
        fightDead = []
        allKillers = None
        lootDict = None
        destroyedList = None
        injuries = None
        if whatHappens == 0:
            desc += 'but it turned out to have nothing of value.'
            if len(eventPeople) > 1:
                probViolence = 0.25 - \
                    relationships.groupCohesion(eventPeople) / 200
                if random.random() < probViolence:
                    fightDesc, fightDead, allKillers, lootDict, injuries, destroyedList = self.fight(
                        eventPeople, relationships)
                    if fightDesc is None:
                        continue
                    desc += ' Violence broke out due to frustration.'
                    desc += fightDesc
            break
        elif whatHappens == 1:
            # get one or two random pieces of loot
            new_loot = random.sample(list(state['items'].values()),
                                     random.randint(1, 2))
            desc += ' and found sweet loot!'  # let the loot be described separately
            lootDict = {}
            destroyedList = []
            # If there is no fight, there's no reason loot would be destroyed.
            overrideLootDestructionChance = 0
            if len(eventPeople) > 1:
                probViolence = 0.5 - relationships.groupCohesion(
                    eventPeople) / 100
                if random.random() < probViolence:
                    overrideLootDestructionChange = None
                    fightDesc, fightDead, allKillers, lootDict, injuries, destroyedList = self.fight(
                        eventPeople,
                        relationships,
                        False,
                        False,
                        preexistingLoot=new_loot)
                    if fightDesc is None:
                        continue
                    desc += ' A fight broke out over the loot.'
                    desc += fightDesc
                    break  # This has separate logic than what happens if there is no fight.
            partialLoot, partialDestroyed = self.lootForMany(
                eventPeople,
                new_loot,
                chanceDestroyedOverride=overrideLootDestructionChance)
            Event.MergeLootDicts(lootDict, partialLoot)
            Event.MergeDestroyedLists(destroyedList, partialDestroyed)
            break
        elif whatHappens == 2:
            desc += ' but the building was booby-trapped! '
            for person in eventPeople:
                if person.stats['cleverness'] + person.stats[
                        'combat ability'] + random.randint(0, 21) < 21:
                    person.kill()
                    fightDead.append(person)
            if not fightDead:
                if len(eventPeople) > 1:
                    desc += 'Everyone escaped safely.'
                else:
                    desc += Event.parseGenderSubject(
                        eventPeople[0]).capitalize() + ' escaped safely.'

            # This must be done separately because it assigns no killers
            # Second entry is the contestants or items named in desc, in desired display. Third is anyone who died. This is in strings.
            return (desc, descList, [x.name for x in fightDead],
                    collections.OrderedDict())

    # Second entry is the contestants or items named in desc, in desired display. Third is anyone who died. This is in strings.
    return EventOutput(desc,
                       descList, [x.name for x in fightDead],
                       allKillers,
                       loot_table=lootDict,
                       injuries=injuries,
                       list_killers=True,
                       destroyed_loot_table=destroyedList)