Exemple #1
0
    public void CreateNPCAsync(InitNPCData initData, Action <ObjNPC> callBack = null)
    {
        GameObject root = null;

        if (null != GameLogic.Instance && null != GameLogic.Instance.Scene)
        {
            root = GameLogic.Instance.Scene.NpcRoot;
        }
        CreateObjAsync(initData, Resource.PrefabPath.NPC,
                       root, callBack);
    }
Exemple #2
0
    public void CreateObj(CreateObjMsg msg)
    {
        if (ObjManager.Instance == null)
        {
            Logger.Log2Bugly("ObjManager.Instance == null");
            return;
        }
        if (PlayerDataManager.Instance == null)
        {
            Logger.Log2Bugly("PlayerDataManager.Instance == null");
            return;
        }
        {
            var __list1      = msg.Data;
            var __listCount1 = __list1.Count;
            for (var __i1 = 0; __i1 < __listCount1; ++__i1)
            {
                var data = __list1[__i1];
                {
                    if (data.ObjId == PlayerDataManager.Instance.GetGuid())
                    {
                        continue;
                    }
                    switch ((OBJ.TYPE)data.Type)
                    {
                    case OBJ.TYPE.NPC:
                    {
                        var init = new InitNPCData();
                        AssignInitCharacterData(init, data);
                        ObjManager.Instance.CreateNPCAsync(init);
                    }
                    break;

                    case OBJ.TYPE.AUTOPLAYER:
                    case OBJ.TYPE.OTHERPLAYER:
                    {
                        var init = new InitOtherPlayerData();
                        if (data.ExtData.Count > 0)
                        {
                            init.ServerId = data.ExtData[0];
                        }
                        for (var i = 0; i < data.Titles.Count; i++)
                        {
                            init.TitleList.Add(i, data.Titles[i]);
                        }
                        if (data.Owner != null && data.Owner.Items != null && data.Owner.Items.Count == 1)
                        {
                            init.RobotId = data.Owner.Items[0];
                        }
                        else
                        {
                            init.RobotId = 0ul;
                        }
                        init.AllianceName = data.AllianceName;
                        AssignInitCharacterData(init, data);
                        ObjManager.Instance.CreateOtherPlayerAsync(init);
                    }
                    break;

                    case OBJ.TYPE.RETINUE:
                    {
                        var init = new InitRetinueData();
                        AssignInitCharacterData(init, data);
                        if (data.Owner != null && data.Owner.Items != null && data.Owner.Items.Count == 1)
                        {
                            init.Owner = data.Owner.Items[0];
                        }
                        ObjManager.Instance.CreateRetinueAsync(init);
                    }
                    break;

                    case OBJ.TYPE.DROPITEM:
                    {
                        var init = new InitDropItemData();
                        AssignInitBaseData(init, data);
                        init.Owner.AddRange(data.Owner.Items);
                        init.RemianSeconds = data.ExtData[0];
                        init.PlayDrop      = 1 == data.ExtData[1] ? true : false;
                        init.TargetPos     = new Vector2(GameUtils.DividePrecision(data.TargetPos[0].x),
                                                         GameUtils.DividePrecision(data.TargetPos[0].y));

                        ObjManager.Instance.CreateDropItemAsync(init);
                    }
                    break;

                    default:
                    {
                        Logger.Fatal("Obj[{0}] is unknow type[{1}]", data.ObjId, data.Type);
                    }
                    break;
                    }
                }
            }
        }
    }
    private void RefreshModel(PlayerInfoMsg info)
    {
        if (ObjManager.Instance.ObjPool.ContainsKey((ulong)GetNpcObjId(professionIndex)))
        {
            ObjManager.Instance.RemoveObj((ulong)GetNpcObjId(professionIndex));
        }
        if (null == info)
        {
            var init       = new InitNPCData();
            var npcId      = GetNpcId(professionIndex);
            var tbSceneNpc = Table.GetSceneNpc(npcId);
            if (null == tbSceneNpc)
            {
                return;
            }
            var tbNpc = Table.GetNpcBase(tbSceneNpc.DataID);
            if (null == tbNpc)
            {
                return;
            }
            var tbCharacterBase = Table.GetCharacterBase(tbSceneNpc.DataID);
            if (null == tbCharacterBase)
            {
                return;
            }
            init.DataId = tbSceneNpc.DataID;
            init.ObjId  = (ulong)tbSceneNpc.DataID * 1000;
            init.Name   = tbNpc.Name;
            init.Level  = tbNpc.Level;
            init.HpMax  = init.HpNow = tbCharacterBase.Attr[13];
            init.MpMax  = init.MpNow = tbCharacterBase.Attr[14];
            init.DirX   = (float)Math.Cos(tbSceneNpc.FaceDirection);
            init.DirZ   = (float)Math.Sin(tbSceneNpc.FaceDirection);
            init.X      = (float)tbSceneNpc.PosX;
            init.Z      = (float)tbSceneNpc.PosZ;
            init.Y      = GameLogic.GetTerrainHeight(init.X, init.Z);
            ObjManager.Instance.CreateNPCAsync(init);
            return;
        }
        var dataId       = info.TypeId;
        var objId        = info.Id;
        var equip        = info.EquipsModel;
        var name         = info.Name;
        var allianceName = string.Empty;
        var battleDic    = PlayerDataManager.Instance._battleCityDic;

        foreach (var item in battleDic)
        {
            if (item.Value.Type == 0)
            {
                allianceName = item.Value.Name;
                break;
            }
        }

        /*
         *      var info = ObjManager.Instance.MyPlayer;
         *      var dataId = info.GetDataId();
         *      var objId = info.GetObjId();
         *      var equip = info.EquipList;
         *      var name = info.Name;
         *      var allianceName = "WWWWW";
         */
        if (mFackeCharacter != null)
        {
            mFackeCharacter.Destroy();
        }
        mFackeCharacter = ObjFakeCharacter.Create(dataId, equip, character =>
        {
            if (null == mFackeCharacter)
            {
                character.Destroy();
                return;
            }

            if (character.GetObjId() != mFackeCharacter.GetObjId())
            {
                character.Destroy();
                return;
            }

            var collider    = character.gameObject.AddComponent <CapsuleCollider>();
            collider.center = new Vector3(0, 1, 0);
            collider.height = 2;

            //character.transform.parent = transform;
            character.transform.position = gameObject.transform.position + Offset;
            character.transform.rotation = Quaternion.Euler(0, 180f, 0);
            //character.transform.forward = Quaternion.Euler(ForwardAngle.x, ForwardAngle.y, ForwardAngle.z) * Vector3.forward;
            character.transform.localScale = Scale;


            int inde = 0;
            switch (info.TypeId)
            {
            case 0:
                inde = 460;
                break;

            case 1:
                inde = 461;
                break;

            case 2:
                inde = 462;
                break;
            }
            var tab_Config = DataTable.Table.GetClientConfig(inde);
            if (null != tab_Config)
            {
                var titles = new Dictionary <int, string>();
                var tabid  = 0;
                if (int.TryParse(tab_Config.Value, out tabid))
                {
                    titles.Add(tabid, null);
                    character.CreateNameBoard(name, titles);
                }
            }
        }, 0, false, -1, objId);
        mFackeCharacter.SetObjId(objId);
        //mFackeCharacter.OnWingLoadedCallback = OnWingLoaded;
        mFackeCharacter.gameObject.layer = LayerMask.NameToLayer("ObjLogic");
        mFackeCharacter.iType            = (int)OBJ.TYPE.FAKE_FIGHTLEADER;
    }