Beispiel #1
0
        public void HandleCreatureKill(MabiCreature creature, MabiCreature killer, MabiVertex position, SkillConst skillId)
        {
            if (killer != null)
            {
                // Shadow Bunshin soul counter
                if (skillId != SkillConst.ShadowBunshin)
                    killer.SoulCount++;

                // Exp
                if (killer.LevelingEnabled)
                {
                    // Give exp
                    var exp = creature.BattleExp * WorldConf.ExpRate;
                    killer.GiveExp((ulong)exp);

                    Send.CombatMessage(killer.Client, killer, "+{0} EXP", exp);

                    EventManager.CreatureEvents.OnCreatureKilled(creature, killer);
                    if (killer is MabiPC)
                        EventManager.PlayerEvents.OnKilledByPlayer(creature, killer);
                }
            }

            var npc = creature as MabiNPC;
            if (npc != null)
            {
                var rnd = RandomProvider.Get();

                // Gold
                if (rnd.NextDouble() < WorldConf.GoldDropRate)
                {
                    var amount = rnd.Next(npc.GoldMin, npc.GoldMax + 1);
                    if (amount > 0)
                    {
                        var gold = new MabiItem(2000);
                        gold.Info.Amount = (ushort)amount;
                        gold.Info.Region = npc.Region;
                        gold.Info.X = (uint)(position.X + rnd.Next(-50, 51));
                        gold.Info.Y = (uint)(position.Y + rnd.Next(-50, 51));
                        gold.DisappearTime = DateTime.Now.AddSeconds(60);

                        this.AddItem(gold);
                    }
                }

                // Drops
                foreach (var drop in npc.Drops)
                {
                    if (rnd.NextDouble() < drop.Chance * WorldConf.DropRate)
                    {
                        var item = new MabiItem(drop.ItemId);
                        item.Info.Amount = 1;
                        item.Info.Region = npc.Region;
                        item.Info.X = (uint)(position.X + rnd.Next(-50, 51));
                        item.Info.Y = (uint)(position.Y + rnd.Next(-50, 51));
                        item.DisappearTime = DateTime.Now.AddSeconds(60);

                        this.AddItem(item);
                    }
                }
            }

            // Set finisher?
            WorldManager.Instance.Broadcast(new MabiPacket(Op.CombatSetFinisher, creature.Id).PutLong(killer.Id), SendTargets.Range, creature);

            // Clear target
            Send.CombatTargetSet(killer, null);

            // Finish this finisher part?
            WorldManager.Instance.Broadcast(new MabiPacket(Op.CombatSetFinisher2, creature.Id), SendTargets.Range, creature);

            // TODO: There appears to be something missing to let it lay there for finish, if we don't kill it with the following packets.
            // TODO: Check for finishing.

            // Make it dead
            WorldManager.Instance.Broadcast(new MabiPacket(Op.IsNowDead, creature.Id), SendTargets.Range, creature);

            // Remove finisher?
            WorldManager.Instance.Broadcast(new MabiPacket(Op.CombatSetFinisher, creature.Id).PutLong(0), SendTargets.Range, creature);

            if (creature.ActiveSkillId != SkillConst.None)
                creature.CancelSkill();

            if (creature.Owner != null)
            {
                Send.DeadFeather(creature, DeadMenuOptions.Here | DeadMenuOptions.FeatherUp);
                // TODO: Unmount.
            }

            creature.CauseOfDeath = DeathCauses.None;

            if (creature.ArenaPvPManager != null && creature.ArenaPvPManager == killer.ArenaPvPManager && creature.ArenaPvPManager.IsAttackableBy(creature, killer))
            {
                creature.ArenaPvPManager.CreatureKilled(creature, killer);
                creature.CauseOfDeath = DeathCauses.Arena;
            }

            // TODO: Trans PvP

            if (creature.CauseOfDeath == DeathCauses.None && creature.EvGEnabled && killer.EvGEnabled)
                if (creature.EvGSupportRace != 0 && killer.EvGSupportRace != 0 && creature.EvGSupportRace != killer.EvGSupportRace)
                    creature.CauseOfDeath = DeathCauses.EvG;

            if (creature.CauseOfDeath == DeathCauses.None)
                creature.CauseOfDeath = DeathCauses.Mob;
        }