From 0483d02e937e0601690b7c9d7e3be7daf7471d7e Mon Sep 17 00:00:00 2001
From: DarkGod <darkgod@net-core.org>
Date: Tue, 7 Jul 2020 18:19:19 +0200
Subject: [PATCH] Call of the Crypt level 5 effect can only sustain at most one
 mage and one archer

---
 .../tome/data/talents/spells/master-of-bones.lua  | 15 +++++++++++++--
 game/modules/tome/data/talents/spells/spells.lua  | 12 ++++++++++--
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/game/modules/tome/data/talents/spells/master-of-bones.lua b/game/modules/tome/data/talents/spells/master-of-bones.lua
index a3af535553..d4e803849d 100644
--- a/game/modules/tome/data/talents/spells/master-of-bones.lua
+++ b/game/modules/tome/data/talents/spells/master-of-bones.lua
@@ -216,8 +216,19 @@ newTalent{
 				if self.__call_crypt_count == 3 then
 					self.__call_crypt_count = 0
 					if self:getTalentLevel(t) >= 5 then
+						local stats = necroArmyStats(self)
 						local pos = rng.tableRemove(possible_spots)
-						if pos then necroSetupSummon(self, rng.percent(50) and t.minions_list.skel_mage or t.minions_list.skel_m_archer, pos.x, pos.y, lev, nil, true) end
+						local kind = nil
+						if not stats.has_skeleton_mage and stats.has_skeleton_archer then
+							kind = t.minions_list.skel_mage
+						elseif stats.has_skeleton_mage and not stats.has_skeleton_archer then
+							kind = t.minions_list.skel_m_archer
+						elseif not stats.has_skeleton_mage and not stats.has_skeleton_archer then
+							kind = rng.percent(50) and t.minions_list.skel_mage or t.minions_list.skel_m_archer
+						else
+							kind = t.minions_list.a_skel_warrior
+						end
+						if pos and kind then necroSetupSummon(self, kind, pos.x, pos.y, lev, nil, true) end
 					end
 				end
 			end
@@ -231,7 +242,7 @@ newTalent{
 		return ([[Call upon the battle fields of old to collect bones and fuse them with souls, combining them to create skeletal minions to do your bidding.
 		Up to %d skeleton warriors of level %d are summoned. Up to %d skeletons can be controlled at once.
 		At level 3 the summons become armoured skeletons warriors.
-		At level 5 every 3 summoned warriors a free skeleton mage or skeleton archer is also created (without costing a soul).
+		At level 5 every 3 summoned warriors a free skeleton mage or skeleton archer is also created (without costing a soul). You can only sustain one mage and one archer at most in your army, in which case the free minion will be an armoured skeleton warrior.
 
 		#GREY##{italic}#Skeleton minions come in fewer numbers than ghoul minions but are generaly more durable.#{normal}#
 		]]):tformat(t:_getNb(self), math.max(1, self.level + t:_getLevel(self)), t:_getMax(self, true))
diff --git a/game/modules/tome/data/talents/spells/spells.lua b/game/modules/tome/data/talents/spells/spells.lua
index c7b9c44183..6ae32eca31 100644
--- a/game/modules/tome/data/talents/spells/spells.lua
+++ b/game/modules/tome/data/talents/spells/spells.lua
@@ -126,7 +126,11 @@ function necroArmyStats(self)
 	if not game.party or not game.party:hasMember(self) then
 		for _, act in pairs(game.level.entities) do if act.summoner == self and act.necrotic_minion then
 			stats.nb = stats.nb + 1
-			if act.skeleton_minion then stats.nb_skeleton = stats.nb_skeleton + 1 end
+			if act.skeleton_minion then
+				stats.nb_skeleton = stats.nb_skeleton + 1
+				if act.skeleton_minion == "mage" then stats.has_skeleton_mage = true end
+				if act.skeleton_minion == "archer" then stats.has_skeleton_archer = true end
+			end
 			if act.ghoul_minion then stats.nb_ghoul = stats.nb_ghoul + 1 end
 			if act.lord_of_skulls then stats.lord_of_skulls = act end
 			if act.is_bone_giant then stats.bone_giant = act end
@@ -136,7 +140,11 @@ function necroArmyStats(self)
 	else
 		for act, _ in pairs(game.party.members) do if act.summoner == self and act.necrotic_minion then
 			stats.nb = stats.nb + 1
-			if act.skeleton_minion then stats.nb_skeleton = stats.nb_skeleton + 1 end
+			if act.skeleton_minion then
+				stats.nb_skeleton = stats.nb_skeleton + 1
+				if act.skeleton_minion == "mage" then stats.has_skeleton_mage = true end
+				if act.skeleton_minion == "archer" then stats.has_skeleton_archer = true end
+			end
 			if act.ghoul_minion then stats.nb_ghoul = stats.nb_ghoul + 1 end
 			if act.lord_of_skulls then stats.lord_of_skulls = act end
 			if act.is_bone_giant then stats.bone_giant = act end
-- 
GitLab