private void ResetWarpAndSprite(PortalPosition portalPosition)
 {
     RemoveWarp(portalPosition);
     AddWarp(portalPosition);
     PortalSprites.RemovePortalSprite(portalPosition);
     PortalSprites.AddPortalSprite(portalPosition);
 }
Exemple #2
0
        /******************************************************************************
         * Portal Sprite Additions
         *****************************************************************************/

        public bool AddPortalSprite(PortalPosition portalPosition)
        {
            AddedPortalSprites.RemoveItem(portalPosition);

            ActivePortalSprites.RemoveItem(portalPosition);
            ActivePortalSprites.AddItem(portalPosition.LocationName, portalPosition);

            // sometimes the current location is null if loading is taking a while
            if (Game1.currentLocation != null &&
                portalPosition.LocationName != Game1.currentLocation.NameOrUniqueName)
            {
                portalPosition.AnimationFrame = PORTAL_ANIM_FRAMES - 1;
                AddedPortalSprites.AddItem(portalPosition.LocationName, portalPosition);
                return(false);
            }
            // animation frame 0 indicates the animation should be played
            else if (portalPosition.AnimationFrame == 0)
            {
                portalPosition.AnimationFrame = 0;
                AddedPortalSprites.RemoveItem(portalPosition);
                AnimatedPortals.AddItem(portalPosition.LocationName, portalPosition);
                return(true);
            }
            // place at full portal size
            else
            {
                portalPosition.AnimationFrame = PORTAL_ANIM_FRAMES - 1;
                PlacePortalSprite(portalPosition);
                AddedPortalSprites.RemoveItem(portalPosition);
            }
            return(true);
        }
        /// <summary>
        /// The main player removes the warp at the portalPosition
        /// </summary>
        public static bool RemoveWarp(PortalPosition portalPosition, bool IsMainPlayer, PortalGunManager portalGuns, IMultiplayerHelper multiplayer, string uniqueModId)
        {
            // Warps are global, so only have host handle them to avoid duplicates and ghosts
            if (!IsMainPlayer)
            {
                multiplayer.SendMessage(portalPosition, "RemoveWarp", modIDs: new[] { uniqueModId });
                return(false);
            }
            string locationName = portalPosition.LocationName;

            if (locationName == "" || locationName == null)
            {
                return(false);
            }
            GameLocation location = Game1.getLocationFromName(portalPosition.LocationName);

            // remove the warp from the location
            Warp warp = portalGuns.GetWarp(portalPosition);

            if (warp != null)
            {
                location.warps.Remove(portalGuns.GetWarp(portalPosition));
            }

            return(true);
        }
Exemple #4
0
        private int GetPortalSpriteIndex(PortalPosition portalPosition)
        {
            int portalSpriteIndex =
                portalPosition.PlayerIndex * 10             // player's portals
                + portalPosition.Index * 5                  // portal color offset
                + portalPosition.AnimationFrame;            // animation frame

            return(portalSpriteIndex % MAX_PORTAL_SPRITES); // for overflow
        }
        public bool AddPortal(PortalPosition portalPos)
        {
            /*// sanitization for multiplayer
             * if (!ValidPortalPos(portalPos))
             *  return false;*/

            portals[portalPos.Index].PortalPos = portalPos;

            RemoveWarps(); // set warps to null
            CreateWarps(); // create new based on new portalPos

            return(true);
        }
        public PortalPosition NewPortalPosition(int index)
        {
            PortalPosition portal = new PortalPosition(index, this.Name, this.PlayerIndex,
                                                       (int)Game1.currentCursorTile.X, (int)Game1.currentCursorTile.Y, Game1.currentLocation.NameOrUniqueName);

            if (ValidPortalPos(portal))
            {
                return(portal);
            }

            else
            {
                return(null);
            }
        }
Exemple #7
0
        private void PlacePortalSprite(PortalPosition portalPosition)
        {
            // remove the existing sprite from the map
            try
            {
                Game1.getLocationFromName(portalPosition.LocationName).removeTile(
                    portalPosition.X, portalPosition.Y, "Buildings");
            }
            catch (IndexOutOfRangeException) { }

            // Add the sprite to the map
            Layer     layer     = Game1.getLocationFromName(portalPosition.LocationName).map.GetLayer("Buildings");
            TileSheet tileSheet = Game1.getLocationFromName(portalPosition.LocationName).map.GetTileSheet("z_portal-spritesheet");

            layer.Tiles[portalPosition.X, portalPosition.Y] = new StaticTile(
                layer, tileSheet, BlendMode.Additive, GetPortalSpriteIndex(portalPosition));
        }
        /******************************************************************************
         * Portal Addition and Placement
         *****************************************************************************/
        /// <summary>
        /// After player has used the tool/action button, check all conditions for
        /// placing a portal
        /// </summary>
        /// <param name="e"></param>
        private void PortalSpawner(ButtonPressedEventArgs e)
        {
            if (Game1.menuUp || Game1.activeClickableMenu != null ||
                Game1.isFestival() || Game1.player.ActiveObject == null ||
                !Game1.player.CurrentItem.DisplayName.Contains("Portal Gun"))
            {
                return;
            }

            // determine which portal was shot
            int portalIndex = 0;

            if (e.Button.IsUseToolButton())
            {
                portalIndex = 0;
            }

            else if (e.Button.IsActionButton())
            {
                portalIndex = 1;
            }

            // animate player
            Game1.switchToolAnimation();

            // create a new portal at the cursor position with the given index
            PortalPosition portalPos = PortalGuns.NewPortalPosition(PlayerIndex, portalIndex);

            // portal could not be created at the given position
            if (portalPos == null)
            {
                this.Monitor.Log("portalPosition is null", LogLevel.Debug);
                return;
            }
            // remove the original portal if any
            RemoveWarpAndSprite(PortalGuns.GetPortalPosition(PlayerIndex, portalIndex));
            // set the portal to animate opening when placed
            portalPos.AnimationFrame = 0;
            // add the portal to the world
            AddPortal(portalPos);
            // play the portal shooting sound
            Game1.currentLocation.playSoundAt("debuffSpell", Game1.player.getTileLocation());
        }
        /// <summary>
        /// Places a portal at portalPosition
        /// Prerequisites: the player has shot a portal into a valid location and
        ///  tile position
        /// </summary>
        private void AddPortal(PortalPosition portalPosition)
        {
            // remove the target's warp
            PortalPosition targetPortalPos = PortalGuns.GetTargetPortal(portalPosition).PortalPos;

            RemoveWarp(targetPortalPos);

            // assign the portal to the gun to handle the targeting warp structure
            //   but not any of the map placement
            PortalGuns.AddPortal(portalPosition);
            this.Helper.Multiplayer.SendMessage(portalPosition, "UpdateAddPortal", modIDs: new[] { this.ModManifest.UniqueID });

            // add the new target portal's warp and sprites
            AddWarp(targetPortalPos);

            // remove the original portal
            RemoveWarpAndSprite(portalPosition);

            // add the placed portal's warps and sprites
            AddWarpAndSprite(portalPosition);
        }
        /// <summary>
        /// The main player adds the warp to the world
        /// </summary>
        public static bool AddWarp(PortalPosition portalPosition, bool IsMainPlayer, PortalGunManager portalGuns, IMultiplayerHelper multiplayer, string uniqueModId)
        {
            if (portalPosition.LocationName == "" || portalPosition.LocationName == null)
            {
                return(false);
            }
            // Warps are global, so only have host handle them to avoid duplicates and ghosts
            if (!IsMainPlayer)
            {
                multiplayer.SendMessage(portalPosition, "AddWarp", modIDs: new[] { uniqueModId });
                return(true);
            }
            // if a warp was created, add it
            Warp warp = portalGuns.GetWarp(portalPosition);

            if (warp == null)
            {
                return(false);
            }

            // add it to the game location
            Game1.getLocationFromName(portalPosition.LocationName).warps.Add(warp);
            return(true);
        }
Exemple #11
0
        public bool RemovePortalSprite(string locationName, PortalPosition portalPosition)
        {
            // if it has already been added previously (same indices, location, and coords) remove from queue
            AddedPortalSprites.RemoveItem(portalPosition);
            AnimatedPortals.RemoveItem(portalPosition);
            ActivePortalSprites.RemoveItem(portalPosition);

            if (Game1.currentLocation != null && locationName != Game1.currentLocation.NameOrUniqueName)
            {
                RemovedPortalSprites.AddItem(locationName, new PortalPosition(portalPosition));
                return(false);
            }
            else
            {
                try
                {
                    Game1.getLocationFromName(locationName).removeTile(portalPosition.X, portalPosition.Y, "Buildings");
                }
                catch (IndexOutOfRangeException) { }

                RemovedPortalSprites.RemoveItem(portalPosition);
            }
            return(true);
        }
Exemple #12
0
 public void AddPortal(PortalPosition portalPosition)
 {
     PortalGuns[portalPosition.PlayerIndex].AddPortal(portalPosition);
 }
Exemple #13
0
 public Warp GetWarp(PortalPosition portalPosition)
 {
     return(PortalGuns[portalPosition.PlayerIndex].GetWarp(portalPosition.Index));
 }
Exemple #14
0
        /******************************************************************************
         * Portal Sprite Removal
         *****************************************************************************/

        public bool RemovePortalSprite(PortalPosition portalPosition)
        {
            return(RemovePortalSprite(portalPosition.LocationName, portalPosition));
        }
Exemple #15
0
 /// <summary>
 /// Returns the portal the targeted by the passed portalPosition
 /// </summary>
 public Portal GetTargetPortal(PortalPosition portalPosition)
 {
     return(PortalGuns[portalPosition.PlayerIndex]
            .GetTargetPortal(portalPosition.Index));
 }
 private bool ValidPortalPos(PortalPosition portalPos)
 {
     return(Game1.getLocationFromName(portalPos.LocationName).isTileLocationTotallyClearAndPlaceable(portalPos.X, portalPos.Y) &&
            Game1.getLocationFromName(portalPos.LocationName).isTileLocationTotallyClearAndPlaceable(portalPos.X + 1, portalPos.Y));
 }
 /// <summary>
 /// The main player removes the warp at the portalPosition
 /// </summary>
 private bool RemoveWarp(PortalPosition portalPosition)
 {
     return(WarpManager.RemoveWarp(portalPosition, Context.IsMainPlayer, PortalGuns, this.Helper.Multiplayer, this.ModManifest.UniqueID));
 }
 /// <summary>
 /// Removes warp, sprite, and messsages other players to remove the sprite
 /// </summary>
 private void RemoveWarpAndSprite(PortalPosition portalPosition)
 {
     RemoveWarp(portalPosition);
     PortalSprites.RemovePortalSprite(portalPosition);
     this.Helper.Multiplayer.SendMessage(portalPosition, "RemovePortalSprite", modIDs: new[] { this.ModManifest.UniqueID });
 }