public bool Decorade(Chunk chunk, int x, int y, int z, IMTBRandom random)
        {
            corners.Clear();
            MTBPlantData data = MTBPlantDataManager.Instance.getData((int)_decorationType);

            int[] trunktemp      = data.leafWidth;
            int   treeCrownWidth = trunktemp.Length > 1 ? random.Range(trunktemp[0], trunktemp[1]) : trunktemp[0];

            trunktemp = data.chunkHeight;
            int treeHeight = trunktemp.Length > 1 ? random.Range(trunktemp[0], trunktemp[1]) : trunktemp[0];

            trunktemp = data.leafWidth;
            int treeCrownDepth = trunktemp.Length > 1 ? random.Range(trunktemp[0], trunktemp[1]) : trunktemp[0];

            trunktemp = data.leafHeight;
            int treeCrownHeight  = trunktemp.Length > 1 ? random.Range(trunktemp[0], trunktemp[1]) : trunktemp[0];
            int startLeaveHeight = data.leafOffset;

            if (!CheckCanGenerator(x, y, z, chunk, treeHeight, treeCrownWidth, treeCrownDepth, startLeaveHeight))
            {
                return(false);
            }
            CreateTree(x, y, z, chunk, treeHeight, treeCrownWidth, treeCrownHeight, treeCrownDepth, startLeaveHeight, random);
            return(true);
        }
        public void loadData()
        {
            XmlDocument dialogueData = new XmlDocument();

            dialogueData.LoadXml(Resources.Load(PLANTDATA_PATH).ToString());
            XmlNodeList nodeList = dialogueData.GetElementsByTagName("PlantData")[0].ChildNodes;

            foreach (XmlElement xe in nodeList)
            {
                MTBPlantData data = new MTBPlantData();
                data.decode(xe);
                PLANTDATALIST.Add(Convert.ToInt32(xe.GetAttribute("decorationType")), data);
                if (data.seedId != 0)
                {
                    PlantConfig.SeedlingList.Add(data.seedId, (DecorationType)data.decorationType);
                }
            }
        }
        ////把植物种植到场景中
        public void buildPlant(Vector3 position, DecorationType type = DecorationType.FaceTree, int aoId = 0, float growTime = 0)
        {
            MTBPlantData        data  = MTBPlantDataManager.Instance.getData((int)type);
            GrowDecorationParam paras = new GrowDecorationParam(data);

            if (aoId == 0)
            {
                paras.aoId = AoIdManager.instance.getAoId();
            }
            else
            {
                paras.aoId = aoId;
            }
            paras.growedTime = 0;
            paras.pos        = position;
            paras.random     = _random;
            int x      = ((int)position.x);
            int z      = ((int)position.z);
            int localx = x % Chunk.chunkWidth;
            int localz = z % Chunk.chunkDepth;

            localx = localx < 0 ? localx + Chunk.chunkWidth : localx;
            localz = localz < 0 ? localz + Chunk.chunkDepth : localz;
            Chunk chunk = World.world.GetChunk(x, (int)position.y, z);

            for (int y = (int)position.y + 5; y >= (int)position.y - 5; y--)
            {
                BlockType curType = chunk.GetBlock(localx, y, localz).BlockType;
                if (curType != BlockType.Air && curType != BlockType.StillWater)
                {
                    paras.loacalPos = new Vector3(localx, y + 1, localz);
                    GrowDecoration decoration = new GrowDecoration(paras);
                    World.world.CheckAndRecalculateMesh(x, y, z, World.world.GetBlock(x, y, z));
                    _plantMap.Add(paras.aoId, decoration);
                    AddToChunkMap(decoration);
                    return;
                }
            }
        }
Beispiel #4
0
        public bool Decorade(Chunk chunk, int x, int y, int z, IMTBRandom random)
        {
            MTBPlantData data = MTBPlantDataManager.Instance.getData((int)_decorationType);

            int[] trunktemp      = data.chunkWidth;
            int   treeTrunkWidth = trunktemp.Length > 1 ? random.Range(trunktemp[0], trunktemp[1]) : trunktemp[0];

            trunktemp = data.chunkHeight;
            int treeTrunkHeight = trunktemp.Length > 1 ? random.Range(trunktemp[0], trunktemp[1]) : trunktemp[0];

            trunktemp = data.leafWidth;
            int treeLeaveWidth = trunktemp.Length > 1 ? random.Range(trunktemp[0], trunktemp[1]) : trunktemp[0];

            trunktemp = data.leafHeight;
            int treeLeaveHeight = trunktemp.Length > 1 ? random.Range(trunktemp[0], trunktemp[1]) : trunktemp[0];
            int treeLeaveOffset = data.leafOffset;

            if (!CheckCanGenerator(x, y, z, chunk, treeTrunkWidth, treeTrunkHeight, treeLeaveWidth, treeLeaveHeight, treeLeaveOffset))
            {
                return(false);
            }
            return(CreateTree(x, y, z, chunk, treeTrunkWidth, treeTrunkHeight, treeLeaveWidth, treeLeaveHeight, treeLeaveOffset, random));
        }
Beispiel #5
0
        public bool Decorade(Chunk chunk, int x, int y, int z, IMTBRandom random)
        {
            MTBPlantData data = MTBPlantDataManager.Instance.getData((int)_decorationType);

            int[] trunktemp      = data.chunkWidth;
            int   treeTrunkWidth = trunktemp.Length > 1 ? random.Range(trunktemp[0], trunktemp[1]) : trunktemp[0];

            trunktemp = data.chunkHeight;
            int treeTrunkHeight = trunktemp.Length > 1 ? random.Range(trunktemp[0], trunktemp[1]) : trunktemp[0];

            trunktemp = data.leafWidth;
            int treeLeaveWidth = trunktemp.Length > 1 ? random.Range(trunktemp[0], trunktemp[1]) : trunktemp[0];

            trunktemp = data.leafHeight;
            int treeLeaveHeight = trunktemp.Length > 1 ? random.Range(trunktemp[0], trunktemp[1]) : trunktemp[0];
            int treeLeaveOffset = data.leafOffset;

            int treeHeight           = treeTrunkHeight + treeLeaveHeight + treeLeaveOffset;
            int treeTrunkStartHeight = y;
            int treeTrunkNextHeight  = y + treeTrunkHeight;
            int treeLeaveStartHeight = y + treeTrunkHeight + treeLeaveOffset;
            int treeLeaveNextHeight  = treeLeaveStartHeight + treeLeaveHeight;

            bool isTrunkWidthEvenNum = (treeTrunkWidth % 2 == 0);
            bool isLeaveWidthEvenNum = (treeLeaveWidth % 2 == 0);

            //调整树叶宽度
            if (isTrunkWidthEvenNum != isLeaveWidthEvenNum)
            {
                treeLeaveWidth++;
                isLeaveWidthEvenNum = !isLeaveWidthEvenNum;
            }

            int halfTreeTrunkWidth = treeTrunkWidth / 2;
            int trunkWidthStartX;
            int trunkWidthStartZ;
            int trunkWidthNextX;
            int trunkWidthNextZ;

            trunkWidthStartX = x - halfTreeTrunkWidth;
            trunkWidthStartZ = z - halfTreeTrunkWidth;
            trunkWidthNextX  = x + halfTreeTrunkWidth;
            trunkWidthNextZ  = z + halfTreeTrunkWidth;
            if (isTrunkWidthEvenNum)
            {
                trunkWidthNextX -= 1;
                trunkWidthNextZ -= 1;
            }

            int halfTreeLeaveWidth = treeLeaveWidth / 2;
            int leaveWidthStartX;
            int leaveWidthStartZ;
            int leaveWidthNextX;
            int leaveWidthNextZ;

            leaveWidthStartX = x - halfTreeLeaveWidth;
            leaveWidthStartZ = z - halfTreeLeaveWidth;
            leaveWidthNextX  = x + halfTreeLeaveWidth;
            leaveWidthNextZ  = z + halfTreeLeaveWidth;
            if (isLeaveWidthEvenNum)
            {
                leaveWidthNextX -= 1;
                leaveWidthNextZ -= 1;
            }

            if (!CheckCanGenerator(chunk, treeTrunkStartHeight, treeTrunkNextHeight, treeLeaveStartHeight, treeLeaveNextHeight,
                                   trunkWidthStartX, trunkWidthStartZ, trunkWidthNextX, trunkWidthNextZ, leaveWidthStartX,
                                   leaveWidthStartZ, leaveWidthNextX, leaveWidthNextZ))
            {
                return(false);
            }
            CreateTree(chunk, random, halfTreeTrunkWidth / 2 + 1, halfTreeLeaveWidth / 2, treeTrunkStartHeight, treeTrunkNextHeight, treeLeaveStartHeight, treeLeaveNextHeight,
                       trunkWidthStartX, trunkWidthStartZ, trunkWidthNextX, trunkWidthNextZ, leaveWidthStartX,
                       leaveWidthStartZ, leaveWidthNextX, leaveWidthNextZ);
            return(true);
        }
 public GrowDecorationParam(MTBPlantData data)
 {
     _plantData = data;
 }