challenge-editor/class/character_tool/character_tool.gd
2024-09-29 18:09:09 +08:00

158 lines
5.1 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

##角色字典工具类
class_name CharacterTool
static func get_character_attribute(character_data:Dictionary,attribute_name:String):
var arr=has_attribute(character_data)
if arr[0]:
var attribute_data=arr[1]
if attribute_data.has(attribute_name):
return attribute_data[attribute_name]
else:
return null
else:
return null
pass
static func has_attribute(character_data:Dictionary):
if character_data.has("basic_attribute"):
return [true,character_data["basic_attribute"]]
else:
return [false,null]
static func get_head(character_data:Dictionary):
return character_data["head"]
pass
static func cacul_fight_attribute(character_data:Dictionary)->Dictionary:
var res={}
var arr=has_attribute(character_data)
if arr[0]:
var attribute_data=arr[1]
#"CON":100,体质
#"AGI":100,敏捷
#"INT":100,智力
#"WIS":100,感知
#"STR":100,力量
#"MND":100,意志
#"LUC":100,幸运
#"AM":100,魅力
#体质
var CON=attribute_data["CON"]
var AGI=attribute_data["AGI"]
var INT=attribute_data["INT"]
var WIS=attribute_data["WIS"]
var STR=attribute_data["STR"]
var MND=attribute_data["MND"]
var LUC=attribute_data["LUC"]
var AM=attribute_data["AM"]
res["HP"]=CON*5
res["SP"]=INT+MND
res["VIT"]=120
return res
pass
static func get_skin_now_use_data(character_data:Dictionary)->Dictionary:
return character_data["skin"][character_data["skin_now_use"]]
static func get_character_name(character_data:Dictionary)->String:
return character_data["name"]
pass
static func get_character_star_num(character_data:Dictionary)->int:
return int(character_data["star"])
#修饰默认的角色数据,例如选择的皮肤,装备的卡片,选择的开局等
#修饰数据存储在玩家数据里用户通过Global获取的角色数据应是修饰后的数据更改角色时通过Global添加修饰器
#"skin":int 改变使用的皮肤
#
static func character_embellish(character_data:Dictionary,embellish_data:Dictionary)->Dictionary:
var res_data=character_data.duplicate(true)
#使用皮肤更改修饰
if embellish_data.has("skin"):
res_data["skin_now_use"]=int(embellish_data["skin"])
#"unclocked_start":[0],
#"start_now_use":0,
#开局更改修饰
if embellish_data.has("start"):
res_data["start_now_use"]=int(embellish_data["start"])
#解锁开局data应该是个int类型的Array因为json解析为float这里转换了
if embellish_data.has("unlock_start"):
var unlock_data:Array=embellish_data["unlock_start"]
for i in unlock_data:
#这里,下同
if not float(i) in res_data["unlocked_start"]:
res_data["unlocked_start"].append(float(i))
#解锁皮肤data应该是个int类型的Array
if embellish_data.has("unlock_skin"):
var unlock_data:Array=embellish_data["unlock_skin"]
for i in unlock_data:
if not float(i) in res_data["unlocked_skin"]:
res_data["unlocked_start"].append(float(i))
return res_data
static func get_initiative_value(character_data:Dictionary)->int:
var AGI=get_character_attribute(character_data,"AGI")
return AGI/2+randi_range(-10,10)
static func get_character_type(character_data:Dictionary)->int:
return int(character_data["basic_mes"]["type"])
static var attribute_key_to_name_dic:Dictionary={
"CON":"体质",
"AGI":"敏捷",
"INT":"智力",
"WIS":"感知",
"STR":"力量",
"MND":"意志",
"LUC":"幸运",
"AM":"魅力",
"HP":"生命",
"SP":"精神",
"VIT":"体力"
}
##通过属性的键名获取显示名字
static func get_name_by_attribute_key(key:String)->String:
if attribute_key_to_name_dic.has(key):
return attribute_key_to_name_dic[key]
else:
return key
#对角色json加载后进行预处理
static func pre_process_character_data(character_data:Dictionary)->Dictionary:
var res:Dictionary=character_data.duplicate(true)
#添加三页装备为null
#每页顺序默认是饰品1饰品2饰品3饰品4手部1手部2头部身体
#共八个
res["equip"]=[
[null,null,null,null,null,null,null,null,],
[null,null,null,null,null,null,null,null,],
[null,null,null,null,null,null,null,null,]
]
res["now_use_equip"]=0
res["skill"]=[]
res["prop"]=[]
return res
#替换装备数据,返回之前装备
static func replace_character_equip(character_data:Dictionary,page:int,pos:int,item_data):
var data=character_data["equip"][page][pos]
if item_data is Dictionary:
character_data["equip"][page][pos]=item_data.duplicate(true)
else:
character_data["equip"][page][pos]=null
return data
#当前使用的装备方案对应页
static func get_character_equip_page(character_data:Dictionary,page:int)->Array:
var data:Array=character_data["equip"][page]
return data.duplicate(true)
#返回角色当前使用的装备队列
static func get_character_equip_now(character_data:Dictionary):
var now_use_page:int=character_data["now_use_equip"]
var data:Array=character_data["equip"][now_use_page]
return data.duplicate(true)
#改变角色当前使用的装备页
static func change_character_equip_now_use(character_data:Dictionary,page:int):
character_data["now_use_equip"]=page
#获取角色当前使用的装备页数
static func get_character_equip_now_use_page(character_data:Dictionary)->int:
return int(character_data["now_use_equip"])