protected static void Serialize(WorldPart worldPart, ref JObject jObject)
        {
            SerializationUtils.AddToObject(jObject, worldPart, worldPartType, serializeableProperties);

            // Serialize Ambient Objects
            JArray ambientObjects = new JArray();

            if (worldPart.AmbientObjects != null)
            {
                foreach (var ambientObject in worldPart.AmbientObjects)
                {
                    ambientObjects.Add(WorldObjectSerializer.Serialize(ambientObject));
                }
            }

            jObject.Add("AmbientObjects", ambientObjects);

            // Serialize Hitable Objects
            JArray containedObjects = new JArray();

            if (worldPart.ContainedObjects != null)
            {
                foreach (var containedObject in worldPart.ContainedObjects)
                {
                    if (containedObject is DurableEntity)
                    {
                        continue;
                    }

                    containedObjects.Add(WorldObjectSerializer.Serialize(containedObject));
                }
            }

            jObject.Add("ContainedObjects", containedObjects);
        }
Beispiel #2
0
 public PageException(OperationType operationType, WorldPart worldPart, GameVersion version) : base
     (
         "Отсутствуют URL адрес удовлетворяющий условию поиска. \n" +
         $"Операция: {operationType.ToString()}\n" +
         $"Расположение сервера: {worldPart.ToString()}\n" +
         $"Версия игры: {version}\n", ExceptionType.Constant
     )
 {
 }
Beispiel #3
0
    public void SpawnNext(GameObject part)
    {
        Vector3 newPos = part.transform.position;

        newPos.x += step;

        WorldPart nextPart = Instantiate(prefab, newPos, Quaternion.identity).GetComponent <WorldPart>();

        nextPart.previousPart = part;
    }
Beispiel #4
0
        private void handleChangePersistencyBtn()
        {
            var       player           = SimulationGame.Player;
            WorldPart currentWorldPart = player.InteriorID == Interior.Outside ? (WorldPart)SimulationGame.World.GetFromRealPoint((int)player.Position.X, (int)player.Position.Y) : SimulationGame.World.InteriorManager.Get(player.InteriorID);

            currentWorldPart.SetPersistent(!currentWorldPart.IsPersistent);

            if (currentWorldPart is WorldGridChunk)
            {
                var chunkPoint = GeometryUtils.GetChunkPosition((int)player.Position.X, (int)player.Position.Y, WorldGrid.WorldChunkPixelSize.X, WorldGrid.WorldChunkPixelSize.Y);

                WorldLoader.SaveWorldGridChunk(chunkPoint.X, chunkPoint.Y, (WorldGridChunk)currentWorldPart);
                WorldLoader.SaveWalkableGridChunk(chunkPoint.X, chunkPoint.Y, (WalkableGridChunk)SimulationGame.World.WalkableGrid.GetFromRealPoint(chunkPoint.X, chunkPoint.Y));
            }
            else
            {
                WorldLoader.SaveInterior(SimulationGame.World.InteriorManager.Get(player.InteriorID));
            }
        }
        protected static void Deserialize(ref JObject jObject, WorldPart worldPart)
        {
            SerializationUtils.SetFromObject(jObject, worldPart, worldPartType, serializeableProperties);

            // Deserialize Ambient Objects
            JArray ambientObjects = (JArray)jObject.GetValue("AmbientObjects");

            foreach (var ambientObject in ambientObjects)
            {
                worldPart.AddAmbientObject((AmbientObject)WorldObjectSerializer.Deserialize((JObject)ambientObject));
            }

            // Deserialize Hitable Objects
            JArray containedObjects = (JArray)jObject.GetValue("ContainedObjects");

            foreach (var containedObject in containedObjects)
            {
                worldPart.AddContainedObject((HitableObject)WorldObjectSerializer.Deserialize((JObject)containedObject));
            }
        }
Beispiel #6
0
        public override void Update(GameTime gameTime)
        {
            if (SimulationGame.IsWorldBuilderOpen)
            {
                base.Update(gameTime);

                setSelectedButtonColor();

                if (placementType != PlacementType.NoType && placementType != PlacementType.Inspect && placementType != PlacementType.WorldPartDetails)
                {
                    switch (placementMode)
                    {
                    case PlacementMode.Manage:
                        manageObjectList.Update(gameTime);

                        if (manageObjectList.SelectedElement != null)
                        {
                            editBtn.Update(gameTime);
                            createNewFromBtn.Update(gameTime);
                            removeBtn.Update(gameTime);
                        }
                        break;

                    case PlacementMode.ChooseTileset:
                        tilesetSelectionList.Update(gameTime);
                        break;

                    case PlacementMode.CreateFromTileset:
                        tileSetSelectionView.Update(gameTime);

                        if (tileSetSelectionView.SelectedSpritePosition != null)
                        {
                            createBtn.Update(gameTime);
                            createIfNotExistBtn.Update(gameTime);
                        }

                        break;
                    }

                    manageBtn.Update(gameTime);
                    createFromJsonBtn.Update(gameTime);

                    if (placementType != PlacementType.LivingEntityPlacement)
                    {
                        createFromTilesetBtn.Update(gameTime);
                    }
                }
                else if (placementType == PlacementType.WorldPartDetails)
                {
                    changePersistencyBtn.Update(gameTime);
                    createWorldLinkBtn.Update(gameTime);
                    createInteriorBtn.Update(gameTime);

                    if (SimulationGame.Player.InteriorID != Interior.Outside)
                    {
                        changeInteriorDimensionsBtn.Update(gameTime);
                        removeInteriorBtn.Update(gameTime);
                    }

                    var       player           = SimulationGame.Player;
                    WorldPart currentWorldPart = player.InteriorID == Interior.Outside ? (WorldPart)SimulationGame.World.GetFromRealPoint((int)player.Position.X, (int)player.Position.Y) : SimulationGame.World.InteriorManager.Get(player.InteriorID);

                    worldPartDetailsTextView.SetText(
                        "CurrentBlock: " + player.BlockPosition.X + "," + player.BlockPosition.Y + "\n" +
                        "IsPersistent: " + currentWorldPart.IsPersistent + "\n" +
                        "InteriorID: " + player.InteriorID + "\n" +
                        (player.InteriorID != Interior.Outside ? ("Dimensions: " + ((Interior)currentWorldPart).Dimensions + "\n") : "")
                        );
                    worldPartDetailsTextView.Update(gameTime);
                }
                else if (placementType == PlacementType.Inspect)
                {
                    if (inspectView.SelectedGameObjects.Count > 0)
                    {
                        selectedObjectDetailTextView.SetText(WorldObjectSerializer.Serialize(inspectView.SelectedGameObjects[0]).ToString(Formatting.Indented));

                        editInstanceBtn.Update(gameTime);
                        removeInstanceBtn.Update(gameTime);
                        showInstanceTypeBtn.Update(gameTime);
                    }
                    else if (inspectView.SelectedWorldLink != null)
                    {
                        selectedObjectDetailTextView.SetText(JToken.FromObject(inspectView.SelectedWorldLink, SerializationUtils.Serializer).ToString(Formatting.Indented));

                        editInstanceBtn.Update(gameTime);
                        removeInstanceBtn.Update(gameTime);
                    }

                    selectedObjectDetailTextView.Update(gameTime);
                }

                if ((placementMode == PlacementMode.Manage && manageObjectList.SelectedElement != null) ||
                    (placementMode == PlacementMode.CreateFromTileset && tileSetSelectionView.SelectedObject != null))
                {
                    placeView.Update(gameTime);
                }
                else
                {
                    inspectView.Update(gameTime);
                }
            }
        }
Beispiel #7
0
        public Actor(World world, ActorInit init) : base(init.Position, null)
        {
            World = world;

            Type     = init.Type;
            Team     = init.Team;
            IsPlayer = init.IsPlayer;
            IsBot    = init.IsBot;

            Height = init.Height;

            ID        = init.ID;
            this.init = init;

            CurrentTerrain = world.TerrainAt(TerrainPosition);

            // Parts
            partManager = new PartManager();
            foreach (var partinfo in init.Type.PartInfos)
            {
                if (partinfo is BotPartInfo && !IsBot)
                {
                    continue;
                }

                var part = partinfo.Create(this);
                partManager.Add(part);

                // Cache some important parts
                if (part is MobilePart mobile)
                {
                    Mobile = mobile;
                }
                if (part is MotorPart motor)
                {
                    Motor = motor;
                }
                else if (part is HealthPart health)
                {
                    Health = health;
                }
                else if (part is RevealsShroudPart revealsShroud)
                {
                    RevealsShroud = revealsShroud;
                }
                else if (part is WeaponPart weapon)
                {
                    Weapon = weapon;
                }
                else if (part is WorldPart worldPart)
                {
                    WorldPart = worldPart;
                }
                else if (part is BotPart botPart)
                {
                    Bot = botPart;
                }
                else if (part is PlayerSwitchPart)
                {
                    IsPlayerSwitch = true;
                }
            }

            if (IsBot && Bot == null)
            {
                IsBot = false;                 // BotPart is not there, thus there's no bot
            }
            if (IsPlayer)
            {
                partManager.Add(new PlayerPart(this));
            }

            tickParts         = partManager.GetPartsOrDefault <ITick>();
            editorTickParts   = partManager.GetPartsOrDefault <ITickInEditor>();
            renderParts       = partManager.GetPartsOrDefault <IRenderable>();
            accelerationParts = partManager.GetPartsOrDefault <INoticeAcceleration>();
            moveParts         = partManager.GetPartsOrDefault <INoticeMove>();
            stopParts         = partManager.GetPartsOrDefault <INoticeStop>();

            Physics = Type.Physics == null ? SimplePhysics.Empty : new SimplePhysics(this, Type.Physics.Type);

            if (Health != null && init.Health >= 0f)
            {
                Health.RelativeHP = init.Health;
            }

            var hoverPart = GetPartOrDefault <HoverPart>();

            if (hoverPart != null)
            {
                Height = hoverPart.DefaultHeight;
            }
        }
Beispiel #8
0
        private void selectGameObjects(Rect selectionRect)
        {
            // Is Deselection Mode?
            if (SimulationGame.KeyboardState.IsKeyDown(Keys.LeftAlt) || SimulationGame.KeyboardState.IsKeyDown(Keys.RightAlt))
            {
                if (SimulationGame.Player.InteriorID == Interior.Outside)
                {
                    // Check collision with interactive && contained objects
                    Point chunkTopLeft     = GeometryUtils.GetChunkPosition(selectionRect.Left, selectionRect.Top, WorldGrid.WorldChunkPixelSize.X, WorldGrid.WorldChunkPixelSize.Y);
                    Point chunkBottomRight = GeometryUtils.GetChunkPosition(selectionRect.Right, selectionRect.Bottom, WorldGrid.WorldChunkPixelSize.X, WorldGrid.WorldChunkPixelSize.Y);

                    for (int chunkX = chunkTopLeft.X - 1; chunkX <= chunkBottomRight.X + 1; chunkX++)
                    {
                        for (int chunkY = chunkTopLeft.Y - 1; chunkY <= chunkBottomRight.Y + 1; chunkY++)
                        {
                            WorldGridChunk worldGridChunk = SimulationGame.World.GetFromChunkPoint(chunkX, chunkY);

                            addSelectedObjectsFromWorldPart(selectionRect, worldGridChunk, true);
                        }
                    }
                }
                else
                {
                    addSelectedObjectsFromWorldPart(selectionRect, SimulationGame.World.InteriorManager.Get(SimulationGame.Player.InteriorID), true);
                }

                if (SelectedGameObjects.Count > 0)
                {
                    gameObjectSelection?.Invoke(SelectedGameObjects);
                }
            }
            else
            {
                if (SimulationGame.KeyboardState.IsKeyDown(Keys.LeftShift) == false && SimulationGame.KeyboardState.IsKeyDown(Keys.RightShift) == false)
                {
                    SelectedBlockPosition = Point.Zero;
                    SelectedBlockType     = null;
                    SelectedWorldLink     = null;
                    SelectedGameObjects.Clear();
                }

                if (SimulationGame.Player.InteriorID == Interior.Outside)
                {
                    // Check collision with interactive && contained objects
                    Point chunkTopLeft     = GeometryUtils.GetChunkPosition(selectionRect.Left, selectionRect.Top, WorldGrid.WorldChunkPixelSize.X, WorldGrid.WorldChunkPixelSize.Y);
                    Point chunkBottomRight = GeometryUtils.GetChunkPosition(selectionRect.Right, selectionRect.Bottom, WorldGrid.WorldChunkPixelSize.X, WorldGrid.WorldChunkPixelSize.Y);

                    for (int chunkX = chunkTopLeft.X - 1; chunkX <= chunkBottomRight.X + 1; chunkX++)
                    {
                        for (int chunkY = chunkTopLeft.Y - 1; chunkY <= chunkBottomRight.Y + 1; chunkY++)
                        {
                            WorldGridChunk worldGridChunk = SimulationGame.World.GetFromChunkPoint(chunkX, chunkY);

                            addSelectedObjectsFromWorldPart(selectionRect, worldGridChunk);
                        }
                    }
                }
                else
                {
                    addSelectedObjectsFromWorldPart(selectionRect, SimulationGame.World.InteriorManager.Get(SimulationGame.Player.InteriorID));
                }

                if (SelectedGameObjects.Count == 0)
                {
                    WorldPart worldPart = (SimulationGame.Player.InteriorID == Interior.Outside) ? SimulationGame.World.GetFromRealPoint((int)selectionRect.X, (int)selectionRect.Y) : (WorldPart)SimulationGame.World.InteriorManager.Get(SimulationGame.Player.InteriorID);

                    if (worldPart.WorldLinks != null)
                    {
                        foreach (var worldLinkItem in worldPart.WorldLinks)
                        {
                            Rect renderPosition = new Rect(worldLinkItem.Value.FromBlock.X * WorldGrid.BlockSize.X, worldLinkItem.Value.FromBlock.Y * WorldGrid.BlockSize.Y, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y);

                            if (renderPosition.Contains(selectionRect.GetPosition()))
                            {
                                SelectedWorldLink = worldLinkItem.Value;
                                worldLinkSelection?.Invoke(SelectedWorldLink);

                                return;
                            }
                        }
                    }

                    // We get the block
                    SelectedBlockPosition = GeometryUtils.GetBlockFromReal((int)SimulationGame.RealWorldMousePosition.X, (int)SimulationGame.RealWorldMousePosition.Y);
                    SelectedBlockType     = BlockType.lookup[SimulationGame.World.GetBlockType(SelectedBlockPosition.X, SelectedBlockPosition.Y, SimulationGame.Player.InteriorID)];

                    blockSelection?.Invoke(SelectedBlockType);
                }
                else
                {
                    gameObjectSelection?.Invoke(SelectedGameObjects);
                }
            }
        }
Beispiel #9
0
        private void addSelectedObjectsFromWorldPart(Rect selectionRect, WorldPart worldPart, bool deselect = false)
        {
            if (worldPart.AmbientObjects != null)
            {
                foreach (var ambientObject in worldPart.AmbientObjects)
                {
                    var ambientObjectType = AmbientObjectType.lookup[ambientObject.AmbientObjectType];
                    var renderPosition    = new Rect((int)(ambientObject.Position.X - ambientObjectType.SpriteOrigin.X), (int)(ambientObject.Position.Y - ambientObjectType.SpriteOrigin.Y), ambientObjectType.SpriteBounds.X, ambientObjectType.SpriteBounds.Y);

                    if (renderPosition.Intersects(selectionRect))
                    {
                        if (deselect)
                        {
                            SelectedGameObjects.Remove(ambientObject);
                        }
                        else
                        {
                            SelectedGameObjects.Add(ambientObject);
                        }
                    }
                }
            }

            if (worldPart.ContainedObjects != null)
            {
                foreach (var hitableObject in worldPart.ContainedObjects)
                {
                    if (hitableObject is Player)
                    {
                        continue;
                    }

                    Rect renderPosition = Rect.Empty;

                    if (hitableObject is LivingEntity)
                    {
                        var livingEntity     = (LivingEntity)hitableObject;
                        var livingEntityType = LivingEntityType.lookup[livingEntity.LivingEntityType];

                        renderPosition = new Rect((int)(livingEntity.Position.X - livingEntityType.SpriteOrigin.X), (int)(livingEntity.Position.Y - livingEntityType.SpriteOrigin.Y), livingEntityType.SpriteBounds.X, livingEntityType.SpriteBounds.Y);
                    }
                    else if (hitableObject is AmbientHitableObject)
                    {
                        var ambientHitableObject     = (AmbientHitableObject)hitableObject;
                        var ambientHitableObjectType = AmbientHitableObjectType.lookup[ambientHitableObject.AmbientHitableObjectType];

                        renderPosition = new Rect((int)(ambientHitableObject.Position.X - ambientHitableObjectType.SpriteOrigin.X), (int)(ambientHitableObject.Position.Y - ambientHitableObjectType.SpriteOrigin.Y), ambientHitableObjectType.SpriteBounds.X, ambientHitableObjectType.SpriteBounds.Y);
                    }

                    if (renderPosition.Intersects(selectionRect))
                    {
                        if (deselect)
                        {
                            SelectedGameObjects.Remove(hitableObject);
                        }
                        else
                        {
                            SelectedGameObjects.Add(hitableObject);
                        }
                    }
                }
            }

            if (worldPart is WorldGridChunk)
            {
                var worldGridChunk = ((WorldGridChunk)worldPart);

                if (worldGridChunk.OverlappingObjects != null)
                {
                    foreach (var hitableObject in worldGridChunk.OverlappingObjects)
                    {
                        if (hitableObject is Player)
                        {
                            continue;
                        }

                        Rect renderPosition = Rect.Empty;

                        if (hitableObject is LivingEntity)
                        {
                            var livingEntity     = (LivingEntity)hitableObject;
                            var livingEntityType = LivingEntityType.lookup[livingEntity.LivingEntityType];

                            renderPosition = new Rect((int)(livingEntity.Position.X - livingEntityType.SpriteOrigin.X), (int)(livingEntity.Position.Y - livingEntityType.SpriteOrigin.Y), livingEntityType.SpriteBounds.X, livingEntityType.SpriteBounds.Y);
                        }
                        else if (hitableObject is AmbientHitableObject)
                        {
                            var ambientHitableObject     = (AmbientHitableObject)hitableObject;
                            var ambientHitableObjectType = AmbientHitableObjectType.lookup[ambientHitableObject.AmbientHitableObjectType];

                            renderPosition = new Rect((int)(ambientHitableObject.Position.X - ambientHitableObjectType.SpriteOrigin.X), (int)(ambientHitableObject.Position.Y - ambientHitableObjectType.SpriteOrigin.Y), ambientHitableObjectType.SpriteBounds.X, ambientHitableObjectType.SpriteBounds.Y);
                        }

                        if (renderPosition.Intersects(selectionRect))
                        {
                            if (deselect)
                            {
                                SelectedGameObjects.Remove(hitableObject);
                            }
                            else if (SelectedGameObjects.Contains(hitableObject) == false)
                            {
                                SelectedGameObjects.Add(hitableObject);
                            }
                        }
                    }
                }
            }
        }