Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更新:v1.0.7 添加了挖矿套的连锁挖矿能力、添加了挖矿套、暗影套、猩红套、黑曜石套、挥发凝胶的配置项 #101

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Challenger/Challenger.CNPCs/EaterofWorldsTail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override void OnKilled()
CProjectile.Update(num);
for (int i = 0; i < 6; i++)
{
Projectile.NewProjectile(null, npc.Center, Utils.RotatedBy(Vector2.UnitY, Math.PI / 3.0 * i, default(Vector2)) * 5f, 909, 14, 0f, -1, 0f, 0f, 0f);
Projectile.NewProjectile(null, npc.Center, Terraria.Utils.RotatedBy(Vector2.UnitY, Math.PI / 3.0 * i, default(Vector2)) * 5f, 909, 14, 0f, -1, 0f, 0f, 0f);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Challenger/Challenger.CNPCs/Skeletron_Surrand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public override void NPCAI()
public override void OnKilled()
{
NPCAimedTarget targetData = npc.GetTargetData(true);
Projectile.NewProjectile(null, npc.Center, Utils.DirectionTo(npc.Center, targetData.Center) * 5f, 270, 6, 30f, -1, 0f, 0f, 0f);
Projectile.NewProjectile(null, npc.Center, Terraria.Utils.DirectionTo(npc.Center, targetData.Center) * 5f, 270, 6, 30f, -1, 0f, 0f, 0f);
}
}
}
163 changes: 140 additions & 23 deletions Challenger/Challenger/Challenger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Xna.Framework;
using Newtonsoft.Json;
using OTAPI;
using System.Net.NetworkInformation;
using System.Text;
using Terraria;
using Terraria.GameContent.Events;
Expand Down Expand Up @@ -34,7 +35,7 @@ public class Challenger : TerrariaPlugin

public override string Name => "Challenger";

public override Version Version => new Version(1, 0, 0, 6);
public override Version Version => new Version(1, 0, 0, 7);

public Challenger(Main game)
: base(game)
Expand All @@ -44,6 +45,7 @@ public Challenger(Main game)
public override void Initialize()
{
LoadConfig();
GetDataHandlers.TileEdit += OnTileEdit;
GeneralHooks.ReloadEvent += new GeneralHooks.ReloadEventD(LoadConfig);
ServerApi.Hooks.GameUpdate.Register((TerrariaPlugin)(object)this, OnGameUpdate);
GetDataHandlers.PlayerDamage.Register(PlayerSufferDamage, (HandlerPriority)3, false);
Expand Down Expand Up @@ -223,6 +225,9 @@ public void FossilArmorEffect(Player player)

public void CrimsonArmorEffect(NpcStrikeEventArgs args)
{
var any = config.CrimsonArmorEffect;
var any2 = config.CrimsonArmorEffect_2;
var any3 = config.CrimsonArmorEffect_3;
CPlayer cPlayer = Collect.cplayers[args.Player.whoAmI];
if (args.Player.armor[0].type != 792 || args.Player.armor[1].type != 793 || args.Player.armor[2].type != 794 || !args.Critical || Timer - cPlayer.CrimsonArmorEffectTimer < 300 || !args.Npc.CanBeChasedBy(null, false))
{
Expand All @@ -243,20 +248,24 @@ public void CrimsonArmorEffect(NpcStrikeEventArgs args)
{
break;
}
Projectile.NewProjectile(null, val.Center, Vector2.Zero, 305, 0, 0f, -1, args.Player.whoAmI, num2, 0f);
Projectile.NewProjectile(null, val.Center, Vector2.Zero, any, any2, any3, -1, args.Player.whoAmI, num2, 0f);
}
cPlayer.CrimsonArmorEffectTimer = (int)Timer;
}

public void ShadowArmorEffect(NpcStrikeEventArgs args)
{
var any = config.ShadowArmorEffect;
var any2 = config.ShadowArmorEffect_2;
var any3 = config.ShadowArmorEffect_3;

Item[] armor = args.Player.armor;
if ((armor[0].netID == 102 || armor[0].netID == 956) && (armor[1].netID == 101 || armor[1].netID == 957) && (armor[2].netID == 100 || armor[2].netID == 958) && args.Critical && Timer - Collect.cplayers[args.Player.whoAmI].ShadowArmorEffectTimer >= 60)
{
int num = Main.rand.Next(2, 6);
for (int i = 0; i < num; i++)
{
int num2 = Collect.MyNewProjectile(null, args.Player.Center, new Vector2((float)Math.Cos(Main.rand.NextDouble() * 6.2831854820251465), (float)Math.Sin(Main.rand.NextDouble() * 6.2831854820251465)), 307, 20, 2f, args.Player.whoAmI);
int num2 = Collect.MyNewProjectile(null, args.Player.Center, new Vector2((float)Math.Cos(Main.rand.NextDouble() * 6.2831854820251465), (float)Math.Sin(Main.rand.NextDouble() * 6.2831854820251465)), any, any2, any3, args.Player.whoAmI);
Projectile obj = Main.projectile[num2];
obj.scale *= 0.5f;
CProjectile.Update(num2);
Expand Down Expand Up @@ -342,7 +351,7 @@ public void BeeArmorEffect(Player player)
}
}

public void NecroArmor(GetDataHandlers.PlayerDamageEventArgs? e, NpcStrikeEventArgs? args)
public void NecroArmor(PlayerDamageEventArgs? e, NpcStrikeEventArgs? args)
{
if (config.NecroArmor)
{
Expand All @@ -360,7 +369,7 @@ public void NecroArmor(GetDataHandlers.PlayerDamageEventArgs? e, NpcStrikeEventA
{
for (int i = 0; i < 8; i++)
{
Vector2 velocity = Terraria.Utils.RotatedBy(Vector2.UnitY, (double)((float)Math.PI / 4f * i + (float)Math.PI / 8f), default(Vector2)) * 4f;
Vector2 velocity = Terraria.Utils.RotatedBy(Vector2.UnitY, (double)((float)Math.PI / 4f * i + (float)Math.PI / 8f), default) * 4f;
int index = Collect.MyNewProjectile(null, Main.player[e.Player.Index].Center, velocity, any, any2, any3, e.Player.Index);
CProjectile.Update(index);
}
Expand All @@ -383,14 +392,16 @@ public void ObsidianArmorEffect(NpcStrikeEventArgs args)
{
if (config.ObsidianArmorEffect)
{
var any = config.ObsidianArmorEffect_1; //自定义掉落稀有度

Item[] armor = args.Player.armor;
if (armor[0].type != 3266 || armor[1].type != 3267 || armor[2].type != 3268 || !args.Npc.CanBeChasedBy(null, false) || args.Npc.SpawnedFromStatue)
{
return;
}
try
{
if (!args.Npc.boss && args.Npc.rarity <= 1 && args.Npc.lifeMax <= 7000)
if (!args.Npc.boss && args.Npc.rarity <= any && args.Npc.lifeMax <= 7000)
{
Collect.cnpcs[args.Npc.whoAmI].AccOfObsidian.Add(args.Player.name);
}
Expand All @@ -415,6 +426,114 @@ public void MoltenArmor(Player player, Config config)
}
}

#region 新加挖矿套永久BUFF效果 + VeinMiner 连锁挖矿
public bool VeinMinerOpen { get; set; } = false;

public void MiningArmor(Player player, Config config)
{
var any = config.MiningArmor;

Item[] armor = player.armor;
if ((armor[0].type == 88 || armor[0].type == 4008) && armor[1].type == 410 && armor[2].type == 411 && Timer % 20 == 0)
{
foreach (var effect in any)
{
TShock.Players[player.whoAmI].SetBuff(effect, 180, false);
}
VeinMinerOpen = true;
}
else
{
VeinMinerOpen = false;
}
}

#region 连锁挖矿方法
public void OnTileEdit(object o, TileEditEventArgs args)
{
if (Main.tile[args.X, args.Y] is { } tile && config.Tile.Contains(tile.type) && args.Action == EditAction.KillTile && args.EditData == 0)
{
var plr = args.Player;
if (plr != null && VeinMinerOpen)
{
args.Handled = true;
Mine(plr, args.X, args.Y, tile.type);
}
}
}

void Mine(TSPlayer plr, int x, int y, int type)
{
var list = GetVein(new List<Point>(), x, y, type);
var count = list.Count;
var item = Utils.GetItemFromTile(x, y);
if (plr.IsSpaceEnough(item.netID, count))
{
plr.GiveItem(item.netID, count);
KillTileAndSend(list, true);
plr.SendMessage($"[c/95CFA6:<挑战者:挖矿套>] 连锁挖掘了 [c/95CFA6: {count} {(item.type == 0 ? "未知" : item.Name)}].", Color.White);
}
else
{
plr.SendInfoMessage($"[c/95CFA6:<挑战者:挖矿套>] 背包已满,还需空位:[c/95CFA6:{count}] 以放入 [c/95CFA6:{item.Name}] .");
plr.SendTileSquareCentered(x, y, 1);
}
}

public static void KillTileAndSend(List<Point> list, bool noItem)
{
Task.Run(() =>
{
if (!list.Any())
return;
var minX = list[0].X;
var minY = list[0].Y;
var maxX = minX;
var maxY = minY;
list.ForEach(p =>
{
if (p.X < minX) minX = p.X;
if (p.X > maxX) maxX = p.X;
if (p.Y < minY) minY = p.Y;
if (p.Y > maxY) maxY = p.Y;
WorldGen.KillTile(p.X, p.Y, false, false, noItem);
NetMessage.SendData(17, -1, -1, null, 4, p.X, p.Y, false.GetHashCode());
});
NetMessage.SendTileSquare(-1, minX, minY, maxX - minX + 1, maxY - minY + 1, Terraria.ID.TileChangeType.None);
});
}

public static List<Point> GetVein(List<Point> list, int x, int y, int type)
{
var stack = new Stack<(int X, int Y)>();
stack.Push((x, y));

while (stack.Any() && list.Count <= 1000)
{
var (curX, curY) = stack.Pop();

if (!list.Any(p => p.Equals(new Point(curX, curY))) && Main.tile[curX, curY] is { } tile && tile.active() && tile.type == type)
{
list.Add(new Point(curX, curY));
var directions = new[] { (1, 0), (-1, 0), (0, 1), (0, -1), (1, 1), (1, -1), (-1, 1), (-1, -1) };
foreach (var (dx, dy) in directions)
{
var newX = curX + dx;
var newY = curY + dy;
if (newX >= 0 && newX < Main.maxTilesX && newY >= 0 && newY < Main.maxTilesY)
{
stack.Push((newX, newY));
}
}
}
}
return list;
}
#endregion


#endregion

public void SpiderArmorEffect(NpcStrikeEventArgs? args, Player? player)
{
if (args != null)
Expand Down Expand Up @@ -992,30 +1111,27 @@ public void VolatileGelatin(NpcStrikeEventArgs args)
{
if (args.Npc.CanBeChasedBy(null, false) && !args.Npc.SpawnedFromStatue)
{
int num = Main.rand.Next(700);
if (num >= 90 && num < 100)
{
Item.NewItem(null, args.Npc.Center, new Vector2(20f, 20f), 502, 1, false, 0, false, false);
}
else if (num >= 80 && num < 90 && Main.BestiaryTracker.Kills.GetKillCount(ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[-4]) > 0)
{
Item.NewItem(null, args.Npc.Center, new Vector2(20f, 20f), 3111, 1, false, 0, false, false);
}
else if (num >= 60 && num < 80)
{
Item.NewItem(null, args.Npc.Center, new Vector2(20f, 20f), 409, 1, false, 0, false, false);
}
else if (num >= 40 && num < 60)
{
Item.NewItem(null, args.Npc.Center, new Vector2(20f, 20f), 23, 1, false, 0, false, false);
}
// 直接从配置的Config数组中随机选择一个物品ID
int randomIndex = Main.rand.Next(config.VolatileGelatin.Length);
int itemId = config.VolatileGelatin[randomIndex];

// 创建掉落物,使用随机选中的itemId
Item.NewItem(null, args.Npc.Center, new Vector2(20f, 20f), itemId, 1, false, 0, false, false);
}
}



public void DisplayTips(TSPlayer tsplayer, short type)
{
switch (type)
{
case 88:
case 4008:
case 410:
case 411:
SendPlayerText(tsplayer, "【挖矿套装】\n挑战模式奖励:给予永久的挖矿、糖果冲刺Buff\n启用连锁挖矿能力", new Color(91, 101, 132), Main.player[tsplayer.Index].Center + new Vector2(0f, -24f));
break;
case 2367:
case 2368:
case 2369:
Expand Down Expand Up @@ -1339,6 +1455,7 @@ private void OnGameUpdate(EventArgs args)
default:
if (Timer % 5 == 0)
{
MiningArmor(tPlayer, config);
FossilArmorEffect(tPlayer);
ChlorophyteArmorEffect(tPlayer);
TurtleArmorEffect(tPlayer);
Expand Down
4 changes: 2 additions & 2 deletions Challenger/Challenger/Collect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ public static int MyNewItem(IEntitySource source, int X, int Y, int Width, int H
{
if (Type == 58)
{
Type = Utils.NextFromList<short>(Main.rand, new short[3] { 1734, 1867, 58 });
Type = Terraria.Utils.NextFromList<short>(Main.rand, new short[3] { 1734, 1867, 58 });
}
if (Type == 184)
{
Type = Utils.NextFromList<short>(Main.rand, new short[3] { 1735, 1868, 184 });
Type = Terraria.Utils.NextFromList<short>(Main.rand, new short[3] { 1735, 1868, 184 });
}
}
if (Main.halloween)
Expand Down
27 changes: 26 additions & 1 deletion Challenger/Challenger/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ public class Config
[JsonProperty("忍者套闪避释放的弹幕击退")]
public float NinjaArmorEffect_5 = 0f;

[JsonProperty("暗影套的弹幕ID")]
public int ShadowArmorEffect = 307;
[JsonProperty("暗影套的弹幕伤害")]
public int ShadowArmorEffect_2 = 20;
[JsonProperty("暗影套的弹幕击退")]
public float ShadowArmorEffect_3 = 2f;

[JsonProperty("猩红套的弹幕ID")]
public int CrimsonArmorEffect = 305;
[JsonProperty("猩红套的弹幕伤害")]
public int CrimsonArmorEffect_2 = 0;
[JsonProperty("猩红套的弹幕击退")]
public float CrimsonArmorEffect_3 = 0f;


[JsonProperty("流星套是否下落星")]
public bool MeteorArmorEffect = true;
[JsonProperty("流星套的弹幕ID")]
Expand Down Expand Up @@ -116,6 +131,8 @@ public class Config

[JsonProperty("黑曜石套是否盗窃双倍掉落物")]
public bool ObsidianArmorEffect = true;
[JsonProperty("黑曜石套盗窃的稀有等级")]
public int ObsidianArmorEffect_1 = 1;

[JsonProperty("水晶刺客套是否释放水晶碎片")]
public bool CrystalAssassinArmorEffect = true;
Expand Down Expand Up @@ -229,11 +246,19 @@ public class Config
[JsonProperty("皇家凝胶物品雨表")]
public int[] RoyalGelList { get; set; } = new int[] { 23 };

[JsonProperty("挥发凝胶击中敌怪掉落物品表")]
public int[] VolatileGelatin { get; set; } = new int[] { 23, 409, 502, 3111 };

[JsonProperty("狱岩套给什么永久BUFF")]
public int[] MoltenArmor { get; set; } = new int[] { 1, 116 };

[JsonProperty("挖矿套给什么永久BUFF")]
public int[] MiningArmor { get; set; } = new int[] { 104, 192 };
[JsonProperty("挖矿套连锁图格ID表")]
public int[] Tile { get; set; } = new int[] { 6, 7, 8, 9, 166, 167, 168, 169, 22, 221, 222, 223, 224, 232, 37, 404, 408, 48, 481, 482, 483, 56, 571, 58, 63, 64, 65, 66, 67, 68, 107, 108, 111, 123, 178, 204, 211, 229, 230 };

[JsonProperty("蠕虫围巾免疫buff是否开启")]
public bool EnableWormScarf = true;
public bool EnableWormScarf = false;
[JsonProperty("蠕虫围巾遍历前几个buff")]
public int WormScarfImmuneList_2 = 22;
[JsonProperty("蠕虫围巾免疫DeBuff列表/遇到会清空所有BUFF")]
Expand Down
49 changes: 49 additions & 0 deletions Challenger/Challenger/Utils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Terraria;
using TShockAPI;

namespace Challenger
{
class Utils
{
public static Item GetItemFromTile(int x, int y)
{
WorldGen.KillTile_GetItemDrops(x, y, Main.tile[x, y], out int id, out int stack, out _, out _);
Item item = new();
item.SetDefaults(id);
item.stack = stack;
return item;
}
}

public static class Expansion
{
public static int GetBlankSlot(this TSPlayer tsp)
{
int num = 0;
tsp.TPlayer.inventory.ForEach(s => { if (s.netID == 0) num++; });
return num;
}

public static bool IsSpaceEnough(this TSPlayer tsp, int id, int stack)
{
int available = 0;
Item item = new Item();
item.SetDefaults(id);
Item s;
for (int i = 0; i < 50; i++)
{
s = tsp.TPlayer.inventory[i];
if (available < stack)
{
if (s.netID == id) available += (s.maxStack - s.stack);
else if (s.netID == 0) available += item.maxStack;
}
else
{
break;
}
}
return available >= stack;
}
}
}
Loading
Loading