Beispiel #1
0
        ////////////////

        public override void ReceiveOnServer(int fromWho)
        {
            Player           plr      = Main.player[this.PlayerWho];
            var              otherplr = TmlLibraries.SafelyGetModPlayer <TMRPlayer>(plr);
            GunAnimationType animType = (GunAnimationType)this.AnimType;

            Item gun = plr.HeldItem;

            if (gun?.active != true)
            {
                return;
            }

            var mygun = gun.modItem as TheMadRangerItem;

            if (mygun == null)
            {
                return;
            }

            switch (animType)
            {
            //case GunAnimationType.Recoil:
            //	otherplr.GunHandling.BeginRecoil( 0f );
            //	break;
            case GunAnimationType.Holster:              // Might interrupt other item actions such that server should know
                otherplr.GunHandling.BeginHolster(plr, mygun);
                break;
                //case GunAnimationType.Reload:
                //	otherplr.GunHandling.BeginReload( plr );
                //	break;
            }

            SimplePacket.SendToClient(this, -1, fromWho);
        }
        /*public override void PostDrawInterface( SpriteBatch sb ) {
         *      if( Main.playerInventory && Main.EquipPage == 0 ) {	//== 2 is misc page
         *              this.DrawAccessoryOverlays( sb );
         *      }
         * }*/


        private void DrawDisabledAccessorySlotOverlays(SpriteBatch sb)
        {
            var myplayer = TmlLibraries.SafelyGetModPlayer <LockedAbilitiesPlayer>(Main.LocalPlayer);

            if (myplayer.TotalAllowedAccessorySlots < 0)
            {
                return;
            }

            int firstAccSlot = PlayerItemLibraries.VanillaAccessorySlotFirst;
            int maxAcc       = PlayerItemLibraries.GetCurrentVanillaMaxAccessories(Main.LocalPlayer) + firstAccSlot;
            int myMaxAcc     = myplayer.TotalAllowedAccessorySlots;

            for (int i = firstAccSlot; i < maxAcc; i++)
            {
                if ((i - firstAccSlot) < myMaxAcc)
                {
                    continue;
                }

                var pos = HUDElementLibraries.GetVanillaAccessorySlotScreenPosition(i - firstAccSlot);
                pos.X += 8;
                pos.Y += 8;

                sb.Draw(this.DisabledItemTex, pos, Color.White);
            }
        }
Beispiel #3
0
        public override void ReceiveOnClient()
        {
            Player           plr      = Main.player[this.PlayerWho];
            var              otherplr = TmlLibraries.SafelyGetModPlayer <TMRPlayer>(plr);
            GunAnimationType animType = (GunAnimationType)this.AnimType;

            Item gun = plr.HeldItem;

            if (gun?.active != true)
            {
                return;
            }

            var mygun = gun.modItem as TheMadRangerItem;

            if (mygun == null)
            {
                return;
            }

            switch (animType)
            {
            case GunAnimationType.Recoil:
                otherplr.GunHandling.BeginRecoil(0f);
                break;

            case GunAnimationType.Holster:
                otherplr.GunHandling.BeginHolster(plr, mygun);
                break;

            case GunAnimationType.Reload:
                otherplr.GunHandling.BeginReload(plr, mygun);
                break;
            }
        }
        protected CustomParticle(
            bool isInWorld,
            Vector2 pos,
            int tickDuration,
            Color color,
            float scale,
            float sprayAmt,
            bool hasGravity)
        {
            this.IsInWorld    = isInWorld;
            this.Position     = pos;
            this.TickDuration = tickDuration;
            this.Color        = color;
            this.Scale        = scale;
            this.SprayAmt     = sprayAmt;
            this.HasGravity   = hasGravity;

            UnifiedRandom rand = TmlLibraries.SafelyGetRand();

            this.Velocity = new Vector2(
                (rand.NextFloat() - 0.5f) * this.SprayAmt,
                (rand.NextFloat() - 0.5f) * this.SprayAmt
                );
            this.RotVelocity = rand.NextFloat() - 0.5f;
        }
Beispiel #5
0
        ////////////////

        /// <summary>
        /// Allows binding actions to `GlobalTile.KillTile(...)` calls for tiles larger than 1x1, and only for the top left
        /// tile.
        /// </summary>
        /// <param name="hook"></param>
        public static void AddKillMultiTileHook(KillMultiTileDelegate hook)
        {
            var eth = TmlLibraries.SafelyGetInstance <ExtendedTileHooks>();

            lock (ExtendedTileHooks.MyLock) {
                eth.OnKillMultiTileHooks.Add(hook);
            }
        }
Beispiel #6
0
 public override void KillWall(int i, int j, int type, ref bool fail)
 {
     if ((!Main.gameMenu && Main.netMode == NetmodeID.Server) || Main.netMode == NetmodeID.Server)
     {
         var eth = TmlLibraries.SafelyGetInstance <ExtendedTileHooks>();
         eth.CallKillWallHooks(i, j, type, ref fail);
     }
 }
        public static float ComputeAimShakeRadiansOffsetWithinCone()
        {
            var           config   = TMRConfig.Instance;
            UnifiedRandom rand     = TmlLibraries.SafelyGetRand();
            float         radRange = MathHelper.ToRadians(config.Get <float>(nameof(TMRConfig.UnaimedConeDegreesRange)));

            return((rand.NextFloat() * radRange) - (radRange * 0.5f));
        }
Beispiel #8
0
        ////////////////

        internal static void BeginScanningForLootDrops(NPC npc)
        {
            var eih = TmlLibraries.SafelyGetInstance <ExtendedItemHooks>();

            if (eih.OnNPCLootHooks.Count > 0)
            {
                eih.LootNPC       = npc;
                eih.ItemsSnapshot = (Item[])Main.item.Clone();
            }
        }
Beispiel #9
0
        public override void KillTile(int i, int j, int type, ref bool fail, ref bool effectOnly, ref bool noItem)
        {
//ModContent.GetInstance<ModLibsGeneralMod>().Logger.Info( "KillTile1 "+type+" ("+i+","+j+") - "
//	+"fail:"+fail+", effectOnly:"+effectOnly+", noItem:"+noItem);
            var eth = TmlLibraries.SafelyGetInstance <ExtendedTileHooks>();

            if ((!Main.gameMenu && Main.netMode != NetmodeID.Server) || Main.netMode == NetmodeID.Server)
            {
                eth.CallKillTileHooks(i, j, type, ref fail, ref effectOnly, ref noItem);
                eth.CallKillMultiTileHooks(i, j, type);
            }
            // why was CallKillMultiTileHooks here instead, previously?
        }
Beispiel #10
0
        public override bool ConsumeItem(Player player)
        {
            var  myplayer            = TmlLibraries.SafelyGetModPlayer <LockedAbilitiesPlayer>(player);
            int  vanillaMaxAcc       = PlayerItemLibraries.GetCurrentVanillaMaxAccessories(player);
            bool canIncreaseAccSlots = myplayer.InternalAllowedAccessorySlots >= 0 &&
                                       myplayer.InternalAllowedAccessorySlots < vanillaMaxAcc;

            if (canIncreaseAccSlots)
            {
                myplayer.IncreaseAllowedAccessorySlots();
            }
            return(canIncreaseAccSlots);
        }
        private static void ErodeBramblesAtRandomly(int tileX, int tileY)
        {
            int minTicks    = 3;
            int maxTicks    = 60 * 60;
            int brambleType = ModContent.TileType <CursedBrambleTile>();

            Timers.SetTimer(TmlLibraries.SafelyGetRand().Next(minTicks, maxTicks), false, () => {
                Tile tile = Framing.GetTileSafely(tileX, tileY);

                if (tile.active() && tile.type == brambleType)
                {
                    TileLibraries.KillTile(tileX, tileY, false, false, true);
                }
                return(false);
            });
        }
Beispiel #12
0
        public static void UpdateLightAversionForTile(int tileX, int tileY, float tolerance, float brightness)
        {
            if (tolerance == 0)
            {
                return;
            }

            float rand = TmlLibraries.SafelyGetRand().NextFloat();

            rand *= tolerance;

            if (rand < brightness)
            {
                ManaCrystalShardTile.TeleportTile(tileX, tileY);
            }
        }
Beispiel #13
0
        ////////////////

        public override void Apply(GenerationProgress progress)
        {
            var           config = LockedAbilitiesConfig.Instance;
            UnifiedRandom rand   = TmlLibraries.SafelyGetRand();

            float implantChance = config.Get <float>(nameof(config.WorldGenChestImplantChance));

            if (implantChance <= 0f)
            {
                return;
            }

            var any = AbilityItemChestsPass.GetAbilityItemWeights()
                      .Select(kv => (kv.chance, new ChestFillItemDefinition(kv.myitem.item.type)))
                      .ToArray();

            var chestDef = new ChestTypeDefinition(
                tiles: new (int?, int?)[0],
        /// <summary>
        /// Attempts to remove a random bramble within a given (tile) area.
        /// </summary>
        /// <param name="minTileX"></param>
        /// <param name="minTileY"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="adjacentRadius"></param>
        /// <param name="sync"></param>
        /// <returns>`true` if a bramble was found and removed.</returns>
        public static bool ErodeRandomBrambleWithinArea(
            int minTileX,
            int minTileY,
            int width,
            int height,
            int adjacentRadius,
            bool sync)
        {
            int randTileX = minTileX + TmlLibraries.SafelyGetRand().Next(width);
            int randTileY = minTileY + TmlLibraries.SafelyGetRand().Next(height);

            Tile tile = Framing.GetTileSafely(randTileX, randTileY);

            if (!tile.active() || tile.type != ModContent.TileType <CursedBrambleTile>())
            {
                return(false);
            }

            if (!sync)
            {
                WorldGen.KillTile(
                    i: randTileX,
                    j: randTileY,
                    fail: false,
                    effectOnly: false,
                    noItem: true
                    );
                WorldGen.SquareTileFrame(randTileX, randTileY);
            }
            else
            {
                TileLibraries.KillTile(
                    tileX: randTileX,
                    tileY: randTileY,
                    effectOnly: false,
                    dropsItem: false,
                    forceSyncIfUnchanged: true
                    );
            }

            CursedBrambleTile.ErodeBramblesWithinAreaRadiusRandomly(minTileX, minTileY, adjacentRadius);

            return(true);
        }
        /// <summary>
        /// Creates a lightning effect relative to the screen. Must be called in a Draw function.
        /// </summary>
        /// <param name="screenStartPos"></param>
        /// <param name="screenEndPos"></param>
        /// <param name="scale"></param>
        /// <param name="color"></param>
        public static void DrawScreenLightning(Vector2 screenStartPos, Vector2 screenEndPos, float scale, Color color)
        {
            var rand = TmlLibraries.SafelyGetRand();
            var segs = new List <(Vector2 Beg, Vector2 End)>();

            Vector2 startPos = screenStartPos;

            while ((startPos - screenEndPos).LengthSquared() > 2304)                 //48^2
            {
                Vector2 dir   = Vector2.Normalize(screenEndPos - startPos);
                Vector2 reach = dir * rand.Next(16, 80);

                float remainingLenFromStartSqr = (screenEndPos - startPos).LengthSquared();
                if (reach.LengthSquared() > remainingLenFromStartSqr)
                {
                    break;
                }

                Vector2 testEndPos;
                float   testLenSqr;
                do
                {
                    testEndPos  = startPos + reach;
                    testEndPos += new Vector2(rand.Next(80) - 40, rand.Next(80) - 40);

                    testLenSqr = (screenEndPos - testEndPos).LengthSquared();
                } while(testLenSqr < 256 || testLenSqr > remainingLenFromStartSqr);

                segs.Add((startPos, testEndPos));

                startPos = testEndPos;
            }

            segs.Add((startPos, screenEndPos));

//LogLibraries.LogAndPrintOnce( "segs: "+segs.Count+", length: "+(screenStartPos-screenEndPos).Length()
//	+", scrStart: "+screenStartPos.ToShortString()+", scrEnd: "+screenEndPos.ToShortString()
//	+", segs: "+string.Join(", ", segs.Select(seg=>seg.Beg.ToShortString()+"->"+seg.End.ToShortString())));
            for (int i = 0; i < segs.Count; i++)
            {
                LightningFxLibraries.DrawLightningBeam(segs[i].Beg, segs[i].End, scale, color);
            }
        }
        ////////////////

        /// <summary>
        /// Attempts to remove a random bramble within a given (tile) radius of a given tile.
        /// </summary>
        /// <param name="tileX"></param>
        /// <param name="tileY"></param>
        /// <param name="radius"></param>
        /// <param name="adjacentRadius"></param>
        /// <returns>`true` if a bramble was found and removed.</returns>
        public static bool ErodeRandomBrambleWithinRadius(int tileX, int tileY, int radius, int adjacentRadius)
        {
            int randX     = TmlLibraries.SafelyGetRand().Next(radius * 2);
            int randY     = TmlLibraries.SafelyGetRand().Next(radius * 2);
            int randTileX = tileX + (randX - radius);
            int randTileY = tileY + (randY - radius);

            Tile tile = Framing.GetTileSafely(randTileX, randTileY);

            if (!tile.active() || tile.type != ModContent.TileType <CursedBrambleTile>())
            {
                return(false);
            }

            TileLibraries.KillTile(randTileX, randTileY, false, false, true);

            CursedBrambleTile.ErodeBramblesWithinAreaRadiusRandomly(tileX, tileY, adjacentRadius);

            return(true);
        }
        public int GetAimStateShakeDamage(int damage)
        {
            if (this.IsModeActive)
            {
                return(damage);
            }

            var           config      = TMRConfig.Instance;
            UnifiedRandom rand        = TmlLibraries.SafelyGetRand();
            float         maxAimDmg   = config.Get <int>(nameof(TMRConfig.MaximumAimedGunDamage));
            float         minUnaimDmg = config.Get <int>(nameof(TMRConfig.MinimumUnaimedGunDamage));
            float         maxUnaimDmg = config.Get <int>(nameof(TMRConfig.MaximumUnaimedGunDamage));
            float         dmgPercent  = (float)damage / maxAimDmg;

            float baseDmg       = maxUnaimDmg * dmgPercent;
            float dmgMinPercent = minUnaimDmg / maxUnaimDmg;
            float dmgRand       = dmgMinPercent + (rand.NextFloat() * (1f - dmgMinPercent));

            int newDmg = (int)(dmgRand * (baseDmg - 1f)) + 1;

            return(newDmg);
        }
Beispiel #18
0
        internal static void FinishScanningForLootDropsAndThenRunHooks()
        {
            var eih = TmlLibraries.SafelyGetInstance <ExtendedItemHooks>();

            if (eih.ItemsSnapshot == null)
            {
                return;
            }

            var newItemWhos = new List <int>();

            int max = Main.item.Length;

            for (int i = 0; i < max; i++)
            {
                Item newItem = Main.item[i];
                if (newItem?.active != true)
                {
                    continue;
                }

                Item oldItem = eih.ItemsSnapshot[i];
                if (oldItem?.active != true)
                {
                    newItemWhos.Add(i);
                }
            }

            foreach (NPCLootDelegate hook in eih.OnNPCLootHooks)
            {
                hook(eih.LootNPC, newItemWhos);
            }

            eih.LootNPC       = null;
            eih.ItemsSnapshot = null;
        }
Beispiel #19
0
        public override void ReceiveOnClient()
        {
            var myplayer = TmlLibraries.SafelyGetModPlayer <LockedAbilitiesPlayer>(Main.player[this.PlayerWho]);

            myplayer.SetAllowedAccessorySlots(this.DarkHearts);
        }
Beispiel #20
0
        ////////////////

        public static short PickFrameX(int i, int j)
        {
            return((short)(TmlLibraries.SafelyGetRand().Next(3) * ManaCrystalShardTile.AnimationFrameWidth));
        }
        public void AnimateManaCrystalShardHint()
        {
            if (Timers.GetTimerTickDuration("ManaCrystalShardHint") > 0)
            {
                return;
            }

            float percent;

            if (this.MeasureClosestOnScreenManaCrystalShardTileDistance(out percent) == null)
            {
                return;
            }

            var config = FMCConfig.Instance;

            int beginTicks = config.Get <int>(nameof(FMCConfig.BinocularsHintBeginDurationTicks));

            Timers.SetTimer("ManaCrystalShardHint", beginTicks, false, () => {
                Item heldItem = Main.LocalPlayer.HeldItem;
                if (heldItem == null || heldItem.IsAir || heldItem.type != ItemID.Binoculars)
                {
                    return(0);
                }

                float?newTileProximityIf = this.MeasureClosestOnScreenManaCrystalShardTileDistance(out percent);
                if (!newTileProximityIf.HasValue)
                {
                    return(0);
                }

                float rateScaleOfSparks = config.Get <float>(nameof(FMCConfig.BinocularsHintIntensity));
                rateScaleOfSparks       = 1f - rateScaleOfSparks;
                float rateOfSparks      = newTileProximityIf.Value * rateScaleOfSparks;
                UnifiedRandom rand      = TmlLibraries.SafelyGetRand();

                int dustIdx = Dust.NewDust(
                    Position: Main.screenPosition,
                    Width: Main.screenWidth,
                    Height: Main.screenHeight,
                    Type: 59,
                    SpeedX: (4f * rand.NextFloat() * percent * percent) - 2f,
                    SpeedY: (4f * rand.NextFloat() * percent * percent) - 2f,
                    Alpha: 128 - (int)(percent * 128f),
                    newColor: new Color(255, 255, 255),
                    Scale: 1.25f + (2f * percent * percent)
                    );
                Dust dust      = Main.dust[dustIdx];
                dust.noGravity = true;
                dust.noLight   = true;

                if (config.DebugModeInfo)
                {
                    DebugLibraries.Print(
                        "FindableManaCrystals",
                        "rateOfSparks: " + rateScaleOfSparks.ToString("N2")
                        + ", proximity: " + newTileProximityIf.Value.ToString("N2")
                        + ", rate: " + rateOfSparks.ToString("N2")
                        );
                }

                return((int)Math.Max(5, rateOfSparks));
            });
        }
Beispiel #22
0
        ////////////////

        private static void _Update()           // <- seems to help avoid Mystery Bugs(TM)
        {
            var eth = TmlLibraries.SafelyGetInstance <ExtendedTileHooks>();

            eth.Update();
        }