Skip to content

Commit

Permalink
Merge pull request #202 from THEXN/master
Browse files Browse the repository at this point in the history
修复:死亡掉落CommonRandomDrops为空时的空引用
  • Loading branch information
Controllerdestiny authored Jun 14, 2024
2 parents 264096c + f7dc375 commit 7accecb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
12 changes: 1 addition & 11 deletions AutoTeam/AutoTeamPlus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,11 @@ namespace autoteam
public class Autoteam : TerrariaPlugin
{
public override string Author => "十七改,肝帝熙恩改";
public override Version Version => new Version(2, 3);
public override Version Version => new Version(2, 4);
public override string Description => "自动队伍";
public override string Name => "AutoTeamPlus";
public static Configuration Config;

private readonly Dictionary<string, string> teamNames = new Dictionary<string, string>
{
{ "none", "无队伍" },
{ "red", "红队" },
{ "green", "绿队" },
{ "blue", "蓝队" },
{ "yellow", "黄队" },
{ "pink", "粉队" }
};

public Autoteam(Main game) : base(game)
{
LoadConfig();
Expand Down
32 changes: 25 additions & 7 deletions DeathDrop/DeathDrop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ private void NPCDead(NpcKilledEventArgs args)

if (Config.EnableRandomDrops)
{
if (GetRandomItemIdFromGlobalConfig(Config) == 0)
{
return;
}
int itemId = GetRandomItemIdFromGlobalConfig(Config);

if (Candorp(Config.RandomDropChance))
Expand Down Expand Up @@ -125,19 +129,26 @@ private int GetRandomItemIdFromGlobalConfig(Configuration config)
{
if (config.FullRandomDrops)
{
int itemId = RandomGenerator.Next(1, 5453);

while (config.FullRandomExcludedItems.Contains(itemId))
int itemId;
do
{
itemId = RandomGenerator.Next(1, 5453);
}
} while (config.FullRandomExcludedItems.Contains(itemId));

return itemId;
}
else
{
int randomIndex = RandomGenerator.Next(config.CommonRandomDrops.Count);
return config.CommonRandomDrops[randomIndex];
// 检查CommonRandomDrops列表是否非空
if (config.CommonRandomDrops.Count > 0)
{
int randomIndex = RandomGenerator.Next(config.CommonRandomDrops.Count);
return config.CommonRandomDrops[randomIndex];
}
else
{
return 0;
}
}
}

Expand All @@ -156,8 +167,15 @@ private int GetRandomItemIdFromMonsterConfig(Configuration.Monster monster)
}
else
{
int randomIndex = RandomGenerator.Next(monster.CommonRandomDrops.Count);
if (monster.CommonRandomDrops.Count > 0)
{
int randomIndex = RandomGenerator.Next(monster.CommonRandomDrops.Count);
return monster.CommonRandomDrops[randomIndex];
}
else
{
return 0;
}
}
}

Expand Down

0 comments on commit 7accecb

Please sign in to comment.