content/hifi-content/davidkelly/production/clientBot/clientBot.js
2022-02-13 22:49:05 +01:00

134 lines
3.8 KiB
JavaScript

//
// BetterClientSimulationBotFromRecording.js
// examples
//
// Created by Brad Hefta-Gaub on 2/6/17.
// Copyright 2017 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
randFloat = function(low, high) {
return low + Math.random() * (high - low);
}
var URL_BASE = "https://s3-us-west-1.amazonaws.com/hifi-content/davidkelly/production/clientBot/";
var RECORDING_URL = URL_BASE + "daveBot.hfr";
var LOCATIONS_ARRAY = [{ min_x: -20, max_x: 60, y: 8.4, min_z: -80, max_z:0 }];
var LOCATION_PARAMS = LOCATIONS_ARRAY[Math.floor(Math.random() * LOCATIONS_ARRAY.length)];
var LOCATION = { x: randFloat(LOCATION_PARAMS.min_x, LOCATION_PARAMS.max_x), y: LOCATION_PARAMS.y, z: randFloat(LOCATION_PARAMS.min_z, LOCATION_PARAMS.max_z) };
Vec3.print("RANDOM LOCATION SELECTED:", LOCATION);
// Disable the privacy bubble
Users.disableIgnoreRadius();
// Set position here if playFromCurrentLocation is true
Agent.isAvatar = true;
Avatar.position = LOCATION;
Avatar.orientation = Quat.fromPitchYawRollDegrees(0, randFloat(0, 360), 0);
Avatar.scale = 1.0;
//Avatar.skeletonModelURL = "https://hifi-content.s3.amazonaws.com/ozan/dev/avatars/hifi_team/david/david.fst"
Recording.loadRecording(RECORDING_URL, function(success) {
if (success) {
Script.update.connect(update);
} else {
print("Failed to load recording from " + RECORDING_URL);
}
});
// This will make a new injector - so maybe every 10th update. Probably
// much worse than the appreciate app
var CHANCE_OF_SOUND = 0.1;
var sounds = [];
// we can always put more in here later (the appreciation app had 16)
function loadSounds() {
var sound_filenames = ["01.wav"];
for (var i = 0; i < sound_filenames.length; i++) {
sounds.push(SoundCache.getSound(URL_BASE + sound_filenames[i]));
}
}
loadSounds();
// Play a random sound from a list of conversational audio clips
var soundInjector = false;
function playRandomSound() {
console.log("Playing Sound!");
sound = sounds[Math.floor(Math.random() * sounds.length)];
if (soundInjector) {
soundInjector.stop();
soundInjector = false;
}
soundInjector = Audio.playSound(sound, {
position: LOCATION,
volume: 1,
pitch: randFloat(0.85, 1.15)
});
}
var entityItemData = {
type: 'Box',
name: 'CrappyBox',
angularVelocity: {
x: 3,
y: 3,
z: 3
},
color: {
red: 100,
green: 200,
blue: 10
},
dimensions: {
x: 0.8,
y: 0.8,
z: 0.8
},
position: LOCATION,
angularDamping:0,
clientOnly: false,
avatarEntity: true
}
var count = 300;
// this will update the size of the avatar entity every 100 updates-ish
var CHANCE_OF_AVATAR_ENTITY_UPDATE = 0.1;
var entityItem = false;
function update(event) {
if (count > 0) {
count -= 1;
return;
}
if (count == 0) {
Recording.setPlayFromCurrentLocation(true)
Recording.setPlayerLoop(true);
Recording.startPlaying();
console.log("started recording");
Avatar.displayName = "bot_RAND" + randFloat(LOCATION_PARAMS.min_x, LOCATION_PARAMS.max_x);
entityItem = Entities.addEntity(entityItemData, "avatar");
count -= 1;
}
if (Math.random() < CHANCE_OF_AVATAR_ENTITY_UPDATE) {
newSize = randFloat(0.5, 1.0);
newDimension = { x: newSize, y: newSize, z: newSize };
newColor = { red: Math.random() * 255, blue: Math.random() * 255, green: Math.random() * 255 }
console.log("updating avatar entity");
Entities.editEntity(entityItem, {dimensions: newDimension, color: newColor});
}
if (Math.random() < CHANCE_OF_SOUND) {
playRandomSound();
}
}