challenge-editor/class/character_tool/character_tool.gd

283 lines
8.9 KiB
GDScript3
Raw Normal View History

2024-09-28 18:46:15 +08:00
##角色字典工具类
2024-09-25 23:56:53 +08:00
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]
2024-09-27 17:51:20 +08:00
static func get_head(character_data:Dictionary):
return character_data["head"]
2024-09-25 23:56:53 +08:00
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,魅力
#体质
2024-10-10 18:09:32 +08:00
#"AD":"物理伤害",
#"AP":"法术强度",
#"CRT":"暴击率",
#"CSD":"暴击伤害",
#"LPD":"物理减伤",
#"LSD":"法术减伤",
2024-09-25 23:56:53 +08:00
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
2024-10-10 18:09:32 +08:00
res["AD"]=int(STR/10)
res["AP"]=int(MND/10)
res["CRT"]=5+LUC/2
res["CSD"]=100+WIS
res["LPD"]=0
res["LSD"]=0
2024-09-25 23:56:53 +08:00
return res
pass
static func get_skin_now_use_data(character_data:Dictionary)->Dictionary:
2024-09-27 17:51:20 +08:00
return character_data["skin"][character_data["skin_now_use"]]
2024-09-25 23:56:53 +08:00
static func get_character_name(character_data:Dictionary)->String:
2024-09-27 17:51:20 +08:00
return character_data["name"]
2024-09-26 11:49:53 +08:00
pass
static func get_character_star_num(character_data:Dictionary)->int:
2024-09-27 17:51:20 +08:00
return int(character_data["star"])
2024-09-26 17:54:02 +08:00
#修饰默认的角色数据,例如选择的皮肤,装备的卡片,选择的开局等
#修饰数据存储在玩家数据里用户通过Global获取的角色数据应是修饰后的数据更改角色时通过Global添加修饰器
#"skin":int 改变使用的皮肤
#
static func character_embellish(character_data:Dictionary,embellish_data:Dictionary)->Dictionary:
var res_data=character_data.duplicate(true)
2024-09-27 11:47:19 +08:00
#使用皮肤更改修饰
2024-09-26 17:54:02 +08:00
if embellish_data.has("skin"):
2024-09-27 17:51:20 +08:00
res_data["skin_now_use"]=int(embellish_data["skin"])
2024-09-27 11:47:19 +08:00
#"unclocked_start":[0],
#"start_now_use":0,
#开局更改修饰
if embellish_data.has("start"):
res_data["start_now_use"]=int(embellish_data["start"])
2024-09-27 17:51:20 +08:00
#解锁开局data应该是个int类型的Array因为json解析为float这里转换了
2024-09-27 11:47:19 +08:00
if embellish_data.has("unlock_start"):
var unlock_data:Array=embellish_data["unlock_start"]
for i in unlock_data:
2024-09-27 17:51:20 +08:00
#这里,下同
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"]:
2024-09-27 11:47:19 +08:00
res_data["unlocked_start"].append(float(i))
2024-09-26 17:54:02 +08:00
return res_data
2024-10-10 18:09:32 +08:00
#获取先手值
2024-09-25 23:56:53 +08:00
static func get_initiative_value(character_data:Dictionary)->int:
var AGI=get_character_attribute(character_data,"AGI")
return AGI/2+randi_range(-10,10)
2024-09-26 17:54:02 +08:00
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":"魅力",
2024-11-08 00:44:27 +08:00
"MOR":"道德",
"LAF":"守序",
2024-09-26 17:54:02 +08:00
"HP":"生命",
"SP":"精神",
2024-11-08 00:44:27 +08:00
2024-10-10 18:09:32 +08:00
"VIT":"体力",
"AD":"物理伤害",
"AP":"法术强度",
"CRT":"暴击率",
"CSD":"暴击伤害",
"LPD":"物理减伤",
"LSD":"法术减伤",
2024-09-26 17:54:02 +08:00
}
##通过属性的键名获取显示名字
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
2024-09-28 18:46:15 +08:00
#对角色json加载后进行预处理
static func pre_process_character_data(character_data:Dictionary)->Dictionary:
var res:Dictionary=character_data.duplicate(true)
2024-09-30 18:06:45 +08:00
#_添加三页装备为null
2024-09-28 18:46:15 +08:00
#每页顺序默认是饰品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
2024-09-30 18:06:45 +08:00
#技能
2024-09-29 18:09:09 +08:00
res["skill"]=[]
2024-09-30 18:06:45 +08:00
#道具
2024-09-29 18:09:09 +08:00
res["prop"]=[]
2024-09-28 18:46:15 +08:00
return res
2024-09-26 17:54:02 +08:00
2024-09-28 18:46:15 +08:00
#替换装备数据,返回之前装备
2024-09-29 11:46:15 +08:00
static func replace_character_equip(character_data:Dictionary,page:int,pos:int,item_data):
2024-09-28 18:46:15 +08:00
var data=character_data["equip"][page][pos]
2024-09-29 11:46:15 +08:00
if item_data is Dictionary:
character_data["equip"][page][pos]=item_data.duplicate(true)
else:
character_data["equip"][page][pos]=null
2024-09-28 18:46:15 +08:00
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"])
2024-09-30 18:06:45 +08:00
#移除第ind个技能卡返回被移除的技能卡数据
static func remove_skill_index(character_data:Dictionary,ind:int):
var data
if character_data.has("skill"):
var skill_arr=character_data["skill"]
if skill_arr is Array and skill_arr.size()>ind:
data=skill_arr[ind]
skill_arr.pop_at(ind)
return data
#根据id移除技能卡(仅仅移除第一个)
static func remove_skill_id(character_data:Dictionary,id:String):
var data
if character_data.has("skill"):
var skill_arr=character_data["skill"]
if skill_arr is Array:
for i in skill_arr.size():
if skill_arr[i]["id"]==id:
data=skill_arr[i].duplicate(true)
skill_arr.pop_at(i)
break
return data
#向角色添加技能卡bool为添加成功与否的标志如果以后角色需要限制技能卡装备数量上限更改此处
static func add_skill_card(character_data:Dictionary,skill_data:Dictionary)->bool:
if character_data.has("skill"):
var skill_arr=character_data["skill"]
skill_arr.append(skill_data.duplicate(true))
return true
else:
return false
#获取角色的技能序列
static func get_character_skill_all(character_data:Dictionary):
if character_data.has("skill"):
var skill_arr:Array=character_data["skill"]
return skill_arr.duplicate(true)
2024-10-02 18:35:48 +08:00
#获取角色与npc之间的关系
static func get_character_with_npc_favor(character_data:Dictionary,npc_id:String):
var favor_data=character_data["favor"]
if favor_data.has(npc_id):
return favor_data[npc_id]
else:
2024-10-04 18:08:33 +08:00
character_data["favor"][npc_id]=Database.get_npc_data(npc_id)["init_favor"]
2024-10-02 18:35:48 +08:00
return favor_data[npc_id]
pass
2024-10-05 18:44:58 +08:00
#计算装备加成后的角色
static func get_character_with_equip_value(character_data:Dictionary)->Dictionary:
var res:Dictionary=character_data.duplicate(true)
2024-10-05 20:51:00 +08:00
var now_equip=get_character_equip_now(character_data)
for i in now_equip:
if i!=null:
var add_attribute=ItemTool.get_item_attribute_basic(i)
var basic_attribute=res["basic_attribute"]
for j in add_attribute.keys():
if basic_attribute.has(j):
#计算白值
basic_attribute[j]+=add_attribute[j]
2024-10-10 18:09:32 +08:00
2024-10-05 18:44:58 +08:00
return res
pass
2024-10-05 20:51:00 +08:00
#计算角色使用鉴定加成卡后的数值
static func get_character_use_identification_card(character_data:Dictionary,item_arr:Array)->Dictionary:
var res=character_data.duplicate(true)
for i in item_arr:
var add_attribute=ItemTool.get_item_attribute_for_indetification(i)
var basic_attribute=res["basic_attribute"]
if add_attribute!=null:
for j in add_attribute.keys():
if basic_attribute.has(j):
#计算白值
basic_attribute[j]+=add_attribute[j]
return res
2024-11-08 00:44:27 +08:00
#获取一个角色身上对应类型的特质
static func get_all_special_type(character_data:Dictionary,target_type:String)->Array[CharacterSpecial]:
var special_all=character_data["special"]
var res:Array[CharacterSpecial]=[]
for i in special_all:
if Database.get_special_type(i)==target_type:
var target_data=Database.get_special_data(i)
var new_special:CharacterSpecial=CharacterSpecial.new()
new_special.data=target_data
res.append(new_special)
return res
pass
#特质工具类
class CharacterSpecial:
var data:Dictionary
#触发特质
func call_triger():
if data.has("triger") and data["triger"] is Array:
var triget_arr:Array=data["triger"]
for i in triget_arr:
Global.call_triger(i["type"],i["data"])