Beispiel #1
0
        private void CreateDefaultDecorator(DecoratorData decorator)
        {
            // create decorator variable
            Add(new Variable("Skill.Framework.AI.Decorator", decorator.Name, "null"));
            // new decorator variable inside CreateTree method
            _CreateTreeMethodBody.AppendLine(string.Format("this.{0} = new Skill.Framework.AI.Decorator(\"{1}\",{2});", Variable.GetName(decorator.Name), decorator.Name, GetDecoratorHandlerName(decorator.Name)));
            // set property SuccessOnFailHandler
            if (decorator.NeverFail == true) // default value is false, so it is not necessary to set it
            {
                _CreateTreeMethodBody.AppendLine(SetProperty(decorator.Name, "NeverFail", decorator.NeverFail.ToString().ToLower()));
            }
            // set weight
            SetBehaviorParameters(decorator);
            // create decorator handler method
            Method m = new Method("bool", GetDecoratorHandlerName(decorator.Name), string.Empty, DecoratorHandlerParams)
            {
                IsPartial = _Tree.ExpandMethods
            };

            if (_Tree.ExpandMethods)
            {
                m.Body = CreateMethodBody(decorator, "return false;");
            }
            else
            {
                m.Body = string.Format("return OnDecorator( Decorators.{0}, sender ,  parameters);", decorator.Name);
            }
            Add(m);
        }
Beispiel #2
0
        private void CreateDecorator(DecoratorData decorator)
        {
            switch (decorator.Type)
            {
            case DecoratorType.Default:
                CreateDefaultDecorator(decorator);
                break;

            case DecoratorType.AccessLimit:
                CreateAccessLimitDecorator((AccessLimitDecoratorData)decorator);
                break;
            }
        }
Beispiel #3
0
    private IEnumerator GenerateMapHelper(float waitTime = 0.0f)
    {
        islandTileCount = new List <int>();
        islandIndex     = 0;
        int tileCount = 0;
        int islands   = 0;

        while (islands < islandCount && tileCount < mapSize.x * mapSize.y)
        {
            // Pick random coordinate
            int randX = UnityEngine.Random.Range(1, mapSize.x - 1);
            int randY = UnityEngine.Random.Range(1, mapSize.y - 1);
            if (map[randX, randY].tileObj == null)
            {
                GameObject startTile = MakeTile(randX, randY, TileType.LAND);
                IslandStart[islands] = startTile.transform.position;
                islands++;
                islandTileCount.Add(1);
                yield return(Grow(randX, randY, waitTime));

                islandIndex = islandTileCount.Count;
            }
        }

        for (int row = 0; row < mapSize.x; row++)
        {
            for (int col = 0; col < mapSize.y; col++)
            {
                if (map[row, col].tileObj != null)
                {
                    SpriteRenderer     spriteRender = map[row, col].tileObj.GetComponentInChildren <SpriteRenderer>();
                    Vector3            rotation;
                    SpriteTileEdgeType spriteType = DetermineEdge(row, col, out rotation);
                    if (spriteType != SpriteTileEdgeType.LAND && spriteType != SpriteTileEdgeType.NUB)
                    {
                        map[row, col].isEdge = true;
                        spriteRender.sprite  = lowerLandData.outerTiles[(int)spriteType];
                    }
                    else if (spriteType == SpriteTileEdgeType.NUB)
                    {
                        map[row, col].isEdge  = true;
                        spriteRender.sprite   = lowerLandData.innerTiles[1];
                        map[row, col].isBoard = true;
                        map[row, col].tileObj.gameObject.layer = LayerMask.NameToLayer("Boarding");
                        map[row, col].tileObj.gameObject.GetComponent <BoxCollider>().isTrigger = true;
                    }
                    else
                    {
                        spriteRender.sprite = lowerLandData.innerTiles[0];
                    }

                    if (rotation != Vector3.zero || spriteType == SpriteTileEdgeType.NUB)
                    {
                        rotation = new Vector3(-90f, rotation.y, 0);
                        spriteRender.transform.rotation = Quaternion.Euler(rotation);
                    }
                    if (waitTime > 0 || iterCount++ % skipEvery == 0)
                    {
                        yield return(new WaitForSeconds(waitTime / 2));
                    }
                }
                else
                {
                    MakeTile(row, col, TileType.SEA);
                }
            }
        }

        for (int row = 0; row < mapSize.x; row++)
        {
            for (int col = 0; col < mapSize.y; col++)
            {
                TileData tile = map[row, col];
                if (isLandTile(tile) && !tile.isEdge)
                {
                    SpriteRenderer      spriteRender = tile.tileObj.GetComponentInChildren <SpriteRenderer>();
                    SpriteTileInnerType spriteType   = DetermineSpriteInnerType(row, col);
                    if (spriteType != SpriteTileInnerType.LAND)
                    {
                        spriteRender.sprite = lowerLandData.edgeTiles[(int)spriteType];
                        if (waitTime > 0 || iterCount++ % skipEvery == 0)
                        {
                            yield return(new WaitForSeconds(waitTime / 2));
                        }
                    }
                }

                if (tile.isDecorated && !tile.isEdge)
                {
                    if (tile.type == TileType.LAND)
                    {
                        int           idx = UnityEngine.Random.Range(0, lowerLandData.decorators.Length);
                        DecoratorData d   = lowerLandData.decorators[idx].GetComponent <DecoratorData>();
                        if (UnityEngine.Random.value <= d.probability)
                        {
                            Instantiate(lowerLandData.decorators[idx], tile.tileObj.transform.position, lowerLandData.decorators[idx].transform.rotation);
                        }
                    }
                    else if (tile.type == TileType.SEA)
                    {
                        int           idx = UnityEngine.Random.Range(0, seaData.decorators.Length);
                        DecoratorData d   = seaData.decorators[idx].GetComponent <DecoratorData>();
                        if (UnityEngine.Random.value <= d.probability)
                        {
                            Instantiate(seaData.decorators[idx], tile.tileObj.transform.position, seaData.decorators[idx].transform.rotation);
                        }
                    }
                }
            }
        }

        isDone = true;
    }