Example #1
0
 void Awake()
 {
     for (int i = 0; i < gameObject.transform.childCount; i++)
     {
         GameObject g = gameObject.transform.GetChild(i).gameObject;
         if (g.GetComponent <CastlePart>() == null)
         {
             CastlePart castlePart = g.AddComponent <CastlePart>();
             castlePart.castle = this;
         }
     }
 }
Example #2
0
    private void newWoodForChoose()
    {
        newWood = Instantiate(WoodParts[Random.Range(0, WoodParts.Length)], newWoodPosition + new Vector3(-5, 0), Quaternion.identity);
        CastlePart castlePart = newWood.AddComponent <CastlePart>();

        castlePart.castle = this;
        castlePart.setNew();

        var pos = newWoodPosition;

        pos.z += 0.1f;
        optionsPopUpInstance = Instantiate(optionsPopUpPrefab, pos, Quaternion.identity);
    }
Example #3
0
        public bool SetCastle(int xStart, int yStart, int width, int height, Player active, string playerID)
        {
            Map map = Map.map;

            if (map.InBounds(xStart, yStart) && map.InBounds(xStart + width - 1, yStart + height - 1))
            {
                WorldObjectData data = WorldObjectData.GetData("Castle");
                size = width * height;
                WorldObject[] parts = new WorldObject[size];
                int           index = 0;
                for (int i = xStart; i < xStart + width; i++)
                {
                    for (int j = yStart; j < yStart + height; j++)
                    {
                        if (map.GetWorldObject(i, j) != null)
                        {
                            size--;
                        }
                        else
                        {
                            parts[index] = new WorldObject();

                            Entity ent = new Entity()
                                         .AddComponent(parts[index]);
                            parts[index].SetWoName(data.woName);
                            parts[index].SetTraversable(data.traversable);
                            parts[index].SetMobile(data.mobile);
                            parts[index].SetHealth(data.health);
                            parts[index].SetMaxHealth(data.maxHealth);

                            parts[index].player = active;

                            ent
                            .AddComponent(new SpriteRenderer())
                            .AddComponent(new Transform2D
                            {
                                Position = map.GetTilePosition(i, j), DrawOrder = 1f
                            })
                            .AddComponent(new Sprite(data.sprite))
                            .AddComponent(new WorldObjectTraits())
                            .AddComponent(new FogRevealBehavior())
                            .AddComponent(new TransformSync())
                            .AddComponent(new WorldObjectSync())
                            .AddComponent(new SyncBehavior())
                            .AddComponent(new FogAdjacents());

                            CastlePart part = new CastlePart();
                            part.SetCastle(this);
                            ent.AddComponent(part);

                            ent.Name = ("WO-" + playerID + "-" + rnd.NextDouble() + "-" + data.woName);
                            map.SetWorldObject(i, j, parts[index]);

                            // for now, as this is traversable, we don't occupy the tile
                            // map.SetTileOccupied(i, j, true);

                            index++;
                        }
                    }
                }
                castleWO = new WorldObject[size];
                Array.Copy(parts, castleWO, size);
            }
            return(size > 0);
        }