Пример #1
0
        public void CreateCastleToTile(Player p, int x, int y, int castleWidth, int castleHeight)
        {
            if (!map.IsTileOccupied(x, y))
            {
                Castle castle = new Castle();
                Entity entity = new Entity()
                                .AddComponent(new Transform2D())
                                .AddComponent(castle);

                bool createdCastle = castle.SetCastle(x, y, castleWidth, castleHeight, p);
                if (createdCastle)
                {
                    Owner.Scene.EntityManager.Add(entity);
                    if (p != null)
                    {
                        p.castle = castle;
                    }
                    castle.player = p;
                }

                Uncheck();
            }
        }
Пример #2
0
        public void Destroy()
        {
            Map map = Map.map;

            if (!traversable)
            {
                map.SetTileOccupied(x, y, false);
            }
            if (mobile)
            {
                if (this.GetWoName() == "Person")
                {
                    if (player != null)
                    {
                        player.GetPeople().Remove(this);
                    }
                }
                MovementBehavior per = Owner.FindComponent <MovementBehavior>();
                if (per.nextTile != null)
                {
                    map.SetTileOccupied(per.nextTile.X, per.nextTile.Y, false);
                }
                map.SetMobile(x, y, null);
            }
            else if (this.GetWoName() == "Bridge")
            {
                WorldObject water = Owner.FindComponent <BridgeTraits>().water;
                water.Owner.IsVisible = true;
                map.SetWorldObject(x, y, water);
                WorldObject person = map.GetMobile(x, y);
                if (map.GetMobile(x, y) != null)
                {
                    person.Destroy();
                }
                map.SetTileOccupied(x, y, true);
            }
            else
            {
                map.SetWorldObject(x, y, null);
            }
            Player active = UIBehavior.ui.activePlayer;

            if (active != null && active.selectedWO == this)
            {
                active.selectedWO = null;
                UIBehavior.ui.ClearActionButtons();
            }

            if (Owner.Parent != null)
            {
                Castle c = Owner.Parent.FindComponent <Castle>();
                if (c != null)
                {
                    c.DestroyPart(this);
                }
                // For some reasons detach+remove do not work and persons keep fighting castles, so we must do this if else
                // and removechild already disposes the castle part
                if (!Owner.IsDisposed)
                {
                    Owner.Parent.RemoveChild(Owner.Name);
                }
            }
            else
            {
                EntityManager.Remove(Owner);
            }
        }
Пример #3
0
        /**
         * ClientDestroy
         */
        public void CDestroy()
        {
            if ((Owner.Scene as NetworkedScene).isHost)
            {
                Map map = Map.map;
                if (!IsTraversable(null))
                {
                    map.SetTileOccupied(x, y, false);
                    if (player != null)
                    {
                        player.GetPeople().Remove(this);
                    }
                }
                if (IsMobile())
                {
                    if (this.GetWoName() == "Person" && player != null)
                    {
                        player.GetPeople().Remove(this);
                    }

                    MovementBehavior per = Owner.FindComponent <MovementBehavior>();
                    if (per.nextTile != null)
                    {
                        map.SetTileOccupied(per.nextTile.X, per.nextTile.Y, false);
                    }
                    map.SetMobile(x, y, null);
                }
                else if (this.GetWoName() == "Bridge")
                {
                    WorldObject person = map.GetMobile(x, y);
                    if (map.GetMobile(x, y) != null)
                    {
                        //We must nullify the coordinates so that when it is destroyed,
                        //the tile from in the bridge will not be set free
                        map.SetMobile(person.GetX(), person.GetY(), null);
                        person.SetX(-1);
                        person.SetY(-1);

                        person.Destroy();
                    }
                    map.SetTileOccupied(x, y, true);
                    WorldObject water = Owner.FindComponent <BridgeTraits>().water;
                    water.Owner.IsVisible = true;
                    map.SetWorldObject(x, y, water);
                }
                else
                {
                    map.SetWorldObject(x, y, null);
                }
            }
            else
            {
                if (this.GetWoName() == "Bridge")
                {
                    //This makes water visible again in client
                    WorldObject water = Owner.FindComponent <BridgeTraits>().water;
                    water.Owner.IsVisible = true;
                }
            }

            Player active = UIBehavior.ui.activePlayer;

            if (active != null && active.selectedWO == this)
            {
                active.selectedWO = null;
                UIBehavior.ui.ClearActionButtons();
            }


            if (Owner.Parent != null)
            {
                Castle c = Owner.Parent.FindComponent <Castle>();
                if (c != null)
                {
                    c.DestroyPart(this);
                }
                // For some reasons detach+remove do not work and persons keep fighting castles, so we must do this if else
                // and removechild already disposes the castle part
                if (!Owner.IsDisposed)
                {
                    Owner.Parent.RemoveChild(Owner.Name);
                }
            }
            else
            {
                EntityManager.Remove(Owner);
            }
        }