// moneyTreeRecevierClient.js // Created by Mark Brosche on 10-18-2018 // Copyright 2018 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 // /* global EventBridge Users AccountServices Agent Avatar */ (function (){ // get userData // spawn Overlays for clients with ID == giverID // delete after overlay after click event or after timer expires. // send data to google sheet var COIN_CLICKED = SoundCache.getSound(Script.resolvePath('assets/sounds/payout.wav')), AUDIO_VOLUME = 0.1, FIVE_SEC = 5000; var _this, injector, spawnerProperties, userData, receiverID, amount, messageOverlay, coinParticleEffects; var TreeGift = function(){ _this = this; }; TreeGift.prototype = { preload: function(entityID){ _this.entityID = entityID; _this.getEntityData(); _this.spawnMessageOverlay(); }, playSound: function(sound, position, localOnly) { if (sound.downloaded) { if (injector) { injector.stop(); } injector = Audio.playSound(sound, { position: position, volume: AUDIO_VOLUME, localOnly: localOnly }); } }, getEntityData: function() { spawnerProperties = Entities.getEntityProperties(_this.entityID, ["position", "rotation", "userData", "parentID"]); if (!spawnerProperties.userData || spawnerProperties.userData === "{}") { print("spawner ", _this.entityID, " is missing user data."); return; } try { userData = JSON.parse(spawnerProperties.userData); receiverID = userData.receiverID; amount = userData.amount; // verify that settings are legit } catch (e) { print("Error in retrieving entity Data"); return; } }, deleteOverlay: function() { if (coinParticleEffects){ Entities.editEntity(coinParticleEffects, { parentID: null }); Entities.deleteEntity(coinParticleEffects); coinParticleEffects = null; } if (messageOverlay) { Overlays.deleteOverlay(messageOverlay); messageOverlay = null; } if (injector) { injector.stop(); } }, spawnMessageOverlay: function() { var text = "You've been chosen to receive " + amount + " HFC!"; if (MyAvatar.sessionUUID === receiverID){ // _this.playSound(COIN_CLICKED, spawnerProperties.position); messageOverlay = Overlays.addOverlay("text3d", { name: "MESSAGE OVERLAY", text: text, color: {red: 255, green: 255, blue: 255}, backgroundAlpha: 0, dimensions: { x: 0.5, y: 0.05, z: 0.5 }, position: Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, { x: -2.5, y: 0, z: -5 })), rotation: MyAvatar.orientation, isSolid: true, drawInFront: true, parentID: MyAvatar.sessionUUID, lineHeight: 0.3 }); } Script.setTimeout(function(){ _this.deleteOverlay(); }, FIVE_SEC); }, unload: function(){ if (injector) { injector.stop(); } _this.deleteOverlay(); } }; return new TreeGift; });