Exemple #1
0
        /// <summary>
        /// Plays sound in range of source.
        /// </summary>
        /// <param name="file">e.g. "data/sound/Glasgavelen_blowaway_endure.wav"</param>
        public static void PlaySound(string file, MabiEntity source)
        {
            var packet = new MabiPacket(Op.PlaySound, source.Id);
            packet.PutString(file);

            WorldManager.Instance.Broadcast(packet, SendTargets.Range, source);
        }
Exemple #2
0
        /// <summary>
        /// Broadcasts Effect packet in range. Parameters can be added,
        /// but you have to watch the types.
        /// </summary>
        public static void Effect(uint effect, MabiEntity source, params object[] args)
        {
            var packet = new MabiPacket(Op.Effect, source.Id);
            packet.PutInt(effect);
            foreach (var arg in args)
            {
                if (!(arg is bool))
                    packet.Put(arg);
                else
                    packet.PutByte((bool)arg);
            }

            WorldManager.Instance.Broadcast(packet, SendTargets.Range, source);
        }
Exemple #3
0
 private static void AddPublicEntityInfo(this MabiPacket packet, MabiEntity entity)
 {
     if (entity is MabiCreature) packet.AddCreatureInfo(entity as MabiCreature, CreaturePacketType.Public);
     else if (entity is MabiItem) packet.AddItemInfo(entity as MabiItem, ItemPacketType.Public);
     else if (entity is MabiProp) packet.AddPropInfo(entity as MabiProp);
     else throw new Exception("Unknown entity class '" + entity.GetType() + "'");
 }
Exemple #4
0
        /// <summary>
        /// Calculates and sets new position for creature, and returns a copy
        /// of the current coordinates, for later use.
        /// </summary>
        /// <param name="target">Creature to knock back</param>
        /// <param name="attacker">Creature that attacked</param>
        /// <param name="distance">Knock back distance</param>
        /// <returns>Position of creature, before the knock back</returns>
        public static MabiVertex KnockBack(MabiCreature target, MabiEntity attacker, int distance = 375)
        {
            var oldPos = target.GetPosition();
            var pos = WorldManager.CalculatePosOnLine(attacker, target, distance);

            // Check for collision, set new pos 200 points before the
            // intersection, to prevent glitching through.
            MabiVertex intersection;
            if (WorldManager.Instance.FindCollision(attacker.Region, oldPos, pos, out intersection))
                pos = WorldManager.CalculatePosOnLine(oldPos, intersection, -200);

            target.SetPosition(pos.X, pos.Y);
            return oldPos;
        }
Exemple #5
0
        private static MabiPacket GetEntityDisappears(MabiEntity entity)
        {
            uint op = Op.EntityDisappears;
            if (entity is MabiItem)
                op = Op.ItemDisappears;

            var packet = new MabiPacket(op, Id.Broadcast);
            packet.PutLong(entity.Id);
            packet.PutByte(0);

            return packet;
        }
Exemple #6
0
 /// <summary>
 /// Checks distance between the entity and the coordinates, does not check region.
 /// </summary>
 public static bool InRange(MabiEntity entity, uint x, uint y, uint range = 0)
 {
     var pos = entity.GetPosition();
     return InRange(pos.X, pos.Y, x, y, range);
 }
Exemple #7
0
 public static MabiPacket SpawnEffect(MabiEntity entity, SpawnEffect type, MabiVertex pos)
 {
     return
         new MabiPacket(Op.Effect, entity.Id)
         .PutInt(Effect.Spawn)
         .PutInt(entity.Region)
         .PutFloats(pos.X, pos.Y)
         .PutByte((byte)type);
 }
Exemple #8
0
        protected IEnumerable Circle(MabiEntity center, bool clockwise, int radius, bool wait)
        {
            var centerPos = center.GetPosition();
            var myPos = this.Creature.GetPosition();

            var deltaX = (double)myPos.X - (double)centerPos.X;
            var deltaY = (double)myPos.Y - (double)centerPos.Y;

            var angle = Math.Atan2(deltaY, deltaX);

            angle += (clockwise ? -1 : 1) * rnd.NextDouble() * (Math.PI / 6);

            var x = (int)(Math.Cos(angle) * radius);
            var y = (int)(Math.Sin(angle) * radius);

            var dest = new MabiVertex(centerPos.X + x, centerPos.Y + y);

            foreach (var a in WalkTo(dest, wait))
                yield return a;
        }
Exemple #9
0
 public static List<MabiMail> FindAllSent(MabiEntity e)
 {
     return FindAllSent(e.Id);
 }
Exemple #10
0
 public static void OnEntityLeavesRegion(MabiEntity entity)
 {
     if (EntityLeavesRegion != null)
         EntityLeavesRegion(entity);
 }
Exemple #11
0
 /// <summary>
 /// Calculates a position on the line between source and target.
 /// e.g. distance 0 would be the position of target, 100 would be
 /// 100 points farther away from source.
 /// </summary>
 public static MabiVertex CalculatePosOnLine(MabiEntity source, MabiEntity target, int distance)
 {
     return CalculatePosOnLine(source.GetPosition(), target.GetPosition(), distance);
 }
Exemple #12
0
        public List<MabiCreature> GetPlayersInRange(MabiEntity entity, uint range = 0)
        {
            if (range < 1)
                range = WorldConf.SightRange;

            lock (_creatures)
                return _creatures.FindAll(a => a != entity && a.IsPlayer && a.Region == entity.Region && InRange(a, entity, range));
        }
Exemple #13
0
 public List<MabiEntity> GetEntitiesInRange(MabiEntity entity, uint range = 0)
 {
     var pos = entity.GetPosition();
     return this.GetEntitiesInRange(entity.Region, pos.X, pos.Y, range);
 }
Exemple #14
0
        public List<MabiCreature> GetAttackableCreaturesInRange(MabiEntity entity, uint range = 0)
        {
            if (range < 1)
                range = WorldConf.SightRange;

            lock (_creatures)
                return _creatures.FindAll(a => a != entity && a is MabiNPC && !(a as MabiNPC).Has(CreatureStates.GoodNpc) && !a.IsDead && a.Region == entity.Region && InRange(a, entity, range));
        }
Exemple #15
0
        /// <summary>
        /// Sends packet to all clients that match the parameters.
        /// </summary>
        /// <param name="packet"></param>
        /// <param name="targets"></param>
        /// <param name="source"></param>
        /// <param name="range"></param>
        public void Broadcast(MabiPacket packet, SendTargets targets, MabiEntity source = null, uint range = 0)
        {
            if (range < 1)
                range = WorldConf.SightRange;

            var excludeSender = ((targets & SendTargets.ExcludeSender) != 0);
            WorldClient sourceClient = null;
            if (source != null && source is MabiCreature)
                sourceClient = (source as MabiCreature).Client as WorldClient;

            lock (_clients)
            {
                if ((targets & SendTargets.All) != 0)
                {
                    foreach (var client in _clients)
                    {
                        if (!(excludeSender && client == sourceClient))
                            client.Send(packet);
                    }
                }
                else if ((targets & SendTargets.Region) != 0)
                {
                    var region = source.Region;
                    foreach (var client in _clients)
                    {
                        if (!(excludeSender && client == sourceClient))
                            if (region == client.Character.Region)
                                client.Send(packet);
                    }
                }
                else if ((targets & SendTargets.Range) != 0)
                {
                    var region = source.Region;
                    foreach (var client in _clients)
                    {
                        if (!(excludeSender && client == sourceClient))
                            if (region == client.Character.Region && InRange(client.Character, source, range))
                                client.Send(packet);
                    }
                }
            }
        }
Exemple #16
0
 /// <summary>
 /// Broadcasts appear to everybody in range, except for entity itself.
 /// </summary>
 /// <param name="entity"></param>
 public static void EntityAppearsOthers(MabiEntity entity)
 {
     WorldManager.Instance.Broadcast(GetEntityAppears(entity), SendTargets.Range | SendTargets.ExcludeSender, entity);
 }
Exemple #17
0
 public static List<MabiMail> FindAllRecieved(MabiEntity e)
 {
     return FindAllRecieved(e.Id);
 }
Exemple #18
0
 /// <summary>
 /// Broadcasts disappear in range of entity.
 /// </summary>
 /// <param name="entity"></param>
 public static void EntityDisappears(MabiEntity entity)
 {
     WorldManager.Instance.Broadcast(GetEntityDisappears(entity), SendTargets.Range, entity);
 }
Exemple #19
0
 public static int GetUnreadCount(MabiEntity e)
 {
     return GetUnreadCount(e.Id);
 }
Exemple #20
0
 /// <summary>
 /// Sends dispappear to client.
 /// </summary>
 /// <param name="client"></param>
 /// <param name="entity"></param>
 public static void EntityDisappears(Client client, MabiEntity entity)
 {
     client.Send(GetEntityDisappears(entity));
 }
Exemple #21
0
 public static MabiPacket SpawnEffect(MabiEntity entity, SpawnEffect type)
 {
     return SpawnEffect(entity, type, entity.GetPosition());
 }
Exemple #22
0
        private static MabiPacket GetEntityAppears(MabiEntity entity)
        {
            var op = Op.EntityAppears;
            if (entity.EntityType == EntityType.Item)
                op = Op.ItemAppears;
            else if (entity.EntityType == EntityType.Prop)
                op = Op.PropAppears;

            var packet = new MabiPacket(op, Id.Broadcast);
            packet.AddPublicEntityInfo(entity);
            //entity.AddToPacket(packet);

            return packet;
        }
Exemple #23
0
        /// <summary>
        /// Lets the creature face the target.
        /// </summary>
        /// <param name="creature"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        public static MabiPacket TurnTo(MabiEntity creature, MabiEntity target)
        {
            var cpos = creature.GetPosition();
            var tpos = target.GetPosition();

            var p = new MabiPacket(Op.TurnTo, creature.Id);
            p.PutFloat((float)tpos.X - (float)cpos.X);
            p.PutFloat((float)tpos.Y - (float)cpos.Y);

            return p;
        }
Exemple #24
0
 // Range and position calculations
 // ==================================================================
 /// <summary>
 /// Checks distance between the two entities, does not check region.
 /// </summary>
 public static bool InRange(MabiEntity c1, MabiEntity c2, uint range = 0)
 {
     return InRange(c1.GetPosition(), c2.GetPosition(), range);
 }