Example #1
0
        public bool AddObject(Object Obj, UInt16 ZoneId, bool MustUpdateRange = false)
        {
            Zone_Info Info = GetZone_Info(ZoneId);

            if (Info == null)
            {
                Log.Error("RegionMgr", "Invalid Zone Id : " + ZoneId);
                return(false);
            }

            if (Obj.Region == null || (Obj.Region != null && Obj.Region != this))
            {
                if (Obj.Region != null)
                {
                    Obj.Region.RemoveObject(Obj);
                }

                GenerateOid(Obj);
            }

            ZoneMgr Mgr = GetZoneMgr(ZoneId, true);

            Mgr.AddObject(Obj);

            if (MustUpdateRange)
            {
                UpdateRange(Obj);
            }

            return(true);
        }
Example #2
0
        private void AddNewObjects()
        {
            try
            {
                lock (_objectsToAdd)
                {
                    foreach (ObjectAdd obj in _objectsToAdd)
                    {
                        var plr = obj.Obj as Player;

                        if (obj.Obj.Region != this)
                        {
                            if (obj.Obj.Region != null)
                            {
                                obj.Obj.Region.RemoveObject(obj.Obj);
                            }

                            GenerateOid(obj.Obj);

                            if (plr != null)
                            {
                                plr.InRegionChange = true;
                                if (!Players.Contains(plr))
                                {
                                    Players.Add(plr);
                                }
                            }
                        }

                        else
                        {
                            obj.Obj.Zone.RemoveObject(obj.Obj);
                        }

                        ZoneMgr mgr = GetZoneMgr(obj.ZoneId);
                        mgr.AddObject(obj.Obj);

                        if (obj.MustUpdateRange)
                        {
                            UpdateRange(obj.Obj);
                        }

                        if (plr != null)
                        {
                            //Bttlfront?.SendObjectives(plr);

                            ndbf?.SendObjectives(plr);
                            WorldMgr.SendCampaignStatus(plr);
                        }
                    }
                    _objectsToAdd.Clear();
                }
            }
            catch (Exception e)
            {
                Log.Error("AddNewObjects", e.ToString());
            }
        }
Example #3
0
        public virtual bool SetPosition(ushort pinX, ushort pinY, ushort pinZ, ushort heading, ushort zoneId, bool sendState = false)
        {
            //Player plr = this as Player;

            bool updated  = false;
            bool doUpdate = false;

            if (zoneId != Zone.ZoneId)
            {
                ZoneMgr newZone = Region.GetZoneMgr(zoneId);

                if (newZone == null)
                {
                    return(false);
                }

                //plr?.DebugMessage("Moving from "+Zone.Info.Name+" to "+newZone.Info.Name, ChatLogFilters.CHATLOGFILTERS_ZONE_AREA, true);

                Zone.RemoveObject(this);
                newZone.AddObject(this);

                doUpdate = true;
            }

            if (doUpdate || pinX != X || pinY != Y || pinZ != Z || heading != Heading)
            {
                X       = pinX;
                Y       = pinY;
                Z       = pinZ;
                Heading = heading;

                //plr?.DebugMessage($"Moving to {X}, {Y}, {Z} in {Zone.Info.Name}", ChatLogFilters.CHATLOGFILTERS_ZONE_AREA, true);

                UpdateWorldPosition();
                UpdateOffset();

                if (!IsPlayer())
                {
                    IsMoving = true;
                    if (sendState)
                    {
                        GetUnit().StateDirty = true;
                    }
                }
                else
                {
                    ushort newOffsetX = (ushort)Math.Truncate((decimal)(X / 4096 + Zone.Info.OffX));
                    ushort newOffsetY = (ushort)Math.Truncate((decimal)(Y / 4096 + Zone.Info.OffY));

                    if (newOffsetX != XOffset || newOffsetY != YOffset)
                    {
                        return(false);
                    }
                }

                updated = Region.UpdateRange(this);
            }
            else if (!IsPlayer())
            {
                IsMoving = false;
            }

            return(updated);
        }