예제 #1
0
 public void AddPhysicalObject(PhysicalObject Object)
 {
     if (!PhysicalObjects.Contains(Object))
     {
         PhysicalObjects.Add(Object);
     }
 }
예제 #2
0
        public void Add(PhysicalObject po)
        {
            if (po.Position.X > _highX || po.Position.Z > _highZ ||
                po.Position.X < _lowX || po.Position.Z < _lowZ)
            {
                _log.Error("Tried to add physical object " + po.ObjectInstanceId + " outside the world.");
                return;
            }

            if (po is Terrain)
            {
                // keep terrain separate
                int terrainX = DivTruncate((int)(po.Position.X - _lowX), Constants.TerrainPieceSize);
                int terrainZ = DivTruncate((int)(po.Position.Z - _lowZ), Constants.TerrainPieceSize);
                _terrain[terrainX, terrainZ] = (Terrain)po;
            }
            else
            {
                // keep everything at ground level
                double?altitude = AltitudeAt(po.Position.X, po.Position.Z);
                if (altitude.HasValue)
                {
                    po.Position.Y = altitude.Value + po.Height / 2F;
                }
                else
                {
                    _log.Warn("Physical object " + po.ObjectInstanceId + " is not on terrain.");
                }

                // add the object to the world
                PhysicalObjects.Add(po.ObjectInstanceId, po);
                if (po is MobileAvatar)
                {
                    Mobiles.Add((MobileAvatar)po);
                }
                int squareX = (int)(po.Position.X - _lowX) / Square.SquareSize;
                int squareZ = (int)(po.Position.Z - _lowZ) / Square.SquareSize;
                if (_square[squareX, squareZ] == null)
                {
                    _square[squareX, squareZ] = new Square();
                }
                _square[squareX, squareZ].Add(po);
            }
            // notify all nearby clients that a new
            // physical object has entered the world
            InformNearby(po, ToClient.AddPhysicalObject.CreateMessage(po));
            //Log.Info( "Added new " + po.GetType() + " " + po.ObjectInstanceID + " at (" + po.Position.X + "," + po.Position.Y + "," +po.Position.Z + ") - ("+squareX+","+squareZ+")" );
        }