예제 #1
0
    def spawn_enemies(self):
        """Spawns enemies"""
        self.enemies.empty()
        self.shooters = []

        for i in self.sprites:
            if i[0] == "P":
                self.plat = platform.Platform((int(i[1]), int(i[2])),
                                              (int(i[3]), int(i[4])))
            elif i[0] == "B":
                self.plat = platform.Books((int(i[1]), int(i[2])), int(i[3]))
            elif i[0] == "PE":
                self.enemy = E.PlatformEnemy(self.plat)
                self.enemies.add(self.enemy)
            elif i[0] == "GE":
                self.enemy = E.GhostEnemy((int(i[1]), int(i[2])))
                self.enemies.add(self.enemy)
            elif i[0] == "TRFE":
                self.triggers.append(
                    trigger.Trigger("FE", (int(i[1]), int(i[2])),
                                    (int(i[3]), int(i[4]))))
            elif i[0] == "TRGE":
                self.triggers.append(
                    trigger.Trigger("GE", (int(i[1]), int(i[2])),
                                    (int(i[3]), int(i[4]))))
            elif i[0] == "TRPE":
                self.plat = platform.Platform((int(i[1]), int(i[2])),
                                              (int(i[3]), int(i[4])),
                                              (int(i[5]), int(i[6])))
                self.triggers.append(trigger.Trigger("PE", (-1, -1),
                                                     self.plat))
            elif i[0] == "SH":
                enemy = E.ShooterEnemy((int(i[1]), int(i[2])), float(i[3]))
                self.shooters.append(enemy)
            elif i[0] == "I":
                self.enemy = E.Spider((int(i[1]), int(i[2])))
                self.enemies.add(self.enemy)
            elif i[0] == "T":
                enemy = boss.Boss()
                self.bosses.add(enemy)
            elif i[0] == "BE":
                enemy = E.BookEnemy((int(i[1]), int(i[2])), i[3])
                self.enemies.add(enemy)
예제 #2
0
    def resolve_trigger(self, trig):
        v.p(verbose_msg,
            "Resolving trigger: " + trig.name + " for " + trig.target.name)
        print(self.trigger_list)
        if trig.name == "Stun No Parry":
            if trig.target.stun_ends_at > self.time:
                new_trig = trigger.Trigger("Stun", trig.target,
                                           trig.target.stun_ends_at)
                self.add_trigger(new_trig)

        else:
            v.p(verbose_msg,
                "Not actually doing anything with this trigger: " + trig.name)
        trig.target.update_status()
예제 #3
0
def test_rule_matches_string():
    '''
    Test regex matching is working properly
    for a string
    '''
    # Mock options to instantiate mailer
    with patch.dict(trigger.OPTIONS, trigger.DEFAULT_OPTIONS):
        with patch.dict(trigger.MAIL_OPTIONS, trigger.DEFAULT_MAIL_OPTIONS):
            with patch.dict(trigger.TELEGRAM_OPTIONS,
                            trigger.DEFAULT_TELEGRAM_OPTIONS):
                my_trigger = trigger.Trigger()
                with patch.object(trigger, 're') as regex:
                    regex.search.side_effect = [MagicMock(), None]
                    assert my_trigger._rule_matches('regex', 'value1') is True
                    regex.search.assert_called_with('regex', 'value1')
                    assert my_trigger._rule_matches('regex', 'value2') is False
                    regex.search.assert_called_with('regex', 'value2')
예제 #4
0
def test_rules_evaluation(alert_spec, input_rules, expected_mail_contacts,
                          expected_telegram_contacts):
    '''
    Test that rules are properly evaluated
    '''
    with patch.dict(trigger.OPTIONS, trigger.DEFAULT_OPTIONS):
        with patch.dict(trigger.MAIL_OPTIONS, trigger.DEFAULT_MAIL_OPTIONS):
            with patch.dict(trigger.TELEGRAM_OPTIONS,
                            trigger.DEFAULT_TELEGRAM_OPTIONS):
                trigger.OPTIONS['group_rules'] = input_rules
                mail_sender = trigger.Trigger()
                with patch.object(mail_sender, '_send_email_message') as _sem:
                    alert = Alert.parse(alert_spec)
                    emailed_contacts, telegram_contacts = mail_sender.diagnose(
                        alert)
                    assert _sem.call_count == 1
                    assert emailed_contacts == expected_mail_contacts
                    assert telegram_contacts == expected_telegram_contacts
예제 #5
0
    def LoadTriggers(self):
        section = self.ini['Triggers']
        triggermap = {}
        triggerCurrent = None
        for prop in section:
            if prop[0] == 'Count':
                continue
            if prop[0] == 'T':
                triggerCurrent = trigger.Trigger()
                for key in prop[1].split(','):
                    triggermap[key] = triggerCurrent
                continue
            if prop[0] == 'C':
                triggerCurrent.LoadCondition(prop[1])
                continue
            if prop[0] == 'A':
                triggerCurrent.LoadAction(prop[1])
                continue

        # Make lists of triggers for each side, from triggermap
        for side in xrange(len(self.sidetriggers)):
            index = 0
            while True:
                found = False
                for key in triggermap.keys():
                    sideT = int(key.split(':')[0])
                    if sideT != side:
                        continue
                    indexT = int(key.split(':')[1])
                    if indexT != index:
                        continue
                    found = True
                    self.sidetriggers[side].append(triggermap[key])
                if not found:
                    break
                index = index + 1
예제 #6
0
 def DoInitialise(self):
     conf = self.GetInitConfiguration().as_dict()
     self.trigger = trigger.Trigger(conf['trigger_path'])
     self.plane = int(conf['plane'])
예제 #7
0
 def setUp(self):
     self.logic = trigger.Trigger()
     patcher = mock.patch('time.time')
     self.addCleanup(patcher.stop)
     self.mock_time = patcher.start()
     self.mock_time.return_value = 1234
예제 #8
0
        # Return Retweets for posting on other bots
        return all_tweets


if __name__ == "__main__":
    # get the config dict of dicts
    with open('config.toml') as configfile:
        config = toml.load(configfile)

    # set log file
    fh = logging.FileHandler(config['logging']['logpath'])
    fh.setLevel(logging.DEBUG)
    logger.addHandler(fh)

    # initialise trigger
    trigger = trigger.Trigger(config)

    # initialise twitter bot
    bot = RetweetBot(config)

    try:
        while True:
            # :todo separate into small functions
            bot.flow(trigger)
            sleep(60)
    except KeyboardInterrupt:
        print("Good bye. Remember to restart the bot!")
    except:
        logger.error('Shutdown', exc_info=True)
        bot.save_last()
        try:
예제 #9
0
    def resolve_attack(self, action):
        roll = dice.oehighroll()
        table = self.attack_tables[action.attack_table]
        if roll <= table.fumble:
            v.p(verbose_msg, "Attack roll is fumbled: " + str(roll))
            self.add_to_log(action.combatant.name + " fumbled the attack.")
        else:
            penalties = self.calc_penalties(action.combatant.hits,
                                            action.combatant.max_hits,
                                            action.combatant.exhpts,
                                            action.combatant.max_exhpts)
            if action.target.current_action.action_type == 0 and \
                            action.target.current_action.target == action.combatant:
                target_parry = action.target.current_action.parry_DB
            else:
                target_parry = 0

            if action.attack_ranged:
                # need to deal with parrying ranged attacks
                adjusted_roll = roll + action.attack_OB + penalties[
                    0] - action.target.DB_ranged
            else:
                adjusted_roll = roll + action.attack_OB + penalties[
                    0] - action.target.DB_melee - target_parry

            v.p(
                verbose_msg, "Roll: " + str(roll) + "OB: " +
                str(action.attack_OB) + " Pen: " + str(penalties[0]) +
                " DBs: " + str(action.target.DB_melee) + "/" +
                str(action.target.DB_ranged) + " Parried by: " +
                str(target_parry) + " Final: " + str(adjusted_roll))

            for item in table.results:
                if adjusted_roll < int(item[0]):
                    pass
                else:
                    result = item[22 - action.target.AT]
                    v.p(verbose_msg, "Attack result: " + result)
                    if result == "-":
                        self.add_to_log(action.combatant.name + " missed " +
                                        action.target.name)
                    else:
                        if result[len(result) - 1].isdigit():
                            damage = int(result)
                            self.add_to_log(action.combatant.name + " did " +
                                            str(damage) + " hits to " +
                                            action.target.name)
                        else:
                            i = 0
                            while result[i].isdigit():
                                i += 1
                            damage = int(result[0:i])
                            critical_level = result[i:]
                            self.add_to_log(action.combatant.name + " did " +
                                            str(damage) + " hits and a " +
                                            critical_level + " critical to " +
                                            action.target.name)

                            critical_table = self.critical_tables[
                                self.attack_tables[
                                    action.attack_table].critical_type]
                            critical_column = critical_table.columns[
                                critical_level]
                            i = 0
                            critical_roll = dice.Dice.d100()
                            while critical_column[i][2] < critical_roll:
                                i += 1
                            crit = critical_column[i]
                            log_message = "Crit: " + str(
                                critical_roll) + " " + crit[3] + "\n   "

                            #Next four lines are for testing purposes:
                            crit[8] = "1~0"
                            crit[7] = "2~0"
                            crit[6] = "1~0"

                            if crit[4] != 0:
                                damage += crit[4]
                                log_message = log_message + " Hits: " + str(
                                    crit[4])
                            if crit[5] != 0:
                                rtrigger = trigger.Trigger(
                                    "Bleeding", action.target, self.time + 10,
                                    {"damage": crit[5]})
                                self.add_recurring_trigger(rtrigger)
                                log_message = log_message + " Bleeding: " + str(
                                    crit[5])
                            if crit[8] != "0~0":
                                snp = crit[8].split("~")
                                num_of_rounds = int(snp[0])
                                penalty = int(snp[1])
                                stun_duration = 0
                                if action.target.stun_no_parry_ends_at > self.time:
                                    end_time = action.target.stun_no_parry_ends_at + 10 * num_of_rounds
                                    for i in self.trigger_list[
                                            action.target.
                                            stun_no_parry_ends_at]:
                                        if i.name == "Stun No Parry" and i.target == action.target:
                                            self.trigger_list[
                                                action.target.
                                                stun_no_parry_ends_at].remove(
                                                    i)
                                    if action.target.stun_ends_at > action.target.stun_no_parry_ends_at:
                                        stun_duration = action.target.stun_ends_at - action.target.stun_no_parry_ends_at
                                        for i in self.trigger_list[
                                                action.target.stun_ends_at]:
                                            if i.name == "Stun" and i.target == action.target:
                                                self.trigger_list[
                                                    action.target.
                                                    stun_ends_at].remove(i)
                                else:
                                    end_time = self.time + 10 * num_of_rounds
                                    if action.target.stun_ends_at > self.time:
                                        stun_duration = action.target.stun_ends_at - self.time
                                action.target.stun_no_parry_ends_at = end_time
                                action.target.stun_ends_at = end_time + stun_duration
                                trig = trigger.Trigger("Stun No Parry",
                                                       action.target, end_time)
                                self.add_trigger(trig)
                                log_message = log_message + " Stun No Parry: " + snp[
                                    0]
                            if crit[7] != "0~0":
                                snp = crit[7].split("~")
                                num_of_rounds = int(snp[0])
                                penalty = int(snp[1])
                                must_parry_duration = 0
                                if action.target.stun_ends_at > self.time:
                                    end_time = action.target.stun_ends_at + 10 * num_of_rounds
                                    for i in self.trigger_list[
                                            action.target.stun_ends_at]:
                                        if i.name == "Stun" and i.target == action.target:
                                            self.trigger_list[
                                                action.target.
                                                stun_ends_at].remove(i)
                                    if action.target.must_parry_ends_at > action.target.stun_ends_at:
                                        must_parry_duration = action.target.must_parry_ends_at - action.target.stun_ends_at
                                        for i in self.trigger_list[
                                                action.target.
                                                must_parry_ends_at]:
                                            if i.name == "Must Parry" and i.target == action.target:
                                                self.trigger_list[
                                                    action.target.
                                                    must_parry_ends_at].remove(
                                                        i)
                                else:
                                    end_time = self.time + 10 * num_of_rounds
                                    if action.target.must_parry_ends_at > self.time:
                                        must_parry_duration = action.target.must_parry_ends_at - self.time
                                action.target.stun_ends_at = end_time
                                action.target.must_parry_ends_at = end_time + must_parry_duration
                                trig = trigger.Trigger("Stun", action.target,
                                                       end_time)
                                self.add_trigger(trig)
                                log_message = log_message + " Stunned: " + snp[
                                    0]
                            if crit[6] != "0~0":
                                snp = crit[6].split("~")
                                num_of_rounds = int(snp[0])
                                penalty = int(snp[1])
                                initiative_loss_duration = 0
                                if action.target.must_parry_ends_at > self.time:
                                    end_time = action.target.must_parry_ends_at + 10 * num_of_rounds
                                    for i in self.trigger_list[
                                            action.target.must_parry_ends_at]:
                                        if i.name == "Must Parry" and i.target == action.target:
                                            self.trigger_list[
                                                action.target.
                                                must_parry_ends_at].remove(i)
                                    if action.target.initiative_loss_ends_at > action.target.must_parry_ends_at:
                                        initiative_loss_duration = action.target.initiative_loss_ends_at - action.target.must_parry_ends_at
                                        for i in self.trigger_list[
                                                action.target.
                                                initiative_loss_ends_at]:
                                            if i.name == "Initiative Loss" and i.target == action.target:
                                                self.trigger_list[
                                                    action.target.
                                                    initiative_loss_ends_at].remove(
                                                        i)
                                else:
                                    end_time = self.time + 10 * num_of_rounds
                                    if action.target.initiative_loss_ends_at > self.time:
                                        initiative_loss_duration = action.target.initiative_loss_ends_at - self.time
                                action.target.must_parry_ends_at = end_time
                                action.target.initiative_loss_ends_at = end_time + initiative_loss_duration
                                trig = trigger.Trigger("Must Parry",
                                                       action.target, end_time)
                                self.add_trigger(trig)
                                log_message = log_message + " Must Parry: " + snp[
                                    0]

                            self.add_to_log(log_message)
                        action.target.hits += -damage
                        action.target.update_status()
                    break
예제 #10
0
import lights
import trigger
import samples
import sys
import time

debug = False
if len(sys.argv) > 1:
    if sys.argv[1] == "debug":  # sys.argv[0] is the filename
        debug = True

lights = lights.Lights()
trigger = trigger.Trigger(23, trigger_distance=40)
samples = samples.SamplePlayer()
p_is_open = False
now = None

while True:
    distance = trigger.get_distance()
    if not now or time.time() - now > 0.5:
        is_open = trigger.lid_is_open()

    if is_open:
        lights.on_open(distance)

    if is_open is not p_is_open:
        p_is_open = is_open
        if is_open:
            now = time.time()
            samples.play_random()
            print("opening")