Exemplo n.º 1
0
        //触发掉落
        public void MonsterKill(ObjNPC npc, ulong killer)
        {
            var tbNpc = Table.GetNpcBase(npc.TypeId);

            if (tbNpc == null)
            {
                Logger.Error("MonsterKill Type={0}", npc.TypeId);
                return;
            }
            var scene      = npc.Scene;
            var GiveExp    = new Dictionary <ObjCharacter, int>();
            var playerList = npc.GetExpList(GiveExp);

            if (playerList == null)
            {
                return;
            }
            if (playerList.Count < 1)
            {
                return;
            }
            //分经验
            foreach (var i in GiveExp)
            {
                var player = i.Key as ObjPlayer;
                if (player != null)
                {
                    var giveExp = 0;
                    if (tbNpc.IsDynamicExp == 1)
                    {
                        var refExp = i.Key.Attr._ExpRef;
                        if (tbNpc.ExpMultiple > 2)
                        {
                            refExp = (tbNpc.ExpMultiple + i.Key.Attr._ExpRef - 10000);
                        }
                        giveExp =
                            (int)
                            (tbNpc.DynamicExpRatio / 10000.0f * Table.GetLevelData(player.GetLevel()).DynamicExp *refExp /
                             10000);
                    }
                    else
                    {
                        if (tbNpc.ExpMultiple < 2)
                        {
                            giveExp = i.Value * i.Key.Attr._ExpRef / 10000;
                        }
                        else
                        {
                            giveExp = (int)(1.0 * i.Value * (tbNpc.ExpMultiple + i.Key.Attr._ExpRef - 10000) / 10000);
                        }
                    }

                    var addCount = AutoActivityManager.GetActivity(1020);
                    if (addCount > 1)
                    {
                        if (tbNpc.Id >= 210000 && tbNpc.Id <= 213104)
                        {
                            giveExp = giveExp * addCount;
                        }
                    }
                    giveExp = (int)(giveExp * player.GetAdditionExp());
                    float fExp = player.Attr.ExpAdd / 10000.0f;
                    giveExp = (int)(giveExp * fExp);
                    if (player.Scene != null)
                    {
                        player.Scene.OnPlayerPickUp(player.ObjId, (int)eResourcesType.ExpRes, giveExp);
                    }

                    CoroutineFactory.NewCoroutine(MonsterKillMessageToLogic, i.Key.ObjId, npc.TypeId, giveExp,
                                                  scene.TypeId).MoveNext();
                    //攻击装备耐久相关
                    player.TryDelAttackEquipDurable();
                }
            }

            var dropId = tbNpc.DropId;

            if (scene.SpecialDrop != -1 && tbNpc.Spare != -1)
            {
                var tbSU = Table.GetSkillUpgrading(tbNpc.Spare);
                dropId = tbSU.GetSkillUpgradingValue(scene.SpecialDrop);
            }
            if (dropId == -1)
            {
                return;
            }
            var Droplist = new Dictionary <int, int>();

            //特殊掉落
            {
                List <int> list;
                if (Drop.SpecialDropForNewCharacter.TryGetValue(tbNpc.Id, out list))
                {
                    var id        = list[0];
                    var character = CharacterManager.Instance.GetCharacterControllerFromMemroy(killer);
                    if (character != null)
                    {
                        var ex = character.mDbData.SpecialDrop;
                        if (!BitFlag.GetLow(ex, id))
                        {
                            Droplist.Clear();
                            var dropid = list[character.TypeId + 1];
                            DropMother(dropid, Droplist);
                            if (Droplist.Count > 0)
                            {
                                ex = BitFlag.LongSetFlag(ex, id);
                                character.mDbData.SpecialDrop = ex;
                                character.MarkDbDirty();
                            }
                            foreach (var i in Droplist)
                            {
                                scene.CreateDropItem(tbNpc.BelongType, new List <ulong> {
                                    character.ObjId
                                }, 0, i.Key, i.Value,
                                                     npc.GetPosition());
                            }
                            Droplist.Clear();
                        }
                    }
                }
            }

            //节日掉落
            {
                var dropIds    = tbNpc.SpecialDrops;
                var yunyingIds = tbNpc.YunYingIds;
                for (int i = 0; i < yunyingIds.Count; i++)
                {
                    var tbOperationActivity = Table.GetOperationActivity(yunyingIds[i]);
                    if (null == tbOperationActivity)
                    {
                        continue;
                    }
                    if (!(System.DateTime.Now >= System.DateTime.Parse(tbOperationActivity.openTime) &&
                          System.DateTime.Now <= System.DateTime.Parse(tbOperationActivity.closeTime)))
                    {
                        continue;
                    }
                    if (i >= dropIds.Count)
                    {
                        continue;
                    }
                    Droplist.Clear();
                    DropMother(dropIds[i], Droplist);
                    var character = CharacterManager.Instance.GetCharacterControllerFromMemroy(killer);
                    if (character != null)
                    {
                        foreach (var dropitem in Droplist)
                        {
                            scene.CreateDropItem(tbNpc.BelongType,
                                                 new List <ulong> {
                                character.ObjId
                            },
                                                 0,
                                                 dropitem.Key,
                                                 dropitem.Value,
                                                 npc.GetPosition());
                            //Logger.Warn("holidaydrop: [{0},{1}]", dropitem.Key, dropitem.Value);
                        }
                        Droplist.Clear();
                    }
                }
            }

            //分掉落物品
            switch (tbNpc.BelongType)
            {
            case 0:     //队内自由拾取
            {
                DropMother(dropId, Droplist);
                var ownerList = new List <ulong>();
                foreach (var character in playerList)
                {
                    if (character != null && tbNpc.LimitFlag > 0)
                    {
                        if (character.GetObjType() == ObjType.PLAYER)
                        {
                            var p = character as ObjPlayer;
                            if (p != null)
                            {
                                Dict_int_int_Data data = new Dict_int_int_Data();
                                data.Data.Add(tbNpc.LimitFlag, 1);
                                p.SendExDataChange(data);
                            }
                        }
                    }
                    ownerList.Add(character.ObjId);
                }
                foreach (var i in Droplist)
                {
                    scene.CreateDropItem(tbNpc.BelongType, ownerList, playerList[0].GetTeamId(), i.Key, i.Value,
                                         npc.GetPosition());
                }
            }
            break;

            case 1:     //队内伤害拾取
            {
                DropMother(dropId, Droplist);
                var ownerList = new List <ulong>();
                if (playerList[0].GetTeamId() == 0)
                {
                    ownerList.Add(playerList[0].ObjId);
                    var p = playerList[0] as ObjPlayer;
                    if (p != null)
                    {
                        Dict_int_int_Data data = new Dict_int_int_Data();
                        data.Data.Add(tbNpc.LimitFlag, 1);
                        p.SendExDataChange(data);
                    }
                }
                else
                {
                    var          maxHatre     = 0;
                    ObjCharacter maxCharacter = null;
                    foreach (var character in playerList)
                    {
                        var nh = npc.GetNowHatre(character);
                        if (nh > maxHatre)
                        {
                            maxHatre     = nh;
                            maxCharacter = character;
                        }
                    }
                    //ObjCharacter maxCharacter = npc.GetMaxHatreByTeam(playerList[0].GetTeamId());
                    if (maxCharacter == null)
                    {
                        ownerList.Add(playerList[0].ObjId);
                        maxCharacter = playerList[0];
                    }
                    else
                    {
                        ownerList.Add(maxCharacter.ObjId);
                    }
                    if (maxCharacter.GetObjType() == ObjType.PLAYER)
                    {
                        var p = maxCharacter as ObjPlayer;
                        if (p != null)
                        {
                            Dict_int_int_Data data = new Dict_int_int_Data();
                            data.Data.Add(tbNpc.LimitFlag, 1);
                            p.SendExDataChange(data);
                        }
                    }
                }
                foreach (var i in Droplist)
                {
                    scene.CreateDropItem(tbNpc.BelongType, ownerList, playerList[0].GetTeamId(), i.Key, i.Value,
                                         npc.GetPosition());
                }
            }
            break;

            case 2:     //队内分别拾取
            {
                foreach (var character in playerList)
                {
                    if (npc.Scene == null || character.Scene == null)
                    {
                        continue;
                    }
                    if (npc.Scene.Guid != character.Scene.Guid)
                    {
                        continue;
                    }
                    Droplist.Clear();
                    DropMother(dropId, Droplist);
                    foreach (var i in Droplist)
                    {
                        scene.CreateDropItem(tbNpc.BelongType, new List <ulong> {
                                character.ObjId
                            }, 0, i.Key, i.Value,
                                             npc.GetPosition());
                    }

                    if (character.GetObjType() == ObjType.PLAYER)
                    {
                        var p = character as ObjPlayer;
                        if (p != null)
                        {
                            Dict_int_int_Data data = new Dict_int_int_Data();
                            data.Data.Add(tbNpc.LimitFlag, 1);
                            p.SendExDataChange(data);
                        }
                    }
                }
            }
            break;

            case 3:     //所有人分别拾取
            {
                var Hatres = npc.GetAllHatre();
                foreach (var hatre in Hatres)
                {
                    if (!(hatre.Key is ObjPlayer))
                    {
                        continue;
                    }
                    if (npc.Scene == null || hatre.Key.Scene == null)
                    {
                        continue;
                    }
                    if (npc.Scene.Guid != hatre.Key.Scene.Guid)
                    {
                        continue;
                    }

                    Droplist.Clear();
                    DropMother(dropId, Droplist);
                    foreach (var i in Droplist)
                    {
                        scene.CreateDropItem(tbNpc.BelongType, new List <ulong> {
                                hatre.Key.ObjId
                            }, 0, i.Key, i.Value,
                                             npc.GetPosition());
                    }

                    if (hatre.Key.GetObjType() == ObjType.PLAYER)
                    {
                        var p = hatre.Key as ObjPlayer;
                        if (p != null)
                        {
                            Dict_int_int_Data data = new Dict_int_int_Data();
                            data.Data.Add(tbNpc.LimitFlag, 1);
                            p.SendExDataChange(data);
                        }
                    }
                }
            }
            break;

            case 4:     //所有人自由拾取
            {
                Droplist.Clear();
                DropMother(dropId, Droplist);
                var addCount = AutoActivityManager.GetActivity(1010);
                if (addCount > 1)
                {
                    if (npc.TableNpc.Id >= 65000 && npc.TableNpc.Id < 65005)
                    {
                        for (var i = 1; i < addCount; i++)
                        {
                            DropMother(dropId, Droplist);
                        }
                    }
                }

                foreach (var i in Droplist)
                {
                    scene.CreateDropItem(tbNpc.BelongType, new List <ulong>(), 0, i.Key, i.Value, npc.GetPosition());
                }
            }
            break;
            }
        }