def random_classic_traveller_character(name: str, must_be_alive=False): """ Produces a random character for classic traveller :param name: the name of the character :param must_be_alive: to forgo the rolls of characters that failed to survive their term :return: a CTCharacter object """ valid_char = False character = CTCharacter(name=name) while not valid_char: character = CTCharacter(name=name) choice_service = roll_die(6) services = ["Navy", "Marines", "Army", "Others", "Scouts", "Merchants"] character.choose_service(services[choice_service - 1], True) stays_in_service = True while character.survived and stays_in_service: character.term(automatic=True) if character.survived: if character.reenlisting == 0: reenlist_roll = roll_die(2) if reenlist_roll == 0: stays_in_service = False elif character.reenlisting == -1: stays_in_service = False if character.survived: character.calc_muster_out(automatic=True) if (must_be_alive and character.survived) or not must_be_alive: valid_char = True return character
def benefit_weapon(self, benefit, automatic=False): """ If the benefit is a weapon, check for skills the character has and picks a weapon in this category if automatic, else just displays the information :param benefit: the weapon type :param automatic: if it's automatic or not :return: the weapon to add to the benefits """ has_skill = self.check_for_sub_skill(benefit + " Combat") # print("Skills are: {h}".format(h=has_skill)) if benefit == "Blade": table = BLADE_CBT_CASC else: table = GUN_CBT_CASC if not automatic: if len(has_skill) > 0: print("You have the following skills in {group}: {b}".format( group=benefit, b=has_skill)) print(table) weapon = input( "Choose a type of {w} to receive.\n".format(w=benefit)) while weapon not in table: weapon = input( "Choose a type of {w} to receive.\n".format(w=benefit)) received_weapon = weapon else: if len(has_skill) > 0: received_weapon = has_skill[0] else: weapon_choice = roll_die(len(table)) received_weapon = table[weapon_choice - 1] self.history.append("Received a {w} as a muster-out benefit.".format( w=received_weapon)) return received_weapon
def roll_benefit(self): """ Rolls for benefits according to proper table :return: a list of benefits as str """ table = [] dm = 0 if self.service == "Navy": table = NAVY_BENEFITS elif self.service == "Marines": table = MARINES_BENEFITS elif self.service == "Army": table = ARMY_BENEFITS elif self.service == "Merchants": table = MERCHANTS_BENEFITS elif self.service == "Scouts": table = SCOUTS_BENEFITS elif self.service == "Others": table = OTHERS_BENEFITS if self.service in ["Navy", "Marines", "Army", "Merchants" ] and self.rank > 4: dm += 1 roll = roll_die(6) + dm - 1 # offset for array if roll >= len(table): # for tables that are shorter roll = len(table) - 1 benefit = table[roll] return benefit
def roll_cash(self): """ Rolls for cash benefits according to proper table and adds it to self.cash """ table = [] dm = 0 if self.service == "Navy": table = NAVY_CASH elif self.service == "Marines": table = MARINES_CASH elif self.service == "Army": table = ARMY_CASH elif self.service == "Merchants": table = MERCHANTS_CASH elif self.service == "Scouts": table = SCOUTS_CASH elif self.service == "Others": table = OTHERS_CASH if self.service in ["Army", "Navy", "Marines", "Merchants" ] and self.rank >= 5: dm += 1 if "Gambling" in self.skills.keys(): dm += 1 roll = roll_die(6) + dm - 1 # offset for array self.cash += table[roll] self.history.append( "Received {c} Credits as a muster-out benefit.".format( c=table[roll])) return table[roll]
def calc_muster_out(self, automatic=False): """ Calculates and asks for player choices on mustering out rolls Automatic sets all choices to random """ if self.reenlisting == 0: self.history.append( "Chose to leave the {ser}".format(ser=self.service)) total_rolls = self.terms bonus_ben = 0 cash_max = 3 benefits = [] if 1 <= self.rank <= 2: bonus_ben = 1 elif 3 <= self.rank <= 4: bonus_ben = 2 elif 5 <= self.rank <= 6: bonus_ben = 3 total_rolls += bonus_ben self.history.append( "Mustering out benefits: {i}".format(i=total_rolls)) if not automatic: while total_rolls > 0: if cash_max > 0: x = input( "Do you want cash or a benefit? You have {t} total rolls left (max {c} cash rolls)." " c for cash, b for benefit\n".format(c=cash_max, t=total_rolls)) if x == "c": cash_max -= 1 total_rolls -= 1 cash = self.roll_cash() print("{c} Credits".format(c=cash)) elif x == "b": total_rolls -= 1 benefit = self.roll_benefit() benefits.append(benefit) print(benefit) else: total_rolls -= 1 benefits.append(self.roll_benefit()) else: while total_rolls > 0: if cash_max > 0: cash_or_benefit = roll_die(2) if cash_or_benefit == 1: cash_max -= 1 total_rolls -= 1 self.roll_cash() else: total_rolls -= 1 benefit = self.roll_benefit() benefits.append(benefit) else: total_rolls -= 1 benefits.append(self.roll_benefit()) self.benefits = self.treat_benefits(benefits, automatic=automatic) self.calc_pension()
def calc_world_presence(self, dm=0): """ Worlds have a 50% chance of existing in a hex in most cases :param dm modifier is for cases in which sectors are more densily with worlds """ roll = roll_die(6) + dm if roll > 3: self.has_world = True
def test_boundaries_roll_20(self): """ Tests that rolls do not go higher than 20 or lower than 1 (for a 100 repeats) :return: nothing """ for i in range(100): a = roll_die(20) assert (a > 0) assert (a < 21)
def get_random_spell(): """ Returns a random spell from the database :return: a DnD5Spell """ number = get_number_of_spells_in_db() roll = roll_die(number - 1) spell = get_spell_by_id(roll) return spell
def get_random_monster(): """ Returns a random monster from the database :return: a DnD5Monster """ number = get_number_of_monsters_in_db() roll = roll_die(number) monster = get_monster_by_id(roll) return monster
def calc_technological_level(self): dm = 0 if self.hex.starport == "A": dm += 6 elif self.hex.starport == "B": dm += 4 elif self.hex.starport == "C": dm += 2 elif self.hex.starport == "X": dm -= 4 if self.size in ["0", "1"]: dm += 2 elif self.size in ["2", "3", "4"]: dm += 1 if self.atmosphere in ["0", "1", "2", "3", "A", "B", "C", "D", "E"]: dm += 1 if self.hydrography == "9": dm += 1 elif self.hydrography == "A": dm += 2 if self.population in ["1", "2", "3", "4", "5"]: dm += 1 elif self.population == "9": dm += 2 elif self.population == "A": dm += 4 if self.government == "0": dm += 1 elif self.government == "5": dm += 1 elif self.government == "D": dm -= 2 if self.government == "A": gov = 10 elif self.government == "B": gov = 11 elif self.government == "C": gov = 12 elif self.government == "D": gov = 13 else: gov = self.government roll = roll_die(6) + int(gov) + dm if roll < 0: roll = 0 # arbitrary max tl 16 hex_trans = hex(roll)[2:].upper() if len(hex_trans) > 1: hex_trans = hex_trans[len(hex_trans) - 1] self.technological_level = hex_trans
def __init__(self, name="", world_dm=0, hex_position=""): self.name = name self.hex = hex_position self.has_world = False self.has_gas_giant = False self.gas_giant_number = 0 self.starport = "X" self.has_naval_base = False self.has_scout_base = False self.worlds = [] self.calc_world_presence(dm=world_dm) if self.has_world: self.calc_gas_giant_presence() self.calc_starport_type() self.calc_naval_base() self.calc_scout_base() if self.has_gas_giant: roll = roll_die(3) self.gas_giant_number = roll roll = roll_die(3) for _ in range(roll): self.worlds.append(CTWorld(self))
def get_drafted(self): """ Rolls for the draft """ a = roll_die(6) - 1 if a == 0: self.service = "Marines" elif a == 1: self.service = "Navy" elif a == 2: self.service = "Army" elif a == 3: self.service = "Merchants" elif a == 4: self.service = "Scouts" elif a == 5: self.service = "Others" self.history.append("Drafted in the {ser}.".format(ser=self.service))
def get_random_monster(): number = get_number_of_monsters_in_db() roll = roll_die(number) monster = get_monster_by_id(roll) return monster
def get_random_spell(): number = get_number_of_spells_in_db() roll = roll_die(number - 1) spell = get_spell_by_id(roll) return spell
def roll_skill(education, service_name, automatic=False): pers_tab = [] adv_skill_tab = [] serv_skill_tab = [] adv_edu_tab = [] if service_name == "Navy": pers_tab = NAVY_SKILLS_PERSONAL_DEV adv_skill_tab = NAVY_SKILLS_ADV serv_skill_tab = NAVY_SKILLS_SERVICE adv_edu_tab = NAVY_SKILLS_ADV_EDU elif service_name == "Marines": pers_tab = MARINES_SKILLS_PERSONAL_DEV adv_skill_tab = MARINES_SKILLS_ADV serv_skill_tab = MARINES_SKILLS_SERVICE adv_edu_tab = MARINES_SKILLS_ADV_EDU elif service_name == "Army": pers_tab = ARMY_SKILLS_PERSONAL_DEV adv_skill_tab = ARMY_SKILLS_ADV serv_skill_tab = ARMY_SKILLS_SERVICE adv_edu_tab = ARMY_SKILLS_ADV_EDU elif service_name == "Merchants": pers_tab = MERCHANTS_SKILLS_PERSONAL_DEV adv_skill_tab = MERCHANTS_SKILLS_ADV serv_skill_tab = MERCHANTS_SKILLS_SERVICE adv_edu_tab = MERCHANTS_SKILLS_ADV_EDU elif service_name == "Scouts": pers_tab = SCOUTS_SKILLS_PERSONAL_DEV adv_skill_tab = SCOUTS_SKILLS_ADV serv_skill_tab = SCOUTS_SKILLS_SERVICE adv_edu_tab = SCOUTS_SKILLS_ADV_EDU elif service_name == "Others": pers_tab = OTHERS_SKILLS_PERSONAL_DEV adv_skill_tab = OTHERS_SKILLS_ADV serv_skill_tab = OTHERS_SKILLS_SERVICE adv_edu_tab = OTHERS_SKILLS_ADV_EDU if education > 7: more = ", 4 for Advanced Education\n" else: more = "\n" table = 0 if not automatic: while (table not in ["1", "2", "3", "4"] and education > 7) or (table not in ["1", "2", "3"] and education < 8): table = input( "Choose a Table to roll on, 1 for Personal Development, " "2 for Service Skills, 3 for Advanced Skills{more}".format( more=more)) else: if education > 7: table = str(roll_die(4) + 1) else: table = str(roll_die(3) + 1) roll = roll_die(6) - 1 if table == "1": return pers_tab[roll] elif table == "2": return serv_skill_tab[roll] elif table == "3": return adv_skill_tab[roll] elif table == "4" and education > 7: return adv_edu_tab[roll]
def test_boundaries_roll_20(self): for i in range(100): a = roll_die(20) assert (a > 0) assert (a < 21)
def add_skills(self, automatic=False): """ Rolls on tables for skills and checks for cascading skill choices """ for _ in range(self.skill_rolls): skill = None while skill is None: if automatic: skill = roll_skill(self.stats["Edu"], self.service, automatic=True) else: skill = roll_skill(self.stats["Edu"], self.service) if skill.startswith("1"): split_skills = skill.split() if self.stats[split_skills[1]] < 15: self.stats[split_skills[1]] += 1 if not automatic: print("Improved {skill} by 1".format( skill=split_skills[1])) self.history.append( "Improved {skill} by 1".format(skill=split_skills[1])) else: print( "Going over the 15 point limit for a stat at creation for humans" ) elif skill.startswith("-"): split_skills = skill[1:].split() self.stats[split_skills[1]] -= 1 self.history.append( "Decreased {skill} by 1".format(skill=split_skills[1])) if not automatic: print( "Decreased {skill} by 1".format(skill=split_skills[1])) else: if skill in CASCADE_SKILLS: if skill == "Blade Combat": if not automatic: print(BLADE_CBT_CASC) spe_choice = input( "Choose one specialty from above for Blade Combat\n" ) while spe_choice not in BLADE_CBT_CASC: spe_choice = input( "Choose one specialty from above for Blade Combat\n" ) else: spe_choice_roll = roll_die(len(BLADE_CBT_CASC)) spe_choice = BLADE_CBT_CASC[spe_choice_roll - 1] skill = "Blade Combat({spe})".format(spe=spe_choice) elif skill == "Gun Combat": if not automatic: print(GUN_CBT_CASC) spe_choice = input( "Choose one specialty from above for Gun Combat\n" ) while spe_choice not in GUN_CBT_CASC: spe_choice = input( "Choose one specialty from above for Gun Combat\n" ) else: spe_choice_roll = roll_die(len(GUN_CBT_CASC)) spe_choice = GUN_CBT_CASC[spe_choice_roll - 1] skill = "Gun Combat({spe})".format(spe=spe_choice) elif skill == "Vehicle": if not automatic: print(VEHICLE_CASC) spe_choice = input( "Choose one specialty from above for Vehicle\n" ) while spe_choice not in VEHICLE_CASC: spe_choice = input( "Choose one specialty from above for Vehicle\n" ) else: spe_choice_roll = roll_die(len(VEHICLE_CASC)) spe_choice = VEHICLE_CASC[spe_choice_roll - 1] if spe_choice in ["Aircraft", "Watercraft"]: skill = spe_choice else: skill = "Vehicle({spe})".format(spe=spe_choice) if skill == "Aircraft": if not automatic: print(AIRCRAFT_CASC) spe_choice = input( "Choose one specialty from above for Aircraft\n" ) while spe_choice not in AIRCRAFT_CASC: spe_choice = input( "Choose one specialty from above for Aircraft\n" ) else: spe_choice_roll = roll_die(len(AIRCRAFT_CASC)) spe_choice = AIRCRAFT_CASC[spe_choice_roll - 1] skill = "Aircraft({spe})".format(spe=spe_choice) elif skill == "Watercraft": if not automatic: print(WATERCRAFT_CASC) spe_choice = input( "Choose one specialty from above for Watercraft\n" ) while spe_choice not in WATERCRAFT_CASC: spe_choice = input( "Choose one specialty from above for Watercraft\n" ) else: spe_choice_roll = roll_die(len(WATERCRAFT_CASC)) spe_choice = WATERCRAFT_CASC[spe_choice_roll - 1] skill = "Watercraft({spe})".format(spe=spe_choice) self.add_skill(skill, automatic=automatic)