Beispiel #1
0
 public bool RemoveGold(Gold gold)
 {
     return RemoveGold(gold.Amount);
 }
Beispiel #2
0
        private void PacketHandler_0x24_DropGold(Object obj, ClientPacket packet)
        {
            var user = (User) obj;
            var amount = packet.ReadUInt32();
            var x = packet.ReadInt16();
            var y = packet.ReadInt16();

            Logger.DebugFormat("{0} {1} {2}", amount, x, y);
            // Do a few sanity checks

            // Is the distance valid? (Can't drop things beyond
            // MAXIMUM_DROP_DISTANCE tiles away)
            if (Math.Abs(x - user.X) > Constants.PICKUP_DISTANCE ||
                Math.Abs(y - user.Y) > Constants.PICKUP_DISTANCE)
            {
                Logger.ErrorFormat("Request to drop gold exceeds maximum distance {0}",
                    Hybrasyl.Constants.MAXIMUM_DROP_DISTANCE);
                return;
            }

            // Does the amount in the packet exceed the 
            // amount of gold the player has?  Are they trying to drop the item on something that 
            // is impassable (i.e. a wall)?
            if ((amount > user.Gold) || (x >= user.Map.X) || (y >= user.Map.Y) ||
                (x < 0) || (y < 0) || (user.Map.IsWall[x, y]))
            {
                Logger.ErrorFormat("Amount {0} exceeds amount {1}, or {2},{3} is a wall, or {2},{3} is out of bounds",
                    amount, user.Gold, x, y);
                return;
            }

            var toDrop = new Gold(amount);
            user.RemoveGold(amount);

            Insert(toDrop);

            // Are we dropping an item onto a reactor?
            Reactor reactor;
            var coordinates = new Tuple<byte, byte>((byte)x, (byte)y);
            if (user.Map.Reactors.TryGetValue(coordinates, out reactor))
            {
                reactor.OnDrop(user, toDrop);
            }
            else
                user.Map.AddGold(x, y, toDrop);
        }
Beispiel #3
0
 public bool AddGold(Gold gold)
 {
     return AddGold(gold.Amount);
 }
Beispiel #4
0
 public void SendVisibleGold(Gold gold)
 {
     Logger.DebugFormat("Sending add visible item packet");
     var x07 = new ServerPacket(0x07);
     x07.WriteUInt16(1);
     x07.WriteUInt16(gold.X);
     x07.WriteUInt16(gold.Y);
     x07.WriteUInt32(gold.Id);
     x07.WriteUInt16((ushort)(gold.Sprite + 0x8000));
     x07.WriteInt32(0);
     x07.DumpPacket();
     Enqueue(x07);
 }
Beispiel #5
0
 public void RemoveGold(Gold gold)
 {
     // Remove the gold from the world at the specified location.
     Logger.DebugFormat("Removing {0} qty {1} id {2}", gold.Name, gold.Amount, gold.Id);
     NotifyNearbyAoiDeparture(gold);
     EntityTree.Remove(gold);
     Objects.Remove(gold);
 }
Beispiel #6
0
 public void AddGold(int x, int y, Gold gold)
 {
     Logger.DebugFormat("{0}, {1}, {2} qty {3} id {4}",
         x, y, gold.Name, gold.Amount, gold.Id);
     if (gold == null)
     {
         Logger.DebugFormat("Item is null, aborting");
         return;
     }
     // Add the gold to the world at the given location.
     gold.X = (byte)x;
     gold.Y = (byte)y;
     gold.Map = this;
     EntityTree.Add(gold);
     Objects.Add(gold);
     NotifyNearbyAoiEntry(gold);
 }
Beispiel #7
0
        public override void OnDeath()
        {
            if (DeathDisabled)
            {
                Stats.Hp = Stats.MaximumHp;
                return;
            }

            // Don't die twice
            if (DeathProcessed == true)
            {
                return;
            }

            // Even if we encounter an error, we still count the death as processed to avoid
            // repeated processiong
            DeathProcessed = true;

            var hitter = LastHitter as User;

            if (hitter == null)
            {
                Map.Remove(this);
                World.Remove(this);
                GameLog.Error("OnDeath: lasthitter was null");
                return; // Don't handle cases of MOB ON MOB COMBAT just yet
            }

            try
            {
                var deadTime = DateTime.Now;

                if (hitter.Grouped)
                {
                    ItemDropAllowedLooters = hitter.Group.Members.Select(user => user.Name).ToList();
                    hitter.Group.Members.ForEach(x => x.TrackKill(Name, deadTime));
                }
                else
                {
                    ItemDropAllowedLooters.Add(hitter.Name);
                    hitter.TrackKill(Name, deadTime);
                }

                hitter.ShareExperience(LootableXP, Stats.Level);
                var itemDropTime = DateTime.Now;

                foreach (var itemname in LootableItems)
                {
                    var item = Game.World.CreateItem(itemname);
                    if (item == null)
                    {
                        GameLog.UserActivityError("User {player}: looting {monster}, loot item {item} is missing", hitter.Name, Name, itemname);
                        continue;
                    }
                    item.ItemDropType           = ItemDropType.MonsterLootPile;
                    item.ItemDropAllowedLooters = ItemDropAllowedLooters;
                    item.ItemDropTime           = itemDropTime;
                    World.Insert(item);
                    Map.Insert(item, X, Y);
                }

                if (LootableGold > 0)
                {
                    var golds = new Gold(LootableGold);
                    golds.ItemDropType           = ItemDropType.MonsterLootPile;
                    golds.ItemDropAllowedLooters = ItemDropAllowedLooters;
                    golds.ItemDropTime           = itemDropTime;
                    World.Insert(golds);
                    Map.Insert(golds, X, Y);
                }
            }
            catch (Exception e)
            {
                GameLog.Error("OnDeath for {Name}: exception encountered, loot/gold cancelled {e}", Name, e);
                Game.ReportException(e);
            }
            Game.World.RemoveStatusCheck(this);
            Map?.Remove(this);
            World?.Remove(this);
        }