Skip to content
Open
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
4 changes: 1 addition & 3 deletions Client/MirObjects/MonsterObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ public void Load(S.ObjectMonster info, bool update = false)

if (MasterObjectId == 0 && Rarity != MonsterType.Normal)
{
//Moving the rarity tag processing from the server to the client allows for more complex tag displays in the future, such as adding special markers on monster health bars.
//Add localization for rarity text
Name = $"{Rarity.ToLocalizedString()}_{Name}";
Name = $"{info.CustomRarityName}_{Name}";
}
Buffs = info.Buffs;

Expand Down
5 changes: 4 additions & 1 deletion Server/MirEnvir/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2559,7 +2559,10 @@ public bool Spawn()
MonsterObject ob = MonsterObject.GetMonster(Monster);
if (ob == null) return true;

MonsterType type = Settings.MonsterRarityEnabled
bool allowRarity = Settings.MonsterRarityEnabled &&
(Monster == null || !Monster.IsBoss);

MonsterType type = allowRarity
? MonsterRarityData.Roll(RandomProvider.GetThreadRandom())
: MonsterType.Normal;

Expand Down
38 changes: 26 additions & 12 deletions Server/MirObjects/MonsterObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,10 @@ protected internal MonsterObject(MonsterInfo info)

public void SetMonsterType(MonsterType type)
{
// Summoned monsters (pets) should always be Normal rarity
if (Master != null && type != MonsterType.Normal)
return;

MonsterType = type;
}
public bool Spawn(Map temp, Point location)
Expand Down Expand Up @@ -760,19 +764,28 @@ protected virtual void ApplyMonsterTypeBonuses()

MonsterRarityProfile profile = GetRarityProfile();

ScaleStat(Stat.HP, profile.HpMultiplier);
if (profile.EnableHpIncrease)
{
ScaleStat(Stat.HP, profile.HpMultiplier);
}

ScaleStat(Stat.MinAC, profile.DefenseMultiplier);
ScaleStat(Stat.MaxAC, profile.DefenseMultiplier);
ScaleStat(Stat.MinMAC, profile.DefenseMultiplier);
ScaleStat(Stat.MaxMAC, profile.DefenseMultiplier);
if (profile.EnableDefenseIncrease)
{
ScaleStat(Stat.MinAC, profile.DefenseMultiplier);
ScaleStat(Stat.MaxAC, profile.DefenseMultiplier);
ScaleStat(Stat.MinMAC, profile.DefenseMultiplier);
ScaleStat(Stat.MaxMAC, profile.DefenseMultiplier);
}

ScaleStat(Stat.MinDC, profile.DamageMultiplier);
ScaleStat(Stat.MaxDC, profile.DamageMultiplier);
ScaleStat(Stat.MinMC, profile.DamageMultiplier);
ScaleStat(Stat.MaxMC, profile.DamageMultiplier);
ScaleStat(Stat.MinSC, profile.DamageMultiplier);
ScaleStat(Stat.MaxSC, profile.DamageMultiplier);
if (profile.EnableDamageIncrease)
{
ScaleStat(Stat.MinDC, profile.DamageMultiplier);
ScaleStat(Stat.MaxDC, profile.DamageMultiplier);
ScaleStat(Stat.MinMC, profile.DamageMultiplier);
ScaleStat(Stat.MaxMC, profile.DamageMultiplier);
ScaleStat(Stat.MinSC, profile.DamageMultiplier);
ScaleStat(Stat.MaxSC, profile.DamageMultiplier);
}
}

protected void ScaleStat(Stat stat, double multiplier)
Expand Down Expand Up @@ -2875,7 +2888,8 @@ public override Packet GetInfo()
BindingShotCenter = BindingShotCenter,
Buffs = Buffs.Where(d => d.Info.Visible).Select(e => e.Type).ToList(),
MasterObjectId = Master?.ObjectID ?? 0,
Rarity= MonsterType
Rarity = MonsterType,
CustomRarityName = GetRarityProfile().CustomName ?? string.Empty
};
}

Expand Down
95 changes: 91 additions & 4 deletions Server/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Drawing;
using System.Security.Cryptography;
using Server.MirDatabase;
using Server.MirObjects;
Expand Down Expand Up @@ -119,7 +120,7 @@ private static MessageQueue MessageQueue
public static bool MonsterRecallEnabled = true;
public static int MonsterRecallRange = 12;
public static int MonsterRecallCooldown = 5000;
public static bool MonsterRarityEnabled = true;
public static bool MonsterRarityEnabled = false;
public static double MonsterRarityUncommonChancePercent = 3.0,
MonsterRarityRareChancePercent = 0.75,
MonsterRarityEliteChancePercent = 0.1;
Expand All @@ -146,6 +147,21 @@ private static MessageQueue MessageQueue
MonsterRarityEliteGoldMultiplier = 2.50;
public static int MonsterRarityEliteItemDropBonusPercent = 75,
MonsterRarityEliteGoldDropBonusPercent = 75;
public static Color MonsterRarityUncommonNameColour = Color.LightGreen;
public static Color MonsterRarityRareNameColour = Color.DeepSkyBlue;
public static Color MonsterRarityEliteNameColour = Color.Gold;
public static string MonsterRarityUncommonCustomName = "Uncommon";
public static string MonsterRarityRareCustomName = "Rare";
public static string MonsterRarityEliteCustomName = "Elite";
public static bool MonsterRarityUncommonEnableHpIncrease = true;
public static bool MonsterRarityUncommonEnableDefenseIncrease = true;
public static bool MonsterRarityUncommonEnableDamageIncrease = true;
public static bool MonsterRarityRareEnableHpIncrease = true;
public static bool MonsterRarityRareEnableDefenseIncrease = true;
public static bool MonsterRarityRareEnableDamageIncrease = true;
public static bool MonsterRarityEliteEnableHpIncrease = true;
public static bool MonsterRarityEliteEnableDefenseIncrease = true;
public static bool MonsterRarityEliteEnableDamageIncrease = true;

public static bool PetSave = false;

Expand Down Expand Up @@ -1731,6 +1747,7 @@ public static void LoadMonsterRarity()
MonsterRarityRareGoldMultiplier = rarityReader.ReadDouble("Rare", "GoldMultiplier", MonsterRarityRareGoldMultiplier);
MonsterRarityRareItemDropBonusPercent = rarityReader.ReadInt32("Rare", "ItemDropBonusPercent", MonsterRarityRareItemDropBonusPercent);
MonsterRarityRareGoldDropBonusPercent = rarityReader.ReadInt32("Rare", "GoldDropBonusPercent", MonsterRarityRareGoldDropBonusPercent);
MonsterRarityRareNameColour = ReadRarityColour(rarityReader, "Rare", "NameColour", MonsterRarityRareNameColour);

MonsterRarityEliteHpMultiplier = rarityReader.ReadDouble("Elite", "HpMultiplier", MonsterRarityEliteHpMultiplier);
MonsterRarityEliteDefenseMultiplier = rarityReader.ReadDouble("Elite", "DefenseMultiplier", MonsterRarityEliteDefenseMultiplier);
Expand All @@ -1739,6 +1756,29 @@ public static void LoadMonsterRarity()
MonsterRarityEliteGoldMultiplier = rarityReader.ReadDouble("Elite", "GoldMultiplier", MonsterRarityEliteGoldMultiplier);
MonsterRarityEliteItemDropBonusPercent = rarityReader.ReadInt32("Elite", "ItemDropBonusPercent", MonsterRarityEliteItemDropBonusPercent);
MonsterRarityEliteGoldDropBonusPercent = rarityReader.ReadInt32("Elite", "GoldDropBonusPercent", MonsterRarityEliteGoldDropBonusPercent);
MonsterRarityEliteNameColour = ReadRarityColour(rarityReader, "Elite", "NameColour", MonsterRarityEliteNameColour);
MonsterRarityUncommonNameColour = ReadRarityColour(rarityReader, "Uncommon", "NameColour", MonsterRarityUncommonNameColour);

string uncommonName = rarityReader.ReadString("Uncommon", "CustomName", MonsterRarityUncommonCustomName);
MonsterRarityUncommonCustomName = string.IsNullOrWhiteSpace(uncommonName) ? "Uncommon" : uncommonName;

string rareName = rarityReader.ReadString("Rare", "CustomName", MonsterRarityRareCustomName);
MonsterRarityRareCustomName = string.IsNullOrWhiteSpace(rareName) ? "Rare" : rareName;

string eliteName = rarityReader.ReadString("Elite", "CustomName", MonsterRarityEliteCustomName);
MonsterRarityEliteCustomName = string.IsNullOrWhiteSpace(eliteName) ? "Elite" : eliteName;

MonsterRarityUncommonEnableHpIncrease = rarityReader.ReadBoolean("Uncommon", "EnableHpIncrease", MonsterRarityUncommonEnableHpIncrease);
MonsterRarityUncommonEnableDefenseIncrease = rarityReader.ReadBoolean("Uncommon", "EnableDefenseIncrease", MonsterRarityUncommonEnableDefenseIncrease);
MonsterRarityUncommonEnableDamageIncrease = rarityReader.ReadBoolean("Uncommon", "EnableDamageIncrease", MonsterRarityUncommonEnableDamageIncrease);

MonsterRarityRareEnableHpIncrease = rarityReader.ReadBoolean("Rare", "EnableHpIncrease", MonsterRarityRareEnableHpIncrease);
MonsterRarityRareEnableDefenseIncrease = rarityReader.ReadBoolean("Rare", "EnableDefenseIncrease", MonsterRarityRareEnableDefenseIncrease);
MonsterRarityRareEnableDamageIncrease = rarityReader.ReadBoolean("Rare", "EnableDamageIncrease", MonsterRarityRareEnableDamageIncrease);

MonsterRarityEliteEnableHpIncrease = rarityReader.ReadBoolean("Elite", "EnableHpIncrease", MonsterRarityEliteEnableHpIncrease);
MonsterRarityEliteEnableDefenseIncrease = rarityReader.ReadBoolean("Elite", "EnableDefenseIncrease", MonsterRarityEliteEnableDefenseIncrease);
MonsterRarityEliteEnableDamageIncrease = rarityReader.ReadBoolean("Elite", "EnableDamageIncrease", MonsterRarityEliteEnableDamageIncrease);

MonsterRarityData.SetEnabled(MonsterRarityEnabled);
MonsterRarityData.Configure(MonsterRarityUncommonChancePercent, MonsterRarityRareChancePercent, MonsterRarityEliteChancePercent);
Expand All @@ -1754,7 +1794,11 @@ public static void LoadMonsterRarity()
GoldMultiplier = MonsterRarityUncommonGoldMultiplier,
ItemDropBonusPercent = MonsterRarityUncommonItemDropBonusPercent,
GoldDropBonusPercent = MonsterRarityUncommonGoldDropBonusPercent,
NameColour = MonsterRarityData.GetProfile(MonsterType.Uncommon).NameColour
NameColour = MonsterRarityUncommonNameColour,
CustomName = MonsterRarityUncommonCustomName,
EnableHpIncrease = MonsterRarityUncommonEnableHpIncrease,
EnableDefenseIncrease = MonsterRarityUncommonEnableDefenseIncrease,
EnableDamageIncrease = MonsterRarityUncommonEnableDamageIncrease
},
[MonsterType.Rare] = new MonsterRarityProfile
{
Expand All @@ -1765,7 +1809,11 @@ public static void LoadMonsterRarity()
GoldMultiplier = MonsterRarityRareGoldMultiplier,
ItemDropBonusPercent = MonsterRarityRareItemDropBonusPercent,
GoldDropBonusPercent = MonsterRarityRareGoldDropBonusPercent,
NameColour = MonsterRarityData.GetProfile(MonsterType.Rare).NameColour
NameColour = MonsterRarityRareNameColour,
CustomName = MonsterRarityRareCustomName,
EnableHpIncrease = MonsterRarityRareEnableHpIncrease,
EnableDefenseIncrease = MonsterRarityRareEnableDefenseIncrease,
EnableDamageIncrease = MonsterRarityRareEnableDamageIncrease
},
[MonsterType.Elite] = new MonsterRarityProfile
{
Expand All @@ -1776,7 +1824,11 @@ public static void LoadMonsterRarity()
GoldMultiplier = MonsterRarityEliteGoldMultiplier,
ItemDropBonusPercent = MonsterRarityEliteItemDropBonusPercent,
GoldDropBonusPercent = MonsterRarityEliteGoldDropBonusPercent,
NameColour = MonsterRarityData.GetProfile(MonsterType.Elite).NameColour
NameColour = MonsterRarityEliteNameColour,
CustomName = MonsterRarityEliteCustomName,
EnableHpIncrease = MonsterRarityEliteEnableHpIncrease,
EnableDefenseIncrease = MonsterRarityEliteEnableDefenseIncrease,
EnableDamageIncrease = MonsterRarityEliteEnableDamageIncrease
}
};

Expand All @@ -1793,5 +1845,40 @@ private static double ReadRarityChancePercent(InIReader reader, string percentKe
return percent;
}

public static void SaveMonsterRarity()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of values missing here not being saved. Everything that's loaded should also be saved.

{
var rarityReader = new InIReader(Path.Combine(ConfigPath, "MonsterRarity.ini"));

rarityReader.Write("General", "Enabled", MonsterRarityEnabled);

rarityReader.Write("Uncommon", "NameColour", MonsterRarityUncommonNameColour.Name);
rarityReader.Write("Rare", "NameColour", MonsterRarityRareNameColour.Name);
rarityReader.Write("Elite", "NameColour", MonsterRarityEliteNameColour.Name);

rarityReader.Write("Uncommon", "CustomName", MonsterRarityUncommonCustomName);
rarityReader.Write("Rare", "CustomName", MonsterRarityRareCustomName);
rarityReader.Write("Elite", "CustomName", MonsterRarityEliteCustomName);

rarityReader.Write("Uncommon", "EnableHpIncrease", MonsterRarityUncommonEnableHpIncrease);
rarityReader.Write("Uncommon", "EnableDefenseIncrease", MonsterRarityUncommonEnableDefenseIncrease);
rarityReader.Write("Uncommon", "EnableDamageIncrease", MonsterRarityUncommonEnableDamageIncrease);

rarityReader.Write("Rare", "EnableHpIncrease", MonsterRarityRareEnableHpIncrease);
rarityReader.Write("Rare", "EnableDefenseIncrease", MonsterRarityRareEnableDefenseIncrease);
rarityReader.Write("Rare", "EnableDamageIncrease", MonsterRarityRareEnableDamageIncrease);

rarityReader.Write("Elite", "EnableHpIncrease", MonsterRarityEliteEnableHpIncrease);
rarityReader.Write("Elite", "EnableDefenseIncrease", MonsterRarityEliteEnableDefenseIncrease);
rarityReader.Write("Elite", "EnableDamageIncrease", MonsterRarityEliteEnableDamageIncrease);

rarityReader.Save();
}

private static Color ReadRarityColour(InIReader reader, string section, string key, Color defaultColour)
{
string value = reader.ReadString(section, key, defaultColour.Name);
Color parsed = Color.FromName(value);
return parsed.IsEmpty ? defaultColour : parsed;
}
}
}
34 changes: 30 additions & 4 deletions Shared/Data/MonsterRarityData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public struct MonsterRarityProfile
public int ItemDropBonusPercent;
public int GoldDropBonusPercent;
public Color NameColour;
public string CustomName;
public bool EnableHpIncrease;
public bool EnableDefenseIncrease;
public bool EnableDamageIncrease;
}

public static class MonsterRarityData
Expand All @@ -28,7 +32,11 @@ public static class MonsterRarityData
GoldMultiplier = 1.00,
ItemDropBonusPercent = 0,
GoldDropBonusPercent = 0,
NameColour = Color.White
NameColour = Color.White,
CustomName = null,
EnableHpIncrease = false,
EnableDefenseIncrease = false,
EnableDamageIncrease = false
},
[MonsterType.Uncommon] = new MonsterRarityProfile
{
Expand All @@ -39,7 +47,11 @@ public static class MonsterRarityData
GoldMultiplier = 1.25,
ItemDropBonusPercent = 15,
GoldDropBonusPercent = 15,
NameColour = Color.LightGreen
NameColour = Color.LightGreen,
CustomName = null,
EnableHpIncrease = true,
EnableDefenseIncrease = true,
EnableDamageIncrease = true
},
[MonsterType.Rare] = new MonsterRarityProfile
{
Expand All @@ -50,7 +62,11 @@ public static class MonsterRarityData
GoldMultiplier = 1.75,
ItemDropBonusPercent = 35,
GoldDropBonusPercent = 35,
NameColour = Color.DeepSkyBlue
NameColour = Color.DeepSkyBlue,
CustomName = null,
EnableHpIncrease = true,
EnableDefenseIncrease = true,
EnableDamageIncrease = true
},
[MonsterType.Elite] = new MonsterRarityProfile
{
Expand All @@ -61,7 +77,11 @@ public static class MonsterRarityData
GoldMultiplier = 2.50,
ItemDropBonusPercent = 75,
GoldDropBonusPercent = 75,
NameColour = Color.Gold
NameColour = Color.Gold,
CustomName = null,
EnableHpIncrease = true,
EnableDefenseIncrease = true,
EnableDamageIncrease = true
}
};

Expand Down Expand Up @@ -99,6 +119,12 @@ public static MonsterRarityProfile GetProfile(MonsterType type)
return Profiles.TryGetValue(type, out var profile) ? profile : Profiles[MonsterType.Normal];
}

public static string GetDisplayName(MonsterType type)
{
var profile = GetProfile(type);
return !string.IsNullOrEmpty(profile.CustomName) ? profile.CustomName : type.ToLocalizedString();
}

public static MonsterType Roll(Random random)
{
if (!Enabled)
Expand Down
5 changes: 4 additions & 1 deletion Shared/ServerPackets.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Drawing;

namespace ServerPackets
Expand Down Expand Up @@ -2232,6 +2232,7 @@ public override short Index
public bool BindingShotCenter;
public uint MasterObjectId;
public MonsterType Rarity;
public string CustomRarityName = string.Empty;

public List<BuffType> Buffs = new List<BuffType>();

Expand All @@ -2256,6 +2257,7 @@ protected override void ReadPacket(BinaryReader reader)
ExtraByte = reader.ReadByte();
MasterObjectId= reader.ReadUInt32();
Rarity= (MonsterType)reader.ReadByte();
CustomRarityName = reader.ReadString();

int count = reader.ReadInt32();
for (int i = 0; i < count; i++)
Expand Down Expand Up @@ -2286,6 +2288,7 @@ protected override void WritePacket(BinaryWriter writer)
writer.Write((byte)ExtraByte);
writer.Write(MasterObjectId);
writer.Write((byte)Rarity);
writer.Write(CustomRarityName);

writer.Write(Buffs.Count);
for (int i = 0; i < Buffs.Count; i++)
Expand Down