Exemplo n.º 1
0
        public override bool OnUse(Player player, Item item, SpellCastTargets targets, ObjectGuid castId)
        {
            GameObject go = null;

            for (byte i = 0; i < ItemScriptConst.CaribouTraps.Length; ++i)
            {
                go = player.FindNearestGameObject(ItemScriptConst.CaribouTraps[i], 5.0f);
                if (go)
                {
                    break;
                }
            }

            if (!go)
            {
                return(false);
            }

            if (go.FindNearestCreature(ItemScriptConst.NpcNesingwaryTrapper, 10.0f, true) || go.FindNearestCreature(ItemScriptConst.NpcNesingwaryTrapper, 10.0f, false) || go.FindNearestGameObject(ItemScriptConst.GoHighQualityFur, 2.0f))
            {
                return(true);
            }

            float x, y, z;

            go.GetClosePoint(out x, out y, out z, go.GetObjectSize() / 3, 7.0f);
            go.SummonGameObject(ItemScriptConst.GoHighQualityFur, go, Quaternion.fromEulerAnglesZYX(go.GetOrientation(), 0.0f, 0.0f), 1);
            TempSummon summon = player.SummonCreature(ItemScriptConst.NpcNesingwaryTrapper, x, y, z, go.GetOrientation(), TempSummonType.DeadDespawn, 1000);

            if (summon)
            {
                summon.SetVisible(false);
                summon.SetReactState(ReactStates.Passive);
                summon.AddUnitFlag(UnitFlags.ImmuneToPc);
            }
            return(false);
        }
Exemplo n.º 2
0
        public CypherStrings VisualizeBoundary(int duration, Unit owner = null, bool fill = false)
        {
            if (!owner)
            {
                return(0);
            }

            if (_boundary.Empty())
            {
                return(CypherStrings.CreatureMovementNotBounded);
            }

            List <KeyValuePair <int, int> > Q = new List <KeyValuePair <int, int> >();
            List <KeyValuePair <int, int> > alreadyChecked = new List <KeyValuePair <int, int> >();
            List <KeyValuePair <int, int> > outOfBounds    = new List <KeyValuePair <int, int> >();

            Position startPosition = owner.GetPosition();

            if (!CheckBoundary(startPosition)) // fall back to creature position
            {
                startPosition = me.GetPosition();
                if (!CheckBoundary(startPosition))
                {
                    startPosition = me.GetHomePosition();
                    if (!CheckBoundary(startPosition)) // fall back to creature home position
                    {
                        return(CypherStrings.CreatureNoInteriorPointFound);
                    }
                }
            }
            float spawnZ = startPosition.GetPositionZ() + SharedConst.BoundaryVisualizeSpawnHeight;

            bool boundsWarning = false;

            Q.Add(new KeyValuePair <int, int>(0, 0));
            while (!Q.Empty())
            {
                var  front = Q.First();
                bool hasOutOfBoundsNeighbor = false;
                foreach (var off in new List <KeyValuePair <int, int> >()
                {
                    new KeyValuePair <int, int>(1, 0), new KeyValuePair <int, int>(0, 1), new KeyValuePair <int, int>(-1, 0), new KeyValuePair <int, int>(0, -1)
                })
                {
                    var next = new KeyValuePair <int, int>(front.Key + off.Key, front.Value + off.Value);
                    if (next.Key > SharedConst.BoundaryVisualizeFailsafeLimit || next.Key < -SharedConst.BoundaryVisualizeFailsafeLimit || next.Value > SharedConst.BoundaryVisualizeFailsafeLimit || next.Value < -SharedConst.BoundaryVisualizeFailsafeLimit)
                    {
                        boundsWarning = true;
                        continue;
                    }
                    if (!alreadyChecked.Contains(next)) // never check a coordinate twice
                    {
                        Position nextPos = new Position(startPosition.GetPositionX() + next.Key * SharedConst.BoundaryVisualizeStepSize, startPosition.GetPositionY() + next.Value * SharedConst.BoundaryVisualizeStepSize, startPosition.GetPositionZ());
                        if (CheckBoundary(nextPos))
                        {
                            Q.Add(next);
                        }
                        else
                        {
                            outOfBounds.Add(next);
                            hasOutOfBoundsNeighbor = true;
                        }
                        alreadyChecked.Add(next);
                    }
                    else
                    {
                        if (outOfBounds.Contains(next))
                        {
                            hasOutOfBoundsNeighbor = true;
                        }
                    }
                }
                if (fill || hasOutOfBoundsNeighbor)
                {
                    var        pos   = new Position(startPosition.GetPositionX() + front.Key * SharedConst.BoundaryVisualizeStepSize, startPosition.GetPositionY() + front.Value * SharedConst.BoundaryVisualizeStepSize, spawnZ);
                    TempSummon point = owner.SummonCreature(SharedConst.BoundaryVisualizeCreature, pos, TempSummonType.TimedDespawn, (uint)(duration * Time.InMilliseconds));
                    if (point)
                    {
                        point.SetObjectScale(SharedConst.BoundaryVisualizeCreatureScale);
                        point.AddUnitFlag(UnitFlags.ImmuneToPc | UnitFlags.Stunned | UnitFlags.ImmuneToNpc);
                        if (!hasOutOfBoundsNeighbor)
                        {
                            point.AddUnitFlag(UnitFlags.NotSelectable);
                        }
                    }
                    Q.Remove(front);
                }
            }
            return(boundsWarning ? CypherStrings.CreatureMovementMaybeUnbounded : 0);
        }