Example #1
0
        public npc_eye_of_acherus(Creature creature) : base(creature)
        {
            me.SetDisplayFromModel(0);

            Player owner = me.GetCharmerOrOwner().ToPlayer();

            if (owner)
            {
                me.GetCharmInfo().InitPossessCreateSpells();
                owner.SendAutoRepeatCancel(me);
            }

            me.SetReactState(ReactStates.Passive);

            me.GetMotionMaster().MovePoint(1, MiscConst.EyeOFAcherusFallPoint, false);

            MoveSplineInit init = new MoveSplineInit(me);

            init.MoveTo(MiscConst.EyeOFAcherusFallPoint.GetPositionX(), MiscConst.EyeOFAcherusFallPoint.GetPositionY(), MiscConst.EyeOFAcherusFallPoint.GetPositionZ(), false);
            init.SetFall();
            init.Launch();
        }
Example #2
0
        public override bool Execute(ulong e_time, uint p_time)
        {
            Contract.Assert(Passenger.IsInWorld);
            Contract.Assert(Target != null && Target.GetBase().IsInWorld);
            Contract.Assert(Target.GetBase().HasAuraTypeWithCaster(AuraType.ControlVehicle, Passenger.GetGUID()));

            Target.RemovePendingEventsForSeat(Seat.Key);
            Target.RemovePendingEventsForPassenger(Passenger);

            Passenger.SetVehicle(Target);
            Seat.Value.Passenger.Guid           = Passenger.GetGUID();
            Seat.Value.Passenger.IsUnselectable = Passenger.HasFlag(UnitFields.Flags, UnitFlags.NotSelectable);
            if (Seat.Value.SeatInfo.CanEnterOrExit())
            {
                Contract.Assert(Target.UsableSeatNum != 0);
                --Target.UsableSeatNum;
                if (Target.UsableSeatNum == 0)
                {
                    if (Target.GetBase().IsTypeId(TypeId.Player))
                    {
                        Target.GetBase().RemoveFlag64(UnitFields.NpcFlags, NPCFlags.PlayerVehicle);
                    }
                    else
                    {
                        Target.GetBase().RemoveFlag64(UnitFields.NpcFlags, NPCFlags.SpellClick);
                    }
                }
            }

            Passenger.InterruptNonMeleeSpells(false);
            Passenger.RemoveAurasByType(AuraType.Mounted);

            VehicleSeatRecord veSeat = Seat.Value.SeatInfo;

            Player player = Passenger.ToPlayer();

            if (player != null)
            {
                // drop flag
                Battleground bg = player.GetBattleground();
                if (bg)
                {
                    bg.EventPlayerDroppedFlag(player);
                }

                player.StopCastingCharm();
                player.StopCastingBindSight();
                player.SendOnCancelExpectedVehicleRideAura();
                if (!veSeat.Flags[1].HasAnyFlag((uint)VehicleSeatFlagsB.KeepPet))
                {
                    player.UnsummonPetTemporaryIfAny();
                }
            }

            if (Seat.Value.SeatInfo.Flags[0].HasAnyFlag((uint)VehicleSeatFlags.PassengerNotSelectable))
            {
                Passenger.SetFlag(UnitFields.Flags, UnitFlags.NotSelectable);
            }

            Passenger.m_movementInfo.transport.pos.Relocate(veSeat.AttachmentOffset.X, veSeat.AttachmentOffset.Y, veSeat.AttachmentOffset.Z);
            Passenger.m_movementInfo.transport.time = 0;
            Passenger.m_movementInfo.transport.seat = Seat.Key;
            Passenger.m_movementInfo.transport.guid = Target.GetBase().GetGUID();

            if (Target.GetBase().IsTypeId(TypeId.Unit) && Passenger.IsTypeId(TypeId.Player) &&
                Seat.Value.SeatInfo.Flags[0].HasAnyFlag((uint)VehicleSeatFlags.CanControl))
            {
                Contract.Assert(Target.GetBase().SetCharmedBy(Passenger, CharmType.Vehicle)); // SMSG_CLIENT_CONTROL
            }
            Passenger.SendClearTarget();                                                      // SMSG_BREAK_TARGET
            Passenger.SetControlled(true, UnitState.Root);                                    // SMSG_FORCE_ROOT - In some cases we send SMSG_SPLINE_MOVE_ROOT here (for creatures)
            // also adds MOVEMENTFLAG_ROOT

            MoveSplineInit init = new MoveSplineInit(Passenger);

            init.DisableTransportPathTransformations();
            init.MoveTo(veSeat.AttachmentOffset.X, veSeat.AttachmentOffset.Y, veSeat.AttachmentOffset.Z, false, true);
            init.SetFacing(0.0f);
            init.SetTransportEnter();
            init.Launch();

            Creature creature = Target.GetBase().ToCreature();

            if (creature != null)
            {
                if (creature.IsAIEnabled)
                {
                    creature.GetAI().PassengerBoarded(Passenger, Seat.Key, true);
                }

                Global.ScriptMgr.OnAddPassenger(Target, Passenger, Seat.Key);

                // Actually quite a redundant hook. Could just use OnAddPassenger and check for unit typemask inside script.
                if (Passenger.HasUnitTypeMask(UnitTypeMask.Accessory))
                {
                    Global.ScriptMgr.OnInstallAccessory(Target, Passenger.ToCreature());
                }
            }

            return(true);
        }
Example #3
0
        public void _setRandomLocation(T creature)
        {
            float respX, respY, respZ, respO, destX, destY, destZ, travelDistZ;

            creature.GetHomePosition(out respX, out respY, out respZ, out respO);
            Map map = creature.GetMap();//GetBaseMap();

            // For 2D/3D system selection
            //bool is_land_ok  = creature.CanWalk();                // not used?
            //bool is_water_ok = creature.CanSwim();                // not used?
            bool is_air_ok = creature.CanFly();

            float angle     = (float)(RandomHelper.rand_norm() * (Math.PI * 2.0f));
            float range     = (float)(RandomHelper.rand_norm() * wander_distance);
            float distanceX = (float)(range * Math.Cos(angle));
            float distanceY = (float)(range * Math.Sin(angle));

            destX = respX + distanceX;
            destY = respY + distanceY;

            // prevent invalid coordinates generation
            //NormalizeMapCoord(destX);
            //NormalizeMapCoord(destY);

            travelDistZ = distanceX * distanceX + distanceY * distanceY;

            if (is_air_ok)                                          // 3D system above ground and above water (flying mode)
            {
                // Limit height change
                float distanceZ = (float)(RandomHelper.rand_norm() * Math.Sqrt(travelDistZ) / 2.0f);
                destZ = respZ + distanceZ;
                float Null;
                float levelZ = map.GetWaterOrGroundLevel(destX, destY, destZ - 2.0f, out Null);

                // Problem here, we must fly above the ground and water, not under. Let's try on next tick
                if (levelZ >= destZ)
                {
                    return;
                }
            }
            //else if (is_water_ok)                                 // 3D system under water and above ground (swimming mode)
            else                                                    // 2D only
            {
                // 10.0 is the max that vmap high can check (MAX_CAN_FALL_DISTANCE)
                travelDistZ = (float)(travelDistZ >= 100.0f ? 10.0f : Math.Sqrt(travelDistZ));

                // The fastest way to get an accurate result 90% of the time.
                // Better result can be obtained like 99% accuracy with a ray light, but the cost is too high and the code is too long.
                destZ = map.GetHeight(creature.GetPhaseMask(), destX, destY, respZ + travelDistZ - 2.0f, false);

                if (Math.Abs(destZ - respZ) > travelDistZ)              // Map check
                {
                    // Vmap Horizontal or above
                    destZ = map.GetHeight(creature.GetPhaseMask(), destX, destY, respZ - 2.0f, true);

                    if (Math.Abs(destZ - respZ) > travelDistZ)
                    {
                        // Vmap Higher
                        destZ = map.GetHeight(creature.GetPhaseMask(), destX, destY, respZ + travelDistZ - 2.0f, true);

                        // let's forget this bad coords where a z cannot be find and retry at next tick
                        if (Math.Abs(destZ - respZ) > travelDistZ)
                        {
                            return;
                        }
                    }
                }
            }

            if (is_air_ok)
            {
                i_nextMoveTime.Reset(0);
            }
            else
            {
                i_nextMoveTime.Reset(RandomHelper.irand(500, 10000));
            }

            creature.AddUnitState(UnitState.Roaming_Move);

            MoveSplineInit init = new MoveSplineInit(creature);

            init.MoveTo(destX, destY, destZ);
            init.SetWalk(true);
            init.Launch();

            //Call for creature group update
            //if (creature.GetFormation() && creature.GetFormation().getLeader() == creature)
            //creature.GetFormation().LeaderMoveTo(destX, destY, destZ);
        }