Exemplo n.º 1
0
        public UnitID CreateNPC(Neptune.NPC npcInfo, Actor parent = null)
        {
            if (npcInfo == null)
            {
                GameDebug.LogError("Error in create npc, npc info is null!!!");
                return(null);
            }

            Vector3 bornPos = npcInfo.Position;

            NpcDefine npcDefine = NpcHelper.MakeNpcDefine((uint)npcInfo.ExcelId);

            if (npcDefine == null)
            {
                GameDebug.LogError("Error in create npc, npc define is null!!!");
                return(null);
            }

            // 护送任务NPC可以创建多个
            if (GetNpcByNpcId((uint)npcInfo.Id) != null && npcDefine.Function != NpcDefine.EFunction.ESCORT)
            {
                return(null);
            }

            uint uuid = GetAvailableUUId(npcInfo, npcDefine);

            DBActor dbActor = DBManager.GetInstance().GetDB <DBActor>();

            DBActor.ActorData actorData = dbActor.GetData((uint)npcDefine.ActorId);

            bornPos = RoleHelp.GetPositionInScene((uint)npcDefine.ActorId, npcInfo.Position.x, npcInfo.Position.z);
            if (npcInfo.Id >= 300)
            {
                GameDebug.LogError("npcInfo.Id is too large! " + npcInfo.Id);
            }
            xc.UnitCacheInfo initData = new xc.UnitCacheInfo(EUnitType.UNITTYPE_NPC, uuid);
            initData.ClientNpc       = npcInfo;
            initData.ClientNpcDefine = NpcHelper.MakeNpcDefine((uint)(npcInfo.ExcelId));
            initData.CacheType       = xc.UnitCacheInfo.EType.ET_Create;
            initData.PosBorn         = bornPos;
            initData.ParentActor     = parent;

            // 如果有父角色,则出生在父角色附近的一个随机位置
            if (parent != null)
            {
                Vector3 pos    = AIHelper.GetActorRangeRandomPosition(parent, 1f, 2f);
                bool    result = false;
                initData.PosBorn = InstanceHelper.ClampInWalkableRange(pos, pos, out result);
            }

            mCreatings.Add(initData.UnitID.obj_idx);

            ActorManager.Instance.PushUnitCacheData(initData);

            return(initData.UnitID);
        }
Exemplo n.º 2
0
        Utils.Timer mEndTimer;// 移动结束的Timer
        public void ReceiveWalkBegin(PkgNwarMove moves)
        {
            if (false == mIsRecvMsg)
            {
                return;
            }

            // 移动时的位置和方向
            Vector3 pos = Vector3.zero;
            Vector3 dir = Vector3.zero;

            pos.x = moves.pos.px * GlobalConst.UnitScale;
            pos.z = moves.pos.py * GlobalConst.UnitScale;

            // 如果速度为0,直接设置到目标点(移动时间太短的话也当作停止处理)
            if (moves.speed == 0 || (moves.time != 0 && moves.time <= 66))
            {
                pos = RoleHelp.GetPositionInScene(mOwner.ActorId, pos.x, pos.z);
                mOwner.SetPosition(pos);
                mOwner.MoveSpeed = 0;
                return;
            }

            dir.x = moves.speed * Mathf.Cos(moves.dir);
            dir.z = moves.speed * Mathf.Sin(moves.dir);

            MoveStep step = new MoveStep();

            step.type  = EActorStepType.AT_WALK_BEGIN;
            step.pos   = pos;
            step.dir   = dir;
            step.speed = moves.speed * GlobalConst.UnitScale;

            mCurStep = step;
            mbDirty  = true;

            // 如果移动时间不为0,则在规定的时间内自动停止
            if (moves.time != 0)
            {
                if (mEndTimer != null)
                {
                    mEndTimer.Destroy();
                }

                mEndTimer = new Utils.Timer((int)moves.time, false, moves.time, OnTimerFinish);
            }
        }
Exemplo n.º 3
0
        public void ReceiveSetPos(S2CNwarSetPos pack)
        {
            if (mOwner.MoveImplement != null)
            {
                Vector3 pos    = RoleHelp.GetPositionInScene(mOwner.ActorId, pack.move.pos.px * GlobalConst.UnitScale, pack.move.pos.py * GlobalConst.UnitScale);
                bool    result = false;
                pos = InstanceHelper.ClampInWalkableRange(pos, pos, out result);
                mOwner.MoveImplement.SetPosition(pos);
            }

            bool isWalking = mOwner.ActorMachine.IsWalking();

            mOwner.Stop();
            TryWalkAlongStop();

            // 如果当前正在寻路,则重新寻路,因为需要重新计算路径
            if (isWalking == true && mOwner.ActorMachine.DestList.size > 0)
            {
                int newWalkId = 0;
                if (mReachCallbacks != null && mReachCallbacks.ContainsKey(m_WalkId) == true)
                {
                    newWalkId = TryWalkToAlong(mOwner.ActorMachine.DestList[mOwner.ActorMachine.DestList.size - 1], mReachCallbacks[m_WalkId]);
                }
                else
                {
                    newWalkId = TryWalkToAlong(mOwner.ActorMachine.DestList[mOwner.ActorMachine.DestList.size - 1]);
                }

                // 如果当前正在任务寻路,则赋值给最新的walk id
                if (TargetPathManager.Instance.IsNavigating == true && TargetPathManager.Instance.PathWalker != null)
                {
                    TargetPathManager.Instance.PathWalker.WalkId = newWalkId;
                }
            }

            // 本地是否要激活自动战斗
            if (pack.move.id == LocalPlayerManager.Instance.LocalActorAttribute.UnitId.obj_idx)
            {
                if (SceneHelp.Instance.IsAutoFightingAfterSwitchInstance == true)
                {
                    SceneHelp.Instance.IsAutoFightingAfterSwitchInstance = false;
                    InstanceManager.Instance.IsAutoFighting = true;
                }
                mIsMoving = false;
            }
        }
Exemplo n.º 4
0
        public static UnitID CreateWorshipModelForLua(uint type_id, uint uid, uint rank, string name, string guildName, uint honor, uint title, XLua.LuaTable modIdLst, XLua.LuaTable fashions, XLua.LuaTable suit_effects, Action <Actor> cbResLoad = null)
        {
            Vector3            pos      = Vector3.zero;
            Quaternion         rotation = Quaternion.identity;
            List <Neptune.Tag> tags     = Neptune.DataHelper.GetTagListByType(Neptune.DataManager.Instance.Data, "special_pos");

            if (rank <= tags.Count)
            {
                pos      = tags[(int)(rank - 1)].Position;
                pos      = RoleHelp.GetPositionInScene(type_id, pos.x, pos.z);
                rotation = tags[(int)(rank - 1)].Rotation;
            }

            xc.UnitCacheInfo info = new xc.UnitCacheInfo(EUnitType.UNITTYPE_PLAYER, GetAvailableUUId());
            info.AOIPlayer.model_id_list = XLua.XUtils.CreateListByLuaTable <uint, uint>(modIdLst);
            info.AOIPlayer.fashions      = XLua.XUtils.CreateListByLuaTable <uint, uint>(fashions);
            info.AOIPlayer.suit_effects  = XLua.XUtils.CreateListByLuaTable <uint, uint>(suit_effects);
            info.AOIPlayer.type_idx      = type_id;
            info.PosBorn  = pos;
            info.Rotation = rotation;

            info.AOIPlayer.model_id_list.AddRange(info.AOIPlayer.fashions);

            ActorHelper.GetModelFashionList(info.AOIPlayer.model_id_list, info.AOIPlayer.model_id_list, info.AOIPlayer.fashions);

            var model = ActorManager.Instance.CreateActor <WorshipModel>(info, info.Rotation, null, true, cbResLoad);

            model.RawUID           = uid;
            model.Rank             = rank;
            model.UserName         = name;
            model.GuildName        = guildName;
            model.mActorAttr.Honor = honor;
            model.mActorAttr.Title = title;

            WorshipModelHeadBehavior worshipModelHeadBehavior = model.GetBehavior <WorshipModelHeadBehavior>();

            worshipModelHeadBehavior.ResetHeadInfo();
            worshipModelHeadBehavior.Honor = honor;
            worshipModelHeadBehavior.Title = title;

            return(info.UnitID);
        }
Exemplo n.º 5
0
        protected virtual UnitCacheInfo CreateUnitCacheData(S2CNwarInitInfo player_info)
        {
            var born_pos  = RoleHelp.GetPositionInScene(ActorHelper.RoleIdToTypeId(player_info.brief.rid), player_info.init_pos.px * GlobalConst.UnitScale, player_info.init_pos.py * GlobalConst.UnitScale);
            var init_data = ActorHelper.CreateUnitCacheInfo(player_info.brief, born_pos);

            // 读取出生点朝向
            List <Neptune.Tag> tags = Neptune.DataHelper.GetTagListByType(Neptune.DataManager.Instance.Data, "born_pos");

            if (tags.Count > 0)
            {
                init_data.Rotation = tags[0].Rotation;
            }
            if (LocalPlayerManager.Instance.BornRotation.Equals(Quaternion.identity) == false)
            {
                init_data.Rotation = LocalPlayerManager.Instance.BornRotation;
                LocalPlayerManager.Instance.BornRotation = Quaternion.identity;
            }

            return(init_data);
        }