Beispiel #1
0
        public void OnSetSelection(WorldSession session, PCSetSelection packet)
        {
            IUnitEntity target = null;

            WorldSession targetSession = Core.Server.Sessions.SingleOrDefault(s => s.Player.ObjectGUID.RawGUID == packet.GUID);

            if (targetSession != null)
            {
                target = targetSession.Player;
            }

            if (target == null)
            {
                target = Core.GetComponent <EntityComponent>().CreatureEntities.SingleOrDefault(e => e.ObjectGUID.RawGUID == packet.GUID);
            }

            if (target != null)
            {
                session.Player.Target = target;
                session.SendMessage("Target: " + target.Name);
            }
            else
            {
                session.SendMessage("Couldnt find target!");
                session.Player.Target = null;
            }
        }
Beispiel #2
0
        public void RemoveUnit(IUnitEntity unit)
        {
            Units.Remove(unit);
            positions.Remove(unit.Position);
            lastPositions.Remove(unit);

            unit.OnMove -= () => UpdateUnitPosition(unit);
        }
Beispiel #3
0
        // TODO: fix removal of NPCUnitEntityAIs
        public void AddUnit(IUnitEntity unit)
        {
            Units.Add(unit);
            positions.Add(unit.Position, unit);
            lastPositions.Add(unit, unit.Position);

            unit.OnMove += () => UpdateUnitPosition(unit);
        }
Beispiel #4
0
        public T GetUnitAt <T>(Vector3Int position) where T : IUnitEntity
        {
            IUnitEntity unit = GetUnitAt(position);

            if (unit is T t)
            {
                return(t);
            }
            return(default);
Beispiel #5
0
        public PSSpellGo(PlayerEntity caster, IUnitEntity target, uint spellID)
            : base(WorldOpcodes.SMSG_SPELL_GO)
        {
            this.WritePackedUInt64(caster.ObjectGUID.RawGUID);
            this.WritePackedUInt64(target.ObjectGUID.RawGUID);

            this.Write(spellID);
            this.Write((ushort)SpellCastFlags.CAST_FLAG_UNKNOWN9); // Cast Flags!?
            this.Write((byte)1); // Target Length
            this.Write(target.ObjectGUID.RawGUID);
            this.Write((byte)0); // End
            this.Write((ushort)2); // TARGET_FLAG_UNIT
            this.WritePackedUInt64(target.ObjectGUID.RawGUID);
        }
Beispiel #6
0
        public PSSpellGo(PlayerEntity caster, IUnitEntity target, uint spellID)
            : base(WorldOpcodes.SMSG_SPELL_GO)
        {
            this.WritePackedUInt64(caster.ObjectGUID.RawGUID);
            this.WritePackedUInt64(target.ObjectGUID.RawGUID);

            this.Write(spellID);
            this.Write((ushort)SpellCastFlags.CAST_FLAG_UNKNOWN9); // Cast Flags!?
            this.Write((byte)1);                                   // Target Length
            this.Write(target.ObjectGUID.RawGUID);
            this.Write((byte)0);                                   // End
            this.Write((ushort)2);                                 // TARGET_FLAG_UNIT
            this.WritePackedUInt64(target.ObjectGUID.RawGUID);
        }
Beispiel #7
0
        private void OnCastSpell(WorldSession session, PCCastSpell packet)
        {
            IUnitEntity target = session.Player.Target ?? session.Player;

            target.SubscribedBy.ToList().ForEach(s => s.SendPacket(new PSSpellGo(session.Player, target, packet.spellID)));
            session.SendPacket(new PSSpellGo(session.Player, target, packet.spellID));
            session.SendPacket(new PSCastFailed(packet.spellID));

            SpellEntry spell      = Core.DBC.GetDBC <SpellEntry>().SingleOrDefault(s => s.ID == packet.spellID);
            float      spellSpeed = spell.Speed;

            /*
             * float distance =  (float)Math.Sqrt((session.Entity.X - session.Entity.Target.X) * (session.Entity.X - session.Entity.Target.X) +
             *                                 (session.Entity.Y - session.Entity.Target.Y) * (session.Entity.Y - session.Entity.Target.Y) +
             *                                 (session.Entity.Z - session.Entity.Target.Z) * (session.Entity.Z - session.Entity.Target.Z));
             *
             * if (distance < 5) distance = 5;
             *
             * float dx = session.Entity.X - target.X;
             * float dy = session.Entity.Y - target.Y;
             * float dz = session.Entity.Z - target.Target.Z;
             * float radius = 5;
             * float distance = (float)Math.Sqrt((dx * dx) + (dy * dy) + (dz * dz)) - radius;
             *
             * //if (distance < 5) distance = 5;
             * float timeToHit = (spellSpeed > 0) ? (float)Math.Floor(distance / spellSpeed * 1000f) : 0;
             *
             * session.sendMessage("Cast [" + spell.Name + "] Distance: " + distance + " Speed: " + spellSpeed + " Time: " + timeToHit);
             * float radians = (float)(Math.Atan2(session.Entity.Y - session.Entity.Target.Y, session.Entity.X - session.Entity.Target.X));
             *
             * if(spellSpeed > 0)
             * {
             *  DoTimer(timeToHit, (s, e) =>
             *  {
             *      WorldServer.TransmitToAll(new PSMoveKnockBack(target, (float)Math.Cos(radians), (float)Math.Sin(radians), -10, -10));
             *  });
             * }
             *
             *
             */
        }
Beispiel #8
0
 public bool TryGetUnitAt(Vector3Int position, out IUnitEntity data)
 {
     return(positions.TryGetValue(position, out data));
 }
Beispiel #9
0
 public void UpdateUnitPosition(IUnitEntity unit)
 {
     positions.Remove(lastPositions[unit]);
     positions.Add(unit.Position, unit);
     lastPositions[unit] = unit.Position;
 }
Beispiel #10
0
        public static void Default(WorldSession session, string[] args)
        {
            if (args.Length == 1 && args[0].ToLower() == "list")
            {
                session.SendMessage("List");
            }
            else if (args.Length == 2)
            {
                string attributeName  = args[0].ToLower();
                string attributeValue = args[1];

                // If player isn't targeting. Target self
                IUnitEntity entity = session.Player.Target ?? session.Player;

                //TODO Fix horrible hack.
                UnitInfo info = entity.ObjectGUID.TypeID == TypeID.TYPEID_PLAYER ? (UnitInfo)((PlayerEntity)entity).Info : ((CreatureEntity)entity).Info;

                bool unknownAttribute = false;

                switch (attributeName)
                {
                case "faction":
                    var val = uint.Parse(attributeValue);
                    if (val == 0)
                    {
                        session.SendMessage("FactionID: " + info.FactionTemplate);
                    }
                    else
                    {
                        session.SendMessage("Old FactionID: " + info.FactionTemplate);
                        info.FactionTemplate = val;
                        session.SendMessage("New FactionID: " + info.FactionTemplate);
                    }
                    break;

                case "scale":
                    info.Scale = float.Parse(attributeValue);
                    break;

                case "health":
                    info.Health = int.Parse(attributeValue);
                    break;

                case "level":
                    info.Level = int.Parse(attributeValue);
                    break;

                case "xp":
                    (info as PlayerInfo).XP = int.Parse(attributeValue);
                    break;

                case "model":
                    info.DisplayID = int.Parse(attributeValue);
                    break;

                case "money":
                    int moneyToAdd = int.Parse(attributeValue) < 0x7fffffff ? int.Parse(attributeValue) : 0x7fffffff;
                    (info as PlayerInfo).Money     += moneyToAdd;
                    session.Player.Character.money += moneyToAdd;
                    break;

                case "standstate":
                    info.StandState = (byte)int.Parse(attributeValue);
                    break;

                case "speed":
                    info.WalkSpeed = float.Parse(attributeValue);
                    session.SendPacket(new PSForceRunSpeedChange(entity.ObjectGUID, info.WalkSpeed));
                    break;

                default:
                    unknownAttribute = true;
                    break;
                }

                if (unknownAttribute)
                {
                    session.SendMessage("Attribute '" + attributeName + "' was unknown");
                }
                else
                {
                    session.SendMessage("Applied " + attributeName + " = " + attributeValue + "");
                }
            }
        }