public override void OnRespawn(ObjNPC npc)
 {
     base.OnRespawn(npc);
     mPtIdx = 0;
 }
Beispiel #2
0
 public override void OnTickDie(ObjNPC npc, float delta)
 {
 }
Beispiel #3
0
        public override void OnNpcDie(ObjNPC npc, ulong characterId = 0)
        {
            base.OnNpcDie(npc, characterId);

            int buffId;
            int dictId;
            var campId = -1;
            int contribution;
            var typeId = npc.TypeId;

            switch (typeId)
            {
            case GuardTypeId1:
            case GuardTypeId2:
            case GuardTypeId3:
            case GuardTypeId4:
            {
                buffId       = 1306;
                dictId       = 300929;
                contribution = StaticVariable.GuardContribution;

                //
                var idx = Guards.IndexOf(npc);
                if (idx == -1)
                {
                    Logger.Error("In OnNpcDie(). idx == -1");
                    break;
                }
                GuardState.Items[idx] = 1;
                NotifyAllianceWarNpcDataToAllPlayer();
            }
            break;

            case Tower1TypeId:
            {
                buffId       = 1307;
                dictId       = 300931;
                contribution = StaticVariable.TowerContribution;

                var tbPos = Table.GetRandomCoordinate(403);
                campId = Offensiver1CampId;
                var camp = Camps[campId];
                camp.RelivePos = new Vector2(tbPos.PosX, tbPos.PosY);
                camp.Step      = 1;
            }
            break;

            case Tower2TypeId:
            {
                buffId       = 1307;
                dictId       = 300931;
                contribution = StaticVariable.TowerContribution;

                var tbPos = Table.GetRandomCoordinate(406);
                campId = Offensiver2CampId;
                var camp = Camps[campId];
                camp.RelivePos = new Vector2(tbPos.PosX, tbPos.PosY);
                camp.Step      = 1;
            }
            break;

            default:
                return;
            }

            //刷新buff
            if (AllianceIds[2] != -1)
            {
//如果只有攻城公会只有一个,就不加buff
                DefenderBuffs.modifyValue(buffId, -1);
                RefreshDefenderBuff(buffId, false);
            }

            //找出击杀者
            var caster = FindCharacter(characterId);

            if (caster == null)
            {
                return;
            }
            caster = caster.GetRewardOwner();
            var casterPlayer = caster as ObjPlayer;

            if (casterPlayer == null)
            {
                return;
            }

            //加贡献
            var players = Camps[casterPlayer.GetCamp()].Players;

            foreach (var player in players)
            {
                Utility.GetItem(player.ObjId, (int)eResourcesType.Contribution, contribution);
            }

            //发通告
            var args = new List <string>();

            args.Add(casterPlayer.AllianceName);
            args.Add(caster.GetName());
            if (dictId == 300931)
            {
                if (Camps[campId].AllianceName != null)
                {
                    args.Add(Camps[campId].AllianceName);
                }
                else
                {
                    dictId = 300941;
                }
            }
            var content = Utils.WrapDictionaryId(dictId, args);

            PushActionToAllPlayer(p => { p.Proxy.NotifyBattleReminder(14, content, 1); });
        }
Beispiel #4
0
 public override void OnExitDie(ObjNPC npc)
 {
 }
Beispiel #5
0
 public override void OnExitIdle(ObjNPC npc)
 {
 }
        public override void OnTickCombat(ObjNPC npc, float delta)
        {
            var enemyTarget = GetEnemyCharacter(npc);

            if (enemyTarget == null)
            {
                npc.EnterState(BehaviorState.Idle);
                return;
            }
            if (!npc.CanMove())
            {
                return;
            }
            NextSkill = FindFreeSkill(npc, enemyTarget);
            if (NextSkill == -1)
            {
                return;
            }
            var tbSkill = Table.GetSkill(NextSkill);

            if (tbSkill == null)
            {
                return;
            }

            if ((SkillTargetType)tbSkill.TargetType == SkillTargetType.SELF ||
                (eCampType)tbSkill.CampType == eCampType.Team)
            {
                if (npc.IsMoving())
                {
                    npc.StopMove();
                }
                if (npc.CanSkill())
                {
                    LastTargetId     = enemyTarget.ObjId;
                    SelectLastTarger = true;
                    npc.TurnFaceTo(enemyTarget.GetPosition());
                    npc.UseSkill(ref NextSkill, npc);
                }
                return;
            }


            mSkillDistance = SkillManager.GetSkillDistance((SkillTargetType)tbSkill.TargetType, tbSkill.TargetParam);
            //跟着敌人打
            if ((npc.GetPosition() - enemyTarget.GetPosition()).Length() > mSkillDistance)
            {
                npc.MoveTo(enemyTarget.GetPosition(), mSkillDistance - 0.1f);
            }
            else
            {
                if (npc.IsMoving())
                {
                    npc.StopMove();
                }
                if (npc.CanSkill())
                {
                    LastTargetId     = enemyTarget.ObjId;
                    SelectLastTarger = true;
                    npc.TurnFaceTo(enemyTarget.GetPosition());
                    npc.UseSkill(ref NextSkill, enemyTarget);
                }
            }
        }
Beispiel #7
0
 //休闲O
 public override void OnEnterIdle(ObjNPC npc)
 {
 }
Beispiel #8
0
        public int CheckToStateChange(ObjNPC npc)
        {
            if (npc.TableAI == null)
            {
                return(-1);
            }
            if (npc.TableAI.NextAI == -1)
            {
                return(-1);
            }
            switch (npc.TableAI.NextAICondition)
            {
            case 0:     //血量
            {
                switch (npc.TableAI.Type)
                {
                case 0:             //低于绝对值
                {
                    if (npc.Attr.GetDataValue(eAttributeType.HpNow) < npc.TableAI.Param)
                    {
                        return(npc.TableAI.NextAI);
                    }
                }
                break;

                case 1:             //高于绝对值
                {
                    if (npc.Attr.GetDataValue(eAttributeType.HpNow) > npc.TableAI.Param)
                    {
                        return(npc.TableAI.NextAI);
                    }
                }
                break;

                case 2:             //低于百分比
                {
                    if ((float)npc.Attr.GetDataValue(eAttributeType.HpNow) /
                        npc.Attr.GetDataValue(eAttributeType.HpMax) < (float)npc.TableAI.Param / 10000)
                    {
                        return(npc.TableAI.NextAI);
                    }
                }
                break;

                case 3:             //高于百分比
                {
                    if ((float)npc.Attr.GetDataValue(eAttributeType.HpNow) /
                        npc.Attr.GetDataValue(eAttributeType.HpMax) > (float)npc.TableAI.Param / 10000)
                    {
                        return(npc.TableAI.NextAI);
                    }
                }
                break;
                }
            }
            break;

            case 1:     //战斗时间
            {
                switch (npc.TableAI.Type)
                {
                case 0:             //低于绝对值
                {
                    if (PatrolTime / 1000 < npc.TableAI.Param)
                    {
                        return(npc.TableAI.NextAI);
                    }
                }
                break;

                case 1:             //高于绝对值
                {
                    if (PatrolTime / 1000 > npc.TableAI.Param)
                    {
                        return(npc.TableAI.NextAI);
                    }
                }
                break;
                }
            }
            break;
            }
            return(-1);
        }
 //回家
 public override void OnEnterGoHome(ObjNPC npc)
 {
     base.OnEnterGoHome(npc);
 }
Beispiel #10
0
        /// <summary>
        ///     进入某个AI状态
        /// </summary>
        /// <param name="_this"></param>
        /// <param name="state"></param>
        public void EnterState(ObjNPC _this, BehaviorState state)
        {
            if (state == _this.CurrentState)
            {
                return;
            }

            try
            {
                switch (_this.CurrentState)
                {
                case BehaviorState.Idle:
                    _this.Script.OnExitIdle(_this);
                    break;

                case BehaviorState.Combat:
                    _this.Script.OnExitCombat(_this);
                    break;

                case BehaviorState.GoHome:
                    _this.Script.OnExitGoHome(_this);
                    break;

                case BehaviorState.Die:
                    _this.Script.OnExitDie(_this);
                    break;

                default:
                    //Logger.Warn("Unknow ai type");
                    break;
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }

            _this.LastState    = _this.CurrentState;
            _this.CurrentState = state;
            try
            {
                switch (_this.CurrentState)
                {
                case BehaviorState.Idle:
                    _this.Script.OnEnterIdle(_this);
                    break;

                case BehaviorState.Combat:
                    _this.Script.OnEnterCombat(_this);
                    break;

                case BehaviorState.GoHome:
                    _this.Script.OnEnterGoHome(_this);
                    _this.RemoveMeFromOtherEnemyList();
                    _this.ClearEnemy();
                    _this.Skill.LastSkillMainTarget.SetTarget(null);
                    break;

                case BehaviorState.Die:
                    _this.Script.OnEnterDie(_this);
                    break;

                default:
                    Logger.Warn("Unknow ai type");
                    break;
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }

            // 爬塔怪物行为状态监听
            if (null != _this.OnBehaviourChangeCallback)
            {
                _this.OnBehaviourChangeCallback.Invoke(_this, _this.CurrentState, _this.LastState);
            }
        }
Beispiel #11
0
        public override void OnTickCombat(ObjNPC npc, float delta)
        {
            if (npc.TableAI.Id == MieShiBuildingAI)
            {
                if (!npc.CanSkill())
                {
                    return;
                }

                if (!npc.CanSkill())
                {
                    return;
                }
                //判断敌人是否存在
                var enemy = GetCanAttack(npc);
                if (null == enemy)
                {
                    npc.EnterState(BehaviorState.GoHome);
                    return;
                }


                var WillskillId     = npc.NormalSkillId; //GetCanDoSkill(npc);//npc.NormalSkillId;
                var mTableWillskill = Table.GetSkill(WillskillId);
                if (mTableWillskill == null)
                {
                    return;
                }

                mSkillDistance = SkillManager.GetSkillDistance((SkillTargetType)mTableWillskill.TargetType,
                                                               mTableWillskill.TargetParam);
                //跟着敌人打
                if ((npc.GetPosition() - enemy.GetPosition()).Length() > mSkillDistance)
                {
                    var diffDis = mSkillDistance - 1.0f;
                    if (diffDis < 0)
                    {
                        diffDis = 0;
                    }
                    npc.MoveTo(enemy.GetPosition(), diffDis);
                }
                else
                {
                    npc.TurnFaceTo(enemy.GetPosition());
                    if (npc.IsMoving())
                    {
                        npc.StopMove();
                    }
                    if (DateTime.Now >= mNextNormalAttackTime)
                    {
                        var reCodes = npc.MustSkill(ref WillskillId, enemy); //npc.UseSkill(ref skillId, enemy);
                        //if (reCodes == ErrorCodes.OK)
                        //{
                        //    PushSkillCd(npc, WillskillId);
                        //}
                    }
                }
            }
            else
            {
                PatrolTime += 500;
                //判断是否需要状态转换
                if (!bAIChange)
                {
                    var nextAi = CheckToStateChange(npc);
                    if (nextAi > -1)
                    {
                        Logger.Warn("======================ChangeAi============================[179] {0}", npc.mTypeId);
                        ChangeAi(npc, nextAi);
                        bAIChange = true;
                        return;
                    }
                }
                base.OnTickCombat(npc, delta);
            }
        }
Beispiel #12
0
        public void Seperate(ObjNPC _this, ObjCharacter enemy, float dist)
        {
            if (ObjNPC.PreCalculatedClockwiseRotation == null)
            {
                CalculateRotation();
            }

            var          move = false;
            ObjCharacter npc;

            // 如果人很多的话,减小距离
            var d = 2 * Math.PI * dist / enemy.EnemyList.Count;
            var t = Math.Min(d * d, 0.25f);
            var s = 0;
            var i = 0;

            for (; i < enemy.EnemyList.Count; i++)
            {
                var npcId = enemy.EnemyList[i];
                if (npcId == _this.ObjId)
                {
                    break;
                }

                npc = _this.Scene.FindCharacter(npcId);
                if (npc == null)
                {
                    enemy.EnemyList.RemoveAt(i);
                    --i;
                    continue;
                }
                var distSqr = (npc.GetPosition() - _this.GetPosition()).LengthSquared();

                if (distSqr < 1)
                {
                    if (distSqr < t)
                    {
                        move = true;
                    }

                    s++;
                }
            }


            if (s >= 36)
            {
                // 怪实在太多了,随便找个地方给他吧
                s = MyRandom.Random(3);
            }

            if (move)
            {
                var pos = _this.GetPosition();
                var p   = (pos - enemy.GetPosition());

                //顺时针旋转
                if (_this.ObjId % 2 == 0)
                {
                    var x = Vector2.Dot(p, ObjNPC.PreCalculatedClockwiseRotation[2 * s]);
                    var y = Vector2.Dot(p, ObjNPC.PreCalculatedClockwiseRotation[2 * s + 1]);
                    pos = enemy.GetPosition() + new Vector2(x, y);
                }
                else
                {
                    var x = Vector2.Dot(p, ObjNPC.PreCalculatedCounterClockwiseRotation[2 * s]);
                    var y = Vector2.Dot(p, ObjNPC.PreCalculatedCounterClockwiseRotation[2 * s + 1]);
                    pos = enemy.GetPosition() + new Vector2(x, y);
                }

                if (enemy.Scene.ValidPosition(pos))
                {
                    _this.SetPosition(pos);
                }
            }
        }
Beispiel #13
0
 /// <summary>
 ///     复活
 /// </summary>
 public void Relive(ObjRetinue _this, bool byItem = false)
 {
     ObjNPC.GetImpl().Relive(_this, byItem);
 }
Beispiel #14
0
 /// <summary>
 ///     重新刷出(注意和复活的区别)
 /// </summary>
 public void Respawn(ObjRetinue _this)
 {
     ObjNPC.GetImpl().Respawn(_this);
 }
Beispiel #15
0
 public override void OnTickGoHome(ObjNPC npc, float delta)
 {
     npc.EnterState(BehaviorState.Idle);
 }
        private void TryToCallPartner(ObjNPC npc, ObjCharacter enemy, float distSqr = 100)
        {
            try
            {
                if (enemy != null)
                {
                    foreach (ObjBase o in npc.Zone.EnumAllVisibleObj())
                    {
                        try
                        {
                            if (!(o is ObjNPC))
                            {
                                continue;
                            }

                            var obj = o as ObjNPC;

                            if (!obj.Active)
                            {
                                continue;
                            }

                            if (obj.CurrentState != BehaviorState.Idle)
                            {
                                continue;
                            }

                            if (obj.GetObjType() != ObjType.NPC)
                            {
                                continue;
                            }

                            if (!obj.IsVisibleTo(enemy))
                            {
                                continue;
                            }

                            if (obj.tbSceneNpc == null || npc.tbSceneNpc == null)
                            {
                                continue;
                            }

                            if (obj.tbSceneNpc.ChouHenGroupId != npc.tbSceneNpc.ChouHenGroupId)
                            {
                                continue;
                            }

                            if (obj.mCamp != npc.mCamp)
                            {
                                continue;
                            }

                            if ((obj.GetPosition() - enemy.GetPosition()).LengthSquared() > distSqr)
                            {
                                continue;
                            }

                            obj.EnterState(BehaviorState.Combat);
                            obj.PushHatre(enemy, 1);
                            obj.AddEnemy(enemy.ObjId);
                            enemy.AddEnemy(obj.ObjId);
                        }
                        catch
                        {
                        }
                    }
                }
            }
            catch { }
        }
Beispiel #17
0
        private ObjCharacter GetCanAttack(ObjNPC npc)
        {
            if (mLastEnemy != null && mLastEnemy.Active && !mLastEnemy.IsDead() && npc.Zone.ObjDict.ContainsKey(mLastEnemy.ObjId))
            {
                return(mLastEnemy);
            }

            if (MyTargetObjList.Count == 0)
            {
                foreach (var pair in npc.Scene.mObjDict)
                {
                    if (!pair.Value.IsCharacter())
                    {
                        continue;
                    }
                    var t = pair.Value as ObjCharacter;

                    if (t.IsDead() || !t.Active)
                    {
                        continue;
                    }
                    if (!mAddList.Contains(t.TypeId))
                    {
                        continue;
                    }
                    MyTargetObjList.Add(t.ObjId);
                }
            }


            var e = npc.Zone.EnumAllVisiblePlayer();

            foreach (var objPlayer in e)
            {
                if (!MyTargetObjList.Contains(objPlayer.ObjId))
                {
                    MyTargetObjList.Add(objPlayer.ObjId);
                }
            }

            ObjCharacter temp   = null;
            var          maxDis = 9999999.0f;

            for (int i = 0; i < MyTargetObjList.Count;)
            {
                var objId  = MyTargetObjList[i];
                var target = npc.Scene.FindObj(objId);
                if (null == target)
                {
                    MyTargetObjList.RemoveAt(i);
                    continue;
                }
                var enemy = target as ObjCharacter;
                if (enemy.IsDead() || !enemy.Active)
                {
                    MyTargetObjList.RemoveAt(i);
                    continue;
                }
                var dis = (npc.GetPosition() - enemy.GetPosition()).LengthSquared();
                if (dis < maxDis)
                {
                    temp   = enemy;
                    maxDis = dis;
                }

                i++;
            }

            mLastEnemy = temp;

            return(temp ?? mLastEnemy);
        }
        public override void OnTickCombat(ObjNPC npc, float delta)
        {
            ObjCharacter enemy = null;

            //判断敌人是否存在
            if (npc.TableAI == null)
            {
                enemy = npc.GetMaxHatre();
            }
            else
            {
                enemy = GetAttackTarget(npc);
            }

            //判断敌人是否存在

            if (null == enemy)
            {
                npc.EnterState(BehaviorState.GoHome);
                return;
            }

            //判断敌人是否有效
            if (enemy.IsDead() || !enemy.Active)
            {
                npc.EnterState(BehaviorState.GoHome);
                return;
            }

            //判断是否太远了
            var dis = (npc.GetPosition() - mBackPosition).Length();

            if (npc.TableNpc.MaxCombatDistance > 0 && dis >= npc.TableNpc.MaxCombatDistance)
            {
                npc.EnterState(BehaviorState.GoHome);
                return;
            }

            //如果有普通
            if (null != mTableNormalSkill)
            {
                //跟着敌人打
                if ((npc.GetPosition() - enemy.GetPosition()).Length() <= mSkillDistance)
                {
                    npc.TurnFaceTo(enemy.GetPosition());
                    if (npc.IsMoving())
                    {
                        GenNextNormalAttackTime(100);
                        npc.StopMove();
                    }
                    if (DateTime.Now >= mNextNormalAttackTime)
                    {
                        npc.Seperate(enemy, mSkillDistance);
                        var skillId = npc.NormalSkillId;
                        npc.UseSkill(ref skillId, enemy);
                        GenNextNormalAttackTime();
                        mNoMoveTime = 0; //攻击了一次就把自己站在原地的累计时间清空
                    }
                }
                else
                {
                    var targetPos = enemy.GetPosition();
                    if (MoveResult.CannotReach == npc.MoveTo(targetPos, mSkillDistance - 0.5f))
                    {
                        //如果长时间无法到达目的地说明卡怪了, 就回去
                        mNoMoveTime += delta;
                        if (mNoMoveTime >= MAX_NO_MOVE_TIME)
                        {
                            npc.EnterState(BehaviorState.GoHome);
                        }
                    }
                    else
                    {
                        mNoMoveTime = 0;
                    }
                }
            }
        }
 private static void IsHaveBuff(ObjNPC npc)
 {
 }
Beispiel #20
0
 //心跳普通
 public override void OnTickIdle(ObjNPC npc, float delta)
 {
     npc.EnterState(BehaviorState.Combat);
 }
Beispiel #21
0
 public override void OnExitCombat(ObjNPC npc)
 {
     npc.RemoveMeFromOtherEnemyList();
     npc.ClearEnemy();
     npc.CleanHatre();
 }
Beispiel #22
0
 //战斗
 public override void OnEnterCombat(ObjNPC npc)
 {
 }
Beispiel #23
0
 public override void OnExitGoHome(ObjNPC npc)
 {
 }
Beispiel #24
0
 //死亡
 public override void OnEnterDie(ObjNPC npc)
 {
 }
Beispiel #25
0
        public override void OnTickCombat(ObjNPC npc, float delta)
        {
            var retinue = npc as ObjRetinue;

            if (retinue == null)
            {
                return;
            }
            if (retinue.Owner == null || retinue.Owner.Scene == null)
            {
                retinue.Scene.LeaveScene(retinue);
                return;
            }
            var myPos    = retinue.GetPosition();
            var ownerPos = retinue.Owner.GetPosition();

            if (mNextNormalAttackTime > DateTime.Now)
            {
                return;
            }
            var distance = (myPos - ownerPos).LengthSquared();

            //if (distance > 400)
            //{
            //    var diff = GetRandomPostion();
            //    diff += ownerPos;
            //    npc.SetCheckPostion(diff);
            //    //retinue.MoveTo(ownerPos, 2);
            //    npc.EnterState(BehaviorState.GoHome);
            //    return;
            //}
            if (distance > 64)
            {
                retinue.MoveTo(ownerPos, 2);
                return;
                //var p = myPos + Vector2.Normalize(ownerPos - myPos) * 2;
                //retinue.MoveTo(p);
            }
            var tag = retinue.Owner.Scene.GetObstacleValue(ownerPos.X, ownerPos.Y);

            if (tag == SceneObstacle.ObstacleValue.Walkable) //自身在安全区禁止攻击
            {
                return;
            }

            var enemyTarget = GetEnemyCharacter(retinue);

            if (enemyTarget == null)
            {
                npc.EnterState(BehaviorState.GoHome);
                return;
            }
            if (enemyTarget.GetObjType() == ObjType.PLAYER)
            {
                tag = enemyTarget.Scene.GetObstacleValue(ownerPos.X, ownerPos.Y);
                if (tag == SceneObstacle.ObstacleValue.Walkable) //对方在安全区禁止攻击
                {
                    return;
                }
            }

            LastTargetId = enemyTarget.ObjId;


            var WillskillId     = GetCanDoSkill(npc); //npc.NormalSkillId;
            var mTableWillskill = Table.GetSkill(WillskillId);

            if (mTableWillskill == null)
            {
                return;
            }
            mSkillDistance = SkillManager.GetSkillDistance((SkillTargetType)mTableWillskill.TargetType,
                                                           mTableWillskill.TargetParam);
            //跟着敌人打
            if ((npc.GetPosition() - enemyTarget.GetPosition()).Length() > mSkillDistance)
            {
                npc.MoveTo(enemyTarget.GetPosition(), mSkillDistance - 0.3f);
            }
            else
            {
                if (npc.IsMoving())
                {
                    npc.StopMove();
                }
                if (npc.UseSkill(ref WillskillId, enemyTarget) == ErrorCodes.OK)
                {
                    //int cd = mTableNormalSkill.Cd;
                    //if (cd < mTableNormalSkill.CommonCd)
                    //{
                    //    cd = mTableNormalSkill.CommonCd;
                    //}
                    //int milliseconds = cd <= 0 ? DEFAULT_NORMAL_ATTACK_INTERVAL_MILLISECONDS : cd;
                    //mNextNormalAttackTime = DateTime.Now + TimeSpan.FromMilliseconds(milliseconds);
                    PushSkillCd(npc, WillskillId);
                }
            }
        }
Beispiel #26
0
 //回家
 public override void OnEnterGoHome(ObjNPC npc)
 {
     //base.OnEnterGoHome(npc);
     //npc.MoveTo(npc.BornPosition);
 }
        public override void OnNpcDie(ObjNPC npc, ulong characterId = 0)
        {
            if (npc == null)
            {
                return;
            }

            ObjCharacter killer = null;

            if (npc.TableNpc.BelongType == 1)                       //古域战场,如果是队内伤害最高,就扣他的体力因为他会得宝物
            {
                killer = FindCharacter(npc.GetTargetCharacterId()); //古域战场Boss,是谁获得了奖励扣谁的体力
            }
            else
            {
                killer = FindCharacter(characterId); //古域战场小怪,是谁获得了奖励扣谁的体力
            }
            if (killer == null)
            {
                return;
            }

            base.OnNpcDie(npc, characterId);
            var tbNpc = Table.GetNpcBase(npc.TypeId);

            if (tbNpc != null)
            {
                var player = killer as ObjPlayer;
                if (null != player)
                {
                    PetIslandReduceTili(player.ObjId, tbNpc.KillExpendType, tbNpc.KillExpendValue);
                }
            }



            bool bSend = false;

            Table.ForeachAcientBattleField(tb =>
            {
                if (tb.CharacterBaseId == npc.TypeId)
                {
                    bSend = true;
                    return(false);
                }
                return(true);
            });
            if (bSend == true)
            {
                var idx = MapNpcRecords.FindIndex(r => r.NpcID == npc.TypeId);
                if (idx == -1)
                {
                    return;
                }
                var info = MapNpcInfo.Data[idx];
                info.Alive = false;
                var data = new MapNpcInfos();
                data.Data.Add(info);
                PushActionToAllPlayer(p =>
                {
                    if (p.Proxy == null)
                    {
                        return;
                    }
                    p.Proxy.NotifyNpcStatus(data);
                });
            }
            CoroutineFactory.NewCoroutine(GetNPCDie, (ulong)0, npc.TypeId).MoveNext();
        }
Beispiel #28
0
 public override void OnNpcDie(ObjNPC npc, ulong characterId = 0)
 {
 }
Beispiel #29
0
 public virtual void Init(ObjNPC npc)
 {
     mImpl.Init(this, npc);
 }
        public override void OnTickCombat(ObjNPC npc, float delta)
        {
            CombatTime += 500;
            if (!npc.CanSkill())
            {
                return;
            }
            //判断是否需要状态转换
            var nextAi = CheckStateChange(npc);

            ChangeAi(npc, nextAi);
            //判断敌人是否存在
            var enemy = GetAttackTarget(npc);

            if (null == enemy || enemy.IsDead() || !enemy.Active)
            {
                npc.EnterState(BehaviorState.Idle);
                npc.SetDirection(npc.BornDirection);
                npc.BroadcastDirection();
                npc.RemoveMeFromOtherEnemyList();
                npc.ClearEnemy();
                return;
            }


            var WillskillId     = GetCanDoSkill(npc); //npc.NormalSkillId;
            var mTableWillskill = Table.GetSkill(WillskillId);

            if (mTableWillskill == null)
            {
                return;
            }
            switch ((SkillTargetType)mTableWillskill.TargetType)
            {
            case SkillTargetType.SELF:
            {
                if (DateTime.Now >= mNextNormalAttackTime)
                {
                    var reCodes = npc.MustSkill(ref WillskillId, npc);     //npc.UseSkill(ref skillId, enemy);
                    if (reCodes == ErrorCodes.OK)
                    {
                        PushSkillCd(npc, WillskillId);
                    }
                    return;
                }
                mTableWillskill = Table.GetSkill(npc.TableAI.CommonSkill);
                if (mTableWillskill == null)
                {
                    return;
                }
            }
            break;

            case SkillTargetType.SINGLE:
                break;

            case SkillTargetType.CIRCLE:
                break;

            case SkillTargetType.SECTOR:
                break;

            case SkillTargetType.RECT:
                break;

            case SkillTargetType.TARGET_CIRCLE:
                break;

            case SkillTargetType.TARGET_RECT:
                break;

            case SkillTargetType.TARGET_SECTOR:
                break;

            default:
                break;
            }
            mSkillDistance = SkillManager.GetSkillDistance((SkillTargetType)mTableWillskill.TargetType,
                                                           mTableWillskill.TargetParam);
            //跟着敌人打
            if ((npc.GetPosition() - enemy.GetPosition()).Length() > mSkillDistance)
            {
                npc.SetDirection(npc.BornDirection);
                npc.BroadcastDirection();
            }
            else
            {
                npc.TurnFaceTo(enemy.GetPosition());

                if (DateTime.Now >= mNextNormalAttackTime)
                {
                    var reCodes = npc.MustSkill(ref WillskillId, enemy); //npc.UseSkill(ref skillId, enemy);
                    if (reCodes == ErrorCodes.OK)
                    {
                        PushSkillCd(npc, WillskillId);
                    }
                }
            }
        }