Vector3 GetPlayerSpawnPos()
            {
                IntVector2 posXZ = VArtifactUtil.GetSpawnPos();
                Vector3    pos   = new Vector3(posXZ.x, VFDataRTGen.GetPosTop(posXZ), posXZ.y);

                return(pos);
            }
Exemple #2
0
    //method 2.
    public void GenTestEntrance(int level = -1)
    {
        int     x      = Mathf.RoundToInt(PeCreature.Instance.mainPlayer.position.x);
        int     z      = Mathf.RoundToInt(PeCreature.Instance.mainPlayer.position.z + 15);
        int     y      = VFDataRTGen.GetPosHeight(x, z);
        Vector3 genPos = new Vector3(x, y, z);

        InstantiateEntrance(genPos, level);
    }
Exemple #3
0
            /*
             *          MaskTileTypeDic maskTileDic = new MaskTileTypeDic();
             *
             *          public byte GetType(int pos_x , int pos_z)
             *          {
             *                  maskTileDic.Reset();
             *                  for(int x = pos_x - 60 ; x < pos_x + 60; x += 20 )
             *                  {
             *                          for(int z = pos_z - 60 ; z < pos_z + 60; z += 20 )
             *                          {
             *                                  if ( VFDataRTGen.IsSea(x,z) )
             *                                          maskTileDic.CountType(MaskTileType.Sea);
             *                                  else
             *                                  {
             *                                          RandomMapType type = VFDataRTGen.GetXZMapType(pos_x,pos_z);
             *                                          maskTileDic.CountType( (MaskTileType) type);
             *                                  }
             *                          }
             *                  }
             *                  return (byte)maskTileDic.GetMostType();
             *          }
             */

            public byte GetType(int pos_x, int pos_z)
            {
                if (VFDataRTGen.IsSea(pos_x, pos_z))
                {
                    return((byte)MaskTileType.Sea);
                }
                else
                {
                    return((byte)VFDataRTGen.GetXZMapType(pos_x, pos_z));
                }
            }
    public static Vector3 GetStartPos()
    {
        if (PeGameMgr.IsSingleAdventure)
        {
            return(VArtifactTownManager.Instance.playerStartPos);
        }
        IntVector2 posXZ = GetSpawnPos();
        Vector3    pos   = new Vector3(posXZ.x, VFDataRTGen.GetPosTop(posXZ), posXZ.y);

        return(pos);
    }
    public void Fill(int cntNpc, int cntMonster)
    {
        Vector3             center     = RectIdxToCenterPos(_idx);
        bool                bAvailable = false;
        SceneEntityPosAgent agent;

        System.Random rand = new System.Random();
        for (int i = 0; i < cntNpc; i++)
        {
            Vector3 point = !PeGameMgr.randomMap ? GetEntityPoint(center, out bAvailable) : GetNpcPointInRndTer(center, out bAvailable);
            if (bAvailable)
            {
                if (VFDataRTGen.IsTownConnectionType(Mathf.RoundToInt(point.x), Mathf.RoundToInt(point.z)))
                {
                    agent        = NpcEntityCreator.CreateAgent(point);
                    agent.spInfo = _rndNpcAgentInfo;
                    _posRndNpcAgents.Add(agent);                        // npc entity would not be destroyed by scene
                }
                else
                {
                    if (rand.NextDouble() < 0.25)
                    {
                        agent        = NpcEntityCreator.CreateAgent(point);
                        agent.spInfo = _rndNpcAgentInfo;
                        _posRndNpcAgents.Add(agent);                            // npc entity would not be destroyed by scene
                    }
                }
            }
        }
        for (int i = 0; i < cntMonster; i++)
        {
            Vector3 point = GetEntityPoint(center, out bAvailable);
            if (bAvailable && null == AIErodeMap.IsInErodeArea2D(point))
            {
                _posRndMonsterAgents.Add(MonsterEntityCreator.CreateAgent(point));
            }
        }
        SceneMan.AddSceneObjs(_posRndNpcAgents);
        SceneMan.AddSceneObjs(_posRndMonsterAgents);

        if (PeGameMgr.IsStory)
        {
            _posFixedMonsterIds = AISpawnPoint.Find(center.x - EntityCreationRadius, center.z - EntityCreationRadius, center.x + EntityCreationRadius, center.z + EntityCreationRadius);
            if (_posFixedMonsterIds.Count > 0)
            {
                SceneEntityCreatorArchiver.Instance.AddFixedSpawnPointToScene(_posFixedMonsterIds);
            }
        }
        else if (PeGameMgr.IsSingleAdventure)
        {
            SceneEntityPosRect.AddProcedualBossSpawnPointToScene(_idx);
        }
    }
    protected override int GetCurrentBgMusicID()
    {
        Vector3 camPos = PETools.PEUtil.MainCamTransform.position;

        if (AiUtil.CheckPositionInCave(camPos, 128.0f, AiUtil.groundedLayer))
        {
            return(836);
        }

        int x = (int)camPos.x;
        int z = (int)camPos.z;

        if (x <= Int32.MinValue)
        {
            Debug.LogError("x value too small!");
            x = Int32.MinValue + 1;
        }
        if (z <= Int32.MinValue)
        {
            Debug.LogError("z value too small!");
            z = Int32.MinValue + 1;
        }

        if (VFDataRTGen.IsSea(x, z))
        {
            return(AISpawnDataStory.GetBackGroundMusic(new Color(255.0f / 255.0f, 100.0f / 255.0f, 150.0f / 255.0f, 255 / 255.0f)));
        }
        else
        {
            RandomMapType mapType = VFDataRTGen.GetXZMapType(x, z);

            switch (mapType)
            {
            case RandomMapType.GrassLand:   return(AISpawnDataStory.GetBackGroundMusic(new Color(30.0f / 255.0f, 50.0f / 255.0f, 50.0f / 255.0f, 255 / 255.0f)));

            case RandomMapType.Forest:      return(AISpawnDataStory.GetBackGroundMusic(new Color(70.0f / 255.0f, 70.0f / 255.0f, 70.0f / 255.0f, 255 / 255.0f)));

            case RandomMapType.Desert:      return(AISpawnDataStory.GetBackGroundMusic(new Color(140.0f / 255.0f, 100.0f / 255.0f, 50.0f / 255.0f, 255 / 255.0f)));

            case RandomMapType.Redstone:    return(AISpawnDataStory.GetBackGroundMusic(new Color(170.0f / 255.0f, 70.0f / 255.0f, 50.0f / 255.0f, 255 / 255.0f)));

            case RandomMapType.Rainforest:  return(AISpawnDataStory.GetBackGroundMusic(new Color(90.0f / 255.0f, 90.0f / 255.0f, 90.0f / 255.0f, 255 / 255.0f)));

            case RandomMapType.Mountain:    return(AISpawnDataStory.GetBackGroundMusic(new Color(170.0f / 255.0f, 70.0f / 255.0f, 150.0f / 255.0f, 255 / 255.0f)));

            case RandomMapType.Swamp:       return(AISpawnDataStory.GetBackGroundMusic(new Color(100.0f / 255.0f, 50.0f / 255.0f, 50.0f / 255.0f, 255 / 255.0f)));

            case RandomMapType.Crater:      return(AISpawnDataStory.GetBackGroundMusic(new Color(180.0f / 255.0f, 180.0f / 255.0f, 180.0f / 255.0f, 255 / 255.0f)));

            default: return(0);
            }
        }
    }
    Vector3 GetNpcPointInRndTer(Vector3 cpos, out bool bSuc)     // Special process to get creation pos for NPC.
    {
        Vector2 v2 = UnityEngine.Random.insideUnitCircle.normalized;

        v2 = v2 * UnityEngine.Random.Range(-SceneEntityPosRect.EntityCreationRadius, SceneEntityPosRect.EntityCreationRadius);
        IntVector2 iv = new IntVector2((int)(cpos.x + v2.x), (int)(cpos.z + v2.y));
        float      fy = VFDataRTGen.GetPosTop(iv, out bSuc);

        if (!bSuc)
        {
            return(Vector3.zero);
        }
        return(new Vector3(iv.x, fy + 1, iv.y));
    }
 public float GetTerrainHeight(Vector3 pos)
 {
     if (Pathea.PeGameMgr.IsStory)
     {
         if (null == mHeightMap)
         {
             return(100f);
         }
         return(mHeightMap.GetHeight(new Vector2(pos.x, pos.z), mWorldSize));
     }
     if (Pathea.PeGameMgr.IsCustom)
     {
         return(100f);
     }
     return(VFDataRTGen.GetBaseTerHeight(new IntVector2(Mathf.RoundToInt(pos.x), Mathf.RoundToInt(pos.z))));
 }
            void PeLauncher.ILaunchable.Launch()
            {
                if (null == BaseNetwork.MainPlayer)
                {
                    return;
                }

                Vector3 pos = BaseNetwork.MainPlayer._pos;

                if (BaseNetwork.MainPlayer.UseNewPos)
                {
                    IntVector2 posXZ = VArtifactUtil.GetSpawnPos();
                    pos = new Vector3(posXZ.x, VFDataRTGen.GetPosTop(posXZ), posXZ.y);
                }

                Pathea.PlayerSpawnPosProvider.Instance.SetPos(pos);
            }
    void RPC_S2C_CreateFollowPos(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        float x, y;
        int   targetid, missionId;

        stream.TryRead <float> (out x);
        stream.TryRead <float> (out y);
        stream.TryRead <int> (out targetid);
        stream.TryRead <int>(out missionId);

        Vector3 pos = new Vector3(x, VFDataRTGen.GetPosTop(new IntVector2((int)x, (int)y)), y);

        if (null != PlayerNetwork.mainPlayer)
        {
            PlayerNetwork.mainPlayer.RPCServer(EPacketType.PT_InGame_MissionFollowPos, pos, targetid);
        }

        TypeFollowData data = MissionManager.GetTypeFollowData(targetid);

        if (data == null)
        {
            return;
        }

        data.m_DistPos    = pos;
        data.m_DistRadius = data.m_AdDistPos.radius2;
        if (data.m_AdNpcRadius.num > 0)
        {
            data.m_LookNameID = StroyManager.Instance.CreateMissionRandomNpc(data.m_DistPos, data.m_AdNpcRadius.num);
        }
        if (IsOwner)
        {
            if (data.m_AdDistPos.refertoType == ReferToType.Transcript)
            {
                RandomDungenMgr.Instance.GenTaskEntrance(new IntVector2((int)data.m_DistPos.x, (int)data.m_DistPos.z), data.m_AdDistPos.referToID);
            }

            for (int i = 0; i < data.m_CreateNpcList.Count; i++)
            {
                Vector3 createpos = StroyManager.Instance.GetPatrolPoint(data.m_DistPos, 3, 8, false);
                EntityCreateMgr.Instance.CreateRandomNpc(data.m_CreateNpcList[i], createpos);
            }
            MissionManager.Instance.m_PlayerMission.ProcessFollowMission(missionId, targetid);
        }
        UpdateMissionMapLabelPos(missionId, targetid, pos);
    }
 public bool IsTerrainAvailableForFeces(IntVector2 GenPos, out Vector3 pos)
 {
     pos = Vector3.zero;
     if (AIErodeMap.IsInErodeArea2D(new Vector3(GenPos.x, 0, GenPos.y)) != null)
     {
         return(false);
     }
     if (PeGameMgr.IsStory)
     {
         Vector3    checkPos = new Vector3(GenPos.x, s_maxHeight, GenPos.y);
         RaycastHit hit;
         if (Physics.Raycast(checkPos, Vector3.down, out hit, s_maxHeight, 1 << Pathea.Layer.VFVoxelTerrain))
         {
             pos = hit.point + new Vector3(0, 1, 0);
             if (!VFVoxelWater.self.IsInWater(pos))
             {
                 if (!mRandomItemsDic.ContainsKey(pos))
                 {
                     return(true);
                 }
             }
         }
         return(false);
     }
     else if (PeGameMgr.IsAdventure)
     {
         int height = VFDataRTGen.GetPosHeight(GenPos.x, GenPos.y, true);
         pos = new Vector3(GenPos.x, height, GenPos.y);
         bool inWater = VFDataRTGen.IsSea(height);
         if (!inWater)
         {
             RaycastHit hit;
             if (Physics.Raycast(pos + new Vector3(0, 2, 0), Vector3.down, out hit, a_maxHeight, 1 << Pathea.Layer.VFVoxelTerrain))
             {
                 pos = hit.point;
             }
             pos.y += 1;
             if (!mRandomItemsDic.ContainsKey(pos))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemple #12
0
    bool IsInWaterSurfaceSea(Vector3 position)
    {
        if (inWaterSurface)
        {
            if (PeGameMgr.sceneMode == PeGameMgr.ESceneMode.Adventure)
            {
                return(VFDataRTGen.IsSea((int)position.x, (int)position.z));
            }
            else if (PeGameMgr.sceneMode == PeGameMgr.ESceneMode.Story)
            {
                Vector2 pos   = new Vector2(position.x, position.z);
                int     mapid = PeMappingMgr.Instance.GetAiSpawnMapId(pos);
                return(mapid == 25 || mapid == 26 || mapid == 22);
            }
        }

        return(false);
    }
    internal override int GetMapID(Vector3 position)
    {
        RandomMapType map = VFDataRTGen.GetXZMapType((int)position.x, (int)position.z);

        switch (map)
        {
        case RandomMapType.GrassLand:   return(2);

        case RandomMapType.Forest:      return(8);

        case RandomMapType.Desert:      return(13);

        case RandomMapType.Redstone:    return(18);

        case RandomMapType.Rainforest:  return(10);

        default:                        return(0);
        }
    }
Exemple #14
0
    public bool IsTerrainAvailable(IntVector2 GenPos, out Vector3 pos)
    {
        if (!VFDataRTGen.IsDungeonEntranceAvailable(GenPos))
        {
            pos = Vector3.zero;
            return(false);
        }
//		int y = VFDataRTGen.GetPosHeight(GenPos,true);
//
//		pos = new Vector3(GenPos.x,y+4,GenPos.y);
//		RaycastHit hit;
//		if (Physics.Raycast(pos, Vector3.down, out hit, 512, 1 << Pathea.Layer.VFVoxelTerrain))
//		{
//			pos.y = hit.point.y;
//		}else{
//			return false;
//		}
        bool result = RandomDunGenUtil.GetAreaLowestPos(GenPos, 10, out pos);

        return(result);
    }
    void RPC_S2C_CreateDiscoveryPos(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        float x         = stream.Read <float>();
        float y         = stream.Read <float>();
        int   targetid  = stream.Read <int>();
        int   missionId = stream.Read <int>();

        TypeSearchData data = MissionManager.GetTypeSearchData(targetid);

        if (data == null)
        {
            return;
        }

        data.m_DistPos    = new Vector3(x, VFDataRTGen.GetPosHeight(x, y), y);
        data.m_DistRadius = data.m_mr.radius2;
        if (IsOwner)
        {
            if (data.m_mr.refertoType == ReferToType.Transcript)
            {
                RandomDungenMgr.Instance.GenTaskEntrance(new IntVector2((int)data.m_DistPos.x, (int)data.m_DistPos.z), data.m_mr.referToID);
            }

            if (MissionManager.Instance.m_bHadInitMission)
            {
                for (int i = 0; i < data.m_CreateNpcList.Count; i++)
                {
                    Vector3 createpos = StroyManager.Instance.GetPatrolPoint(data.m_DistPos, 3, 8, false);
                    EntityCreateMgr.Instance.CreateRandomNpc(data.m_CreateNpcList[i], createpos);
                }
            }
            if (null != PlayerNetwork.mainPlayer)
            {
                PlayerNetwork.mainPlayer.RPCServer(EPacketType.PT_InGame_MissionDiscoveryPos, data.m_DistPos, targetid);
            }
        }
        UpdateMissionMapLabelPos(missionId, targetid, data.m_DistPos);
    }
Exemple #16
0
    public static Vector3 GetPosOnGround(IntVector2 GenPos)
    {
        int        y   = VFDataRTGen.GetPosHeight(GenPos, true);
        Vector3    pos = new Vector3(GenPos.x, y + 4, GenPos.y);
        RaycastHit hit;

        if (Physics.Raycast(pos, Vector3.down, out hit, 512, 1 << Pathea.Layer.VFVoxelTerrain))
        {
            if (hit.point.y > 0)
            {
                pos.y = hit.point.y;
            }
            else
            {
                pos.y = y;
            }
        }
        else
        {
            pos.y = y;
        }
        return(pos);
    }
Exemple #17
0
    public static void Update()
    {
        if (Nova != null)
        {
            if (Pathea.SingleGameStory.curType == Pathea.SingleGameStory.StoryScene.PajaShip)
            {
                Nova.LocalTime = 0;
            }
            else
            {
                Nova.LocalTime = GameTime.Timer.Second;
            }
            if (Pathea.PeGameMgr.IsMulti)
            {
                if (PlayerNetwork.mainPlayer != null && PlayerNetwork.mainPlayer._curSceneId == (int)Pathea.SingleGameStory.StoryScene.PajaShip)
                {
                    Nova.LocalTime = 0;
                }
            }
            Nova.Settings.TimeElapseSpeed = GameTime.Timer.ElapseSpeed;
            Nova.Settings.SoundVolume     = SystemSettingData.Instance.SoundVolume * SystemSettingData.Instance.EffectVolume;
            Nova.WetCoef = (float)System.Math.Pow(System.Math.Max((s_envNoise.Noise(Nova.LocalDay * 1.2)
                                                                   + s_envNoise.Noise(Nova.LocalDay * 2.4) * 0.5
                                                                   + s_envNoise.Noise(Nova.LocalDay * 4.8) * 0.25
                                                                   + s_envNoise.Noise(Nova.LocalDay * 9.6) * 0.125) * 0.38 + 0.45, 0), 3);
            // 小雨多一点..
            if (Nova.WetCoef > 0.55f)
            {
                Nova.WetCoef -= 0.55f;
                Nova.WetCoef *= 2.2f;
                Nova.WetCoef  = (float)System.Math.Pow(Nova.WetCoef, 2f);
                Nova.WetCoef /= 2.2f;
                Nova.WetCoef += 0.55f;
            }
            Nova.WetCoef = (Mathf.Clamp01(Nova.WetCoef) * ControlRain + BaseRain) * rainSwitch;


            Debug.DrawLine(new Vector3((float)Nova.LocalDay, (float)Nova.WetCoef, 0), new Vector3((float)Nova.LocalDay + 0.01f, (float)Nova.WetCoef, 0), Color.white, 1000);

            bool water_opt1 = SystemSettingData.Instance.WaterDepth;
            bool water_opt2 = SystemSettingData.Instance.WaterRefraction;

            int water_opt_ = 0;

            if (water_opt1 && water_opt2)
            {
                water_opt_ = 3;
            }
            else if (water_opt1 || water_opt2)
            {
                water_opt_ = 2;
            }
            else
            {
                water_opt_ = 1;
            }

            if (water_opt != water_opt_)
            {
                Material water_mat = null;
                switch (water_opt_)
                {
                case 3: water_mat = Resources.Load <Material>("PEWater_High"); break;

                case 2: water_mat = Resources.Load <Material>("PEWater_Medium"); break;

                case 1: water_mat = Resources.Load <Material>("PEWater_Low"); break;

                default: break;
                }
                if (VFVoxelWater.self != null && PEWaveSystem.Self != null)
                {
                    Material new_water_mat = Material.Instantiate(water_mat) as Material;
                    VFVoxelWater.self.WaterMat = new_water_mat;
                    NovaSettings.WaterMaterial = new_water_mat;
                    water_opt = water_opt_;
                }
            }
            RenderSettings.fog = !VCEditor.s_Ready;

            if (Pathea.PeGameMgr.sceneMode == Pathea.PeGameMgr.ESceneMode.Story)
            {
                if (PeMappingMgr.inited)
                {
                    switch (PeMappingMgr.Instance.Biome)
                    {
                    case GraphMapping.EBiome.Sea: Nova.BiomoIndex = 0; break;

                    case GraphMapping.EBiome.Marsh: Nova.BiomoIndex = 4; break;

                    case GraphMapping.EBiome.Jungle: Nova.BiomoIndex = 2; break;

                    case GraphMapping.EBiome.Forest: Nova.BiomoIndex = 1; break;

                    case GraphMapping.EBiome.Desert: Nova.BiomoIndex = 0; break;

                    case GraphMapping.EBiome.Canyon: Nova.BiomoIndex = 0; break;

                    case GraphMapping.EBiome.Volcano: Nova.BiomoIndex = 6; break;

                    case GraphMapping.EBiome.Grassland: Nova.BiomoIndex = 0; break;

                    case GraphMapping.EBiome.Mountainous: Nova.BiomoIndex = 3; break;

                    default: Nova.BiomoIndex = 0; break;
                    }

                    float mul_target = 1f;
                    float ofs_target = 0f;
                    switch (PeMappingMgr.Instance.Biome)
                    {
                    case GraphMapping.EBiome.Desert: mul_target = 0.3f; ofs_target = 0.0f; break;

                    case GraphMapping.EBiome.Volcano: mul_target = 0.3f; ofs_target = 0.45f; break;

                    default: mul_target = 1f; ofs_target = 0f; break;
                    }

                    wetcoef_multiplier = Mathf.Lerp(wetcoef_multiplier, mul_target, 0.01f);
                    wetcoef_offset     = Mathf.Lerp(wetcoef_offset, ofs_target, 0.01f);
                    Nova.WetCoef      *= wetcoef_multiplier;
                    Nova.WetCoef      += wetcoef_offset;
                }
                else
                {
                    Nova.BiomoIndex = 0;
                }
            }
            else
            {
                Nova.BiomoIndex = 0;
            }

            if (RandomDungenMgrData.InDungeon)
            {
                Nova.BiomoIndex = 5;
            }
            else
            {
                if (Pathea.PeGameMgr.IsAdventure || Pathea.PeGameMgr.IsBuild)
                {
                    if (Pathea.PeCreature.Instance.mainPlayer != null)
                    {
                        RandomMapType rmt = VFDataRTGen.GetXZMapType(Mathf.RoundToInt(Pathea.PeCreature.Instance.mainPlayer.position.x),
                                                                     Mathf.RoundToInt(Pathea.PeCreature.Instance.mainPlayer.position.z));
                        switch (rmt)
                        {
                        case RandomMapType.Swamp: Nova.BiomoIndex = 4; break;

                        case RandomMapType.Rainforest: Nova.BiomoIndex = 2; break;

                        case RandomMapType.Forest: Nova.BiomoIndex = 1; break;

                        case RandomMapType.Desert: Nova.BiomoIndex = 0; break;

                        case RandomMapType.Redstone: Nova.BiomoIndex = 0; break;

                        case RandomMapType.Crater: Nova.BiomoIndex = 6; break;

                        case RandomMapType.GrassLand: Nova.BiomoIndex = 0; break;

                        case RandomMapType.Mountain: Nova.BiomoIndex = 3; break;

                        default: Nova.BiomoIndex = 0; break;
                        }
                    }
                }
            }

            if (Pathea.PeGameMgr.sceneMode == Pathea.PeGameMgr.ESceneMode.Story ||
                Pathea.PeGameMgr.sceneMode == Pathea.PeGameMgr.ESceneMode.Custom)
            {
                switch (SystemSettingData.Instance.TerrainLevel)
                {
                //lz-2016.06.17 由(0=128M,1=256M,2=512M,3=1KM)改为(0=256M,1=512M,2=1KM),因此这里改为这样
                case 0: Nova.Settings.MaxFogEndDistance = 200; break;

                case 1: Nova.Settings.MaxFogEndDistance = 340; break;

                case 2: Nova.Settings.MaxFogEndDistance = 700; break;

                case 3: Nova.Settings.MaxFogEndDistance = 1300; break;
                }
            }
            else
            {
                Nova.Settings.MaxFogEndDistance = 550;
            }

            // 靠近海洋才打开水的反射效果,远离海洋则关闭,
            //if (Input.GetKeyDown(KeyCode.I)){		AlterNearSea(false);		}
            //if (Input.GetKeyDown(KeyCode.O)){		AlterNearSea(true);			}
            AlterNearSea(WaterReflection.ReqRefl());
            if (Mathf.Abs(_nearSeaTarget - _nearSeaCurrent) > 0.0001f)
            {
                _nearSeaCurrent = Mathf.Lerp(_nearSeaCurrent, _nearSeaTarget, 0.04f);                 // About 3s
            }
            if (_nearSeaCurrent < 0.001f)
            {
                WaterReflection.DisableRefl();
            }
            else
            {
                WaterReflection.EnableRefl();
            }
            Nova.WaterReflectionMasterBlend = _nearSeaCurrent;
        }        // End Nova != null
    }
    public bool IsTerrainAvailable(IntVector2 GenPos, out Vector3 pos, out int boxId)
    {
        //--to do: 1.random the data
        int  height  = VFDataRTGen.GetPosHeight(GenPos.x, GenPos.y, true);
        bool inWater = VFDataRTGen.IsSea(height);
        bool inCave  = false;

        pos = new Vector3(GenPos.x, height - 2, GenPos.y);
        RaycastHit hitTest;

        if (Physics.Raycast(pos, Vector3.down, out hitTest, 512, 1 << Pathea.Layer.VFVoxelTerrain))
        {
            inCave = true;
        }
        RandomMapType type = VFDataRTGen.GetXZMapType(GenPos.x, GenPos.x);

        IntVector2    tileIndex = new IntVector2(GenPos.x >> VoxelTerrainConstants._shift, GenPos.y >> VoxelTerrainConstants._shift);
        VArtifactTown vaTown    = null;

        if (VArtifactTownManager.Instance != null)
        {
            for (int i = -4; i < 5; i++)
            {
                for (int j = -4; j < 5; j++)
                {
                    vaTown = VArtifactTownManager.Instance.GetTileTown(new IntVector2(tileIndex.x + i, tileIndex.y + j));
                    if (vaTown != null)
                    {
                        break;
                    }
                }
                if (vaTown != null)
                {
                    break;
                }
            }
        }



        List <int> genCondition = new List <int>();


        if (vaTown != null)
        {
            if (vaTown.type == VArtifactType.NpcTown)
            {
                genCondition.Add(BoxMapTypeInt.NEAR_TOWN);
            }
            else
            {
                genCondition.Add(BoxMapTypeInt.NEAR_CAMP);
            }
        }

        switch (type)
        {
        case RandomMapType.Desert:
            genCondition.Add(BoxMapTypeInt.DESERT);
            break;

        case RandomMapType.Redstone:
            genCondition.Add(BoxMapTypeInt.REDSTONE);
            break;

        default:
            genCondition.Add(BoxMapTypeInt.GRASSLAND);
            break;
        }

        if (inWater)
        {
            genCondition.Add(BoxMapTypeInt.IN_WATER);
        }

        if (inCave)
        {
            genCondition.Add(BoxMapTypeInt.IN_CAVE);
        }


        boxId = -1;
        List <RandomItemBoxInfo> boxInfoList = RandomItemDataMgr.GetBoxIdByCondition(genCondition, height);

        if (boxInfoList == null || boxInfoList.Count == 0)
        {
            return(false);
        }
        List <RandomItemBoxInfo> boxInfoAvailable = new List <RandomItemBoxInfo> ();

        foreach (RandomItemBoxInfo rib in boxInfoList)
        {
            if (IsBoxNumAvailable(rib.boxId, rib.boxAmount))
            {
                boxInfoAvailable.Add(rib);
            }
        }
        if (boxInfoAvailable.Count == 0)
        {
            return(false);
        }

        RandomItemBoxInfo boxInfo = boxInfoAvailable[new System.Random((int)System.DateTime.UtcNow.Ticks).Next(boxInfoAvailable.Count)];

        boxId = boxInfo.boxId;
        float deep = boxInfo.boxDepth;


        //2.check with boxId
        if (deep <= 0)
        {
            deep = -3;
        }
        else if (deep < 2)
        {
            deep = 2;
        }
        pos = new Vector3(GenPos.x, height - deep, GenPos.y);
        if (pos.y < 0)
        {
            pos.y = 0;
        }
        else
        {
            RaycastHit hit;
            if (Physics.Raycast(pos, Vector3.down, out hit, 512, 1 << Pathea.Layer.VFVoxelTerrain))
            {
                pos.y = hit.point.y - boxInfo.boxDepth;
            }
        }

        if (pos.y < 0)
        {
            return(false);
        }

        return(true);
    }
Exemple #19
0
    void BtnClick_OnCancel()
    {
        if (currentState == ReivieState.Reivie_Servant || currentEntity == null)
        {
            Hide();
            return;
        }
        if (!PeGameMgr.IsMulti)
        {
            ReviveLabel label = new ReviveLabel();
            label.pos = currentEntity.position;
            ReviveLabel.Mgr.Instance.Add(label);

            if (RandomDungenMgrData.InDungeon)
            {
                bool reviveSuc = DoRevive(true);
                if (reviveSuc)
                {
                    currentEntity.position = RandomDungenMgrData.revivePos;
                    Hide();
                }
                return;
            }

            //lz-2016.08.03 空对象
            if (null != MissionManager.Instance)
            {
                MissionManager.Instance.RemoveFollowTowerMission();
            }
            DoRevive(true);
            Vector3 revivePos;
            if (SingleGameStory.curType == SingleGameStory.StoryScene.DienShip0)
            {
                revivePos = new Vector3(14798.09f, 20.98818f, 8246.396f);
            }
            else if (SingleGameStory.curType == SingleGameStory.StoryScene.L1Ship)
            {
                revivePos = new Vector3(9649.354f, 90.488f, 12744.77f);
            }
            else if (SingleGameStory.curType == SingleGameStory.StoryScene.PajaShip)
            {
                revivePos = new Vector3(1593.53f, 148.635f, 8022.03f);
            }
            else
            {
                revivePos = GetNearFastTrvalPos(currentEntity.position);
            }
            Pathea.FastTravelMgr.Instance.TravelTo(revivePos);
        }
        else
        {
            Vector3 warpPos = Vector3.zero;
            if (RandomDungenMgrData.InDungeon)
            {
                warpPos = RandomDungenMgrData.revivePos;
            }
            else if (PeGameMgr.IsMultiCoop)
            {
                warpPos = GetNearFastTrvalPos(currentEntity.position);
            }
            else
            {
                if (PeGameMgr.IsCustom)
                {
                    warpPos = PlayerNetwork.mainPlayer.GetCustomModePos();
                }
                else
                {
                    IntVector2 posXZ = VArtifactUtil.GetSpawnPos();
                    warpPos = new Vector3(posXZ.x, VFDataRTGen.GetPosTop(posXZ), posXZ.y);
                }
            }

            PlayerNetwork.mainPlayer.RPCServer(EPacketType.PT_InGame_PlayerReset, warpPos);
            PlayerNetwork.mainPlayer.RequestChangeScene(0);
        }

        Hide();
    }
    public void PlantVegetation(VFTile terTile, double[][] tileNoiseBuf, float[][] tileHeightBuf, float[][] tileGradTanBuf,
                                List <TreeInfo> outlstTreeInfo, List <VoxelGrassInstance> outlstGrassInst, RandomMapType[][] tileMapType, int szCell)
    {
        int startX = terTile.tileX << VoxelTerrainConstants._shift;
        int startZ = terTile.tileZ << VoxelTerrainConstants._shift;
        int iScl   = 1 << terTile.tileL;

        for (int iz = 0; iz < VoxelTerrainConstants._numVoxelsPerAxis; iz += szCell)
        {
            int      idxZ        = iz + VoxelTerrainConstants._numVoxelsPrefix;
            double[] xNoiseBuf   = tileNoiseBuf[idxZ];
            float[]  xHeightBuf  = tileHeightBuf[idxZ];
            float[]  xGradTanBuf = tileGradTanBuf[idxZ];
            byte[][] xyVoxels    = terTile.terraVoxels[idxZ];
            for (int ix = 0; ix < VoxelTerrainConstants._numVoxelsPerAxis; ix += szCell)
            {
                int    idxX    = ix + VoxelTerrainConstants._numVoxelsPrefix;
                float  fy      = xHeightBuf[idxX];
                byte[] yVoxels = xyVoxels[idxX];
                byte   vType   = yVoxels[((int)fy) * VFVoxel.c_VTSize + 1];
                if (VFDataRTGen.IsNoPlantType(vType))
                {
                    continue;
                }

                curRegion = prms.RegionDescArrayValues[MapTypeToRegionId(tileMapType[iz][ix])];

                VoxelPaintXML.PlantDescArrayCLS veges0 = curRegion.trees;
                VoxelPaintXML.PlantDescArrayCLS veges1 = curRegion.grasses;
                VoxelPaintXML.PlantDescArrayCLS veges2 = curRegion.newgrasses;

                VoxelPaintXML.PlantHeightDesc treeHeight     = null;
                VoxelPaintXML.PlantHeightDesc grassHeight    = null;
                VoxelPaintXML.PlantHeightDesc newGrassHeight = null;

                VoxelPaintXML.PlantGradientDesc treeGradient     = null;
                VoxelPaintXML.PlantGradientDesc grassGradient    = null;
                VoxelPaintXML.PlantGradientDesc newGrassGradient = null;

                double noise256 = (xNoiseBuf[idxX] + 1) * 128;
                float  gradTan  = xGradTanBuf[idxX];

                //坡度大于60度草树皆不刷
                if (gradTan >= noVegeTan1)
                {
                    continue;
                }
                if (gradTan < noVegeTan0)
                {
                    if (veges0 != null)
                    {
                        //树的空间单位
                        if (0 == ix % veges0.cellSize && 0 == iz % veges0.cellSize)
                        {
                            bool bTree = false;
                            if (noise256 >= veges0.start || (noise256 > veges0.startFadeIn && myRand.NextDouble() <= (noise256 - veges0.startFadeIn) / (veges0.start - veges0.startFadeIn)))
                            {
                                bTree = true;
                            }

                            if (bTree)
                            {
                                for (int i = 0; i < veges0.PlantHeightDescValues.Length; i++)
                                {
                                    VoxelPaintXML.PlantHeightDesc heightDesc = veges0.PlantHeightDescValues [i];
                                    if (heightDesc.start <= fy && heightDesc.end > fy)
                                    {
                                        treeHeight = heightDesc;
                                    }
                                }
                                if (treeHeight != null)
                                {
                                    for (int i = 0; i < treeHeight.PlantGradientDescValues.Length; i++)
                                    {
                                        VoxelPaintXML.PlantGradientDesc GradientDesc = treeHeight.PlantGradientDescValues [i];
                                        if (GradientDesc.start <= gradTan && GradientDesc.end > gradTan)
                                        {
                                            treeGradient = GradientDesc;
                                        }
                                    }
                                    PlantAVegetation(startX, startZ, ix, iz, iScl, treeGradient.PlantDescArrayValues, tileHeightBuf, 5.0f, outlstTreeInfo);
                                }
                            }
                        }
                    }
                }


                //坡度大于45度不刷草药
                //if (gradTan >= noVegeTan0) continue;
                if (gradTan < noVegeTan3)
                {
                    if (veges1 != null)
                    {
                        //旧草的空间单位
                        if (0 == ix % veges1.cellSize && 0 == iz % veges1.cellSize)
                        {
                            if (noise256 >= veges1.start || (noise256 > veges1.startFadeIn && myRand.NextDouble() <= (noise256 - veges1.startFadeIn) / (veges1.start - veges1.startFadeIn)))
                            {
                                foreach (VoxelPaintXML.PlantHeightDesc heightDesc in veges1.PlantHeightDescValues)
                                {
                                    if (heightDesc.start <= fy && heightDesc.end > fy)
                                    {
                                        grassHeight = heightDesc;
                                    }
                                }
                                if (grassHeight != null)
                                {
                                    foreach (VoxelPaintXML.PlantGradientDesc GradientDesc in grassHeight.PlantGradientDescValues)
                                    {
                                        if (GradientDesc.start <= gradTan && GradientDesc.end > gradTan)
                                        {
                                            grassGradient = GradientDesc;
                                        }
                                    }
                                    if (grassGradient != null)
                                    {
                                        PlantAVegetation(startX, startZ, ix, iz, iScl, grassGradient.PlantDescArrayValues, tileHeightBuf, 1.7f, outlstTreeInfo);
                                    }
                                }
                            }
                        }
                    }
                }

                // legacy grass
                // new grass

                // greed>30 no new grass
                if (gradTan >= noVegeTan2)
                {
                    continue;
                }
                if (veges2 != null)
                {
                    //新草的空间单位
                    if (0 == ix % veges2.cellSize && 0 == iz % veges2.cellSize)
                    {
                        if (noise256 >= veges2.start || (noise256 > veges2.startFadeIn && myRand.NextDouble() <= (noise256 - veges2.startFadeIn) / (veges2.start - veges2.startFadeIn)))
                        {
                            foreach (VoxelPaintXML.PlantHeightDesc heightDesc in veges2.PlantHeightDescValues)
                            {
                                if (heightDesc.start <= fy && heightDesc.end > fy)
                                {
                                    newGrassHeight = heightDesc;
                                }
                            }
                            if (newGrassHeight != null)
                            {
                                foreach (VoxelPaintXML.PlantGradientDesc GradientDesc in newGrassHeight.PlantGradientDescValues)
                                {
                                    if (GradientDesc.start <= gradTan && GradientDesc.end > gradTan)
                                    {
                                        newGrassGradient = GradientDesc;
                                    }
                                }
                                if (newGrassGradient != null)
                                {
                                    float fDensity = ((float)noise256 - veges2.startFadeIn) / (veges0.start - veges0.startFadeIn);
                                    if (fDensity > 1.0f)
                                    {
                                        fDensity = 1.0f;
                                    }
                                    PlantANewGrass(startX, startZ, ix, iz, fDensity, newGrassGradient.PlantDescArrayValues, tileHeightBuf, outlstGrassInst);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    public void PlantGrass(VFTile terTile, double[][] tileNoiseBuf, float[][] tileHeightBuf, float[][] tileGradTanBuf,
                           List <VoxelGrassInstance> outlstGrassInst, RandomMapType[][] tileMapType, int szCell)
    {
        int startX = terTile.tileX << VoxelTerrainConstants._shift;
        int startZ = terTile.tileZ << VoxelTerrainConstants._shift;

        //int iScl = 1 << terTile.tileL;
        for (int iz = 0; iz < VoxelTerrainConstants._numVoxelsPerAxis; iz += szCell)
        {
            int      idxZ        = iz + VoxelTerrainConstants._numVoxelsPrefix;
            double[] xNoiseBuf   = tileNoiseBuf[idxZ];
            float[]  xHeightBuf  = tileHeightBuf[idxZ];
            float[]  xGradTanBuf = tileGradTanBuf[idxZ];
            byte[][] xyVoxels    = terTile.terraVoxels[idxZ];
            for (int ix = 0; ix < VoxelTerrainConstants._numVoxelsPerAxis; ix += szCell)
            {
                int    idxX    = ix + VoxelTerrainConstants._numVoxelsPrefix;
                float  fy      = xHeightBuf[idxX];
                byte[] yVoxels = xyVoxels[idxX];
                byte   vType   = yVoxels[((int)fy) * VFVoxel.c_VTSize + 1];
                if (VFDataRTGen.IsNoPlantType(vType))
                {
                    continue;
                }

                float gradTan = xGradTanBuf[idxX];
                //坡度大于60度草树皆不刷
                if (gradTan >= noVegeTan1)
                {
                    continue;
                }
                // greed>30 no new grass
                if (gradTan >= noVegeTan2)
                {
                    continue;
                }

                curRegion = prms.RegionDescArrayValues[MapTypeToRegionId(tileMapType[iz][ix])];
                VoxelPaintXML.PlantDescArrayCLS veges2 = curRegion.newgrasses;
                if (veges2 != null)
                {
                    //新草的空间单位
                    if (0 == ix % veges2.cellSize && 0 == iz % veges2.cellSize)
                    {
                        double noise256 = (xNoiseBuf[idxX] + 1) * 128;
                        if (noise256 >= veges2.start || (noise256 > veges2.startFadeIn && myRand.NextDouble() <= (noise256 - veges2.startFadeIn) / (veges2.start - veges2.startFadeIn)))
                        {
                            VoxelPaintXML.PlantHeightDesc   newGrassHeight   = null;
                            VoxelPaintXML.PlantGradientDesc newGrassGradient = null;
                            foreach (VoxelPaintXML.PlantHeightDesc heightDesc in veges2.PlantHeightDescValues)
                            {
                                if (heightDesc.start <= fy && heightDesc.end > fy)
                                {
                                    newGrassHeight = heightDesc;
                                }
                            }
                            if (newGrassHeight != null)
                            {
                                foreach (VoxelPaintXML.PlantGradientDesc GradientDesc in newGrassHeight.PlantGradientDescValues)
                                {
                                    if (GradientDesc.start <= gradTan && GradientDesc.end > gradTan)
                                    {
                                        newGrassGradient = GradientDesc;
                                    }
                                }
                                if (newGrassGradient != null)
                                {
                                    float fDensity = ((float)noise256 - veges2.startFadeIn) / (veges2.start - veges2.startFadeIn);                                     /// old : veges0
                                    if (fDensity > 1.0f)
                                    {
                                        fDensity = 1.0f;
                                    }
                                    PlantANewGrass(startX, startZ, ix, iz, fDensity, newGrassGradient.PlantDescArrayValues, tileHeightBuf, outlstGrassInst);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
Exemple #22
0
    public void SetMapParam()
    {
        WeatherConfig.SetClimateType(ScenceClimate, vegetationId);
        SetTerrainHeight(terrainHeight, ScenceClimate);
        VFDataRTGen.SetRiverDensity(riverDensity);
        VFDataRTGen.SetRiverWidth(riverWidth);
        System.Random randTool = new System.Random(RandSeed);
        VFDataRTGen.SetPlainThickness(plainHeight);
//		VFDataRTGen.SetPlainMin((float)randTool.NextDouble());
//		VFDataRTGen.SetPlainMax((float)randTool.NextDouble());
        VFDataRTGen.SetFlatness(flatness);
        VFDataRTGen.SetFlatMin((float)randTool.NextDouble());
        VFDataRTGen.SetFlatMax((float)randTool.NextDouble());
        VFDataRTGen.SetBridgeMaxHeight(bridgeMaxHeight);
        //Debug.LogError(Mathf.Atan(1)*4);
        switch (mapSize)
        {
        case 0:
            //boundary
            SetBoundary(-20000, 20000, -20000, 20000, 200);
            //VFDataRTGen mineral
            VFDataRTGen.MetalReduceSwitch = false;
            VFDataRTGen.MetalReduceArea   = 4000;
            //VFDataRTGen.MineFrequency0 = 0.5;
            //VFDataRTGen.MineFrequency1 = 2;

            VFDataRTGen.SetMapTypeFrequency(1f);
            //VArtifactTownManager town level campDistance detectarea
            //SetTownBoundary(-19200, 19200, -19200, 19200);
            //VArtifactTownManager.Instance.LevelRadius = 4000;
            //SetTownDistance(1, 1);
            //VArtifactTownManager.Instance.DetectedChunkNum = 32;
            //allyCount=8;
            break;

        case 1:
            //boundary
            SetBoundary(-10000, 10000, -10000, 10000, 100);
            //VFDataRTGen mineral
            VFDataRTGen.MetalReduceSwitch = false;
            VFDataRTGen.MetalReduceArea   = 2000;
            //VFDataRTGen.MineFrequency0 = 0.5;
            //VFDataRTGen.MineFrequency1 = 2;

            VFDataRTGen.SetMapTypeFrequency(1f);
            //VArtifactTownManager town level
            //SetTownBoundary(-9600, 9600, -9600, 9600);
            //VArtifactTownManager.Instance.LevelRadius = 2000;
            //SetTownDistance(1, 1);
            //VArtifactTownManager.Instance.DetectedChunkNum = 32;
            //allyCount=8;
            break;

        case 2:
            //boundary
            SetBoundary(-4000, 4000, -4000, 4000, 40);
            //VFDataRTGen mineral
            VFDataRTGen.MetalReduceSwitch = false;
            //VFDataRTGen.MineFrequency0 = 0.25;
            //VFDataRTGen.MineFrequency1 = 0.25;
            //maptype
            VFDataRTGen.SetMapTypeFrequency(1.5f);
            //VFDataRTGen.SetTerrainFrequency(1.5f);
            //VArtifactTownManager town level campDistance detectarea
            //SetTownBoundary(-3860, 3860, -3860, 3860);
            //VArtifactTownManager.Instance.LevelRadius = 800;
            //SetTownDistance(0.5f, 0.8f);
            //VArtifactTownManager.Instance.DetectedChunkNum = 16;
            //allyCount=8;
            break;

        case 3:
            //boundary
            SetBoundary(-2000, 2000, -2000, 2000, 20);
            //VFDataRTGen mineral
            VFDataRTGen.MetalReduceSwitch = false;
            //VFDataRTGen.MineFrequency0 = 1;
            //VFDataRTGen.MineFrequency1 = 2;
            VFDataRTGen.SetMapTypeFrequency(3f);
            //VFDataRTGen.SetTerrainFrequency(3f);
            //VArtifactTownManager town level campDistance detectarea
            //SetTownBoundary(-1920, 1920, -1920, 1920);
            //VArtifactTownManager.Instance.LevelRadius = 400;
            //SetTownDistance(0.5f, 0.8f);
            //VArtifactTownManager.Instance.DetectedChunkNum = 12;
            //allyCount=4;
            break;

        case 4:
            //boundary
            SetBoundary(-1000, 1000, -1000, 1000, 10);
            //VFDataRTGen mineral
            VFDataRTGen.MetalReduceSwitch = false;
            //VFDataRTGen.MineFrequency0 = 1;
            //VFDataRTGen.MineFrequency1 = 2;
            VFDataRTGen.SetMapTypeFrequency(3f);
            //VFDataRTGen.SetTerrainFrequency(3f);
            //VArtifactTownManager town level campDistance detectarea
            //SetTownBoundary(-960, 960, -960, 960);
            //VArtifactTownManager.Instance.LevelRadius = 200;
            //SetTownDistance(0.25f, 0.8f);
            //VArtifactTownManager.Instance.DetectedChunkNum = 6;
            //allyCount=4;
            break;
        }
        //VFDataRTGen.TestMapBound();

        Debug.Log("<color=red>SeedString:" + SeedString
                  + "terrainHeight:" + terrainHeight
                  + "mapsize: " + mapSize
                  + ", riverdensity: " + riverDensity
                  + ", riverwidth: " + riverWidth
                  + "plainHeight:" + plainHeight
                  + "flatness:" + flatness
                  + "bridgemaxheight:" + bridgeMaxHeight
                  + "allyCount" + allyCount
                  + "</color>");


        VFVoxelWater.c_fWaterLvl = VFDataRTGen.WaterHeightBase;
        if (ScenceClimate == ClimateType.CT_Wet)
        {
            System.Random waterseed = new System.Random(RandSeed);
            int           waterplus = waterseed.Next(VFDataRTGen.WET_WATER_PLUS_MIN, VFDataRTGen.WET_WATER_PLUS_MAX);
            VFVoxelWater.c_fWaterLvl += waterplus;
        }
        else if (ScenceClimate == ClimateType.CT_Temperate)
        {
            System.Random waterseed = new System.Random(RandSeed);
            int           waterplus = waterseed.Next(VFDataRTGen.TEMP_WATER_PLUS_MIN, VFDataRTGen.TEMP_WATER_PLUS_MAX);
            VFVoxelWater.c_fWaterLvl += waterplus;
        }
        VFDataRTGen.sceneClimate = ScenceClimate;
        VFDataRTGen.waterHeight  = VFVoxelWater.c_fWaterLvl;
        VFDataRTGen.InitStaticParam(RandSeed);
        SetGlobalFogHeight(VFDataRTGen.waterHeight);
    }