예제 #1
0
        private static Ambush CreateRandomWorldAmbush(int maxAttempts)
        {
            int           attempts = 0;
            int           randTileX, randTileY;
            UnifiedRandom rand = TmlHelpers.SafelyGetRand();

            do
            {
                randTileX = rand.Next(64, Main.maxTilesX - 64);
                randTileY = rand.Next((int)Main.worldSurface, Main.maxTilesY - 220);

                if (Ambush.CheckForAmbushElegibility(randTileX, randTileY))
                {
                    break;
                }
            } while(attempts++ < maxAttempts);

            if (attempts >= maxAttempts)
            {
                return(null);
            }

            Ambush.AdjustAmbushTileCenter(randTileX, ref randTileY);
            return(Ambush.CreateRandomType(randTileX, randTileY));
        }
        ////

        public void UnarmAmbush(Ambush ambush)
        {
            lock (AmbushManager.MyLock) {
                bool foundY = false;
                bool foundX = this.ArmedAmbushes.ContainsKey(ambush.TileX);
                int  radius = AmbushesMod.Config.AmbushTriggerRadiusTiles;

                if (foundX)
                {
                    foundY = this.ArmedAmbushes[ambush.TileX]
                             .Remove(ambush.TileY);
                }

                if (!foundX || !foundY)
                {
                    if (AmbushesMod.Config.DebugModeInfo)
                    {
                        LogHelpers.WarnOnce("Isolated ambush found at " + ambush.TileX + ":" + ambush.TileY + " (" + foundX + "," + foundY + ")");
                        Main.NewText("Isolated ambush found at " + ambush.TileX + ":" + ambush.TileY, Color.Yellow);
                    }
                }

                int segX = ambush.TileX / radius;
                int segY = ambush.TileY / radius;

                if (this.ArmedAmbushSegs.ContainsKey(segX))
                {
                    this.ArmedAmbushSegs[segX].Remove2D(segY, ambush);
                }
            }
        }
        ////////////////

        public static int GetAmbushCode(Ambush ambush)
        {
            for (int i = 0; i < Ambush.StaticInstances.Count; i++)
            {
                if (ambush.GetType().Name == Ambush.StaticInstances[i].GetType().Name)
                {
                    return(i);
                }
            }
            return(-1);
        }
        ////////////////

        public void TriggerAmbush(Ambush ambush, Player player)
        {
            if (ambush.Trigger(player))
            {
                lock (AmbushManager.MyLock) {
                    this.ActiveAmbushes.Add(ambush);
                }
            }

            this.UnarmAmbush(ambush);
        }
예제 #5
0
        private bool CreateRandomWorldAmbush()
        {
            lock (AmbushesWorld.MyLock) {
                Ambush ambush = this.CreateNonNeighboringRandomWorldAmbush(50, 10000);

                if (ambush != null)
                {
                    this.SpawnAmbush(ambush);
                    return(true);
                }
            }
            return(false);
        }
        public static Ambush CreateType(int ambushType, int tileX, int tileY, bool isEntrapping)
        {
            Ambush template = Ambush.StaticInstances[ambushType];
            Ambush ambush   = template.CloneRandomized(tileX, tileY);

            if (ambush is BrambleEnclosureAmbush)
            {
                var brambleAmbush = (BrambleEnclosureAmbush)ambush;
                brambleAmbush.IsEntrapping = isEntrapping;
            }

            return(ambush);
        }
예제 #7
0
        ////////////////

        private void SpawnAmbush(Ambush ambush)
        {
            if (AmbushesMod.Config.DebugModeInfo)
            {
                LogHelpers.Log("Created ambush at " + ambush.TileX + "," + ambush.TileY + " (" + this.AmbushMngr.CountTotalAmbushes() + ")");
            }

            this.AmbushMngr.ArmAmbush(ambush);

            if (Main.netMode == 2)
            {
                AmbushAddProtocol.QuickSendToClients(ambush);
            }
        }
        ////////////////

        public static Ambush CreateRandomType(int tileX, int tileY)
        {
            float  rand       = TmlHelpers.SafelyGetRand().NextFloat() * (float)Ambush.TotalWeight;
            Ambush randAmbush = null;

            float counted = 0f;

            foreach (Ambush ambush in Ambush.StaticInstances)
            {
                if (rand >= counted && rand < (ambush.WorldGenWeight + counted))
                {
                    randAmbush = ambush;
                    break;
                }
                counted += ambush.WorldGenWeight;
            }

            return(randAmbush?.CloneRandomized(tileX, tileY));
        }
예제 #9
0
        ////////////////

        public void PlayMusic(Ambush ambush)
        {
            if (this.RecentMusic != null)
            {
                if (!this.RecentMusic.IsFadingOut)
                {
                    return;
                }
            }

            this.RecentMusic = OverlaySound.Create(
                sourceMod: AmbushesMod.Instance,
                soundPath: "Sounds/LowAmbushBGM",
                fadeTicks: 60,
                playDurationTicks: -1,
                customCondition: () => (0.8f, ambush.IsEnded)
                );
            this.RecentMusic.Play();
        }
        ////////////////

        public void ArmAmbush(Ambush ambush)
        {
            int radius = AmbushesMod.Config.AmbushTriggerRadiusTiles;

            lock (AmbushManager.MyLock) {
                this.ArmedAmbushes.Set2D(ambush.TileX, ambush.TileY, ambush);

                IList <Ambush> segAmbushes;
                if (this.ArmedAmbushSegs.TryGetValue2D(ambush.TileX / radius, ambush.TileY / radius, out segAmbushes))
                {
                    segAmbushes.Add(ambush);
                }
                else
                {
                    this.ArmedAmbushSegs.Set2D(ambush.TileX / radius, ambush.TileY / radius, new List <Ambush> {
                        ambush
                    });
                }
            }
        }
예제 #11
0
        ////

        private void DrawAmbushOnFullscreenMap(int tileX, int tileY, Ambush ambush)
        {
            var wldPos      = new Vector2(tileX * 16, tileY * 16);
            var overMapData = HUDMapHelpers.GetFullMapScreenPosition(wldPos);

            if (overMapData.Item2)
            {
                Main.spriteBatch.DrawString(
                    Main.fontMouseText,
                    "X",
                    overMapData.Item1,
                    Color.Red
                    );
            }

            if (this.LatestMinibossWho != -1)
            {
                NPC npc = Main.npc[this.LatestMinibossWho];

                if (npc == null || !npc.active)
                {
                    this.LatestMinibossWho = -1;
                }
                else
                {
                    Tuple <Vector2, bool> minibossPosData = HUDMapHelpers.GetFullMapScreenPosition(npc.position);

                    if (minibossPosData.Item2)
                    {
                        Main.spriteBatch.DrawString(
                            Main.fontMouseText,
                            "X",
                            minibossPosData.Item1,
                            Color.Green
                            );
                    }
                }
            }
        }
예제 #12
0
        ////////////////

        private Ambush CreateNonNeighboringRandomWorldAmbush(int maxNonNeighborAttempts, int maxCreateAttempts)
        {
            Ambush ambush   = null;
            int    attempts = 0;

            do
            {
                ambush = AmbushesWorld.CreateRandomWorldAmbush(maxCreateAttempts);
                if (ambush == null)
                {
                    continue;
                }

                if (!this.HasNearbyAmbushes(ambush.TileX, ambush.TileY))
                {
                    break;
                }

                ambush = null;
            } while(attempts++ < maxNonNeighborAttempts);

            return(ambush);
        }
예제 #13
0
 public override void Unload()
 {
     Ambush.OnModsUnload();
     AmbushesMod.Instance = null;
 }
예제 #14
0
 public override void Load()
 {
     Ambush.OnModsLoad();
 }