Beispiel #1
0
        public void AddObject(MapObject obj, bool spawn = false)
        {
            if (Objects.ContainsKey(obj.MapObjectID))
            {
                Log.WriteLine(LogLevel.Warn, "Duplicate object id in sector {0}:{1}", Y, X);
                Objects.Remove(obj.MapObjectID);
            }
            Objects.Add(obj.MapObjectID, obj);
            obj.MapSector = this;

            if (spawn)
            {
                //broadcast mob to map
                //broadcast other players to map (port code from Map.CharacterEnteredMap to here)

                // If Player: Spawn all Mobs and Players in range to Player, and Whole NPC list
                // If Mob: Spawn Mob to all Players in range
                // If NPC: Lolwut

                if (obj is ZoneCharacter)
                {
                    Map.SendCharacterEnteredMap(obj as ZoneCharacter);
                }
                else if (obj is Mob)
                {
                    using (var spawnpacket = obj.Spawn())
                    {
                        Broadcast(spawnpacket);
                    }
                }
            }
        }
Beispiel #2
0
 public Drop(Item item, MapObject dropper, int x, int y, int secondsToLive)
 {
     Item = new DroppedItem(item);
     DroppedBy = dropper;
     Position = new Vector2(x, y);
     Expire = Program.CurrentTime.AddSeconds(secondsToLive);
     CanTake = true;
 }
Beispiel #3
0
 public AttackSequence(MapObject att, uint min, uint max, ushort skillid, uint x = 0, uint y = 0)
     : this(att, null, min, max, skillid, true)
 {
     this.X = x;
     this.Y = y;
     this._nextAction = Program.CurrentTime.AddMilliseconds(skillInfo.CastTime);
     this.State = AnimationState.AoEShow;
 }
Beispiel #4
0
 public AttackSequence(MapObject att, MapObject vict, uint min, uint max, ushort skillid, bool derp)
     : this(att, vict, min, max, 0)
 {
     this.skillid = skillid;
     this.MinDamage += skillInfo.MinDamage;
     this.MaxDamage += skillInfo.MaxDamage;
     this.X = 0;
     this.Y = 0;
 }
Beispiel #5
0
        private MapObject to; // Could be a player too (PvP or EvP)

        #endregion Fields

        #region Constructors

        public AttackSequence_(MapObject from, MapObject to, ushort skill = (ushort) 0xFFFF, ushort attackspeed = (ushort) 1400)
        {
            this.from = from;
            this.to = to;
            toID = to.MapObjectID;
            State = AnimationState.Running;
            nextSequence = Program.CurrentTime;
            attackSpeed = attackspeed;
            skillid = skill;
        }
Beispiel #6
0
 public AttackSequence__(MapObject from, MapObject to, ushort skill = 0xFFFF, ushort attackspeed = 1400)
 {
     From = from;
     To = to;
     _ToID = to.MapObjectID;
     State = AnimationState.Running;
     _nextSequence = Program.CurrentTime;
     attackSpeed = attackspeed;
     skillid = skill;
 }
Beispiel #7
0
 public AttackSequence(MapObject att, MapObject vict, uint min, uint max, ushort attackspeed)
 {
     this.State = AnimationState.Starting;
     this.attacker = att;
     this.victim = vict;
     this.MinDamage = min;
     this.MaxDamage = max;
     this.attackspeed = attackspeed;
     this._nextAction = Program.CurrentTime;
     this.skillid = NoSkill;
     this.AnimationID = att.UpdateCounter;
     this.State = AnimationState.Running;
 }
Beispiel #8
0
        public static void SendAttackAnimation(MapObject from, ushort objectID, ushort attackspeed, byte stance)
        {
            using (var packet = new Packet(SH9Type.AttackAnimation))
            {
                packet.WriteUShort(from.MapObjectID);
                packet.WriteUShort(objectID);
                packet.WriteByte(stance);

                packet.WriteUShort(attackspeed);

                packet.WriteByte(4);
                packet.WriteByte(100);
                from.MapSector.Broadcast(packet);
            }
        }
Beispiel #9
0
        public override void Update(DateTime date)
        {
            if (Position == null)
            {
                return;
            }

            if (IsDead)
            {
                if (!DeathTriggered)
                {
                    Die();
                    return; // Wait till 3 seconds are over, then remove
                }
                else if (_nextUpdate <= date)
                {
                    Map.RemoveObject(this.MapObjectID);
                    Position = null;
                    return;
                }
                return;
            }

            if (AttackingSequence != null && Target != null)
            {
                if (Vector2.Distance(Target.Position, Position) < 50)
                {
                    AttackingSequence.Update(date);
                    if (AttackingSequence.State == AttackSequence.AnimationState.Ended)
                    {
                        AttackingSequence = null;
                        Target = null;

                    }
                }
                else
                {
                    _nextUpdate = _nextUpdate.AddDays(-1);
                }
            }

            if (_nextUpdate > date) return;

            if (Target != null)
            {
                _nextUpdate = Program.CurrentTime.AddSeconds(1);

                // Try to move to target's pos
                // Might glitch the f**k out. lol
                if (Target.Map != Map)
                {
                    Target = null; // Stop aggro-ing >:(
                }
                else
                {
                    if (Vector2.Distance(Target.Position, Position) < 800)
                    {
                        if (Map.Block.CanWalk(Target.Position.X, Target.Position.Y))
                        {
                            Move(Position.X, Position.Y, Target.Position.X, Target.Position.Y, false, false);
                        }
                    }
                    else
                    {
                        Target = null; // Stop aggro-ing >:(
                    }
                }
                return;
            }
            else
            {
                _nextUpdate = Program.CurrentTime.AddSeconds(Program.Randomizer.Next(10, 60)); // Around 10 seconds to 1 minute before new movement is made

                // Move to random spot.
                Vector2 newpos = new Vector2(Position);
                bool ok = false;
                for (int i = 1; i <= 20; i++)
                {
                    // Generate new position, and check if it's in valid bounds, else recheck
                    newpos = Vector2.GetRandomSpotAround(Program.Randomizer, newpos, 60);
                    if (newpos.X > 0 && newpos.Y > 0 && Map.Block.CanWalk(newpos.X, newpos.Y) && PositionIsInBoundries(newpos))
                    {
                        ok = true;
                        break;
                    }
                    /*
                    int t = Program.Randomizer.Next() % 11;

                    if (t <= 2)
                    {
                        // All +

                        newx += Program.Randomizer.Next(MinMovement, MaxMovement);
                        newy += Program.Randomizer.Next(MinMovement, MaxMovement);
                    }
                    else if (t <= 5)
                    {
                        newx -= Program.Randomizer.Next(MinMovement, MaxMovement);
                        newy += Program.Randomizer.Next(MinMovement, MaxMovement);
                    }
                    else if (t <= 8)
                    {
                        newx += Program.Randomizer.Next(MinMovement, MaxMovement);
                        newy -= Program.Randomizer.Next(MinMovement, MaxMovement);
                    }
                    else
                    {
                        newx -= Program.Randomizer.Next(MinMovement, MaxMovement);
                        newy -= Program.Randomizer.Next(MinMovement, MaxMovement);
                    }
                    Vector2 test = newpos + new Vector2(newx, newy);
                    if (Map.Block.CanWalk(test.X, test.Y) && PositionIsInBoundries(test))
                    {
                        newpos = test;
                        break;
                    }
                    */
                }

                if (ok)
                {
                    Move(Position.X, Position.Y, newpos.X, newpos.Y, false, false);
                }
            }
        }
Beispiel #10
0
        public override void AttackSkill(ushort skillid, MapObject victim)
        {
            base.AttackSkill(skillid, victim); // lol

            if (AttackingSequence != null) return;
            AttackingSequence = new AttackSequence(this, victim, 0, InfoServer.Str, skillid, true);
            Target = victim;
        }
Beispiel #11
0
 public bool FullAddObject(MapObject obj)
 {
     Log.WriteLine(LogLevel.Debug, "Added {0} to the map.", obj.GetType().ToString());
     if (AssignObjectID(obj))
     {
         return FinalizeAdd(obj);
     }
     else return false;
 }
Beispiel #12
0
 public bool AssignObjectID(MapObject obj)
 {
     bool result = false;
     lock (availableLifeKeys)
     {
         if (availableLifeKeys.Count == 0)
         {
             if (lifeIndexer == ushort.MaxValue)
             {
                 Log.WriteLine(LogLevel.Warn, "Map is having map object id overflow (cannot handler more than {0})", ushort.MaxValue);
                 result = false;
             }
             else
             {
                 ushort key = lifeIndexer;
                 ++lifeIndexer;
                 obj.MapObjectID = key;
                 result = true;
             }
         }
         else
         {
             ushort key = availableLifeKeys.Dequeue();
             obj.MapObjectID = key;
             result = true;
         }
         if (result)
             obj.Map = this;
         return result;
     }
 }
Beispiel #13
0
 public static void SendSkillStartOthers(MapObject user, ushort skillid, ushort victim, ushort animid)
 {
     // 9 79 | [9A 26] [06 06] [8A 27] [97 2D]
     using (var packet = new Packet(SH9Type.SkillUsePrepareOthers))
     {
         packet.WriteUShort(user.MapObjectID);
         packet.WriteUShort(skillid);
         packet.WriteUShort(victim);
         packet.WriteUShort(animid);
         user.MapSector.Broadcast(packet, user.MapObjectID);
     }
 }
Beispiel #14
0
 public static void SendSkillNoVictim(MapObject user, ushort animid)
 {
     // 9 82 | [75 70] [32 29] [00]
     using (var packet = new Packet(SH9Type.SkillAnimationTarget))
     {
         packet.WriteUShort(animid);
         packet.WriteUShort(user.MapObjectID);
         packet.WriteBool(false);
         user.MapSector.Broadcast(packet);
     }
 }
Beispiel #15
0
        public void RemoveObject(MapObject obj)
        {
            Objects.Remove(obj.MapObjectID);
            obj.MapSector = null;

            using (var remover = Handler7.RemoveObject(obj))
            {
                Broadcast(remover);
            }
        }
Beispiel #16
0
 public static void SendSkillAnimationForPlayer(MapObject user, ushort skillid, ushort animid)
 {
     // 9 87 | [E5 3F] [8A 27] [04 06]
     // 9 87 | [97 2D] [9A 26] [06 06]
     using (var packet = new Packet(SH9Type.SkillAnimation))
     {
         packet.WriteUShort(animid);
         packet.WriteUShort(user.MapObjectID);
         packet.WriteUShort(skillid);
         user.MapSector.Broadcast(packet);
     }
 }
Beispiel #17
0
        public void Transfer(MapObject obj, Sector to)
        {
            Objects.Remove(obj.MapObjectID);
            to.AddObject(obj);
            // we remove object first to the 'non display region'
            ZoneCharacter character = obj as ZoneCharacter;
            List<Sector> oldsectors = Map.GetSectorsOutOfRange(this, to);

            // The idea of this function
            // 1. Remove obj from map for players that are out of range
            // (IF PLAYER) 2. Remove objects that are out of range for obj
            // (IF PLAYER) 3. Spawn objects that are new in range for obj
            // 4. Spawn obj for all players in new range

            using (var removeObjPacket = Handler7.RemoveObject(obj)) // Make new packet to remove object from map for others
            {
                // Even nederlands: Kijken of we mensen kunnen vinden in range?
                foreach (var victimObject in Map.GetObjectsBySectors(oldsectors))
                {
                    if (victimObject is NPC) continue; // NPC's are for noobs. Can't despawn

                    if (victimObject is ZoneCharacter)
                    {
                        // Remove obj for player
                        ZoneCharacter victim = victimObject as ZoneCharacter;
                        victim.Client.SendPacket(removeObjPacket);
                    }

                    if (character != null)
                    {
                        // Despawn victimObject for obj
                        using (var removeVictimPacket = Handler7.RemoveObject(victimObject))
                        {
                            character.Client.SendPacket(removeVictimPacket);
                        }
                    }

                }
            }

            //we remove all the drops out of the character's region
            if (character != null && character.Client != null)
            {
                foreach (var dropoutofrange in Map.GetDropsBySectors(oldsectors))
                {
                    using (var despawndrop = Handler6.RemoveDrop(dropoutofrange))
                    {
                        character.Client.SendPacket(despawndrop);
                    }
                }
            }

            //now we spawn the object to other objects in map
            List<Sector> newsectors = Map.GetSectorsNewInRange(this, to);
            List<MapObject> objects = Map.GetObjectsBySectors(newsectors);
            using (var packet = obj.Spawn())
            {
                foreach (var mapObject in objects)
                {
                    if (mapObject is NPC) continue; //we don't respawn NPCs

                    if (mapObject is ZoneCharacter)
                    {
                        ZoneCharacter rangechar = mapObject as ZoneCharacter;

                        // Send spawn packet of the object (can be both a character and mob) to mapObject (a player)
                        rangechar.Client.SendPacket(packet);
                    }

                    if (character != null)
                    {
                        // Send spawn packet of mapObject to character
                        using (var spawn = mapObject.Spawn())
                        {
                            character.Client.SendPacket(spawn);
                        }
                    }
                }
            }

            if (character != null && character.Client != null)
            {
                using (var spawndrops = Handler7.ShowDrops(Map.GetDropsBySectors(newsectors)))
                {
                    character.Client.SendPacket(spawndrops);
                }
            }
        }
Beispiel #18
0
 public static void SendSkillPosition(MapObject user, ushort animid, ushort skillid, uint x, uint y)
 {
     // 9 81 | [32 29] [B8 10] [56 0A 00 00] [3A 27 00 00] [75 70]
     using (var packet = new Packet(SH9Type.SkillAnimationPosition))
     {
         packet.WriteUShort(user.MapObjectID);
         packet.WriteUShort(skillid);
         packet.WriteUInt(x);
         packet.WriteUInt(y);
         packet.WriteUShort(animid);
         user.MapSector.Broadcast(packet);
     }
 }
Beispiel #19
0
 public static Packet RemoveObject(MapObject obj)
 {
     Packet packet = new Packet(SH7Type.RemoveObject);
     packet.WriteUShort(obj.MapObjectID);
     return packet;
 }
Beispiel #20
0
 public static void SendStatsUpdate(MapObject pObject, ZoneClient to, bool selectedby)
 {
     using (var packet = new Packet(SH9Type.StatUpdate))
     {
         packet.WriteBool(selectedby);
         packet.WriteUShort(pObject.MapObjectID);
         if (pObject is ZoneCharacter)
         {
             ((ZoneCharacter)pObject).WriteUpdateStats(packet);
         }
         else
         {
             ((Mob)pObject).WriteUpdateStats(packet);
         }
         to.SendPacket(packet);
     }
 }
Beispiel #21
0
        public override void AttackSkill(ushort skillid, MapObject victim)
        {
            if (victim == null)
            {
                victim = SelectedObject;
            }

            if (IsAttacking || victim == null || !victim.IsAttackable) return;

            ushort attackspeed = 1200;
            Equip weapon;
            EquippedItems.TryGetValue(ItemSlot.Weapon, out weapon);
            uint dmgmin = (uint)GetWeaponDamage(true);
            uint dmgmax = (uint)(GetWeaponDamage(true) + (GetWeaponDamage(true) % 3));
            if (weapon != null)
            {
                attackspeed = weapon.Info.AttackSpeed;
                dmgmin += weapon.Info.MinMelee;
                dmgmax += weapon.Info.MaxMelee;
            }

            AttackingSequence = new AttackSequence(this, victim, dmgmin, dmgmax, skillid, true);
        }
Beispiel #22
0
        public static void SendAttackDamage(MapObject from, ushort objectID, ushort damage, bool crit, uint hpleft, ushort counter)
        {
            using (var packet = new Packet(SH9Type.AttackDamage))
            {
                packet.WriteUShort(from.MapObjectID);
                packet.WriteUShort(objectID);
                packet.WriteBool(crit);
                packet.WriteUShort(damage);
                packet.WriteUInt(hpleft);
                packet.WriteUShort(counter);
                packet.WriteByte(4);
                packet.WriteByte(100);

                from.MapSector.Broadcast(packet);
            }
        }
Beispiel #23
0
 public override void Damage(MapObject bully, uint amount, bool isSP = false)
 {
     base.Damage(bully, amount, isSP);
     if (IsDead)
     {
         State = PlayerState.Dead;
         this.SetHP(0);
         Handler4.SendReviveWindow(this.Client, 180);
     }
 }
Beispiel #24
0
 public bool FinalizeAdd(MapObject obj)
 {
     Sector sector = GetSectorByPos(obj.Position);
     sector.AddObject(obj, true);
     return Objects.TryAdd(obj.MapObjectID, obj);
 }
Beispiel #25
0
 public static void SendDieAnimation(MapObject from, ushort objectID)
 {
     // DO NOT SEND THIS TO THE DYING PLAYER, LOL
     using (var packet = new Packet(SH9Type.DieAnimation))
     {
         packet.WriteUShort(objectID);
         packet.WriteUShort(from.MapObjectID);
         from.MapSector.Broadcast(packet, objectID);
     }
 }
Beispiel #26
0
        public override void Attack(MapObject victim)
        {
            base.Attack(victim); // lol

            if (AttackingSequence != null) return;
            AttackingSequence = new AttackSequence(this, victim, 0, InfoServer.Str, 1400);
            Target = victim;
        }
Beispiel #27
0
 public static void SendSkill(MapObject user, ushort animid, ushort victimid, uint damage, uint newhp, ushort counter, byte special1 = (byte) 0x10, byte special2 = (byte) 0x00)
 {
     // 9 82 | [E5 3F] [8A 27] [01] [8A 27] [10 00] [09 00 00 00] [5E 00 00 00] [A7 4C]
     // 9 82 | [9A 35] [8A 27] [01] [C2 05] [10 00] [0A 00 00 00] [1D 01 00 00] [73 37]
     // 9 82 | [43 3C] [42 15] [01] [AC 4C] [01 01] [7A 02 00 00] [00 00 00 00] [35 09]
     // 9 82 | [0E 39] [42 15] [01] [00 4A] [21 01] [1C 03 00 00] [00 00 00 00] [8C 0E]
     using (var packet = new Packet(SH9Type.SkillAnimationTarget))
     {
         packet.WriteUShort(animid);
         packet.WriteUShort(user.MapObjectID);
         packet.WriteBool(true);
         packet.WriteUShort(victimid);
         packet.WriteByte(special1);
         packet.WriteByte(special2);
         packet.WriteUInt(damage);
         packet.WriteUInt(newhp);
         packet.WriteUShort(counter);
         user.MapSector.Broadcast(packet);
     }
 }
Beispiel #28
0
        public void Die()
        {
            HP = 0;
            Moving = false;
            boundryLT = null;
            boundryRB = null;
            AttackingSequence = null;
            Target = null;
            DeathTriggered = true;

            if (Spawnplace != null)
            {
                Spawnplace.CurrentMobs--;
            }
            _nextUpdate = Program.CurrentTime.AddSeconds(3);
        }
Beispiel #29
0
 public static void SendSkill(MapObject user, ushort animid, List<SkillVictim> victims)
 {
     using (var packet = new Packet(SH9Type.SkillAnimationTarget))
     {
         packet.WriteUShort(animid);
         packet.WriteUShort(user.MapObjectID);
         packet.WriteByte((byte)(victims.Count > 255 ? 255 : victims.Count));
         for (byte i = 0; i < victims.Count && i != 255; i++)
         {
             var victim = victims[i];
             packet.WriteUShort(victim.MapObjectID);
             packet.WriteByte(victim.Stance1);
             packet.WriteByte(victim.Stance2);
             packet.WriteUInt(victim.Damage);
             packet.WriteUInt(victim.HPLeft);
             packet.WriteUShort(victim.HPCounter);
         }
         user.MapSector.Broadcast(packet);
     }
 }
Beispiel #30
0
        private void Init()
        {
            Info = DataProvider.Instance.GetMobInfo(ID);
            MobInfoServer temp;
            DataProvider.Instance.MobData.TryGetValue(Info.Name, out temp);
            InfoServer = temp;
            Moving = false;
            Target = null;
            Spawnplace = null;
            _nextUpdate = Program.CurrentTime;
            DeathTriggered = false;

            HP = MaxHP;
            SP = MaxSP;
            Level = Info.Level;
        }
Beispiel #31
0
        public void Transfer(MapObject obj, Sector to)
        {
            Objects.Remove(obj.MapObjectID);
            to.AddObject(obj);
            // we remove object first to the 'non display region'
            ZoneCharacter character  = obj as ZoneCharacter;
            List <Sector> oldsectors = Map.GetSectorsOutOfRange(this, to);

            // The idea of this function
            // 1. Remove obj from map for players that are out of range
            // (IF PLAYER) 2. Remove objects that are out of range for obj
            // (IF PLAYER) 3. Spawn objects that are new in range for obj
            // 4. Spawn obj for all players in new range

            using (var removeObjPacket = Handler7.RemoveObject(obj)) // Make new packet to remove object from map for others
            {
                // Even nederlands: Kijken of we mensen kunnen vinden in range?
                foreach (var victimObject in Map.GetObjectsBySectors(oldsectors))
                {
                    if (victimObject is NPC)
                    {
                        continue;                      // NPC's are for noobs. Can't despawn
                    }
                    if (victimObject is ZoneCharacter)
                    {
                        // Remove obj for player
                        ZoneCharacter victim = victimObject as ZoneCharacter;
                        victim.Client.SendPacket(removeObjPacket);
                    }

                    if (character != null)
                    {
                        // Despawn victimObject for obj
                        using (var removeVictimPacket = Handler7.RemoveObject(victimObject))
                        {
                            character.Client.SendPacket(removeVictimPacket);
                        }
                    }
                }
            }

            //we remove all the drops out of the character's region
            if (character != null && character.Client != null)
            {
                foreach (var dropoutofrange in Map.GetDropsBySectors(oldsectors))
                {
                    using (var despawndrop = Handler6.RemoveDrop(dropoutofrange))
                    {
                        character.Client.SendPacket(despawndrop);
                    }
                }
            }


            //now we spawn the object to other objects in map
            List <Sector>    newsectors = Map.GetSectorsNewInRange(this, to);
            List <MapObject> objects    = Map.GetObjectsBySectors(newsectors);

            using (var packet = obj.Spawn())
            {
                foreach (var mapObject in objects)
                {
                    if (mapObject is NPC)
                    {
                        continue;                   //we don't respawn NPCs
                    }
                    if (mapObject is ZoneCharacter)
                    {
                        ZoneCharacter rangechar = mapObject as ZoneCharacter;

                        // Send spawn packet of the object (can be both a character and mob) to mapObject (a player)
                        rangechar.Client.SendPacket(packet);
                    }

                    if (character != null)
                    {
                        // Send spawn packet of mapObject to character
                        using (var spawn = mapObject.Spawn())
                        {
                            character.Client.SendPacket(spawn);
                        }
                    }
                }
            }

            if (character != null && character.Client != null)
            {
                using (var spawndrops = Handler7.ShowDrops(Map.GetDropsBySectors(newsectors)))
                {
                    character.Client.SendPacket(spawndrops);
                }
            }
        }