/// <summary>
        /// Checks for position updates.
        /// </summary>
        /// <remarks>
        /// First we'll check to see if we could see, actor x from
        /// our old position. After that we'll check if can see actor x
        /// from our new position. If we can see him, we'll forward our movement
        /// packet. If we can't see him we'll sent a actor disappearance packet.
        ///
        /// Once that's done, we'll check if we can see a non-former visible actor
        /// is now visible in our new position. Which will cause us to invoke a appearance
        /// packet.
        /// </remarks>
        /// <param name="cpkt"></param>
        private void CM_CHARACTER_MOVEMENTSTOPPED(CMSG_MOVEMENTSTOPPED cpkt)
        {
            if (this.isloaded == false) return;
            //If character was previous walking/running
            if (!this.character.IsMoving)
            {
                this.character.LastPositionTick = Environment.TickCount;
                return;
            }
            else
            {
                //Sending packet to late
                int time = Environment.TickCount - this.character.LastPositionTick;
                if (time > 10000)
                {
                    CommonFunctions.Warp(this.character, this.character.Position, this.character.currentzone);
                    this.character.LastPositionTick = Environment.TickCount;
                    return;
                }
                else
                {
                    this.character.LastPositionTick = Environment.TickCount;
                }
            }

            // GENERATE NEW PACKETS, WE PREPROCESS
            SMSG_MOVEMENTSTOPPED spkt = new SMSG_MOVEMENTSTOPPED();
            spkt.ActorID = this.character.id;
            spkt.speed = cpkt.Speed;
            spkt.X = cpkt.X;
            spkt.Y = cpkt.Y;
            spkt.Z = cpkt.Z;
            spkt.yaw = cpkt.Yaw;
            spkt.TargetActor = this.character._targetid;
            spkt.DelayTime = cpkt.DelayTime;

            //Get new actors for next-tick
            Point oldP = this.character.Position;
            Point newP = new Point(cpkt.X, cpkt.Y, cpkt.Z);

            this.character.stance = (byte)StancePosition.Stand;
            this.character.Position = newP;
            Regiontree.UpdateRegion(this.character);
            Regiontree tree = this.character.currentzone.Regiontree;

            try
            {
                foreach (MapObject regionObject in tree.SearchActors(this.character, SearchFlags.Npcs | SearchFlags.Characters | SearchFlags.MapItems))
                {
                    bool CanSeePrev = Point.IsInSightRangeByRadius(regionObject.Position, oldP);
                    bool CanSeeNext = Point.IsInSightRangeByRadius(regionObject.Position, newP);
                    if (CanSeeNext && !CanSeePrev)
                    {
                        if (MapObject.IsPlayer(regionObject))
                        {
                            Character current = (Character)regionObject;
                            this.character.ShowObject(current);
                        }

                        regionObject.ShowObject(this.character);
                        regionObject.Appears(this.character);
                    }
                    else if (CanSeePrev && !CanSeeNext)
                    {
                        //Hide Object to other characters
                        if (MapObject.IsPlayer(regionObject))
                        {
                            Character current = (Character)regionObject;
                            this.character.HideObject(current);
                        }

                        //Hide Object to myself
                        regionObject.HideObject(this.character);
                        regionObject.Disappear(this.character);
                    }
                    else if (CanSeeNext && CanSeePrev)
                    {
                        if (MapObject.IsPlayer(regionObject))
                        {
                            Character current = (Character)regionObject;
                            if (current.client.isloaded == false) continue;
                            spkt.SessionId = current.id;
                            current.client.Send((byte[])spkt);
                        }
                    }
                }
            }
            catch (Exception)
            {
                Trace.WriteLine("Error network code");
            }
            finally
            {
                if (this.character.sessionParty != null)
                {
                    foreach (Character target in this.character.sessionParty._Characters)
                    {
                        try
                        {
                            if (target.id == this.character.id) continue;
                            SMSG_PARTYMEMBERLOCATION spkt3 = new SMSG_PARTYMEMBERLOCATION();
                            spkt3.Index = 1;
                            spkt3.ActorId = this.character.id;
                            spkt3.SessionId = target.id;
                            spkt3.X = (this.character.Position.x / 1000);
                            spkt3.Y = (this.character.Position.y / 1000);
                            target.client.Send((byte[])spkt3);
                        }
                        catch (SocketException)
                        {
                            Trace.WriteLine("Network error");
                        }
                        catch (Exception)
                        {
                            Trace.WriteLine("Unknown error");
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public void StopMovement()
        {
            //Set my destination position
            this.DestPosition = this.Position;

            //Generate packet
            SMSG_MOVEMENTSTOPPED spkt = new SMSG_MOVEMENTSTOPPED();
            spkt.ActorID = this.id;
            spkt.speed = (ushort)this.Status.WalkingSpeed;
            spkt.DelayTime = 0;
            spkt.X = this.Position.x;
            spkt.Y = this.Position.y;
            spkt.Z = this.Position.z;
            spkt.yaw = this.Yaw;

            //Send over movement start to all characters in neighbourhood
            Regiontree tree = this.currentzone.Regiontree;
            foreach (Character character in tree.SearchActors(this, SearchFlags.Characters))
                if (Point.IsInSightRangeByRadius(this.Position, character.Position))
                {
                    spkt.SessionId = character.id;
                    character.client.Send((byte[])spkt);
                }

            //Set is moving to false
            this.stance = 3;
        }