content/hifi-content/elisalj/hub/happy420-server.js
2022-02-13 23:16:46 +01:00

71 lines
2.2 KiB
JavaScript

//
// happy420-server.js
//
// Author: Liv Erickson
// Edited for pills by: Elisa Lupin-Jimenez
// Copyright High Fidelity 2018
//
// Licensed under the Apache 2.0 License
// See accompanying license file or http://apache.org/
//
(function(){
var LIFETIME = 30; // seconds
var SPAWN_POSITION;
var CHECK_INTERVAL = LIFETIME * 100; // milliseconds
var MAX_PILLS = 10;
var PILL_URL = Script.resolvePath("models/pill.fbx");
var SWALLOW_PILL_SCRIPT = Script.resolvePath('./swallow420Pill.js?01');
var PILL_SIZE = {x: 0.1259, y: 0.1259, z: 0.3227};
var DEBUG = false;
var pillProperties;
var spawnPillInterval;
var pillBox = [];
var PillSpawner = function(){
// nothing here
};
PillSpawner.prototype = {
preload: function(entityID) {
if (DEBUG) {
print("preload for 420 Pills");
}
SPAWN_POSITION = Entities.getEntityProperties(entityID, "position").position;
pillProperties = {
type: "Model",
shapeType: "capsule-z",
modelURL: PILL_URL,
script: SWALLOW_PILL_SCRIPT,
lifetime: LIFETIME,
position: SPAWN_POSITION,
dimensions: PILL_SIZE,
dynamic: true,
velocity: {x:0, y: -0.1, z: 0},
gravity: {x:0, y: -9.8, z: 0},
visible: true,
collisionless: false,
userData : "{\"grabbableKey\":{\"grabbable\":true}}"
};
spawnPillInterval = Script.setInterval(function() {
if (pillBox.length < MAX_PILLS) {
var pillID = Entities.addEntity(pillProperties);
pillBox.push(pillID);
} else {
pillBox.pop();
}
}, CHECK_INTERVAL);
},
unload: function() {
if (DEBUG) {
print("unload 420 Pills");
}
Script.clearInterval(spawnPillInterval);
}
};
return new PillSpawner();
});