From ae5ace36149dc001ec21cd4342327576bcc5b02b Mon Sep 17 00:00:00 2001
From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54>
Date: Sat, 23 Oct 2010 18:10:34 +0000
Subject: [PATCH] Stores now have a limit on the price they can give for an
 item, it changes from stores to stores

git-svn-id: http://svn.net-core.org/repos/t-engine4@1608 51575b47-30f0-44d4-a5cc-537603b46e54
---
 game/engines/default/engine/Store.lua         |  4 +-
 game/modules/tome/class/Store.lua             | 39 +++++++++++--------
 .../tome/data/general/stores/basic.lua        |  9 +++++
 .../tome/data/talents/spells/stone.lua        | 24 ++++++------
 4 files changed, 45 insertions(+), 31 deletions(-)

diff --git a/game/engines/default/engine/Store.lua b/game/engines/default/engine/Store.lua
index cec31a6b21..5d9c520657 100644
--- a/game/engines/default/engine/Store.lua
+++ b/game/engines/default/engine/Store.lua
@@ -106,8 +106,8 @@ function _M:transfer(src, dest, item, nb)
 		local o = src:removeObject(src_inven, item)
 		dest:addObject(dest_inven, o)
 	end
-	self:sortInven(store)
-	who:sortInven(inven)
+	src:sortInven(src_inven)
+	dest:sortInven(dest_inven)
 end
 
 function _M:doBuy(who, o, item, nb, store_dialog)
diff --git a/game/modules/tome/class/Store.lua b/game/modules/tome/class/Store.lua
index d9a33b4648..d4d046f515 100644
--- a/game/modules/tome/class/Store.lua
+++ b/game/modules/tome/class/Store.lua
@@ -30,10 +30,13 @@ function _M:loadStores(f)
 end
 
 function _M:init(t, no_default)
-	t.buy_percent = t.buy_percent or 10
-	t.sell_percent = t.sell_percent or 100
+	t.store.buy_percent = t.store.buy_percent or 10
+	t.store.sell_percent = t.store.sell_percent or 100
+	t.store.purse = t.store.purse or 20
 	Store.init(self, t, no_default)
 
+	self.name = self.name .. (" (Max buy %0.2f gold)"):format(self.store.purse)
+
 	if self.store and self.store.restock_after then self.store.restock_after = self.store.restock_after * 10 end
 end
 
@@ -44,9 +47,9 @@ end
 -- @param nb number of items (if stacked) to buy
 -- @return true if allowed to buy
 function _M:tryBuy(who, o, item, nb)
-	local price = o:getPrice() * self.sell_percent / 100
+	local price = o:getPrice() * self.store.sell_percent / 100
 	if who.money >= price * nb then
-		return nb, price * nb  --FINISH ME !!!!
+		return nb, price * nb
 	else
 		Dialog:simplePopup("Not enough gold", "You do not have enough gold!")
 	end
@@ -59,8 +62,9 @@ end
 -- @param nb number of items (if stacked) to sell
 -- @return true if allowed to sell
 function _M:trySell(who, o, item, nb)
-	local price = o:getPrice() * self.buy_percent / 100
+	local price = o:getPrice() * self.store.buy_percent / 100
 	if price <= 0 or nb <= 0 then return end
+	price = math.min(price * nb, self.store.purse)
 	return nb, price
 end
 
@@ -73,7 +77,7 @@ end
 -- @return true if allowed to buy
 function _M:onBuy(who, o, item, nb, before)
 	if before then return end
-	local price = o:getPrice() * self.sell_percent / 100
+	local price = o:getPrice() * self.store.sell_percent / 100
 	if who.money >= price * nb then
 		who:incMoney(- price * nb)
 	end
@@ -89,17 +93,19 @@ end
 function _M:onSell(who, o, item, nb, before)
 	if before then o:identify(true) return end
 
-	local price = o:getPrice() * self.buy_percent / 100
+	local price = o:getPrice() * self.store.buy_percent / 100
 	if price <= 0 or nb <= 0 then return end
-	who:incMoney(price * nb)
+	price = math.min(price * nb, self.store.purse)
+	who:incMoney(price)
 end
 
 --- Override the default
 function _M:doBuy(who, o, item, nb, store_dialog)
 	nb = math.min(nb, o:getNumber())
-	nb = self:tryBuy(who, o, item, nb)
+	local price
+	nb, price = self:tryBuy(who, o, item, nb)
 	if nb then
-		Dialog:yesnoPopup("Buy", ("Buy %d %s for %0.2f gold"):format(nb, o:getName{do_color=true, no_count=true}), function(ok) if ok then
+		Dialog:yesnoPopup("Buy", ("Buy %d %s for %0.2f gold"):format(nb, o:getName{do_color=true, no_count=true}, price), function(ok) if ok then
 			self:onBuy(who, o, item, nb, true)
 			self:transfer(self, who, item, nb)
 			self:onBuy(who, o, item, nb, false)
@@ -111,9 +117,10 @@ end
 --- Override the default
 function _M:doSell(who, o, item, nb, store_dialog)
 	nb = math.min(nb, o:getNumber())
-	nb = self:trySell(who, o, item, nb)
+	local price
+	nb, price = self:trySell(who, o, item, nb)
 	if nb then
-		Dialog:yesnoPopup("Sell", ("Sell %d %s for %0.2f gold"):format(nb, o:getName{do_color=true, no_count=true}), function(ok) if ok then
+		Dialog:yesnoPopup("Sell", ("Sell %d %s for %0.2f gold"):format(nb, o:getName{do_color=true, no_count=true}, price), function(ok) if ok then
 			self:onSell(who, o, item, nb, true)
 			self:transfer(who, self, item, nb)
 			self:onSell(who, o, item, nb, false)
@@ -129,11 +136,11 @@ end
 -- @return a string (possibly multiline) describing the object
 function _M:descObject(who, what, o)
 	if what == "buy" then
-		local desc = tstring({"font", "bold"}, {"color", "GOLD"}, ("Buy for: %0.2f gold (You have %0.2f gold)"):format(o:getPrice() * self.sell_percent / 100, who.money), {"font", "normal"}, {"color", "LAST"}, true, true)
+		local desc = tstring({"font", "bold"}, {"color", "GOLD"}, ("Buy for: %0.2f gold (You have %0.2f gold)"):format(o:getPrice() * self.store.sell_percent / 100, who.money), {"font", "normal"}, {"color", "LAST"}, true, true)
 		desc:merge(o:getDesc())
 		return desc
 	else
-		local desc = tstring({"font", "bold"}, {"color", "GOLD"}, ("Sell for: %0.2f gold (You have %0.2f gold)"):format(o:getPrice() * self.buy_percent / 100, who.money), {"font", "normal"}, {"color", "LAST"}, true, true)
+		local desc = tstring({"font", "bold"}, {"color", "GOLD"}, ("Sell for: %0.2f gold (You have %0.2f gold)"):format(o:getPrice() * self.store.buy_percent / 100, who.money), {"font", "normal"}, {"color", "LAST"}, true, true)
 		desc:merge(o:getDesc())
 		return desc
 	end
@@ -146,9 +153,9 @@ end
 -- @return a string describing the price
 function _M:descObjectPrice(who, what, o)
 	if what == "buy" then
-		return o:getPrice() * self.sell_percent / 100, who.money
+		return o:getPrice() * self.store.sell_percent / 100, who.money
 	else
-		return o:getPrice() * self.buy_percent / 100, who.money
+		return o:getPrice() * self.store.buy_percent / 100, who.money
 	end
 end
 
diff --git a/game/modules/tome/data/general/stores/basic.lua b/game/modules/tome/data/general/stores/basic.lua
index b6987cc1ad..514a48d4bf 100644
--- a/game/modules/tome/data/general/stores/basic.lua
+++ b/game/modules/tome/data/general/stores/basic.lua
@@ -22,6 +22,7 @@ newEntity{
 	name = "general store",
 	display = '1', color=colors.LIGHT_UMBER,
 	store = {
+		purse = 10,
 		restock_after = 1000,
 		empty_before_restock = true,
 		buy_percent = 10,
@@ -41,6 +42,7 @@ newEntity{
 	name = "armour smith",
 	display = '2', color=colors.UMBER,
 	store = {
+		purse = 25,
 		restock_after = 1000,
 		empty_before_restock = true,
 		buy_percent = 10,
@@ -57,6 +59,7 @@ newEntity{
 	name = "weapon smith",
 	display = '3', color=colors.UMBER,
 	store = {
+		purse = 25,
 		restock_after = 1000,
 		empty_before_restock = true,
 		buy_percent = 10,
@@ -74,6 +77,7 @@ newEntity{
 	name = "alchemist store",
 	display = '4', color=colors.LIGHT_BLUE,
 	store = {
+		purse = 10,
 		restock_after = 1000,
 		empty_before_restock = true,
 		buy_percent = 10,
@@ -90,6 +94,7 @@ newEntity{
 	name = "scribe store",
 	display = '5', color=colors.WHITE,
 	store = {
+		purse = 10,
 		restock_after = 1000,
 		empty_before_restock = true,
 		buy_percent = 10,
@@ -107,6 +112,7 @@ newEntity{
 	name = "gem store",
 	display = '9', color=colors.BLUE,
 	store = {
+		purse = 30,
 		restock_after = 1000,
 		empty_before_restock = true,
 		buy_percent = 10,
@@ -123,6 +129,7 @@ newEntity{
 	name = "staves and wands store",
 	display = '6', color=colors.RED,
 	store = {
+		purse = 25,
 		restock_after = 1000,
 		empty_before_restock = true,
 		buy_percent = 10,
@@ -142,6 +149,7 @@ newEntity{
 	name = "jewelry store",
 	display = '2', color=colors.BLUE,
 	store = {
+		purse = 20,
 		restock_after = 1000,
 		empty_before_restock = true,
 		buy_percent = 10,
@@ -159,6 +167,7 @@ newEntity{
 	name = "rare goods",
 	display = '7', color=colors.BLUE,
 	store = {
+		purse = 35,
 		restock_after = 1000,
 		empty_before_restock = true,
 		buy_percent = 10,
diff --git a/game/modules/tome/data/talents/spells/stone.lua b/game/modules/tome/data/talents/spells/stone.lua
index 096e56f58b..daf30ecec8 100644
--- a/game/modules/tome/data/talents/spells/stone.lua
+++ b/game/modules/tome/data/talents/spells/stone.lua
@@ -37,29 +37,27 @@ newTalent{
 		local tg = {type="bolt", range=self:getTalentRange(t), talent=t, display={particle="stone_shards", trail="earthtrail"}}
 		local x, y = self:getTarget(tg)
 		if not x or not y then return nil end
-		self:projectile(tg, x, y, DamageType.SPLIT_BLEED, self:spellCrit(self:combatTalentSpellDamage(t, 20, 120)), nil)
+		self:projectile(tg, x, y, DamageType.SPLIT_BLEED, self:spellCrit(self:combatTalentSpellDamage(t, 15, 120)), nil)
 		game:playSoundNear(self, "talents/earth")
-		--missile #2 (Talent Level 3 Bonus Missile)
-		if self:getTalentLevel(t) >= 3 then
-			local tg2 = {type="bolt", range=self:getTalentRange(t), talent=t, display={particle="stone_shards", trail="earthtrail"}}
-			local x, y = self:getTarget(tg2)
-			if not x or not y then return nil end
-			self:projectile(tg2, x, y, DamageType.SPLIT_BLEED, self:spellCrit(self:combatTalentSpellDamage(t, 20, 120)), nil)
-			game:playSoundNear(self, "talents/earth")
-		else end
-		--missile #3 (Talent Level 5 Bonus Missile)
+		--missile #2
+		local tg2 = {type="bolt", range=self:getTalentRange(t), talent=t, display={particle="stone_shards", trail="earthtrail"}}
+		local x, y = self:getTarget(tg2)
+		if not x or not y then return nil end
+		self:projectile(tg2, x, y, DamageType.SPLIT_BLEED, self:spellCrit(self:combatTalentSpellDamage(t, 15, 120)), nil)
+		game:playSoundNear(self, "talents/earth")
+		--missile #3 (Talent Level 4 Bonus Missile)
 		if self:getTalentLevel(t) >= 5 then
 			local tg3 = {type="bolt", range=self:getTalentRange(t), talent=t, display={particle="stone_shards", trail="earthtrail"}}
 			local x, y = self:getTarget(tg3)
 			if not x or not y then return nil end
-			self:projectile(tg3, x, y, DamageType.SPLIT_BLEED, self:spellCrit(self:combatTalentSpellDamage(t, 20, 120)), nil)
+			self:projectile(tg3, x, y, DamageType.SPLIT_BLEED, self:spellCrit(self:combatTalentSpellDamage(t, 15, 120)), nil)
 			game:playSoundNear(self, "talents/earth")
 		else end
 		return true
 	end,
 	info = function(self, t)
-		return ([[Conjures stalactite shaped rocks that you fire individually at any target or targets in range.  Each missile deals %0.2f physical damage and an additional %0.2f bleeding damage over six turns.
-		At talent level 1 you conjure a single missile, at talent level 3 two missiles, and at talent level 5 three missiles.
+		return ([[Conjures stalactite shaped rocks that you target individually at any target or targets in range.  Each missile deals %0.2f physical damage and an additional %0.2f bleeding damage over six turns.
+		At talent level 1 you conjure two missile with an additional missile at talent level 5.
 		The damage will increase with the Magic stat]]):format(damDesc(self, DamageType.PHYSICAL, self:combatTalentSpellDamage(t, 20, 120)/2), damDesc(self, DamageType.PHYSICAL, self:combatTalentSpellDamage(t, 20, 120)/2))
 	end,
 }
-- 
GitLab