Exemplo n.º 1
0
        protected override void ClientInitialize(ClientInitializeData data)
        {
            base.ClientInitialize(data);
            var worldObject = data.GameObject;

            // create sound emitter
            data.ClientState.SoundEmitter = Client.Audio.CreateSoundEmitter(
                data.GameObject,
                SoundResourceActive,
                isLooped: true,
                volume: 0.5f,
                radius: 1.5f);
            data.ClientState.SoundEmitter.CustomMaxDistance = 4f;

            // add fan sprite renderers
            var randomizer = (int)(PositionHashHelper.GetHashUInt32(worldObject.TilePosition.X,
                                                                    worldObject.TilePosition.Y)
                                   % 128);

            AddFanRenderer((41 / 256.0, 253 / 256.0), frameOffset: randomizer, out var componentAnimator1);
            AddFanRenderer((137 / 256.0, 253 / 256.0), frameOffset: randomizer + 2, out var componentAnimator2);

            // sound and animation are played only if there is a power grid (a land claim area)
            var isActive = LandClaimSystem.SharedIsObjectInsideAnyArea(worldObject);

            componentAnimator1.IsEnabled
                    = componentAnimator2.IsEnabled
                    = data.ClientState.SoundEmitter.IsEnabled
                    = isActive;

            void AddFanRenderer(
                Vector2D vector2D,
                int frameOffset,
                out ClientComponentSpriteSheetAnimator componentAnimator)
            {
                var overlaySpriteRenderer = Client.Rendering.CreateSpriteRenderer(
                    worldObject,
                    positionOffset: vector2D,
                    spritePivotPoint: (0, 0),
                    drawOrder: data.ClientState.Renderer.DrawOrder);

                overlaySpriteRenderer.DrawOrderOffsetY = -vector2D.Y
                                                         - 0.01
                                                         + data.ClientState.Renderer.DrawOrderOffsetY;

                // add sprite sheet animation for fan sprite
                var sceneObject = worldObject.ClientSceneObject;

                componentAnimator = sceneObject.AddComponent <ClientComponentSpriteSheetAnimator>();
                componentAnimator.Setup(overlaySpriteRenderer,
                                        ClientComponentSpriteSheetAnimator.CreateAnimationFrames(
                                            this.textureAtlasActive),
                                        isLooped: true,
                                        frameDurationSeconds: 5 / 60.0,
                                        initialFrameOffset: frameOffset);
            }
        }
Exemplo n.º 2
0
        public static int Get(Vector2Ushort position, int minInclusive, int maxExclusive, uint seed = 0)
        {
            maxExclusive--;
            if (minInclusive == maxExclusive)
            {
                return(minInclusive);
            }

            Api.Assert(minInclusive < maxExclusive, "Min should be < max");

            var value = PositionHashHelper.GetHashDouble(position.X, position.Y, seed);
            var range = maxExclusive - minInclusive;

            value = minInclusive + value * range;
            return((int)Math.Round(value, MidpointRounding.AwayFromZero));
        }
Exemplo n.º 3
0
 public double Get(double x, double y)
 {
     return(PositionHashHelper.GetHashDouble((uint)x, (uint)y, this.seed));
 }