示例#1
0
        private void Add(TriggerArea _this, ObjCharacter character)
        {
            if (null == character)
            {
                return;
            }

            if (!_this.mCharacterList.Contains(character))
            {
                _this.mCharacterList.Add(character);

                try
                {
                    _this.Scene.OnCharacterEnterArea(_this.Id, character);
                }
                catch (Exception e)
                {
                    Logger.Error(e, "Scene.OnCharacterEnterArea");
                }
            }
            else
            {
                Logger.Warn("TriggerArea mObjDict has this");
            }

            if (character.GetObjType() == ObjType.PLAYER)
            {
                if (!_this.mPlayer.Contains(character))
                {
                    _this.mPlayer.Add(character as ObjPlayer);
                }
            }
        }
示例#2
0
 public override void OnCharacterLeaveArea(int areaId, ObjCharacter character)
 {
     if (character.GetObjType() != ObjType.PLAYER)
     {
         return;
     }
     OnTriggerAreaPlayersChanged(AreaDict[areaId]);
 }
示例#3
0
 public void OnDamage(ObjBoss _this, ObjCharacter enemy, int damage)
 {
     ObjNPC.GetImpl().OnDamage(_this, enemy, damage);
     enemy = enemy.GetRewardOwner();
     if (enemy.GetObjType() == ObjType.PLAYER)
     {
         var unit = new DamageUnit();
         unit.CharacterId = enemy.ObjId;
         unit.Damage      = damage;
         _this.damageList.Data.Add(unit);
     }
 }
示例#4
0
        public static bool FindPath(Coroutine co,
                                    SceneObstacle obstacle,
                                    ObjCharacter obj,
                                    Vector2 start,
                                    Vector2 end,
                                    AsyncReturnValue <List <Vector2> > result)
        {
            if (mWaitingPathToFind.Count > 100)
            {
                if (obj.GetObjType() == ObjType.NPC)
                {
                    var npc = obj as ObjNPC;
                    if (npc.CurrentState != BehaviorState.Combat)
                    {
                        result.Value = SceneObstacle.EmptyPath;
                        if (!SceneServer.Instance.ServerControl.mWaitingEvents.IsAddingCompleted)
                        {
                            SceneServer.Instance.ServerControl.mWaitingEvents.Add(new ContinueEvent(co));
                        }

                        return(false);
                    }
                }
            }

            if (!mWaitingPathToFind.IsAddingCompleted)
            {
                mWaitingPathToFind.Add(() =>
                {
                    var path     = obstacle.FindPath(start, end);
                    result.Value = path;

                    if (path.Count == 0)
                    {
                        // Count为0时,我们认为start点是无效的
                        // 当前点的格子中心点是有效的。。存在无效的可能??
                        var ValidStart = new Vector2(((int)(start.X * 2)) / 2.0f, ((int)(start.Y * 2)) / 2.0f);

                        path         = obstacle.FindPath(ValidStart, end);
                        result.Value = path;
                    }

                    if (!SceneServer.Instance.ServerControl.mWaitingEvents.IsAddingCompleted)
                    {
                        SceneServer.Instance.ServerControl.mWaitingEvents.Add(new ContinueEvent(co));
                    }
                });
            }

            return(true);
        }
示例#5
0
        public void Remove(TriggerArea _this, ObjCharacter character)
        {
            if (character.GetObjType() == ObjType.PLAYER)
            {
                _this.mPlayer.Remove(character as ObjPlayer);
            }

            if (_this.mCharacterList.Contains(character))
            {
                _this.mCharacterList.Remove(character);
                try
                {
                    _this.Scene.OnCharacterLeaveArea(_this.Id, character);
                }
                catch (Exception e)
                {
                    Logger.Error(e, "Scene.OnCharacterLeaveArea");
                }
            }
            else
            {
                Logger.Warn("TriggerArea mObjDict doesn't has this");
            }
        }
示例#6
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;
            }
        }