content/hifi-public/sam/2018-oct/CarrotHunt-11-5/asset/carrot-server.js
Dale Glass 0d14e5a379 Initial data.
Needs a lot of cleanup. Data has been de-duplicated, and where identical copies existed, one of them
has been replaced with a symlink.

Some files have been excluded, such as binaries, installers and debug dumps. Some of that may still
be present.
2022-02-13 18:59:11 +01:00

211 lines
No EOL
7.4 KiB
JavaScript

//
// Carrot Server.js
//
// Team 8 Hifi Hackathon 2018
// Chang Kayla Sam Lab
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
/* globals Entities */
(function() {
var _this;
var _entityID;
var triggered = false;
var AUDIO_VOLUME_LEVEL = 0.25;
var TRIGGER_SOUND = SoundCache.getSound(Script.resolvePath("./audio/cartoon-squeak_fklEvdNd.mp3"));
var TOOFAR_TRIGGER_SOUND = SoundCache.getSound(Script.resolvePath("./audio/click-blip_fyNxFdNd.mp3"));
var WIN_TRIGGER_SOUND = SoundCache.getSound(Script.resolvePath("./audio/jg-032316-sfx-video-game-beeps-4.mp3"));
var NOOP_TRIGGER_SOUND = SoundCache.getSound(Script.resolvePath("./audio/laser-charge-quick_My3a2IVd.mp3"));
var LOST_TRIGGER_SOUND = SoundCache.getSound(Script.resolvePath("./audio/boing_f1YRp34O.mp3"));
var MISS_TRIGGER_SOUND = SoundCache.getSound(Script.resolvePath("./audio/boing-spring-3_fyW6R2EO.mp3"));
var GONG_TIMER_SOUND = SoundCache.getSound(Script.resolvePath("./audio/chinese-gong-crash_z1sgFyHO.mp3"));
var WIN_CARROT_MODEL_URL = Script.resolvePath("./model/carrot%20gold%20winner.fbx");
var LOOSE_CARROT_MODEL_URL = Script.resolvePath("./model/beet-fbx.fbx");
var CARROT_ICON_URL = Script.resolvePath("./model/whitecarrot2.png");
var WIN_PARTICLEFX = {
"lifetime": 15,
"alpha": 0.44999998807907104,
"alphaFinish": 0,
"alphaStart": 1,
"clientOnly": false,
"color": {
"blue": 27,
"green": 223,
"red": 245
},
"colorFinish": {
"blue": 0,
"green": 0,
"red": 0,
"x": 0,
"y": 0,
"z": 0
},
"colorStart": {
"blue": 0,
"green": 213,
"red": 255,
"x": 255,
"y": 213,
"z": 0
},
"created": "2018-10-26T20:08:25Z",
"dimensions": {
"blue": 26.269893646240234,
"green": 26.269893646240234,
"red": 26.269893646240234,
"x": 26.269893646240234,
"y": 26.269893646240234,
"z": 26.269893646240234
},
"editionNumber": 35,
"emitAcceleration": {
"blue": 0,
"green": 0.10000000149011612,
"red": 0,
"x": 0,
"y": 0.10000000149011612,
"z": 0
},
"emitDimensions": {
"blue": 1.5,
"green": 1.5,
"red": 1.5,
"x": 1.5,
"y": 1.5,
"z": 1.5
},
"emitOrientation": {
"w": 1,
"x": -1.52587890625e-05,
"y": -1.52587890625e-05,
"z": -1.52587890625e-05
},
"emitRate": 20,
"emitSpeed": 0,
"itemArtist": "alexia",
"lifespan": 14.010000228881836,
"maxParticles": 3619,
"name": "Stars",
"owningAvatarID": "{00000000-0000-0000-0000-000000000000}",
"particleRadius": 0.5099999904632568,
"polarFinish": 3.1415927410125732,
"radiusFinish": 0,
"radiusStart": 0,
"rotation": {
"w": 0.8073700666427612,
"x": -7.62939453125e-05,
"y": -0.5900511145591736,
"z": -7.62939453125e-05
},
"speedSpread": 0,
"spinFinish": null,
"spinStart": null,
"textures": CARROT_ICON_URL,
"type": "ParticleEffect",
"userData": "{\"grabbableKey\":{\"grabbable\":false}}"
};
function Print(m) {
if (true) {
print(m)
}
};
var Carrot = function() {
_this = this;
};
Carrot.prototype = {
remotelyCallable: ['triggerCarrot'],
preload: function(entityID) {
_entityID = entityID;
_this.entityID = entityID;
_this.position = Entities.getEntityProperties(_this.entityID, 'position').position;
_this.winner = JSON.parse(Entities.getEntityProperties(_this.entityID, 'userData').userData).winner;
if (_this.winner == -1) {
_this.resetPos = JSON.parse(Entities.getEntityProperties(_this.entityID, 'userData').userData).resetPos;
}
},
triggerCarrot: function(senderID, params) {
var playerUUID = params[0];
print("received a triggerCarrot!!! from " + playerUUID)
/*
Can t guarantee that we don;t have a cheater ....
var position = Entities.getEntityProperties(_entityID, 'position').position;
var avatarsInRange = AvatarList.getAvatarsInRange(position, 1.0);
print("Avatars in range are: " + JSON.stringify(avatarsInRange))
*/
if (triggered === false) {
triggered = true;
_this.triggerWin(playerUUID);
} else {
_this.triggerMiss();
}
},
triggerWin: function(playerUUID) {
Print("I triggered that carrot!!!");
if (_this.winner == 1) {
var props = WIN_PARTICLEFX
props.position = _this.position
Entities.addEntity(WIN_PARTICLEFX)
Print("THis is the THe Golden Carrot!!!!!!!!!!!!!!!!!!!!!!!!");
_this.position = Vec3.sum(_this.position, {x: 0, y: 1.0, z: 0})
Entities.editEntity(_this.entityID, { position: _this.position, angularVelocity: {x: 1.3, y: 2, z: 1},
dimensions: {x: 1, y: 2, z: 1},
modelURL: WIN_CARROT_MODEL_URL } )
_this.playSound(WIN_TRIGGER_SOUND, _this.position)
} else if (_this.winner == -1) {
Print("THis a Losing Carrot ....... ");
_this.position = Vec3.sum(_this.position, {x: 0, y: 0.7, z: 0})
Entities.editEntity(_this.entityID, { position: _this.position,
dynamic:true, velocity:{"x":0,"y":1,"z":0}, gravity:{"x":0,"y":-9,"z":0},
angularVelocity: {x: 0.3, y: 0.8, z: 1}, modelURL: LOOSE_CARROT_MODEL_URL } )
_this.playSound(LOST_TRIGGER_SOUND, _this.position);
Entities.callEntityClientMethod(playerUUID, _entityID, 'triggerBad');
} else {
_this.position = Vec3.sum(_this.position, {x: 0, y: 0.5, z: 0})
Entities.editEntity(_this.entityID, { position: _this.position,
dynamic:true, velocity:{"x":0,"y":0.8,"z":0}, gravity:{"x":0,"y":-9,"z":0},
} )
_this.playSound(NOOP_TRIGGER_SOUND, _this.position)
}
},
triggerMiss: function() {
Print("You MISSED that carrot :(");
_this.playSound(MISS_TRIGGER_SOUND, _this.position);
},
playSound: function(sound, position, local) {
if (sound.downloaded) {
Audio.playSound(sound, {
position: position,
localOnly: (local === undefined) ? false : local,
volume: AUDIO_VOLUME_LEVEL
});
}
},
};
return new Carrot();
});