예제 #1
0
    def make_relations(city):
        """ Try to make relations between citizens of current city """
        #we get all possible variants here, to see if we can make connection
        suspicion_of_connection = combinations(filter(lambda x: not x.dead, city.denizens), 2)
        for pair in suspicion_of_connection:
            #if they're still not acquainted - make them friends or enemies
            a, b = pair
            if a.dead or b.dead: continue

            if not a.know(b) and util.onechancein(3):
                a.ack(b, city)
            elif a.know(b):
                a.meet(b, city)
        for denizen in city.denizens:
            denizen.free_action(city)
        for deity in city.deities:
            deity.free_action(city)
        if isinstance(world.king, KingNPC):
            world.king.free_action(city)
        if city.plague_src : #if there is a plague in the city
            if util.onechancein(15) and city==world.capital and len(world.royalties): 
                #infect royalty
                victim = choice(world.royalties)
                victim.plague = True
            elif util.onechancein(7) and len(city.denizens):
                victim = choice(city.denizens)
                victim.plague = True
예제 #2
0
    def make_relations(city):
        """ Try to make relations between citizens of current city """
        #we get all possible variants here, to see if we can make connection
        suspicion_of_connection = combinations(
            filter(lambda x: not x.dead, city.denizens), 2)
        for pair in suspicion_of_connection:
            #if they're still not acquainted - make them friends or enemies
            a, b = pair
            if a.dead or b.dead: continue

            if not a.know(b) and util.onechancein(3):
                a.ack(b, city)
            elif a.know(b):
                a.meet(b, city)
        for denizen in city.denizens:
            denizen.free_action(city)
        for deity in city.deities:
            deity.free_action(city)
        if isinstance(world.king, KingNPC):
            world.king.free_action(city)
        if city.plague_src:  #if there is a plague in the city
            if util.onechancein(15) and city == world.capital and len(
                    world.royalties):
                #infect royalty
                victim = choice(world.royalties)
                victim.plague = True
            elif util.onechancein(7) and len(city.denizens):
                victim = choice(city.denizens)
                victim.plague = True
예제 #3
0
def _add_enchants(wep, cost, single_digit=False):
    max_wait = 20
    while cost > 0 and wep.enchantment < wep.max_enchantment and max_wait > 0:
        max_wait -= 1
        if single_digit:
            if util.onechancein(3) and wep.enchantment < wep.max_enchantment and cost > 0:
                wep.enchantment += 1
                cost -= ONE_PIECE_ENCHANTMENT
        else:
            for x in (0, 1):
                if util.onechancein(3) and wep.enchantment[x] < wep.max_enchantment[x] and cost > 0:
                    wep.enchantment[x] += 1
                    cost -= ONE_PIECE_ENCHANTMENT
예제 #4
0
def acquire_armor(npc, unique=None, base_type=None, artefact=False):
    cost = TOP_COST_ARMOR + random.randrange(-1 * TOP_COST_ARMOR_RANGE, TOP_COST_ARMOR_RANGE)
    if base_type is None:
        base_type = random.choice(items.weapon)
    cost -= base_type.base_cost
    arm = base_type()
    if util.onechancein(6):
        cost -= _make_resist(arm)
    elif util.onechancein(7) or artefact:
        cost += FIXED_ART_UP
        cost -= _make_randart(arm, unique)
        cost -= _add_misc(arm, cost)
    _add_enchants(arm, cost, True)
    return arm
예제 #5
0
 def fulfil(self, hero, chance=15):
     if util.onechancein(chance): #yeah, rescuing princesses is that simple
         world.global_quests.remove(self)
         hero.history.append('In year %d %s rescued %s' %
                 (world.year, hero.name, self.who.name))
         self.who.rescued_by(hero)
         self.issuer.award_for_quest(hero, self)
예제 #6
0
 def fulfil(self, hero, chance=15):
     if util.onechancein(chance):
         thief = 'unknown man'
         if self.thief:
             thief = self.thief.name
         world.global_quests.remove(self)
         hero.history.append('In year %d %s retrieved %s from %s' %
                 (world.year, hero.name, self.what.unique_name, thief))
         hero.retrieved_stolen_from(self.thief, self.what, self.issuer, stolen=False)
예제 #7
0
def generate_artefacts(artefacts_count, check=None):
    """Generates as many artefacts as specified by artefacts_count argument."""
    result = []
    arts = artefacts[:]
    shuffle(arts)
    while artefacts_count > 0:
        artefacts_count -= 1
        if util.onechancein(3) and len(arts) > 0:
            result.append(arts.pop())
        else:
            result.append(acquire(unique=check, artefact=True))
    return result
예제 #8
0
def generate_artefacts(artefacts_count, check=None):
    """Generates as many artefacts as specified by artefacts_count argument."""
    result = []
    arts = artefacts[:]
    shuffle(arts)
    while artefacts_count > 0:
        artefacts_count -= 1
        if util.onechancein(3) and len(arts) > 0:
            result.append(arts.pop())
        else:
            result.append(acquire(unique=check, artefact=True))
    return result
예제 #9
0
def acquire_weapon(npc, unique=None):
    cost = TOP_COST_WEP + random.randrange(-1 * TOP_COST_WEP_RANGE, TOP_COST_WEP_RANGE)
    base_type = random.choice(items.weapons)
    cost -= base_type.base_cost
    wep = base_type()
    if util.coinflip():
        cost -= _make_brand(wep)
    if util.onechancein(5):
        cost += FIXED_ART_UP
        cost -= _make_randart(wep, unique)
        cost -= _add_misc(wep, cost)
    _add_enchants(wep, cost)
    return wep
예제 #10
0
def _add_misc(wep, cost):
    old_cost = cost
    accumulated_chance = 2
    accumulated_cost = 100
    feats = items.multilevel_features[:]*3 + items.innate_features[:]
    random.shuffle(feats)
    for feat in feats:
        if cost <= 0 : break
        if util.onechancein(accumulated_chance):
            wep.resists.append(feat)
            cost -= accumulated_cost
            accumulated_cost *= 3
            accumulated_chance *= 2
    return old_cost - cost
예제 #11
0
 assign_random_name_from_list((WereNPC, BadNPC), world.demon_npc_names, demon=True)
 assign_random_name_from_list(DeityNPC, world.deity_npc_names)
 #all that left without names gets brand new name
 for npc in world.mNPC:
     if npc.name is None:
         name = util.gen_name(check_unique=world.npc_names)
         if debug_names:
             name += ' ' + str(npc.__class__)
         npc.name = name
 #now we handle WereNPC, so that each get his own proxy and target
 weres = filter(lambda x: isinstance(x, WereNPC), world.mNPC)
 wered_npc = {}
 for were in weres:
     while True:
         #first find target
         if util.onechancein(20): #mimic royalty
             if util.coinflip():
                 if wered_npc.has_key(world.king): continue
                 were.target = world.king
                 wered_npc[world.king] = were
                 logger.debug('King will be WereNPC  '+ were.name)
             else:
                 royalty = choice(world.royalties)
                 if wered_npc.has_key(royalty): continue
                 were.target = royalty
                 wered_npc[royalty] = were
                 logger.debug('%s %s will be WereNPC %s' % (royalty.type, royalty.name, were.name))
             break
         else:
             target = choice(world.mNPC)
             if isinstance(target, WereNPC): continue
예제 #12
0
 def fulfil(self, hero, chance=15):
     if util.onechancein(chance):
         hero.retrieve_lost(self.issuer, self.what)
         world.global_quests.remove(self)
예제 #13
0
def _make_resist(arm):
    """ This is used for items with single resistance alowed - like armor """
    if util.onechancein(5):
        arm.resist = "fire"
    return 400
예제 #14
0
                              demon=True)
 assign_random_name_from_list(DeityNPC, world.deity_npc_names)
 #all that left without names gets brand new name
 for npc in world.mNPC:
     if npc.name is None:
         name = util.gen_name(check_unique=world.npc_names)
         if debug_names:
             name += ' ' + str(npc.__class__)
         npc.name = name
 #now we handle WereNPC, so that each get his own proxy and target
 weres = filter(lambda x: isinstance(x, WereNPC), world.mNPC)
 wered_npc = {}
 for were in weres:
     while True:
         #first find target
         if util.onechancein(20):  #mimic royalty
             if util.coinflip():
                 if wered_npc.has_key(world.king): continue
                 were.target = world.king
                 wered_npc[world.king] = were
                 logger.debug('King will be WereNPC  ' + were.name)
             else:
                 royalty = choice(world.royalties)
                 if wered_npc.has_key(royalty): continue
                 were.target = royalty
                 wered_npc[royalty] = were
                 logger.debug('%s %s will be WereNPC %s' %
                              (royalty.type, royalty.name, were.name))
             break
         else:
             target = choice(world.mNPC)