Ejemplo n.º 1
0
        /// <summary>
        /// Gets an indoor cell ID for a position within a dungeon
        /// </summary>
        private static uint GetIndoorCell(this Position p)
        {
            var adjustCell = AdjustCell.Get(p.Landblock);
            var envCell    = adjustCell.GetCell(p.Pos);

            if (envCell != null)
            {
                return(envCell.Value);
            }
            else
            {
                return(p.Cell);
            }
        }
Ejemplo n.º 2
0
        public void UpdateIndoorCells(Vector3 newPos)
        {
            var adjustCell = AdjustCell.Get(Location.LandblockId.Raw >> 16);

            if (adjustCell == null)
            {
                return;
            }
            var newCell = adjustCell.GetCell(newPos);

            if (newCell == null)
            {
                return;
            }
            if (newCell.Value == Location.LandblockId.Raw)
            {
                return;
            }
            Location.LandblockId = new LandblockId(newCell.Value);
            //Console.WriteLine("Moving " + Name + " to indoor cell " + newCell.Value.ToString("X8"));
        }
Ejemplo n.º 3
0
        public uint GetIndoorCell(uint blockCellID)
        {
            var dungeonID = blockCellID >> 16;

            var adjustCell = AdjustCell.Get(dungeonID);

            if (adjustCell == null)
            {
                //Console.WriteLine("Position: couldn't find ObjCellID for indoor cell " + blockCellID.ToString("X8"));
                //return LScape.get_landcell(ObjCellID);
                return(ObjCellID);
            }
            var newCell = adjustCell.GetCell(Frame.Origin);

            if (newCell == null)
            {
                //Console.WriteLine("Position: couldn't find new cell for indoor cell " + blockCellID.ToString("X8"));
                //return LScape.get_landcell(ObjCellID);
                return(ObjCellID);
            }
            //return LScape.get_landcell(newCell.Value);
            return(newCell.Value);
        }
Ejemplo n.º 4
0
        public static void TryFindObject(Vector3 dir)
        {
            Dir = dir;

            LastPickResult = PickResult;

            ClearSelection();

            PickResult = new PickResult();

            // first try using physics engine for this

            // try spawning a tiny 'projectile' object at the camera position

            // if successfully spawned, simulate proceeding in that direction until something is hit

            var startPos = Camera.GetPosition();

            if (startPos == null)
            {
                Console.WriteLine($"Couldn't find current camera position in world!");
                return;
            }

            var maxSteps = 500;
            var stepSize = 1.0f;
            var i        = 0;

            var stepDir = (dir * stepSize).ToNumerics();

            var singleBlock = WorldViewer.Instance.SingleBlock;

            if (singleBlock != uint.MaxValue)
            {
                var landblock = LScape.get_landblock(singleBlock);

                // custom for single landblock IsDungeon
                if (landblock.IsDungeon)
                {
                    if (startPos.Landblock != singleBlock >> 16)
                    {
                        startPos.Reframe(singleBlock);
                    }

                    var adjustCell = AdjustCell.Get(startPos.Landblock);

                    for ( ; i < maxSteps; i++)
                    {
                        var foundCell = adjustCell.GetCell(startPos.Frame.Origin);

                        if (foundCell != null)
                        {
                            startPos.ObjCellID = foundCell.Value;
                            break;
                        }
                        startPos.Frame.Origin += stepDir;
                    }
                }
            }

            // todo: make this static
            var pickerObj = PhysicsObj.makeObject(setupId, pickerGuid.Full, true);

            pickerObj.State |= PhysicsState.PathClipped;
            pickerObj.State &= ~PhysicsState.Gravity;

            pickerObj.set_object_guid(pickerGuid);

            var worldObj = new WorldObject();
            //worldObj.Name = "Picker";

            var weenie = new WeenieObject(worldObj);

            pickerObj.set_weenie_obj(weenie);

            // perform transition
            PhysicsObj.IsPicking = true;

            var showedMsg = false;

            var spawned = false;

            for ( ; i < maxSteps; i++)
            {
                if (!spawned)
                {
                    var success = pickerObj.enter_world(startPos);

                    if (!success)
                    {
                        startPos.Frame.Origin += stepDir;
                        continue;
                    }
                    else
                    {
                        //Console.WriteLine($"Successfully spawned picker @ {startPos}");
                        spawned = true;
                    }
                }

                var nextPos = new ACE.Server.Physics.Common.Position(pickerObj.Position);

                nextPos.Frame.Origin += stepDir;

                var transition = pickerObj.transition(pickerObj.Position, nextPos, false);

                // debug collision info
                if (transition == null)
                {
                    Console.WriteLine($"Null transition result!");
                    showedMsg = true;
                    break;
                }
                else if (transition.CollisionInfo.CollidedWithEnvironment || transition.CollisionInfo.CollideObject.Count > 0)
                {
                    /*if (transition.CollisionInfo.CollidedWithEnvironment)
                     *  Console.WriteLine($"CollidedWithEnvironment");
                     *
                     * if (transition.CollisionInfo.CollideObject.Count > 0)
                     * {
                     *  Console.WriteLine($"CollideObjs:");
                     *  foreach (var collideObj in transition.CollisionInfo.CollideObject)
                     *      Console.WriteLine($"{collideObj.PartArray.Setup._dat.Id:X8} @ {collideObj.Position.ShortLoc()}");
                     * }*/

                    BuildHitPolys();
                    showedMsg = true;
                    break;
                }
                else
                {
                    pickerObj.SetPositionInternal(transition);
                }
            }

            PhysicsObj.IsPicking = false;

            if (!spawned)
            {
                Console.WriteLine($"Failed to spawn picker @ {Camera.GetPosition()}");
            }
            else if (!showedMsg)
            {
                Console.WriteLine($"No collisions");
            }

            // cleanup
            pickerObj.DestroyObject();
        }