Beispiel #1
0
 def stringToLoot(self, inloot):
     if inloot == None:
         return None
     loot = inloot.lower().split(',')
     i = random.choice(loot[0].split('/'))
     item = items.byName(i)
     if item == None:
         sys.exit('%s not found' % i)
     if len(loot) < 2:
         count = 1
     else:
         count = int(loot[1])
     if len(loot) < 3:
         enchantments = []
         if item.name.startswith('magic_'):
             ench_level = 0
             if len(item.ench) > 0:
                 for e in item.ench.split(','):
                     k = int(e.split('-')[0])
                     v = int(e.split('-')[-1])
                     enchantments.append(dict({'id': k, 'lvl': v}))
     else:
         enchantments = list(loottable.enchant(item.name, int(loot[2])))
     return loottable.Loot(0, count, item.value, item.data, enchantments,
                           item.p_effect, item.customname, item.flag,
                           item.flagparam, item.lore, item.file)
Beispiel #2
0
 def buildFrameItemTag(self, i, ench=(), customname=''):
     item = items.byName(i)
     if customname == '':
         customname = item.customname
     thisloot = loottable.Loot(None, 1, item.value, item.data, ench,
                               item.p_effect, customname, item.flag,
                               item.flagparam, item.lore, item.file)
     return self.buildItemTag(thisloot)
def combat(a, b):
    """
    State machine that controls combat flow between a (typically the player)
    and b (typically player's enemy)
    """
    c_state = None
    n_state = "standby"
    while True:
        c_state = n_state

        if c_state == "standby":
            action = getAction(a, b)
            if action == "a":
                n_state = "a_attack"
            elif action == "i":
                n_state = "inventory"
            elif action == "e":
                n_state = "info"
            elif action == "r":
                n_state = "run"
            else:
                n_state = n_state
            print "----------------------------"  # Newline

        elif c_state == "effects":
            pass

        elif c_state == "a_attack":
            if "skip" in a.status:
                print a.name + " skipped their turn."
                a.status.remove("skip")
            elif "normal" in a.status:
                a.attack(b)
            time.sleep(1)
            if "dead" in b.status:
                n_state = "endturn"
            else:
                n_state = "b_attack"
        elif c_state == "b_attack":
            if "skip" in b.status:
                print b.name + " skipped their turn."
                b.status.remove("skip")
                time.sleep(1)
            elif "caught" in b.status:
                time.sleep(1)
                b.attack(a)
                b.status.remove("caught")
                raw_input("Press \"Enter\" to continue...")
            elif "normal" in a.status:
                b.attack(a)
                time.sleep(1)
            n_state = "endturn"

        elif c_state == "endturn":
            if "dead" in a.status:
                print a.name + " has been defeated!"
                print a.takeGold(50 * a.level)
                raw_input("Press \"Enter\" to continue...")
                break
            elif "dead" in b.status:
                print b.name + " has been defeated!"
                n_state = "win"
            else:
                n_state = "standby"

        elif c_state == "win":
            loot = loottable.Loot(b.level)
            if loot[1] is not None:
                a.giveItem(loot[1])
            a.giveGold(loot[0])
            a.giveExp((a.exp_needed / (9 + a.level)) * (b.level / a.level))
            raw_input("Press \"Enter\" to continue...")
            break

        elif c_state == "inventory":
            a.getInventory("combat")
            n_state = "standby"

        elif c_state == "info":
            b.getCharacterSheet()
            raw_input("Press \"Enter\" to continue...")
            n_state = "standby"

        elif c_state == "run":
            if random.randrange(1, 4) == 1:
                print "You were able to get away!"
                raw_input("Press \"Enter\" to continue...")
                break
            else:
                print "You couldn't get away and %s caught you!" % b.name
                n_state = "b_attack"
                b.status.append("caught")