Beispiel #1
0
        internal void SetPosition(Vec3f pos, bool sendToClient)
        {
            this.specPos = pos.ClampToWorldLimits();
            this.specWorld.UpdateSpectatorCell(this, this.specPos);

            if (specPos.GetDistancePlanar(lastPos) > UpdateDistance)
            {
                lastPos = specPos;
                UpdateVobList(this.specWorld, specPos);
            }
        }
Beispiel #2
0
        /// <summary> Updates the position & angles property. (Is called once every frame by default) </summary>
        public virtual void UpdateOrientation()
        {
            if (this.gvob != null)
            {
                var trafo = this.gVob.TrafoObjToWorld;
                this.pos.X = Vec3f.ClampToWorldLimits(trafo[3]);
                this.pos.Y = Vec3f.ClampToWorldLimits(trafo[7]);
                this.pos.Z = Vec3f.ClampToWorldLimits(trafo[11]);

                this.ang = new Angles(trafo);
            }
        }
Beispiel #3
0
        /// <summary>
        /// The client will lose control of its current NPC and move into spectator mode (free view).
        /// </summary>
        public void SetToSpectate(World world, Vec3f position, Angles angles)
        {
            if (world == null)
            {
                throw new Exception("World is null!");
            }
            if (!world.IsCreated)
            {
                throw new Exception("World is not created!");
            }

            if (this.isSpectating && specWorld == world)
            {
                SpecSetPosAng(position, angles);
                return;
            }

            this.specPos = position.ClampToWorldLimits();
            this.specAng = angles.Clamp();

            pSetToSpectate(world, specPos, specAng);
        }
Beispiel #4
0
        /// <summary> Spawns the Vob in the given world at the given position & direction. </summary>
        public virtual void Spawn(World world, Vec3f position, Angles angles)
        {
            if (world == null)
            {
                throw new ArgumentNullException("World is null!");
            }

            if (this.instance == null)
            {
                throw new Exception("Vob has no Instance!");
            }

            if (this.ScriptObject == null)
            {
                throw new Exception("Vob has no ScriptObject!");
            }

            if (this.isCreated)
            {
                throw new Exception("Vob is already spawned!");
            }

            Vec3f  spawnPos = position.ClampToWorldLimits();
            Angles spawnAng = angles.Clamp();

            this.pBeforeSpawn(world, spawnPos, spawnAng);

            this.pos = spawnPos;
            this.ang = spawnAng;

            world.AddVob(this);
            this.world     = world;
            this.isCreated = true;

            this.pAfterSpawn(world, spawnPos, spawnAng);

            this.OnSpawn?.Invoke(this, world, position, angles);
            sOnSpawn?.Invoke(this, world, position, angles);
        }
Beispiel #5
0
        /// <summary>
        /// Spawns the NPC in the given world at the given position & direction.
        /// If the NPC is a player, the spawn will be postponed until the client has loaded the map.
        /// </summary>
        public override void Spawn(World world, Vec3f position, Angles angles)
        {
            if (this.IsPlayer)
            {
                if (world == null)
                {
                    throw new ArgumentNullException("World is null!");
                }

                if (this.Instance == null)
                {
                    throw new Exception("Vob has no Instance!");
                }

                if (this.ScriptObject == null)
                {
                    throw new Exception("Vob has no ScriptObject!");
                }

                if (this.isCreated)
                {
                    throw new Exception("Vob is already spawned!");
                }

                this.pos   = position.ClampToWorldLimits();
                this.ang   = angles.Clamp();
                this.world = world;

                // wait until the client has loaded the map
                World.Messages.WriteLoadWorld(this.client, world); // tell the client to change worlds first
            }
            else
            {
                base.Spawn(world, position, angles);
                world.AddToNPCCells(this);
            }
        }
Beispiel #6
0
        internal void SetPosAng(Vec3f position, Angles angles, GameClient exclude)
        {
            this.pos = position.ClampToWorldLimits();
            this.ang = angles.Clamp();

            if (this.isCreated && !this.IsStatic)
            {
                this.world.UpdateVobCell(this, pos);
                if (this is NPC)
                {
                    this.world.UpdateNPCCell((NPC)this, pos);
                }

                bool updateVis;
                if (lastUpdatePos.GetDistancePlanar(this.pos) > 100)
                {
                    updateVis     = true;
                    lastUpdatePos = this.pos;
                    CleanClientList();
                }
                else
                {
                    updateVis = false;
                }

                if (visibleClients.Count > 0 || targetOf.Count > 0)
                {
                    this.WritePosAngMessage(exclude);
                }

                if (updateVis)
                {
                    UpdateClientList();
                }
            }
        }
Beispiel #7
0
 public void SpecSetPosAng(Vec3f position, Angles angles)
 {
     this.specPos = position.ClampToWorldLimits();
     this.specAng = angles.Clamp();
     pSpecSetPosAng();
 }
Beispiel #8
0
 public void SpecSetPos(Vec3f position)
 {
     this.specPos = position.ClampToWorldLimits();
     pSpecSetPos();
 }
Beispiel #9
0
 /// <summary> Sets the position of this Vob </summary>
 public void SetPosition(Vec3f position)
 {
     this.pos = position.ClampToWorldLimits();
     pSetPosition();
 }