From b274a5005e2467cd36be1a3eef1121388b828445 Mon Sep 17 00:00:00 2001
From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54>
Date: Fri, 8 Apr 2011 16:28:01 +0000
Subject: [PATCH] Armour changed again, it is back to a flat damage reduction
 New stat: armour hardiness, it's base 30% and can be increased with Armour
 Training. It represents how much of a blow is affected by armour

git-svn-id: http://svn.net-core.org/repos/t-engine4@3189 51575b47-30f0-44d4-a5cc-537603b46e54
---
 game/modules/tome/class/Actor.lua               |  2 +-
 game/modules/tome/class/interface/Archery.lua   | 16 +++++++---------
 game/modules/tome/class/interface/Combat.lua    | 17 +++++++++++++----
 .../tome/class/interface/PlayerDumpJSON.lua     |  1 +
 .../tome/class/interface/TooltipsData.lua       |  4 ++++
 .../data/talents/techniques/combat-training.lua |  5 ++++-
 game/modules/tome/dialogs/CharacterSheet.lua    |  6 ++++--
 7 files changed, 34 insertions(+), 17 deletions(-)

diff --git a/game/modules/tome/class/Actor.lua b/game/modules/tome/class/Actor.lua
index d081af35a0..6512145ea8 100644
--- a/game/modules/tome/class/Actor.lua
+++ b/game/modules/tome/class/Actor.lua
@@ -72,12 +72,12 @@ _M.temporary_values_conf.global_speed = "mult0"
 _M.temporary_values_conf.movement_speed = "mult0"
 _M.temporary_values_conf.combat_physspeed = "mult0"
 _M.temporary_values_conf.combat_spellspeed = "mult0"
-_M.temporary_values_conf.resists = "perc_inv"
 
 function _M:init(t, no_default)
 	-- Define some basic combat stats
 	self.combat_def = 0
 	self.combat_armor = 0
+	self.combat_armor_hardiness = 0
 	self.combat_atk = 0
 	self.combat_apr = 0
 	self.combat_dam = 0
diff --git a/game/modules/tome/class/interface/Archery.lua b/game/modules/tome/class/interface/Archery.lua
index 2f0508be2d..569325622e 100644
--- a/game/modules/tome/class/interface/Archery.lua
+++ b/game/modules/tome/class/interface/Archery.lua
@@ -132,12 +132,10 @@ local function archery_projectile(tx, ty, tg, self)
 		apr = apr + (tg.archery.apr or 0)
 		print("[ATTACK ARCHERY] raw dam", dam, "versus", armor, "with APR", apr)
 
-		apr = 1-math.pow(0.99, apr)
-		armor = 1-math.pow(0.99, armor)
-		print("[ATTACK] raw dam", dam, "versus", armor, "with APR", apr)
+		local pres = util.bound(self:combatArmorHardiness() / 100, 0, 1)
 		armor = math.max(0, armor - apr)
-		dam = dam * (1 - armor)
-		print("[ATTACK] after armor", dam)
+		dam = math.max(dam * pres - armor, 0) + (dam * (1 - pres))
+		print("[ATTACK ARCHERY] after armor", dam)
 
 		local damrange = self:combatDamageRange(ammo)
 		dam = rng.range(dam, dam * damrange)
@@ -177,21 +175,21 @@ local function archery_projectile(tx, ty, tg, self)
 		DamageType:get(DamageType.TEMPORAL).projector(self, target.x, target.y, DamageType.TEMPORAL, dam)
 	end
 
-	
+
 	-- Regen on being hit
 	if hitted and not target.dead and target:attr("stamina_regen_on_hit") then target:incStamina(target.stamina_regen_on_hit) end
 	if hitted and not target.dead and target:attr("mana_regen_on_hit") then target:incMana(target.mana_regen_on_hit) end
-	
+
 	-- Ablative armor
 	if hitted and not target.dead and target:attr("carbon_spikes") then
 		if target.carbon_armor >= 1 then
-			target.carbon_armor = target.carbon_armor - 1 
+			target.carbon_armor = target.carbon_armor - 1
 		else
 			-- Deactivate without loosing energy
 			target:forceUseTalent(target.T_CARBON_SPIKES, {ignore_energy=true})
 		end
 	end
-	
+
 end
 
 --- Shoot at one target
diff --git a/game/modules/tome/class/interface/Combat.lua b/game/modules/tome/class/interface/Combat.lua
index e4a85363cc..cdead4e819 100644
--- a/game/modules/tome/class/interface/Combat.lua
+++ b/game/modules/tome/class/interface/Combat.lua
@@ -232,11 +232,10 @@ function _M:attackTargetWith(target, weapon, damtype, mult)
 		evaded = true
 		game.logSeen(target, "%s evades %s.", target.name:capitalize(), self.name)
 	elseif self:checkHit(atk, def) then
-		apr = 1-math.pow(0.99, apr)
-		armor = 1-math.pow(0.99, armor)
-		print("[ATTACK] raw dam", dam, "versus", armor, "with APR", apr)
+		local pres = util.bound(self:combatArmorHardiness() / 100, 0, 1)
+		print("[ATTACK] raw dam", dam, "versus", armor, pres, "with APR", apr)
 		armor = math.max(0, armor - apr)
-		dam = dam * (1 - armor)
+		dam = math.max(dam * pres - armor, 0) + (dam * (1 - pres))
 		print("[ATTACK] after armor", dam)
 		local damrange = self:combatDamageRange(weapon)
 		dam = rng.range(dam, dam * damrange)
@@ -507,6 +506,16 @@ function _M:combatArmor()
 	return self.combat_armor + add
 end
 
+--- Gets armor hardiness
+-- This is how much % of a blow we can reduce with armor
+function _M:combatArmorHardiness()
+	local add = 0
+	if self:hasHeavyArmor() and self:knowTalent(self.T_ARMOUR_TRAINING) then
+		add = add + self:getTalentLevel(self.T_ARMOUR_TRAINING) * 5
+	end
+	return 30 + self.combat_armor_hardiness + add
+end
+
 --- Gets the attack
 function _M:combatAttackBase(weapon, ammo)
 	weapon = weapon or self.combat or {}
diff --git a/game/modules/tome/class/interface/PlayerDumpJSON.lua b/game/modules/tome/class/interface/PlayerDumpJSON.lua
index 76f17a1b23..4ca94101f4 100644
--- a/game/modules/tome/class/interface/PlayerDumpJSON.lua
+++ b/game/modules/tome/class/interface/PlayerDumpJSON.lua
@@ -156,6 +156,7 @@ function _M:dumpToJSON(js)
 	local d = js:newSection("defense", "defense", "pairs", "break")
 	d[#d+1] = { ["fatigue"] = self:combatFatigue() }
 	d[#d+1] = { ["armour"] = self:combatArmor() }
+	d[#d+1] = { ["armour hardiness"] = self:combatArmorHardiness() }
 	d[#d+1] = { ["defense"] = self:combatDefense() }
 	d[#d+1] = { ["ranged defense"] = self:combatDefenseRanged() }
 	d[#d+1] = { ["physical save"] = self:combatPhysicalResist() }
diff --git a/game/modules/tome/class/interface/TooltipsData.lua b/game/modules/tome/class/interface/TooltipsData.lua
index d4f31aedaf..3ac3142e84 100644
--- a/game/modules/tome/class/interface/TooltipsData.lua
+++ b/game/modules/tome/class/interface/TooltipsData.lua
@@ -178,6 +178,10 @@ TOOLTIP_ARMOR = [[#GOLD#Armour#LAST#
 Armour value is a damage reduction from every incoming melee and ranged physical attacks.
 This is countered by armour penetration and is applied before all kinds of critical damage increase, talent multipliers and damage multiplier, thus making even small amounts have greater effects.
 ]]
+TOOLTIP_ARMOR_HARDINESS = [[#GOLD#Armour Hardiness#LAST#
+Armour hardiness value represents how much of every incoming blows the armor will affect.
+With 50% you will apply your armor to half the damage of a blow, with 100% to all of it.
+]]
 TOOLTIP_DEFENSE = [[#GOLD#Defense#LAST#
 Defense represents your chance to avoid being hit at all by a melee attack, it is measured against the attacker's accuracy chance.
 ]]
diff --git a/game/modules/tome/data/talents/techniques/combat-training.lua b/game/modules/tome/data/talents/techniques/combat-training.lua
index 737e3db2c6..21695d5730 100644
--- a/game/modules/tome/data/talents/techniques/combat-training.lua
+++ b/game/modules/tome/data/talents/techniques/combat-training.lua
@@ -43,17 +43,20 @@ newTalent{
 	mode = "passive",
 	points = 10,
 	require = { stat = { str=function(level) return 18 + level - 1 end }, },
+	getArmorHardiness = function(self, t) return self:getTalentLevel(t) * 5 end,
 	getArmor = function(self, t) return self:getTalentLevel(t) * 1.4 end,
 	getCriticalChanceReduction = function(self, t) return self:getTalentLevel(t) * 1.9 end,
 	info = function(self, t)
+		local hardiness = t.getArmorHardiness(self, t)
 		local armor = t.getArmor(self, t)
 		local criticalreduction = t.getCriticalChanceReduction(self, t)
 		return ([[Teaches the usage of armours. Increases armour value by %d and reduces chance to be critically hit by %d%% when wearing a heavy mail armour or a massive plate armour.
+		It also increases armour hardiness by %d%%.
 		At level 1 it allows you to wear gauntlets, helms and heavy boots.
 		At level 2 it allows you to wear heavy mail armour.
 		At level 3 it allows you to wear shields.
 		At level 4 it allows you to wear massive plate armour.]]):
-		format(armor, criticalreduction)
+		format(armor, criticalreduction, hardiness)
 	end,
 }
 
diff --git a/game/modules/tome/dialogs/CharacterSheet.lua b/game/modules/tome/dialogs/CharacterSheet.lua
index adf97d4116..7db7ef3a33 100644
--- a/game/modules/tome/dialogs/CharacterSheet.lua
+++ b/game/modules/tome/dialogs/CharacterSheet.lua
@@ -203,6 +203,7 @@ function _M:drawDialog(s)
 	w = 400
 	self:mouseTooltip(self.TOOLTIP_FATIGUE, s:drawColorStringBlended(self.font, ("Fatigue:        #00ff00#%3d%%"):format(player:combatFatigue()), w, h, 255, 255, 255)) h = h + self.font_h
 	self:mouseTooltip(self.TOOLTIP_ARMOR,   s:drawColorStringBlended(self.font, ("Armor:          #00ff00#%3d"):format(player:combatArmor()), w, h, 255, 255, 255)) h = h + self.font_h
+	self:mouseTooltip(self.TOOLTIP_ARMOR_HARDINESS,   s:drawColorStringBlended(self.font, ("Armor Hardiness:#00ff00#%3d%%"):format(player:combatArmorHardiness()), w, h, 255, 255, 255)) h = h + self.font_h
 	self:mouseTooltip(self.TOOLTIP_DEFENSE, s:drawColorStringBlended(self.font, ("Defense:        #00ff00#%3d"):format(player:combatDefense()), w, h, 255, 255, 255)) h = h + self.font_h
 	self:mouseTooltip(self.TOOLTIP_RDEFENSE,s:drawColorStringBlended(self.font, ("Ranged Defense: #00ff00#%3d"):format(player:combatDefenseRanged()), w, h, 255, 255, 255)) h = h + self.font_h
 
@@ -384,10 +385,11 @@ function _M:dump()
 	nl(makelabel("Spellpower", player:combatSpellpower() ..""))
 	nnl(("%-32s"):format(makelabel("Armor", player:combatArmor() .. "")))
 	nl(makelabel("Spell Crit", player:combatSpellCrit() .."%"))
-	nnl(("%-32s"):format(makelabel("Defense", player:combatDefense() .. "")))
+	nnl(("%-32s"):format(makelabel("Armor Hardiness", player:combatArmorHardiness() .. "%")))
 	nl(makelabel("Spell Speed", player:combatSpellSpeed() ..""))
-	nnl(("%-32s"):format(makelabel("Ranged Defense", player:combatDefenseRanged() .. "")))
+	nnl(("%-32s"):format(makelabel("Defense", player:combatDefense() .. "")))
 	nl()
+	nnl(("%-32s"):format(makelabel("Ranged Defense", player:combatDefenseRanged() .. "")))
 
 	nl()
 	if player.inc_damage.all then nl(makelabel("All damage", player.inc_damage.all.."%")) end
-- 
GitLab