コード例 #1
0
        public static WorldObjectData GetData(string name)
        {
            WorldObjectData data = null;

            switch (name)
            {
            case "Person":
                data = new PersonData();
                break;

            case "Castle":
                data = new CastleData();
                break;

            case "Tree":
                data = new TreeData();
                break;

            case "Rock":
                data = new RockData();
                break;

            case "Trap":
                data = new TrapData();
                break;

            case "FakeTree":
                data = new FakeTreeData();
                break;

            case "Cottage":
                data = new CottageData();
                break;

            case "Candle":
                data = new CandleData();
                break;

            case "Water":
                data = new WaterData();
                break;

            case "Bridge":
                data = new BridgeData();
                break;

            default:
                break;
            }
            return(data);
        }
コード例 #2
0
        public void SetCastleForClient(IncomingMessage receivedMessage, Player p)
        {
            WorldObjectData data = WorldObjectData.GetData("Castle");

            //castle size
            size     = receivedMessage.ReadInt32();
            castleWO = new WorldObject[size];
            for (int index = 0; index < size; index++)
            {
                castleWO[index] = new WorldObject();
                Entity ent = new Entity();
                ent.Name = receivedMessage.ReadString();
                ent
                .AddComponent(castleWO[index]);
                castleWO[index].SetWoName(data.woName);
                castleWO[index].SetTraversable(data.traversable);
                castleWO[index].SetMobile(data.mobile);
                castleWO[index].SetHealth(data.health);
                castleWO[index].SetMaxHealth(data.maxHealth);
                castleWO[index].player = p;

                //castle part name
                ent
                .AddComponent(new SpriteRenderer())
                //castle part x
                //castle part y
                .AddComponent(new Transform2D
                {
                    Position  = Map.map.GetTilePosition(receivedMessage.ReadInt32(), receivedMessage.ReadInt32()),
                    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());
            }
        }
コード例 #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);
        }
コード例 #4
0
        private Entity Create(LayerTile tile, Player p)
        {
            if (tile != null)
            {
                WorldObjectData data   = WorldObjectData.GetData(creating);
                WorldObject     wo     = new WorldObject();
                Entity          entity = new Entity()
                                         .AddComponent(new Transform2D
                {
                    Position  = tile.LocalPosition,
                    DrawOrder = data.traversable ? 1f : 0.5f     //traversable should be rendered behind non traversable
                })
                                         .AddComponent(wo)
                                         .AddComponent(new FogRevealBehavior());
                data.AddTraits(entity);

                wo.SetWoName(creating);
                wo.SetTraversable(data.traversable);
                wo.SetMobile(data.mobile);
                wo.SetMaxHealth(data.maxHealth);
                wo.SetHealth(data.health);
                wo.player = p;
                bool canCreate = (!data.isBuilding || wo.player == null ||
                                  ((fog == null || fog.IsVisible(tile)) && wo.player.HasEnoughWood(data.woodRequired)));
                if (creating == "FakeTree")
                {
                    canCreate = canCreate && map.GetMobile(tile.X, tile.Y) == null;
                }
                //Has it passed all this requirements?Let's check the tiles
                if (canCreate)
                {
                    //Reset the requirements
                    canCreate = false;
                    //¿can it move?
                    if (data.mobile)
                    {
                        if (map.GetMobile(tile.X, tile.Y) == null)
                        {
                            if (data.traversable)
                            {
                                //traversable, mobile object
                                //Nothing like this
                                map.SetMobile(tile.X, tile.Y, wo);
                                canCreate = true;
                            }
                            else
                            {
                                //non traversable, mobile object
                                //Like person
                                if (!map.IsTileOccupied(tile.X, tile.Y) && (map.GetWorldObject(tile.X, tile.Y) == null || map.GetWorldObject(tile.X, tile.Y).IsTraversable(wo)))
                                {
                                    //must be free to create
                                    map.SetMobile(tile.X, tile.Y, wo);
                                    map.SetTileOccupied(tile.X, tile.Y, true);
                                    canCreate = true;
                                }
                            }
                        }
                        entity.AddComponent(new MovementBehavior())
                        .AddComponent(new DStarLite())
                        .AddComponent(new SwitchBehavior())
                        .AddComponent(new SpriteAtlas(WaveContent.Assets.persona_spritesheet))
                        .AddComponent(new SpriteAtlasRenderer())
                        .AddComponent(new Animation2D()
                        {
                            PlayAutomatically = false,
                        })
                        .AddComponent(new AnimationBehavior());
                    }
                    else
                    {
                        if ((map.GetWorldObject(tile.X, tile.Y) == null && creating != "Bridge") || (map.GetWorldObject(tile.X, tile.Y) != null && map.GetWorldObject(tile.X, tile.Y).GetWoName() == "Water" && creating == "Bridge"))
                        {
                            if (data.traversable)
                            {
                                //traversable, static object
                                //fake tree,traps
                                Trace.WriteLine(creating);
                                if (creating == "Bridge")
                                {
                                    WorldObject water = map.GetWorldObject(tile.X, tile.Y);
                                    entity.FindComponent <BridgeTraits>().water = water;
                                    water.Owner.IsVisible = false;
                                    map.SetTileOccupied(tile.X, tile.Y, false);
                                }
                                map.SetWorldObject(tile.X, tile.Y, wo);
                                canCreate = true;
                            }
                            else
                            {
                                //non-traversable, static object
                                //tree,rock
                                if (!map.IsTileOccupied(tile.X, tile.Y))
                                {
                                    //must be free to create
                                    map.SetWorldObject(tile.X, tile.Y, wo);
                                    map.SetTileOccupied(tile.X, tile.Y, true);
                                    canCreate = true;
                                }
                            }
                        }
                        entity.AddComponent(new SpriteRenderer())
                        .AddComponent(new Sprite(data.sprite));
                    }
                    //Has it passed all the requirements, including the tiles?Let's populate the entity with behaviors
                    if (canCreate)
                    {
                        if (data.isBuilding && wo.player != null)
                        {
                            wo.player.RemoveWood(data.woodRequired);
                        }
                        data.AddComponents(entity);
                        if (creating == "Person")
                        {
                            if (wo.player != null)
                            {
                                wo.player.GetPeople().Add(wo);
                            }
                        }


                        //From now on, we must set the visibility for those tiles visible, otherwise they must be not visible
                        //New fog of war handles this
                        entity.IsVisible = fog == null || (wo.IsVisible(activePlayer) && fog.IsVisible(tile.X, tile.Y));
                        Owner.Scene.EntityManager.Add(entity);

                        Uncheck();
                        //We update the tile visibility, in case it is revealed
                        if (fog != null)
                        {
                            fog.AddUpdatedTile(tile);
                        }
                    }
                    return(entity);
                }
            }
            return(null);
        }