Exemplo n.º 1
0
        public MonsterObject(uint _id,int nAi_Id,short x,short y,bool isCreateTypeId = true)
        {
            mTarget = null;
            id = _id;
            type = OBJECTTYPE.MONSTER;
            attr = new GameStruct.MonterAttribute();
            mRebirthTime = 1000; //默认复活时间
            if (isCreateTypeId)
            {
                typeid = IDManager.CreateTypeId(type);
            }
            mInitPoint = new GameStruct.Point();
            mInitPoint.x = x;
            mInitPoint.y = y;
            m_Ai = CreateAi(nAi_Id);

            mnDieMagicTick = System.Environment.TickCount;
            mDieMagicInfo = null;
            attr.life = attr.life_max = 0;
            mAliveTime = new GameBase.Core.TimeOut();
            mAliveTime.SetInterval(mRebirthTime);

            this.SetPoint(x, y);
               // ai = new AI.BaseAI(this);
            Alive();
        }
Exemplo n.º 2
0
 public PlayerFight(PlayerObject _play)
 {
     play = _play;
     mAutoTarget = null;
     mnAutoAttackTick = System.Environment.TickCount;
     mnLastAttackTick = System.Environment.TickCount;
     mnYanHunQiangIndex = mnYanHunQiangExIndex = 0;
     mListQiShiTuanGuard = null;
     mLiuXingYunHuoTime = null;
 }
Exemplo n.º 3
0
        public void AddObject(BaseObject obj, GameBase.Network.GameSession session = null)
        {
            mListAddObj.Add(obj);

              //  mDicObject[obj.GetGameID()] = obj;
            obj.mGameMap = this;
            obj.session = session;
            if (obj.type == OBJECTTYPE.PLAYER)
            {
                last_null_tick = System.Environment.TickCount;
            }
        }
Exemplo n.º 4
0
        public DiYuXieFu(PlayerObject _play, BaseObject _AttackTarget, short x, short y, byte dir, uint _id, int nAi_Id)
            : base(_id, nAi_Id,x,y, false)
        {
            type = GameBase.Config.OBJECTTYPE.CALLOBJECT;

            typeid = IDManager.CreateTypeId(GameBase.Config.OBJECTTYPE.GUARDKNIGHT);
            SetPoint(x, y);
            mRebirthTime = 0;//不允许复活
            mPlay = _play;
            SetDir(dir);
            this.GetAi().SetAttackTarget(_AttackTarget);
        }
Exemplo n.º 5
0
 //添加可视对象
 //
 public void AddVisibleObject(BaseObject obj,bool bRefreshTag = true)
 {
     RefreshObject refobj = null;
     if (this.GetVisibleList().ContainsKey(obj.GetGameID()))
     {
         refobj = mVisibleList[obj.GetGameID()];
         refobj.bRefreshTag = bRefreshTag;
         return;
     }
     refobj = new RefreshObject();
     refobj.bRefreshTag = bRefreshTag;
     refobj.obj = obj;
     mVisibleList[obj.GetGameID()] = refobj;
 }
Exemplo n.º 6
0
        public ShenYuanELing(PlayerObject _play,BaseObject _AttackTarget, short x, short y, byte dir, uint _id, int nAi_Id)
            : base(_id, nAi_Id,x,y, false)
        {
            type = OBJECTTYPE.CALLOBJECT;
            mPlay = _play;
            //1.5倍的血量
            this.attr.life = this.attr.life_max =  (int)(mPlay.GetBaseAttr().life * 1.5f);

            typeid = IDManager.CreateTypeId(OBJECTTYPE.GUARDKNIGHT);
            SetPoint(x, y);
            mRebirthTime = 0;//不允许复活

            SetDir(dir);
            this.GetAi().SetAttackTarget(_AttackTarget);
        }
Exemplo n.º 7
0
 public override bool CanPK(BaseObject obj, bool bGoCrime = true)
 {
     bool ret = base.CanPK(obj);
     if (ret)
     {
         //不攻击主人
         if (obj.type == OBJECTTYPE.PLAYER)
         {
             if (obj.GetTypeId() == mPlay.GetTypeId())
             {
                 return false;
             }
         }
     }
     return ret;
     // return base.CheckIsAttack(obj);
 }
Exemplo n.º 8
0
        public override void Injured(BaseObject obj, uint value, NetMsg.MsgAttackInfo info)
        {
            mbIsCombo = play.GetFightSystem().IsComboMagic(info.usType);
            this.GetAttr().life -= (int)value;
            if (this.GetAttr().life < 0)
            {
                this.GetAttr().life = 0;

            }
            if (!mbIsCombo && this.GetAttr().life <= 0)
            {
                GameStruct.Action action = new GameStruct.Action(GameStruct.Action.DIE, null);
                this.PushAction(action);

            }

            NetMsg.MsgEudemonInfo msg = new NetMsg.MsgEudemonInfo();
            msg.id = this.GetTypeId();
            msg.AddAttribute(EudemonAttribute.Life, this.GetAttr().life);
            this.BrocatBuffer(msg.GetBuffer());
        }
Exemplo n.º 9
0
 //广播移动消息
 //public void BroadcastMove(BaseObject obj,byte[] data)
 //{
 //    foreach (BaseObject o in obj.mVisibleList.Values)
 //    {
 //        if (o.type == OBJECTTYPE.PLAYER)
 //        {
 //            PlayerObject po = o as PlayerObject;
 //            o.SendData(data);
 //       }
 //   }
 //}
 //广播消息
 public void BroadcastBuffer(BaseObject obj, byte[] buff)
 {
     //  obj.RefreshVisibleObject();
     foreach (RefreshObject o in obj.GetVisibleList().Values)
     {
         BaseObject _obj = o.obj;
         if (_obj.type == OBJECTTYPE.PLAYER && _obj.GetGameSession() != null)
         {
             NetMsg.BaseMsg basemsg = new NetMsg.BaseMsg();
             basemsg.Create(buff, _obj.GetGamePackKeyEx());
             _obj.SendData(basemsg.GetBuffer());
         }
     }
 }
Exemplo n.º 10
0
 public virtual void Die()
 {
     TargetObj = null;
     if(findlist != null) findlist.Clear();
 }
Exemplo n.º 11
0
 //检测是否可以攻击
 public virtual bool CanPK(BaseObject obj, bool bGoCrime = true)
 {
     return true;
 }
Exemplo n.º 12
0
 public virtual void Injured(BaseObject attackobj)
 {
     //if (TargetObj == null)
     //{
     //    TargetObj = attackobj;
     //    mnLastAttackTick = System.Environment.TickCount ;
     //}
     SetAttackTarget(attackobj);
     nState = BaseAI.INJURED;
 }
Exemplo n.º 13
0
 public virtual void SetAttackTarget(BaseObject obj)
 {
     if (obj != null && !SelObj.CanPK(obj))
     {
         //对象不可攻击
         TargetObj = null;
         nState = BaseAI.STATE_IDLE;
         return;
     }
     TargetObj = obj;
     if (TargetObj == null)
     {
         nState = BaseAI.STATE_IDLE;
     }
     else
     {
         nState = BaseAI.ATTACK;
     }
     //mnLastAttackTick = System.Environment.TickCount;
     //mnLastMoveTick = mnLastAttackTick;
     if (findlist != null) findlist.Clear();
 }
Exemplo n.º 14
0
        //自动普通攻击
        private void AutoAttack()
        {
            //清除自动攻击对象
            if (mAutoTarget != null)
            {
                if (mAutoTarget.IsDie()) mAutoTarget = null;
            }
            if (play.IsDie() || play.IsLock()) return;
            if (mAutoTarget != null && !mAutoTarget.IsLock())
            {
                if (System.Environment.TickCount - mnAutoAttackTick > 1500/*1.5秒攻击一次*/)
                {

                    NetMsg.MsgAttackInfo info = new NetMsg.MsgAttackInfo();
                    //触发被动技能
                    if (PassiveMagic(info))
                    {
                        return;
                    }
                    info.idTarget = mAutoTarget.GetTypeId();
                    Attack(info);
                    mnAutoAttackTick = System.Environment.TickCount;
                }

            }
        }
Exemplo n.º 15
0
        //连击技能
        private void ComboMagic(NetMsg.MsgAttackInfo info, BaseObject target)
        {
            byte[] msg = null;
            ushort magiclv = play.GetMagicSystem().GetMagicLevel(info.skillid);
            GameStruct.MagicTypeInfo baseinfo = ConfigManager.Instance().GetMagicTypeInfo(info.usType);

            //施法动作
            NetMsg.MsgMonsterMagicInjuredInfo magicinfo = new NetMsg.MsgMonsterMagicInjuredInfo();
            magicinfo.roleid = play.GetTypeId();
            magicinfo.role_x = play.GetCurrentX();
            magicinfo.role_y = play.GetCurrentY();
            magicinfo.injuredvalue = 0;
            magicinfo.monsterid = play.GetTypeId();
            magicinfo.tag = 21;
            magicinfo.magicid = (ushort)info.usType;
            magicinfo.magiclv = magiclv;
            msg = magicinfo.GetBuffer();
            play.BroadcastBuffer(msg);
            //play.GetGameMap().BroadcastBuffer(play, msg);
            int _locktime = ConfigManager.Instance().GetTrackTime(baseinfo.track_id);
            int _target_locktime = ConfigManager.Instance().GetTrackTime(baseinfo.track_id2);

            int trackcount = ConfigManager.Instance().GetTrackNumber(baseinfo.track_id);
            //锁定自己与目标
            play.Lock(_locktime);
            target.Lock(_target_locktime, target.type == OBJECTTYPE.PLAYER);
            //计算伤害值
             NetMsg.MsgMagicAttackInfo magicattack ;
            for (int i = 0; i < trackcount; i++)
            {
                ////如果是影轮回,就有几率穿透伤害
                //magicattack = new NetMsg.MsgMagicAttackInfo();
                //magicattack.id = play.GetTypeId();

                //magicattack.value = 0;
                //magicattack.magicid = (ushort)GameStruct.MagicTypeInfo.ZHENSHIDAJI;
                //magicattack.level = magiclv;
                //magicattack.targetid = target.GetTypeId();
                //msg = magicattack.GetBuffer();
                //play.BroadcastBuffer(msg, true);
               // target.Injured(play, injured, info);

                //优先攻击合体的幻兽
                uint target_id = target.GetTypeId();
                if (target.type == OBJECTTYPE.PLAYER)
                {
                    EudemonObject eudemon_obj = (target as PlayerObject).GetEudemonSystem().GetInjuredEudemon();
                    if (eudemon_obj != null)
                    {
                        target_id = eudemon_obj.GetTypeId();
                    }
                }

                magicattack = new NetMsg.MsgMagicAttackInfo();
                magicattack.id = play.GetTypeId();
                uint injured = BattleSystem.AdjustDamage(play, target);
                magicattack.value = injured;
                magicattack.magicid = (ushort)info.usType;
                magicattack.level = magiclv;
                magicattack.targetid = target_id;
                msg = magicattack.GetBuffer();
                play.BroadcastBuffer(msg, true);
                target.Injured(play, injured, info);
            }

            if (baseinfo.track_id > 0)
            {
                //取得攻击方向
                byte attackdir = GameStruct.DIR.GetDirByPos(play.GetCurrentX(), play.GetCurrentY(), target.GetCurrentX(), target.GetCurrentY());
                play.SetDir(attackdir);
                target.SetDir(attackdir);

                NetMsg.MsgCombo combo = new NetMsg.MsgCombo();
                combo.CalcTag(info.usType, play, target);
                short x = 0;
                short y = 0;
                GameStruct.TrackInfo trackinfo = ConfigManager.Instance().GetTrackInfo(baseinfo.track_id);
                GameStruct.TrackInfo track2 = ConfigManager.Instance().GetTrackInfo(baseinfo.track_id2);
                for (int i = 0; i < trackcount; i++)
                {
                    //怪物
                    if (track2.step > 0)
                    {
                        if (GameStruct.DIR.GetNexPoint(target, ref x, ref y)) { target.SetPoint(x, y); }
                    }
                    //角色
                    if (trackinfo.step > 0)
                    {
                        for (int j = 0; j < trackinfo.step;j++ )
                        {
                            if (GameStruct.DIR.GetNexPoint(play, ref x, ref y)) { play.SetPoint(x, y); }
                        }

                    }

                    combo.AddComboInfo(info.usType, play, target, trackinfo.action, track2.action);

                    trackinfo = ConfigManager.Instance().GetTrackInfo(trackinfo.id_next);
                    if (track2.id_next != 0)
                    {
                        track2 = ConfigManager.Instance().GetTrackInfo(track2.id_next);
                    }
                }
                msg = combo.GetBuffer();
                play.BroadcastBuffer(msg, true);

            }
        }
Exemplo n.º 16
0
        //死亡
        //target 击杀者 this 被击杀者
        public void Die(BaseObject target)
        {
            ushort nAddPk = 0; //击杀者需要增加pk值
            int nMinDropItem = 0; //最小掉落道具概率,百分比
            int nMaxDropItem = 0;   //最大掉落装备概率,百分比
            int nMinGold = 0;       //最小掉落金钱概率
            int nMaxGold = 0;           //最大掉落金钱概率
            int nExp = 0;           //减少的经验百分比
            switch (mnNameType)
            {
                case Define.PK_NAME_WHITE:
                    {
                        nAddPk = 20;
                        nMinDropItem = 10; //百分之十
                        nMaxDropItem = 50;//百分之五十
                        nMinGold = 10;
                        nMaxGold = 50;
                        nExp = 1; //百分之一
                        break;
                    }
                case Define.PK_NAME_RED:
                    {
                        nAddPk = 10;
                        nMinDropItem = 50; //百分之五十
                        nMaxDropItem = 100; //百分之一百
                        nMinGold = 50;
                        nMaxGold = 100;
                        nExp = 20;
                        break;
                    }
                case Define.PK_NAME_BLACK:
                    {
                        nMinDropItem = 100;
                        nMaxDropItem = 100;
                        nMinGold = 100;
                        nMaxGold = 100;
                        nExp = 30;
                        nAddPk = 0; //如果自身是黑名,击杀者无罪
                        break;
                    }
            }
            //自身是蓝名,击杀者无罪
            if (IsPKing()) { nAddPk = 0; }
            int nDropItem = IRandom.Random(nMinDropItem, nMaxDropItem);
            int nDropGold = IRandom.Random(nMinGold, nMaxGold);

            int nItemCount = (int)((float)play.GetItemSystem().GetBagCount() * ((float)nDropItem / 100f)); //掉落的道具数量
            if (nItemCount > 0)
            {
                while (nItemCount > 0)
                {
                    int nIndex = IRandom.Random(0, nItemCount);
                    int nAddIndex = 0;
                    foreach (GameStruct.RoleItemInfo itemobj in play.GetItemSystem().GetDicItem().Values)
                    {
                        if (itemobj.postion == NetMsg.MsgItemInfo.ITEMPOSITION_BACKPACK)
                        {
                            if (nAddIndex == nIndex)
                            {
                                play.GetItemSystem().DropItemBag(itemobj.id);
                                break;
                            }
                            nAddIndex++;
                        }
                    }
                    nItemCount--;
                }
            }
            //掉落金钱
            int nGoldCount = (int)((float)play.GetBaseAttr().gold * ((float)nDropGold / 100));
            if (nGoldCount > 0)
            {
                play.GetItemSystem().DropGold(nGoldCount);
            }
            //减少经验
            long nDecExp = play.GetBaseAttr().exp * (nExp / 100);
            if (nDecExp > 0)
            {
                play.ChangeAttribute(UserAttribute.EXP, (int)-nDecExp);
            }

            if (nAddPk > 0 && target.type == OBJECTTYPE.PLAYER)
            {
                (target as PlayerObject).ChangeAttribute(GameStruct.UserAttribute.PK, nAddPk);
            }

            //清除pk状态
            this.SetPKIng(false);

            //如果死亡时是黑名- 进监狱 并且身上穿戴装备随机掉一件-百分之百哦 2015.11.15
            if (mnNameType == Define.PK_NAME_BLACK)
            {
                int nIndex = 0;
                while(true)
                {
                    byte rand = IRandom.Random(NetMsg.MsgItemInfo.ITEMPOSITION_ARMOR, NetMsg.MsgItemInfo.ITEMPOSITION_SHOES);
                    if (rand == NetMsg.MsgItemInfo.ITEMPOSITION_WEAPONL) continue; //游戏里并没有左武器
                    GameStruct.RoleItemInfo role_item_info = play.GetItemSystem().GetEquipByPostion(rand);
                    if (role_item_info != null)
                    {
                        play.GetItemSystem().DropItemEquip(role_item_info.id);
                        break;
                    }
                    nIndex ++;
                    if (nIndex >= 8)
                    {
                        break;
                    }
                }
                play.ChangeMap(Define.PK_PRISON_MAPID, Define.PRISON_MAP_X, Define.PRISON_MAP_Y);
            }
        }
Exemplo n.º 17
0
 //设置自动攻击对象
 public void SetAutoAttackTarget(BaseObject obj)
 {
     mAutoTarget = obj;
     mnAutoAttackTick = System.Environment.TickCount;
 }
Exemplo n.º 18
0
 public void Reset()
 {
     bRefreshTag = false;
     obj = null;
 }
Exemplo n.º 19
0
        public const byte EXPLODE_ITEM_CHANCE4 = 3; //大爆

        #endregion Fields

        #region Methods

        //计算伤害
        public static uint AdjustDamage(BaseObject attack, BaseObject def,bool isMagicAck = false/*是否是魔法伤害*/)
        {
            //玩家与玩家伤害计算用战斗力表示
            if (attack.type == OBJECTTYPE.PLAYER && def.type == OBJECTTYPE.PLAYER)
            {
                return AdjustDamage(attack as PlayerObject, def as PlayerObject, isMagicAck);
            }
            int nMaxRand = 50 + attack.GetLuck();
            int nAtk = 0;
            if (IRandom.Random(0, 100) < nMaxRand)
            {
                //魔法攻击只适用于法师
                if (isMagicAck &&
                    attack.type == OBJECTTYPE.PLAYER &&
                    (attack as PlayerObject).GetBaseAttr().profession == JOB.MAGE)
                {
                    nAtk = attack.GetMagicAck() +
                IRandom.Random(0, attack.GetMaxMagixAck() - attack.GetMagicAck()) ;
                }
                else
                {
                    nAtk = attack.GetMaxAck() +
                 IRandom.Random(0, attack.GetMaxAck() - attack.GetMinAck()) ;
                }

            }
            else
            {
                if (isMagicAck &&
                     attack.type == OBJECTTYPE.PLAYER &&
                     (attack as PlayerObject).GetBaseAttr().profession == JOB.MAGE)
                {
                    nAtk = attack.GetMagicAck() + IRandom.Random(0, attack.GetMaxMagixAck() - attack.GetMagicAck());
                }
                else
                {
                    nAtk = attack.GetMinAck() + IRandom.Random(0, attack.GetMaxAck() - attack.GetMinAck()) ;
                }

            }

            int nDef = 0;
            if (isMagicAck)
            {
               nDef = def.GetMagicDefense();
            }
            else
            {
               nDef = def.GetDefense();
            }
            int nDamage = nAtk - nDef;

            if (attack.type == OBJECTTYPE.PLAYER)
            {
                nDamage += attack.GetLevel() / 10;
            }

            if (nDamage <= 0)
            {
                nDamage = IRandom.Random(1, 100) >= 50  ? 1 : 0;
                if (!isMagicAck) nDamage = 1;
             }

            return (uint)nDamage;
        }
Exemplo n.º 20
0
 public virtual void Injured(BaseObject obj, uint value, NetMsg.MsgAttackInfo info)
 {
 }
Exemplo n.º 21
0
        public bool Eudemon_Injured(BaseObject obj, uint value, NetMsg.MsgAttackInfo info)
        {
            int i = mBattleObj.Count;
            bool bRet = false;
            //从上到下是因为最上面的是最外面的合体幻兽
            while (i > 0)
            {
                i--;
                EudemonObject eudemon_obj = mBattleObj[i];
                if (eudemon_obj.GetState() == EUDEMONSTATE.FIT)
                {

                    eudemon_obj.Injured(obj, value, info);
                    bRet = true;
                    break;
                }

            }
            return bRet;
        }
Exemplo n.º 22
0
        //如果可以pk该对象返回true
        //OBJ 被PK的对象
        //bCrime 是否立即闪蓝[用于范围技能]
        public override bool CanPK(BaseObject obj, bool bGoCrime = true)
        {
            bool bCrime = true; //犯罪标识
            PlayerObject _play = null;
            if (obj.type == OBJECTTYPE.EUDEMON)
            {
                _play = (obj as EudemonObject).GetOwnerPlay();

            }
            if (obj.type == OBJECTTYPE.PLAYER)
            {
                _play = (obj as PlayerObject);
            }
            if (_play == null) return true;
            byte pkmode = this.GetBaseAttr().pk_mode;
            bool bCanPk = false;
            if (pkmode == GameBase.Config.Define.PK_MODE_FREE)
            {
                bCanPk = true;
            }
            if (pkmode == GameBase.Config.Define.PK_MODE_SAFE) return false; //安全pk模式
            if (pkmode == GameBase.Config.Define.PK_MODE_GUARD)
            {
                if (_play.GetPKSystem().IsPKing() ||
                    _play.GetPKSystem().GetNameType() == GameBase.Config.Define.PK_NAME_BLACK)//蓝名 or 黑名
                {
                    bCanPk = true;
                    bCrime = false;
                }
            }
            //对方已隐身
            if (_play.GetTimerSystem().QueryStatus(GameStruct.RoleStatus.STATUS_HIDDEN) != null)
            {
                bCanPk = false;
            }

            //闪蓝-PK犯罪状态
            if (bCanPk && bGoCrime == true)
            {
                this.GetPKSystem().SetPKIng(true, bCrime);
            }
            return bCanPk;
        }
Exemplo n.º 23
0
 public virtual void Init(BaseObject obj = null, int nAi_Id = Define.AI_TYPE_MELEE)
 {
     TargetObj = null;
     SelObj = obj;
     nState = STATE_IDLE;
     mnLastAttackTick = System.Environment.TickCount;
     mnLastMoveTick = mnLastAttackTick;
     findlist = null;
     mAiInfo = ConfigManager.Instance().GetAIInfo(nAi_Id);
     mnActiveAttackTick = System.Environment.TickCount;
 }
Exemplo n.º 24
0
        public void SendMoveInfo(BaseObject obj, byte runValue)
        {
            //if (obj.type != OBJECTTYPE.PLAYER) return;
            //PlayerObject play = obj as PlayerObject;
            //if (obj.GetGameSession() == null) return; //已经断线
            //if (!play.GetPlayObjectList().ContainsKey(this.GetGameID()) ||
            //    !this.GetPlayObjectList().ContainsKey(play.GetGameID()))
            //{
            //    this.SendPlayRefreshInfo(play);
            //    play.GetPlayObjectList()[this.GetGameID()] = this;
            //    this.GetPlayObjectList()[play.GetGameID()] = play;
            //  //  Log.Instance().WriteLog("发送刷新幻兽信息!!");
            //    return;
            //}

            //存在可视列表就发移动消息
            NetMsg.MsgMoveInfo move = new NetMsg.MsgMoveInfo();
            move.Create(null, obj.GetGamePackKeyEx());
            move.id = this.GetTypeId();
            move.x = this.GetCurrentX();
            move.y = this.GetCurrentY();
            move.dir = this.GetDir();
            move.ucMode = runValue;
            obj.SendData(move.GetBuffer());
        }
Exemplo n.º 25
0
        public virtual void Run()
        {
            if (SelObj.IsDie()) return; //自身实体已死亡
            if (SelObj.IsLock())  //自身被锁定
            {
                if (findlist != null)
                    findlist.Clear();
                return;
            }
            //攻击的对方被锁定,攻击不了
            if (TargetObj != null && TargetObj.IsLock()) return;
            //目标已死亡切换目标
            if (TargetObj != null && TargetObj.IsDie())
            {
                SetAttackTarget(null);
            }
            //目标是幻兽- 并且在休息状态
            if(TargetObj != null && TargetObj.type == OBJECTTYPE.EUDEMON &&
                (TargetObj as EudemonObject).GetState() != EUDEMONSTATE.BATTLE)
            {
                SetAttackTarget(null);
            }
            //空闲状态走路
            if (nState == BaseAI.STATE_IDLE && mAiInfo.bIdle_Move)
            {
                if (System.Environment.TickCount - SelObj.GetLastWalkTime() > SelObj.GetWalkTime() && !SelObj.IsDie())
                {
                    //二分之一的几率不走路
                    if (IRandom.Random(1, 4) > 2)
                    {
                        //增加判断- 优化服务端运行效率- 视野里有玩家才走
                        bool bWalk = false;
                        foreach (RefreshObject obj in SelObj.GetVisibleList().Values)
                        {
                            if (obj.obj.type == OBJECTTYPE.PLAYER)
                            {
                                bWalk = true;
                                break;
                            }
                        }
                        if (bWalk)
                        {
                            byte dir = 0; short x = 0; short y = 0;
                            if (DIR.Random_Walk(SelObj, ref dir, ref x, ref y))
                            {
                                SelObj.Walk(dir, x, y);
                            }
                        }

                    }
                }
            }
            //玩家意外掉线
            if (TargetObj != null && TargetObj.type == OBJECTTYPE.PLAYER &&
                TargetObj.GetGameSession() == null)
            {
                SetAttackTarget(null);

            }
            //主动怪物- 遍历视野范围内的玩家- 找到最近的那一个开始攻击他
            ActiveAttackPlay();

            //受伤了..反击
            if ((TargetObj != null) &&
                (nState == BaseAI.INJURED || nState == BaseAI.ATTACK ||
                nState == BaseAI.FOLLOW))
            {
                if (!SelObj.CanPK(TargetObj))
                {
                    SetAttackTarget(null);
                    return;
                }
                //目标角色死亡了或者已经不在可视范围内
                if (TargetObj.IsDie() || !SelObj.GetPoint().CheckVisualDistance(TargetObj.GetCurrentX(),
                    TargetObj.GetCurrentY(),mAiInfo.nRange))
                {
                    TargetObj = null;
                    nState = BaseAI.STATE_IDLE;
                    if (findlist != null) findlist.Clear();
                }

                if (TargetObj != null &&
                    System.Environment.TickCount - mnLastMoveTick > mAiInfo.nMove_Speed &&
                    mAiInfo.bMove)
                {
                    //与目标差距太大-- 就跟随
                    if (Math.Abs(TargetObj.GetCurrentX() - SelObj.GetCurrentX()) > mAiInfo.nAttack_Range ||
                        Math.Abs(TargetObj.GetCurrentY() - SelObj.GetCurrentY()) > mAiInfo.nAttack_Range)
                    {
                        if (findlist != null && findlist.Count > 0)
                        {
                            MapServer.FindPoint point = findlist[findlist.Count - 1];
                            findlist.RemoveAt(findlist.Count - 1);
                            if (point.x == SelObj.GetCurrentX() && point.y == SelObj.GetCurrentY()) return;
                            byte dir = DIR.GetDirByPos(SelObj.GetCurrentX(), SelObj.GetCurrentY(), point.x, point.y);
                         //   Console.WriteLine("当前怪物坐标:"+SelObj.GetCurrentX().ToString()+"y:"+SelObj.GetCurrentY().ToString() + "目的坐标:"+point.x.ToString() + "y:" + point.y.ToString() + "方向:" + dir.ToString()+"\n");
                            if (findlist.Count == 0)
                            {
                                nState = BaseAI.ATTACK;

                            //    Console.Write("------------------------------------------------------------\n");
                            }
                            SelObj.Walk(dir,point.x,point.y);

                        }else this.FollowTarget();

                        mnLastMoveTick = System.Environment.TickCount ;
                       // Console.WriteLine((System.Environment.TickCount - mnLastMoveTick).ToString());
                        return;
                    }

                }
                //攻击目标
                if(TargetObj != null &&
                    System.Environment.TickCount - mnLastAttackTick > mAiInfo.nAttack_Speed)
                {
                    //在攻击范围内
                    if(Math.Abs(TargetObj.GetCurrentX() - SelObj.GetCurrentX()) <= mAiInfo.nAttack_Range &&
                        Math.Abs(TargetObj.GetCurrentY() - SelObj.GetCurrentY()) <= mAiInfo.nAttack_Range)
                    {
                        NetMsg.MsgMonsterAttackInfo msg = new NetMsg.MsgMonsterAttackInfo();
                        msg.Create(null, null);
                        msg.monsterid = SelObj.GetTypeId();
                        msg.roleid = TargetObj.GetTypeId(); ;
                        msg.role_x = TargetObj.GetCurrentX();
                        msg.role_y = TargetObj.GetCurrentY();
                        msg.injuredvalue = BattleSystem.AdjustDamage(SelObj, TargetObj); ;
                        byte[] buff = msg.GetBuffer();
                        //广播
                        (SelObj as MonsterObject).BrocatBuffer(buff);
                        //GameStruct.Action act = new GameStruct.Action(GameStruct.Action.ATTACK, buff);
                        //SelObj.PushAction(act);

                        //反馈角色被攻击--减血3
                        NetMsg.MsgAttackInfo info = new NetMsg.MsgAttackInfo();
                        info.tag = 21;
                        TargetObj.Injured(SelObj, msg.injuredvalue, info);
                        mnLastAttackTick = System.Environment.TickCount;
                    }
                }

            }
        }
Exemplo n.º 26
0
 //取该坐标点是否有对象[优先判断是否有阻挡]
 public bool GetPointOfObj(BaseObject obj, short x, short y)
 {
     if (!CanMove(x, y)) return true;
     obj.RefreshVisibleObject();
     foreach (RefreshObject baseobj in obj.GetVisibleList().Values)
     {
         BaseObject _obj = baseobj.obj;
         if (_obj.GetCurrentX() == x && _obj.GetCurrentY() == y)
         {
             return true;
         }
     }
     if (mListAddObj.Count > 0)
     {
         for (int i = 0; i < mListAddObj.Count; i++)
         {
             BaseObject _obj = mListAddObj[i];
             if (_obj.GetCurrentX() == x && _obj.GetCurrentY() == y)
             {
                 return true;
             }
         }
     }
     return false;
 }
Exemplo n.º 27
0
        //主动攻击
        protected virtual void ActiveAttackPlay()
        {
            if (mAiInfo.nType != Define.MONSTER_TYPE_ACTIVE) return;//不是主动怪物-
            //寻找目标需要时间--
            if (System.Environment.TickCount - mnActiveAttackTick < Define.MONSTER_ACTIVEATTACK_TIME * 1000)
            {
                return;
            }
            mnActiveAttackTick = System.Environment.TickCount;
            GameStruct.Point point = null;
            GameStruct.Point newPoint = null;
            BaseObject newObj = null;
            if (TargetObj == null &&
                System.Environment.TickCount - mnLastMoveTick > mAiInfo.nMove_Speed &&
                SelObj.GetVisibleList().Count > 0
                )
            {
                foreach (RefreshObject refobj in SelObj.GetVisibleList().Values)
                {
                    if(refobj.obj.type != OBJECTTYPE.PLAYER && //只攻击角色与幻兽与暗黑龙骑的守护骑士
                        refobj.obj.type != OBJECTTYPE.EUDEMON &&
                        refobj.obj.type != OBJECTTYPE.GUARDKNIGHT &&
                        refobj.obj.type != OBJECTTYPE.MONSTER &&
                        refobj.obj.type != OBJECTTYPE.CALLOBJECT)
                    {
                        continue;
                    }
                    //如果是暗杀邪龙. 不攻击主人

                    if (!SelObj.CanPK(refobj.obj))
                    {
                        continue;
                    }
                    point = new GameStruct.Point();
                    point.x = (short)Math.Abs(refobj.obj.GetCurrentX() - SelObj.GetCurrentX());
                    point.y = (short)Math.Abs(refobj.obj.GetCurrentY() - SelObj.GetCurrentY());
                    if (newPoint == null)
                    {
                        newPoint = point;
                        newObj = refobj.obj;
                    }
                    if(point.x < newPoint.x &&
                        point.y < newPoint.y)
                    {
                        newPoint = point;
                        newObj = refobj.obj;
                    }
                }
                if (newObj != null)
                {
                    //设置为攻击状态
                    TargetObj = newObj;
                    nState = BaseAI.ATTACK;
                    mnLastMoveTick = System.Environment.TickCount;
                }

            }
        }
Exemplo n.º 28
0
 //删除地图对象
 public void RemoveObj(BaseObject obj)
 {
     uint id ;
     if(obj.type == OBJECTTYPE.MONSTER) id = obj.GetTypeId();
     else id =obj.GetGameID();
     if ( mDicObject.ContainsKey(id))
     {
         if (obj.type == OBJECTTYPE.PLAYER)
         {
             PlayerObject play = obj as PlayerObject;
             play.ClearThis(); //广播删除自己
         }
         if (obj.type == OBJECTTYPE.EUDEMON)
         {
             EudemonObject eudemon = obj as EudemonObject;
             eudemon.ReCall();
         }
         if (obj.type == OBJECTTYPE.PTICH)
         {
             PtichObject ptich = obj as PtichObject;
             ptich.ClearThis();
         }
         //加到临时删除列表- 下次process时处理删除
         mListDeleteObj.Add(obj);
       //  mDicObject.Remove(id);
     }
     if (this.GetObjectCount(OBJECTTYPE.PLAYER) == 0)
     {
         last_null_tick = System.Environment.TickCount;
     }
 }
Exemplo n.º 29
0
 //是否可以加入到技能伤害列表
 //obj 检测到的对象
 public bool IsAddMagicVisibleObj(BaseObject obj)
 {
     if (obj.IsDie() ||   /*已死亡*/
         obj.IsLock() || //已锁定
         (obj.type != OBJECTTYPE.PLAYER &&
         obj.type != OBJECTTYPE.MONSTER))
     {
         return false;
     }
     if (!play.CanPK(obj,false)) return false;
     return true;
 }
Exemplo n.º 30
0
        //计算爆率.. 0.不爆 1.小爆 2 ~ 5
        //2.中爆 6 ~ 9
        //3.大爆 10 ~ 15
        public static byte AdjustDrop(BaseObject attack, BaseObject Def)
        {
            byte attklv = attack.GetLevel();
            byte deflv = Def.GetLevel();

            int dislv = attklv - deflv;

            if (dislv >= 0) //攻击者高于被攻击者
            {
                if (dislv <= 5 && dislv > 3)//差距小于5级
                {
                    return IRandom.Random(0, 100) < 50 ? EXPLODE_ITEM_CHANCE3 : EXPLODE_ITEM_CHANCE1;
                }
                else if (dislv <= 9 && dislv > 6)//差距小于10级
                {
                    return IRandom.Random(0, 100) < 50 ? EXPLODE_ITEM_CHANCE2 : EXPLODE_ITEM_CHANCE1;
                }
                else //大爆 就算大爆不了,也小爆
                {
                    return IRandom.Random(0, 100) < 50 ? EXPLODE_ITEM_CHANCE4 : EXPLODE_ITEM_CHANCE2;
                }
            }
            else //攻击者低于被攻击者
            {
                if (dislv <= -5 && dislv > -3)//差距小于5级
                {
                    return IRandom.Random(0, 100) < 50 ? EXPLODE_ITEM_CHANCE3 : EXPLODE_ITEM_CHANCE2;
                }
                else if (dislv <= -9 && dislv > -6)//差距小于10级
                {
                    return IRandom.Random(0, 100) < 50 ? EXPLODE_ITEM_CHANCE2 : EXPLODE_ITEM_CHANCE1;
                }
                else //大爆 就算大爆不了,也小爆
                {
                    return IRandom.Random(0, 100) < 50 ? EXPLODE_ITEM_CHANCE4 : EXPLODE_ITEM_CHANCE2;
                }
            }
        }