261 lines
8.0 KiB
GDScript
261 lines
8.0 KiB
GDScript
class_name Func
|
|
extends Node
|
|
|
|
|
|
|
|
static func kfzwx():
|
|
print("一个开发者的玩笑")
|
|
|
|
#计算临时属性
|
|
static func role_count_data(temporary_key,role_data):
|
|
if role_data.is_empty():
|
|
role_data = Global.select_role_data
|
|
match temporary_key:
|
|
"hp":
|
|
return role_data.con
|
|
"san":
|
|
return (role_data.inte+role_data.wil)/2+20
|
|
"state_resis":
|
|
return (role_data.con+role_data.wil)/2*0.2
|
|
"str_hit_rate":
|
|
return role_data.str+20
|
|
"per_hit_rate":
|
|
return role_data.per+20
|
|
"dodge_chance":
|
|
return role_data.agi*0.2
|
|
"critical_chance":
|
|
return role_data.luc*0.2
|
|
#"critical_rate":
|
|
#return get_role_attribute(role_data,"str")+100
|
|
"action":
|
|
return role_data.con+role_data.str+95
|
|
"limited_heavy":
|
|
return role_data.str+role_data.con
|
|
"mp":
|
|
return role_data.inte+role_data.wil
|
|
|
|
|
|
##角色数据 角色属性名 倍率 (计算角色属性倍率)
|
|
#static func role_count_attribute_magnification(roleData,key,magnification):
|
|
#return (roleData[key] * magnification)
|
|
#
|
|
##角色临时数据 角色属性名 倍率 (计算角色属性倍率)
|
|
#static func role_temporary_count_attribute_magnification(roleData,key,magnification):
|
|
#if roleData.temporary.has(key):
|
|
#return (roleData.temporary[key] * magnification)
|
|
#else:
|
|
#return 0
|
|
#///////////////效果方法 增减数值/////////////////
|
|
#角色数据 角色属性名 数值 (修改角色属性值)
|
|
static func add_role_attribute(roledata,key,value):
|
|
#如果角色数据不为空且拥有这个属性名称 则加上数值
|
|
if !roledata.is_empty() and roledata.has(key):
|
|
roledata[key] += value
|
|
pass
|
|
|
|
#添加或者修改角色数据 角色临时属性名 数值 (修改角色临时属性值)
|
|
#如果有 +给的数值 如果没有 先创建初始值为0 再+给的数值
|
|
static func add_role_temporary_attribute(role,temporary_key,value):
|
|
if role != null:
|
|
var roleData = role.role_data
|
|
if !roleData.temporary.has(temporary_key):
|
|
roleData.temporary[temporary_key] = 0
|
|
roleData.temporary[temporary_key] += value
|
|
return value
|
|
return null
|
|
|
|
static func add_value_pop_up(text,role,modulate = "ffffff"):
|
|
if text == null: return
|
|
var VALUE_POP_UP = load("res://common/gui/value_pop_up.tscn").instantiate()
|
|
VALUE_POP_UP.text = text
|
|
if role is Vector2:
|
|
VALUE_POP_UP.global_position = role
|
|
else:
|
|
VALUE_POP_UP.global_position = role.global_position
|
|
VALUE_POP_UP.modulate = Color(modulate)
|
|
Global.get_tree().get_root().add_child(VALUE_POP_UP)
|
|
#////////////////////计算出修正后的数据//////////////
|
|
#返回 角色数据 角色属性名 数值 (获取角色属性值)
|
|
static func get_role_attribute(roleData,key):
|
|
#如果有这个属性名称 获取(属性值+临时属性对应的修正值)*临时属性对应的倍量 否则返回0
|
|
if roleData.has(key):
|
|
var fixation_key = "fixation_"+key
|
|
var intensity_key = "intensity_"+key
|
|
return (roleData[key] + roleData.temporary[fixation_key]) * roleData.temporary[intensity_key]
|
|
return 0
|
|
|
|
#返回 角色数据 角色临时属性名 数值 (获取角色临时属性值)
|
|
static func get_role_temporary_attribute(role,temporary_key):
|
|
#如果有这个属性名称 获取临时属性值 否则返回0
|
|
if role != null:
|
|
var roleData = role.role_data
|
|
if roleData.temporary.has(temporary_key):
|
|
var fixation_key = "fixation_"+temporary_key
|
|
var intensity_key = "intensity_"+temporary_key
|
|
return (roleData.temporary[temporary_key] + roleData.temporary[fixation_key]) * roleData.temporary[intensity_key]
|
|
return 0
|
|
|
|
#////////////////////////初始化自动处理 角色属性的初始化固定值和百分比值///////////////
|
|
#用于角色信息界面、创建角色界面
|
|
#必须先判断是否具有该属性
|
|
static func dispose_role_attribute(roleData,key):
|
|
if roleData.has(key):
|
|
var fixation_key = "fixation_"+key
|
|
var intensity_key = "intensity_"+key
|
|
#固定值
|
|
roleData.temporary[fixation_key] = 0
|
|
#倍率
|
|
roleData.temporary[intensity_key] = 1
|
|
pass
|
|
|
|
#初始化自动处理 角色临时属性的初始化固定值和百分比值
|
|
static func dispose_role_temporary_attribute(roleData,temporary_key):
|
|
if roleData.temporary.has(temporary_key):
|
|
var fixation_key = "fixation_"+temporary_key
|
|
var intensity_key = "intensity_"+temporary_key
|
|
#固定值
|
|
roleData.temporary[fixation_key] = 0
|
|
#倍率
|
|
roleData.temporary[intensity_key] = 1
|
|
pass
|
|
static func add_bullet(target_node,node):
|
|
var flight = preload("res://game/skill/flight.tscn").instantiate()
|
|
if target_node is Vector2:
|
|
flight.target = target_node
|
|
else:
|
|
flight.target = target_node.global_position
|
|
flight.target_node = target_node
|
|
Global.get_tree().get_root().add_child(flight)
|
|
|
|
flight.node = node
|
|
flight.skill_data = node.Selected_skill
|
|
flight.global_position = node.global_position
|
|
flight.read()
|
|
return flight
|
|
#添加技能特效
|
|
static func add_skill_special_effects(node,path):
|
|
var special_effects = load(path).instantiate()
|
|
node.add_child(special_effects)
|
|
#给选定角色添加技能
|
|
static func add_role_skill(role_data,skill_id):
|
|
if !role_data.has("skill"):
|
|
role_data["skill"] = []
|
|
role_data.skill.append(Global.skill_data[skill_id].duplicate(true))
|
|
|
|
#给选定角色移除技能
|
|
static func remove_role_skill(role_data,skill_id):
|
|
if !role_data.has("skill"):
|
|
role_data["skill"] = []
|
|
for index in role_data.skill.size():
|
|
if str(role_data.skill[index]) == Global.skill_data[skill_id]:
|
|
role_data.skill.remove_at(index)
|
|
|
|
#计算
|
|
static func count(a,b,operator):
|
|
match operator:
|
|
"+":
|
|
return a+b
|
|
"-":
|
|
return a-b
|
|
"*":
|
|
return a*b
|
|
"/":
|
|
return a/b
|
|
#角色受伤
|
|
static func hurt(role,value):
|
|
role.hurt(value)
|
|
#随机值:
|
|
static func random(min,max):
|
|
print("==")
|
|
return randi_range(min,max)
|
|
#获取时间
|
|
static func get_time():
|
|
return TimeUtil.get_system_time_secs()
|
|
|
|
#获取对象到玩家的距离
|
|
static func to_playe_distance(node):
|
|
return distance(node,Global.playe)
|
|
#获取玩家位置
|
|
static func get_post():
|
|
return Global.playe.global_position
|
|
#获取节点位置
|
|
static func get_node_post(node):
|
|
return node.global_position
|
|
#获取两个对象距离
|
|
static func distance(node1,node2):
|
|
return node1.global_position.distance_to(node2.global_position)
|
|
|
|
#比较
|
|
static func compare(a,b,operator):
|
|
match operator:
|
|
">":
|
|
return a > b
|
|
"<":
|
|
return a < b
|
|
#判断对象是否为玩家
|
|
static func is_player(node):
|
|
return node == Global.playe
|
|
#判断
|
|
static func If(Bool):
|
|
if !Bool:
|
|
return "return"
|
|
#======================事件=====================
|
|
|
|
#把节点添加到全局选中
|
|
static func add_select(node):
|
|
Global.select = node
|
|
#两个角色id战斗(队伍对象,对战队伍id)
|
|
static func fight_node_id(node1,arr_id):
|
|
var role_data = []
|
|
for id in arr_id:
|
|
role_data.append(Global.role_data[id])
|
|
return await fight(node1.role_arr,role_data)
|
|
#两个角色id战斗(队伍数据,对战队伍id)
|
|
static func fight_data_id(role_arr1,arr_id):
|
|
var role_data = []
|
|
for id in arr_id:
|
|
role_data.append(Global.role_data[id])
|
|
return await fight(role_arr1,role_data)
|
|
#两个角色队伍数据战斗
|
|
static func fight_node(node1,node2):
|
|
return await fight(node1.role_arr,node2.role_arr)
|
|
#两个角色队伍对象战斗
|
|
static func fight(role_arr1,role_arr2):
|
|
var node = add_ui("res://game/fight/fight_ui.tscn")
|
|
node.add_role_arr(1,role_arr1.duplicate(true))
|
|
node.add_role_arr(2,role_arr2.duplicate(true))
|
|
node.ready()
|
|
return await node.result
|
|
#关闭场景
|
|
static func queue_node(node):
|
|
node.queue_free()
|
|
#加载ui场景
|
|
static func add_ui(path):
|
|
var node = load(path).instantiate()
|
|
Ui.add_child(node)
|
|
return node
|
|
#跳转场景
|
|
static func go_to_scene(path,scene):
|
|
var node = load(path).instantiate()
|
|
Global.get_parent().add_child(node)
|
|
scene.queue_free()
|
|
#根据寻路去移动
|
|
static func go_to_move(post,node):
|
|
node.set_target(post)
|
|
#传送到坐标点
|
|
static func go_to_post(post,node):
|
|
go_to_post_x(post.x,node)
|
|
go_to_post_y(post.y,node)
|
|
static func go_to_post_x(x,node):
|
|
node.global_position.x = x
|
|
static func go_to_post_y(y,node):
|
|
node.global_position.y = y
|
|
|
|
#显隐节点
|
|
static func visible(node,Bool):
|
|
node.visible = Bool
|
|
#static func
|
|
#static func show_event_panel():
|
|
#await Loading.load_path("res://game/event/event_panel.tscn").complete
|
|
#pass
|