Exemplo n.º 1
0
 private void ResetWarpAndSprite(PortalPosition portalPosition)
 {
     RemoveWarp(portalPosition);
     AddWarp(portalPosition);
     PortalSprites.RemovePortalSprite(portalPosition);
     PortalSprites.AddPortalSprite(portalPosition);
 }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 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
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
            }
        }
Exemplo n.º 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));
        }
Exemplo n.º 8
0
        /******************************************************************************
         * 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());
        }
Exemplo n.º 9
0
        /// <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);
        }
Exemplo n.º 10
0
        /// <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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 12
0
 public void AddPortal(PortalPosition portalPosition)
 {
     PortalGuns[portalPosition.PlayerIndex].AddPortal(portalPosition);
 }
Exemplo n.º 13
0
 public Warp GetWarp(PortalPosition portalPosition)
 {
     return(PortalGuns[portalPosition.PlayerIndex].GetWarp(portalPosition.Index));
 }
Exemplo n.º 14
0
        /******************************************************************************
         * Portal Sprite Removal
         *****************************************************************************/

        public bool RemovePortalSprite(PortalPosition portalPosition)
        {
            return(RemovePortalSprite(portalPosition.LocationName, portalPosition));
        }
Exemplo n.º 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));
 }
Exemplo n.º 16
0
 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));
 }
Exemplo n.º 17
0
 /// <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));
 }
Exemplo n.º 18
0
 /// <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 });
 }