Ejemplo n.º 1
0
    static public void Init() //玩家使用的职业的初始化
    {
        //锁定的脚底光圈
        GameObject obj_prefab = GAMEAPI.ABFight_LoadPrefab("common_lock_fx");
        GameObject obj_inst   = GameObject.Instantiate(obj_prefab) as GameObject;

        s_LockFX = obj_inst.transform;

        GameObject obj_boss_prefab = GAMEAPI.ABFight_LoadPrefab("common_lock_fx_boss");
        GameObject obj_boss_inst   = GameObject.Instantiate(obj_boss_prefab) as GameObject;

        s_LockFX_boss = obj_boss_inst.transform;


        int p = PlayerModel.getInstance().profession;

        if (p == 2)
        {
            FightText.userText = FightText.WARRIOR_TEXT;
        }
        else if (p == 3)
        {
            FightText.userText = FightText.MAGE_TEXT;
        }
        else if (p == 5)
        {
            FightText.userText = FightText.ASSI_TEXT;
        }


        //P1Warrior warrior = new P1Warrior();
        //warrior.Init();
        //_inst = warrior;

        //debug.Log("进入游戏的角色是 ................ " + PlayerModel.getInstance().profession+" "+PlayerModel.getInstance().iid);


        GameObject mainborn = GameObject.Find("mainbronpt");

        if (mainborn != null)
        {
            PlayerModel.getInstance().mapBeginX       = mainborn.transform.position.x;
            PlayerModel.getInstance().mapBeginY       = mainborn.transform.position.z;
            PlayerModel.getInstance().mapBeginroatate = mainborn.transform.eulerAngles.y;
        }

        ProfessionRole me    = null;
        A3_PROFESSION  a3_pf = (A3_PROFESSION)PlayerModel.getInstance().profession;

        if (A3_PROFESSION.Warrior == a3_pf)
        {
            P2Warrior p2 = new P2Warrior();
            p2.m_bUserSelf = true;
            p2.Init(PlayerModel.getInstance().name, EnumLayer.LM_SELFROLE, Vector3.zero, true);
            me = p2;
        }
        else if (A3_PROFESSION.Mage == a3_pf)
        {
            P3Mage p3 = new P3Mage();
            p3.m_bUserSelf = true;
            p3.Init(PlayerModel.getInstance().name, EnumLayer.LM_SELFROLE, Vector3.zero, true);
            me = p3;
        }
        else if (A3_PROFESSION.Assassin == a3_pf)
        {
            P5Assassin p5 = new P5Assassin();
            p5.m_bUserSelf = true;
            p5.Init(PlayerModel.getInstance().name, EnumLayer.LM_SELFROLE, Vector3.zero, true);
            me = p5;
        }
        else
        {
            P3Mage p3 = new P3Mage();
            p3.m_bUserSelf = true;
            p3.Init(PlayerModel.getInstance().name, EnumLayer.LM_SELFROLE, Vector3.zero, true);
            me = p3;
        }

        //P3Mage me = new P3Mage();
        me.m_ePK_Type   = PlayerModel.getInstance().up_lvl < 1 ? PK_TYPE.PK_PEACE : PK_TYPE.PK_PKALL;
        me.m_unIID      = PlayerModel.getInstance().iid;
        me.m_unPK_Param = PlayerModel.getInstance().cid;
        me.refreshmapCount((int)PlayerModel.getInstance().treasure_num);
        me.refreshserialCount(PlayerModel.getInstance().serial);
        me.serial = PlayerModel.getInstance().serial;
        me.refreshVipLvl((uint)A3_VipModel.getInstance().Level);
        me.m_curPhy.gameObject.layer = EnumLayer.LM_BT_SELF;
        _inst       = me;
        _inst.speed = PlayerModel.getInstance().speed;

        var rideInfo = A3_RideModel.getInstance().GetRideInfo();

        if (GRMap.curSvrConf.ContainsKey("maptype") && GRMap.curSvrConf["maptype"]._int > 0)
        {
            if (rideInfo != null && rideInfo.mount == (uint)RIDESTATE.UP)
            {
                A3_RideModel.getInstance().GetRideInfo().mount = 0;
                A3_RideProxy.getInstance().SendC2S(4, "mount", 0, true);
            }

            //副本中不携带坐骑
        }
        else
        {
            if (rideInfo != null && rideInfo.mount == ( uint )RIDESTATE.UP)
            {
                _inst.set_Ride(( int )rideInfo.dress, true);
            }
        }


        //Transform one = U3DAPI.DEF_TRANSFORM;
        //one.position = me.m_curModel.position;
        //OtherPlayerMgr._inst.AddOtherPlayer(one, 1);
        //OtherPlayerMgr._inst.AddOtherPlayer(one, 2);
        //OtherPlayerMgr._inst.AddOtherPlayer(one, 1);
        //OtherPlayerMgr._inst.AddOtherPlayer(one, 1);
        //OtherPlayerMgr._inst.AddOtherPlayer(one, 1);
        //OtherPlayerMgr._inst.AddOtherPlayer(one, 1);


        //临时存放在这里
        //GameObject raffle_group = GameObject.Find("a3_scene/raffle");
        GameObject raffle_group = GameObject.Find("game_scene/lv3/raffle");

        if (raffle_group != null)
        {
            //debug.Log("找到了木桶组");
            for (int i = 0; i < raffle_group.transform.childCount; i++)
            {
                Transform cur_tf = raffle_group.transform.GetChild(i);

                Transform cur_whole = cur_tf.Find("whole");
                Transform cur_boom  = cur_tf.Find("boom");

                if (cur_whole != null && cur_boom != null)
                {
                    RaffleHurtPoint rht = cur_tf.gameObject.AddComponent <RaffleHurtPoint>();
                    rht.m_Raffle   = cur_tf.gameObject;
                    rht.m_RafWhole = cur_whole.gameObject;
                    rht.m_RafBoom  = cur_boom.gameObject;

                    cur_tf.gameObject.layer = EnumLayer.LM_BT_FIGHT;
                }
                else
                {
                    GameObject.Destroy(cur_tf.gameObject);
                }
            }
        }

        //子弹墙
        //GameObject btwall_group = GameObject.Find("a3_scene/btwall");
        GameObject btwall_group = GameObject.Find("game_scene/lv3/btwall");

        if (btwall_group != null)
        {
            for (int i = 0; i < btwall_group.transform.childCount; i++)
            {
                Transform cur_tf = btwall_group.transform.GetChild(i);
                cur_tf.gameObject.AddComponent <BtWallHurtPoint>();

                cur_tf.gameObject.layer = EnumLayer.LM_BT_FIGHT;
            }
        }

        ////初始化装备模型
        //foreach (a3_BagItemData equip in a3_EquipModel.getInstance().getEquips().Values)
        //{
        //    a3_EquipModel.getInstance().equipModel_on(equip);
        //}
        //初始化装备模型
        if (a3_EquipModel.getInstance().getEquips() != null && a3_EquipModel.getInstance().getEquips().Count > 0)
        {
            foreach (a3_BagItemData equip in a3_EquipModel.getInstance().getEquips().Values)
            {
                a3_EquipModel.getInstance().equipModel_on(equip);
            }
        }
        else
        {
            a3_EquipModel.getInstance().equipModel_on(null);
        }


        //初始化翅膀模型
        A3_WingModel.getInstance().OnEquipModelChange();

        //初始化宠物模型和注册宠物avatar改变
        if (PlayerModel.getInstance().last_time != 0)
        {
            OnPetAvatarChange();
        }

        //A3_PetModel.getInstance().OnStageChange += OnPetAvatarChange;
        MonsterMgr._inst.dispatchEvent(GameEvent.Create(MonsterMgr.EVENT_ROLE_BORN, MonsterMgr._inst, SelfRole._inst));


        //用于设置第一次创建模型时不发移动协议,解决刚进副本激活怪物ai的bug
        MoveProxy.getInstance().resetFirstMove();

        _inst.m_LockDis = XMLMgr.instance.GetSXML("comm.lockdis").getFloat("dis");
    }
Ejemplo n.º 2
0
    static public void FrameMove(float delta_time)
    {
        //切地图时加个保护
        if (GRMap.instance != null && GRMap.grmap_loading == true)
        {
            return;
        }

        //需要不停的发位置变化的消息给服务器
        if (_inst != null)
        {
            bool haveTarget = false;
            try { haveTarget = _inst.m_LockRole?.m_curModel ?? false; } catch (Exception e) { _inst.m_LockRole = null; haveTarget = false; }
            if (haveTarget)
            {
                if (s_LockFX != null && _inst.m_LockRole.m_circle_type == -1)
                {                                                             //通用类型光圈
                    PkmodelAdmin.RefreshShow(_inst.m_LockRole);
                    s_LockFX.position = _inst.m_LockRole.m_curModel.position; //m_curPhy
                    if (_inst.m_LockRole.isDead)
                    {
                        s_LockFX.position = Vector3.zero;
                    }
                }
                if (s_LockFX_boss != null && _inst.m_LockRole.m_circle_type == 1)
                {//boss类型光圈
                    s_LockFX_boss.position = _inst.m_LockRole.m_curPhy.position;
                    if (_inst.m_LockRole.isDead)
                    {
                        s_LockFX_boss.position = Vector3.zero;
                    }
                    float scale_value = _inst.m_LockRole.m_circle_scale;
                    s_LockFX_boss.localScale = new Vector3(scale_value, scale_value, scale_value);
                }
            }
            else
            {
                if (s_LockFX != null)
                {
                    s_LockFX.position = Vector3.zero;
                }
                if (s_LockFX_boss != null)
                {
                    s_LockFX_boss.position = Vector3.zero;
                }
            }

            _inst.FrameMove(delta_time);
            MoveProxy.getInstance().TrySyncPos(delta_time);
            try
            {
                long    tm  = muNetCleint.instance.g_netM.CurServerTimeStampMS;
                Vector3 pos = _inst.m_curModel.position;


                //Vector3 vec3 = new Vector3(x, pGameobject.transform.position.y, y);
                //LGCamera.instance.updateMainPlayerPos();
                //  MoveProxy.getInstance().sendstop((uint)x, (uint)y, 1, tm, false);

                if (_inst.moving)
                {
                    float angle = Mathf.Atan2(a1_gamejoy.inst_joystick.MovePosiNorm.z, a1_gamejoy.inst_joystick.MovePosiNorm.x) * Mathf.Rad2Deg;
                    angle = SceneCamera.m_curCamGo.transform.eulerAngles.y - angle;
                    pos   = Quaternion.Euler(0, angle, 0) * new Vector3(1f, 0f, 0f) + pos;

                    NavMeshHit hit;
                    NavMesh.SamplePosition(pos, out hit, 3f, NavmeshUtils.allARE);
                    pos = hit.position;
                }

                float x = (float)(pos.x) * GameConstant.PIXEL_TRANS_UNITYPOS;
                float y = (float)(pos.z) * GameConstant.PIXEL_TRANS_UNITYPOS;
                MoveProxy.getInstance().sendstop((uint)x, (uint)y, 1, tm, false);
            }
            catch (System.Exception ex)
            {
                debug.Log(ex.ToString());
            }

            fsm.Update(delta_time);

            if (_inst.m_LockRole != null)
            {//添加怪物离开锁定范围的判定
                try
                {
                    Vector3 off_pos = _inst.m_LockRole.m_curPhy.position - _inst.m_curModel.position;
                    float   off_dis = off_pos.magnitude;
                    if (off_dis > _inst.m_LockDis)
                    {
                        _inst.m_LockRole = null;
                    }
                }
                catch (Exception) { _inst.m_LockRole = null; }
            }
        }
    }