예제 #1
0
        public override void KillTile(int i, int j, ref bool fail, ref bool effectOnly, ref bool noItem)
        {
            base.KillTile(i, j, ref fail, ref effectOnly, ref noItem);
            // make sure the MP client still gets the signal that the tile was killed.
            if (!fail)
            {
                if (Main.netMode == NetmodeID.MultiplayerClient)
                {
                    NetworkHelper.playerSync.SendDragonBallRemove(256, Main.myPlayer, WhichDragonBallAmI);
                }
                DBZWorld.GetWorld().RemoveDragonBallLocation(WhichDragonBallAmI, true);
            }
            // if we're in multiplayer let the server handle item drops.
            if (Main.netMode == NetmodeID.MultiplayerClient)
            {
                return;
            }
            if (!noItem)
            {
                Item.NewItem(i * 16, j * 16, 32, 48, drop);

                Player player = Main.player[Player.FindClosest(new Vector2(i * 16f, j * 16f), 1, 1)];
                if (player != null && WhichDragonBallAmI == 4)
                {
                    MyPlayer modplayer = player.GetModPlayer <MyPlayer>(mod);
                    if (!modplayer.FirstFourStarDBPickup && !noItem)
                    {
                        Item.NewItem(i * 16, j * 16, 32, 48, mod.ItemType("DBNote"));
                        modplayer.FirstFourStarDBPickup = true;
                    }
                }
            }
            noItem = true; // kill tile behavior overrides typical drops.
        }
예제 #2
0
 public override void PlaceInWorld(int i, int j, Item item)
 {
     base.PlaceInWorld(i, j, item);
     if (DebugUtil.IsDebugModeOn())
     {
         var oldTile = DBZWorld.GetWorld().GetDragonBallLocation(WhichDragonBallAmI);
         if (oldTile != new Point(-1, -1) && oldTile != new Point(i, j))
         {
             WorldGen.KillTile(oldTile.X, oldTile.Y, false, false, true);
             Main.NewText("Replaced the Old Dragon ball with this one.");
         }
         DebugUtil.Log(string.Format("Placing db in world: {0} {1}", i, j));
         DBZWorld.GetWorld().SetDragonBallLocation(WhichDragonBallAmI, new Point(i, j), true);
     }
     else
     {
         if (DBZWorld.IsExistingDragonBall(WhichDragonBallAmI))
         {
             WorldGen.KillTile(i, j, false, false, true);
             Main.NewText("Cheated Dragon Balls taste awful.");
         }
         else
         {
             DebugUtil.Log(string.Format("Placing db in world: {0} {1}", i, j));
             DBZWorld.GetWorld().SetDragonBallLocation(WhichDragonBallAmI, new Point(i, j), true);
         }
     }
 }
        public void HandleDestroyAndRespawnDragonBalls(BinaryReader reader, int fromWho)
        {
            DebugUtil.Log("Receiving despawn packet for dragon balls");
            int ignorePlayer = reader.ReadInt32();

            if (Main.netMode == NetmodeID.Server)
            {
                for (var i = 0; i < Main.player.Length; i++)
                {
                    if (Main.player[i] == null)
                    {
                        continue;
                    }
                    if (Main.player[i].whoAmI != i)
                    {
                        continue;
                    }
                    if (i == ignorePlayer)
                    {
                        continue;
                    }
                    SendDestroyAndRespawnDragonBalls(i, 256, ignorePlayer);
                }
            }

            DBZWorld.DestroyAndRespawnDragonBalls();
        }
        public void ReceiveDragonBallKeySync(BinaryReader reader, int fromWho)
        {
            var dbWorld = DBZWorld.GetWorld();
            var dbKey   = reader.ReadInt32();
            var db1X    = reader.ReadInt32();
            var db1Y    = reader.ReadInt32();
            var db2X    = reader.ReadInt32();
            var db2Y    = reader.ReadInt32();
            var db3X    = reader.ReadInt32();
            var db3Y    = reader.ReadInt32();
            var db4X    = reader.ReadInt32();
            var db4Y    = reader.ReadInt32();
            var db5X    = reader.ReadInt32();
            var db5Y    = reader.ReadInt32();
            var db6X    = reader.ReadInt32();
            var db6Y    = reader.ReadInt32();
            var db7X    = reader.ReadInt32();
            var db7Y    = reader.ReadInt32();

            dbWorld.SetDragonBallLocation(1, new Point(db1X, db1Y), false);
            dbWorld.SetDragonBallLocation(2, new Point(db2X, db2Y), false);
            dbWorld.SetDragonBallLocation(3, new Point(db3X, db3Y), false);
            dbWorld.SetDragonBallLocation(4, new Point(db4X, db4Y), false);
            dbWorld.SetDragonBallLocation(5, new Point(db5X, db5Y), false);
            dbWorld.SetDragonBallLocation(6, new Point(db6X, db6Y), false);
            dbWorld.SetDragonBallLocation(7, new Point(db7X, db7Y), false);
            dbWorld.WorldDragonBallKey = dbKey;
        }
예제 #5
0
        public void ReceiveDragonBallChange(BinaryReader reader, int fromWho)
        {
            DBZWorld world           = DBZWorld.GetWorld();
            var      whichDragonBall = reader.ReadInt32();
            var      locationX       = reader.ReadInt32();
            var      locationY       = reader.ReadInt32();

            world.CacheDragonBallLocation(whichDragonBall, new Point(locationX, locationY));
        }
예제 #6
0
        public override void KillTile(int i, int j, ref bool fail, ref bool effectOnly, ref bool noItem)
        {
            var kiBeaconLocation = new Vector2(i * 16f, j * 16f);

            DBZWorld.GetWorld().kiBeacons.Remove(kiBeaconLocation);
            if (Main.netMode == NetmodeID.MultiplayerClient)
            {
                NetworkHelper.playerSync.SendKiBeaconRemove(256, Main.myPlayer, kiBeaconLocation);
            }
        }
예제 #7
0
        public override void PlaceInWorld(int i, int j, Item item)
        {
            var kiBeaconLocation = new Vector2(i * 16f, j * 16f);

            DBZWorld.GetWorld().kiBeacons.Add(kiBeaconLocation);
            if (Main.netMode == NetmodeID.MultiplayerClient)
            {
                NetworkHelper.playerSync.SendKiBeaconAdd(256, Main.myPlayer, kiBeaconLocation);
            }
        }
예제 #8
0
 public override void UpdateInventory(Player player)
 {
     // world isn't loaded yet.
     if (DBZWorld.GetWorld().WorldDragonBallKey == 0)
     {
         return;
     }
     if (!RemoveThisDragonBallIfUnkeyed(player))
     {
         DoDragonBallLegitimacyCheck(player);
     }
 }
예제 #9
0
        // handle receiving ki beacon sync from the server.
        public void ReceiveKiBeaconInitialSync(BinaryReader reader, int toWho)
        {
            var dbWorld    = DBZWorld.GetWorld();
            var numIndexes = reader.ReadInt32();

            // presume whatever we have in ours is wrong and wipe it out.
            dbWorld.kiBeacons.Clear();
            for (var i = 0; i < numIndexes; i++)
            {
                var coordX = reader.ReadSingle();
                var coordY = reader.ReadSingle();
                dbWorld.kiBeacons.Add(new Vector2(coordX, coordY));
            }
        }
예제 #10
0
        public Vector2 SeekBeaconTarget(Vector2 cursorWorldPosition)
        {
            foreach (var beaconLocation in DBZWorld.GetWorld().KiBeacons)
            {
                var beaconCenter = beaconLocation + new Vector2(24, -24); // roughly half the size of a beacon, looking for its center, slightly "above" it.

                if (IsValidTarget(cursorWorldPosition, beaconCenter))
                {
                    return(beaconLocation + new Vector2(16, -48));
                }
            }

            return(Vector2.Zero);
        }
예제 #11
0
        // handle a single ki beacon update (including removals)
        public void ReceiveKiBeaconAdd(BinaryReader reader, int fromWho)
        {
            var coordX   = reader.ReadSingle();
            var coordY   = reader.ReadSingle();
            var location = new Vector2(coordX, coordY);
            var dbWorld  = DBZWorld.GetWorld();

            if (!dbWorld.kiBeacons.Contains(location))
            {
                dbWorld.kiBeacons.Add(location);
            }
            if (Main.netMode == NetmodeID.Server)
            {
                SendKiBeaconAdd(-1, fromWho, location);
            }
        }
        // handle a single ki beacon update (including removals)
        public void ReceiveDragonBallAdd(BinaryReader reader, int fromWho)
        {
            var whichDragonBall = reader.ReadInt32();
            var coordX          = reader.ReadInt32();
            var coordY          = reader.ReadInt32();

            DebugUtil.Log(string.Format("Receiving signal to add dragon ball {0} to {1} {2}", whichDragonBall, coordX, coordY));
            var location = new Point(coordX, coordY);
            var dbWorld  = DBZWorld.GetWorld();

            dbWorld.SetDragonBallLocation(whichDragonBall, location, false);
            if (Main.netMode == NetmodeID.Server)
            {
                SendDragonBallAdd(-1, fromWho, location, whichDragonBall);
            }
        }
예제 #13
0
        public void HandleDrawingKiBeacons()
        {
            Texture2D texture = DBZMOD.instance.GetTexture("UI/KiBeaconMap");

            // desperation starts here
            foreach (var beaconLocation in DBZWorld.GetWorld().KiBeacons)
            {
                // map coordinates represent the map tile being placed at *the center* of the screen.
                var mapX = Main.mapFullscreenPos.X;
                var mapY = Main.mapFullscreenPos.Y;

                // drawing, thus, is relative to the center, offset by the scaled distance between the target to render and the current map display "center".
                var mapOffsetX = Main.screenWidth / 2 + ((beaconLocation.X + 8f) - (mapX * 16f)) / (16 / Main.mapFullscreenScale);
                var mapOffsetY = Main.screenHeight / 2 + ((beaconLocation.Y - 8f) - (mapY * 16f)) / (16 / Main.mapFullscreenScale);
                Main.spriteBatch.Draw(texture, new Vector2(mapOffsetX, mapOffsetY), new Rectangle(0, 0, texture.Width, texture.Height), Color.White, 0f, texture.Size() * 0.5f, 1f, SpriteEffects.None, 0f);
            }
        }
예제 #14
0
        public void SetDragonBallWorldKey(Player player)
        {
            if (!IsItemStoneBall(item.type))
            {
                // we already have a dragon ball key, abandon ship.
                if (WorldDragonBallKey > 0)
                {
                    return;
                }

                // it's legit, set its dragon ball key
                var world = DBZWorld.GetWorld();

                WorldDragonBallKey = world.WorldDragonBallKey;
            }
            return;
        }
        // handle a single ki beacon update (including removals)
        public void ReceiveDragonBallRemove(BinaryReader reader, int fromWho)
        {
            var whichDragonBall = reader.ReadInt32();
            var dbWorld         = DBZWorld.GetWorld();
            var tileLocation    = dbWorld.GetDragonBallLocation(whichDragonBall);

            // our work here is done lol
            if (tileLocation.X == -1 && tileLocation.Y == -1)
            {
                return;
            }
            DebugUtil.Log(string.Format("Receiving signal to remove dragon ball {0}", whichDragonBall));
            DebugUtil.Log(string.Format("Calling kill tile at {0} {1}", tileLocation.X, tileLocation.Y));
            WorldGen.KillTile(tileLocation.X, tileLocation.Y, false, false, true);
            if (Main.netMode == NetmodeID.Server)
            {
                SendDragonBallRemove(-1, fromWho, whichDragonBall);
            }
        }
예제 #16
0
        public void SendAllDragonBallLocations(int toWho = -1)
        {
            if (Main.netMode != NetmodeID.Server)
            {
                return;
            }
            DBZWorld world = DBZWorld.GetWorld();

            for (var i = 0; i < world.CachedDragonBallLocations.Length; i++)
            {
                if (toWho == -1)
                {
                    SendDragonBallChange(i + 1, world.GetCachedDragonBallLocation(i + 1), 256);
                }
                else
                {
                    SendDragonBallChange(toWho, i + 1, world.GetCachedDragonBallLocation(i + 1));
                }
            }
        }
        public void ReceiveDragonBallKeySyncRequest(int toWho)
        {
            ModPacket packet  = GetPacket(SendDragonBallKeySync, 256);
            var       dbWorld = DBZWorld.GetWorld();

            packet.Write(dbWorld.WorldDragonBallKey);
            // new stuff, send the player all the dragon ball points.
            packet.Write(dbWorld.GetDragonBallLocation(1).X);
            packet.Write(dbWorld.GetDragonBallLocation(1).Y);
            packet.Write(dbWorld.GetDragonBallLocation(2).X);
            packet.Write(dbWorld.GetDragonBallLocation(2).Y);
            packet.Write(dbWorld.GetDragonBallLocation(3).X);
            packet.Write(dbWorld.GetDragonBallLocation(3).Y);
            packet.Write(dbWorld.GetDragonBallLocation(4).X);
            packet.Write(dbWorld.GetDragonBallLocation(4).Y);
            packet.Write(dbWorld.GetDragonBallLocation(5).X);
            packet.Write(dbWorld.GetDragonBallLocation(5).Y);
            packet.Write(dbWorld.GetDragonBallLocation(6).X);
            packet.Write(dbWorld.GetDragonBallLocation(6).Y);
            packet.Write(dbWorld.GetDragonBallLocation(7).X);
            packet.Write(dbWorld.GetDragonBallLocation(7).Y);
            packet.Send(toWho, -1);
        }
예제 #18
0
        // handle a request to receive ki beacon sync from server
        public void ReceiveKiBeaconInitialSyncRequest(int toWho)
        {
            var dbWorld    = DBZWorld.GetWorld();
            var numIndexes = dbWorld.kiBeacons.Count;

            // if there aren't any, no sync needed, skip this.
            if (numIndexes == 0)
            {
                return;
            }
            ModPacket packet = GetPacket(SEND_KI_BEACON_INITIAL_SYNC, 256);

            // attach the number of indexes to be unpacked so the client knows when to stop reading on the other side.
            packet.Write(numIndexes);
            // loop over beacon locations and write each to the packet.
            foreach (var kiBeacon in dbWorld.kiBeacons)
            {
                // each beacon position coordinate is two floats.
                packet.Write(kiBeacon.X);
                packet.Write(kiBeacon.Y);
            }
            packet.Send(toWho, -1);
        }
예제 #19
0
        public static bool DragonRadarDebug(Player player)
        {
            if (!IsDebugModeOn())
            {
                return(true);
            }
            var world = DBZWorld.GetWorld();
            var count = 0;

            for (var i = 0; i < Main.maxTilesX; i++)
            {
                for (var j = 0; j < Main.maxTilesY; j++)
                {
                    if (world.IsDragonBallLocation(i, j))
                    {
                        Log($"Dragon ball found at {i} {j}");
                        count++;
                    }
                }
            }
            Log($"Debug count of dragon balls returned {count}");
            return(true);
        }
예제 #20
0
 public override bool AltFunctionUse(Player player)
 {
     // silently try to check for dragon ball existence in the world and attempt to replace any locations that aren't valid.
     DBZWorld.DoDragonBallCleanupCheck();
     return(base.AltFunctionUse(player));
 }
예제 #21
0
        private void GrantWish(UIMouseEvent evt, UIElement listeningelement)
        {
            Player   player    = Main.LocalPlayer;
            MyPlayer modplayer = Main.LocalPlayer.GetModPlayer <MyPlayer>();
            bool     UsedWish  = false;

            switch (WishSelection)
            {
            case WishSelectionID.Power:
                if (modplayer.PowerWishesLeft > 0)
                {
                    UsedWish = true;
                    DoPowerWish();
                    SoundUtil.PlayCustomSound("Sounds/WishGranted", player.Center);
                }
                else
                {
                    Main.PlaySound(SoundID.MenuClose);
                }
                break;

            case WishSelectionID.Wealth:
                UsedWish = true;
                DoWealthWish();
                SoundUtil.PlayCustomSound("Sounds/WishGranted", player.Center);
                break;

            case WishSelectionID.Immortality:
                if (modplayer.ImmortalityWishesLeft > 0)
                {
                    UsedWish = true;
                    DoImmortalityWish();
                    SoundUtil.PlayCustomSound("Sounds/WishGranted", player.Center);
                }
                else
                {
                    Main.PlaySound(SoundID.MenuClose);
                }
                break;

            case WishSelectionID.Genetic:
                UsedWish = true;
                DoGeneticWish();
                SoundUtil.PlayCustomSound("Sounds/WishGranted", player.Center);
                break;

            case WishSelectionID.Awakening:
                if (modplayer.AwakeningWishesLeft > 0)
                {
                    UsedWish = true;
                    DoAwakeningWish();
                    SoundUtil.PlayCustomSound("Sounds/WishGranted", player.Center);
                }
                else
                {
                    Main.PlaySound(SoundID.MenuClose);
                }
                break;

            default:
                break;
            }

            if (UsedWish)
            {
                DebugUtil.Log("Wish has been used.");
                WishSelection = WishSelectionID.None;
                DBZWorld.DestroyAndRespawnDragonBalls();
                modplayer.WishActive = false;
                Main.PlaySound(SoundID.MenuClose);
            }

            Initialize();
            DBZMOD.ActivateWishmenu();
        }
예제 #22
0
 public void DoDragonBallLegitimacyCheck(Player player)
 {
     if (Main.netMode == NetmodeID.Server)
     {
         return;
     }
     if (Main.netMode == NetmodeID.MultiplayerClient && player.whoAmI != Main.myPlayer)
     {
         return;
     }
     if (!WorldDragonBallKey.HasValue)
     {
         return;
     }
     // if the keys match, check to see if this dragon ball is cheated in.
     if (DBZWorld.GetWorld().WorldDragonBallKey == WorldDragonBallKey.Value)
     {
         bool isStoneBallTakingPlaceOfExistingDragonBall = false;
         bool isStoneBallStale = false;
         // check if this is an inert ball that needs to be restored to its glory.
         if (IsItemStoneBall(item.type))
         {
             if (!DBZWorld.IsDragonBallWithPlayers(WorldDragonBallKey.Value))
             {
                 ItemHelper.SwapStoneBallWithDragonBall(player.inventory, WorldDragonBallKey.Value, GetWhichDragonBall());
                 isStoneBallTakingPlaceOfExistingDragonBall = true;
             }
             else
             {
                 // the player is bringing a dragon ball back legitimately, but someone else found the replacement while they were gone. Tough luck.
                 isStoneBallStale = true;
             }
         }
         var dbLocation = DBZWorld.GetWorld().GetDragonBallLocation(GetWhichDragonBall());
         // something bad has happened, don't proceed
         if (dbLocation == new Point(-1, -1))
         {
             return;
         }
         var dbTile     = Framing.GetTileSafely(dbLocation.X, dbLocation.Y);
         var dbTileType = DBZMOD.instance.TileType(DBZWorld.GetDragonBallTileTypeFromNumber(GetWhichDragonBall()));
         // strange: the tile is still where the server thinks it is. this means the player probably cheated in a dragon ball.
         if (dbTile.type == dbTileType)
         {
             // the player is cheating. if we're in debug mode this is fine, but destroy that tile.
             if (DebugUtil.IsDebugModeOn() || isStoneBallTakingPlaceOfExistingDragonBall)
             {
                 WorldGen.KillTile(dbLocation.X, dbLocation.Y, false, false, true);
                 return;
             }
             else
             {
                 if (isStoneBallStale)
                 {
                     Main.NewText(string.Format("{0} lost the {1} Star Dragonball because they left and someone else found it.", player.name, GetWhichDragonBall()));
                 }
                 else
                 {
                     Main.NewText("Cheated Dragon Balls taste awful.");
                 }
                 ItemHelper.RemoveDragonBall(player.inventory, WorldDragonBallKey.Value, GetWhichDragonBall());
                 return;
             }
         }
     }
     else
     {
         // the keys don't match.. what we have here is a different world's dragon ball.
         ItemHelper.SwapDragonBallWithStoneBall(player.inventory, WorldDragonBallKey.Value, GetWhichDragonBall());
         return;
     }
 }