-- 字符串断行函数

function cutChrCHN(txt,w)
	local chr = utf8:new(delSpaceTxt(txt))
	local x = ""
	local y = ""
	local z = ""
	local num_count = 0
	local line_count = 0
	local check_chr = ""
	local sharp = false
	for i = 1 , chr:len() do
		check_chr = chr:sub(i,i)
		if sharp and check_chr ~= "#" then
			x = x..check_chr
		elseif check_chr == "#" and sharp ~= true then
			sharp = true
			x = x..check_chr
		elseif check_chr == "#" and sharp == true then
			sharp = false
			x = x..check_chr
		elseif string.find(check_chr,"[%w%p]") then
			if line_count > w-0.5 then
				x = x.."\n"..z..check_chr
				z = ""
				line_count = num_count
			else
				z = z..check_chr
				num_count = num_count + 0.5
			end
		elseif check_chr == "\n" then 
			if z == "" then
				x = x.."\n"
				line_count = 0
				num_count = 0
			else
				x = x..z.."\n"
				num_count = 0
				line_count  = 0
			end
		elseif i == chr:len() then
			x = x..z..check_chr
		else
			if z == "" then
				if line_count > w-0.5 then 
					if string.find(check_chr,"[，。？；！：]") then
						x = x..check_chr.."\n"
						line_count = 0
					else
						x = x.."\n"..check_chr
						line_count = 1
					end
				else
					x = x..check_chr
					line_count = line_count + 1
				end
			else
				if line_count+num_count > w-0.5 then
					if string.find(check_chr,"[，。？；！：]") then
						x = x..z..check_chr.."\n"
						line_count = 0
						z = ""
						num_count = 0
					else
						x = x..z.."\n"..check_chr
						line_count = 1
						z = ""
						num_count = 0
					end
				else
					x = x..z..check_chr
					line_count = line_count + num_count +1
					z = ""
					num_count = 0
				end
			end
		end
	end
	return x
end

-- 删除字符串中的空格和制表符
function delSpaceTxt(txt)
	local chr = utf8:new(txt)
	local chr_new = ""
	local len_chr = chr:len()
	for i = 1 , len_chr do
		if chr:sub(i,i) ~= " " and chr:sub(i,i) ~= "\t" then
			chr_new = chr_new..chr:sub(i,i)
		end
	end
	return chr_new
end

----阵营替换
function checkFactionCHN(txt)
	if txt=="Enemies" then return "敌人"
	elseif txt=="Undead" then return "亡灵"
	elseif txt=="Allied Kingdoms" then return "联合王国"
	elseif txt=="Shalore" then return "永恒精灵"
	elseif txt=="Thalore" then return "自然精灵"
	elseif txt=="Iron Throne" then return "钢铁王座"
	elseif txt=="The Way" then return "维网"
	elseif txt=="Angolwen" then return "Angolwen"
	elseif txt=="Dreadfell" then return "恐怖荒野"
	elseif txt=="Temple of Creation" then return "创始者神庙"
	elseif txt=="Water lair" then return "水下墓穴"
	elseif txt=="Assassin lair" then return "盗贼巢穴"
	elseif txt=="Rhalore" then return "雪精灵"
	elseif txt=="Zigur" then return "Zigur"
	elseif txt=="Sunwall" then return "太阳堡垒"
	elseif txt=="Orc Pride" then return "兽人的荣耀"
	elseif txt=="Sandworm Burrowers" then return "钻地沙虫"
	elseif txt=="Victim" then return "受害者"
	elseif txt=="Slavers" then return "奴隶贩子"
	elseif txt=="Sorcerers" then return "法师会"
	elseif txt=="Fearscape" then return "Fearscape"
	elseif txt=="Sher'Tul" then return "Sher'Tul"
	else return txt
	end
end

-- 判断是否有汉化的名称，t1为汉化字段，t2为原字段
function checkHaveChnName(t1,t2)
	if t1 then return t1
	else return t2
	end
end

--- 获取伤害类型中文名
function getDamageTypeCHN(t1,t2)
	if t1 then return t1
	else
		return t2
	end
end

--- 获取属性中文名
function getStatCHN(s)
	if s == "str" or s == "Strength" then return "力量"
	elseif s == "mag" or s == "Magic" then return "魔法"
	elseif s == "cun" or s == "Cunning" then return "灵巧"
	elseif s == "con" or s == "Constitution" then return "体质"
	elseif s == "dex" or s == "Dexterity" then return "敏捷"
	elseif s == "wil" or s == "Willpower" then return "意志"
	elseif s == "lck" then return "幸运"
	else return s
	end
end

-- 判定技能系别的函数
function checkTalentTypeCHN(ttype)
	if ttype == "technique" then return "技巧"
	elseif ttype =="cunning" then return "灵巧"
	elseif ttype =="celestial" then return "天空"
	elseif ttype =="chronomancy" then return "时光"
	elseif ttype =="corruption" then return "堕落"
	elseif ttype =="cursed" then return "诅咒"
	elseif ttype =="wild-gift" then return "野性恩赐"
	elseif ttype =="inscriptions" then return "铭文"
	elseif ttype =="base" then return "基础"
	elseif ttype =="psionic" then return "超能"
	elseif ttype =="spell" then return "法术"
	elseif ttype =="undead" then return "死灵"
	elseif ttype =="race" then return "种族专长"
	else return ttype
	end
end

--替换装备主类型

function checkMainType(mtype)
	if mtype == "weapon" then return "武器"
	elseif mtype == "jewelry" then return "首饰"
	elseif mtype == "lite" then return "照明"
	elseif mtype == "armor" then return "护甲"
	elseif mtype == "mount" then return "基座"
	elseif mtype == "gem" then return "珠宝"
	elseif mtype == "potion" then return "药水"
	elseif mtype == "orb" then return "水晶球"
	elseif mtype == "scroll" then return "卷轴"
	else return mtype
	end
end

--替换装备副类型
function checkSubType(stype)
	if stype == "battleaxe" then return "战斧"
	elseif stype == "greatmaul" then return "巨槌"
	elseif stype == "greatsword" then return "大剑"
	elseif stype == "trident" then return "三叉戟"
	elseif stype == "waraxe" then return "巨斧"
	elseif stype == "longbow" then return "长弓"
	elseif stype == "cloak" then return "斗蓬"
	elseif stype == "cloth" then return "长袍"
	elseif stype == "digger" then return "鹤嘴锄"
	elseif stype == "whip" then return "鞭子"
	elseif stype == "hands" then return "手部"
	elseif stype == "white" then return "白宝石"
	elseif stype == "blue" then return "蓝宝石"
	elseif stype == "green" then return "绿宝石"
	elseif stype == "red" then return "红宝石"
	elseif stype == "violet" then return "紫宝石"
	elseif stype == "yellow" then return "黄宝石"
	elseif stype == "multi-hued" then return "混晶石"
	elseif stype == "black" then return "黑曜石"
	elseif stype == "white" then return "白宝石"
	elseif stype == "color" then return "多彩"
	elseif stype == "heavy" then return "重甲"
	elseif stype == "feet" then return "脚部"
	elseif stype == "head" then return "头部"
	elseif stype == "staff" then return "法杖"
	elseif stype == "scroll" then return "卷轴"
	elseif stype == "infusion" then return "纹身"
	elseif stype == "potion" then return "药水"
	elseif stype == "rune" then return "符文"
	elseif stype == "taint" then return "堕落印记"
	elseif stype == "lore" then return "传说"
	elseif stype == "mummy" then return "木乃伊裹尸布"
	elseif stype == "golem" then return "傀儡"
	elseif stype == "money" then return "金币"
	elseif stype == "massive" then return "板甲"
	elseif stype == "mace" then return "锤子"
	elseif stype == "sling" then return "投石索"
	elseif stype == "lite" then return "灯具"
	elseif stype == "shield" then return "盾牌"
	elseif stype == "light" then return "轻甲"
	elseif stype == "wand" then return "魔杖"
	elseif stype == "belt" then return "腰带"
	elseif stype == "dagger" then return "匕首"
	elseif stype == "longsword" then return "长剑"
	elseif stype == "amulet" then return "项链"
	elseif stype == "ring" then return "戒指"
	elseif stype == "orb" then return "水晶球"
	elseif stype == "shot" then return "子弹"
	elseif stype == "arrow" then return "箭矢"
	elseif stype == "ingredient" then return "配料"
	else return stype
	end
end