mirror of
https://github.com/zoffline/zwift-offline.git
synced 2025-12-12 07:40:36 -08:00
Allow random body attributes for ghosts
Allow custom running equipment for ghosts
This commit is contained in:
@@ -46,6 +46,9 @@ def main(argv):
|
||||
parser.add_argument('-o', '--socks', help='Get socks', default=False)
|
||||
parser.add_argument('-g', '--glasses', help='Get glasses', default=False)
|
||||
megroup.add_argument('-p', '--paintjob', help='Get paintjob', default=False)
|
||||
parser.add_argument('--run_shirt', help='Get run shirt', default=False)
|
||||
parser.add_argument('--run_shorts', help='Get run shorts', default=False)
|
||||
parser.add_argument('--run_shoes', help='Get run shoes', default=False)
|
||||
args = parser.parse_args()
|
||||
|
||||
total_data = {}
|
||||
@@ -70,6 +73,13 @@ def main(argv):
|
||||
total_data.update(get_item("./PAINTJOBS/PAINTJOB", args.paintjob, 'bike_frame_colour'))
|
||||
total_data['bike_frame_colour'] <<= 32
|
||||
total_data.update(get_item("./BIKEFRAMES/BIKEFRAME", total_data['bike_frame_colour_name'].split('-')[0], 'bike_frame'))
|
||||
if args.run_shirt:
|
||||
total_data.update(get_item("./RUNSHIRTS/RUNSHIRT", args.run_shirt, 'run_shirt_type'))
|
||||
if args.run_shorts:
|
||||
total_data.update(get_item("./RUNSHORTS/RUNSHORT", args.run_shorts, 'run_shorts_type'))
|
||||
if args.run_shoes:
|
||||
total_data.update(get_item("./RUNSHOES/RUNSHOE", args.run_shoes, 'run_shoes_type'))
|
||||
total_data['random_body'] = False
|
||||
|
||||
data = json.dumps(total_data, indent=2)
|
||||
print(data)
|
||||
|
||||
@@ -514,7 +514,7 @@ def load_bots():
|
||||
positions = []
|
||||
for n in range(0, multiplier):
|
||||
p = profile_pb2.PlayerProfile()
|
||||
p.CopyFrom(zo.random_profile(p))
|
||||
zo.random_equipment(p)
|
||||
p.id = i + 1000000 + n * 10000
|
||||
global_bots[p.id] = BotVariables()
|
||||
bot = global_bots[p.id]
|
||||
@@ -532,17 +532,11 @@ def load_bots():
|
||||
loop_riders = get_names()
|
||||
random.shuffle(loop_riders)
|
||||
rider = loop_riders.pop()
|
||||
for item in ['first_name', 'last_name', 'is_male', 'country_code', 'ride_jersey', 'bike_frame', 'bike_frame_colour', 'bike_wheel_front', 'bike_wheel_rear', 'ride_helmet_type', 'glasses_type', 'ride_shoes_type', 'ride_socks_type']:
|
||||
for item in ['first_name', 'last_name', 'is_male', 'country_code', 'bike_frame', 'bike_frame_colour', 'bike_wheel_front', 'bike_wheel_rear',
|
||||
'glasses_type', 'ride_jersey', 'ride_helmet_type', 'ride_shoes_type', 'ride_socks_type', 'run_shirt_type', 'run_shorts_type', 'run_shoes_type']:
|
||||
if item in rider:
|
||||
setattr(p, item, rider[item])
|
||||
p.hair_type = random.choice(zo.GD['hair_types'])
|
||||
p.hair_colour = random.randrange(5)
|
||||
if p.is_male:
|
||||
p.body_type = random.choice(zo.GD['body_types_male'])
|
||||
p.facial_hair_type = random.choice(zo.GD['facial_hair_types'])
|
||||
p.facial_hair_colour = random.randrange(5)
|
||||
else:
|
||||
p.body_type = random.choice(zo.GD['body_types_female'])
|
||||
zo.random_body(p)
|
||||
bot.profile = p
|
||||
i += 1
|
||||
|
||||
|
||||
@@ -2124,7 +2124,7 @@ def time_since(date):
|
||||
if interval > 1: interval_type += 's'
|
||||
return '%s %s ago' % (interval, interval_type)
|
||||
|
||||
def random_profile(p):
|
||||
def random_equipment(p):
|
||||
p.ride_helmet_type = random.choice(GD['headgears'])
|
||||
p.glasses_type = random.choice(GD['glasses'])
|
||||
p.ride_shoes_type = random.choice(GD['bikeshoes'])
|
||||
@@ -2136,7 +2136,18 @@ def random_profile(p):
|
||||
p.run_shirt_type = random.choice(GD['runshirts'])
|
||||
p.run_shorts_type = random.choice(GD['runshorts'])
|
||||
p.run_shoes_type = random.choice(GD['runshoes'])
|
||||
return p
|
||||
|
||||
def random_body(p, random_gender=False):
|
||||
if random_gender:
|
||||
p.is_male = bool(random.getrandbits(1))
|
||||
p.hair_type = random.choice(GD['hair_types'])
|
||||
p.hair_colour = random.randrange(5)
|
||||
if p.is_male:
|
||||
p.body_type = random.choice(GD['body_types_male'])
|
||||
p.facial_hair_type = random.choice(GD['facial_hair_types'])
|
||||
p.facial_hair_colour = random.randrange(5)
|
||||
else:
|
||||
p.body_type = random.choice(GD['body_types_female'])
|
||||
|
||||
@app.route('/api/profiles', methods=['GET'])
|
||||
def api_profiles():
|
||||
@@ -2144,27 +2155,29 @@ def api_profiles():
|
||||
profiles = profile_pb2.PlayerProfiles()
|
||||
for i in args:
|
||||
p_id = int(i)
|
||||
profile = profile_pb2.PlayerProfile()
|
||||
if p_id > 10000000:
|
||||
ghostId = math.floor(p_id / 10000000)
|
||||
player_id = p_id - ghostId * 10000000
|
||||
p = profiles.profiles.add()
|
||||
profile_file = '%s/%s/profile.bin' % (STORAGE_DIR, player_id)
|
||||
if os.path.isfile(profile_file):
|
||||
with open(profile_file, 'rb') as fd:
|
||||
profile.ParseFromString(fd.read())
|
||||
p = profiles.profiles.add()
|
||||
p.CopyFrom(random_profile(profile))
|
||||
p.id = p_id
|
||||
p.first_name = ''
|
||||
try: # profile can be requested after ghost is deleted
|
||||
p.last_name = time_since(global_ghosts[player_id].play[ghostId-1].date)
|
||||
except:
|
||||
p.last_name = 'Ghost'
|
||||
p.country_code = 0
|
||||
if GHOST_PROFILE:
|
||||
for item in ['country_code', 'ride_jersey', 'bike_frame', 'bike_frame_colour', 'bike_wheel_front', 'bike_wheel_rear', 'ride_helmet_type', 'glasses_type', 'ride_shoes_type', 'ride_socks_type']:
|
||||
if item in GHOST_PROFILE:
|
||||
setattr(p, item, GHOST_PROFILE[item])
|
||||
p.ParseFromString(fd.read())
|
||||
p.id = p_id
|
||||
p.first_name = ''
|
||||
try: # profile can be requested after ghost is deleted
|
||||
p.last_name = time_since(global_ghosts[player_id].play[ghostId-1].date)
|
||||
except:
|
||||
p.last_name = 'Ghost'
|
||||
p.country_code = 0
|
||||
random_equipment(p)
|
||||
if GHOST_PROFILE:
|
||||
for item in ['is_male', 'country_code', 'bike_frame', 'bike_frame_colour', 'bike_wheel_front', 'bike_wheel_rear', 'glasses_type',
|
||||
'ride_jersey', 'ride_helmet_type', 'ride_shoes_type', 'ride_socks_type', 'run_shirt_type', 'run_shorts_type', 'run_shoes_type']:
|
||||
if item in GHOST_PROFILE:
|
||||
setattr(p, item, GHOST_PROFILE[item])
|
||||
if 'random_body' in GHOST_PROFILE and GHOST_PROFILE['random_body']:
|
||||
random_body(p, 'is_male' not in GHOST_PROFILE)
|
||||
elif p_id > 9000000:
|
||||
p = profiles.profiles.add()
|
||||
p.id = p_id
|
||||
@@ -2176,6 +2189,7 @@ def api_profiles():
|
||||
elif p_id in global_bots.keys():
|
||||
profile = global_bots[p_id].profile
|
||||
else:
|
||||
profile = profile_pb2.PlayerProfile()
|
||||
profile_file = '%s/%s/profile.bin' % (STORAGE_DIR, p_id)
|
||||
if os.path.isfile(profile_file):
|
||||
with open(profile_file, 'rb') as fd:
|
||||
|
||||
Reference in New Issue
Block a user